Chromium Code Reviews| 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 size_t rec_bytes_per_sample; |
| 259 // WebRTC can only receive audio in 10ms chunks, hence we fail if the native | 238 { |
| 260 // audio layer tries to deliver something else. | 239 rtc::CritScope lock(&lock_); |
| 261 RTC_CHECK_EQ(num_samples, rec_samples_per_10ms_); | 240 rec_bytes_per_sample = rec_bytes_per_sample_; |
| 262 | |
| 263 rtc::CritScope lock(&_critSect); | |
| 264 | |
| 265 if (rec_channel_ == AudioDeviceModule::kChannelBoth) { | |
| 266 // Copy the complete input buffer to the local buffer. | |
| 267 memcpy(&rec_buffer_[0], audio_buffer, rec_bytes_per_10ms_); | |
| 268 } else { | |
| 269 int16_t* ptr16In = (int16_t*)audio_buffer; | |
| 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 } | 241 } |
|
kwiberg-webrtc
2016/09/14 08:39:04
An elegant way to do this, which avoids the use of
henrika_webrtc
2016/09/14 10:26:53
Thanks, will change. Must admit that I have not wo
kwiberg-webrtc
2016/09/14 11:17:17
It's the capture list---the list of variables of t
henrika_webrtc
2016/10/07 12:18:05
Acknowledged.
henrika_webrtc
2016/10/07 12:18:05
Done.
| |
| 282 | 242 // Copy the complete input buffer to the local buffer. |
| 243 size_t size_in_bytes = num_samples * rec_bytes_per_sample; | |
|
kwiberg-webrtc
2016/09/14 08:39:04
const
henrika_webrtc
2016/09/14 10:26:53
Acknowledged.
| |
| 244 rec_buffer_.SetData(static_cast<const int8_t*>(audio_buffer), size_in_bytes); | |
| 283 // Update some stats but do it on the task queue to ensure that the members | 245 // Update some stats but do it on the task queue to ensure that the members |
| 284 // are modified and read on the same thread. | 246 // are modified and read on the same thread. |
| 285 task_queue_.PostTask(rtc::Bind(&AudioDeviceBuffer::UpdateRecStats, this, | 247 task_queue_.PostTask(rtc::Bind(&AudioDeviceBuffer::UpdateRecStats, this, |
| 286 audio_buffer, num_samples)); | 248 audio_buffer, num_samples)); |
| 287 return 0; | 249 return 0; |
| 288 } | 250 } |
| 289 | 251 |
| 290 int32_t AudioDeviceBuffer::DeliverRecordedData() { | 252 int32_t AudioDeviceBuffer::DeliverRecordedData() { |
| 291 RTC_DCHECK(audio_transport_cb_); | 253 rtc::CritScope lock(&lock_cb_); |
| 292 rtc::CritScope lock(&_critSectCb); | |
| 293 | |
| 294 if (!audio_transport_cb_) { | 254 if (!audio_transport_cb_) { |
| 295 LOG(LS_WARNING) << "Invalid audio transport"; | 255 LOG(LS_WARNING) << "Invalid audio transport"; |
| 296 return 0; | 256 return 0; |
| 297 } | 257 } |
| 298 | 258 size_t rec_bytes_per_sample; |
| 299 int32_t res(0); | 259 { |
| 300 uint32_t newMicLevel(0); | 260 rtc::CritScope lock(&lock_); |
| 301 uint32_t totalDelayMS = play_delay_ms_ + rec_delay_ms_; | 261 rec_bytes_per_sample = rec_bytes_per_sample_; |
| 302 res = audio_transport_cb_->RecordedDataIsAvailable( | 262 } |
|
kwiberg-webrtc
2016/09/14 08:39:04
You can use the lambda trick here too.
henrika_webrtc
2016/09/14 10:26:53
Acknowledged.
| |
| 303 &rec_buffer_[0], rec_samples_per_10ms_, rec_bytes_per_sample_, | 263 uint32_t new_mic_level(0); |
| 304 rec_channels_, rec_sample_rate_, totalDelayMS, clock_drift_, | 264 uint32_t total_delay_ms = play_delay_ms_ + rec_delay_ms_; |
| 305 current_mic_level_, typing_status_, newMicLevel); | 265 size_t num_samples = rec_buffer_.size() / rec_bytes_per_sample; |
| 266 int32_t res = audio_transport_cb_->RecordedDataIsAvailable( | |
| 267 rec_buffer_.data(), num_samples, rec_bytes_per_sample_, rec_channels_, | |
| 268 rec_sample_rate_, total_delay_ms, clock_drift_, current_mic_level_, | |
| 269 typing_status_, new_mic_level); | |
| 306 if (res != -1) { | 270 if (res != -1) { |
| 307 new_mic_level_ = newMicLevel; | 271 new_mic_level_ = new_mic_level; |
| 308 } else { | 272 } else { |
| 309 LOG(LS_ERROR) << "RecordedDataIsAvailable() failed"; | 273 LOG(LS_ERROR) << "RecordedDataIsAvailable() failed"; |
| 310 } | 274 } |
| 311 | |
| 312 return 0; | 275 return 0; |
| 313 } | 276 } |
| 314 | 277 |
| 315 int32_t AudioDeviceBuffer::RequestPlayoutData(size_t num_samples) { | 278 int32_t AudioDeviceBuffer::RequestPlayoutData(size_t num_samples) { |
| 316 // Measure time since last function call and update an array where the | 279 // Measure time since last function call and update an array where the |
| 317 // position/index corresponds to time differences (in milliseconds) between | 280 // position/index corresponds to time differences (in milliseconds) between |
| 318 // two successive playout callbacks, and the stored value is the number of | 281 // two successive playout callbacks, and the stored value is the number of |
| 319 // times a given time difference was found. | 282 // times a given time difference was found. |
| 320 int64_t now_time = rtc::TimeMillis(); | 283 int64_t now_time = rtc::TimeMillis(); |
| 321 size_t diff_time = rtc::TimeDiff(now_time, last_playout_time_); | 284 size_t diff_time = rtc::TimeDiff(now_time, last_playout_time_); |
| 322 // Truncate at 500ms to limit the size of the array. | 285 // Truncate at 500ms to limit the size of the array. |
| 323 diff_time = std::min(kMaxDeltaTimeInMs, diff_time); | 286 diff_time = std::min(kMaxDeltaTimeInMs, diff_time); |
| 324 last_playout_time_ = now_time; | 287 last_playout_time_ = now_time; |
| 325 playout_diff_times_[diff_time]++; | 288 playout_diff_times_[diff_time]++; |
| 326 | 289 |
| 327 UpdatePlayoutParameters(); | 290 rtc::CritScope lock(&lock_cb_); |
| 328 // WebRTC can only provide audio in 10ms chunks, hence we fail if the native | |
| 329 // audio layer asks for something else. | |
| 330 RTC_CHECK_EQ(num_samples, play_samples_per_10ms_); | |
| 331 | |
| 332 rtc::CritScope lock(&_critSectCb); | |
| 333 | 291 |
| 334 // It is currently supported to start playout without a valid audio | 292 // It is currently supported to start playout without a valid audio |
| 335 // transport object. Leads to warning and silence. | 293 // transport object. Leads to warning and silence. |
| 336 if (!audio_transport_cb_) { | 294 if (!audio_transport_cb_) { |
| 337 LOG(LS_WARNING) << "Invalid audio transport"; | 295 LOG(LS_WARNING) << "Invalid audio transport"; |
| 338 return 0; | 296 return 0; |
| 339 } | 297 } |
| 340 | 298 |
| 341 uint32_t res(0); | 299 size_t play_bytes_per_sample; |
| 300 { | |
| 301 rtc::CritScope lock(&lock_); | |
| 302 play_bytes_per_sample = play_bytes_per_sample_; | |
| 303 } | |
|
kwiberg-webrtc
2016/09/14 08:39:04
lambda
henrika_webrtc
2016/09/14 10:26:53
Acknowledged.
| |
| 304 | |
| 305 // The consumer can change the request size on the fly and we therefore | |
| 306 // resize the buffer accordingly. Also takes place at the first call to this | |
| 307 // method. | |
| 308 size_t size_in_bytes = num_samples * play_bytes_per_sample; | |
|
kwiberg-webrtc
2016/09/14 08:39:04
const
henrika_webrtc
2016/09/14 10:26:53
Acknowledged.
| |
| 309 if (play_buffer_.size() != size_in_bytes) { | |
| 310 play_buffer_.SetSize(size_in_bytes); | |
| 311 LOG(LS_INFO) << "Size of playout buffer: " << play_buffer_.size(); | |
| 312 } | |
| 313 | |
| 342 int64_t elapsed_time_ms = -1; | 314 int64_t elapsed_time_ms = -1; |
| 343 int64_t ntp_time_ms = -1; | 315 int64_t ntp_time_ms = -1; |
| 344 size_t num_samples_out(0); | 316 size_t num_samples_out(0); |
| 345 res = audio_transport_cb_->NeedMorePlayData( | 317 uint32_t res = audio_transport_cb_->NeedMorePlayData( |
| 346 play_samples_per_10ms_, play_bytes_per_sample_, play_channels_, | 318 num_samples, play_bytes_per_sample_, play_channels_, |
| 347 play_sample_rate_, &play_buffer_[0], num_samples_out, &elapsed_time_ms, | 319 play_sample_rate_, &play_buffer_[0], num_samples_out, &elapsed_time_ms, |
| 348 &ntp_time_ms); | 320 &ntp_time_ms); |
| 349 if (res != 0) { | 321 if (res != 0) { |
| 350 LOG(LS_ERROR) << "NeedMorePlayData() failed"; | 322 LOG(LS_ERROR) << "NeedMorePlayData() failed"; |
| 351 } | 323 } |
| 352 | 324 |
| 353 // Update some stats but do it on the task queue to ensure that access of | 325 // Update some stats but do it on the task queue to ensure that access of |
| 354 // members is serialized hence avoiding usage of locks. | 326 // members is serialized hence avoiding usage of locks. |
| 355 task_queue_.PostTask(rtc::Bind(&AudioDeviceBuffer::UpdatePlayStats, this, | 327 task_queue_.PostTask(rtc::Bind(&AudioDeviceBuffer::UpdatePlayStats, this, |
| 356 &play_buffer_[0], num_samples_out)); | 328 &play_buffer_[0], num_samples_out)); |
| 357 return static_cast<int32_t>(num_samples_out); | 329 return static_cast<int32_t>(num_samples_out); |
| 358 } | 330 } |
| 359 | 331 |
| 360 int32_t AudioDeviceBuffer::GetPlayoutData(void* audio_buffer) { | 332 int32_t AudioDeviceBuffer::GetPlayoutData(void* audio_buffer) { |
| 361 rtc::CritScope lock(&_critSect); | 333 RTC_DCHECK_GT(play_buffer_.size(), 0u); |
| 362 memcpy(audio_buffer, &play_buffer_[0], play_bytes_per_10ms_); | 334 size_t play_bytes_per_sample; |
| 363 return static_cast<int32_t>(play_samples_per_10ms_); | 335 { |
| 364 } | 336 rtc::CritScope lock(&lock_); |
| 365 | 337 play_bytes_per_sample = play_bytes_per_sample_; |
| 366 void AudioDeviceBuffer::UpdatePlayoutParameters() { | 338 } |
|
kwiberg-webrtc
2016/09/14 08:39:04
lambda
henrika_webrtc
2016/09/14 10:26:53
Acknowledged.
| |
| 367 RTC_CHECK(play_bytes_per_sample_); | 339 memcpy(audio_buffer, &play_buffer_[0], play_buffer_.size()); |
|
kwiberg-webrtc
2016/09/14 08:39:04
play_buffer_.data() instead of &play_buffer_[0]; b
henrika_webrtc
2016/09/14 10:26:53
Acknowledged.
| |
| 368 rtc::CritScope lock(&_critSect); | 340 return static_cast<int32_t>(play_buffer_.size() / play_bytes_per_sample); |
| 369 // Update the required buffer size given sample rate and number of channels. | |
| 370 play_samples_per_10ms_ = static_cast<size_t>(play_sample_rate_ * 10 / 1000); | |
| 371 play_bytes_per_10ms_ = play_bytes_per_sample_ * play_samples_per_10ms_; | |
| 372 RTC_DCHECK_LE(play_bytes_per_10ms_, kMaxBufferSizeBytes); | |
| 373 } | |
| 374 | |
| 375 void AudioDeviceBuffer::UpdateRecordingParameters() { | |
| 376 RTC_CHECK(rec_bytes_per_sample_); | |
| 377 rtc::CritScope lock(&_critSect); | |
| 378 // Update the required buffer size given sample rate and number of channels. | |
| 379 rec_samples_per_10ms_ = static_cast<size_t>(rec_sample_rate_ * 10 / 1000); | |
| 380 rec_bytes_per_10ms_ = rec_bytes_per_sample_ * rec_samples_per_10ms_; | |
| 381 RTC_DCHECK_LE(rec_bytes_per_10ms_, kMaxBufferSizeBytes); | |
| 382 } | 341 } |
| 383 | 342 |
| 384 void AudioDeviceBuffer::StartTimer() { | 343 void AudioDeviceBuffer::StartTimer() { |
| 385 num_stat_reports_ = 0; | 344 num_stat_reports_ = 0; |
| 386 last_log_stat_time_ = rtc::TimeMillis(); | 345 last_log_stat_time_ = rtc::TimeMillis(); |
| 387 task_queue_.PostDelayedTask(rtc::Bind(&AudioDeviceBuffer::LogStats, this), | 346 task_queue_.PostDelayedTask(rtc::Bind(&AudioDeviceBuffer::LogStats, this), |
| 388 kTimerIntervalInMilliseconds); | 347 kTimerIntervalInMilliseconds); |
| 389 } | 348 } |
| 390 | 349 |
| 391 void AudioDeviceBuffer::LogStats() { | 350 void AudioDeviceBuffer::LogStats() { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 491 int16_t max_abs = WebRtcSpl_MaxAbsValueW16( | 450 int16_t max_abs = WebRtcSpl_MaxAbsValueW16( |
| 492 static_cast<int16_t*>(const_cast<void*>(audio_buffer)), | 451 static_cast<int16_t*>(const_cast<void*>(audio_buffer)), |
| 493 num_samples * play_channels_); | 452 num_samples * play_channels_); |
| 494 if (max_abs > max_play_level_) { | 453 if (max_abs > max_play_level_) { |
| 495 max_play_level_ = max_abs; | 454 max_play_level_ = max_abs; |
| 496 } | 455 } |
| 497 } | 456 } |
| 498 } | 457 } |
| 499 | 458 |
| 500 } // namespace webrtc | 459 } // namespace webrtc |
| OLD | NEW |