首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AppRTCDemo(WebRTC)+ iOS on iPhone 6 (iOS9):当我设置约束时,本地RTCMediaStream无法工作

AppRTCDemo(WebRTC)+ iOS on iPhone 6 (iOS9):当我设置约束时,本地RTCMediaStream无法工作
EN

Stack Overflow用户
提问于 2016-05-27 01:46:48
回答 1查看 801关注 0票数 1

我使用pod 'libjingle_peerconnection','~> 11142.2.0'

当我设置约束时

代码语言:javascript
复制
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];

下一步

代码语言:javascript
复制
RTCAVFoundationVideoSource *source =
[[RTCAVFoundationVideoSource alloc] initWithFactory:_factory
                                        constraints:mediaConstraints];
localVideoTrack =
[[RTCVideoTrack alloc] initWithFactory:_factory
                                source:source
                               trackId:@"ARDAMSv0"];

代码语言:javascript
复制
RTCVideoCapturer *capturer = [RTCVideoCapturer capturerWithDeviceName:cameraID];
RTCVideoSource *videoSource = [_factory videoSourceWithCapturer:capturer constraints:mediaConstraints];
localVideoTrack = [_factory videoTrackWithID:@"ARDAMSv0" source:videoSource];

然后结果是“黑色”本地流。也是当我开始

代码语言:javascript
复制
RTCMediaConstraints* constraints = [[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil
                                                                         optionalConstraints:nil];

它正常工作;我如何创建带有一些约束的流?

EN

回答 1

Stack Overflow用户

发布于 2016-05-27 13:29:21

这是我的约束初始化代码:

代码语言:javascript
复制
- (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:@[]];
        }
    }
}

然后我在这里用它们:

代码语言:javascript
复制
- (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检查如前所述。这并不限制发送到远程对等端的帧的数量,但它确实限制了呈现的帧数量,这已经极大地提高了性能。

为了完整起见,下面是我的整个呈现程序和相关的视图控制器代码

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37473528

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档