OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 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 |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #import "RTCPeerConnectionFactory+Private.h" |
| 12 |
| 13 #import "NSString+StdString.h" |
| 14 #import "RTCAVFoundationVideoSource+Private.h" |
| 15 #import "RTCAudioSource+Private.h" |
| 16 #import "RTCAudioTrack+Private.h" |
| 17 #import "RTCMediaConstraints+Private.h" |
| 18 #import "RTCMediaStream+Private.h" |
| 19 #import "RTCPeerConnection+Private.h" |
| 20 #import "RTCVideoSource+Private.h" |
| 21 #import "RTCVideoTrack+Private.h" |
| 22 #import "WebRTC/RTCLogging.h" |
| 23 |
| 24 #include "objcvideotracksource.h" |
| 25 #include "videotoolboxvideocodecfactory.h" |
| 26 |
| 27 @implementation RTCPeerConnectionFactory { |
| 28 std::unique_ptr<rtc::Thread> _networkThread; |
| 29 std::unique_ptr<rtc::Thread> _workerThread; |
| 30 std::unique_ptr<rtc::Thread> _signalingThread; |
| 31 BOOL _hasStartedAecDump; |
| 32 } |
| 33 |
| 34 @synthesize nativeFactory = _nativeFactory; |
| 35 |
| 36 - (instancetype)init { |
| 37 if ((self = [super init])) { |
| 38 _networkThread = rtc::Thread::CreateWithSocketServer(); |
| 39 BOOL result = _networkThread->Start(); |
| 40 NSAssert(result, @"Failed to start network thread."); |
| 41 |
| 42 _workerThread = rtc::Thread::Create(); |
| 43 result = _workerThread->Start(); |
| 44 NSAssert(result, @"Failed to start worker thread."); |
| 45 |
| 46 _signalingThread = rtc::Thread::Create(); |
| 47 result = _signalingThread->Start(); |
| 48 NSAssert(result, @"Failed to start signaling thread."); |
| 49 |
| 50 const auto encoder_factory = new webrtc::VideoToolboxVideoEncoderFactory(); |
| 51 const auto decoder_factory = new webrtc::VideoToolboxVideoDecoderFactory(); |
| 52 |
| 53 // Ownership of encoder/decoder factories is passed on to the |
| 54 // peerconnectionfactory, that handles deleting them. |
| 55 _nativeFactory = webrtc::CreatePeerConnectionFactory( |
| 56 _networkThread.get(), _workerThread.get(), _signalingThread.get(), |
| 57 nullptr, encoder_factory, decoder_factory); |
| 58 NSAssert(_nativeFactory, @"Failed to initialize PeerConnectionFactory!"); |
| 59 } |
| 60 return self; |
| 61 } |
| 62 |
| 63 - (RTCAudioSource *)audioSourceWithConstraints:(nullable RTCMediaConstraints *)c
onstraints { |
| 64 std::unique_ptr<webrtc::MediaConstraints> nativeConstraints; |
| 65 if (constraints) { |
| 66 nativeConstraints = constraints.nativeConstraints; |
| 67 } |
| 68 rtc::scoped_refptr<webrtc::AudioSourceInterface> source = |
| 69 _nativeFactory->CreateAudioSource(nativeConstraints.get()); |
| 70 return [[RTCAudioSource alloc] initWithNativeAudioSource:source]; |
| 71 } |
| 72 |
| 73 - (RTCAudioTrack *)audioTrackWithTrackId:(NSString *)trackId { |
| 74 RTCAudioSource *audioSource = [self audioSourceWithConstraints:nil]; |
| 75 return [self audioTrackWithSource:audioSource trackId:trackId]; |
| 76 } |
| 77 |
| 78 - (RTCAudioTrack *)audioTrackWithSource:(RTCAudioSource *)source |
| 79 trackId:(NSString *)trackId { |
| 80 return [[RTCAudioTrack alloc] initWithFactory:self |
| 81 source:source |
| 82 trackId:trackId]; |
| 83 } |
| 84 |
| 85 - (RTCAVFoundationVideoSource *)avFoundationVideoSourceWithConstraints: |
| 86 (nullable RTCMediaConstraints *)constraints { |
| 87 return [[RTCAVFoundationVideoSource alloc] initWithFactory:self |
| 88 constraints:constraints]; |
| 89 } |
| 90 |
| 91 - (RTCVideoSource *)videoSource { |
| 92 rtc::scoped_refptr<webrtc::ObjcVideoTrackSource> objcVideoTrackSource( |
| 93 new rtc::RefCountedObject<webrtc::ObjcVideoTrackSource>()); |
| 94 return [[RTCVideoSource alloc] initWithNativeVideoSource:objcVideoTrackSource]
; |
| 95 } |
| 96 |
| 97 - (RTCVideoTrack *)videoTrackWithSource:(RTCVideoSource *)source |
| 98 trackId:(NSString *)trackId { |
| 99 return [[RTCVideoTrack alloc] initWithFactory:self |
| 100 source:source |
| 101 trackId:trackId]; |
| 102 } |
| 103 |
| 104 - (RTCMediaStream *)mediaStreamWithStreamId:(NSString *)streamId { |
| 105 return [[RTCMediaStream alloc] initWithFactory:self |
| 106 streamId:streamId]; |
| 107 } |
| 108 |
| 109 - (RTCPeerConnection *)peerConnectionWithConfiguration: |
| 110 (RTCConfiguration *)configuration |
| 111 constraints: |
| 112 (RTCMediaConstraints *)constraints |
| 113 delegate: |
| 114 (nullable id<RTCPeerConnectionDelegate>)delegate { |
| 115 return [[RTCPeerConnection alloc] initWithFactory:self |
| 116 configuration:configuration |
| 117 constraints:constraints |
| 118 delegate:delegate]; |
| 119 } |
| 120 |
| 121 - (BOOL)startAecDumpWithFilePath:(NSString *)filePath |
| 122 maxSizeInBytes:(int64_t)maxSizeInBytes { |
| 123 RTC_DCHECK(filePath.length); |
| 124 RTC_DCHECK_GT(maxSizeInBytes, 0); |
| 125 |
| 126 if (_hasStartedAecDump) { |
| 127 RTCLogError(@"Aec dump already started."); |
| 128 return NO; |
| 129 } |
| 130 int fd = open(filePath.UTF8String, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_I
WUSR); |
| 131 if (fd < 0) { |
| 132 RTCLogError(@"Error opening file: %@. Error: %d", filePath, errno); |
| 133 return NO; |
| 134 } |
| 135 _hasStartedAecDump = _nativeFactory->StartAecDump(fd, maxSizeInBytes); |
| 136 return _hasStartedAecDump; |
| 137 } |
| 138 |
| 139 - (void)stopAecDump { |
| 140 _nativeFactory->StopAecDump(); |
| 141 _hasStartedAecDump = NO; |
| 142 } |
| 143 |
| 144 @end |
OLD | NEW |