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

Side by Side Diff: media/base/audio_renderer_mixer_input.cc

Issue 2067863003: Mixing audio with different latency requirements (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: android test fix Created 4 years, 5 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_input.h" 5 #include "media/base/audio_renderer_mixer_input.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
11 #include "media/base/audio_renderer_mixer.h" 11 #include "media/base/audio_renderer_mixer.h"
12 #include "media/base/audio_renderer_mixer_pool.h" 12 #include "media/base/audio_renderer_mixer_pool.h"
13 13
14 namespace media { 14 namespace media {
15 15
16 AudioRendererMixerInput::AudioRendererMixerInput( 16 AudioRendererMixerInput::AudioRendererMixerInput(
17 AudioRendererMixerPool* mixer_pool, 17 AudioRendererMixerPool* mixer_pool,
18 int owner_id, 18 int owner_id,
19 const std::string& device_id, 19 const std::string& device_id,
20 const url::Origin& security_origin) 20 const url::Origin& security_origin,
21 AudioLatency::LatencyType latency)
21 : mixer_pool_(mixer_pool), 22 : mixer_pool_(mixer_pool),
22 started_(false), 23 started_(false),
23 playing_(false), 24 playing_(false),
24 volume_(1.0f), 25 volume_(1.0f),
25 owner_id_(owner_id), 26 owner_id_(owner_id),
26 device_id_(device_id), 27 device_id_(device_id),
27 security_origin_(security_origin), 28 security_origin_(security_origin),
29 latency_(latency),
28 mixer_(nullptr), 30 mixer_(nullptr),
29 callback_(nullptr), 31 callback_(nullptr),
30 error_cb_(base::Bind(&AudioRendererMixerInput::OnRenderError, 32 error_cb_(base::Bind(&AudioRendererMixerInput::OnRenderError,
31 base::Unretained(this))) { 33 base::Unretained(this))) {
32 DCHECK(mixer_pool_); 34 DCHECK(mixer_pool_);
33 } 35 }
34 36
35 AudioRendererMixerInput::~AudioRendererMixerInput() { 37 AudioRendererMixerInput::~AudioRendererMixerInput() {
36 DCHECK(!started_); 38 DCHECK(!started_);
37 DCHECK(!mixer_); 39 DCHECK(!mixer_);
38 } 40 }
39 41
40 void AudioRendererMixerInput::Initialize( 42 void AudioRendererMixerInput::Initialize(
41 const AudioParameters& params, 43 const AudioParameters& params,
42 AudioRendererSink::RenderCallback* callback) { 44 AudioRendererSink::RenderCallback* callback) {
43 DCHECK(!started_); 45 DCHECK(!started_);
44 DCHECK(!mixer_); 46 DCHECK(!mixer_);
45 DCHECK(callback); 47 DCHECK(callback);
46 48
47 params_ = params; 49 params_ = params;
48 callback_ = callback; 50 callback_ = callback;
49 } 51 }
50 52
51 void AudioRendererMixerInput::Start() { 53 void AudioRendererMixerInput::Start() {
52 DCHECK(!started_); 54 DCHECK(!started_);
53 DCHECK(!mixer_); 55 DCHECK(!mixer_);
54 DCHECK(callback_); // Initialized. 56 DCHECK(callback_); // Initialized.
55 57
56 started_ = true; 58 started_ = true;
57 mixer_ = mixer_pool_->GetMixer(owner_id_, params_, device_id_, 59 mixer_ = mixer_pool_->GetMixer(owner_id_, params_, latency_, device_id_,
58 security_origin_, nullptr); 60 security_origin_, nullptr);
59 if (!mixer_) { 61 if (!mixer_) {
60 callback_->OnRenderError(); 62 callback_->OnRenderError();
61 return; 63 return;
62 } 64 }
63 65
64 // Note: OnRenderError() may be called immediately after this call returns. 66 // Note: OnRenderError() may be called immediately after this call returns.
65 mixer_->AddErrorCallback(error_cb_); 67 mixer_->AddErrorCallback(error_cb_);
66 68
67 if (!pending_switch_callback_.is_null()) { 69 if (!pending_switch_callback_.is_null()) {
68 SwitchOutputDevice(pending_switch_device_id_, 70 SwitchOutputDevice(pending_switch_device_id_,
69 pending_switch_security_origin_, 71 pending_switch_security_origin_,
70 base::ResetAndReturn(&pending_switch_callback_)); 72 base::ResetAndReturn(&pending_switch_callback_));
71 } 73 }
72 } 74 }
73 75
74 void AudioRendererMixerInput::Stop() { 76 void AudioRendererMixerInput::Stop() {
75 // Stop() may be called at any time, if Pause() hasn't been called we need to 77 // Stop() may be called at any time, if Pause() hasn't been called we need to
76 // remove our mixer input before shutdown. 78 // remove our mixer input before shutdown.
77 Pause(); 79 Pause();
78 80
79 if (mixer_) { 81 if (mixer_) {
80 // TODO(dalecurtis): This is required so that |callback_| isn't called after 82 // TODO(dalecurtis): This is required so that |callback_| isn't called after
81 // Stop() by an error event since it may outlive this ref-counted object. We 83 // Stop() by an error event since it may outlive this ref-counted object. We
82 // should instead have sane ownership semantics: http://crbug.com/151051 84 // should instead have sane ownership semantics: http://crbug.com/151051
83 mixer_->RemoveErrorCallback(error_cb_); 85 mixer_->RemoveErrorCallback(error_cb_);
84 mixer_pool_->ReturnMixer(owner_id_, params_, device_id_, security_origin_); 86 mixer_pool_->ReturnMixer(mixer_);
85 mixer_ = nullptr; 87 mixer_ = nullptr;
86 } 88 }
87 89
88 started_ = false; 90 started_ = false;
89 91
90 if (!pending_switch_callback_.is_null()) { 92 if (!pending_switch_callback_.is_null()) {
91 base::ResetAndReturn(&pending_switch_callback_) 93 base::ResetAndReturn(&pending_switch_callback_)
92 .Run(OUTPUT_DEVICE_STATUS_ERROR_INTERNAL); 94 .Run(OUTPUT_DEVICE_STATUS_ERROR_INTERNAL);
93 } 95 }
94 } 96 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 return; 144 return;
143 } 145 }
144 146
145 DCHECK(pending_switch_callback_.is_null()); 147 DCHECK(pending_switch_callback_.is_null());
146 if (device_id == device_id_) { 148 if (device_id == device_id_) {
147 callback.Run(OUTPUT_DEVICE_STATUS_OK); 149 callback.Run(OUTPUT_DEVICE_STATUS_OK);
148 return; 150 return;
149 } 151 }
150 152
151 OutputDeviceStatus new_mixer_status = OUTPUT_DEVICE_STATUS_ERROR_INTERNAL; 153 OutputDeviceStatus new_mixer_status = OUTPUT_DEVICE_STATUS_ERROR_INTERNAL;
152 AudioRendererMixer* new_mixer = mixer_pool_->GetMixer( 154 AudioRendererMixer* new_mixer =
153 owner_id_, params_, device_id, security_origin, &new_mixer_status); 155 mixer_pool_->GetMixer(owner_id_, params_, latency_, device_id,
156 security_origin, &new_mixer_status);
154 if (new_mixer_status != OUTPUT_DEVICE_STATUS_OK) { 157 if (new_mixer_status != OUTPUT_DEVICE_STATUS_OK) {
155 callback.Run(new_mixer_status); 158 callback.Run(new_mixer_status);
156 return; 159 return;
157 } 160 }
158 161
159 bool was_playing = playing_; 162 bool was_playing = playing_;
160 Stop(); 163 Stop();
161 device_id_ = device_id; 164 device_id_ = device_id;
162 security_origin_ = security_origin; 165 security_origin_ = security_origin;
163 mixer_ = new_mixer; 166 mixer_ = new_mixer;
(...skipping 23 matching lines...) Expand all
187 base::AutoLock auto_lock(volume_lock_); 190 base::AutoLock auto_lock(volume_lock_);
188 return frames_filled > 0 ? volume_ : 0; 191 return frames_filled > 0 ? volume_ : 0;
189 } 192 }
190 } 193 }
191 194
192 void AudioRendererMixerInput::OnRenderError() { 195 void AudioRendererMixerInput::OnRenderError() {
193 callback_->OnRenderError(); 196 callback_->OnRenderError();
194 } 197 }
195 198
196 } // namespace media 199 } // namespace media
OLDNEW
« no previous file with comments | « media/base/audio_renderer_mixer_input.h ('k') | media/base/audio_renderer_mixer_input_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698