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

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

Issue 1769933002: Looking up device id by session id for AudioRendererMixerInput (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment and bug ref to remove AudioManagerBase dependency Created 4 years, 8 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_output_device.h ('k') | media/audio/audio_output_device_unittest.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 9
10 #include <cmath> 10 #include <cmath>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/callback_helpers.h" 13 #include "base/callback_helpers.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/threading/thread_restrictions.h" 15 #include "base/threading/thread_restrictions.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "base/trace_event/trace_event.h" 17 #include "base/trace_event/trace_event.h"
18 #include "build/build_config.h" 18 #include "build/build_config.h"
19 #include "media/audio/audio_manager_base.h"
19 #include "media/audio/audio_output_controller.h" 20 #include "media/audio/audio_output_controller.h"
20 #include "media/base/limits.h" 21 #include "media/base/limits.h"
21 22
22 namespace media { 23 namespace media {
23 24
24 // Takes care of invoking the render callback on the audio thread. 25 // Takes care of invoking the render callback on the audio thread.
25 // An instance of this class is created for each capture stream in 26 // An instance of this class is created for each capture stream in
26 // OnStreamCreated(). 27 // OnStreamCreated().
27 class AudioOutputDevice::AudioThreadCallback 28 class AudioOutputDevice::AudioThreadCallback
28 : public AudioDeviceThread::Callback { 29 : public AudioDeviceThread::Callback {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 base::Bind(&AudioOutputDevice::SetVolumeOnIOThread, this, volume))) { 135 base::Bind(&AudioOutputDevice::SetVolumeOnIOThread, this, volume))) {
135 return false; 136 return false;
136 } 137 }
137 138
138 return true; 139 return true;
139 } 140 }
140 141
141 OutputDeviceInfo AudioOutputDevice::GetOutputDeviceInfo() { 142 OutputDeviceInfo AudioOutputDevice::GetOutputDeviceInfo() {
142 CHECK(!task_runner()->BelongsToCurrentThread()); 143 CHECK(!task_runner()->BelongsToCurrentThread());
143 did_receive_auth_.Wait(); 144 did_receive_auth_.Wait();
144 return OutputDeviceInfo(device_id_, device_status_, output_params_); 145 return OutputDeviceInfo(
146 AudioManagerBase::UseSessionIdToSelectDevice(session_id_, device_id_)
147 ? matched_device_id_
148 : device_id_,
149 device_status_, output_params_);
145 } 150 }
146 151
147 void AudioOutputDevice::RequestDeviceAuthorizationOnIOThread() { 152 void AudioOutputDevice::RequestDeviceAuthorizationOnIOThread() {
148 DCHECK(task_runner()->BelongsToCurrentThread()); 153 DCHECK(task_runner()->BelongsToCurrentThread());
149 DCHECK_EQ(state_, IDLE); 154 DCHECK_EQ(state_, IDLE);
150 state_ = AUTHORIZING; 155 state_ = AUTHORIZING;
151 ipc_->RequestDeviceAuthorization(this, session_id_, device_id_, 156 ipc_->RequestDeviceAuthorization(this, session_id_, device_id_,
152 security_origin_); 157 security_origin_);
153 } 158 }
154 159
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 callback_->OnRenderError(); 274 callback_->OnRenderError();
270 break; 275 break;
271 default: 276 default:
272 NOTREACHED(); 277 NOTREACHED();
273 break; 278 break;
274 } 279 }
275 } 280 }
276 281
277 void AudioOutputDevice::OnDeviceAuthorized( 282 void AudioOutputDevice::OnDeviceAuthorized(
278 OutputDeviceStatus device_status, 283 OutputDeviceStatus device_status,
279 const media::AudioParameters& output_params) { 284 const media::AudioParameters& output_params,
285 const std::string& matched_device_id) {
280 DCHECK(task_runner()->BelongsToCurrentThread()); 286 DCHECK(task_runner()->BelongsToCurrentThread());
281 DCHECK_EQ(state_, AUTHORIZING); 287 DCHECK_EQ(state_, AUTHORIZING);
282 288
283 // It may happen that a second authorization is received as a result to a 289 // It may happen that a second authorization is received as a result to a
284 // call to Start() after Stop(). If the status for the second authorization 290 // call to Start() after Stop(). If the status for the second authorization
285 // differs from the first, it will not be reflected in |device_status_| 291 // differs from the first, it will not be reflected in |device_status_|
286 // to avoid a race. 292 // to avoid a race.
287 // This scenario is unlikely. If it occurs, the new value will be 293 // This scenario is unlikely. If it occurs, the new value will be
288 // different from OUTPUT_DEVICE_STATUS_OK, so the AudioOutputDevice 294 // different from OUTPUT_DEVICE_STATUS_OK, so the AudioOutputDevice
289 // will enter the IPC_CLOSED state anyway, which is the safe thing to do. 295 // will enter the IPC_CLOSED state anyway, which is the safe thing to do.
290 // This is preferable to holding a lock. 296 // This is preferable to holding a lock.
291 if (!did_receive_auth_.IsSignaled()) 297 if (!did_receive_auth_.IsSignaled())
292 device_status_ = device_status; 298 device_status_ = device_status;
293 299
294 if (device_status == OUTPUT_DEVICE_STATUS_OK) { 300 if (device_status == OUTPUT_DEVICE_STATUS_OK) {
295 state_ = AUTHORIZED; 301 state_ = AUTHORIZED;
296 if (!did_receive_auth_.IsSignaled()) { 302 if (!did_receive_auth_.IsSignaled()) {
297 output_params_ = output_params; 303 output_params_ = output_params;
304
305 // It's possible to not have a matched device obtained via session id. It
306 // means matching output device through |session_id_| failed and the
307 // default device is used.
308 DCHECK(AudioManagerBase::UseSessionIdToSelectDevice(session_id_,
309 device_id_) ||
310 matched_device_id_.empty());
311 matched_device_id_ = matched_device_id;
312
313 DVLOG(1) << "AudioOutputDevice authorized, session_id: " << session_id_
314 << ", device_id: " << device_id_
315 << ", matched_device_id: " << matched_device_id_;
316
298 did_receive_auth_.Signal(); 317 did_receive_auth_.Signal();
299 } 318 }
300 if (start_on_authorized_) 319 if (start_on_authorized_)
301 CreateStreamOnIOThread(audio_parameters_); 320 CreateStreamOnIOThread(audio_parameters_);
302 } else { 321 } else {
303 // Closing IPC forces a Signal(), so no clients are locked waiting 322 // Closing IPC forces a Signal(), so no clients are locked waiting
304 // indefinitely after this method returns. 323 // indefinitely after this method returns.
305 ipc_->CloseStream(); 324 ipc_->CloseStream();
306 OnIPCClosed(); 325 OnIPCClosed();
307 if (callback_) 326 if (callback_)
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 443
425 // Update the audio-delay measurement, inform about the number of skipped 444 // Update the audio-delay measurement, inform about the number of skipped
426 // frames, and ask client to render audio. Since |output_bus_| is wrapping 445 // frames, and ask client to render audio. Since |output_bus_| is wrapping
427 // the shared memory the Render() call is writing directly into the shared 446 // the shared memory the Render() call is writing directly into the shared
428 // memory. 447 // memory.
429 render_callback_->Render(output_bus_.get(), std::round(frames_delayed), 448 render_callback_->Render(output_bus_.get(), std::round(frames_delayed),
430 frames_skipped); 449 frames_skipped);
431 } 450 }
432 451
433 } // namespace media 452 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_output_device.h ('k') | media/audio/audio_output_device_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698