| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #import "RTCPeerConnectionFactory+Private.h" | 11 #import "RTCPeerConnectionFactory+Private.h" |
| 12 | 12 |
| 13 #import "NSString+StdString.h" | 13 #import "NSString+StdString.h" |
| 14 #import "RTCAudioSource+Private.h" | 14 #import "RTCAudioSource+Private.h" |
| 15 #import "RTCAudioTrack+Private.h" | 15 #import "RTCAudioTrack+Private.h" |
| 16 #import "RTCMediaConstraints+Private.h" | 16 #import "RTCMediaConstraints+Private.h" |
| 17 #import "RTCMediaStream+Private.h" | 17 #import "RTCMediaStream+Private.h" |
| 18 #import "RTCPeerConnection+Private.h" | 18 #import "RTCPeerConnection+Private.h" |
| 19 #import "RTCVideoSource+Private.h" | 19 #import "RTCVideoSource+Private.h" |
| 20 #import "RTCVideoTrack+Private.h" | 20 #import "RTCVideoTrack+Private.h" |
| 21 #import "RTCAVFoundationVideoSource+Private.h" | 21 #import "RTCAVFoundationVideoSource+Private.h" |
| 22 #import "WebRTC/RTCLogging.h" | 22 #import "WebRTC/RTCLogging.h" |
| 23 | 23 |
| 24 #include "Video/objcvideotracksource.h" | 24 #include "Video/objcvideotracksource.h" |
| 25 #include "VideoToolbox/videocodecfactory.h" | 25 #include "VideoToolbox/videocodecfactory.h" |
| 26 #include "webrtc/api/videosourceproxy.h" | 26 #include "webrtc/api/videosourceproxy.h" |
| 27 // Adding the nogncheck to disable the including header check. |
| 28 // The no-media version PeerConnectionFactory doesn't depend on media related |
| 29 // C++ target. |
| 30 // TODO(zhihuang): Remove nogncheck once MediaEngineInterface is moved to C++ |
| 31 // API layer. |
| 32 #include "webrtc/media/engine/webrtcmediaengine.h" // nogncheck |
| 27 | 33 |
| 28 @implementation RTCPeerConnectionFactory { | 34 @implementation RTCPeerConnectionFactory { |
| 29 std::unique_ptr<rtc::Thread> _networkThread; | 35 std::unique_ptr<rtc::Thread> _networkThread; |
| 30 std::unique_ptr<rtc::Thread> _workerThread; | 36 std::unique_ptr<rtc::Thread> _workerThread; |
| 31 std::unique_ptr<rtc::Thread> _signalingThread; | 37 std::unique_ptr<rtc::Thread> _signalingThread; |
| 32 BOOL _hasStartedAecDump; | 38 BOOL _hasStartedAecDump; |
| 33 } | 39 } |
| 34 | 40 |
| 35 @synthesize nativeFactory = _nativeFactory; | 41 @synthesize nativeFactory = _nativeFactory; |
| 36 | 42 |
| 37 - (instancetype)init { | 43 - (instancetype)init { |
| 38 if ((self = [super init])) { | 44 if ((self = [super init])) { |
| 39 _networkThread = rtc::Thread::CreateWithSocketServer(); | 45 _networkThread = rtc::Thread::CreateWithSocketServer(); |
| 40 BOOL result = _networkThread->Start(); | 46 BOOL result = _networkThread->Start(); |
| 41 NSAssert(result, @"Failed to start network thread."); | 47 NSAssert(result, @"Failed to start network thread."); |
| 42 | 48 |
| 43 _workerThread = rtc::Thread::Create(); | 49 _workerThread = rtc::Thread::Create(); |
| 44 result = _workerThread->Start(); | 50 result = _workerThread->Start(); |
| 45 NSAssert(result, @"Failed to start worker thread."); | 51 NSAssert(result, @"Failed to start worker thread."); |
| 46 | 52 |
| 47 _signalingThread = rtc::Thread::Create(); | 53 _signalingThread = rtc::Thread::Create(); |
| 48 result = _signalingThread->Start(); | 54 result = _signalingThread->Start(); |
| 49 NSAssert(result, @"Failed to start signaling thread."); | 55 NSAssert(result, @"Failed to start signaling thread."); |
| 50 | 56 #ifdef HAVE_NO_MEDIA |
| 57 _nativeFactory = webrtc::CreateModularPeerConnectionFactory( |
| 58 _networkThread.get(), |
| 59 _workerThread.get(), |
| 60 _signalingThread.get(), |
| 61 nullptr, // default_adm |
| 62 nullptr, // audio_encoder_factory |
| 63 nullptr, // audio_decoder_factory |
| 64 nullptr, // video_encoder_factory |
| 65 nullptr, // video_decoder_factory |
| 66 nullptr, // audio_mixer |
| 67 std::unique_ptr<cricket::MediaEngineInterface>(), |
| 68 std::unique_ptr<webrtc::CallFactoryInterface>(), |
| 69 std::unique_ptr<webrtc::RtcEventLogFactoryInterface>()); |
| 70 #else |
| 51 const auto encoder_factory = new webrtc::VideoToolboxVideoEncoderFactory(); | 71 const auto encoder_factory = new webrtc::VideoToolboxVideoEncoderFactory(); |
| 52 const auto decoder_factory = new webrtc::VideoToolboxVideoDecoderFactory(); | 72 const auto decoder_factory = new webrtc::VideoToolboxVideoDecoderFactory(); |
| 53 | 73 |
| 54 // Ownership of encoder/decoder factories is passed on to the | 74 // Ownership of encoder/decoder factories is passed on to the |
| 55 // peerconnectionfactory, that handles deleting them. | 75 // peerconnectionfactory, that handles deleting them. |
| 56 _nativeFactory = webrtc::CreatePeerConnectionFactory( | 76 _nativeFactory = webrtc::CreatePeerConnectionFactory( |
| 57 _networkThread.get(), _workerThread.get(), _signalingThread.get(), | 77 _networkThread.get(), _workerThread.get(), _signalingThread.get(), |
| 58 nullptr, encoder_factory, decoder_factory); | 78 nullptr, encoder_factory, decoder_factory); |
| 79 #endif |
| 59 NSAssert(_nativeFactory, @"Failed to initialize PeerConnectionFactory!"); | 80 NSAssert(_nativeFactory, @"Failed to initialize PeerConnectionFactory!"); |
| 60 } | 81 } |
| 61 return self; | 82 return self; |
| 62 } | 83 } |
| 63 | 84 |
| 64 - (RTCAudioSource *)audioSourceWithConstraints:(nullable RTCMediaConstraints *)c
onstraints { | 85 - (RTCAudioSource *)audioSourceWithConstraints:(nullable RTCMediaConstraints *)c
onstraints { |
| 65 std::unique_ptr<webrtc::MediaConstraints> nativeConstraints; | 86 std::unique_ptr<webrtc::MediaConstraints> nativeConstraints; |
| 66 if (constraints) { | 87 if (constraints) { |
| 67 nativeConstraints = constraints.nativeConstraints; | 88 nativeConstraints = constraints.nativeConstraints; |
| 68 } | 89 } |
| 69 rtc::scoped_refptr<webrtc::AudioSourceInterface> source = | 90 rtc::scoped_refptr<webrtc::AudioSourceInterface> source = |
| 70 _nativeFactory->CreateAudioSource(nativeConstraints.get()); | 91 _nativeFactory->CreateAudioSource(nativeConstraints.get()); |
| 71 return [[RTCAudioSource alloc] initWithNativeAudioSource:source]; | 92 return [[RTCAudioSource alloc] initWithNativeAudioSource:source]; |
| 72 } | 93 } |
| 73 | 94 |
| 74 - (RTCAudioTrack *)audioTrackWithTrackId:(NSString *)trackId { | 95 - (RTCAudioTrack *)audioTrackWithTrackId:(NSString *)trackId { |
| 75 RTCAudioSource *audioSource = [self audioSourceWithConstraints:nil]; | 96 RTCAudioSource *audioSource = [self audioSourceWithConstraints:nil]; |
| 76 return [self audioTrackWithSource:audioSource trackId:trackId]; | 97 return [self audioTrackWithSource:audioSource trackId:trackId]; |
| 77 } | 98 } |
| 78 | 99 |
| 79 - (RTCAudioTrack *)audioTrackWithSource:(RTCAudioSource *)source | 100 - (RTCAudioTrack *)audioTrackWithSource:(RTCAudioSource *)source |
| 80 trackId:(NSString *)trackId { | 101 trackId:(NSString *)trackId { |
| 81 return [[RTCAudioTrack alloc] initWithFactory:self | 102 return [[RTCAudioTrack alloc] initWithFactory:self |
| 82 source:source | 103 source:source |
| 83 trackId:trackId]; | 104 trackId:trackId]; |
| 84 } | 105 } |
| 85 | 106 |
| 86 - (RTCAVFoundationVideoSource *)avFoundationVideoSourceWithConstraints: | 107 - (RTCAVFoundationVideoSource *)avFoundationVideoSourceWithConstraints: |
| 87 (nullable RTCMediaConstraints *)constraints { | 108 (nullable RTCMediaConstraints *)constraints { |
| 88 return [[RTCAVFoundationVideoSource alloc] initWithFactory:self | 109 #ifdef HAVE_NO_MEDIA |
| 89 constraints:constraints]; | 110 return nil; |
| 111 #else |
| 112 return [[RTCAVFoundationVideoSource alloc] initWithFactory:self constraints:co
nstraints]; |
| 113 #endif |
| 90 } | 114 } |
| 91 | 115 |
| 92 - (RTCVideoSource *)videoSource { | 116 - (RTCVideoSource *)videoSource { |
| 93 rtc::scoped_refptr<webrtc::ObjcVideoTrackSource> objcVideoTrackSource( | 117 rtc::scoped_refptr<webrtc::ObjcVideoTrackSource> objcVideoTrackSource( |
| 94 new rtc::RefCountedObject<webrtc::ObjcVideoTrackSource>()); | 118 new rtc::RefCountedObject<webrtc::ObjcVideoTrackSource>()); |
| 95 return [[RTCVideoSource alloc] | 119 return [[RTCVideoSource alloc] |
| 96 initWithNativeVideoSource:webrtc::VideoTrackSourceProxy::Create(_signaling
Thread.get(), | 120 initWithNativeVideoSource:webrtc::VideoTrackSourceProxy::Create(_signaling
Thread.get(), |
| 97 _workerThr
ead.get(), | 121 _workerThr
ead.get(), |
| 98 objcVideoT
rackSource)]; | 122 objcVideoT
rackSource)]; |
| 99 } | 123 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 _hasStartedAecDump = _nativeFactory->StartAecDump(fd, maxSizeInBytes); | 163 _hasStartedAecDump = _nativeFactory->StartAecDump(fd, maxSizeInBytes); |
| 140 return _hasStartedAecDump; | 164 return _hasStartedAecDump; |
| 141 } | 165 } |
| 142 | 166 |
| 143 - (void)stopAecDump { | 167 - (void)stopAecDump { |
| 144 _nativeFactory->StopAecDump(); | 168 _nativeFactory->StopAecDump(); |
| 145 _hasStartedAecDump = NO; | 169 _hasStartedAecDump = NO; |
| 146 } | 170 } |
| 147 | 171 |
| 148 @end | 172 @end |
| OLD | NEW |