Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_device_impl.h" | 5 #include "content/renderer/media/webrtc_audio_device_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/win/windows_version.h" | 9 #include "base/win/windows_version.h" |
| 10 #include "content/renderer/media/audio_hardware.h" | 10 #include "content/renderer/media/audio_hardware.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 } | 58 } |
| 59 return ret; | 59 return ret; |
| 60 } | 60 } |
| 61 | 61 |
| 62 void WebRtcAudioDeviceImpl::Render( | 62 void WebRtcAudioDeviceImpl::Render( |
| 63 const std::vector<float*>& audio_data, | 63 const std::vector<float*>& audio_data, |
| 64 size_t number_of_frames, | 64 size_t number_of_frames, |
| 65 size_t audio_delay_milliseconds) { | 65 size_t audio_delay_milliseconds) { |
| 66 DCHECK_LE(number_of_frames, output_buffer_size_); | 66 DCHECK_LE(number_of_frames, output_buffer_size_); |
| 67 | 67 |
| 68 // Store the reported audio delay locally. | 68 { |
| 69 output_delay_ms_ = audio_delay_milliseconds; | 69 base::AutoLock auto_lock(lock_); |
| 70 // Store the reported audio delay locally. | |
| 71 output_delay_ms_ = audio_delay_milliseconds; | |
| 72 } | |
| 70 | 73 |
| 71 const int channels = audio_data.size(); | 74 const int channels = audio_data.size(); |
| 72 DCHECK_LE(channels, output_channels_); | 75 DCHECK_LE(channels, output_channels_); |
| 73 | 76 |
| 74 int samples_per_sec = static_cast<int>(output_sample_rate_); | 77 int samples_per_sec = static_cast<int>(output_sample_rate_); |
| 75 if (samples_per_sec == 44100) { | 78 if (samples_per_sec == 44100) { |
| 76 // Even if the hardware runs at 44.1kHz, we use 44.0 internally. | 79 // Even if the hardware runs at 44.1kHz, we use 44.0 internally. |
| 77 samples_per_sec = 44000; | 80 samples_per_sec = 44000; |
| 78 } | 81 } |
| 79 uint32_t samples_per_10_msec = (samples_per_sec / 100); | 82 uint32_t samples_per_10_msec = (samples_per_sec / 100); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 } | 117 } |
| 115 | 118 |
| 116 void WebRtcAudioDeviceImpl::Capture( | 119 void WebRtcAudioDeviceImpl::Capture( |
| 117 const std::vector<float*>& audio_data, | 120 const std::vector<float*>& audio_data, |
| 118 size_t number_of_frames, | 121 size_t number_of_frames, |
| 119 size_t audio_delay_milliseconds) { | 122 size_t audio_delay_milliseconds) { |
| 120 DCHECK_LE(number_of_frames, input_buffer_size_); | 123 DCHECK_LE(number_of_frames, input_buffer_size_); |
| 121 | 124 |
| 122 // Store the reported audio delay locally. | 125 // Store the reported audio delay locally. |
| 123 input_delay_ms_ = audio_delay_milliseconds; | 126 input_delay_ms_ = audio_delay_milliseconds; |
| 127 int output_delay_ms = 0; | |
| 128 { | |
| 129 base::AutoLock auto_lock(lock_); | |
| 130 output_delay_ms = output_delay_ms_; | |
| 131 } | |
| 124 | 132 |
| 125 const int channels = audio_data.size(); | 133 const int channels = audio_data.size(); |
| 126 DCHECK_LE(channels, input_channels_); | 134 DCHECK_LE(channels, input_channels_); |
| 127 uint32_t new_mic_level = 0; | 135 uint32_t new_mic_level = 0; |
| 128 | 136 |
| 129 // Interleave, scale, and clip input to int16 and store result in | 137 // Interleave, scale, and clip input to int16 and store result in |
| 130 // a local byte buffer. | 138 // a local byte buffer. |
| 131 media::InterleaveFloatToInt16(audio_data, | 139 media::InterleaveFloatToInt16(audio_data, |
| 132 input_buffer_.get(), | 140 input_buffer_.get(), |
| 133 number_of_frames); | 141 number_of_frames); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 149 // buffer is empty. | 157 // buffer is empty. |
| 150 while (accumulated_audio_samples < number_of_frames) { | 158 while (accumulated_audio_samples < number_of_frames) { |
| 151 // Deliver 10ms of recorded PCM audio. | 159 // Deliver 10ms of recorded PCM audio. |
| 152 // TODO(henrika): add support for analog AGC? | 160 // TODO(henrika): add support for analog AGC? |
| 153 audio_transport_callback_->RecordedDataIsAvailable( | 161 audio_transport_callback_->RecordedDataIsAvailable( |
| 154 audio_byte_buffer, | 162 audio_byte_buffer, |
| 155 samples_per_10_msec, | 163 samples_per_10_msec, |
| 156 bytes_per_sample_, | 164 bytes_per_sample_, |
| 157 channels, | 165 channels, |
| 158 samples_per_sec, | 166 samples_per_sec, |
| 159 input_delay_ms_ + output_delay_ms_, | 167 input_delay_ms_ + output_delay_ms, |
| 160 0, // clock_drift | 168 0, // clock_drift |
| 161 0, // current_mic_level | 169 0, // current_mic_level |
| 162 new_mic_level); // not used | 170 new_mic_level); // not used |
| 163 accumulated_audio_samples += samples_per_10_msec; | 171 accumulated_audio_samples += samples_per_10_msec; |
| 164 audio_byte_buffer += bytes_per_10_msec; | 172 audio_byte_buffer += bytes_per_10_msec; |
| 165 } | 173 } |
| 166 } | 174 } |
| 167 | 175 |
| 168 void WebRtcAudioDeviceImpl::OnDeviceStarted(const std::string& device_id) { | 176 void WebRtcAudioDeviceImpl::OnDeviceStarted(const std::string& device_id) { |
| 169 VLOG(1) << "OnDeviceStarted (device_id=" << device_id << ")"; | 177 VLOG(1) << "OnDeviceStarted (device_id=" << device_id << ")"; |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 590 return 0; | 598 return 0; |
| 591 } | 599 } |
| 592 | 600 |
| 593 int32_t WebRtcAudioDeviceImpl::StopPlayout() { | 601 int32_t WebRtcAudioDeviceImpl::StopPlayout() { |
| 594 DVLOG(1) << "StopPlayout()"; | 602 DVLOG(1) << "StopPlayout()"; |
| 595 DCHECK(audio_output_device_); | 603 DCHECK(audio_output_device_); |
| 596 if (!playing_) { | 604 if (!playing_) { |
| 597 // webrtc::VoiceEngine assumes that it is OK to call Stop() just in case. | 605 // webrtc::VoiceEngine assumes that it is OK to call Stop() just in case. |
| 598 return 0; | 606 return 0; |
| 599 } | 607 } |
| 600 playing_ = !audio_output_device_->Stop(); | 608 audio_output_device_->Stop(); |
| 601 return (!playing_ ? 0 : -1); | 609 playing_ = false; |
| 610 return 0; | |
| 602 } | 611 } |
| 603 | 612 |
| 604 bool WebRtcAudioDeviceImpl::Playing() const { | 613 bool WebRtcAudioDeviceImpl::Playing() const { |
| 605 return playing_; | 614 return playing_; |
| 606 } | 615 } |
| 607 | 616 |
| 608 int32_t WebRtcAudioDeviceImpl::StartRecording() { | 617 int32_t WebRtcAudioDeviceImpl::StartRecording() { |
| 609 DVLOG(1) << "StartRecording()"; | 618 DVLOG(1) << "StartRecording()"; |
| 610 #if defined(OS_MACOSX) | 619 #if defined(OS_MACOSX) |
| 611 DLOG(WARNING) << "Real-time recording is not yet fully supported on Mac OS X"; | 620 DLOG(WARNING) << "Real-time recording is not yet fully supported on Mac OS X"; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 634 audio_input_device_->SetDevice(session_id_); | 643 audio_input_device_->SetDevice(session_id_); |
| 635 audio_input_device_->Start(); | 644 audio_input_device_->Start(); |
| 636 recording_ = true; | 645 recording_ = true; |
| 637 return 0; | 646 return 0; |
| 638 } | 647 } |
| 639 | 648 |
| 640 int32_t WebRtcAudioDeviceImpl::StopRecording() { | 649 int32_t WebRtcAudioDeviceImpl::StopRecording() { |
| 641 DVLOG(1) << "StopRecording()"; | 650 DVLOG(1) << "StopRecording()"; |
| 642 DCHECK(audio_input_device_); | 651 DCHECK(audio_input_device_); |
| 643 | 652 |
| 644 base::AutoLock auto_lock(lock_); | 653 { |
| 645 if (!recording_) { | 654 base::AutoLock auto_lock(lock_); |
| 646 // webrtc::VoiceEngine assumes that it is OK to call Stop() just in case. | 655 if (!recording_) { |
| 647 return 0; | 656 // webrtc::VoiceEngine assumes that it is OK to call Stop() just in case. |
| 657 return 0; | |
| 658 } | |
| 648 } | 659 } |
| 649 recording_ = !audio_input_device_->Stop(); | 660 |
| 650 return (!recording_ ? 0 : -1); | 661 audio_input_device_->Stop(); |
| 662 | |
| 663 { | |
|
tommi (sloooow) - chröme
2011/12/05 13:41:04
nit: no need for this scope
no longer working on chromium
2011/12/09 09:48:19
Done.
| |
| 664 base::AutoLock auto_lock(lock_); | |
| 665 recording_ = false; | |
| 666 } | |
| 667 return 0; | |
| 651 } | 668 } |
| 652 | 669 |
| 653 bool WebRtcAudioDeviceImpl::Recording() const { | 670 bool WebRtcAudioDeviceImpl::Recording() const { |
| 654 return recording_; | 671 return recording_; |
| 655 } | 672 } |
| 656 | 673 |
| 657 int32_t WebRtcAudioDeviceImpl::SetAGC(bool enable) { | 674 int32_t WebRtcAudioDeviceImpl::SetAGC(bool enable) { |
| 658 DVLOG(2) << "WARNING: WebRtcAudioDeviceImpl::SetAGC() " << "NOT IMPLEMENTED"; | 675 DVLOG(2) << "WARNING: WebRtcAudioDeviceImpl::SetAGC() " << "NOT IMPLEMENTED"; |
| 659 return -1; | 676 return -1; |
| 660 } | 677 } |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 881 } | 898 } |
| 882 | 899 |
| 883 int32_t WebRtcAudioDeviceImpl::PlayoutBuffer(BufferType* type, | 900 int32_t WebRtcAudioDeviceImpl::PlayoutBuffer(BufferType* type, |
| 884 uint16_t* size_ms) const { | 901 uint16_t* size_ms) const { |
| 885 NOTIMPLEMENTED(); | 902 NOTIMPLEMENTED(); |
| 886 return -1; | 903 return -1; |
| 887 } | 904 } |
| 888 | 905 |
| 889 int32_t WebRtcAudioDeviceImpl::PlayoutDelay(uint16_t* delay_ms) const { | 906 int32_t WebRtcAudioDeviceImpl::PlayoutDelay(uint16_t* delay_ms) const { |
| 890 // Report the cached output delay value. | 907 // Report the cached output delay value. |
| 908 base::AutoLock auto_lock(lock_); | |
| 891 *delay_ms = static_cast<uint16_t>(output_delay_ms_); | 909 *delay_ms = static_cast<uint16_t>(output_delay_ms_); |
| 892 return 0; | 910 return 0; |
| 893 } | 911 } |
| 894 | 912 |
| 895 int32_t WebRtcAudioDeviceImpl::RecordingDelay(uint16_t* delay_ms) const { | 913 int32_t WebRtcAudioDeviceImpl::RecordingDelay(uint16_t* delay_ms) const { |
| 896 // Report the cached output delay value. | 914 // Report the cached output delay value. |
| 897 *delay_ms = static_cast<uint16_t>(input_delay_ms_); | 915 *delay_ms = static_cast<uint16_t>(input_delay_ms_); |
|
henrika (OOO until Aug 14)
2011/12/05 13:56:24
Why no lock here?
no longer working on chromium
2011/12/09 09:48:19
We don't use RecordingDelay() now, but I can add i
no longer working on chromium
2011/12/09 09:48:19
Done.
| |
| 898 return 0; | 916 return 0; |
| 899 } | 917 } |
| 900 | 918 |
| 901 int32_t WebRtcAudioDeviceImpl::CPULoad(uint16_t* load) const { | 919 int32_t WebRtcAudioDeviceImpl::CPULoad(uint16_t* load) const { |
| 902 NOTIMPLEMENTED(); | 920 NOTIMPLEMENTED(); |
| 903 return -1; | 921 return -1; |
| 904 } | 922 } |
| 905 | 923 |
| 906 int32_t WebRtcAudioDeviceImpl::StartRawOutputFileRecording( | 924 int32_t WebRtcAudioDeviceImpl::StartRawOutputFileRecording( |
| 907 const char pcm_file_name_utf8[webrtc::kAdmMaxFileNameSize]) { | 925 const char pcm_file_name_utf8[webrtc::kAdmMaxFileNameSize]) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 964 } | 982 } |
| 965 | 983 |
| 966 int32_t WebRtcAudioDeviceImpl::GetLoudspeakerStatus(bool* enabled) const { | 984 int32_t WebRtcAudioDeviceImpl::GetLoudspeakerStatus(bool* enabled) const { |
| 967 NOTIMPLEMENTED(); | 985 NOTIMPLEMENTED(); |
| 968 return -1; | 986 return -1; |
| 969 } | 987 } |
| 970 | 988 |
| 971 void WebRtcAudioDeviceImpl::SetSessionId(int session_id) { | 989 void WebRtcAudioDeviceImpl::SetSessionId(int session_id) { |
| 972 session_id_ = session_id; | 990 session_id_ = session_id; |
| 973 } | 991 } |
| OLD | NEW |