iOS Webrtc - 捕获本地视频流时崩溃

iOS Webrtc - Crash in capturing local Video Stream

我正在尝试使用 Google 的 repo 中的 webrtc 库。我按照这些步骤创建了一个单独的项目,其中包含类似于 APPRTC 的说明和代码,并且我能够让它工作。我能够在 2 台设备之间召开会议。但是当我尝试与一个旧项目集成时,Webrtc 崩溃了。以下是重现崩溃的步骤。

  1. 初始化对等连接工厂
  2. 尝试在主线程中创建本地视频流
  3. 应用崩溃

当我尝试在下面的代码片段中创建 VideoSource 时,我遇到了崩溃。任何提示或建议表示赞赏。

- (RTCVideoTrack *)createLocalVideoTrack {
  RTCVideoTrack *localVideoTrack = nil;
  if (_peerConnection && self.localMediaStream) {
    [_peerConnection removeStream:self.localMediaStream];
    self.localMediaStream=nil;
    self.localVideoTrack=nil;
    self.localAudioTrack=nil;
  }
  NSString *cameraID = nil;
  AVCaptureDevicePosition devicePosition;
  if (self.captureDevice == kWebrtcMediaCaptureDeviceFrontCam) {
    devicePosition = AVCaptureDevicePositionFront;
  }
  else{
    devicePosition = AVCaptureDevicePositionBack;
  }
  for (AVCaptureDevice *captureDevice in
       [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]) {
    if (captureDevice.position == devicePosition) {
      //[self configureCameraForHighestFrameRate:captureDevice];
      cameraID = [captureDevice localizedName];
      break;
    }
  }
  NSAssert(cameraID, @"Unable to get the front camera id");
  RTCVideoCapturer *capturer = [RTCVideoCapturer capturerWithDeviceName:cameraID];
  RTCMediaConstraints *mediaConstraints = [self defaultMediaStreamConstraints];
  RTCVideoSource *videoSource = [_factory videoSourceWithCapturer:capturer
                                                      constraints:mediaConstraints];
  localVideoTrack = [_factory videoTrackWithID:@"ARDAMSv0" source:videoSource];
  return localVideoTrack;
}

And the crash log

* thread #1: tid = 0x33125c, 0x320b9b2c libsystem_kernel.dylib`__psynch_cvwait + 24, queue = 'com.apple.main-thread'
    frame #0: 0x320b9b2c libsystem_kernel.dylib`__psynch_cvwait + 24
    frame #1: 0x32137388 libsystem_pthread.dylib`_pthread_cond_wait + 520
    frame #2: 0x3213826c libsystem_pthread.dylib`pthread_cond_wait + 40
    frame #3: 0x00515230  `rtc::Event::Wait(int) + 160
  * frame #4: 0x003e4912  `webrtc::MethodCall2<webrtc::PeerConnectionFactoryInterface, rtc::scoped_refptr<webrtc::VideoSourceInterface>, cricket::VideoCapturer*, webrtc::MediaConstraintsInterface const*>::Marshal(rtc::Thread*) + 46
    frame #5: 0x003e419c  `webrtc::PeerConnectionFactoryProxy::CreateVideoSource(cricket::VideoCapturer*, webrtc::MediaConstraintsInterface const*) + 68
    frame #6: 0x00414470  `-[RTCPeerConnectionFactory videoSourceWithCapturer:constraints:] + 192
    frame #7: 0x0001fc4e  `-[WebrtcManager createLocalVideoTrack](self=0x01896620, _cmd=0x0083e058) + 1662 at WebrtcManager.m:360
    frame #8: 0x0001ca96  `__40-[WebrtcManager initializeWebrtcManager]_block_invoke(.block_descriptor=<unavailable>) + 46 at WebrtcManager.m:46
    frame #9: 0x01420172 libdispatch.dylib`_dispatch_call_block_and_release + 10
    frame #10: 0x0142015e libdispatch.dylib`_dispatch_client_callout + 22
    frame #11: 0x01423e44 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 1512
    frame #12: 0x234ad608 CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
    frame #13: 0x234abd08 CoreFoundation`__CFRunLoopRun + 1512
    frame #14: 0x233f8200 CoreFoundation`CFRunLoopRunSpecific + 476
    frame #15: 0x233f8012 CoreFoundation`CFRunLoopRunInMode + 106
    frame #16: 0x2ac91200 GraphicsServices`GSEventRunModal + 136
    frame #17: 0x26b9ca58 UIKit`UIApplicationMain + 1440
    frame #18: 0x00279f60  `main(argc=1, argv=0x00e37a78) + 132 at main.m:17

我的错!我试图在工作线程中创建 PeerConnectionFactory 和 LocalVideoTrack!当我将它们移动到主线程时,问题就解决了。我已经在 Apprtc-Swift with description on this tutorial

上传了 apprtc 版本

我遇到了同样的问题,但通过为摄像头和麦克风权限提示添加两个 Info-plist 值解决了这个问题:

Privacy - Microphone Usage Description

Privacy - Camera Usage Description

取值为你希望出现在权限提示中的字符串