Chromium Code Reviews| Index: media/audio/audio_output_device.h |
| diff --git a/media/audio/audio_output_device.h b/media/audio/audio_output_device.h |
| index 8046fd1060acfd940891502cc75fdc131c53342a..f7b3784666958b88bad371d75cfb3b4d91f0141a 100644 |
| --- a/media/audio/audio_output_device.h |
| +++ b/media/audio/audio_output_device.h |
| @@ -22,16 +22,22 @@ |
| // State sequences. |
| // |
| // Task [IO thread] IPC [IO thread] |
| +// RequestDeviceAuthorization -> RequestDeviceAuthorizationOnIOThread ------> |
| +// RequestDeviceAuthorization -> |
| +// <- OnDeviceAuthorized <- AudioMsg_NotifyDeviceAuthorized <- |
| // |
| // Start -> CreateStreamOnIOThread -----> CreateStream ------> |
| // <- OnStreamCreated <- AudioMsg_NotifyStreamCreated <- |
| // ---> PlayOnIOThread -----------> PlayStream --------> |
| // |
| -// Optionally Play() / Pause() sequences may occur: |
| +// Optionally Play() / Pause() / SwitchOutputDevice() sequences may occur: |
| // Play -> PlayOnIOThread --------------> PlayStream ---------> |
| // Pause -> PauseOnIOThread ------------> PauseStream --------> |
| -// (note that Play() / Pause() sequences before OnStreamCreated are |
| -// deferred until OnStreamCreated, with the last valid state being used) |
| +// SwitchOutputDevice -> SwitchOutputDeviceOnIOThread -> SwitchOutputDevice -> |
| +// <- OnOutputDeviceSwitched <- AudioMsg_NotifyOutputDeviceSwitched <- |
| +// (note that Play() / Pause() / SwitchOutptuDevice() sequences before |
| +// OnStreamCreated are deferred until OnStreamCreated, with the last valid |
| +// state being used) |
| // |
| // AudioOutputDevice::Render => audio transport on audio thread => |
| // | |
| @@ -64,6 +70,7 @@ |
| #include "base/bind.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/memory/shared_memory.h" |
| +#include "base/synchronization/waitable_event.h" |
| #include "media/audio/audio_device_thread.h" |
| #include "media/audio/audio_output_ipc.h" |
| #include "media/audio/audio_parameters.h" |
| @@ -85,11 +92,16 @@ class MEDIA_EXPORT AudioOutputDevice |
| scoped_ptr<AudioOutputIPC> ipc, |
| const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); |
| - // Initialize the stream using |session_id|, which is used for the browser |
| - // to select the correct input device. |
| - void InitializeWithSessionId(const AudioParameters& params, |
| - RenderCallback* callback, |
| - int session_id); |
| + // Create AudioOutputDevice associated with a given output device. |
| + AudioOutputDevice( |
| + scoped_ptr<AudioOutputIPC> ipc, |
| + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
| + int session_id, |
| + const std::string& device_id, |
| + const GURL& security_origin); |
| + |
| + // Request authorization to use the device specified in the constructor. |
| + void RequestDeviceAuthorization(); |
| // AudioRendererSink implementation. |
| void Initialize(const AudioParameters& params, |
| @@ -105,15 +117,19 @@ class MEDIA_EXPORT AudioOutputDevice |
| void SwitchOutputDevice(const std::string& device_id, |
| const GURL& security_origin, |
| const SwitchOutputDeviceCB& callback) override; |
| + AudioParameters GetOutputParameters() override; |
| // Methods called on IO thread ---------------------------------------------- |
| // AudioOutputIPCDelegate methods. |
| void OnStateChanged(AudioOutputIPCDelegateState state) override; |
| + void OnDeviceAuthorized(bool success, |
| + const media::AudioParameters& output_params) override; |
| void OnStreamCreated(base::SharedMemoryHandle handle, |
| base::SyncSocket::Handle socket_handle, |
| int length) override; |
| - void OnOutputDeviceSwitched(int request_id, |
| - SwitchOutputDeviceResult result) override; |
| + void OnOutputDeviceSwitched( |
| + SwitchOutputDeviceResult result, |
| + const media::AudioParameters& output_params) override; |
| void OnIPCClosed() override; |
| protected: |
| @@ -125,10 +141,13 @@ class MEDIA_EXPORT AudioOutputDevice |
| private: |
| // Note: The ordering of members in this enum is critical to correct behavior! |
| enum State { |
| - IPC_CLOSED, // No more IPCs can take place. |
| - IDLE, // Not started. |
| + IPC_CLOSED, // No more IPCs can take place. |
| + IDLE, // Not started. |
| + NOT_AUTHORIZED, // Failed device authorization received. |
|
DaleCurtis
2015/09/12 01:17:19
Should we just reuse IPC_CLOSED for this state?
Guido Urdaneta
2015/09/14 11:35:48
Done.
|
| + AUTHORIZING, // Sent device authorization request, waiting for reply. |
| + AUTHORIZED, // Successful device authorization received. |
| CREATING_STREAM, // Waiting for OnStreamCreated() to be called back. |
| - PAUSED, // Paused. OnStreamCreated() has been called. Can Play()/Stop(). |
| + PAUSED, // Paused. OnStreamCreated() has been called. Can Play()/Stop(). |
| PLAYING, // Playing back. Can Pause()/Stop(). |
| }; |
| @@ -136,6 +155,7 @@ class MEDIA_EXPORT AudioOutputDevice |
| // The following methods are tasks posted on the IO thread that need to |
| // be executed on that thread. They use AudioOutputIPC to send IPC messages |
| // upon state changes. |
| + void RequestDeviceAuthorizationOnIOThread(); |
| void CreateStreamOnIOThread(const AudioParameters& params); |
| void PlayOnIOThread(); |
| void PauseOnIOThread(); |
| @@ -149,7 +169,10 @@ class MEDIA_EXPORT AudioOutputDevice |
| // If the IO loop dies before we do, we shut down the audio thread from here. |
| void WillDestroyCurrentMessageLoop() override; |
| - void SetCurrentSwitchRequest(const SwitchOutputDeviceCB& callback); |
| + void SetCurrentSwitchRequest(const SwitchOutputDeviceCB& callback, |
| + const std::string& device_id, |
| + const GURL& security_origin); |
| + void SetOutputParams(const media::AudioParameters& output_params); |
| AudioParameters audio_parameters_; |
| @@ -164,6 +187,9 @@ class MEDIA_EXPORT AudioOutputDevice |
| // State enum above. |
| State state_; |
| + // State of Start() calls before OnDeviceAuthorized() is called. |
| + bool start_on_authorized_; |
| + |
| // State of Play() / Pause() calls before OnStreamCreated() is called. |
| bool play_on_start_; |
| @@ -171,6 +197,10 @@ class MEDIA_EXPORT AudioOutputDevice |
| // Only used by Unified IO. |
| int session_id_; |
| + // ID of hardware output device to be used (provided session_id_ is zero) |
| + std::string device_id_; |
| + GURL security_origin_; |
| + |
| // Our audio thread callback class. See source file for details. |
| class AudioThreadCallback; |
| @@ -188,8 +218,13 @@ class MEDIA_EXPORT AudioOutputDevice |
| // the callback via Start(). See http://crbug.com/151051 for details. |
| bool stopping_hack_; |
| - int current_switch_request_id_; |
| SwitchOutputDeviceCB current_switch_callback_; |
| + std::string current_switch_device_id_; |
| + GURL current_switch_security_origin_; |
| + bool switch_output_device_on_start_; |
| + |
| + base::WaitableEvent did_set_output_params_; |
| + media::AudioParameters output_params_; |
| DISALLOW_COPY_AND_ASSIGN(AudioOutputDevice); |
| }; |