blob: 02607da6762eeb02293e7b27b69b8098c51528e6 [file] [log] [blame]
Henrik Kjellanderbd0ae452016-02-10 09:53:121/*
kjellander95ed4e62016-02-10 15:54:432 * Copyright 2011 The WebRTC project authors. All Rights Reserved.
Henrik Kjellanderbd0ae452016-02-10 09:53:123 *
kjellander95ed4e62016-02-10 15:54:434 * 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 Kjellanderbd0ae452016-02-10 09:53:129 */
10
ossu25e4ac72017-01-23 12:56:2511#include "webrtc/pc/audiotrack.h"
Henrik Kjellanderbd0ae452016-02-10 09:53:1212
Edward Lemur76de83e2017-07-06 17:44:3413#include "webrtc/rtc_base/checks.h"
Henrik Kjellanderbd0ae452016-02-10 09:53:1214
15using rtc::scoped_refptr;
16
17namespace webrtc {
18
Henrik Kjellanderbd0ae452016-02-10 09:53:1219// static
20scoped_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
26AudioTrack::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
35AudioTrack::~AudioTrack() {
36 RTC_DCHECK(thread_checker_.CalledOnValidThread());
37 set_state(MediaStreamTrackInterface::kEnded);
38 if (audio_source_)
39 audio_source_->UnregisterObserver(this);
40}
41
42std::string AudioTrack::kind() const {
43 RTC_DCHECK(thread_checker_.CalledOnValidThread());
44 return kAudioKind;
45}
46
47AudioSourceInterface* AudioTrack::GetSource() const {
48 RTC_DCHECK(thread_checker_.CalledOnValidThread());
49 return audio_source_.get();
50}
51
52void AudioTrack::AddSink(AudioTrackSinkInterface* sink) {
53 RTC_DCHECK(thread_checker_.CalledOnValidThread());
54 if (audio_source_)
55 audio_source_->AddSink(sink);
56}
57
58void AudioTrack::RemoveSink(AudioTrackSinkInterface* sink) {
59 RTC_DCHECK(thread_checker_.CalledOnValidThread());
60 if (audio_source_)
61 audio_source_->RemoveSink(sink);
62}
63
64void AudioTrack::OnChanged() {
65 RTC_DCHECK(thread_checker_.CalledOnValidThread());
perkj8dde01d2016-03-23 07:33:5666 if (audio_source_->state() == MediaSourceInterface::kEnded) {
67 set_state(kEnded);
68 } else {
69 set_state(kLive);
Henrik Kjellanderbd0ae452016-02-10 09:53:1270 }
Henrik Kjellanderbd0ae452016-02-10 09:53:1271}
72
73} // namespace webrtc