OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 kTimerIntervalInSeconds * rtc::kNumMillisecsPerSec; | 32 kTimerIntervalInSeconds * rtc::kNumMillisecsPerSec; |
33 | 33 |
34 AudioDeviceBuffer::AudioDeviceBuffer() | 34 AudioDeviceBuffer::AudioDeviceBuffer() |
35 : audio_transport_cb_(nullptr), | 35 : audio_transport_cb_(nullptr), |
36 task_queue_(kTimerQueueName), | 36 task_queue_(kTimerQueueName), |
37 timer_has_started_(false), | 37 timer_has_started_(false), |
38 rec_sample_rate_(0), | 38 rec_sample_rate_(0), |
39 play_sample_rate_(0), | 39 play_sample_rate_(0), |
40 rec_channels_(0), | 40 rec_channels_(0), |
41 play_channels_(0), | 41 play_channels_(0), |
42 rec_channel_(AudioDeviceModule::kChannelBoth), | |
43 rec_bytes_per_sample_(0), | 42 rec_bytes_per_sample_(0), |
44 play_bytes_per_sample_(0), | 43 play_bytes_per_sample_(0), |
45 rec_samples_per_10ms_(0), | |
46 rec_bytes_per_10ms_(0), | |
47 play_samples_per_10ms_(0), | |
48 play_bytes_per_10ms_(0), | |
49 current_mic_level_(0), | 44 current_mic_level_(0), |
50 new_mic_level_(0), | 45 new_mic_level_(0), |
51 typing_status_(false), | 46 typing_status_(false), |
52 play_delay_ms_(0), | 47 play_delay_ms_(0), |
53 rec_delay_ms_(0), | 48 rec_delay_ms_(0), |
54 clock_drift_(0), | 49 clock_drift_(0), |
55 num_stat_reports_(0), | 50 num_stat_reports_(0), |
56 rec_callbacks_(0), | 51 rec_callbacks_(0), |
57 last_rec_callbacks_(0), | 52 last_rec_callbacks_(0), |
58 play_callbacks_(0), | 53 play_callbacks_(0), |
59 last_play_callbacks_(0), | 54 last_play_callbacks_(0), |
60 rec_samples_(0), | 55 rec_samples_(0), |
61 last_rec_samples_(0), | 56 last_rec_samples_(0), |
62 play_samples_(0), | 57 play_samples_(0), |
63 last_play_samples_(0), | 58 last_play_samples_(0), |
64 last_log_stat_time_(0), | 59 last_log_stat_time_(0), |
65 max_rec_level_(0), | 60 max_rec_level_(0), |
66 max_play_level_(0), | 61 max_play_level_(0), |
67 num_rec_level_is_zero_(0) { | 62 num_rec_level_is_zero_(0) { |
68 LOG(INFO) << "AudioDeviceBuffer::ctor"; | 63 LOG(INFO) << "AudioDeviceBuffer::ctor"; |
69 // TODO(henrika): improve buffer handling and ensure that we don't allocate | |
70 // more than what is required. | |
71 play_buffer_.reset(new int8_t[kMaxBufferSizeBytes]); | |
72 rec_buffer_.reset(new int8_t[kMaxBufferSizeBytes]); | |
73 } | 64 } |
74 | 65 |
75 AudioDeviceBuffer::~AudioDeviceBuffer() { | 66 AudioDeviceBuffer::~AudioDeviceBuffer() { |
76 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 67 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
77 LOG(INFO) << "AudioDeviceBuffer::~dtor"; | 68 LOG(INFO) << "AudioDeviceBuffer::~dtor"; |
78 | 69 |
79 size_t total_diff_time = 0; | 70 size_t total_diff_time = 0; |
80 int num_measurements = 0; | 71 int num_measurements = 0; |
81 LOG(INFO) << "[playout diff time => #measurements]"; | 72 LOG(INFO) << "[playout diff time => #measurements]"; |
82 for (size_t diff = 0; diff < arraysize(playout_diff_times_); ++diff) { | 73 for (size_t diff = 0; diff < arraysize(playout_diff_times_); ++diff) { |
(...skipping 18 matching lines...) Expand all Loading... |
101 // and reading these members on the creating thread feels safe. | 92 // and reading these members on the creating thread feels safe. |
102 if (rec_callbacks_ > 0 && num_stat_reports_ > 0) { | 93 if (rec_callbacks_ > 0 && num_stat_reports_ > 0) { |
103 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.RecordedOnlyZeros", | 94 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.RecordedOnlyZeros", |
104 static_cast<int>(num_stat_reports_ == num_rec_level_is_zero_)); | 95 static_cast<int>(num_stat_reports_ == num_rec_level_is_zero_)); |
105 } | 96 } |
106 } | 97 } |
107 | 98 |
108 int32_t AudioDeviceBuffer::RegisterAudioCallback( | 99 int32_t AudioDeviceBuffer::RegisterAudioCallback( |
109 AudioTransport* audio_callback) { | 100 AudioTransport* audio_callback) { |
110 LOG(INFO) << __FUNCTION__; | 101 LOG(INFO) << __FUNCTION__; |
111 rtc::CritScope lock(&_critSectCb); | 102 rtc::CritScope lock(&lock_cb_); |
112 audio_transport_cb_ = audio_callback; | 103 audio_transport_cb_ = audio_callback; |
113 return 0; | 104 return 0; |
114 } | 105 } |
115 | 106 |
116 int32_t AudioDeviceBuffer::InitPlayout() { | 107 int32_t AudioDeviceBuffer::InitPlayout() { |
117 LOG(INFO) << __FUNCTION__; | 108 LOG(INFO) << __FUNCTION__; |
118 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 109 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
119 ResetPlayStats(); | 110 ResetPlayStats(); |
120 if (!timer_has_started_) { | 111 if (!timer_has_started_) { |
121 StartTimer(); | 112 StartTimer(); |
122 timer_has_started_ = true; | 113 timer_has_started_ = true; |
123 } | 114 } |
124 return 0; | 115 return 0; |
125 } | 116 } |
126 | 117 |
127 int32_t AudioDeviceBuffer::InitRecording() { | 118 int32_t AudioDeviceBuffer::InitRecording() { |
128 LOG(INFO) << __FUNCTION__; | 119 LOG(INFO) << __FUNCTION__; |
129 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 120 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
130 ResetRecStats(); | 121 ResetRecStats(); |
131 if (!timer_has_started_) { | 122 if (!timer_has_started_) { |
132 StartTimer(); | 123 StartTimer(); |
133 timer_has_started_ = true; | 124 timer_has_started_ = true; |
134 } | 125 } |
135 return 0; | 126 return 0; |
136 } | 127 } |
137 | 128 |
138 int32_t AudioDeviceBuffer::SetRecordingSampleRate(uint32_t fsHz) { | 129 int32_t AudioDeviceBuffer::SetRecordingSampleRate(uint32_t fsHz) { |
139 LOG(INFO) << "SetRecordingSampleRate(" << fsHz << ")"; | 130 LOG(INFO) << "SetRecordingSampleRate(" << fsHz << ")"; |
140 rtc::CritScope lock(&_critSect); | 131 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
141 rec_sample_rate_ = fsHz; | 132 rec_sample_rate_ = fsHz; |
142 return 0; | 133 return 0; |
143 } | 134 } |
144 | 135 |
145 int32_t AudioDeviceBuffer::SetPlayoutSampleRate(uint32_t fsHz) { | 136 int32_t AudioDeviceBuffer::SetPlayoutSampleRate(uint32_t fsHz) { |
146 LOG(INFO) << "SetPlayoutSampleRate(" << fsHz << ")"; | 137 LOG(INFO) << "SetPlayoutSampleRate(" << fsHz << ")"; |
147 rtc::CritScope lock(&_critSect); | 138 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
148 play_sample_rate_ = fsHz; | 139 play_sample_rate_ = fsHz; |
149 return 0; | 140 return 0; |
150 } | 141 } |
151 | 142 |
152 int32_t AudioDeviceBuffer::RecordingSampleRate() const { | 143 int32_t AudioDeviceBuffer::RecordingSampleRate() const { |
153 return rec_sample_rate_; | 144 return rec_sample_rate_; |
154 } | 145 } |
155 | 146 |
156 int32_t AudioDeviceBuffer::PlayoutSampleRate() const { | 147 int32_t AudioDeviceBuffer::PlayoutSampleRate() const { |
157 return play_sample_rate_; | 148 return play_sample_rate_; |
158 } | 149 } |
159 | 150 |
160 int32_t AudioDeviceBuffer::SetRecordingChannels(size_t channels) { | 151 int32_t AudioDeviceBuffer::SetRecordingChannels(size_t channels) { |
161 LOG(INFO) << "SetRecordingChannels(" << channels << ")"; | 152 LOG(INFO) << "SetRecordingChannels(" << channels << ")"; |
162 rtc::CritScope lock(&_critSect); | 153 rtc::CritScope lock(&lock_); |
163 rec_channels_ = channels; | 154 rec_channels_ = channels; |
164 rec_bytes_per_sample_ = | 155 rec_bytes_per_sample_ = sizeof(int16_t) * channels; |
165 2 * channels; // 16 bits per sample in mono, 32 bits in stereo | |
166 return 0; | 156 return 0; |
167 } | 157 } |
168 | 158 |
169 int32_t AudioDeviceBuffer::SetPlayoutChannels(size_t channels) { | 159 int32_t AudioDeviceBuffer::SetPlayoutChannels(size_t channels) { |
170 LOG(INFO) << "SetPlayoutChannels(" << channels << ")"; | 160 LOG(INFO) << "SetPlayoutChannels(" << channels << ")"; |
171 rtc::CritScope lock(&_critSect); | 161 rtc::CritScope lock(&lock_); |
172 play_channels_ = channels; | 162 play_channels_ = channels; |
173 // 16 bits per sample in mono, 32 bits in stereo | 163 play_bytes_per_sample_ = sizeof(int16_t) * channels; |
174 play_bytes_per_sample_ = 2 * channels; | |
175 return 0; | 164 return 0; |
176 } | 165 } |
177 | 166 |
178 int32_t AudioDeviceBuffer::SetRecordingChannel( | 167 int32_t AudioDeviceBuffer::SetRecordingChannel( |
179 const AudioDeviceModule::ChannelType channel) { | 168 const AudioDeviceModule::ChannelType channel) { |
180 rtc::CritScope lock(&_critSect); | 169 LOG(INFO) << "SetRecordingChannel(" << channel << ")"; |
181 | 170 LOG(LS_WARNING) << "Not implemented"; |
182 if (rec_channels_ == 1) { | 171 // Add DCHECK to ensure that user does not try to use this API with a non- |
183 return -1; | 172 // default parameter. |
184 } | 173 RTC_DCHECK_EQ(channel, AudioDeviceModule::kChannelBoth); |
185 | 174 return -1; |
186 if (channel == AudioDeviceModule::kChannelBoth) { | |
187 // two bytes per channel | |
188 rec_bytes_per_sample_ = 4; | |
189 } else { | |
190 // only utilize one out of two possible channels (left or right) | |
191 rec_bytes_per_sample_ = 2; | |
192 } | |
193 rec_channel_ = channel; | |
194 | |
195 return 0; | |
196 } | 175 } |
197 | 176 |
198 int32_t AudioDeviceBuffer::RecordingChannel( | 177 int32_t AudioDeviceBuffer::RecordingChannel( |
199 AudioDeviceModule::ChannelType& channel) const { | 178 AudioDeviceModule::ChannelType& channel) const { |
200 channel = rec_channel_; | 179 LOG(LS_WARNING) << "Not implemented"; |
201 return 0; | 180 return -1; |
202 } | 181 } |
203 | 182 |
204 size_t AudioDeviceBuffer::RecordingChannels() const { | 183 size_t AudioDeviceBuffer::RecordingChannels() const { |
205 return rec_channels_; | 184 return rec_channels_; |
206 } | 185 } |
207 | 186 |
208 size_t AudioDeviceBuffer::PlayoutChannels() const { | 187 size_t AudioDeviceBuffer::PlayoutChannels() const { |
209 return play_channels_; | 188 return play_channels_; |
210 } | 189 } |
211 | 190 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 return 0; | 227 return 0; |
249 } | 228 } |
250 | 229 |
251 int32_t AudioDeviceBuffer::StopOutputFileRecording() { | 230 int32_t AudioDeviceBuffer::StopOutputFileRecording() { |
252 LOG(LS_WARNING) << "Not implemented"; | 231 LOG(LS_WARNING) << "Not implemented"; |
253 return 0; | 232 return 0; |
254 } | 233 } |
255 | 234 |
256 int32_t AudioDeviceBuffer::SetRecordedBuffer(const void* audio_buffer, | 235 int32_t AudioDeviceBuffer::SetRecordedBuffer(const void* audio_buffer, |
257 size_t num_samples) { | 236 size_t num_samples) { |
258 UpdateRecordingParameters(); | 237 const size_t rec_bytes_per_sample = [&] { |
259 // WebRTC can only receive audio in 10ms chunks, hence we fail if the native | 238 rtc::CritScope lock(&lock_); |
260 // audio layer tries to deliver something else. | 239 return rec_bytes_per_sample_; |
261 RTC_CHECK_EQ(num_samples, rec_samples_per_10ms_); | 240 }(); |
262 | 241 // Copy the complete input buffer to the local buffer. |
263 rtc::CritScope lock(&_critSect); | 242 const size_t size_in_bytes = num_samples * rec_bytes_per_sample; |
264 | 243 const size_t old_size = rec_buffer_.size(); |
265 if (rec_channel_ == AudioDeviceModule::kChannelBoth) { | 244 rec_buffer_.SetData(static_cast<const uint8_t*>(audio_buffer), size_in_bytes); |
266 // Copy the complete input buffer to the local buffer. | 245 // Keep track of the size of the recording buffer. Only updated when the |
267 memcpy(&rec_buffer_[0], audio_buffer, rec_bytes_per_10ms_); | 246 // size changes, which is a rare event. |
268 } else { | 247 if (old_size != rec_buffer_.size()) { |
269 int16_t* ptr16In = (int16_t*)audio_buffer; | 248 LOG(LS_INFO) << "Size of recording buffer: " << rec_buffer_.size(); |
270 int16_t* ptr16Out = (int16_t*)&rec_buffer_[0]; | |
271 if (AudioDeviceModule::kChannelRight == rec_channel_) { | |
272 ptr16In++; | |
273 } | |
274 // Exctract left or right channel from input buffer to the local buffer. | |
275 for (size_t i = 0; i < rec_samples_per_10ms_; i++) { | |
276 *ptr16Out = *ptr16In; | |
277 ptr16Out++; | |
278 ptr16In++; | |
279 ptr16In++; | |
280 } | |
281 } | 249 } |
282 | |
283 // Update some stats but do it on the task queue to ensure that the members | 250 // Update some stats but do it on the task queue to ensure that the members |
284 // are modified and read on the same thread. | 251 // are modified and read on the same thread. |
285 task_queue_.PostTask(rtc::Bind(&AudioDeviceBuffer::UpdateRecStats, this, | 252 task_queue_.PostTask(rtc::Bind(&AudioDeviceBuffer::UpdateRecStats, this, |
286 audio_buffer, num_samples)); | 253 audio_buffer, num_samples)); |
287 return 0; | 254 return 0; |
288 } | 255 } |
289 | 256 |
290 int32_t AudioDeviceBuffer::DeliverRecordedData() { | 257 int32_t AudioDeviceBuffer::DeliverRecordedData() { |
291 rtc::CritScope lock(&_critSectCb); | 258 rtc::CritScope lock(&lock_cb_); |
292 | |
293 if (!audio_transport_cb_) { | 259 if (!audio_transport_cb_) { |
294 LOG(LS_WARNING) << "Invalid audio transport"; | 260 LOG(LS_WARNING) << "Invalid audio transport"; |
295 return 0; | 261 return 0; |
296 } | 262 } |
297 | 263 const size_t rec_bytes_per_sample = [&] { |
298 int32_t res(0); | 264 rtc::CritScope lock(&lock_); |
299 uint32_t newMicLevel(0); | 265 return rec_bytes_per_sample_; |
300 uint32_t totalDelayMS = play_delay_ms_ + rec_delay_ms_; | 266 }(); |
301 res = audio_transport_cb_->RecordedDataIsAvailable( | 267 uint32_t new_mic_level(0); |
302 &rec_buffer_[0], rec_samples_per_10ms_, rec_bytes_per_sample_, | 268 uint32_t total_delay_ms = play_delay_ms_ + rec_delay_ms_; |
303 rec_channels_, rec_sample_rate_, totalDelayMS, clock_drift_, | 269 size_t num_samples = rec_buffer_.size() / rec_bytes_per_sample; |
304 current_mic_level_, typing_status_, newMicLevel); | 270 int32_t res = audio_transport_cb_->RecordedDataIsAvailable( |
| 271 rec_buffer_.data(), num_samples, rec_bytes_per_sample_, rec_channels_, |
| 272 rec_sample_rate_, total_delay_ms, clock_drift_, current_mic_level_, |
| 273 typing_status_, new_mic_level); |
305 if (res != -1) { | 274 if (res != -1) { |
306 new_mic_level_ = newMicLevel; | 275 new_mic_level_ = new_mic_level; |
307 } else { | 276 } else { |
308 LOG(LS_ERROR) << "RecordedDataIsAvailable() failed"; | 277 LOG(LS_ERROR) << "RecordedDataIsAvailable() failed"; |
309 } | 278 } |
310 | |
311 return 0; | 279 return 0; |
312 } | 280 } |
313 | 281 |
314 int32_t AudioDeviceBuffer::RequestPlayoutData(size_t num_samples) { | 282 int32_t AudioDeviceBuffer::RequestPlayoutData(size_t num_samples) { |
315 // Measure time since last function call and update an array where the | 283 // Measure time since last function call and update an array where the |
316 // position/index corresponds to time differences (in milliseconds) between | 284 // position/index corresponds to time differences (in milliseconds) between |
317 // two successive playout callbacks, and the stored value is the number of | 285 // two successive playout callbacks, and the stored value is the number of |
318 // times a given time difference was found. | 286 // times a given time difference was found. |
319 int64_t now_time = rtc::TimeMillis(); | 287 int64_t now_time = rtc::TimeMillis(); |
320 size_t diff_time = rtc::TimeDiff(now_time, last_playout_time_); | 288 size_t diff_time = rtc::TimeDiff(now_time, last_playout_time_); |
321 // Truncate at 500ms to limit the size of the array. | 289 // Truncate at 500ms to limit the size of the array. |
322 diff_time = std::min(kMaxDeltaTimeInMs, diff_time); | 290 diff_time = std::min(kMaxDeltaTimeInMs, diff_time); |
323 last_playout_time_ = now_time; | 291 last_playout_time_ = now_time; |
324 playout_diff_times_[diff_time]++; | 292 playout_diff_times_[diff_time]++; |
325 | 293 |
326 UpdatePlayoutParameters(); | 294 const size_t play_bytes_per_sample = [&] { |
327 // WebRTC can only provide audio in 10ms chunks, hence we fail if the native | 295 rtc::CritScope lock(&lock_); |
328 // audio layer asks for something else. | 296 return play_bytes_per_sample_; |
329 RTC_CHECK_EQ(num_samples, play_samples_per_10ms_); | 297 }(); |
330 | 298 |
331 rtc::CritScope lock(&_critSectCb); | 299 // The consumer can change the request size on the fly and we therefore |
| 300 // resize the buffer accordingly. Also takes place at the first call to this |
| 301 // method. |
| 302 const size_t size_in_bytes = num_samples * play_bytes_per_sample; |
| 303 if (play_buffer_.size() != size_in_bytes) { |
| 304 play_buffer_.SetSize(size_in_bytes); |
| 305 LOG(LS_INFO) << "Size of playout buffer: " << play_buffer_.size(); |
| 306 } |
| 307 |
| 308 rtc::CritScope lock(&lock_cb_); |
332 | 309 |
333 // It is currently supported to start playout without a valid audio | 310 // It is currently supported to start playout without a valid audio |
334 // transport object. Leads to warning and silence. | 311 // transport object. Leads to warning and silence. |
335 if (!audio_transport_cb_) { | 312 if (!audio_transport_cb_) { |
336 LOG(LS_WARNING) << "Invalid audio transport"; | 313 LOG(LS_WARNING) << "Invalid audio transport"; |
337 return 0; | 314 return 0; |
338 } | 315 } |
339 | 316 |
340 uint32_t res(0); | |
341 int64_t elapsed_time_ms = -1; | 317 int64_t elapsed_time_ms = -1; |
342 int64_t ntp_time_ms = -1; | 318 int64_t ntp_time_ms = -1; |
343 size_t num_samples_out(0); | 319 size_t num_samples_out(0); |
344 res = audio_transport_cb_->NeedMorePlayData( | 320 uint32_t res = audio_transport_cb_->NeedMorePlayData( |
345 play_samples_per_10ms_, play_bytes_per_sample_, play_channels_, | 321 num_samples, play_bytes_per_sample_, play_channels_, play_sample_rate_, |
346 play_sample_rate_, &play_buffer_[0], num_samples_out, &elapsed_time_ms, | 322 play_buffer_.data(), num_samples_out, &elapsed_time_ms, &ntp_time_ms); |
347 &ntp_time_ms); | |
348 if (res != 0) { | 323 if (res != 0) { |
349 LOG(LS_ERROR) << "NeedMorePlayData() failed"; | 324 LOG(LS_ERROR) << "NeedMorePlayData() failed"; |
350 } | 325 } |
351 | 326 |
352 // Update some stats but do it on the task queue to ensure that access of | 327 // Update some stats but do it on the task queue to ensure that access of |
353 // members is serialized hence avoiding usage of locks. | 328 // members is serialized hence avoiding usage of locks. |
354 task_queue_.PostTask(rtc::Bind(&AudioDeviceBuffer::UpdatePlayStats, this, | 329 task_queue_.PostTask(rtc::Bind(&AudioDeviceBuffer::UpdatePlayStats, this, |
355 &play_buffer_[0], num_samples_out)); | 330 play_buffer_.data(), num_samples_out)); |
356 return static_cast<int32_t>(num_samples_out); | 331 return static_cast<int32_t>(num_samples_out); |
357 } | 332 } |
358 | 333 |
359 int32_t AudioDeviceBuffer::GetPlayoutData(void* audio_buffer) { | 334 int32_t AudioDeviceBuffer::GetPlayoutData(void* audio_buffer) { |
360 rtc::CritScope lock(&_critSect); | 335 RTC_DCHECK_GT(play_buffer_.size(), 0u); |
361 memcpy(audio_buffer, &play_buffer_[0], play_bytes_per_10ms_); | 336 const size_t play_bytes_per_sample = [&] { |
362 return static_cast<int32_t>(play_samples_per_10ms_); | 337 rtc::CritScope lock(&lock_); |
363 } | 338 return play_bytes_per_sample_; |
364 | 339 }(); |
365 void AudioDeviceBuffer::UpdatePlayoutParameters() { | 340 memcpy(audio_buffer, play_buffer_.data(), play_buffer_.size()); |
366 RTC_CHECK(play_bytes_per_sample_); | 341 return static_cast<int32_t>(play_buffer_.size() / play_bytes_per_sample); |
367 rtc::CritScope lock(&_critSect); | |
368 // Update the required buffer size given sample rate and number of channels. | |
369 play_samples_per_10ms_ = static_cast<size_t>(play_sample_rate_ * 10 / 1000); | |
370 play_bytes_per_10ms_ = play_bytes_per_sample_ * play_samples_per_10ms_; | |
371 RTC_DCHECK_LE(play_bytes_per_10ms_, kMaxBufferSizeBytes); | |
372 } | |
373 | |
374 void AudioDeviceBuffer::UpdateRecordingParameters() { | |
375 RTC_CHECK(rec_bytes_per_sample_); | |
376 rtc::CritScope lock(&_critSect); | |
377 // Update the required buffer size given sample rate and number of channels. | |
378 rec_samples_per_10ms_ = static_cast<size_t>(rec_sample_rate_ * 10 / 1000); | |
379 rec_bytes_per_10ms_ = rec_bytes_per_sample_ * rec_samples_per_10ms_; | |
380 RTC_DCHECK_LE(rec_bytes_per_10ms_, kMaxBufferSizeBytes); | |
381 } | 342 } |
382 | 343 |
383 void AudioDeviceBuffer::StartTimer() { | 344 void AudioDeviceBuffer::StartTimer() { |
384 num_stat_reports_ = 0; | 345 num_stat_reports_ = 0; |
385 last_log_stat_time_ = rtc::TimeMillis(); | 346 last_log_stat_time_ = rtc::TimeMillis(); |
386 task_queue_.PostDelayedTask(rtc::Bind(&AudioDeviceBuffer::LogStats, this), | 347 task_queue_.PostDelayedTask(rtc::Bind(&AudioDeviceBuffer::LogStats, this), |
387 kTimerIntervalInMilliseconds); | 348 kTimerIntervalInMilliseconds); |
388 } | 349 } |
389 | 350 |
390 void AudioDeviceBuffer::LogStats() { | 351 void AudioDeviceBuffer::LogStats() { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 int16_t max_abs = WebRtcSpl_MaxAbsValueW16( | 451 int16_t max_abs = WebRtcSpl_MaxAbsValueW16( |
491 static_cast<int16_t*>(const_cast<void*>(audio_buffer)), | 452 static_cast<int16_t*>(const_cast<void*>(audio_buffer)), |
492 num_samples * play_channels_); | 453 num_samples * play_channels_); |
493 if (max_abs > max_play_level_) { | 454 if (max_abs > max_play_level_) { |
494 max_play_level_ = max_abs; | 455 max_play_level_ = max_abs; |
495 } | 456 } |
496 } | 457 } |
497 } | 458 } |
498 | 459 |
499 } // namespace webrtc | 460 } // namespace webrtc |
OLD | NEW |