AppRTCDemo和xFF08;webRTC和xFF09+;iphone6上的iOS(iOS9):设置约束时,本地RTCMediaStream不工作
我使用pod'libjingle\u peerconnection',“~>11142.2.0” 当我设置约束时AppRTCDemo和xFF08;webRTC和xFF09+;iphone6上的iOS(iOS9):设置约束时,本地RTCMediaStream不工作,ios,webrtc,Ios,Webrtc,我使用pod'libjingle\u peerconnection',“~>11142.2.0” 当我设置约束时 NSArray *mandatoryConstraints = @[ [[RTCPair alloc] initWithKey:@"maxWidth" value:@"320"], [[RTCPair alloc] initWithKey:@"max
NSArray *mandatoryConstraints = @[
[[RTCPair alloc] initWithKey:@"maxWidth" value:@"320"],
[[RTCPair alloc] initWithKey:@"maxHeight" value:@"240"],
[[RTCPair alloc] initWithKey:@"maxFrameRate" value:@"15"]
];
RTCMediaConstraints* mediaConstraints = [[RTCMediaConstraints alloc] initWithMandatoryConstraints:mandatoryConstraints
optionalConstraints:nil];
接下来呢
RTCAVFoundationVideoSource *source =
[[RTCAVFoundationVideoSource alloc] initWithFactory:_factory
constraints:mediaConstraints];
localVideoTrack =
[[RTCVideoTrack alloc] initWithFactory:_factory
source:source
trackId:@"ARDAMSv0"];
或
然后生成一个“黑色”本地流。
而且当我设置
RTCMediaConstraints* constraints = [[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil
optionalConstraints:nil];
它工作正常;如何创建带有一些约束的流?这是我的约束初始化代码:
- (void) initMediaConstraints {
if (!mediaConstraints) {
// retrieve system information and set device name
struct utsname systemInfo;
uname(&systemInfo);
NSString *deviceName = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
if ([deviceName isEqualToString:@"iPad1,1"] || [deviceName isEqualToString:@"iPad2,1"] || [deviceName isEqualToString:@"iPad2,2"] || [deviceName isEqualToString:@"iPad2,3"] || [deviceName isEqualToString:@"iPad2,4"]) {
// use these constraints on crappy devices
mediaConstraints = [[RTCMediaConstraints alloc] initWithMandatoryConstraints:@[
[[RTCPair alloc] initWithKey:@"minWidth" value:@"192"],
[[RTCPair alloc] initWithKey:@"minHeight" value:@"144"],
[[RTCPair alloc] initWithKey:@"maxWidth" value:@"352"],
[[RTCPair alloc] initWithKey:@"maxHeight" value:@"288"]
] optionalConstraints:@[]];
} else {
mediaConstraints = [[RTCMediaConstraints alloc] initWithMandatoryConstraints:@[
[[RTCPair alloc] initWithKey:@"minWidth" value:@"640"],
[[RTCPair alloc] initWithKey:@"minHeight" value:@"480"],
[[RTCPair alloc] initWithKey:@"maxWidth" value:@"1280"],
[[RTCPair alloc] initWithKey:@"maxHeight" value:@"760"]]
optionalConstraints:@[]];
}
}
}
然后我在这里使用它们:
- (void) initVideoSource {
// create a capturer and video source
if (!localVideoCapturer) {
localVideoCapturer = [RTCVideoCapturer capturerWithDeviceName:cameraId];
}
if (!localVideoSource) {
localVideoSource = [peerConnectionFactory videoSourceWithCapturer:localVideoCapturer constraints:mediaConstraints];
}
}
它检测应用程序是否在较旧的iOS设备上运行,如果运行,则设置较低的限制(我忘记了是哪些设备,但我们在大量设备上进行了彻底测试,以找到这些值)。如果它在更好的设备上运行,它会设置更高的分辨率约束(同样,为了找到这些值,我们进行了大量测试)
据我所知,最大设置最大帧速率对本机iOS库还不起作用,至少对我来说从来没有。相反,我实现了自己的最大fps检查。这不会限制发送到远程对等方的帧数量,但会限制渲染的帧数量,这已经大大提高了性能
这是我的约束初始化代码:
- (void) initMediaConstraints {
if (!mediaConstraints) {
// retrieve system information and set device name
struct utsname systemInfo;
uname(&systemInfo);
NSString *deviceName = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
if ([deviceName isEqualToString:@"iPad1,1"] || [deviceName isEqualToString:@"iPad2,1"] || [deviceName isEqualToString:@"iPad2,2"] || [deviceName isEqualToString:@"iPad2,3"] || [deviceName isEqualToString:@"iPad2,4"]) {
// use these constraints on crappy devices
mediaConstraints = [[RTCMediaConstraints alloc] initWithMandatoryConstraints:@[
[[RTCPair alloc] initWithKey:@"minWidth" value:@"192"],
[[RTCPair alloc] initWithKey:@"minHeight" value:@"144"],
[[RTCPair alloc] initWithKey:@"maxWidth" value:@"352"],
[[RTCPair alloc] initWithKey:@"maxHeight" value:@"288"]
] optionalConstraints:@[]];
} else {
mediaConstraints = [[RTCMediaConstraints alloc] initWithMandatoryConstraints:@[
[[RTCPair alloc] initWithKey:@"minWidth" value:@"640"],
[[RTCPair alloc] initWithKey:@"minHeight" value:@"480"],
[[RTCPair alloc] initWithKey:@"maxWidth" value:@"1280"],
[[RTCPair alloc] initWithKey:@"maxHeight" value:@"760"]]
optionalConstraints:@[]];
}
}
}
然后我在这里使用它们:
- (void) initVideoSource {
// create a capturer and video source
if (!localVideoCapturer) {
localVideoCapturer = [RTCVideoCapturer capturerWithDeviceName:cameraId];
}
if (!localVideoSource) {
localVideoSource = [peerConnectionFactory videoSourceWithCapturer:localVideoCapturer constraints:mediaConstraints];
}
}
它检测应用程序是否在较旧的iOS设备上运行,如果运行,则设置较低的限制(我忘记了是哪些设备,但我们在大量设备上进行了彻底测试,以找到这些值)。如果它在更好的设备上运行,它会设置更高的分辨率约束(同样,为了找到这些值,我们进行了大量测试)
据我所知,最大设置最大帧速率对本机iOS库还不起作用,至少对我来说从来没有。相反,我实现了自己的最大fps检查。这不会限制发送到远程对等方的帧数量,但会限制渲染的帧数量,这已经大大提高了性能
因此,当您要提供强制约束时,可选约束必须是空数组@[],而不是零…因此,当您要提供强制约束时,可选约束必须是空数组@[],而不是零。。。