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_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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 } | 65 } |
66 | 66 |
67 int32_t WebRtcAudioDeviceImpl::Release() { | 67 int32_t WebRtcAudioDeviceImpl::Release() { |
68 int ret = base::subtle::Barrier_AtomicIncrement(&ref_count_, -1); | 68 int ret = base::subtle::Barrier_AtomicIncrement(&ref_count_, -1); |
69 if (ret == 0) { | 69 if (ret == 0) { |
70 delete this; | 70 delete this; |
71 } | 71 } |
72 return ret; | 72 return ret; |
73 } | 73 } |
74 | 74 |
75 size_t WebRtcAudioDeviceImpl::Render( | 75 int WebRtcAudioDeviceImpl::Render( |
76 const std::vector<float*>& audio_data, | 76 const std::vector<float*>& audio_data, |
77 size_t number_of_frames, | 77 int number_of_frames, |
78 size_t audio_delay_milliseconds) { | 78 int audio_delay_milliseconds) { |
79 DCHECK_LE(number_of_frames, output_buffer_size()); | 79 DCHECK_LE(number_of_frames, output_buffer_size()); |
80 | 80 |
81 { | 81 { |
82 base::AutoLock auto_lock(lock_); | 82 base::AutoLock auto_lock(lock_); |
83 // Store the reported audio delay locally. | 83 // Store the reported audio delay locally. |
84 output_delay_ms_ = audio_delay_milliseconds; | 84 output_delay_ms_ = audio_delay_milliseconds; |
85 } | 85 } |
86 | 86 |
87 const int channels = audio_data.size(); | 87 const int channels = audio_data.size(); |
88 DCHECK_LE(channels, output_channels()); | 88 DCHECK_LE(channels, output_channels()); |
89 | 89 |
90 int samples_per_sec = output_sample_rate(); | 90 int samples_per_sec = output_sample_rate(); |
91 if (samples_per_sec == 44100) { | 91 if (samples_per_sec == 44100) { |
92 // Even if the hardware runs at 44.1kHz, we use 44.0 internally. | 92 // Even if the hardware runs at 44.1kHz, we use 44.0 internally. |
93 samples_per_sec = 44000; | 93 samples_per_sec = 44000; |
94 } | 94 } |
95 uint32_t samples_per_10_msec = (samples_per_sec / 100); | 95 int samples_per_10_msec = (samples_per_sec / 100); |
96 const int bytes_per_10_msec = | 96 const int bytes_per_10_msec = |
97 channels * samples_per_10_msec * bytes_per_sample_; | 97 channels * samples_per_10_msec * bytes_per_sample_; |
98 | 98 |
99 uint32_t num_audio_samples = 0; | 99 uint32_t num_audio_samples = 0; |
100 size_t accumulated_audio_samples = 0; | 100 int accumulated_audio_samples = 0; |
101 | 101 |
102 char* audio_byte_buffer = reinterpret_cast<char*>(output_buffer_.get()); | 102 char* audio_byte_buffer = reinterpret_cast<char*>(output_buffer_.get()); |
103 | 103 |
104 // Get audio samples in blocks of 10 milliseconds from the registered | 104 // Get audio samples in blocks of 10 milliseconds from the registered |
105 // webrtc::AudioTransport source. Keep reading until our internal buffer | 105 // webrtc::AudioTransport source. Keep reading until our internal buffer |
106 // is full. | 106 // is full. |
107 while (accumulated_audio_samples < number_of_frames) { | 107 while (accumulated_audio_samples < number_of_frames) { |
108 // Get 10ms and append output to temporary byte buffer. | 108 // Get 10ms and append output to temporary byte buffer. |
109 audio_transport_callback_->NeedMorePlayData(samples_per_10_msec, | 109 audio_transport_callback_->NeedMorePlayData(samples_per_10_msec, |
110 bytes_per_sample_, | 110 bytes_per_sample_, |
(...skipping 19 matching lines...) Expand all Loading... |
130 return number_of_frames; | 130 return number_of_frames; |
131 } | 131 } |
132 | 132 |
133 void WebRtcAudioDeviceImpl::OnRenderError() { | 133 void WebRtcAudioDeviceImpl::OnRenderError() { |
134 DCHECK_EQ(MessageLoop::current(), ChildProcess::current()->io_message_loop()); | 134 DCHECK_EQ(MessageLoop::current(), ChildProcess::current()->io_message_loop()); |
135 // TODO(henrika): Implement error handling. | 135 // TODO(henrika): Implement error handling. |
136 LOG(ERROR) << "OnRenderError()"; | 136 LOG(ERROR) << "OnRenderError()"; |
137 } | 137 } |
138 | 138 |
139 void WebRtcAudioDeviceImpl::Capture(const std::vector<float*>& audio_data, | 139 void WebRtcAudioDeviceImpl::Capture(const std::vector<float*>& audio_data, |
140 size_t number_of_frames, | 140 int number_of_frames, |
141 size_t audio_delay_milliseconds, | 141 int audio_delay_milliseconds, |
142 double volume) { | 142 double volume) { |
143 DCHECK_LE(number_of_frames, input_buffer_size()); | 143 DCHECK_LE(number_of_frames, input_buffer_size()); |
144 #if defined(OS_WIN) || defined(OS_MACOSX) | 144 #if defined(OS_WIN) || defined(OS_MACOSX) |
145 DCHECK_LE(volume, 1.0); | 145 DCHECK_LE(volume, 1.0); |
146 #elif defined(OS_LINUX) || defined(OS_OPENBSD) | 146 #elif defined(OS_LINUX) || defined(OS_OPENBSD) |
147 // We have a special situation on Linux where the microphone volume can be | 147 // We have a special situation on Linux where the microphone volume can be |
148 // "higher than maximum". The input volume slider in the sound preference | 148 // "higher than maximum". The input volume slider in the sound preference |
149 // allows the user to set a scaling that is higher than 100%. It means that | 149 // allows the user to set a scaling that is higher than 100%. It means that |
150 // even if the reported maximum levels is N, the actual microphone level can | 150 // even if the reported maximum levels is N, the actual microphone level can |
151 // go up to 1.5*N and that corresponds to a normalized |volume| of 1.5. | 151 // go up to 1.5*N and that corresponds to a normalized |volume| of 1.5. |
(...skipping 19 matching lines...) Expand all Loading... |
171 number_of_frames); | 171 number_of_frames); |
172 | 172 |
173 int samples_per_sec = input_sample_rate(); | 173 int samples_per_sec = input_sample_rate(); |
174 if (samples_per_sec == 44100) { | 174 if (samples_per_sec == 44100) { |
175 // Even if the hardware runs at 44.1kHz, we use 44.0 internally. | 175 // Even if the hardware runs at 44.1kHz, we use 44.0 internally. |
176 samples_per_sec = 44000; | 176 samples_per_sec = 44000; |
177 } | 177 } |
178 const int samples_per_10_msec = (samples_per_sec / 100); | 178 const int samples_per_10_msec = (samples_per_sec / 100); |
179 const int bytes_per_10_msec = | 179 const int bytes_per_10_msec = |
180 channels * samples_per_10_msec * bytes_per_sample_; | 180 channels * samples_per_10_msec * bytes_per_sample_; |
181 size_t accumulated_audio_samples = 0; | 181 int accumulated_audio_samples = 0; |
| 182 |
182 char* audio_byte_buffer = reinterpret_cast<char*>(input_buffer_.get()); | 183 char* audio_byte_buffer = reinterpret_cast<char*>(input_buffer_.get()); |
183 | 184 |
184 // Map internal volume range of [0.0, 1.0] into [0, 255] used by the | 185 // Map internal volume range of [0.0, 1.0] into [0, 255] used by the |
185 // webrtc::VoiceEngine. | 186 // webrtc::VoiceEngine. |
186 uint32_t current_mic_level = static_cast<uint32_t>(volume * kMaxVolumeLevel); | 187 uint32_t current_mic_level = static_cast<uint32_t>(volume * kMaxVolumeLevel); |
187 | 188 |
188 // Write audio samples in blocks of 10 milliseconds to the registered | 189 // Write audio samples in blocks of 10 milliseconds to the registered |
189 // webrtc::AudioTransport sink. Keep writing until our internal byte | 190 // webrtc::AudioTransport sink. Keep writing until our internal byte |
190 // buffer is empty. | 191 // buffer is empty. |
191 while (accumulated_audio_samples < number_of_frames) { | 192 while (accumulated_audio_samples < number_of_frames) { |
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 } | 1038 } |
1038 | 1039 |
1039 int32_t WebRtcAudioDeviceImpl::GetLoudspeakerStatus(bool* enabled) const { | 1040 int32_t WebRtcAudioDeviceImpl::GetLoudspeakerStatus(bool* enabled) const { |
1040 NOTIMPLEMENTED(); | 1041 NOTIMPLEMENTED(); |
1041 return -1; | 1042 return -1; |
1042 } | 1043 } |
1043 | 1044 |
1044 void WebRtcAudioDeviceImpl::SetSessionId(int session_id) { | 1045 void WebRtcAudioDeviceImpl::SetSessionId(int session_id) { |
1045 session_id_ = session_id; | 1046 session_id_ = session_id; |
1046 } | 1047 } |
OLD | NEW |