Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: content/renderer/media/webrtc_audio_capturer.cc

Issue 185413009: Implements the GetSignalLevel and GetStats interface for the local audio track. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebased https://codereview.chromium.org/178223013 and used scope_refpt Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 need_audio_processing); 61 need_audio_processing);
62 } 62 }
63 } 63 }
64 64
65 void OnSetFormat(const media::AudioParameters& params) { 65 void OnSetFormat(const media::AudioParameters& params) {
66 base::AutoLock lock(lock_); 66 base::AutoLock lock(lock_);
67 if (delegate_) 67 if (delegate_)
68 delegate_->OnSetFormat(params); 68 delegate_->OnSetFormat(params);
69 } 69 }
70 70
71 void SetAudioProcessor(
72 const scoped_refptr<MediaStreamAudioProcessor>& processor) {
73 base::AutoLock lock(lock_);
74 if (delegate_)
75 delegate_->SetAudioProcessor(processor);
76 }
77
71 void Reset() { 78 void Reset() {
72 base::AutoLock lock(lock_); 79 base::AutoLock lock(lock_);
73 delegate_ = NULL; 80 delegate_ = NULL;
74 } 81 }
75 82
76 void Stop() { 83 void Stop() {
77 base::AutoLock lock(lock_); 84 base::AutoLock lock(lock_);
78 DCHECK(delegate_); 85 DCHECK(delegate_);
79 86
80 // This can be reentrant so reset |delegate_| before calling out. 87 // This can be reentrant so reset |delegate_| before calling out.
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 // Dispatch the new parameters both to the sink(s) and to the new source, 296 // Dispatch the new parameters both to the sink(s) and to the new source,
290 // also apply the new |constraints|. 297 // also apply the new |constraints|.
291 // The idea is to get rid of any dependency of the microphone parameters 298 // The idea is to get rid of any dependency of the microphone parameters
292 // which would normally be used by default. 299 // which would normally be used by default.
293 // bits_per_sample is always 16 for now. 300 // bits_per_sample is always 16 for now.
294 int buffer_size = GetBufferSize(sample_rate); 301 int buffer_size = GetBufferSize(sample_rate);
295 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 302 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
296 channel_layout, 0, sample_rate, 303 channel_layout, 0, sample_rate,
297 16, buffer_size, effects); 304 16, buffer_size, effects);
298 scoped_refptr<MediaStreamAudioProcessor> new_audio_processor( 305 scoped_refptr<MediaStreamAudioProcessor> new_audio_processor(
299 new MediaStreamAudioProcessor(params, constraints, effects, 306 new talk_base::RefCountedObject<MediaStreamAudioProcessor>(
300 audio_device_)); 307 params, constraints, effects, audio_device_));
301 { 308 {
302 base::AutoLock auto_lock(lock_); 309 base::AutoLock auto_lock(lock_);
303 audio_processor_ = new_audio_processor; 310 audio_processor_ = new_audio_processor;
304 need_audio_processing_ = NeedsAudioProcessing(constraints, effects); 311 need_audio_processing_ = NeedsAudioProcessing(constraints, effects);
305 312
306 // Notify all tracks about the new format. 313 // Notify all tracks about the new format.
307 tracks_.TagAll(); 314 tracks_.TagAll();
308 } 315 }
309 316
310 if (source.get()) 317 if (source.get())
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 audio_processor->InputFormat().channels()); 470 audio_processor->InputFormat().channels());
464 DCHECK_EQ(audio_source->frames(), 471 DCHECK_EQ(audio_source->frames(),
465 audio_processor->InputFormat().frames_per_buffer()); 472 audio_processor->InputFormat().frames_per_buffer());
466 473
467 // Notify the tracks on when the format changes. This will do nothing if 474 // Notify the tracks on when the format changes. This will do nothing if
468 // |tracks_to_notify_format| is empty. 475 // |tracks_to_notify_format| is empty.
469 media::AudioParameters output_params = audio_processor_->OutputFormat(); 476 media::AudioParameters output_params = audio_processor_->OutputFormat();
470 for (TrackList::ItemList::const_iterator it = tracks_to_notify_format.begin(); 477 for (TrackList::ItemList::const_iterator it = tracks_to_notify_format.begin();
471 it != tracks_to_notify_format.end(); ++it) { 478 it != tracks_to_notify_format.end(); ++it) {
472 (*it)->OnSetFormat(output_params); 479 (*it)->OnSetFormat(output_params);
480 (*it)->SetAudioProcessor(audio_processor);
473 } 481 }
474 482
475 // Push the data to the processor for processing. 483 // Push the data to the processor for processing.
476 audio_processor->PushCaptureData(audio_source); 484 audio_processor->PushCaptureData(audio_source);
477 485
478 // Process and consume the data in the processor until there is not enough 486 // Process and consume the data in the processor until there is not enough
479 // data in the processor. 487 // data in the processor.
480 int16* output = NULL; 488 int16* output = NULL;
481 int new_volume = 0; 489 int new_volume = 0;
482 while (audio_processor->ProcessAndConsumeData( 490 while (audio_processor->ProcessAndConsumeData(
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 const scoped_refptr<media::AudioCapturerSource>& source, 568 const scoped_refptr<media::AudioCapturerSource>& source,
561 media::AudioParameters params) { 569 media::AudioParameters params) {
562 // Create a new audio stream as source which uses the new source. 570 // Create a new audio stream as source which uses the new source.
563 SetCapturerSource(source, params.channel_layout(), 571 SetCapturerSource(source, params.channel_layout(),
564 static_cast<float>(params.sample_rate()), 572 static_cast<float>(params.sample_rate()),
565 params.effects(), 573 params.effects(),
566 constraints_); 574 constraints_);
567 } 575 }
568 576
569 } // namespace content 577 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698