WebRTC iOS: remote video is not shown in iOS client

回眸只為那壹抹淺笑 提交于 2020-07-08 19:04:02

问题


I am trying to implement WebRTC in an iOS application using GoogleWebRTC pod. i can place a video call between iOS app and a web client, in which case the audio/video works just fine. however when i place a video call between two iOS devices there is no video(audio works). i've checked if there is remote stream and there is.

let localStream = connectionFactory?.mediaStream(withStreamId: "StreamID")
let audioTrack = connectionFactory?.audioTrack(withTrackId: "AudioTrackID")
let videoSource = connectionFactory?.avFoundationVideoSource(with: mediaConstraint)
let videoTrack = connectionFactory?.videoTrack(with: videoSource!, trackId: "VideoTrackID")
localStream?.addAudioTrack(audioTrack!)
localStream?.addVideoTrack(videoTrack!)
peerConnection?.add(localStream!)

回答1:


Could be a lot of things, try going off my example: https://github.com/redfearnk/WebRTCVideoChat




回答2:


As my understanding, you can add a remote video track when first create your local video track, then video track will auto produce frames when it is receiving from peer connection, an example code from WebRTC iOS client:

- (void)createMediaSenders {
    RTCMediaConstraints *constraints = [self defaultMediaAudioConstraints];
    RTCAudioSource *source = [_factory audioSourceWithConstraints:constraints];
    if (_isAudioEnabled) {
        RTCAudioTrack *track = [_factory audioTrackWithSource:source trackId:kDSAudioTrackId];
        [_peerConnection addTrack:track streamIds:@[ kDSMediaStreamId ]];
    }
    if (_isVideoEnabled) {
        _localVideoTrack = [self createLocalVideoTrack];
        if (_localVideoTrack) {
            [_peerConnection addTrack:_localVideoTrack streamIds:@[ kDSMediaStreamId ]];

            // Create remote video track
            RTCVideoTrack *track = (RTCVideoTrack *)([self videoTransceiver].receiver.track);
            [_delegate appRTC:self didReceiveRemoteVideoTrack:track];
        }
    }
}



回答3:


Found the problem. I was giving a hard coded string as id when creating stream and video track. which when a connection is established becomes the same for both local and remote streams. providing unique strings as ids solves the problem.




回答4:


in func rtcClient(client : RTCClient, didReceiveRemoteVideoTrack remoteVideoTrack: RTCVideoTrack) perform a selector that will call after 2 sec then in that selector add track to remoteview



来源:https://stackoverflow.com/questions/47290365/webrtc-ios-remote-video-is-not-shown-in-ios-client

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!