Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" | 5 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "content/renderer/media/media_stream_audio_processor.h" | 9 #include "content/renderer/media/media_stream_audio_processor.h" |
| 10 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" | 10 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 return adapter; | 39 return adapter; |
| 40 } | 40 } |
| 41 | 41 |
| 42 WebRtcLocalAudioTrackAdapter::WebRtcLocalAudioTrackAdapter( | 42 WebRtcLocalAudioTrackAdapter::WebRtcLocalAudioTrackAdapter( |
| 43 const std::string& label, | 43 const std::string& label, |
| 44 webrtc::AudioSourceInterface* track_source, | 44 webrtc::AudioSourceInterface* track_source, |
| 45 const scoped_refptr<base::SingleThreadTaskRunner>& signaling_thread) | 45 const scoped_refptr<base::SingleThreadTaskRunner>& signaling_thread) |
| 46 : webrtc::MediaStreamTrack<webrtc::AudioTrackInterface>(label), | 46 : webrtc::MediaStreamTrack<webrtc::AudioTrackInterface>(label), |
| 47 owner_(NULL), | 47 owner_(NULL), |
| 48 track_source_(track_source), | 48 track_source_(track_source), |
| 49 signaling_thread_(signaling_thread), | 49 signaling_thread_(signaling_thread) { |
| 50 signal_level_(0) { | |
| 51 signaling_thread_checker_.DetachFromThread(); | 50 signaling_thread_checker_.DetachFromThread(); |
|
mcasas
2016/02/26 01:28:19
DCHECK(signaling_thread_);
(this should not happen
miu
2016/02/27 03:46:36
I actually have some threading fixes to this class
| |
| 52 capture_thread_.DetachFromThread(); | 51 capture_thread_.DetachFromThread(); |
| 53 } | 52 } |
| 54 | 53 |
| 55 WebRtcLocalAudioTrackAdapter::~WebRtcLocalAudioTrackAdapter() { | 54 WebRtcLocalAudioTrackAdapter::~WebRtcLocalAudioTrackAdapter() { |
| 56 } | 55 } |
| 57 | 56 |
| 58 void WebRtcLocalAudioTrackAdapter::Initialize(WebRtcLocalAudioTrack* owner) { | 57 void WebRtcLocalAudioTrackAdapter::Initialize(WebRtcLocalAudioTrack* owner) { |
| 59 DCHECK(!owner_); | 58 DCHECK(!owner_); |
| 60 DCHECK(owner); | 59 DCHECK(owner); |
| 61 owner_ = owner; | 60 owner_ = owner; |
| 62 } | 61 } |
| 63 | 62 |
| 64 void WebRtcLocalAudioTrackAdapter::SetAudioProcessor( | 63 void WebRtcLocalAudioTrackAdapter::SetAudioProcessor( |
| 65 const scoped_refptr<MediaStreamAudioProcessor>& processor) { | 64 const scoped_refptr<MediaStreamAudioProcessor>& processor) { |
| 66 // SetAudioProcessor will be called when a new capture thread has been | 65 // SetAudioProcessor will be called when a new capture thread has been |
| 67 // initialized, so we need to detach from any current capture thread we're | 66 // initialized, so we need to detach from any current capture thread we're |
| 68 // checking and attach to the current one. | 67 // checking and attach to the current one. |
| 69 capture_thread_.DetachFromThread(); | 68 capture_thread_.DetachFromThread(); |
| 70 DCHECK(capture_thread_.CalledOnValidThread()); | 69 DCHECK(capture_thread_.CalledOnValidThread()); |
| 71 base::AutoLock auto_lock(lock_); | 70 base::AutoLock auto_lock(lock_); |
| 72 audio_processor_ = processor; | 71 audio_processor_ = processor; |
| 73 } | 72 } |
| 74 | 73 |
| 74 void WebRtcLocalAudioTrackAdapter::SetLevel( | |
| 75 scoped_refptr<MediaStreamAudioLevelCalculator::Level> level) { | |
|
mcasas
2016/02/26 01:28:19
Paranoia nit:
DCHECK(capture_thread_.CalledOnVali
miu
2016/02/27 03:46:36
Actually, it's not called from either of those thr
| |
| 76 base::AutoLock auto_lock(lock_); | |
| 77 level_ = level; | |
| 78 } | |
| 79 | |
| 75 std::string WebRtcLocalAudioTrackAdapter::kind() const { | 80 std::string WebRtcLocalAudioTrackAdapter::kind() const { |
| 76 return kAudioTrackKind; | 81 return kAudioTrackKind; |
| 77 } | 82 } |
| 78 | 83 |
| 79 bool WebRtcLocalAudioTrackAdapter::set_enabled(bool enable) { | 84 bool WebRtcLocalAudioTrackAdapter::set_enabled(bool enable) { |
| 80 // If we're not called on the signaling thread, we need to post a task to | 85 // If we're not called on the signaling thread, we need to post a task to |
| 81 // change the state on the correct thread. | 86 // change the state on the correct thread. |
| 82 if (signaling_thread_.get() && !signaling_thread_->BelongsToCurrentThread()) { | 87 if (signaling_thread_.get() && !signaling_thread_->BelongsToCurrentThread()) { |
| 83 signaling_thread_->PostTask(FROM_HERE, | 88 signaling_thread_->PostTask(FROM_HERE, |
| 84 base::Bind( | 89 base::Bind( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 it != sink_adapters_.end(); ++it) { | 124 it != sink_adapters_.end(); ++it) { |
| 120 if ((*it)->IsEqual(sink)) { | 125 if ((*it)->IsEqual(sink)) { |
| 121 owner_->RemoveSink(*it); | 126 owner_->RemoveSink(*it); |
| 122 sink_adapters_.erase(it); | 127 sink_adapters_.erase(it); |
| 123 return; | 128 return; |
| 124 } | 129 } |
| 125 } | 130 } |
| 126 } | 131 } |
| 127 | 132 |
| 128 bool WebRtcLocalAudioTrackAdapter::GetSignalLevel(int* level) { | 133 bool WebRtcLocalAudioTrackAdapter::GetSignalLevel(int* level) { |
| 129 DCHECK(signaling_thread_checker_.CalledOnValidThread()); | 134 // Note: Called on the signaling thread by WebRtc. |
| 130 | 135 float signal_level = 0.0f; |
| 131 base::AutoLock auto_lock(lock_); | 136 { |
| 132 *level = signal_level_; | 137 base::AutoLock auto_lock(lock_); |
| 138 if (!level_) | |
| 139 return false; | |
| 140 signal_level = level_->GetCurrent(); | |
| 141 } | |
| 142 DCHECK_GE(signal_level, 0.0f); | |
| 143 DCHECK_LE(signal_level, 1.0f); | |
| 144 // Convert from float in range [0.0,1.0] to an int in range [0,32767]. | |
| 145 *level = static_cast<int>(signal_level * std::numeric_limits<int16_t>::max() + | |
| 146 0.5f /* rounding to nearest int */); | |
| 133 return true; | 147 return true; |
| 134 } | 148 } |
| 135 | 149 |
| 136 rtc::scoped_refptr<webrtc::AudioProcessorInterface> | 150 rtc::scoped_refptr<webrtc::AudioProcessorInterface> |
| 137 WebRtcLocalAudioTrackAdapter::GetAudioProcessor() { | 151 WebRtcLocalAudioTrackAdapter::GetAudioProcessor() { |
| 138 DCHECK(signaling_thread_checker_.CalledOnValidThread()); | 152 DCHECK(signaling_thread_checker_.CalledOnValidThread()); |
| 139 base::AutoLock auto_lock(lock_); | 153 base::AutoLock auto_lock(lock_); |
| 140 return audio_processor_.get(); | 154 return audio_processor_.get(); |
| 141 } | 155 } |
| 142 | 156 |
| 143 void WebRtcLocalAudioTrackAdapter::SetSignalLevel(int signal_level) { | |
| 144 DCHECK(capture_thread_.CalledOnValidThread()); | |
| 145 base::AutoLock auto_lock(lock_); | |
| 146 signal_level_ = signal_level; | |
| 147 } | |
| 148 | |
| 149 webrtc::AudioSourceInterface* WebRtcLocalAudioTrackAdapter::GetSource() const { | 157 webrtc::AudioSourceInterface* WebRtcLocalAudioTrackAdapter::GetSource() const { |
| 150 DCHECK(signaling_thread_checker_.CalledOnValidThread()); | 158 DCHECK(signaling_thread_checker_.CalledOnValidThread()); |
| 151 return track_source_; | 159 return track_source_; |
| 152 } | 160 } |
| 153 | 161 |
| 154 } // namespace content | 162 } // namespace content |
| OLD | NEW |