| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| 11 #include "content/public/renderer/media_stream_audio_sink.h" | 11 #include "content/public/renderer/media_stream_audio_sink.h" |
| 12 #include "content/renderer/media/media_stream_audio_level_calculator.h" | 12 #include "content/renderer/media/media_stream_audio_level_calculator.h" |
| 13 #include "content/renderer/media/media_stream_audio_processor.h" | 13 #include "content/renderer/media/media_stream_audio_processor.h" |
| 14 #include "content/renderer/media/media_stream_audio_sink_owner.h" | 14 #include "content/renderer/media/media_stream_audio_sink_owner.h" |
| 15 #include "content/renderer/media/media_stream_audio_track_sink.h" | 15 #include "content/renderer/media/media_stream_audio_track_sink.h" |
| 16 #include "content/renderer/media/webaudio_capturer_source.h" | 16 #include "content/renderer/media/webaudio_capturer_source.h" |
| 17 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" | 17 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" |
| 18 #include "content/renderer/media/webrtc_audio_capturer.h" | 18 #include "content/renderer/media/webrtc_audio_capturer.h" |
| 19 | 19 |
| 20 #include "base/debug/stack_trace.h" |
| 21 |
| 20 namespace content { | 22 namespace content { |
| 21 | 23 |
| 22 WebRtcLocalAudioTrack::WebRtcLocalAudioTrack( | 24 WebRtcLocalAudioTrack::WebRtcLocalAudioTrack( |
| 23 WebRtcLocalAudioTrackAdapter* adapter, | 25 WebRtcLocalAudioTrackAdapter* adapter, |
| 24 const scoped_refptr<WebRtcAudioCapturer>& capturer, | 26 const scoped_refptr<WebRtcAudioCapturer>& capturer, |
| 25 WebAudioCapturerSource* webaudio_source) | 27 WebAudioCapturerSource* webaudio_source) |
| 26 : MediaStreamAudioTrack(true), | 28 : MediaStreamAudioTrack(true), |
| 27 adapter_(adapter), | 29 adapter_(adapter), |
| 28 capturer_(capturer), | 30 capturer_(capturer), |
| 29 webaudio_source_(webaudio_source) { | 31 webaudio_source_(webaudio_source) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 47 if (webaudio_source_.get()) { | 49 if (webaudio_source_.get()) { |
| 48 return media::AudioParameters(); | 50 return media::AudioParameters(); |
| 49 } else { | 51 } else { |
| 50 return capturer_->GetOutputFormat(); | 52 return capturer_->GetOutputFormat(); |
| 51 } | 53 } |
| 52 } | 54 } |
| 53 | 55 |
| 54 void WebRtcLocalAudioTrack::Capture(const media::AudioBus& audio_bus, | 56 void WebRtcLocalAudioTrack::Capture(const media::AudioBus& audio_bus, |
| 55 base::TimeTicks estimated_capture_time, | 57 base::TimeTicks estimated_capture_time, |
| 56 bool force_report_nonzero_energy) { | 58 bool force_report_nonzero_energy) { |
| 59 /* |
| 60 static bool first_time = true; |
| 61 if (first_time) { |
| 62 first_time = false; |
| 63 base::debug::StackTrace st; |
| 64 st.Print(); |
| 65 } |
| 66 */ |
| 57 DCHECK(capture_thread_checker_.CalledOnValidThread()); | 67 DCHECK(capture_thread_checker_.CalledOnValidThread()); |
| 58 DCHECK(!estimated_capture_time.is_null()); | 68 DCHECK(!estimated_capture_time.is_null()); |
| 59 | 69 |
| 60 // Calculate the signal level regardless of whether the track is disabled or | 70 // Calculate the signal level regardless of whether the track is disabled or |
| 61 // enabled. If |force_report_nonzero_energy| is true, |audio_bus| contains | 71 // enabled. If |force_report_nonzero_energy| is true, |audio_bus| contains |
| 62 // post-processed data that may be all zeros even though the signal contained | 72 // post-processed data that may be all zeros even though the signal contained |
| 63 // energy before the processing. In this case, report nonzero energy even if | 73 // energy before the processing. In this case, report nonzero energy even if |
| 64 // the energy of the data in |audio_bus| is zero. | 74 // the energy of the data in |audio_bus| is zero. |
| 65 const float minimum_signal_level = | 75 const float minimum_signal_level = |
| 66 force_report_nonzero_energy ? 1.0f / std::numeric_limits<int16_t>::max() | 76 force_report_nonzero_energy ? 1.0f / std::numeric_limits<int16_t>::max() |
| (...skipping 25 matching lines...) Expand all Loading... |
| 92 // TODO(jiayl): we should not pass the real audio data down if the track is | 102 // TODO(jiayl): we should not pass the real audio data down if the track is |
| 93 // disabled. This is currently done so to feed input to WebRTC typing | 103 // disabled. This is currently done so to feed input to WebRTC typing |
| 94 // detection and should be changed when audio processing is moved from | 104 // detection and should be changed when audio processing is moved from |
| 95 // WebRTC to the track. | 105 // WebRTC to the track. |
| 96 for (const auto& sink : sinks) | 106 for (const auto& sink : sinks) |
| 97 sink->OnData(audio_bus, estimated_capture_time); | 107 sink->OnData(audio_bus, estimated_capture_time); |
| 98 } | 108 } |
| 99 | 109 |
| 100 void WebRtcLocalAudioTrack::OnSetFormat( | 110 void WebRtcLocalAudioTrack::OnSetFormat( |
| 101 const media::AudioParameters& params) { | 111 const media::AudioParameters& params) { |
| 112 printf("******* WebRtcLocalAudioTrack::OnSetFormat %p\n", this); |
| 113 // static bool first_time = true; |
| 114 // if (first_time) { |
| 115 // first_time = false; |
| 116 // base::debug::StackTrace st; |
| 117 // st.Print(); |
| 118 // } |
| 119 |
| 102 DVLOG(1) << "WebRtcLocalAudioTrack::OnSetFormat()"; | 120 DVLOG(1) << "WebRtcLocalAudioTrack::OnSetFormat()"; |
| 103 // If the source is restarted, we might have changed to another capture | 121 // If the source is restarted, we might have changed to another capture |
| 104 // thread. | 122 // thread. |
| 105 capture_thread_checker_.DetachFromThread(); | 123 capture_thread_checker_.DetachFromThread(); |
| 106 DCHECK(capture_thread_checker_.CalledOnValidThread()); | 124 DCHECK(capture_thread_checker_.CalledOnValidThread()); |
| 107 | 125 |
| 108 audio_parameters_ = params; | 126 audio_parameters_ = params; |
| 109 level_calculator_.reset(new MediaStreamAudioLevelCalculator()); | 127 level_calculator_.reset(new MediaStreamAudioLevelCalculator()); |
| 110 | 128 |
| 111 base::AutoLock auto_lock(lock_); | 129 base::AutoLock auto_lock(lock_); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 (*it)->Reset(); | 250 (*it)->Reset(); |
| 233 } | 251 } |
| 234 } | 252 } |
| 235 | 253 |
| 236 webrtc::AudioTrackInterface* WebRtcLocalAudioTrack::GetAudioAdapter() { | 254 webrtc::AudioTrackInterface* WebRtcLocalAudioTrack::GetAudioAdapter() { |
| 237 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 255 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
| 238 return adapter_.get(); | 256 return adapter_.get(); |
| 239 } | 257 } |
| 240 | 258 |
| 241 } // namespace content | 259 } // namespace content |
| OLD | NEW |