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

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

Issue 8799011: remove the race related to output_delay_ms_ in ADM and races in the unittests. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: rebase Created 9 years 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 | Annotate | Revision Log
OLDNEW
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
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 number_of_frames); 115 number_of_frames);
113 } 116 }
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 int output_delay_ms = 0;
123 input_delay_ms_ = audio_delay_milliseconds; 126 {
127 base::AutoLock auto_lock(lock_);
128 // Store the reported audio delay locally.
129 input_delay_ms_ = audio_delay_milliseconds;
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
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 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 audio_input_device_->SetDevice(session_id_); 643 audio_input_device_->SetDevice(session_id_);
636 audio_input_device_->Start(); 644 audio_input_device_->Start();
637 recording_ = true; 645 recording_ = true;
638 return 0; 646 return 0;
639 } 647 }
640 648
641 int32_t WebRtcAudioDeviceImpl::StopRecording() { 649 int32_t WebRtcAudioDeviceImpl::StopRecording() {
642 DVLOG(1) << "StopRecording()"; 650 DVLOG(1) << "StopRecording()";
643 DCHECK(audio_input_device_); 651 DCHECK(audio_input_device_);
644 652
653 {
654 base::AutoLock auto_lock(lock_);
655 if (!recording_) {
656 // webrtc::VoiceEngine assumes that it is OK to call Stop() just in case.
657 return 0;
658 }
659 }
660
661 audio_input_device_->Stop();
662
645 base::AutoLock auto_lock(lock_); 663 base::AutoLock auto_lock(lock_);
646 if (!recording_) {
647 // webrtc::VoiceEngine assumes that it is OK to call Stop() just in case.
648 return 0;
649 }
650 audio_input_device_->Stop();
651 recording_ = false; 664 recording_ = false;
652 return 0; 665 return 0;
653 } 666 }
654 667
655 bool WebRtcAudioDeviceImpl::Recording() const { 668 bool WebRtcAudioDeviceImpl::Recording() const {
656 return recording_; 669 return recording_;
657 } 670 }
658 671
659 int32_t WebRtcAudioDeviceImpl::SetAGC(bool enable) { 672 int32_t WebRtcAudioDeviceImpl::SetAGC(bool enable) {
660 DVLOG(2) << "WARNING: WebRtcAudioDeviceImpl::SetAGC() " << "NOT IMPLEMENTED"; 673 DVLOG(2) << "WARNING: WebRtcAudioDeviceImpl::SetAGC() " << "NOT IMPLEMENTED";
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 } 896 }
884 897
885 int32_t WebRtcAudioDeviceImpl::PlayoutBuffer(BufferType* type, 898 int32_t WebRtcAudioDeviceImpl::PlayoutBuffer(BufferType* type,
886 uint16_t* size_ms) const { 899 uint16_t* size_ms) const {
887 NOTIMPLEMENTED(); 900 NOTIMPLEMENTED();
888 return -1; 901 return -1;
889 } 902 }
890 903
891 int32_t WebRtcAudioDeviceImpl::PlayoutDelay(uint16_t* delay_ms) const { 904 int32_t WebRtcAudioDeviceImpl::PlayoutDelay(uint16_t* delay_ms) const {
892 // Report the cached output delay value. 905 // Report the cached output delay value.
906 base::AutoLock auto_lock(lock_);
893 *delay_ms = static_cast<uint16_t>(output_delay_ms_); 907 *delay_ms = static_cast<uint16_t>(output_delay_ms_);
894 return 0; 908 return 0;
895 } 909 }
896 910
897 int32_t WebRtcAudioDeviceImpl::RecordingDelay(uint16_t* delay_ms) const { 911 int32_t WebRtcAudioDeviceImpl::RecordingDelay(uint16_t* delay_ms) const {
898 // Report the cached output delay value. 912 // Report the cached output delay value.
913 base::AutoLock auto_lock(lock_);
899 *delay_ms = static_cast<uint16_t>(input_delay_ms_); 914 *delay_ms = static_cast<uint16_t>(input_delay_ms_);
900 return 0; 915 return 0;
901 } 916 }
902 917
903 int32_t WebRtcAudioDeviceImpl::CPULoad(uint16_t* load) const { 918 int32_t WebRtcAudioDeviceImpl::CPULoad(uint16_t* load) const {
904 NOTIMPLEMENTED(); 919 NOTIMPLEMENTED();
905 return -1; 920 return -1;
906 } 921 }
907 922
908 int32_t WebRtcAudioDeviceImpl::StartRawOutputFileRecording( 923 int32_t WebRtcAudioDeviceImpl::StartRawOutputFileRecording(
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 } 981 }
967 982
968 int32_t WebRtcAudioDeviceImpl::GetLoudspeakerStatus(bool* enabled) const { 983 int32_t WebRtcAudioDeviceImpl::GetLoudspeakerStatus(bool* enabled) const {
969 NOTIMPLEMENTED(); 984 NOTIMPLEMENTED();
970 return -1; 985 return -1;
971 } 986 }
972 987
973 void WebRtcAudioDeviceImpl::SetSessionId(int session_id) { 988 void WebRtcAudioDeviceImpl::SetSessionId(int session_id) {
974 session_id_ = session_id; 989 session_id_ = session_id;
975 } 990 }
OLDNEW
« no previous file with comments | « content/renderer/media/webrtc_audio_device_impl.h ('k') | content/renderer/media/webrtc_audio_device_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698