Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 16 #include "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
| 17 #include "base/time/time.h" | 17 #include "base/timer/elapsed_timer.h" |
| 18 #include "base/timer/timer.h" | 18 #include "base/timer/timer.h" |
| 19 #include "base/trace_event/trace_event.h" | 19 #include "base/trace_event/trace_event.h" |
| 20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 21 #include "media/audio/audio_device_description.h" | 21 #include "media/audio/audio_device_description.h" |
| 22 #include "media/audio/audio_output_controller.h" | 22 #include "media/audio/audio_output_controller.h" |
| 23 #include "media/base/limits.h" | 23 #include "media/base/limits.h" |
| 24 | 24 |
| 25 namespace media { | 25 namespace media { |
| 26 | 26 |
| 27 // Takes care of invoking the render callback on the audio thread. | 27 // Takes care of invoking the render callback on the audio thread. |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 return audio_callback_->CurrentThreadIsAudioDeviceThread(); | 162 return audio_callback_->CurrentThreadIsAudioDeviceThread(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void AudioOutputDevice::RequestDeviceAuthorizationOnIOThread() { | 165 void AudioOutputDevice::RequestDeviceAuthorizationOnIOThread() { |
| 166 DCHECK(task_runner()->BelongsToCurrentThread()); | 166 DCHECK(task_runner()->BelongsToCurrentThread()); |
| 167 DCHECK_EQ(state_, IDLE); | 167 DCHECK_EQ(state_, IDLE); |
| 168 state_ = AUTHORIZING; | 168 state_ = AUTHORIZING; |
| 169 ipc_->RequestDeviceAuthorization(this, session_id_, device_id_, | 169 ipc_->RequestDeviceAuthorization(this, session_id_, device_id_, |
| 170 security_origin_); | 170 security_origin_); |
| 171 | 171 |
| 172 auth_timer_.reset(new base::ElapsedTimer()); | |
| 172 if (auth_timeout_ > base::TimeDelta()) { | 173 if (auth_timeout_ > base::TimeDelta()) { |
| 173 // Create the timer on the thread it's used on. It's guaranteed to be | 174 // Create the timer on the thread it's used on. It's guaranteed to be |
| 174 // deleted on the same thread since users must call Stop() before deleting | 175 // deleted on the same thread since users must call Stop() before deleting |
| 175 // AudioOutputDevice; see ShutDownOnIOThread(). | 176 // AudioOutputDevice; see ShutDownOnIOThread(). |
| 176 auth_timeout_action_.reset(new base::OneShotTimer()); | 177 auth_timeout_action_.reset(new base::OneShotTimer()); |
| 177 auth_timeout_action_->Start( | 178 auth_timeout_action_->Start( |
| 178 FROM_HERE, auth_timeout_, | 179 FROM_HERE, auth_timeout_, |
| 179 base::Bind(&AudioOutputDevice::OnDeviceAuthorized, this, | 180 base::Bind(&AudioOutputDevice::OnDeviceAuthorized, this, |
| 180 OUTPUT_DEVICE_STATUS_ERROR_TIMED_OUT, | 181 OUTPUT_DEVICE_STATUS_ERROR_TIMED_OUT, |
| 181 media::AudioParameters(), std::string())); | 182 media::AudioParameters(), std::string())); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 | 319 |
| 319 auth_timeout_action_.reset(); | 320 auth_timeout_action_.reset(); |
| 320 | 321 |
| 321 // Do nothing if late authorization is received after timeout. | 322 // Do nothing if late authorization is received after timeout. |
| 322 if (state_ == IPC_CLOSED) | 323 if (state_ == IPC_CLOSED) |
| 323 return; | 324 return; |
| 324 | 325 |
| 325 UMA_HISTOGRAM_BOOLEAN("Media.Audio.Render.OutputDeviceAuthorizationTimedOut", | 326 UMA_HISTOGRAM_BOOLEAN("Media.Audio.Render.OutputDeviceAuthorizationTimedOut", |
| 326 device_status == OUTPUT_DEVICE_STATUS_ERROR_TIMED_OUT); | 327 device_status == OUTPUT_DEVICE_STATUS_ERROR_TIMED_OUT); |
| 327 | 328 |
| 329 DCHECK(auth_timer_); | |
| 330 UMA_HISTOGRAM_CUSTOM_TIMES("Media.Audio.Render.OutputDeviceAuthorizationTime", | |
|
DaleCurtis
2016/07/07 17:39:39
This doesn't allow us to make adjustments without
| |
| 331 auth_timer_->Elapsed(), | |
| 332 base::TimeDelta::FromMilliseconds(1), | |
| 333 base::TimeDelta::FromMilliseconds(5000), 100); | |
| 334 auth_timer_.reset(); | |
| 335 | |
| 328 DCHECK_EQ(state_, AUTHORIZING); | 336 DCHECK_EQ(state_, AUTHORIZING); |
| 329 | 337 |
| 330 // It may happen that a second authorization is received as a result to a | 338 // It may happen that a second authorization is received as a result to a |
| 331 // call to Start() after Stop(). If the status for the second authorization | 339 // call to Start() after Stop(). If the status for the second authorization |
| 332 // differs from the first, it will not be reflected in |device_status_| | 340 // differs from the first, it will not be reflected in |device_status_| |
| 333 // to avoid a race. | 341 // to avoid a race. |
| 334 // This scenario is unlikely. If it occurs, the new value will be | 342 // This scenario is unlikely. If it occurs, the new value will be |
| 335 // different from OUTPUT_DEVICE_STATUS_OK, so the AudioOutputDevice | 343 // different from OUTPUT_DEVICE_STATUS_OK, so the AudioOutputDevice |
| 336 // will enter the IPC_CLOSED state anyway, which is the safe thing to do. | 344 // will enter the IPC_CLOSED state anyway, which is the safe thing to do. |
| 337 // This is preferable to holding a lock. | 345 // This is preferable to holding a lock. |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 492 render_callback_->Render(output_bus_.get(), std::round(frames_delayed), | 500 render_callback_->Render(output_bus_.get(), std::round(frames_delayed), |
| 493 frames_skipped); | 501 frames_skipped); |
| 494 } | 502 } |
| 495 | 503 |
| 496 bool AudioOutputDevice::AudioThreadCallback:: | 504 bool AudioOutputDevice::AudioThreadCallback:: |
| 497 CurrentThreadIsAudioDeviceThread() { | 505 CurrentThreadIsAudioDeviceThread() { |
| 498 return thread_checker_.CalledOnValidThread(); | 506 return thread_checker_.CalledOnValidThread(); |
| 499 } | 507 } |
| 500 | 508 |
| 501 } // namespace media | 509 } // namespace media |
| OLD | NEW |