| 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_audio_capturer.h" | 5 #include "content/renderer/media/webrtc_audio_capturer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 { | 106 { |
| 107 base::AutoLock auto_lock(lock_); | 107 base::AutoLock auto_lock(lock_); |
| 108 if (source_ == source) | 108 if (source_ == source) |
| 109 return; | 109 return; |
| 110 | 110 |
| 111 source_.swap(old_source); | 111 source_.swap(old_source); |
| 112 source_ = source; | 112 source_ = source; |
| 113 } | 113 } |
| 114 | 114 |
| 115 // Detach the old source from normal recording. | 115 // Detach the old source from normal recording. |
| 116 if (old_source) | 116 if (old_source) { |
| 117 old_source->Stop(); | 117 old_source->Stop(); |
| 118 | 118 |
| 119 // TODO(henrika, crogers): I have hard coded parameters given knowledge |
| 120 // of a file source (44.1kHz, mono) here and use these parameters to reset |
| 121 // our member parameters. I then dispatch the new parameters both to the |
| 122 // sink(s) and to the new source. The idea is to get rid of any dependency |
| 123 // of the microphone parameters which are uses as base otherwise. |
| 124 |
| 125 // I guess we could add this info to AudioCapturerSource to enable a |
| 126 // query here. E.g.: |
| 127 |
| 128 // source->ModifyAudioParameters(¶ms_); |
| 129 |
| 130 params_.Reset(params_.format(), |
| 131 media::CHANNEL_LAYOUT_MONO, // <-- get this from WebKit? |
| 132 44100, // <-- get this from WebKit? |
| 133 16, // <-- get this from WebKit? |
| 134 440); // requires knowledge about WebRTC @ 10ms |
| 135 |
| 136 buffer_.reset(new int16[params_.frames_per_buffer() * params_.channels()]); |
| 137 |
| 138 for (SinkList::const_iterator it = sinks_.begin(); |
| 139 it != sinks_.end(); ++it) { |
| 140 (*it)->SetCaptureFormat(params_); |
| 141 } |
| 142 } |
| 143 |
| 119 if (source) | 144 if (source) |
| 120 source->Initialize(params_, this, this); | 145 source->Initialize(params_, this, this); |
| 121 } | 146 } |
| 122 | 147 |
| 123 void WebRtcAudioCapturer::SetStopCallback( | 148 void WebRtcAudioCapturer::SetStopCallback( |
| 124 const base::Closure& on_device_stopped_cb) { | 149 const base::Closure& on_device_stopped_cb) { |
| 125 DVLOG(1) << "WebRtcAudioCapturer::SetStopCallback()"; | 150 DVLOG(1) << "WebRtcAudioCapturer::SetStopCallback()"; |
| 126 base::AutoLock auto_lock(lock_); | 151 base::AutoLock auto_lock(lock_); |
| 127 on_device_stopped_cb_ = on_device_stopped_cb; | 152 on_device_stopped_cb_ = on_device_stopped_cb; |
| 128 } | 153 } |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 // Inform the local renderer about the stopped device. | 395 // Inform the local renderer about the stopped device. |
| 371 // The renderer can then save resources by not asking for more data from | 396 // The renderer can then save resources by not asking for more data from |
| 372 // the stopped source. We are on the IO thread but the callback task will | 397 // the stopped source. We are on the IO thread but the callback task will |
| 373 // be posted on the message loop of the main render thread thanks to | 398 // be posted on the message loop of the main render thread thanks to |
| 374 // usage of BindToLoop() when the callback was initialized. | 399 // usage of BindToLoop() when the callback was initialized. |
| 375 if (!on_device_stopped_cb_.is_null()) | 400 if (!on_device_stopped_cb_.is_null()) |
| 376 on_device_stopped_cb_.Run(); | 401 on_device_stopped_cb_.Run(); |
| 377 } | 402 } |
| 378 | 403 |
| 379 } // namespace content | 404 } // namespace content |
| OLD | NEW |