3

在为最新的 webrtc 框架更新之后,我没有得到如何向用户显示本地流的原因方法已更改,在存储库的“iOS”文件夹中没有示例。

在旧代码中...

   RTCVideoCapturer *capturer = [RTCVideoCapturer capturerWithDeviceName:cameraID];
   RTCMediaConstraints *mediaConstraints = [self defaultMediaStreamConstraints];
   RTCVideoSource *videoSource = [_factory videoSourceWithCapturer:capturer constraints:mediaConstraints];
   localVideoTrack = [_factory videoTrackWithID:@"ARDAMSv0" source:videoSource];

RTCVideoCapturer 对象和 RTCVideoSource 对象在此处相互链接。

但是在新代码中......

  RTCVideoSource *source = [_factory videoSource];
  RTCCameraVideoCapturer *capturer = [[RTCCameraVideoCapturer alloc] initWithDelegate:source];
  [_delegate appClient:self didCreateLocalCapturer:capturer];
    localVideoTrack = [_factory videoTrackWithSource:source
                                             trackId:kARDVideoTrackId];

彼此之间没有任何联系。那么,委托方法做了什么,[_delegate appClient:self didCreateLocalCapturer:capturer]; 我不明白。[需要帮助!]

4

1 回答 1

3

在视频通话视图控制器中实现此委托方法....

- (void)appClient:(ARDAppClient *)client didCreateLocalCapturer:(RTCCameraVideoCapturer *)localCapturer{

    NSLog(@"%s %@",__PRETTY_FUNCTION__ ,localCapturer);

    _captureController =  [[ARDCaptureController alloc] initWithCapturer:localCapturer
                                                                settings:[[ARDSettingsModel alloc] init]];
    [_captureController startCapture];
}

然后......这个方法调用它来创建相同的......

 - (RTCVideoTrack *)createLocalVideoTrack {
      RTCVideoTrack* localVideoTrack = nil;
      // The iOS simulator doesn't provide any sort of camera capture
      // trying to open a local stream.
    #if !TARGET_IPHONE_SIMULATOR
      if (![_settings currentAudioOnlySettingFromStore]) {
          RTCVideoSource *source = [_factory videoSource];
          RTCCameraVideoCapturer *capturer = [[RTCCameraVideoCapturer alloc] initWithDelegate:source];
          [_delegate appClient:self didCreateLocalCapturer:capturer];
          localVideoTrack = [_factory videoTrackWithSource:source
                                                   trackId:kARDVideoTrackId];

          [_delegate appClient:self didReceiveLocalVideoTrack:localVideoTrack];

      }

然后打电话...

_localVideoTrack = [self createLocalVideoTrack]; 

在你的初始化方法中......

- (void)initCall {
    NSLog(@"%s",__PRETTY_FUNCTION__);
    if (!_isTurnComplete) {
        return;
    }
    self.state = kARDAppClientStateConnected;
    _localVideoTrack = [self createLocalVideoTrack];
    // Create peer connection.
    _constraints = [self defaultPeerConnectionConstraints];

}

这段代码让我能够做到这一点!

于 2017-12-15T06:01:37.270 回答