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+Native.h" |
11 #import "RTCPeerConnectionFactory+Private.h" | 12 #import "RTCPeerConnectionFactory+Private.h" |
12 | 13 |
13 #import "NSString+StdString.h" | 14 #import "NSString+StdString.h" |
14 #import "RTCAVFoundationVideoSource+Private.h" | 15 #import "RTCAVFoundationVideoSource+Private.h" |
15 #import "RTCAudioSource+Private.h" | 16 #import "RTCAudioSource+Private.h" |
16 #import "RTCAudioTrack+Private.h" | 17 #import "RTCAudioTrack+Private.h" |
17 #import "RTCMediaConstraints+Private.h" | 18 #import "RTCMediaConstraints+Private.h" |
18 #import "RTCMediaStream+Private.h" | 19 #import "RTCMediaStream+Private.h" |
19 #import "RTCPeerConnection+Private.h" | 20 #import "RTCPeerConnection+Private.h" |
20 #import "RTCVideoSource+Private.h" | 21 #import "RTCVideoSource+Private.h" |
21 #import "RTCVideoTrack+Private.h" | 22 #import "RTCVideoTrack+Private.h" |
22 #import "WebRTC/RTCLogging.h" | 23 #import "WebRTC/RTCLogging.h" |
23 #import "WebRTC/RTCVideoCodecFactory.h" | 24 #import "WebRTC/RTCVideoCodecFactory.h" |
24 #ifndef HAVE_NO_MEDIA | 25 #ifndef HAVE_NO_MEDIA |
| 26 #include "VideoToolbox/objc_video_decoder_factory.h" |
| 27 #include "VideoToolbox/objc_video_encoder_factory.h" |
25 #import "WebRTC/RTCVideoCodecH264.h" | 28 #import "WebRTC/RTCVideoCodecH264.h" |
| 29 // The no-media version PeerConnectionFactory doesn't depend on these files, but
the gn check tool |
| 30 // is not smart enough to take the #ifdef into account. |
| 31 #include "webrtc/api/audio_codecs/builtin_audio_decoder_factory.h" // nogncheck |
| 32 #include "webrtc/api/audio_codecs/builtin_audio_encoder_factory.h" // nogncheck |
26 #endif | 33 #endif |
27 | 34 |
28 #include "Video/objcvideotracksource.h" | 35 #include "Video/objcvideotracksource.h" |
29 #include "VideoToolbox/objc_video_decoder_factory.h" | |
30 #include "VideoToolbox/objc_video_encoder_factory.h" | |
31 #include "webrtc/api/videosourceproxy.h" | 36 #include "webrtc/api/videosourceproxy.h" |
32 // Adding the nogncheck to disable the including header check. | 37 // Adding the nogncheck to disable the including header check. |
33 // The no-media version PeerConnectionFactory doesn't depend on media related | 38 // The no-media version PeerConnectionFactory doesn't depend on media related |
34 // C++ target. | 39 // C++ target. |
35 // TODO(zhihuang): Remove nogncheck once MediaEngineInterface is moved to C++ | 40 // TODO(zhihuang): Remove nogncheck once MediaEngineInterface is moved to C++ |
36 // API layer. | 41 // API layer. |
37 #include "webrtc/media/engine/webrtcmediaengine.h" // nogncheck | 42 #include "webrtc/media/engine/webrtcmediaengine.h" // nogncheck |
38 | 43 |
39 @implementation RTCPeerConnectionFactory { | 44 @implementation RTCPeerConnectionFactory { |
40 std::unique_ptr<rtc::Thread> _networkThread; | 45 std::unique_ptr<rtc::Thread> _networkThread; |
41 std::unique_ptr<rtc::Thread> _workerThread; | 46 std::unique_ptr<rtc::Thread> _workerThread; |
42 std::unique_ptr<rtc::Thread> _signalingThread; | 47 std::unique_ptr<rtc::Thread> _signalingThread; |
43 BOOL _hasStartedAecDump; | 48 BOOL _hasStartedAecDump; |
44 } | 49 } |
45 | 50 |
46 @synthesize nativeFactory = _nativeFactory; | 51 @synthesize nativeFactory = _nativeFactory; |
47 | 52 |
48 - (instancetype)init { | 53 - (instancetype)init { |
49 #ifdef HAVE_NO_MEDIA | 54 #ifdef HAVE_NO_MEDIA |
50 return [self initWithEncoderFactory:nil decoderFactory:nil]; | 55 return [self initWithNativeAudioEncoderFactory:nil |
| 56 nativeAudioDecoderFactory:nil |
| 57 nativeVideoEncoderFactory:nil |
| 58 nativeVideoDecoderFactory:nil]; |
51 #else | 59 #else |
52 return [self initWithEncoderFactory:[[RTCVideoEncoderFactoryH264 alloc] init] | 60 return [self initWithNativeAudioEncoderFactory:webrtc::CreateBuiltinAudioEncod
erFactory() |
53 decoderFactory:[[RTCVideoDecoderFactoryH264 alloc] init]]
; | 61 nativeAudioDecoderFactory:webrtc::CreateBuiltinAudioDecod
erFactory() |
| 62 nativeVideoEncoderFactory:new webrtc::ObjCVideoEncoderFac
tory( |
| 63 [[RTCVideoEncoderFactoryH26
4 alloc] init]) |
| 64 nativeVideoDecoderFactory:new webrtc::ObjCVideoDecoderFac
tory( |
| 65 [[RTCVideoDecoderFactoryH26
4 alloc] init])]; |
54 #endif | 66 #endif |
55 } | 67 } |
56 | 68 |
57 - (instancetype)initWithEncoderFactory:(nullable id<RTCVideoEncoderFactory>)enco
derFactory | 69 - (instancetype)initWithEncoderFactory:(nullable id<RTCVideoEncoderFactory>)enco
derFactory |
58 decoderFactory:(nullable id<RTCVideoDecoderFactory>)deco
derFactory { | 70 decoderFactory:(nullable id<RTCVideoDecoderFactory>)deco
derFactory { |
| 71 #ifdef HAVE_NO_MEDIA |
| 72 return [self initWithNativeAudioEncoderFactory:nil |
| 73 nativeAudioDecoderFactory:nil |
| 74 nativeVideoEncoderFactory:nil |
| 75 nativeVideoDecoderFactory:nil]; |
| 76 #else |
| 77 cricket::WebRtcVideoEncoderFactory *native_encoder_factory = |
| 78 encoderFactory ? new webrtc::ObjCVideoEncoderFactory(encoderFactory) : nul
lptr; |
| 79 cricket::WebRtcVideoDecoderFactory *native_decoder_factory = |
| 80 decoderFactory ? new webrtc::ObjCVideoDecoderFactory(decoderFactory) : nul
lptr; |
| 81 return [self initWithNativeAudioEncoderFactory:webrtc::CreateBuiltinAudioEncod
erFactory() |
| 82 nativeAudioDecoderFactory:webrtc::CreateBuiltinAudioDecod
erFactory() |
| 83 nativeVideoEncoderFactory:native_encoder_factory |
| 84 nativeVideoDecoderFactory:native_decoder_factory]; |
| 85 #endif |
| 86 } |
| 87 |
| 88 - (instancetype)initWithNativeAudioEncoderFactory: |
| 89 (rtc::scoped_refptr<webrtc::AudioEncoderFactory>)audioEncode
rFactory |
| 90 nativeAudioDecoderFactory: |
| 91 (rtc::scoped_refptr<webrtc::AudioDecoderFactory>)aud
ioDecoderFactory |
| 92 nativeVideoEncoderFactory: |
| 93 (nullable cricket::WebRtcVideoEncoderFactory *)video
EncoderFactory |
| 94 nativeVideoDecoderFactory: |
| 95 (nullable cricket::WebRtcVideoDecoderFactory *)video
DecoderFactory { |
59 if (self = [super init]) { | 96 if (self = [super init]) { |
60 _networkThread = rtc::Thread::CreateWithSocketServer(); | 97 _networkThread = rtc::Thread::CreateWithSocketServer(); |
61 BOOL result = _networkThread->Start(); | 98 BOOL result = _networkThread->Start(); |
62 NSAssert(result, @"Failed to start network thread."); | 99 NSAssert(result, @"Failed to start network thread."); |
63 | 100 |
64 _workerThread = rtc::Thread::Create(); | 101 _workerThread = rtc::Thread::Create(); |
65 result = _workerThread->Start(); | 102 result = _workerThread->Start(); |
66 NSAssert(result, @"Failed to start worker thread."); | 103 NSAssert(result, @"Failed to start worker thread."); |
67 | 104 |
68 _signalingThread = rtc::Thread::Create(); | 105 _signalingThread = rtc::Thread::Create(); |
69 result = _signalingThread->Start(); | 106 result = _signalingThread->Start(); |
70 NSAssert(result, @"Failed to start signaling thread."); | 107 NSAssert(result, @"Failed to start signaling thread."); |
71 #ifdef HAVE_NO_MEDIA | 108 #ifdef HAVE_NO_MEDIA |
72 _nativeFactory = webrtc::CreateModularPeerConnectionFactory( | 109 _nativeFactory = webrtc::CreateModularPeerConnectionFactory( |
73 _networkThread.get(), | 110 _networkThread.get(), |
74 _workerThread.get(), | 111 _workerThread.get(), |
75 _signalingThread.get(), | 112 _signalingThread.get(), |
76 nullptr, // default_adm | 113 nullptr, // default_adm |
77 nullptr, // audio_encoder_factory | 114 nullptr, // audio_encoder_factory |
78 nullptr, // audio_decoder_factory | 115 nullptr, // audio_decoder_factory |
79 nullptr, // video_encoder_factory | 116 nullptr, // video_encoder_factory |
80 nullptr, // video_decoder_factory | 117 nullptr, // video_decoder_factory |
81 nullptr, // audio_mixer | 118 nullptr, // audio_mixer |
82 std::unique_ptr<cricket::MediaEngineInterface>(), | 119 std::unique_ptr<cricket::MediaEngineInterface>(), |
83 std::unique_ptr<webrtc::CallFactoryInterface>(), | 120 std::unique_ptr<webrtc::CallFactoryInterface>(), |
84 std::unique_ptr<webrtc::RtcEventLogFactoryInterface>()); | 121 std::unique_ptr<webrtc::RtcEventLogFactoryInterface>()); |
85 #else | 122 #else |
86 cricket::WebRtcVideoEncoderFactory *platform_encoder_factory = nullptr; | |
87 cricket::WebRtcVideoDecoderFactory *platform_decoder_factory = nullptr; | |
88 if (encoderFactory) { | |
89 platform_encoder_factory = new webrtc::ObjCVideoEncoderFactory(encoderFact
ory); | |
90 } | |
91 if (decoderFactory) { | |
92 platform_decoder_factory = new webrtc::ObjCVideoDecoderFactory(decoderFact
ory); | |
93 } | |
94 | |
95 // Ownership of encoder/decoder factories is passed on to the | 123 // Ownership of encoder/decoder factories is passed on to the |
96 // peerconnectionfactory, that handles deleting them. | 124 // peerconnectionfactory, that handles deleting them. |
97 _nativeFactory = webrtc::CreatePeerConnectionFactory(_networkThread.get(), | 125 _nativeFactory = webrtc::CreatePeerConnectionFactory(_networkThread.get(), |
98 _workerThread.get(), | 126 _workerThread.get(), |
99 _signalingThread.get(), | 127 _signalingThread.get(), |
100 nullptr, | 128 nullptr, // audio devi
ce module |
101 platform_encoder_factor
y, | 129 audioEncoderFactory, |
102 platform_decoder_factor
y); | 130 audioDecoderFactory, |
| 131 videoEncoderFactory, |
| 132 videoDecoderFactory); |
103 #endif | 133 #endif |
104 NSAssert(_nativeFactory, @"Failed to initialize PeerConnectionFactory!"); | 134 NSAssert(_nativeFactory, @"Failed to initialize PeerConnectionFactory!"); |
105 } | 135 } |
106 return self; | 136 return self; |
107 } | 137 } |
108 | 138 |
109 - (RTCAudioSource *)audioSourceWithConstraints:(nullable RTCMediaConstraints *)c
onstraints { | 139 - (RTCAudioSource *)audioSourceWithConstraints:(nullable RTCMediaConstraints *)c
onstraints { |
110 std::unique_ptr<webrtc::MediaConstraints> nativeConstraints; | 140 std::unique_ptr<webrtc::MediaConstraints> nativeConstraints; |
111 if (constraints) { | 141 if (constraints) { |
112 nativeConstraints = constraints.nativeConstraints; | 142 nativeConstraints = constraints.nativeConstraints; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 _hasStartedAecDump = _nativeFactory->StartAecDump(fd, maxSizeInBytes); | 217 _hasStartedAecDump = _nativeFactory->StartAecDump(fd, maxSizeInBytes); |
188 return _hasStartedAecDump; | 218 return _hasStartedAecDump; |
189 } | 219 } |
190 | 220 |
191 - (void)stopAecDump { | 221 - (void)stopAecDump { |
192 _nativeFactory->StopAecDump(); | 222 _nativeFactory->StopAecDump(); |
193 _hasStartedAecDump = NO; | 223 _hasStartedAecDump = NO; |
194 } | 224 } |
195 | 225 |
196 @end | 226 @end |
OLD | NEW |