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

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: Rebase 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
« no previous file with comments | « media/audio/audio_input_device.cc ('k') | media/audio/audio_output_stream_sink.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
10 #include <cmath>
9 #include <utility> 11 #include <utility>
10 12
11 #include "base/callback_helpers.h" 13 #include "base/callback_helpers.h"
12 #include "base/macros.h" 14 #include "base/macros.h"
13 #include "base/threading/thread_restrictions.h" 15 #include "base/threading/thread_restrictions.h"
14 #include "base/time/time.h" 16 #include "base/time/time.h"
15 #include "base/trace_event/trace_event.h" 17 #include "base/trace_event/trace_event.h"
16 #include "build/build_config.h" 18 #include "build/build_config.h"
17 #include "media/audio/audio_output_controller.h" 19 #include "media/audio/audio_output_controller.h"
18 #include "media/base/limits.h" 20 #include "media/base/limits.h"
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 sizeof(AudioOutputBufferParameters) + 408 sizeof(AudioOutputBufferParameters) +
407 AudioBus::CalculateMemorySize(audio_parameters_)); 409 AudioBus::CalculateMemorySize(audio_parameters_));
408 410
409 AudioOutputBuffer* buffer = 411 AudioOutputBuffer* buffer =
410 reinterpret_cast<AudioOutputBuffer*>(shared_memory_.memory()); 412 reinterpret_cast<AudioOutputBuffer*>(shared_memory_.memory());
411 output_bus_ = AudioBus::WrapMemory(audio_parameters_, buffer->audio); 413 output_bus_ = AudioBus::WrapMemory(audio_parameters_, buffer->audio);
412 } 414 }
413 415
414 // Called whenever we receive notifications about pending data. 416 // Called whenever we receive notifications about pending data.
415 void AudioOutputDevice::AudioThreadCallback::Process(uint32_t pending_data) { 417 void AudioOutputDevice::AudioThreadCallback::Process(uint32_t pending_data) {
416 // Convert the number of pending bytes in the render buffer into milliseconds. 418 // Convert the number of pending bytes in the render buffer into frames.
417 uint32_t audio_delay_milliseconds = pending_data / bytes_per_ms_; 419 double frames_delayed = static_cast<double>(pending_data) / bytes_per_frame_;
418 420
419 callback_num_++; 421 callback_num_++;
420 TRACE_EVENT1("audio", "AudioOutputDevice::FireRenderCallback", 422 TRACE_EVENT1("audio", "AudioOutputDevice::FireRenderCallback",
421 "callback_num", callback_num_); 423 "callback_num", callback_num_);
422 424
423 // When playback starts, we get an immediate callback to Process to make sure 425 // 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 426 // 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. 427 // ingesting data, which is what we want to track with this trace.
426 if (callback_num_ == 2) { 428 if (callback_num_ == 2) {
427 TRACE_EVENT_ASYNC_END0("audio", "StartingPlayback", this); 429 TRACE_EVENT_ASYNC_END0("audio", "StartingPlayback", this);
428 } 430 }
429 431
430 // Read and reset the number of frames skipped. 432 // Read and reset the number of frames skipped.
431 AudioOutputBuffer* buffer = 433 AudioOutputBuffer* buffer =
432 reinterpret_cast<AudioOutputBuffer*>(shared_memory_.memory()); 434 reinterpret_cast<AudioOutputBuffer*>(shared_memory_.memory());
433 uint32_t frames_skipped = buffer->params.frames_skipped; 435 uint32_t frames_skipped = buffer->params.frames_skipped;
434 buffer->params.frames_skipped = 0; 436 buffer->params.frames_skipped = 0;
435 437
438 DVLOG(4) << __FUNCTION__ << " pending_data:" << pending_data
439 << " frames_delayed(pre-round):" << frames_delayed
440 << " frames_skipped:" << frames_skipped;
441
436 // Update the audio-delay measurement, inform about the number of skipped 442 // Update the audio-delay measurement, inform about the number of skipped
437 // frames, and ask client to render audio. Since |output_bus_| is wrapping 443 // 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 444 // the shared memory the Render() call is writing directly into the shared
439 // memory. 445 // memory.
440 render_callback_->Render(output_bus_.get(), audio_delay_milliseconds, 446 render_callback_->Render(output_bus_.get(), std::round(frames_delayed),
441 frames_skipped); 447 frames_skipped);
442 } 448 }
443 449
444 } // namespace media 450 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_input_device.cc ('k') | media/audio/audio_output_stream_sink.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698