Jon Hjelle | ca91e38 | 2016-01-21 15:36:47 -0800 | [diff] [blame] | 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 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 11 | #import "RTCAudioTrack+Private.h" |
Jon Hjelle | ca91e38 | 2016-01-21 15:36:47 -0800 | [diff] [blame] | 12 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 13 | #import "NSString+StdString.h" |
tkchin | d4bfbfc | 2016-08-30 11:56:05 -0700 | [diff] [blame] | 14 | #import "RTCAudioSource+Private.h" |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 15 | #import "RTCMediaStreamTrack+Private.h" |
| 16 | #import "RTCPeerConnectionFactory+Private.h" |
Jon Hjelle | ca91e38 | 2016-01-21 15:36:47 -0800 | [diff] [blame] | 17 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "rtc_base/checks.h" |
tkchin | d4bfbfc | 2016-08-30 11:56:05 -0700 | [diff] [blame] | 19 | |
Jon Hjelle | ca91e38 | 2016-01-21 15:36:47 -0800 | [diff] [blame] | 20 | @implementation RTCAudioTrack |
| 21 | |
tkchin | d4bfbfc | 2016-08-30 11:56:05 -0700 | [diff] [blame] | 22 | @synthesize source = _source; |
| 23 | |
Jon Hjelle | ca91e38 | 2016-01-21 15:36:47 -0800 | [diff] [blame] | 24 | - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory |
tkchin | d4bfbfc | 2016-08-30 11:56:05 -0700 | [diff] [blame] | 25 | source:(RTCAudioSource *)source |
Jon Hjelle | ca91e38 | 2016-01-21 15:36:47 -0800 | [diff] [blame] | 26 | trackId:(NSString *)trackId { |
tkchin | d4bfbfc | 2016-08-30 11:56:05 -0700 | [diff] [blame] | 27 | RTC_DCHECK(factory); |
| 28 | RTC_DCHECK(source); |
| 29 | RTC_DCHECK(trackId.length); |
| 30 | |
Jon Hjelle | ca91e38 | 2016-01-21 15:36:47 -0800 | [diff] [blame] | 31 | std::string nativeId = [NSString stdStringForString:trackId]; |
| 32 | rtc::scoped_refptr<webrtc::AudioTrackInterface> track = |
tkchin | d4bfbfc | 2016-08-30 11:56:05 -0700 | [diff] [blame] | 33 | factory.nativeFactory->CreateAudioTrack(nativeId, source.nativeAudioSource); |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame^] | 34 | if (self = [self initWithFactory:factory nativeTrack:track type:RTCMediaStreamTrackTypeAudio]) { |
tkchin | d4bfbfc | 2016-08-30 11:56:05 -0700 | [diff] [blame] | 35 | _source = source; |
| 36 | } |
| 37 | return self; |
Jon Hjelle | ca91e38 | 2016-01-21 15:36:47 -0800 | [diff] [blame] | 38 | } |
| 39 | |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame^] | 40 | - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory |
| 41 | nativeTrack:(rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack |
| 42 | type:(RTCMediaStreamTrackType)type { |
| 43 | NSParameterAssert(factory); |
Jon Hjelle | ca91e38 | 2016-01-21 15:36:47 -0800 | [diff] [blame] | 44 | NSParameterAssert(nativeTrack); |
| 45 | NSParameterAssert(type == RTCMediaStreamTrackTypeAudio); |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame^] | 46 | return [super initWithFactory:factory nativeTrack:nativeTrack type:type]; |
Jon Hjelle | ca91e38 | 2016-01-21 15:36:47 -0800 | [diff] [blame] | 47 | } |
| 48 | |
tkchin | d4bfbfc | 2016-08-30 11:56:05 -0700 | [diff] [blame] | 49 | |
| 50 | - (RTCAudioSource *)source { |
| 51 | if (!_source) { |
| 52 | rtc::scoped_refptr<webrtc::AudioSourceInterface> source = |
| 53 | self.nativeAudioTrack->GetSource(); |
| 54 | if (source) { |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame^] | 55 | _source = |
| 56 | [[RTCAudioSource alloc] initWithFactory:self.factory nativeAudioSource:source.get()]; |
tkchin | d4bfbfc | 2016-08-30 11:56:05 -0700 | [diff] [blame] | 57 | } |
| 58 | } |
| 59 | return _source; |
| 60 | } |
| 61 | |
Jon Hjelle | ca91e38 | 2016-01-21 15:36:47 -0800 | [diff] [blame] | 62 | #pragma mark - Private |
| 63 | |
| 64 | - (rtc::scoped_refptr<webrtc::AudioTrackInterface>)nativeAudioTrack { |
| 65 | return static_cast<webrtc::AudioTrackInterface *>(self.nativeTrack.get()); |
| 66 | } |
| 67 | |
| 68 | @end |