Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2014 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/api/remoteaudiosource.h" | 11 #include "webrtc/api/remoteaudiosource.h" |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 #include <functional> | 14 #include <functional> |
| 15 #include <memory> | 15 #include <memory> |
| 16 #include <utility> | 16 #include <utility> |
| 17 | 17 |
| 18 #include "webrtc/api/mediastreamprovider.h" | |
| 19 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
| 20 #include "webrtc/base/constructormagic.h" | 19 #include "webrtc/base/constructormagic.h" |
| 21 #include "webrtc/base/logging.h" | 20 #include "webrtc/base/logging.h" |
| 22 #include "webrtc/base/thread.h" | 21 #include "webrtc/base/thread.h" |
| 23 | 22 |
| 24 namespace webrtc { | 23 namespace webrtc { |
| 25 | 24 |
| 26 class RemoteAudioSource::MessageHandler : public rtc::MessageHandler { | 25 class RemoteAudioSource::MessageHandler : public rtc::MessageHandler { |
| 27 public: | 26 public: |
| 28 explicit MessageHandler(RemoteAudioSource* source) : source_(source) {} | 27 explicit MessageHandler(RemoteAudioSource* source) : source_(source) {} |
| 29 | 28 |
| 30 private: | 29 private: |
| 31 ~MessageHandler() override {} | 30 ~MessageHandler() override {} |
| 32 | 31 |
| 33 void OnMessage(rtc::Message* msg) override { | 32 void OnMessage(rtc::Message* msg) override { |
| 34 source_->OnMessage(msg); | 33 source_->OnMessage(msg); |
| 35 delete this; | 34 delete this; |
| 36 } | 35 } |
| 37 | 36 |
| 38 const rtc::scoped_refptr<RemoteAudioSource> source_; | 37 const rtc::scoped_refptr<RemoteAudioSource> source_; |
| 39 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(MessageHandler); | 38 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(MessageHandler); |
| 40 }; | 39 }; |
| 41 | 40 |
| 42 class RemoteAudioSource::Sink : public AudioSinkInterface { | 41 class RemoteAudioSource::Sink : public AudioSinkInterface { |
| 43 public: | 42 public: |
| 44 explicit Sink(RemoteAudioSource* source) : source_(source) {} | 43 explicit Sink(RemoteAudioSource* source) : source_(source) {} |
| 45 ~Sink() override { source_->OnAudioProviderGone(); } | 44 ~Sink() override { source_->OnAudioChannelGone(); } |
| 46 | 45 |
| 47 private: | 46 private: |
| 48 void OnData(const AudioSinkInterface::Data& audio) override { | 47 void OnData(const AudioSinkInterface::Data& audio) override { |
| 49 if (source_) | 48 if (source_) |
| 50 source_->OnData(audio); | 49 source_->OnData(audio); |
| 51 } | 50 } |
| 52 | 51 |
| 53 const rtc::scoped_refptr<RemoteAudioSource> source_; | 52 const rtc::scoped_refptr<RemoteAudioSource> source_; |
| 54 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Sink); | 53 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Sink); |
| 55 }; | 54 }; |
| 56 | 55 |
| 57 rtc::scoped_refptr<RemoteAudioSource> RemoteAudioSource::Create( | 56 rtc::scoped_refptr<RemoteAudioSource> RemoteAudioSource::Create( |
| 58 uint32_t ssrc, | 57 uint32_t ssrc, |
| 59 AudioProviderInterface* provider) { | 58 cricket::VoiceChannel* channel) { |
| 60 rtc::scoped_refptr<RemoteAudioSource> ret( | 59 rtc::scoped_refptr<RemoteAudioSource> ret( |
| 61 new rtc::RefCountedObject<RemoteAudioSource>()); | 60 new rtc::RefCountedObject<RemoteAudioSource>()); |
| 62 ret->Initialize(ssrc, provider); | 61 ret->Initialize(ssrc, channel); |
| 63 return ret; | 62 return ret; |
| 64 } | 63 } |
| 65 | 64 |
| 66 RemoteAudioSource::RemoteAudioSource() | 65 RemoteAudioSource::RemoteAudioSource() |
| 67 : main_thread_(rtc::Thread::Current()), | 66 : main_thread_(rtc::Thread::Current()), |
| 68 state_(MediaSourceInterface::kLive) { | 67 state_(MediaSourceInterface::kLive) { |
| 69 RTC_DCHECK(main_thread_); | 68 RTC_DCHECK(main_thread_); |
| 70 } | 69 } |
| 71 | 70 |
| 72 RemoteAudioSource::~RemoteAudioSource() { | 71 RemoteAudioSource::~RemoteAudioSource() { |
| 73 RTC_DCHECK(main_thread_->IsCurrent()); | 72 RTC_DCHECK(main_thread_->IsCurrent()); |
| 74 RTC_DCHECK(audio_observers_.empty()); | 73 RTC_DCHECK(audio_observers_.empty()); |
| 75 RTC_DCHECK(sinks_.empty()); | 74 RTC_DCHECK(sinks_.empty()); |
| 76 } | 75 } |
| 77 | 76 |
| 78 void RemoteAudioSource::Initialize(uint32_t ssrc, | 77 void RemoteAudioSource::Initialize(uint32_t ssrc, |
| 79 AudioProviderInterface* provider) { | 78 cricket::VoiceChannel* channel) { |
| 80 RTC_DCHECK(main_thread_->IsCurrent()); | 79 RTC_DCHECK(main_thread_->IsCurrent()); |
| 81 // To make sure we always get notified when the provider goes out of scope, | 80 // To make sure we always get notified when the channel goes out of scope, |
| 82 // we register for callbacks here and not on demand in AddSink. | 81 // we register for callbacks here and not on demand in AddSink. |
| 83 if (provider) { // May be null in tests. | 82 if (channel) { // May be null in tests. |
| 84 provider->SetRawAudioSink( | 83 channel->SetRawAudioSink( |
| 85 ssrc, std::unique_ptr<AudioSinkInterface>(new Sink(this))); | 84 ssrc, std::unique_ptr<AudioSinkInterface>(new Sink(this))); |
|
pthatcher1
2016/06/21 07:45:41
SetRawAudioSink could be part of RtpReceiverIntern
Taylor Brandstetter
2016/06/22 00:50:17
That sounds like a good idea but I think it can ha
| |
| 86 } | 85 } |
| 87 } | 86 } |
| 88 | 87 |
| 89 MediaSourceInterface::SourceState RemoteAudioSource::state() const { | 88 MediaSourceInterface::SourceState RemoteAudioSource::state() const { |
| 90 RTC_DCHECK(main_thread_->IsCurrent()); | 89 RTC_DCHECK(main_thread_->IsCurrent()); |
| 91 return state_; | 90 return state_; |
| 92 } | 91 } |
| 93 | 92 |
| 94 bool RemoteAudioSource::remote() const { | 93 bool RemoteAudioSource::remote() const { |
| 95 RTC_DCHECK(main_thread_->IsCurrent()); | 94 RTC_DCHECK(main_thread_->IsCurrent()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 | 137 |
| 139 void RemoteAudioSource::OnData(const AudioSinkInterface::Data& audio) { | 138 void RemoteAudioSource::OnData(const AudioSinkInterface::Data& audio) { |
| 140 // Called on the externally-owned audio callback thread, via/from webrtc. | 139 // Called on the externally-owned audio callback thread, via/from webrtc. |
| 141 rtc::CritScope lock(&sink_lock_); | 140 rtc::CritScope lock(&sink_lock_); |
| 142 for (auto* sink : sinks_) { | 141 for (auto* sink : sinks_) { |
| 143 sink->OnData(audio.data, 16, audio.sample_rate, audio.channels, | 142 sink->OnData(audio.data, 16, audio.sample_rate, audio.channels, |
| 144 audio.samples_per_channel); | 143 audio.samples_per_channel); |
| 145 } | 144 } |
| 146 } | 145 } |
| 147 | 146 |
| 148 void RemoteAudioSource::OnAudioProviderGone() { | 147 void RemoteAudioSource::OnAudioChannelGone() { |
| 149 // Called when the data provider is deleted. It may be the worker thread | 148 // Called when the audio channel is deleted. It may be the worker thread |
| 150 // in libjingle or may be a different worker thread. | 149 // in libjingle or may be a different worker thread. |
| 151 main_thread_->Post(new MessageHandler(this)); | 150 main_thread_->Post(new MessageHandler(this)); |
| 152 } | 151 } |
| 153 | 152 |
| 154 void RemoteAudioSource::OnMessage(rtc::Message* msg) { | 153 void RemoteAudioSource::OnMessage(rtc::Message* msg) { |
| 155 RTC_DCHECK(main_thread_->IsCurrent()); | 154 RTC_DCHECK(main_thread_->IsCurrent()); |
| 156 sinks_.clear(); | 155 sinks_.clear(); |
| 157 state_ = MediaSourceInterface::kEnded; | 156 state_ = MediaSourceInterface::kEnded; |
| 158 FireOnChanged(); | 157 FireOnChanged(); |
| 159 } | 158 } |
| 160 | 159 |
| 161 } // namespace webrtc | 160 } // namespace webrtc |
| OLD | NEW |