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/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 // also apply the new |constraints|. | 324 // also apply the new |constraints|. |
325 // The idea is to get rid of any dependency of the microphone parameters | 325 // The idea is to get rid of any dependency of the microphone parameters |
326 // which would normally be used by default. | 326 // which would normally be used by default. |
327 // bits_per_sample is always 16 for now. | 327 // bits_per_sample is always 16 for now. |
328 int buffer_size = GetBufferSize(sample_rate); | 328 int buffer_size = GetBufferSize(sample_rate); |
329 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 329 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
330 channel_layout, 0, sample_rate, | 330 channel_layout, 0, sample_rate, |
331 16, buffer_size, | 331 16, buffer_size, |
332 device_info_.device.input.effects); | 332 device_info_.device.input.effects); |
333 | 333 |
| 334 // Hack to test. |
| 335 media::AudioParameters params_msap( |
| 336 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 337 media::CHANNEL_LAYOUT_STEREO, |
| 338 0, sample_rate, 16, buffer_size, |
| 339 device_info_.device.input.effects); |
| 340 |
334 { | 341 { |
335 base::AutoLock auto_lock(lock_); | 342 base::AutoLock auto_lock(lock_); |
336 // Notify the |audio_processor_| of the new format. | 343 // Notify the |audio_processor_| of the new format. |
337 audio_processor_->OnCaptureFormatChanged(params); | 344 audio_processor_->OnCaptureFormatChanged(params_msap); |
338 | 345 |
339 MediaAudioConstraints audio_constraints(constraints_, | 346 MediaAudioConstraints audio_constraints(constraints_, |
340 device_info_.device.input.effects); | 347 device_info_.device.input.effects); |
341 need_audio_processing_ = audio_constraints.NeedsAudioProcessing(); | 348 need_audio_processing_ = audio_constraints.NeedsAudioProcessing(); |
342 // Notify all tracks about the new format. | 349 // Notify all tracks about the new format. |
343 tracks_.TagAll(); | 350 tracks_.TagAll(); |
344 } | 351 } |
345 | 352 |
346 if (source.get()) | 353 if (source.get()) |
347 source->Initialize(params, this, session_id()); | 354 source->Initialize(params, this, session_id()); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 tracks_.RetrieveAndClearTags(&tracks_to_notify_format); | 495 tracks_.RetrieveAndClearTags(&tracks_to_notify_format); |
489 | 496 |
490 // Set the flag to turn on the audio processing in PeerConnection level. | 497 // Set the flag to turn on the audio processing in PeerConnection level. |
491 // Note that, we turn off the audio processing in PeerConnection if the | 498 // Note that, we turn off the audio processing in PeerConnection if the |
492 // processor has already processed the data. | 499 // processor has already processed the data. |
493 need_audio_processing = need_audio_processing_ ? | 500 need_audio_processing = need_audio_processing_ ? |
494 !MediaStreamAudioProcessor::IsAudioTrackProcessingEnabled() : false; | 501 !MediaStreamAudioProcessor::IsAudioTrackProcessingEnabled() : false; |
495 } | 502 } |
496 | 503 |
497 DCHECK(audio_processor_->InputFormat().IsValid()); | 504 DCHECK(audio_processor_->InputFormat().IsValid()); |
498 DCHECK_EQ(audio_source->channels(), | 505 // DCHECK_EQ(audio_source->channels(), |
499 audio_processor_->InputFormat().channels()); | 506 // audio_processor_->InputFormat().channels()); |
500 DCHECK_EQ(audio_source->frames(), | 507 DCHECK_EQ(audio_source->frames(), |
501 audio_processor_->InputFormat().frames_per_buffer()); | 508 audio_processor_->InputFormat().frames_per_buffer()); |
502 | 509 |
| 510 scoped_ptr<media::AudioBus> audio_source_2ch = |
| 511 media::AudioBus::CreateWrapper(2); |
| 512 audio_source_2ch->SetChannelData(0, audio_source->channel(0)); |
| 513 audio_source_2ch->SetChannelData(1, audio_source->channel(1)); |
| 514 audio_source_2ch->set_frames(audio_source->frames()); |
| 515 |
503 // Notify the tracks on when the format changes. This will do nothing if | 516 // Notify the tracks on when the format changes. This will do nothing if |
504 // |tracks_to_notify_format| is empty. | 517 // |tracks_to_notify_format| is empty. |
505 media::AudioParameters output_params = audio_processor_->OutputFormat(); | 518 media::AudioParameters output_params = audio_processor_->OutputFormat(); |
| 519 // LOG(ERROR) << "***** LAYOUT: " << output_params.channel_layout(); |
506 for (TrackList::ItemList::const_iterator it = tracks_to_notify_format.begin(); | 520 for (TrackList::ItemList::const_iterator it = tracks_to_notify_format.begin(); |
507 it != tracks_to_notify_format.end(); ++it) { | 521 it != tracks_to_notify_format.end(); ++it) { |
508 (*it)->OnSetFormat(output_params); | 522 (*it)->OnSetFormat(output_params); |
509 (*it)->SetAudioProcessor(audio_processor_); | 523 (*it)->SetAudioProcessor(audio_processor_); |
510 } | 524 } |
511 | 525 |
| 526 // LOG(ERROR) << "***** FRAMES = " << audio_source->frames(); |
| 527 // LOG(ERROR) << "***** FRAMES 2ch = " << audio_source_2ch->frames(); |
| 528 |
512 if ((base::TimeTicks::Now() - last_audio_level_log_time_).InSeconds() > | 529 if ((base::TimeTicks::Now() - last_audio_level_log_time_).InSeconds() > |
513 kPowerMonitorLogIntervalSeconds) { | 530 kPowerMonitorLogIntervalSeconds) { |
514 audio_power_monitor_.Scan(*audio_source, audio_source->frames()); | 531 audio_power_monitor_.Scan(*audio_source, audio_source->frames()); |
515 | 532 |
516 last_audio_level_log_time_ = base::TimeTicks::Now(); | 533 last_audio_level_log_time_ = base::TimeTicks::Now(); |
517 | 534 |
518 std::pair<float, bool> result = | 535 std::pair<float, bool> result = |
519 audio_power_monitor_.ReadCurrentPowerAndClip(); | 536 audio_power_monitor_.ReadCurrentPowerAndClip(); |
520 WebRtcLogMessage(base::StringPrintf( | 537 WebRtcLogMessage(base::StringPrintf( |
521 "WAC::Capture: current_audio_power=%.2fdBFS.", result.first)); | 538 "WAC::Capture: current_audio_power=%.2fdBFS.", result.first)); |
522 | 539 |
523 audio_power_monitor_.Reset(); | 540 audio_power_monitor_.Reset(); |
524 } | 541 } |
525 | 542 |
526 // Push the data to the processor for processing. | 543 // Push the data to the processor for processing. |
527 audio_processor_->PushCaptureData(audio_source); | 544 // audio_processor_->PushCaptureData(audio_source); |
| 545 audio_processor_->PushCaptureData(audio_source_2ch.get()); |
528 | 546 |
529 // Process and consume the data in the processor until there is not enough | 547 // Process and consume the data in the processor until there is not enough |
530 // data in the processor. | 548 // data in the processor. |
531 int16* output = NULL; | 549 int16* output = NULL; |
532 int new_volume = 0; | 550 int new_volume = 0; |
533 while (audio_processor_->ProcessAndConsumeData( | 551 while (audio_processor_->ProcessAndConsumeData( |
534 audio_delay, current_volume, key_pressed, &new_volume, &output)) { | 552 audio_delay, current_volume, key_pressed, &new_volume, &output)) { |
535 // Feed the post-processed data to the tracks. | 553 // Feed the post-processed data to the tracks. |
536 for (TrackList::ItemList::const_iterator it = tracks.begin(); | 554 for (TrackList::ItemList::const_iterator it = tracks.begin(); |
537 it != tracks.end(); ++it) { | 555 it != tracks.end(); ++it) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 | 627 |
610 void WebRtcAudioCapturer::SetCapturerSourceForTesting( | 628 void WebRtcAudioCapturer::SetCapturerSourceForTesting( |
611 const scoped_refptr<media::AudioCapturerSource>& source, | 629 const scoped_refptr<media::AudioCapturerSource>& source, |
612 media::AudioParameters params) { | 630 media::AudioParameters params) { |
613 // Create a new audio stream as source which uses the new source. | 631 // Create a new audio stream as source which uses the new source. |
614 SetCapturerSource(source, params.channel_layout(), | 632 SetCapturerSource(source, params.channel_layout(), |
615 static_cast<float>(params.sample_rate())); | 633 static_cast<float>(params.sample_rate())); |
616 } | 634 } |
617 | 635 |
618 } // namespace content | 636 } // namespace content |
OLD | NEW |