ios - 在 webRTC iOS 中设置视频大小

标签 ios webrtc

我正在使用 RTCMediaConstraints 来创建 RTCPeerConnection 和发送 SDP,但我觉得与视频最大宽度/高度相关的可选约束没有得到遵守。

- (RTCMediaConstraints *)mediaConstraints {

    RTCPair *audioConstraint = [[RTCPair alloc] initWithKey:kKeyOfferToReceiveAudio value:kKeyTrue];
    RTCPair *videoConstraint = [[RTCPair alloc] initWithKey:kKeyOfferToReceiveVideo value:kKeyTrue];

    RTCPair *sctpConstraint = [[RTCPair alloc] initWithKey:kKeyInternalSctpDataChannels value:kKeyTrue];
    RTCPair *dtlsConstraint = [[RTCPair alloc] initWithKey:kKeyDtlsSrtpKeyAgreement value:kKeyTrue];

    RTCPair *maxWidth = [[RTCPair alloc] initWithKey:kKeyMaxWidth value:@"640"];
    RTCPair *minWidth = [[RTCPair alloc] initWithKey:kKeyMinWidth value:@"320"];

    RTCPair *maxHeight = [[RTCPair alloc] initWithKey:kKeyMaxHeight value:@"480"];
    RTCPair *minHeight = [[RTCPair alloc] initWithKey:kKeyMinHeight value:@"240"];

    RTCPair *maxFrameRate = [[RTCPair alloc] initWithKey:kKeyMaxFrameRate value:@"30"];
    RTCPair *minFrameRate = [[RTCPair alloc] initWithKey:kKeyMinFrameRate value:@"24"];

    RTCPair *minAspectRatio = [[RTCPair alloc] initWithKey:@"minAspectRatio" value:@"4:3"];
    RTCPair *maxAspectRatio = [[RTCPair alloc] initWithKey:kKeyMaxAspectRatio value:@"4:3"];

    return [[RTCMediaConstraints alloc] initWithMandatoryConstraints:@[audioConstraint, videoConstraint]
                                                 optionalConstraints:@[sctpConstraint, dtlsConstraint, maxAspectRatio, minAspectRatio, minFrameRate, maxFrameRate, maxWidth, minWidth, maxHeight, minHeight]];
}

当我为 RTCVideoSource 添加约束时,我只看到没有视频的黑屏。

RTCVideoCapturer *capturer = [RTCVideoCapturer capturerWithDeviceName:[device localizedName]];
RTCVideoSource *videoSource = [_peerFactory videoSourceWithCapturer:capturer constraints:[self mediaConstraints]];
RTCVideoTrack *videoTrack = [_peerFactory videoTrackWithID:[[NSUUID UUID] UUIDString] source:videoSource];

[_localMediaStream addVideoTrack:videoTrack];

有人对此有什么建议吗?

最佳答案

查看WebRTC的RTCMediaConstraints.h文件,没有kKeyOfferToReceiveAudio和kKeyOfferToReceiveVideo的 key 。 RTCMediaConstraints 不支持这些语句,这可能是一个问题。

关于ios - 在 webRTC iOS 中设置视频大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28233370/

相关文章:

objective-c - NSURLConnection 成功后重新加载 TableView

audio - 我可以使用 MediaDevices.getUserMedia() 连接到多个音频输入设备以获取 webrtc 流吗?

android - Android 中的 WebRTC

javascript - 处理使用 PeerConnection 时处理 ICE 候选人的过程?

javascript - 使用 webrtc 将鼠标点击发送到另一台计算机

webrtc - CentOS7安装janus-gateway报错

ios - 如何从 Watch App(Watch OS 2)与不活动的 IOS 应用程序通信

ios - 如何在 willDisplay 单元格回调中访问 UICollectionView 中的特定单元格

ios - 关于 Realm 数据库中的事务

ios - 数据变化时解析推送通知