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

Side by Side Diff: media/audio/audio_output_device.cc

Issue 1687213002: Express audio delay more precisely in frames rather than milliseconds. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 (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 "media/audio/audio_output_device.h" 5 #include "media/audio/audio_output_device.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <utility> 9 #include <utility>
10 10
DaleCurtis 2016/02/11 01:57:15 #include cmath for std::round (which is C++11) now
chcunningham 2016/02/11 21:02:52 Done.
11 #include "base/callback_helpers.h" 11 #include "base/callback_helpers.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/threading/thread_restrictions.h" 13 #include "base/threading/thread_restrictions.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "base/trace_event/trace_event.h" 15 #include "base/trace_event/trace_event.h"
16 #include "build/build_config.h" 16 #include "build/build_config.h"
17 #include "media/audio/audio_output_controller.h" 17 #include "media/audio/audio_output_controller.h"
18 #include "media/base/limits.h" 18 #include "media/base/limits.h"
19 19
20 namespace media { 20 namespace media {
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 sizeof(AudioOutputBufferParameters) + 406 sizeof(AudioOutputBufferParameters) +
407 AudioBus::CalculateMemorySize(audio_parameters_)); 407 AudioBus::CalculateMemorySize(audio_parameters_));
408 408
409 AudioOutputBuffer* buffer = 409 AudioOutputBuffer* buffer =
410 reinterpret_cast<AudioOutputBuffer*>(shared_memory_.memory()); 410 reinterpret_cast<AudioOutputBuffer*>(shared_memory_.memory());
411 output_bus_ = AudioBus::WrapMemory(audio_parameters_, buffer->audio); 411 output_bus_ = AudioBus::WrapMemory(audio_parameters_, buffer->audio);
412 } 412 }
413 413
414 // Called whenever we receive notifications about pending data. 414 // Called whenever we receive notifications about pending data.
415 void AudioOutputDevice::AudioThreadCallback::Process(uint32_t pending_data) { 415 void AudioOutputDevice::AudioThreadCallback::Process(uint32_t pending_data) {
416 // Convert the number of pending bytes in the render buffer into milliseconds. 416 // Convert the number of pending bytes in the render buffer into frames.
417 uint32_t audio_delay_milliseconds = pending_data / bytes_per_ms_; 417 double frames_delayed = static_cast<double>(pending_data) / bytes_per_frame_;
418 418
419 callback_num_++; 419 callback_num_++;
420 TRACE_EVENT1("audio", "AudioOutputDevice::FireRenderCallback", 420 TRACE_EVENT1("audio", "AudioOutputDevice::FireRenderCallback",
421 "callback_num", callback_num_); 421 "callback_num", callback_num_);
422 422
423 // When playback starts, we get an immediate callback to Process to make sure 423 // When playback starts, we get an immediate callback to Process to make sure
424 // that we have some data, we'll get another one after the device is awake and 424 // that we have some data, we'll get another one after the device is awake and
425 // ingesting data, which is what we want to track with this trace. 425 // ingesting data, which is what we want to track with this trace.
426 if (callback_num_ == 2) { 426 if (callback_num_ == 2) {
427 TRACE_EVENT_ASYNC_END0("audio", "StartingPlayback", this); 427 TRACE_EVENT_ASYNC_END0("audio", "StartingPlayback", this);
428 } 428 }
429 429
430 // Read and reset the number of frames skipped. 430 // Read and reset the number of frames skipped.
431 AudioOutputBuffer* buffer = 431 AudioOutputBuffer* buffer =
432 reinterpret_cast<AudioOutputBuffer*>(shared_memory_.memory()); 432 reinterpret_cast<AudioOutputBuffer*>(shared_memory_.memory());
433 uint32_t frames_skipped = buffer->params.frames_skipped; 433 uint32_t frames_skipped = buffer->params.frames_skipped;
434 buffer->params.frames_skipped = 0; 434 buffer->params.frames_skipped = 0;
435 435
436 DVLOG(4) << __FUNCTION__ << " pending_data:" << pending_data
437 << " frames_delayed(pre-round):" << frames_delayed
438 << " frames_skipped:" << frames_skipped;
439
436 // Update the audio-delay measurement, inform about the number of skipped 440 // Update the audio-delay measurement, inform about the number of skipped
437 // frames, and ask client to render audio. Since |output_bus_| is wrapping 441 // frames, and ask client to render audio. Since |output_bus_| is wrapping
438 // the shared memory the Render() call is writing directly into the shared 442 // the shared memory the Render() call is writing directly into the shared
439 // memory. 443 // memory.
440 render_callback_->Render(output_bus_.get(), audio_delay_milliseconds, 444 render_callback_->Render(output_bus_.get(), std::round(frames_delayed),
DaleCurtis 2016/02/11 01:57:15 You can also just use frames_delayed + 0.5 since t
chcunningham 2016/02/11 21:02:52 Ack. If you don't object I prefer round though...
441 frames_skipped); 445 frames_skipped);
442 } 446 }
443 447
444 } // namespace media 448 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698