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

Side by Side Diff: media/base/audio_renderer_mixer.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/base/audio_renderer_mixer.h" 5 #include "media/base/audio_renderer_mixer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
11 namespace media { 11 namespace media {
12 12
13 enum { kPauseDelaySeconds = 10 }; 13 enum { kPauseDelaySeconds = 10 };
14 14
15 AudioRendererMixer::AudioRendererMixer( 15 AudioRendererMixer::AudioRendererMixer(
16 const AudioParameters& output_params, 16 const AudioParameters& output_params,
17 const scoped_refptr<AudioRendererSink>& sink) 17 const scoped_refptr<AudioRendererSink>& sink)
18 : audio_sink_(sink), 18 : audio_sink_(sink),
19 output_params_(output_params), 19 output_params_(output_params),
20 microseconds_per_frame_(
DaleCurtis 2016/02/11 01:57:15 Should we instead have a AudioParameters::GetMicro
chcunningham 2016/02/11 21:02:52 Done.
21 static_cast<double>(base::Time::kMicrosecondsPerSecond) /
22 output_params.sample_rate()),
20 master_converter_(output_params, output_params, true), 23 master_converter_(output_params, output_params, true),
21 pause_delay_(base::TimeDelta::FromSeconds(kPauseDelaySeconds)), 24 pause_delay_(base::TimeDelta::FromSeconds(kPauseDelaySeconds)),
22 last_play_time_(base::TimeTicks::Now()), 25 last_play_time_(base::TimeTicks::Now()),
23 // Initialize |playing_| to true since Start() results in an auto-play. 26 // Initialize |playing_| to true since Start() results in an auto-play.
24 playing_(true) { 27 playing_(true) {
25 audio_sink_->Initialize(output_params, this); 28 audio_sink_->Initialize(output_params, this);
26 audio_sink_->Start(); 29 audio_sink_->Start();
27 } 30 }
28 31
29 AudioRendererMixer::~AudioRendererMixer() { 32 AudioRendererMixer::~AudioRendererMixer() {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 NOTREACHED(); 113 NOTREACHED();
111 } 114 }
112 115
113 OutputDevice* AudioRendererMixer::GetOutputDevice() { 116 OutputDevice* AudioRendererMixer::GetOutputDevice() {
114 DVLOG(1) << __FUNCTION__; 117 DVLOG(1) << __FUNCTION__;
115 base::AutoLock auto_lock(lock_); 118 base::AutoLock auto_lock(lock_);
116 return audio_sink_->GetOutputDevice(); 119 return audio_sink_->GetOutputDevice();
117 } 120 }
118 121
119 int AudioRendererMixer::Render(AudioBus* audio_bus, 122 int AudioRendererMixer::Render(AudioBus* audio_bus,
120 uint32_t audio_delay_milliseconds, 123 uint32_t frames_delayed,
121 uint32_t frames_skipped) { 124 uint32_t frames_skipped) {
122 base::AutoLock auto_lock(lock_); 125 base::AutoLock auto_lock(lock_);
123 126
124 // If there are no mixer inputs and we haven't seen one for a while, pause the 127 // If there are no mixer inputs and we haven't seen one for a while, pause the
125 // sink to avoid wasting resources when media elements are present but remain 128 // sink to avoid wasting resources when media elements are present but remain
126 // in the pause state. 129 // in the pause state.
127 const base::TimeTicks now = base::TimeTicks::Now(); 130 const base::TimeTicks now = base::TimeTicks::Now();
128 if (!master_converter_.empty()) { 131 if (!master_converter_.empty()) {
129 last_play_time_ = now; 132 last_play_time_ = now;
130 } else if (now - last_play_time_ >= pause_delay_ && playing_) { 133 } else if (now - last_play_time_ >= pause_delay_ && playing_) {
131 audio_sink_->Pause(); 134 audio_sink_->Pause();
132 playing_ = false; 135 playing_ = false;
133 } 136 }
134 137
135 master_converter_.ConvertWithDelay( 138 base::TimeDelta audio_delay = base::TimeDelta::FromMicroseconds(
136 base::TimeDelta::FromMilliseconds(audio_delay_milliseconds), audio_bus); 139 frames_delayed * microseconds_per_frame_);
140
DaleCurtis 2016/02/11 01:57:15 Mark as TODO: Remove conversion once AudioConverte
chcunningham 2016/02/11 21:02:52 Done.
141 master_converter_.ConvertWithDelay(audio_delay, audio_bus);
137 return audio_bus->frames(); 142 return audio_bus->frames();
138 } 143 }
139 144
140 void AudioRendererMixer::OnRenderError() { 145 void AudioRendererMixer::OnRenderError() {
141 // Call each mixer input and signal an error. 146 // Call each mixer input and signal an error.
142 base::AutoLock auto_lock(lock_); 147 base::AutoLock auto_lock(lock_);
143 for (const auto& cb : error_callbacks_) 148 for (const auto& cb : error_callbacks_)
144 cb.Run(); 149 cb.Run();
145 } 150 }
146 151
147 } // namespace media 152 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698