Index: content/renderer/media/webrtc_audio_capturer.cc |
diff --git a/content/renderer/media/webrtc_audio_capturer.cc b/content/renderer/media/webrtc_audio_capturer.cc |
index aa3ecf8627f84ca4165d481afd14b50388faf291..00b3b8baf465542b106739d70988f98677e9a7e8 100644 |
--- a/content/renderer/media/webrtc_audio_capturer.cc |
+++ b/content/renderer/media/webrtc_audio_capturer.cc |
@@ -63,6 +63,8 @@ class WebRtcAudioCapturer::TrackOwner |
void Reset() { |
base::AutoLock lock(lock_); |
+ if (delegate_) |
+ delegate_->Stop(); |
delegate_ = NULL; |
} |
@@ -101,8 +103,9 @@ scoped_refptr<WebRtcAudioCapturer> WebRtcAudioCapturer::CreateCapturer() { |
return capturer; |
} |
-void WebRtcAudioCapturer::Reconfigure(int sample_rate, |
- media::ChannelLayout channel_layout) { |
+void WebRtcAudioCapturer::Reconfigure( |
+ int sample_rate, |
+ media::ChannelLayout channel_layout) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
int buffer_size = GetBufferSize(sample_rate); |
DVLOG(1) << "Using WebRTC input buffer size: " << buffer_size; |
@@ -114,6 +117,7 @@ void WebRtcAudioCapturer::Reconfigure(int sample_rate, |
int bits_per_sample = 16; |
media::AudioParameters params(format, channel_layout, sample_rate, |
bits_per_sample, buffer_size); |
+ DCHECK(params.IsValid()); |
TrackList tracks; |
{ |
@@ -128,14 +132,15 @@ void WebRtcAudioCapturer::Reconfigure(int sample_rate, |
(*it)->SetCaptureFormat(params); |
} |
-bool WebRtcAudioCapturer::Initialize(int render_view_id, |
- media::ChannelLayout channel_layout, |
- int sample_rate, |
- int buffer_size, |
- int session_id, |
- const std::string& device_id, |
- int paired_output_sample_rate, |
- int paired_output_frames_per_buffer) { |
+bool WebRtcAudioCapturer::Initialize( |
+ int render_view_id, |
+ media::ChannelLayout channel_layout, |
+ int sample_rate, |
+ int buffer_size, |
+ int session_id, |
+ const std::string& device_id, |
+ int paired_output_sample_rate, |
+ int paired_output_frames_per_buffer) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
DCHECK_GE(render_view_id, 0); |
DVLOG(1) << "WebRtcAudioCapturer::Initialize()"; |
@@ -187,9 +192,9 @@ bool WebRtcAudioCapturer::Initialize(int render_view_id, |
// Create and configure the default audio capturing source. The |source_| |
// will be overwritten if an external client later calls SetCapturerSource() |
// providing an alternative media::AudioCapturerSource. |
- SetCapturerSource(AudioDeviceFactory::NewInputDevice(render_view_id), |
- channel_layout, |
- static_cast<float>(sample_rate)); |
+ InitializeCapturerSource(AudioDeviceFactory::NewInputDevice(render_view_id), |
+ channel_layout, |
+ static_cast<float>(sample_rate)); |
return true; |
} |
@@ -202,11 +207,11 @@ WebRtcAudioCapturer::WebRtcAudioCapturer() |
hardware_buffer_size_(0), |
session_id_(0), |
volume_(0), |
- source_provider_(new WebRtcLocalAudioSourceProvider()), |
peer_connection_mode_(false), |
output_sample_rate_(0), |
- output_frames_per_buffer_(0) { |
- DCHECK(source_provider_.get()); |
+ output_frames_per_buffer_(0), |
+ audio_delay_ms_(0), |
+ key_pressed_(false) { |
DVLOG(1) << "WebRtcAudioCapturer::WebRtcAudioCapturer()"; |
} |
@@ -230,7 +235,9 @@ void WebRtcAudioCapturer::AddTrack(WebRtcLocalAudioTrack* track) { |
DCHECK(std::find_if(tracks_.begin(), tracks_.end(), |
TrackOwner::TrackWrapper(track)) == tracks_.end()); |
- track->SetCaptureFormat(params_); |
+ if (params_.IsValid()) |
+ track->SetCaptureFormat(params_); |
+ |
tracks_.push_back(new WebRtcAudioCapturer::TrackOwner(track)); |
} |
@@ -260,13 +267,13 @@ void WebRtcAudioCapturer::RemoveTrack(WebRtcLocalAudioTrack* track) { |
Stop(); |
} |
-void WebRtcAudioCapturer::SetCapturerSource( |
+void WebRtcAudioCapturer::InitializeCapturerSource( |
const scoped_refptr<media::AudioCapturerSource>& source, |
media::ChannelLayout channel_layout, |
float sample_rate) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
- DVLOG(1) << "SetCapturerSource(channel_layout=" << channel_layout << "," |
- << "sample_rate=" << sample_rate << ")"; |
+ DVLOG(1) << "InitializeCapturerSource(channel_layout=" << channel_layout |
+ << "," << "sample_rate=" << sample_rate << ")"; |
scoped_refptr<media::AudioCapturerSource> old_source; |
bool restart_source = false; |
{ |
@@ -293,7 +300,6 @@ void WebRtcAudioCapturer::SetCapturerSource( |
// Make sure to grab the new parameters in case they were reconfigured. |
media::AudioParameters params = audio_parameters(); |
- source_provider_->Initialize(params); |
if (source.get()) |
source->Initialize(params, this, session_id_); |
@@ -327,9 +333,9 @@ void WebRtcAudioCapturer::EnablePeerConnectionMode() { |
// Create a new audio stream as source which will open the hardware using |
// WebRtc native buffer size. |
- SetCapturerSource(AudioDeviceFactory::NewInputDevice(render_view_id), |
- params.channel_layout(), |
- static_cast<float>(params.sample_rate())); |
+ InitializeCapturerSource(AudioDeviceFactory::NewInputDevice(render_view_id), |
+ params.channel_layout(), |
+ static_cast<float>(params.sample_rate())); |
} |
void WebRtcAudioCapturer::Start() { |
@@ -352,17 +358,22 @@ void WebRtcAudioCapturer::Start() { |
void WebRtcAudioCapturer::Stop() { |
DVLOG(1) << "WebRtcAudioCapturer::Stop()"; |
scoped_refptr<media::AudioCapturerSource> source; |
+ TrackList tracks; |
{ |
base::AutoLock auto_lock(lock_); |
if (!running_) |
return; |
source = source_; |
+ tracks = tracks_; |
running_ = false; |
} |
if (source.get()) |
source->Stop(); |
+ |
+ for (TrackList::const_iterator it = tracks.begin(); it != tracks.end(); ++it) |
+ (*it)->Reset(); |
} |
void WebRtcAudioCapturer::SetVolume(int volume) { |
@@ -426,11 +437,6 @@ void WebRtcAudioCapturer::Capture(media::AudioBus* audio_source, |
tracks = tracks_; |
} |
- // Deliver captured data to source provider, which stores the data into FIFO |
- // for WebAudio to fetch. |
- source_provider_->DeliverData(audio_source, audio_delay_milliseconds, |
- current_volume, key_pressed); |
- |
// Feed the data to the tracks. |
for (TrackList::const_iterator it = tracks.begin(); |
it != tracks.end(); |
@@ -478,4 +484,12 @@ int WebRtcAudioCapturer::GetBufferSize(int sample_rate) const { |
return (sample_rate / 100); |
} |
+void WebRtcAudioCapturer::GetAudioProcessingParams( |
+ int* delay_ms, int* volume, bool* key_pressed) { |
+ base::AutoLock auto_lock(lock_); |
+ *delay_ms = audio_delay_ms_; |
+ *volume = volume_; |
+ *key_pressed = key_pressed_; |
+} |
+ |
} // namespace content |