• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2011 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 
11 #include "pc/audio_track.h"
12 
13 #include "rtc_base/checks.h"
14 #include "rtc_base/ref_counted_object.h"
15 
16 namespace webrtc {
17 
18 // static
Create(const std::string & id,const rtc::scoped_refptr<AudioSourceInterface> & source)19 rtc::scoped_refptr<AudioTrack> AudioTrack::Create(
20     const std::string& id,
21     const rtc::scoped_refptr<AudioSourceInterface>& source) {
22   return new rtc::RefCountedObject<AudioTrack>(id, source);
23 }
24 
AudioTrack(const std::string & label,const rtc::scoped_refptr<AudioSourceInterface> & source)25 AudioTrack::AudioTrack(const std::string& label,
26                        const rtc::scoped_refptr<AudioSourceInterface>& source)
27     : MediaStreamTrack<AudioTrackInterface>(label), audio_source_(source) {
28   if (audio_source_) {
29     audio_source_->RegisterObserver(this);
30     OnChanged();
31   }
32 }
33 
~AudioTrack()34 AudioTrack::~AudioTrack() {
35   RTC_DCHECK(thread_checker_.IsCurrent());
36   set_state(MediaStreamTrackInterface::kEnded);
37   if (audio_source_)
38     audio_source_->UnregisterObserver(this);
39 }
40 
kind() const41 std::string AudioTrack::kind() const {
42   RTC_DCHECK(thread_checker_.IsCurrent());
43   return kAudioKind;
44 }
45 
GetSource() const46 AudioSourceInterface* AudioTrack::GetSource() const {
47   RTC_DCHECK(thread_checker_.IsCurrent());
48   return audio_source_.get();
49 }
50 
AddSink(AudioTrackSinkInterface * sink)51 void AudioTrack::AddSink(AudioTrackSinkInterface* sink) {
52   RTC_DCHECK(thread_checker_.IsCurrent());
53   if (audio_source_)
54     audio_source_->AddSink(sink);
55 }
56 
RemoveSink(AudioTrackSinkInterface * sink)57 void AudioTrack::RemoveSink(AudioTrackSinkInterface* sink) {
58   RTC_DCHECK(thread_checker_.IsCurrent());
59   if (audio_source_)
60     audio_source_->RemoveSink(sink);
61 }
62 
OnChanged()63 void AudioTrack::OnChanged() {
64   RTC_DCHECK(thread_checker_.IsCurrent());
65   if (audio_source_->state() == MediaSourceInterface::kEnded) {
66     set_state(kEnded);
67   } else {
68     set_state(kLive);
69   }
70 }
71 
72 }  // namespace webrtc
73