我正在使用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];
有人对此有一些建议吗?
答案 0 :(得分:0)
根据我对WebRTC约束的经验,黑屏意味着一个错误的约束。
此外,我不认为你应该在视频源上提供优惠和DTLS约束,如果你正在做的那样。
我几乎可以告诉你。
答案 1 :(得分:0)
查看WebRTC的RTCMediaConstraints.h文件,没有kKeyOfferToReceiveAudio和kKeyOfferToReceiveVideo的密钥。 RTCMediaConstraints不支持这些语句,这可能是一个问题。