ios - 如何使用原生 webrtc 中的约束?

标签 ios objective-c ios7 webrtc

我终于有了一个可以与另一个对等点建立连接的应用程序,并且两个对等点都从远程接收音频和视频。它是一个使用 native RTC APIiOS 应用程序。我现在正在尝试如何提高质量,因此我开始寻找针对媒体限制的选项。

这是我的初始化代码:

//init
peerConnectionFactory = [[RTCPeerConnectionFactory alloc] init];
[RTCPeerConnectionFactory initializeSSL];

//set 2 arrays to be used for the media constraints
NSMutableArray *m = [[NSMutableArray alloc] init];
NSMutableArray *o = [[NSMutableArray alloc] init];

//add stuff to the mandatory array
[m addObject:[[RTCPair alloc] initWithKey:@"OfferToReceiveAudio" value:@"true"]];
[m addObject:[[RTCPair alloc] initWithKey:@"OfferToReceiveVideo" value:@"true"]];

//add stuff to the optional array
//these lines are disabled for now, because my colleague working on the Android version does not support dtls yet
//[o addObject:[[RTCPair alloc] initWithKey:@"internalSctpDataChannels" value:@"true"]];
//[o addObject:[[RTCPair alloc] initWithKey:@"DtlsSrtpKeyAgreement" value:@"true"]];

//use the 2 arrays to init the media constraints
constraints = [[RTCMediaConstraints alloc] initWithMandatoryConstraints:m optionalConstraints:o];

//init stun and turn servers
RTCICEServer *turn = [[RTCICEServer alloc] initWithURI:[NSURL URLWithString:@"turn:numb.viagenie.ca:3478"] username:@"*" password:@"*"];
RTCICEServer *stun = [[RTCICEServer alloc] initWithURI:[NSURL URLWithString:@"stun:stun.l.google.com:19302"] username:@"" password:@""];
NSArray *iceServers = [[NSArray alloc] initWithObjects:turn, stun, nil];

//init the peerconnection object
peerConnection = [peerConnectionFactory peerConnectionWithICEServers:nil
                                                         constraints:constraints
                                                            delegate:self];

我尝试设置以下 RTCPair:

首先我尝试了这些,只是想看看它会做什么。

[o addObject:[[RTCPair alloc] initWithKey:@"minWidth" value:@"1280"]];
[o addObject:[[RTCPair alloc] initWithKey:@"minHeight" value:@"720"]];

它什么也没做。
然后我尝试了这些行(没有前 2 行)。

[m addObject:[[RTCPair alloc] initWithKey:@"minWidth" value:@"1280"]];
[m addObject:[[RTCPair alloc] initWithKey:@"minHeight" value:@"720"]];

这会导致应用程序陷入生成ice候选者的困境。
考虑到该设备可能不支持如此高分辨率,我尝试了以下操作。

[o addObject:[[RTCPair alloc] initWithKey:@"maxWidth" value:@"320"]];
[o addObject:[[RTCPair alloc] initWithKey:@"maxHeight" value:@"180"]];

再次没有效果。

我尝试了更多我不记得的组合,但对我来说,似乎将除 OfferToReceiveAudioOfferToReceiveVideo 之外的任何内容添加到强制数组只会破坏整个过程,并且向可选数组添加任何内容都会被忽略(尽管设置 dtls 会导致无法连接到 Android 版本)。

最佳答案

我正在为对等连接初始化设置约束,但必须为视频源设置它们。创建本地媒体流时,您必须指定摄像机,使用该摄像机初始化捕获器,然后设置视频源以使用该捕获器。设置视频源时,您可以传递约束。

关于ios - 如何使用原生 webrtc 中的约束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25505400/

相关文章:

ios - 如何以编程方式触发 UITableViewCell editActions?

iphone - 我应该在 Core Data 中使用 Cascade 还是 nullify 来建立关系?

iphone - 如何在 NSMutableArray 中创建查询并打印结果?

iOS 7 与 iOS 8 约束大小不同

iphone - 在 iOS 7 中移动状态栏

ios - 如何将 json 转换为我类的对象,反之亦然(使用 alamofire、SwiftyJSON)

ios - 使用 Google Firebase 同时上传多张图片

ios - 在日历 View iOS 中使用 Parse 后端

ios - 不能使用 Outlet 属性将 Segue 从 1 个 Controller 传递到另一个 Controller ?

iOS:使用类型 'CGRect'(又名 'struct CGRect'),其中需要算术或指针类型