• 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 
15 namespace webrtc {
16 
17 // static
Create(absl::string_view id,const rtc::scoped_refptr<AudioSourceInterface> & source)18 rtc::scoped_refptr<AudioTrack> AudioTrack::Create(
19     absl::string_view id,
20     const rtc::scoped_refptr<AudioSourceInterface>& source) {
21   return rtc::make_ref_counted<AudioTrack>(id, source);
22 }
23 
AudioTrack(absl::string_view label,const rtc::scoped_refptr<AudioSourceInterface> & source)24 AudioTrack::AudioTrack(absl::string_view label,
25                        const rtc::scoped_refptr<AudioSourceInterface>& source)
26     : MediaStreamTrack<AudioTrackInterface>(label), audio_source_(source) {
27   if (audio_source_) {
28     audio_source_->RegisterObserver(this);
29     OnChanged();
30   }
31 }
32 
~AudioTrack()33 AudioTrack::~AudioTrack() {
34   RTC_DCHECK_RUN_ON(&signaling_thread_checker_);
35   set_state(MediaStreamTrackInterface::kEnded);
36   if (audio_source_)
37     audio_source_->UnregisterObserver(this);
38 }
39 
kind() const40 std::string AudioTrack::kind() const {
41   return kAudioKind;
42 }
43 
GetSource() const44 AudioSourceInterface* AudioTrack::GetSource() const {
45   // Callable from any thread.
46   return audio_source_.get();
47 }
48 
AddSink(AudioTrackSinkInterface * sink)49 void AudioTrack::AddSink(AudioTrackSinkInterface* sink) {
50   RTC_DCHECK_RUN_ON(&signaling_thread_checker_);
51   if (audio_source_)
52     audio_source_->AddSink(sink);
53 }
54 
RemoveSink(AudioTrackSinkInterface * sink)55 void AudioTrack::RemoveSink(AudioTrackSinkInterface* sink) {
56   RTC_DCHECK_RUN_ON(&signaling_thread_checker_);
57   if (audio_source_)
58     audio_source_->RemoveSink(sink);
59 }
60 
OnChanged()61 void AudioTrack::OnChanged() {
62   RTC_DCHECK_RUN_ON(&signaling_thread_checker_);
63   if (audio_source_->state() == MediaSourceInterface::kEnded) {
64     set_state(kEnded);
65   } else {
66     set_state(kLive);
67   }
68 }
69 
70 }  // namespace webrtc
71