henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2011 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 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. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "pc/audiotrack.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 12 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 13 | #include "rtc_base/checks.h" |
Niels Möller | 84255bb | 2017-10-06 13:43:23 +0200 | [diff] [blame] | 14 | #include "rtc_base/refcountedobject.h" |
tommi | 6eca7e3 | 2015-12-15 04:27:11 -0800 | [diff] [blame] | 15 | |
| 16 | using rtc::scoped_refptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 17 | |
| 18 | namespace webrtc { |
| 19 | |
tommi | 6eca7e3 | 2015-12-15 04:27:11 -0800 | [diff] [blame] | 20 | // static |
| 21 | scoped_refptr<AudioTrack> AudioTrack::Create( |
| 22 | const std::string& id, |
| 23 | const scoped_refptr<AudioSourceInterface>& source) { |
| 24 | return new rtc::RefCountedObject<AudioTrack>(id, source); |
| 25 | } |
| 26 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 27 | AudioTrack::AudioTrack(const std::string& label, |
tommi | 6eca7e3 | 2015-12-15 04:27:11 -0800 | [diff] [blame] | 28 | const scoped_refptr<AudioSourceInterface>& source) |
| 29 | : MediaStreamTrack<AudioTrackInterface>(label), audio_source_(source) { |
| 30 | if (audio_source_) { |
| 31 | audio_source_->RegisterObserver(this); |
| 32 | OnChanged(); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | AudioTrack::~AudioTrack() { |
| 37 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 38 | set_state(MediaStreamTrackInterface::kEnded); |
| 39 | if (audio_source_) |
| 40 | audio_source_->UnregisterObserver(this); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | std::string AudioTrack::kind() const { |
tommi | 6eca7e3 | 2015-12-15 04:27:11 -0800 | [diff] [blame] | 44 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 45 | return kAudioKind; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 46 | } |
| 47 | |
tommi | 6eca7e3 | 2015-12-15 04:27:11 -0800 | [diff] [blame] | 48 | AudioSourceInterface* AudioTrack::GetSource() const { |
| 49 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 50 | return audio_source_.get(); |
| 51 | } |
| 52 | |
| 53 | void AudioTrack::AddSink(AudioTrackSinkInterface* sink) { |
| 54 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 55 | if (audio_source_) |
| 56 | audio_source_->AddSink(sink); |
| 57 | } |
| 58 | |
| 59 | void AudioTrack::RemoveSink(AudioTrackSinkInterface* sink) { |
| 60 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 61 | if (audio_source_) |
| 62 | audio_source_->RemoveSink(sink); |
| 63 | } |
| 64 | |
| 65 | void AudioTrack::OnChanged() { |
| 66 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
perkj | c8f952d | 2016-03-23 00:33:56 -0700 | [diff] [blame] | 67 | if (audio_source_->state() == MediaSourceInterface::kEnded) { |
| 68 | set_state(kEnded); |
| 69 | } else { |
| 70 | set_state(kLive); |
tommi | 6eca7e3 | 2015-12-15 04:27:11 -0800 | [diff] [blame] | 71 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | } // namespace webrtc |