blob: 5fa2d464ff10d0b73fa2b42e4c22f002a70907de [file] [log] [blame]
Jon Hjelleca91e382016-01-21 15:36:47 -08001/*
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
tkchin9eeb6242016-04-27 01:54:20 -070011#import "RTCAudioTrack+Private.h"
Jon Hjelleca91e382016-01-21 15:36:47 -080012
tkchin9eeb6242016-04-27 01:54:20 -070013#import "NSString+StdString.h"
tkchind4bfbfc2016-08-30 11:56:05 -070014#import "RTCAudioSource+Private.h"
tkchin9eeb6242016-04-27 01:54:20 -070015#import "RTCMediaStreamTrack+Private.h"
16#import "RTCPeerConnectionFactory+Private.h"
Jon Hjelleca91e382016-01-21 15:36:47 -080017
tkchind4bfbfc2016-08-30 11:56:05 -070018#include "webrtc/base/checks.h"
19
Jon Hjelleca91e382016-01-21 15:36:47 -080020@implementation RTCAudioTrack
21
tkchind4bfbfc2016-08-30 11:56:05 -070022@synthesize source = _source;
23
Jon Hjelleca91e382016-01-21 15:36:47 -080024- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
tkchind4bfbfc2016-08-30 11:56:05 -070025 source:(RTCAudioSource *)source
Jon Hjelleca91e382016-01-21 15:36:47 -080026 trackId:(NSString *)trackId {
tkchind4bfbfc2016-08-30 11:56:05 -070027 RTC_DCHECK(factory);
28 RTC_DCHECK(source);
29 RTC_DCHECK(trackId.length);
30
Jon Hjelleca91e382016-01-21 15:36:47 -080031 std::string nativeId = [NSString stdStringForString:trackId];
32 rtc::scoped_refptr<webrtc::AudioTrackInterface> track =
tkchind4bfbfc2016-08-30 11:56:05 -070033 factory.nativeFactory->CreateAudioTrack(nativeId, source.nativeAudioSource);
34 if ([self initWithNativeTrack:track type:RTCMediaStreamTrackTypeAudio]) {
35 _source = source;
36 }
37 return self;
Jon Hjelleca91e382016-01-21 15:36:47 -080038}
39
40- (instancetype)initWithNativeTrack:
41 (rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack
42 type:(RTCMediaStreamTrackType)type {
43 NSParameterAssert(nativeTrack);
44 NSParameterAssert(type == RTCMediaStreamTrackTypeAudio);
45 return [super initWithNativeTrack:nativeTrack type:type];
46}
47
tkchind4bfbfc2016-08-30 11:56:05 -070048
49- (RTCAudioSource *)source {
50 if (!_source) {
51 rtc::scoped_refptr<webrtc::AudioSourceInterface> source =
52 self.nativeAudioTrack->GetSource();
53 if (source) {
54 _source = [[RTCAudioSource alloc] initWithNativeAudioSource:source.get()];
55 }
56 }
57 return _source;
58}
59
Jon Hjelleca91e382016-01-21 15:36:47 -080060#pragma mark - Private
61
62- (rtc::scoped_refptr<webrtc::AudioTrackInterface>)nativeAudioTrack {
63 return static_cast<webrtc::AudioTrackInterface *>(self.nativeTrack.get());
64}
65
66@end