2016-01-21 15:36:47 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-04-27 01:54:20 -07:00
|
|
|
#import "RTCAudioTrack+Private.h"
|
2016-01-21 15:36:47 -08:00
|
|
|
|
2016-08-30 11:56:05 -07:00
|
|
|
#import "RTCAudioSource+Private.h"
|
2016-04-27 01:54:20 -07:00
|
|
|
#import "RTCMediaStreamTrack+Private.h"
|
|
|
|
|
#import "RTCPeerConnectionFactory+Private.h"
|
2018-08-30 09:30:29 +02:00
|
|
|
#import "helpers/NSString+StdString.h"
|
2016-01-21 15:36:47 -08:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/checks.h"
|
2016-08-30 11:56:05 -07:00
|
|
|
|
2016-01-21 15:36:47 -08:00
|
|
|
@implementation RTCAudioTrack
|
|
|
|
|
|
2016-08-30 11:56:05 -07:00
|
|
|
@synthesize source = _source;
|
|
|
|
|
|
2016-01-21 15:36:47 -08:00
|
|
|
- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
|
2016-08-30 11:56:05 -07:00
|
|
|
source:(RTCAudioSource *)source
|
2016-01-21 15:36:47 -08:00
|
|
|
trackId:(NSString *)trackId {
|
2016-08-30 11:56:05 -07:00
|
|
|
RTC_DCHECK(factory);
|
|
|
|
|
RTC_DCHECK(source);
|
|
|
|
|
RTC_DCHECK(trackId.length);
|
|
|
|
|
|
2016-01-21 15:36:47 -08:00
|
|
|
std::string nativeId = [NSString stdStringForString:trackId];
|
|
|
|
|
rtc::scoped_refptr<webrtc::AudioTrackInterface> track =
|
2016-08-30 11:56:05 -07:00
|
|
|
factory.nativeFactory->CreateAudioTrack(nativeId, source.nativeAudioSource);
|
2018-07-11 15:35:40 +03:00
|
|
|
if (self = [self initWithFactory:factory nativeTrack:track type:RTCMediaStreamTrackTypeAudio]) {
|
2016-08-30 11:56:05 -07:00
|
|
|
_source = source;
|
|
|
|
|
}
|
|
|
|
|
return self;
|
2016-01-21 15:36:47 -08:00
|
|
|
}
|
|
|
|
|
|
2018-07-11 15:35:40 +03:00
|
|
|
- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
|
|
|
|
|
nativeTrack:(rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>)nativeTrack
|
|
|
|
|
type:(RTCMediaStreamTrackType)type {
|
|
|
|
|
NSParameterAssert(factory);
|
2016-01-21 15:36:47 -08:00
|
|
|
NSParameterAssert(nativeTrack);
|
|
|
|
|
NSParameterAssert(type == RTCMediaStreamTrackTypeAudio);
|
2018-07-11 15:35:40 +03:00
|
|
|
return [super initWithFactory:factory nativeTrack:nativeTrack type:type];
|
2016-01-21 15:36:47 -08:00
|
|
|
}
|
|
|
|
|
|
2016-08-30 11:56:05 -07:00
|
|
|
|
|
|
|
|
- (RTCAudioSource *)source {
|
|
|
|
|
if (!_source) {
|
|
|
|
|
rtc::scoped_refptr<webrtc::AudioSourceInterface> source =
|
|
|
|
|
self.nativeAudioTrack->GetSource();
|
|
|
|
|
if (source) {
|
2018-07-11 15:35:40 +03:00
|
|
|
_source =
|
|
|
|
|
[[RTCAudioSource alloc] initWithFactory:self.factory nativeAudioSource:source.get()];
|
2016-08-30 11:56:05 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return _source;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-21 15:36:47 -08:00
|
|
|
#pragma mark - Private
|
|
|
|
|
|
|
|
|
|
- (rtc::scoped_refptr<webrtc::AudioTrackInterface>)nativeAudioTrack {
|
|
|
|
|
return static_cast<webrtc::AudioTrackInterface *>(self.nativeTrack.get());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|