放置“呼叫”后,我将使用以下代码创建本地视频流。我的 iPhone 6 的本地媒体流没有生成,但是远程媒体流在我的手机上运行良好。有谁知道为什么我无法获得 iPhone 的本地媒体流?
我正在使用带有 node.js 的 Kurento 媒体服务器。
- (RTCMediaStream *)createLocalMediaStream {
RTCMediaConstraints *constraints = [self defaultPeerConnectionConstraints];
self.peerConnection = [self.peerConnectionFactory peerConnectionWithICEServers:server
constraints:constraints
delegate:self];
RTCMediaStream *localStream = [self createLocalMediaStream];
[self.peerConnection addStream:localStream];
[_peerConnection createOfferWithDelegate:self constraints:[self defaultOfferConstraints]];
RTCMediaStream* localStream = [self.peerConnectionFactory mediaStreamWithLabel:@"ARDAMS"];
RTCVideoTrack* localVideoTrack = nil;
#if !TARGET_IPHONE_SIMULATOR && TARGET_OS_IPHONE
NSString *cameraID = nil;
for (AVCaptureDevice *captureDevice in
[AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]) {
if (captureDevice.position == AVCaptureDevicePositionFront) {
cameraID = [captureDevice localizedName];
break;
}
}
NSAssert(cameraID, @"Unable to get the front camera id");
RTCVideoCapturer *capturer = [RTCVideoCapturer capturerWithDeviceName:cameraID];
RTCMediaConstraints* constraints = [self defaultMediaStreamConstraints];
RTCVideoSource *videoSource = [self.peerConnectionFactory videoSourceWithCapturer:capturer constraints:constraints];
localVideoTrack =
[self.peerConnectionFactory videoTrackWithID:@"ARDAMSv0" source:videoSource];
if (localVideoTrack) {
[localStream addVideoTrack:localVideoTrack];
}
[self.delegate connectionManager:self didReceiveLocalVideoTrack:localVideoTrack];
#endif
[localStream addAudioTrack:[self.peerConnectionFactory audioTrackWithID:@"ARDAMSa0"]];
return localStream;
}
- (RTCMediaConstraints *)defaultPeerConnectionConstraints {
NSArray *optionalConstraints = @[
[[RTCPair alloc] initWithKey:@"DtlsSrtpKeyAgreement" value:@"true"]
];
RTCMediaConstraints* constraints =
[[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil optionalConstraints:optionalConstraints];
return constraints;
}
- (RTCMediaConstraints *)defaultOfferConstraints {
NSArray *mandatoryConstraints = @[
[[RTCPair alloc] initWithKey:@"OfferToReceiveAudio" value:@"true"],
[[RTCPair alloc] initWithKey:@"OfferToReceiveVideo" value:@"true"]
];
RTCMediaConstraints* constraints = [[RTCMediaConstraints alloc] initWithMandatoryConstraints:mandatoryConstraints optionalConstraints:nil];
return constraints;
}
- (RTCMediaConstraints *)defaultMediaStreamConstraints {
NSArray *mandatoryConstraints = @[
[[RTCPair alloc] initWithKey:@"maxWidth" value:@"640"],
[[RTCPair alloc] initWithKey:@"minWidth" value:@"640"],
[[RTCPair alloc] initWithKey:@"maxHeight" value:@"480"],
[[RTCPair alloc] initWithKey:@"minHeight" value:@"480"],
[[RTCPair alloc] initWithKey:@"maxFrameRate" value:@"30"],
[[RTCPair alloc] initWithKey:@"minFrameRate" value:@"5"],
[[RTCPair alloc] initWithKey:@"googLeakyBucket" value:@"true"]
];
RTCMediaConstraints *constrains = [[RTCMediaConstraints alloc] initWithMandatoryConstraints:mandatoryConstraints optionalConstraints:nil];
return constrains;
}