| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 #include "media/audio/audio_output_ipc.h" | 73 #include "media/audio/audio_output_ipc.h" |
| 74 #include "media/audio/scoped_task_runner_observer.h" | 74 #include "media/audio/scoped_task_runner_observer.h" |
| 75 #include "media/base/audio_parameters.h" | 75 #include "media/base/audio_parameters.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_info.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 RestartableAudioRendererSink), |
| 84 NON_EXPORTED_BASE(public AudioRendererSink::RenderCallback), |
| 84 NON_EXPORTED_BASE(public AudioOutputIPCDelegate), | 85 NON_EXPORTED_BASE(public AudioOutputIPCDelegate), |
| 85 NON_EXPORTED_BASE(public ScopedTaskRunnerObserver) { | 86 NON_EXPORTED_BASE(public ScopedTaskRunnerObserver) { |
| 86 public: | 87 public: |
| 87 // NOTE: Clients must call Initialize() before using. | 88 // NOTE: Clients must call Initialize() before using. |
| 88 AudioOutputDevice( | 89 AudioOutputDevice( |
| 89 std::unique_ptr<AudioOutputIPC> ipc, | 90 std::unique_ptr<AudioOutputIPC> ipc, |
| 90 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 91 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
| 91 int session_id, | 92 int session_id, |
| 92 const std::string& device_id, | 93 const std::string& device_id, |
| 93 const url::Origin& security_origin); | 94 const url::Origin& security_origin); |
| 94 | 95 |
| 95 // Request authorization to use the device specified in the constructor. | 96 // Request authorization to use the device specified in the constructor. |
| 96 void RequestDeviceAuthorization(); | 97 void RequestDeviceAuthorization(); |
| 97 | 98 |
| 98 // AudioRendererSink implementation. | 99 // AudioRendererSink implementation. |
| 99 void Initialize(const AudioParameters& params, | 100 void Initialize(const AudioParameters& params, |
| 100 RenderCallback* callback) override; | 101 AudioRendererSink::RenderCallback* callback) override; |
| 101 void Start() override; | 102 void Start() override; |
| 102 void Stop() override; | 103 void Stop() override; |
| 103 void Play() override; | 104 void Play() override; |
| 104 void Pause() override; | 105 void Pause() override; |
| 105 bool SetVolume(double volume) override; | 106 bool SetVolume(double volume) override; |
| 106 OutputDeviceInfo GetOutputDeviceInfo() override; | 107 OutputDeviceInfo GetOutputDeviceInfo() override; |
| 107 | 108 |
| 108 // Methods called on IO thread ---------------------------------------------- | 109 // Methods called on IO thread ---------------------------------------------- |
| 109 // AudioOutputIPCDelegate methods. | 110 // AudioOutputIPCDelegate methods. |
| 110 void OnStateChanged(AudioOutputIPCDelegateState state) override; | 111 void OnStateChanged(AudioOutputIPCDelegateState state) override; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 127 enum State { | 128 enum State { |
| 128 IPC_CLOSED, // No more IPCs can take place. | 129 IPC_CLOSED, // No more IPCs can take place. |
| 129 IDLE, // Not started. | 130 IDLE, // Not started. |
| 130 AUTHORIZING, // Sent device authorization request, waiting for reply. | 131 AUTHORIZING, // Sent device authorization request, waiting for reply. |
| 131 AUTHORIZED, // Successful device authorization received. | 132 AUTHORIZED, // Successful device authorization received. |
| 132 CREATING_STREAM, // Waiting for OnStreamCreated() to be called back. | 133 CREATING_STREAM, // Waiting for OnStreamCreated() to be called back. |
| 133 PAUSED, // Paused. OnStreamCreated() has been called. Can Play()/Stop(). | 134 PAUSED, // Paused. OnStreamCreated() has been called. Can Play()/Stop(). |
| 134 PLAYING, // Playing back. Can Pause()/Stop(). | 135 PLAYING, // Playing back. Can Pause()/Stop(). |
| 135 }; | 136 }; |
| 136 | 137 |
| 138 // media::AudioRendererSink::RenderCallback implementation. |
| 139 // These two functions are called on the audio worker thread. |
| 140 int Render(media::AudioBus* audio_bus, |
| 141 uint32_t frames_delayed, |
| 142 uint32_t frames_skipped) override; |
| 143 void OnRenderError() override; |
| 144 |
| 137 // Methods called on IO thread ---------------------------------------------- | 145 // Methods called on IO thread ---------------------------------------------- |
| 138 // The following methods are tasks posted on the IO thread that need to | 146 // The following methods are tasks posted on the IO thread that need to |
| 139 // be executed on that thread. They use AudioOutputIPC to send IPC messages | 147 // be executed on that thread. They use AudioOutputIPC to send IPC messages |
| 140 // upon state changes. | 148 // upon state changes. |
| 141 void RequestDeviceAuthorizationOnIOThread(); | 149 void RequestDeviceAuthorizationOnIOThread(); |
| 142 void CreateStreamOnIOThread(const AudioParameters& params); | 150 void InitializeOnIOThread(const AudioParameters& params, |
| 151 AudioRendererSink::RenderCallback* callback); |
| 152 void CreateStreamOnIOThread(); |
| 143 void PlayOnIOThread(); | 153 void PlayOnIOThread(); |
| 144 void PauseOnIOThread(); | 154 void PauseOnIOThread(); |
| 145 void ShutDownOnIOThread(); | 155 void StopOnIOThread(); |
| 146 void SetVolumeOnIOThread(double volume); | 156 void SetVolumeOnIOThread(double volume); |
| 147 | 157 |
| 148 // base::MessageLoop::DestructionObserver implementation for the IO loop. | 158 // base::MessageLoop::DestructionObserver implementation for the IO loop. |
| 149 // If the IO loop dies before we do, we shut down the audio thread from here. | 159 // If the IO loop dies before we do, we shut down the audio thread from here. |
| 150 void WillDestroyCurrentMessageLoop() override; | 160 void WillDestroyCurrentMessageLoop() override; |
| 151 | 161 |
| 152 AudioParameters audio_parameters_; | 162 AudioParameters audio_parameters_; |
| 153 | 163 |
| 154 RenderCallback* callback_; | 164 base::Lock callback_lock_; |
| 165 AudioRendererSink::RenderCallback* callback_; |
| 155 | 166 |
| 156 // A pointer to the IPC layer that takes care of sending requests over to | 167 // A pointer to the IPC layer that takes care of sending requests over to |
| 157 // the AudioRendererHost. Only valid when state_ != IPC_CLOSED and must only | 168 // the AudioRendererHost. Only valid when state_ != IPC_CLOSED and must only |
| 158 // be accessed on the IO thread. | 169 // be accessed on the IO thread. |
| 159 std::unique_ptr<AudioOutputIPC> ipc_; | 170 std::unique_ptr<AudioOutputIPC> ipc_; |
| 160 | 171 |
| 161 // Current state (must only be accessed from the IO thread). See comments for | 172 // Current state (must only be accessed from the IO thread). See comments for |
| 162 // State enum above. | 173 // State enum above. |
| 163 State state_; | 174 State state_; |
| 164 | 175 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 base::WaitableEvent did_receive_auth_; | 211 base::WaitableEvent did_receive_auth_; |
| 201 AudioParameters output_params_; | 212 AudioParameters output_params_; |
| 202 OutputDeviceStatus device_status_; | 213 OutputDeviceStatus device_status_; |
| 203 | 214 |
| 204 DISALLOW_COPY_AND_ASSIGN(AudioOutputDevice); | 215 DISALLOW_COPY_AND_ASSIGN(AudioOutputDevice); |
| 205 }; | 216 }; |
| 206 | 217 |
| 207 } // namespace media | 218 } // namespace media |
| 208 | 219 |
| 209 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_ | 220 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_ |
| OLD | NEW |