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

Unified Diff: media/audio/audio_output_device.cc

Issue 2437863004: Make more media APIs aware of |delay| and |delay_timestamp| (Closed)
Patch Set: Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: media/audio/audio_output_device.cc
diff --git a/media/audio/audio_output_device.cc b/media/audio/audio_output_device.cc
index 0dcc76aca062b19bbdfb941088d053c1d1970ad3..25ea86a239c98a480ab2297a13bbc3b29b2ed7d2 100644
--- a/media/audio/audio_output_device.cc
+++ b/media/audio/audio_output_device.cc
@@ -20,6 +20,7 @@
#include "build/build_config.h"
#include "media/audio/audio_device_description.h"
#include "media/audio/audio_output_controller.h"
+#include "media/base/audio_timestamp_helper.h"
#include "media/base/limits.h"
namespace media {
@@ -39,14 +40,14 @@ class AudioOutputDevice::AudioThreadCallback
void MapSharedMemory() override;
// Called whenever we receive notifications about pending data.
- void Process(uint32_t pending_data) override;
+ void Process(int64_t pending_data, base::TimeTicks delay_timestamp) override;
// Returns whether the current thread is the audio device thread or not.
// Will always return true if DCHECKs are not enabled.
bool CurrentThreadIsAudioDeviceThread();
private:
- const int bytes_per_frame_;
+ const int frame_rate_;
AudioRendererSink::RenderCallback* render_callback_;
std::unique_ptr<AudioBus> output_bus_;
uint64_t callback_num_;
@@ -431,7 +432,7 @@ AudioOutputDevice::AudioThreadCallback::AudioThreadCallback(
int memory_length,
AudioRendererSink::RenderCallback* render_callback)
: AudioDeviceThread::Callback(audio_parameters, memory, memory_length, 1),
- bytes_per_frame_(audio_parameters.GetBytesPerFrame()),
+ frame_rate_(audio_parameters.sample_rate()),
render_callback_(render_callback),
callback_num_(0) {}
@@ -451,9 +452,10 @@ void AudioOutputDevice::AudioThreadCallback::MapSharedMemory() {
}
// Called whenever we receive notifications about pending data.
-void AudioOutputDevice::AudioThreadCallback::Process(uint32_t pending_data) {
- // Convert the number of pending bytes in the render buffer into frames.
- double frames_delayed = static_cast<double>(pending_data) / bytes_per_frame_;
+void AudioOutputDevice::AudioThreadCallback::Process(
+ int64_t pending_data,
+ base::TimeTicks delay_timestamp) {
+ base::TimeDelta delay = base::TimeDelta::FromInternalValue(pending_data);
miu 2016/10/23 01:19:16 Instead of passing pending_data as an int64_t, cou
Mikhail 2016/10/24 19:50:24 The reason for keeping this is 'AudioInputDevice::
callback_num_++;
TRACE_EVENT1("audio", "AudioOutputDevice::FireRenderCallback",
@@ -472,15 +474,19 @@ void AudioOutputDevice::AudioThreadCallback::Process(uint32_t pending_data) {
uint32_t frames_skipped = buffer->params.frames_skipped;
buffer->params.frames_skipped = 0;
- DVLOG(4) << __func__ << " pending_data:" << pending_data
- << " frames_delayed(pre-round):" << frames_delayed
+ DVLOG(4) << __func__ << " delay:" << delay
<< " frames_skipped:" << frames_skipped;
+ // TODO(Mikhail) : Now all clients expect that bus duration included to
+ // |delay|. We should reconsider this.
+ const int frames = output_bus_->frames();
chcunningham 2016/10/21 18:19:47 I'm confused. Why are we doing this here instead o
Mikhail 2016/10/24 19:50:24 Indeed. Thanks for noticing!
+ delay += AudioTimestampHelper::FramesToTime(frames, frame_rate_);
+
// Update the audio-delay measurement, inform about the number of skipped
// frames, and ask client to render audio. Since |output_bus_| is wrapping
// the shared memory the Render() call is writing directly into the shared
// memory.
- render_callback_->Render(output_bus_.get(), std::round(frames_delayed),
+ render_callback_->Render(output_bus_.get(), delay, delay_timestamp,
frames_skipped);
}

Powered by Google App Engine
This is Rietveld 408576698