| 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..d5ce695e6cac7fe5e18b410fe7b2f451ff9aa2e3 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"
|
| @@ -83,13 +90,13 @@ class MEDIA_EXPORT AudioOutputDevice
|
| // NOTE: Clients must call Initialize() before using.
|
| AudioOutputDevice(
|
| scoped_ptr<AudioOutputIPC> ipc,
|
| - const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner);
|
| + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
|
| + int session_id,
|
| + const std::string& device_id,
|
| + const url::Origin& security_origin);
|
|
|
| - // 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);
|
| + // Request authorization to use the device specified in the constructor.
|
| + void RequestDeviceAuthorization();
|
|
|
| // AudioRendererSink implementation.
|
| void Initialize(const AudioParameters& params,
|
| @@ -103,17 +110,19 @@ class MEDIA_EXPORT AudioOutputDevice
|
|
|
| // OutputDevice implementation
|
| void SwitchOutputDevice(const std::string& device_id,
|
| - const GURL& security_origin,
|
| + const url::Origin& 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) override;
|
| void OnIPCClosed() override;
|
|
|
| protected:
|
| @@ -125,10 +134,12 @@ 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.
|
| + 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,20 +147,24 @@ 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();
|
| void ShutDownOnIOThread();
|
| void SetVolumeOnIOThread(double volume);
|
| void SwitchOutputDeviceOnIOThread(const std::string& device_id,
|
| - const GURL& security_origin,
|
| + const url::Origin& security_origin,
|
| const SwitchOutputDeviceCB& callback);
|
|
|
| // base::MessageLoop::DestructionObserver implementation for the IO loop.
|
| // 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 url::Origin& security_origin);
|
| + void SetOutputParams(const media::AudioParameters& output_params);
|
|
|
| AudioParameters audio_parameters_;
|
|
|
| @@ -164,6 +179,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 +189,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_;
|
| + url::Origin security_origin_;
|
| +
|
| // Our audio thread callback class. See source file for details.
|
| class AudioThreadCallback;
|
|
|
| @@ -188,8 +210,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_;
|
| + url::Origin 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);
|
| };
|
|
|