我使用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];它正常工作;我如何创建带有一些约束的流?
发布于 2016-05-27 13:29:21
这是我的约束初始化代码:
- (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检查如前所述。这并不限制发送到远程对等端的帧的数量,但它确实限制了呈现的帧数量,这已经极大地提高了性能。
https://stackoverflow.com/questions/37473528
复制相似问题