| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_local_audio_track.h" | 5 #include "content/renderer/media/webrtc_local_audio_track.h" |
| 6 | 6 |
| 7 #include "content/public/renderer/media_stream_audio_sink.h" | 7 #include "content/public/renderer/media_stream_audio_sink.h" |
| 8 #include "content/renderer/media/media_stream_audio_level_calculator.h" |
| 8 #include "content/renderer/media/media_stream_audio_sink_owner.h" | 9 #include "content/renderer/media/media_stream_audio_sink_owner.h" |
| 9 #include "content/renderer/media/media_stream_audio_track_sink.h" | 10 #include "content/renderer/media/media_stream_audio_track_sink.h" |
| 10 #include "content/renderer/media/peer_connection_audio_sink_owner.h" | 11 #include "content/renderer/media/peer_connection_audio_sink_owner.h" |
| 11 #include "content/renderer/media/webaudio_capturer_source.h" | 12 #include "content/renderer/media/webaudio_capturer_source.h" |
| 12 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" | 13 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" |
| 13 #include "content/renderer/media/webrtc_audio_capturer.h" | 14 #include "content/renderer/media/webrtc_audio_capturer.h" |
| 14 | 15 |
| 15 namespace content { | 16 namespace content { |
| 16 | 17 |
| 17 WebRtcLocalAudioTrack::WebRtcLocalAudioTrack( | 18 WebRtcLocalAudioTrack::WebRtcLocalAudioTrack( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 39 // Users might not call Stop() on the track. | 40 // Users might not call Stop() on the track. |
| 40 Stop(); | 41 Stop(); |
| 41 } | 42 } |
| 42 | 43 |
| 43 void WebRtcLocalAudioTrack::Capture(const int16* audio_data, | 44 void WebRtcLocalAudioTrack::Capture(const int16* audio_data, |
| 44 base::TimeDelta delay, | 45 base::TimeDelta delay, |
| 45 int volume, | 46 int volume, |
| 46 bool key_pressed, | 47 bool key_pressed, |
| 47 bool need_audio_processing) { | 48 bool need_audio_processing) { |
| 48 DCHECK(capture_thread_checker_.CalledOnValidThread()); | 49 DCHECK(capture_thread_checker_.CalledOnValidThread()); |
| 50 |
| 51 // Calculate the signal level regardless if the track is disabled or enabled. |
| 52 int signal_level = level_calculator_->Calculate( |
| 53 audio_data, audio_parameters_.channels(), |
| 54 audio_parameters_.frames_per_buffer()); |
| 55 adapter_->SetSignalLevel(signal_level); |
| 56 |
| 49 scoped_refptr<WebRtcAudioCapturer> capturer; | 57 scoped_refptr<WebRtcAudioCapturer> capturer; |
| 50 SinkList::ItemList sinks; | 58 SinkList::ItemList sinks; |
| 51 SinkList::ItemList sinks_to_notify_format; | 59 SinkList::ItemList sinks_to_notify_format; |
| 52 { | 60 { |
| 53 base::AutoLock auto_lock(lock_); | 61 base::AutoLock auto_lock(lock_); |
| 54 capturer = capturer_; | 62 capturer = capturer_; |
| 55 sinks = sinks_.Items(); | 63 sinks = sinks_.Items(); |
| 56 sinks_.RetrieveAndClearTags(&sinks_to_notify_format); | 64 sinks_.RetrieveAndClearTags(&sinks_to_notify_format); |
| 57 } | 65 } |
| 58 | 66 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 99 |
| 92 void WebRtcLocalAudioTrack::OnSetFormat( | 100 void WebRtcLocalAudioTrack::OnSetFormat( |
| 93 const media::AudioParameters& params) { | 101 const media::AudioParameters& params) { |
| 94 DVLOG(1) << "WebRtcLocalAudioTrack::OnSetFormat()"; | 102 DVLOG(1) << "WebRtcLocalAudioTrack::OnSetFormat()"; |
| 95 // If the source is restarted, we might have changed to another capture | 103 // If the source is restarted, we might have changed to another capture |
| 96 // thread. | 104 // thread. |
| 97 capture_thread_checker_.DetachFromThread(); | 105 capture_thread_checker_.DetachFromThread(); |
| 98 DCHECK(capture_thread_checker_.CalledOnValidThread()); | 106 DCHECK(capture_thread_checker_.CalledOnValidThread()); |
| 99 | 107 |
| 100 audio_parameters_ = params; | 108 audio_parameters_ = params; |
| 109 level_calculator_.reset(new MediaStreamAudioLevelCalculator()); |
| 101 | 110 |
| 102 base::AutoLock auto_lock(lock_); | 111 base::AutoLock auto_lock(lock_); |
| 103 // Remember to notify all sinks of the new format. | 112 // Remember to notify all sinks of the new format. |
| 104 sinks_.TagAll(); | 113 sinks_.TagAll(); |
| 105 } | 114 } |
| 106 | 115 |
| 107 void WebRtcLocalAudioTrack::AddSink(MediaStreamAudioSink* sink) { | 116 void WebRtcLocalAudioTrack::AddSink(MediaStreamAudioSink* sink) { |
| 108 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 117 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
| 109 DVLOG(1) << "WebRtcLocalAudioTrack::AddSink()"; | 118 DVLOG(1) << "WebRtcLocalAudioTrack::AddSink()"; |
| 110 base::AutoLock auto_lock(lock_); | 119 base::AutoLock auto_lock(lock_); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 | 235 |
| 227 for (SinkList::ItemList::const_iterator it = sinks.begin(); | 236 for (SinkList::ItemList::const_iterator it = sinks.begin(); |
| 228 it != sinks.end(); | 237 it != sinks.end(); |
| 229 ++it){ | 238 ++it){ |
| 230 (*it)->OnReadyStateChanged(blink::WebMediaStreamSource::ReadyStateEnded); | 239 (*it)->OnReadyStateChanged(blink::WebMediaStreamSource::ReadyStateEnded); |
| 231 (*it)->Reset(); | 240 (*it)->Reset(); |
| 232 } | 241 } |
| 233 } | 242 } |
| 234 | 243 |
| 235 } // namespace content | 244 } // namespace content |
| OLD | NEW |