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 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
432 TrackList::ItemList tracks_to_notify_format; | 432 TrackList::ItemList tracks_to_notify_format; |
433 int current_volume = 0; | 433 int current_volume = 0; |
434 base::TimeDelta audio_delay; | 434 base::TimeDelta audio_delay; |
435 scoped_refptr<MediaStreamAudioProcessor> audio_processor; | 435 scoped_refptr<MediaStreamAudioProcessor> audio_processor; |
436 bool need_audio_processing = true; | 436 bool need_audio_processing = true; |
437 { | 437 { |
438 base::AutoLock auto_lock(lock_); | 438 base::AutoLock auto_lock(lock_); |
439 if (!running_) | 439 if (!running_) |
440 return; | 440 return; |
441 | 441 |
442 // Map internal volume range of [0.0, 1.0] into [0, 255] used by the | 442 // Map internal volume range of [0.0, 1.0] into [0, 255] used by the |
ajm
2014/01/22 21:50:55
FYI, I'd like to change the AudioProcessing interf
no longer working on chromium
2014/01/23 12:46:08
I will be happy to do the chromium change once APM
| |
443 // webrtc::VoiceEngine. webrtc::VoiceEngine will handle the case when the | 443 // webrtc::VoiceEngine. webrtc::VoiceEngine will handle the case when the |
444 // volume is higher than 255. | 444 // volume is higher than 255. |
445 volume_ = static_cast<int>((volume * MaxVolume()) + 0.5); | 445 volume_ = static_cast<int>((volume * MaxVolume()) + 0.5); |
446 current_volume = volume_; | 446 current_volume = volume_; |
447 audio_delay = base::TimeDelta::FromMilliseconds(audio_delay_milliseconds); | 447 audio_delay = base::TimeDelta::FromMilliseconds(audio_delay_milliseconds); |
448 audio_delay_ = audio_delay; | 448 audio_delay_ = audio_delay; |
449 key_pressed_ = key_pressed; | 449 key_pressed_ = key_pressed; |
450 tracks = tracks_.Items(); | 450 tracks = tracks_.Items(); |
451 tracks_.RetrieveAndClearTags(&tracks_to_notify_format); | 451 tracks_.RetrieveAndClearTags(&tracks_to_notify_format); |
452 audio_processor = audio_processor_; | 452 audio_processor = audio_processor_; |
(...skipping 18 matching lines...) Expand all Loading... | |
471 it != tracks_to_notify_format.end(); ++it) { | 471 it != tracks_to_notify_format.end(); ++it) { |
472 (*it)->OnSetFormat(output_params); | 472 (*it)->OnSetFormat(output_params); |
473 } | 473 } |
474 | 474 |
475 // Push the data to the processor for processing. | 475 // Push the data to the processor for processing. |
476 audio_processor->PushCaptureData(audio_source); | 476 audio_processor->PushCaptureData(audio_source); |
477 | 477 |
478 // Process and consume the data in the processor until there is not enough | 478 // Process and consume the data in the processor until there is not enough |
479 // data in the processor. | 479 // data in the processor. |
480 int16* output = NULL; | 480 int16* output = NULL; |
481 int new_volume = 0; | |
481 while (audio_processor->ProcessAndConsumeData( | 482 while (audio_processor->ProcessAndConsumeData( |
482 audio_delay, current_volume, key_pressed, &output)) { | 483 audio_delay, current_volume, key_pressed, &new_volume, &output)) { |
483 // Feed the post-processed data to the tracks. | 484 // Feed the post-processed data to the tracks. |
484 for (TrackList::ItemList::const_iterator it = tracks.begin(); | 485 for (TrackList::ItemList::const_iterator it = tracks.begin(); |
485 it != tracks.end(); ++it) { | 486 it != tracks.end(); ++it) { |
486 (*it)->Capture(output, audio_delay, current_volume, key_pressed, | 487 (*it)->Capture(output, audio_delay, current_volume, key_pressed, |
487 need_audio_processing); | 488 need_audio_processing); |
488 } | 489 } |
489 // TODO(xians): Apply the new volume after AGC is working with the | 490 |
490 // MediaStreamAudioProcessor. | 491 // TODO(xians): Check with ajm@ if we should set curret_volume to |
tommi (sloooow) - chröme
2014/01/21 15:06:20
current_volume
no longer working on chromium
2014/01/23 12:46:08
comment was removed.
| |
492 // new_volume to avoid setting the volume twice. | |
ajm
2014/01/22 21:50:55
Yes, you should update current_volume.
no longer working on chromium
2014/01/23 12:46:08
Done.
| |
493 if (new_volume) | |
494 SetVolume(new_volume); | |
491 } | 495 } |
492 } | 496 } |
493 | 497 |
494 void WebRtcAudioCapturer::OnCaptureError() { | 498 void WebRtcAudioCapturer::OnCaptureError() { |
495 NOTIMPLEMENTED(); | 499 NOTIMPLEMENTED(); |
496 } | 500 } |
497 | 501 |
498 media::AudioParameters WebRtcAudioCapturer::source_audio_parameters() const { | 502 media::AudioParameters WebRtcAudioCapturer::source_audio_parameters() const { |
499 base::AutoLock auto_lock(lock_); | 503 base::AutoLock auto_lock(lock_); |
500 return audio_processor_ ? | 504 return audio_processor_ ? |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
575 const scoped_refptr<media::AudioCapturerSource>& source, | 579 const scoped_refptr<media::AudioCapturerSource>& source, |
576 media::AudioParameters params) { | 580 media::AudioParameters params) { |
577 // Create a new audio stream as source which uses the new source. | 581 // Create a new audio stream as source which uses the new source. |
578 SetCapturerSource(source, params.channel_layout(), | 582 SetCapturerSource(source, params.channel_layout(), |
579 static_cast<float>(params.sample_rate()), | 583 static_cast<float>(params.sample_rate()), |
580 params.effects(), | 584 params.effects(), |
581 constraints_); | 585 constraints_); |
582 } | 586 } |
583 | 587 |
584 } // namespace content | 588 } // namespace content |
OLD | NEW |