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

Side by Side Diff: media/audio/alsa/alsa_input.cc

Issue 2689483006: Switch browser side audio capture path to use base time primitives. (Closed)
Patch Set: Bloop Created 3 years, 10 months 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "media/audio/alsa/alsa_input.h" 5 #include "media/audio/alsa/alsa_input.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 193
194 base::TimeDelta next_check_time = buffer_duration_ / 2; 194 base::TimeDelta next_check_time = buffer_duration_ / 2;
195 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 195 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
196 FROM_HERE, 196 FROM_HERE,
197 base::Bind(&AlsaPcmInputStream::ReadAudio, weak_factory_.GetWeakPtr()), 197 base::Bind(&AlsaPcmInputStream::ReadAudio, weak_factory_.GetWeakPtr()),
198 next_check_time); 198 next_check_time);
199 return; 199 return;
200 } 200 }
201 201
202 int num_buffers = frames / params_.frames_per_buffer(); 202 int num_buffers = frames / params_.frames_per_buffer();
203 uint32_t hardware_delay_bytes = 203 base::TimeDelta hardware_delay = base::TimeDelta::FromSecondsD(
204 static_cast<uint32_t>(GetCurrentDelay() * params_.GetBytesPerFrame()); 204 GetCurrentDelay() / static_cast<double>(params_.sample_rate()));
205 double normalized_volume = 0.0; 205 double normalized_volume = 0.0;
206 206
207 // Update the AGC volume level once every second. Note that, |volume| is 207 // Update the AGC volume level once every second. Note that, |volume| is
208 // also updated each time SetVolume() is called through IPC by the 208 // also updated each time SetVolume() is called through IPC by the
209 // render-side AGC. 209 // render-side AGC.
210 GetAgcVolume(&normalized_volume); 210 GetAgcVolume(&normalized_volume);
211 211
212 while (num_buffers--) { 212 while (num_buffers--) {
213 int frames_read = wrapper_->PcmReadi(device_handle_, audio_buffer_.get(), 213 int frames_read = wrapper_->PcmReadi(device_handle_, audio_buffer_.get(),
214 params_.frames_per_buffer()); 214 params_.frames_per_buffer());
215 if (frames_read == params_.frames_per_buffer()) { 215 if (frames_read == params_.frames_per_buffer()) {
216 audio_bus_->FromInterleaved(audio_buffer_.get(), 216 audio_bus_->FromInterleaved(audio_buffer_.get(), audio_bus_->frames(),
217 audio_bus_->frames(),
218 params_.bits_per_sample() / 8); 217 params_.bits_per_sample() / 8);
219 callback_->OnData( 218 callback_->OnData(this, audio_bus_.get(), hardware_delay,
220 this, audio_bus_.get(), hardware_delay_bytes, normalized_volume); 219 base::TimeTicks::Now(), normalized_volume);
221 } else { 220 } else {
222 LOG(WARNING) << "PcmReadi returning less than expected frames: " 221 LOG(WARNING) << "PcmReadi returning less than expected frames: "
223 << frames_read << " vs. " << params_.frames_per_buffer() 222 << frames_read << " vs. " << params_.frames_per_buffer()
224 << ". Dropping this buffer."; 223 << ". Dropping this buffer.";
225 } 224 }
226 } 225 }
227 226
228 next_read_time_ += buffer_duration_; 227 next_read_time_ += buffer_duration_;
229 base::TimeDelta delay = next_read_time_ - base::TimeTicks::Now(); 228 base::TimeDelta delay = next_read_time_ - base::TimeTicks::Now();
230 if (delay < base::TimeDelta()) { 229 if (delay < base::TimeDelta()) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 bool AlsaPcmInputStream::IsMuted() { 341 bool AlsaPcmInputStream::IsMuted() {
343 return false; 342 return false;
344 } 343 }
345 344
346 void AlsaPcmInputStream::HandleError(const char* method, int error) { 345 void AlsaPcmInputStream::HandleError(const char* method, int error) {
347 LOG(WARNING) << method << ": " << wrapper_->StrError(error); 346 LOG(WARNING) << method << ": " << wrapper_->StrError(error);
348 callback_->OnError(this); 347 callback_->OnError(this);
349 } 348 }
350 349
351 } // namespace media 350 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698