我正在使用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的键。 RTCMediaConstraints不支持这些语句,这可能是一个问题。