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 // Audio rendering unit utilizing audio output stream provided by browser | 5 // Audio rendering unit utilizing audio output stream provided by browser |
| 6 // process through IPC. | 6 // process through IPC. |
| 7 // | 7 // |
| 8 // Relationship of classes. | 8 // Relationship of classes. |
| 9 // | 9 // |
| 10 // AudioOutputController AudioOutputDevice | 10 // AudioOutputController AudioOutputDevice |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 #include "base/macros.h" | 68 #include "base/macros.h" |
| 69 #include "base/memory/scoped_ptr.h" | 69 #include "base/memory/scoped_ptr.h" |
| 70 #include "base/memory/shared_memory.h" | 70 #include "base/memory/shared_memory.h" |
| 71 #include "base/synchronization/waitable_event.h" | 71 #include "base/synchronization/waitable_event.h" |
| 72 #include "media/audio/audio_device_thread.h" | 72 #include "media/audio/audio_device_thread.h" |
| 73 #include "media/audio/audio_output_ipc.h" | 73 #include "media/audio/audio_output_ipc.h" |
| 74 #include "media/audio/audio_parameters.h" | 74 #include "media/audio/audio_parameters.h" |
| 75 #include "media/audio/scoped_task_runner_observer.h" | 75 #include "media/audio/scoped_task_runner_observer.h" |
| 76 #include "media/base/audio_renderer_sink.h" | 76 #include "media/base/audio_renderer_sink.h" |
| 77 #include "media/base/media_export.h" | 77 #include "media/base/media_export.h" |
| 78 #include "media/base/output_device.h" | 78 #include "media/base/output_device_info.h" |
| 79 | 79 |
| 80 namespace media { | 80 namespace media { |
| 81 | 81 |
| 82 class MEDIA_EXPORT AudioOutputDevice | 82 class MEDIA_EXPORT AudioOutputDevice |
| 83 : NON_EXPORTED_BASE(public AudioRendererSink), | 83 : NON_EXPORTED_BASE(public AudioRendererSink), |
| 84 NON_EXPORTED_BASE(public AudioOutputIPCDelegate), | 84 NON_EXPORTED_BASE(public AudioOutputIPCDelegate), |
| 85 NON_EXPORTED_BASE(public OutputDevice), | |
| 86 NON_EXPORTED_BASE(public ScopedTaskRunnerObserver) { | 85 NON_EXPORTED_BASE(public ScopedTaskRunnerObserver) { |
| 87 public: | 86 public: |
| 88 // NOTE: Clients must call Initialize() before using. | 87 // NOTE: Clients must call Initialize() before using. |
| 89 AudioOutputDevice( | 88 AudioOutputDevice( |
| 90 scoped_ptr<AudioOutputIPC> ipc, | 89 scoped_ptr<AudioOutputIPC> ipc, |
| 91 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 90 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
| 92 int session_id, | 91 int session_id, |
| 93 const std::string& device_id, | 92 const std::string& device_id, |
| 94 const url::Origin& security_origin); | 93 const url::Origin& security_origin); |
| 95 | 94 |
| 96 // Request authorization to use the device specified in the constructor. | 95 // Request authorization to use the device specified in the constructor. |
| 97 void RequestDeviceAuthorization(); | 96 void RequestDeviceAuthorization(); |
| 98 | 97 |
| 99 // AudioRendererSink implementation. | 98 // AudioRendererSink implementation. |
| 100 void Initialize(const AudioParameters& params, | 99 void Initialize(const AudioParameters& params, |
| 101 RenderCallback* callback) override; | 100 RenderCallback* callback) override; |
| 102 void Start() override; | 101 void Start() override; |
| 103 void Stop() override; | 102 void Stop() override; |
| 104 void Play() override; | 103 void Play() override; |
| 105 void Pause() override; | 104 void Pause() override; |
| 106 bool SetVolume(double volume) override; | 105 bool SetVolume(double volume) override; |
| 107 OutputDevice* GetOutputDevice() override; | |
| 108 | 106 |
| 109 // OutputDevice implementation | 107 // Returns output device information. |
|
Guido Urdaneta
2016/03/22 15:30:18
This documentation is already in audio_renderer_si
o1ka
2016/03/22 16:13:56
Done.
| |
| 110 AudioParameters GetOutputParameters() override; | 108 // If the information is not available yet, this method may block until it |
| 111 OutputDeviceStatus GetDeviceStatus() override; | 109 // becomes available. Must never be called on the IO thread. |
| 110 OutputDeviceInfo GetOutputDeviceInfo() override; | |
| 112 | 111 |
| 113 // Methods called on IO thread ---------------------------------------------- | 112 // Methods called on IO thread ---------------------------------------------- |
| 114 // AudioOutputIPCDelegate methods. | 113 // AudioOutputIPCDelegate methods. |
| 115 void OnStateChanged(AudioOutputIPCDelegateState state) override; | 114 void OnStateChanged(AudioOutputIPCDelegateState state) override; |
| 116 void OnDeviceAuthorized(OutputDeviceStatus device_status, | 115 void OnDeviceAuthorized(OutputDeviceStatus device_status, |
| 117 const media::AudioParameters& output_params) override; | 116 const media::AudioParameters& output_params) override; |
| 118 void OnStreamCreated(base::SharedMemoryHandle handle, | 117 void OnStreamCreated(base::SharedMemoryHandle handle, |
| 119 base::SyncSocket::Handle socket_handle, | 118 base::SyncSocket::Handle socket_handle, |
| 120 int length) override; | 119 int length) override; |
| 121 void OnIPCClosed() override; | 120 void OnIPCClosed() override; |
| 122 | 121 |
| 123 protected: | 122 protected: |
| 124 // Magic required by ref_counted.h to avoid any code deleting the object | 123 // Magic required by ref_counted.h to avoid any code deleting the object |
| 125 // accidentally while there are references to it. | 124 // accidentally while there are references to it. |
| 126 friend class base::RefCountedThreadSafe<AudioOutputDevice>; | 125 friend class base::RefCountedThreadSafe<AudioOutputDevice>; |
| 127 ~AudioOutputDevice() override; | 126 ~AudioOutputDevice() override; |
| 128 | 127 |
| 129 private: | 128 private: |
| 130 // Note: The ordering of members in this enum is critical to correct behavior! | 129 // Note: The ordering of members in this enum is critical to correct behavior! |
| 131 enum State { | 130 enum State { |
| 132 IPC_CLOSED, // No more IPCs can take place. | 131 IPC_CLOSED, // No more IPCs can take place. |
| 133 IDLE, // Not started. | 132 IDLE, // Not started. |
| 134 AUTHORIZING, // Sent device authorization request, waiting for reply. | 133 AUTHORIZING, // Sent device authorization request, waiting for reply. |
| 135 AUTHORIZED, // Successful device authorization received. | 134 AUTHORIZED, // Successful device authorization received. |
| 136 CREATING_STREAM, // Waiting for OnStreamCreated() to be called back. | 135 CREATING_STREAM, // Waiting for OnStreamCreated() to be called back. |
| 137 PAUSED, // Paused. OnStreamCreated() has been called. Can Play()/Stop(). | 136 PAUSED, // Paused. OnStreamCreated() has been called. Can Play()/Stop(). |
| 138 PLAYING, // Playing back. Can Pause()/Stop(). | 137 PLAYING, // Playing back. Can Pause()/Stop(). |
| 139 }; | 138 }; |
| 140 | 139 |
| 141 // Unsupported OutputDevice implementation | |
| 142 void SwitchOutputDevice(const std::string& device_id, | |
| 143 const url::Origin& security_origin, | |
| 144 const SwitchOutputDeviceCB& callback) override; | |
| 145 | |
| 146 // Methods called on IO thread ---------------------------------------------- | 140 // Methods called on IO thread ---------------------------------------------- |
| 147 // The following methods are tasks posted on the IO thread that need to | 141 // The following methods are tasks posted on the IO thread that need to |
| 148 // be executed on that thread. They use AudioOutputIPC to send IPC messages | 142 // be executed on that thread. They use AudioOutputIPC to send IPC messages |
| 149 // upon state changes. | 143 // upon state changes. |
| 150 void RequestDeviceAuthorizationOnIOThread(); | 144 void RequestDeviceAuthorizationOnIOThread(); |
| 151 void CreateStreamOnIOThread(const AudioParameters& params); | 145 void CreateStreamOnIOThread(const AudioParameters& params); |
| 152 void PlayOnIOThread(); | 146 void PlayOnIOThread(); |
| 153 void PauseOnIOThread(); | 147 void PauseOnIOThread(); |
| 154 void ShutDownOnIOThread(); | 148 void ShutDownOnIOThread(); |
| 155 void SetVolumeOnIOThread(double volume); | 149 void SetVolumeOnIOThread(double volume); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 | 190 |
| 197 // Temporary hack to ignore OnStreamCreated() due to the user calling Stop() | 191 // Temporary hack to ignore OnStreamCreated() due to the user calling Stop() |
| 198 // so we don't start the audio thread pointing to a potentially freed | 192 // so we don't start the audio thread pointing to a potentially freed |
| 199 // |callback_|. | 193 // |callback_|. |
| 200 // | 194 // |
| 201 // TODO(scherkus): Replace this by changing AudioRendererSink to either accept | 195 // TODO(scherkus): Replace this by changing AudioRendererSink to either accept |
| 202 // the callback via Start(). See http://crbug.com/151051 for details. | 196 // the callback via Start(). See http://crbug.com/151051 for details. |
| 203 bool stopping_hack_; | 197 bool stopping_hack_; |
| 204 | 198 |
| 205 base::WaitableEvent did_receive_auth_; | 199 base::WaitableEvent did_receive_auth_; |
| 206 media::AudioParameters output_params_; | 200 AudioParameters output_params_; |
| 207 OutputDeviceStatus device_status_; | 201 OutputDeviceStatus device_status_; |
| 208 | 202 |
| 209 DISALLOW_COPY_AND_ASSIGN(AudioOutputDevice); | 203 DISALLOW_COPY_AND_ASSIGN(AudioOutputDevice); |
| 210 }; | 204 }; |
| 211 | 205 |
| 212 } // namespace media | 206 } // namespace media |
| 213 | 207 |
| 214 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_ | 208 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_ |
| OLD | NEW |