我使用 pod'libjingle_peerconnection','〜> 11142.2.0'
当我设置约束时
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"];
或
RTCVideoCapturer *capturer = [RTCVideoCapturer capturerWithDeviceName:cameraID];
RTCVideoSource *videoSource = [_factory videoSourceWithCapturer:capturer constraints:mediaConstraints];
localVideoTrack = [_factory videoTrackWithID:@"ARDAMSv0" source:videoSource];
然后结果是“黑色”本地流。 而且当我设置
RTCMediaConstraints* constraints = [[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil
optionalConstraints:nil];
它正常工作;我如何使用一些约束创建流?
答案 0 :(得分:0)
这是我的约束初始化代码:
- (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设备上运行,如果是,则设置较低的约束(我忘记了哪些设备,但我们在各种设备上进行了相当彻底的测试以找到这些值)。如果它在更好的设备上运行,它会设置更高的分辨率约束(我们再次测试了很多以找到这些值)。
据我所知,max设置最大帧速率并不适用于本机iOS库,至少它从来没有对我有用。相反,我实现了自己的最大fps检查as explained here。这并不限制发送到远程对等体的帧数量,但它确实限制了它们的渲染量,这已经大大提高了性能。
For completeness' sake, here's my entire renderer and related view controller code