Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 1 | /* |
kjellander | 95ed4e6 | 2016-02-10 15:54:43 | [diff] [blame] | 2 | * Copyright 2011 The WebRTC project authors. All Rights Reserved. |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 3 | * |
kjellander | 95ed4e6 | 2016-02-10 15:54:43 | [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. |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 9 | */ |
| 10 | |
ossu | 25e4ac7 | 2017-01-23 12:56:25 | [diff] [blame] | 11 | #include "webrtc/pc/audiotrack.h" |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 12 | |
Edward Lemur | 76de83e | 2017-07-06 17:44:34 | [diff] [blame] | 13 | #include "webrtc/rtc_base/checks.h" |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 14 | |
| 15 | using rtc::scoped_refptr; |
| 16 | |
| 17 | namespace webrtc { |
| 18 | |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 19 | // static |
| 20 | scoped_refptr<AudioTrack> AudioTrack::Create( |
| 21 | const std::string& id, |
| 22 | const scoped_refptr<AudioSourceInterface>& source) { |
| 23 | return new rtc::RefCountedObject<AudioTrack>(id, source); |
| 24 | } |
| 25 | |
| 26 | AudioTrack::AudioTrack(const std::string& label, |
| 27 | const scoped_refptr<AudioSourceInterface>& source) |
| 28 | : MediaStreamTrack<AudioTrackInterface>(label), audio_source_(source) { |
| 29 | if (audio_source_) { |
| 30 | audio_source_->RegisterObserver(this); |
| 31 | OnChanged(); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | AudioTrack::~AudioTrack() { |
| 36 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 37 | set_state(MediaStreamTrackInterface::kEnded); |
| 38 | if (audio_source_) |
| 39 | audio_source_->UnregisterObserver(this); |
| 40 | } |
| 41 | |
| 42 | std::string AudioTrack::kind() const { |
| 43 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 44 | return kAudioKind; |
| 45 | } |
| 46 | |
| 47 | AudioSourceInterface* AudioTrack::GetSource() const { |
| 48 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 49 | return audio_source_.get(); |
| 50 | } |
| 51 | |
| 52 | void AudioTrack::AddSink(AudioTrackSinkInterface* sink) { |
| 53 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 54 | if (audio_source_) |
| 55 | audio_source_->AddSink(sink); |
| 56 | } |
| 57 | |
| 58 | void AudioTrack::RemoveSink(AudioTrackSinkInterface* sink) { |
| 59 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 60 | if (audio_source_) |
| 61 | audio_source_->RemoveSink(sink); |
| 62 | } |
| 63 | |
| 64 | void AudioTrack::OnChanged() { |
| 65 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
perkj | 8dde01d | 2016-03-23 07:33:56 | [diff] [blame] | 66 | if (audio_source_->state() == MediaSourceInterface::kEnded) { |
| 67 | set_state(kEnded); |
| 68 | } else { |
| 69 | set_state(kLive); |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 70 | } |
Henrik Kjellander | bd0ae45 | 2016-02-10 09:53:12 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | } // namespace webrtc |