blob: 73ec98f2aabec1d8f4bf0979dd2cdbcf21417aad [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
tkchind4bfbfc2016-08-30 11:56:05 -070013#import "RTCAudioSource+Private.h"
tkchin9eeb6242016-04-27 01:54:20 -070014#import "RTCMediaStreamTrack+Private.h"
15#import "RTCPeerConnectionFactory+Private.h"
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020016#import "helpers/NSString+StdString.h"
Jon Hjelleca91e382016-01-21 15:36:47 -080017
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "rtc_base/checks.h"
tkchind4bfbfc2016-08-30 11:56:05 -070019
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020020@implementation RTC_OBJC_TYPE (RTCAudioTrack)
Jon Hjelleca91e382016-01-21 15:36:47 -080021
tkchind4bfbfc2016-08-30 11:56:05 -070022@synthesize source = _source;
23
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020024- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
25 source:(RTC_OBJC_TYPE(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);
Yura Yaroshevich01cee072018-07-11 15:35:40 +030034 if (self = [self initWithFactory:factory nativeTrack:track type:RTCMediaStreamTrackTypeAudio]) {
tkchind4bfbfc2016-08-30 11:56:05 -070035 _source = source;
36 }
37 return self;
Jon Hjelleca91e382016-01-21 15:36:47 -080038}
39
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020040- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
Yura Yaroshevich01cee072018-07-11 15:35:40 +030041 nativeTrack:(rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack
42 type:(RTCMediaStreamTrackType)type {
43 NSParameterAssert(factory);
Jon Hjelleca91e382016-01-21 15:36:47 -080044 NSParameterAssert(nativeTrack);
45 NSParameterAssert(type == RTCMediaStreamTrackTypeAudio);
Yura Yaroshevich01cee072018-07-11 15:35:40 +030046 return [super initWithFactory:factory nativeTrack:nativeTrack type:type];
Jon Hjelleca91e382016-01-21 15:36:47 -080047}
48
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020049- (RTC_OBJC_TYPE(RTCAudioSource) *)source {
tkchind4bfbfc2016-08-30 11:56:05 -070050 if (!_source) {
Niels Möllerac0d1832022-01-17 15:26:54 +010051 rtc::scoped_refptr<webrtc::AudioSourceInterface> source(self.nativeAudioTrack->GetSource());
tkchind4bfbfc2016-08-30 11:56:05 -070052 if (source) {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020053 _source = [[RTC_OBJC_TYPE(RTCAudioSource) alloc] initWithFactory:self.factory
Niels Möllerac0d1832022-01-17 15:26:54 +010054 nativeAudioSource:source];
tkchind4bfbfc2016-08-30 11:56:05 -070055 }
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 {
Niels Möllerac0d1832022-01-17 15:26:54 +010063 return rtc::scoped_refptr<webrtc::AudioTrackInterface>(
64 static_cast<webrtc::AudioTrackInterface *>(self.nativeTrack.get()));
Jon Hjelleca91e382016-01-21 15:36:47 -080065}
66
67@end