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

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

Issue 594233002: Strip away the keyboard mic channel if no audio processing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@change_stream_layout_to_kmic
Patch Set: Created 6 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/media_stream_audio_processor.h" 5 #include "content/renderer/media/media_stream_audio_processor.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #if defined(OS_MACOSX) 9 #if defined(OS_MACOSX)
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 220
221 // Reset the |capture_thread_checker_| since the capture data will come from 221 // Reset the |capture_thread_checker_| since the capture data will come from
222 // a new capture thread. 222 // a new capture thread.
223 capture_thread_checker_.DetachFromThread(); 223 capture_thread_checker_.DetachFromThread();
224 } 224 }
225 225
226 void MediaStreamAudioProcessor::PushCaptureData( 226 void MediaStreamAudioProcessor::PushCaptureData(
227 const media::AudioBus* audio_source) { 227 const media::AudioBus* audio_source) {
228 DCHECK(capture_thread_checker_.CalledOnValidThread()); 228 DCHECK(capture_thread_checker_.CalledOnValidThread());
229 229
230 capture_fifo_->Push(audio_source); 230 // If we don't use audio processing we strip any keyboard mic channel before
231 // putting it in the fifo.
232 if (input_format_.channel_layout() ==
no longer working on chromium 2014/09/24 12:41:27 you should move these code to MediaStreamAudioFifo
Henrik Grunell 2014/09/24 20:01:29 Yep, but I need the additional info about layout a
Henrik Grunell 2014/09/26 10:04:27 Changed to what I proposed offline: take source an
233 media::CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC &&
234 !audio_processing_) {
235 scoped_ptr<media::AudioBus> audio_source_stereo =
no longer working on chromium 2014/09/24 12:41:27 use a member in MediaStreamAudioFifo, and set it u
Henrik Grunell 2014/09/26 10:04:27 Done.
236 media::AudioBus::CreateWrapper(2);
237 audio_source_stereo->SetChannelData(
238 0, const_cast<float*>(audio_source->channel(0)));
239 audio_source_stereo->SetChannelData(
240 1, const_cast<float*>(audio_source->channel(1)));
241 audio_source_stereo->set_frames(audio_source->frames());
242 capture_fifo_->Push(audio_source_stereo.get());
243 } else {
244 capture_fifo_->Push(audio_source);
245 }
231 } 246 }
232 247
233 bool MediaStreamAudioProcessor::ProcessAndConsumeData( 248 bool MediaStreamAudioProcessor::ProcessAndConsumeData(
234 base::TimeDelta capture_delay, int volume, bool key_pressed, 249 base::TimeDelta capture_delay, int volume, bool key_pressed,
235 int* new_volume, int16** out) { 250 int* new_volume, int16** out) {
236 DCHECK(capture_thread_checker_.CalledOnValidThread()); 251 DCHECK(capture_thread_checker_.CalledOnValidThread());
237 TRACE_EVENT0("audio", "MediaStreamAudioProcessor::ProcessAndConsumeData"); 252 TRACE_EVENT0("audio", "MediaStreamAudioProcessor::ProcessAndConsumeData");
238 253
239 MediaStreamAudioBus* process_bus; 254 MediaStreamAudioBus* process_bus;
240 if (!capture_fifo_->Consume(&process_bus)) 255 if (!capture_fifo_->Consume(&process_bus))
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 DCHECK(input_format.IsValid()); 474 DCHECK(input_format.IsValid());
460 input_format_ = input_format; 475 input_format_ = input_format;
461 476
462 // TODO(ajm): For now, we assume fixed parameters for the output when audio 477 // TODO(ajm): For now, we assume fixed parameters for the output when audio
463 // processing is enabled, to match the previous behavior. We should either 478 // processing is enabled, to match the previous behavior. We should either
464 // use the input parameters (in which case, audio processing will convert 479 // use the input parameters (in which case, audio processing will convert
465 // at output) or ideally, have a backchannel from the sink to know what 480 // at output) or ideally, have a backchannel from the sink to know what
466 // format it would prefer. 481 // format it would prefer.
467 const int output_sample_rate = audio_processing_ ? 482 const int output_sample_rate = audio_processing_ ?
468 kAudioProcessingSampleRate : input_format.sample_rate(); 483 kAudioProcessingSampleRate : input_format.sample_rate();
469 const media::ChannelLayout output_channel_layout = audio_processing_ ? 484 media::ChannelLayout output_channel_layout = audio_processing_ ?
470 media::GuessChannelLayout(kAudioProcessingNumberOfChannels) : 485 media::GuessChannelLayout(kAudioProcessingNumberOfChannels) :
471 input_format.channel_layout(); 486 input_format.channel_layout();
no longer working on chromium 2014/09/24 12:41:27 can the output_channel_layout be media::CHANNEL_LA
Henrik Grunell 2014/09/24 20:01:29 No.
472 487
473 // webrtc::AudioProcessing requires a 10 ms chunk size. We use this native 488 // webrtc::AudioProcessing requires a 10 ms chunk size. We use this native
474 // size when processing is enabled. When disabled we use the same size as 489 // size when processing is enabled. When disabled we use the same size as
475 // the source if less than 10 ms. 490 // the source if less than 10 ms.
476 // 491 //
477 // TODO(ajm): This conditional buffer size appears to be assuming knowledge of 492 // TODO(ajm): This conditional buffer size appears to be assuming knowledge of
478 // the sink based on the source parameters. PeerConnection sinks seem to want 493 // the sink based on the source parameters. PeerConnection sinks seem to want
479 // 10 ms chunks regardless, while WebAudio sinks want less, and we're assuming 494 // 10 ms chunks regardless, while WebAudio sinks want less, and we're assuming
480 // we can identify WebAudio sinks by the input chunk size. Less fragile would 495 // we can identify WebAudio sinks by the input chunk size. Less fragile would
481 // be to have the sink actually tell us how much it wants (as in the above 496 // be to have the sink actually tell us how much it wants (as in the above
482 // TODO). 497 // TODO).
483 int processing_frames = input_format.sample_rate() / 100; 498 int processing_frames = input_format.sample_rate() / 100;
484 int output_frames = output_sample_rate / 100; 499 int output_frames = output_sample_rate / 100;
485 if (!audio_processing_ && input_format.frames_per_buffer() < output_frames) { 500 if (!audio_processing_ && input_format.frames_per_buffer() < output_frames) {
486 processing_frames = input_format.frames_per_buffer(); 501 processing_frames = input_format.frames_per_buffer();
487 output_frames = processing_frames; 502 output_frames = processing_frames;
488 } 503 }
489 504
505 int capture_fifo_channels = input_format.channels();
506
507 // Special cases for if we have a keyboard mic channel on the input and no
508 // audio processing is used. We will then strip away that channel before
509 // putting it in the fifo. We keep the layout in |input_format_| since that's
510 // what we expect as input to this class.
511 if (input_format.channel_layout() ==
512 media::CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC &&
513 !audio_processing_) {
514 capture_fifo_channels = 2;
515 output_channel_layout = media::CHANNEL_LAYOUT_STEREO;
516 }
517
490 output_format_ = media::AudioParameters( 518 output_format_ = media::AudioParameters(
491 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 519 media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
492 output_channel_layout, 520 output_channel_layout,
493 output_sample_rate, 521 output_sample_rate,
494 16, 522 16,
495 output_frames); 523 output_frames);
496 524
497 capture_fifo_.reset( 525 capture_fifo_.reset(
498 new MediaStreamAudioFifo(input_format.channels(), 526 new MediaStreamAudioFifo(capture_fifo_channels,
no longer working on chromium 2014/09/24 12:41:27 how about modify MediaStreamAudioFifo constructor
Henrik Grunell 2014/09/24 20:01:29 Yes, but the fifo would need to know about the lay
499 input_format.frames_per_buffer(), 527 input_format.frames_per_buffer(),
500 processing_frames)); 528 processing_frames));
501 529
502 if (audio_processing_) { 530 if (audio_processing_) {
503 output_bus_.reset(new MediaStreamAudioBus(output_format_.channels(), 531 output_bus_.reset(new MediaStreamAudioBus(output_format_.channels(),
504 output_frames)); 532 output_frames));
505 } 533 }
506 output_data_.reset(new int16[output_format_.GetBytesPerBuffer() / 534 output_data_.reset(new int16[output_format_.GetBytesPerBuffer() /
507 sizeof(int16)]); 535 sizeof(int16)]);
508 } 536 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 vad->stream_has_voice()); 608 vad->stream_has_voice());
581 base::subtle::Release_Store(&typing_detected_, detected); 609 base::subtle::Release_Store(&typing_detected_, detected);
582 } 610 }
583 611
584 // Return 0 if the volume hasn't been changed, and otherwise the new volume. 612 // Return 0 if the volume hasn't been changed, and otherwise the new volume.
585 return (agc->stream_analog_level() == volume) ? 613 return (agc->stream_analog_level() == volume) ?
586 0 : agc->stream_analog_level(); 614 0 : agc->stream_analog_level();
587 } 615 }
588 616
589 } // namespace content 617 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698