You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.0 KiB

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