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; | 106 OutputDeviceInfo GetOutputDeviceInfo() override; |
108 | |
109 // OutputDevice implementation | |
110 AudioParameters GetOutputParameters() override; | |
111 OutputDeviceStatus GetDeviceStatus() override; | |
112 | 107 |
113 // Methods called on IO thread ---------------------------------------------- | 108 // Methods called on IO thread ---------------------------------------------- |
114 // AudioOutputIPCDelegate methods. | 109 // AudioOutputIPCDelegate methods. |
115 void OnStateChanged(AudioOutputIPCDelegateState state) override; | 110 void OnStateChanged(AudioOutputIPCDelegateState state) override; |
116 void OnDeviceAuthorized(OutputDeviceStatus device_status, | 111 void OnDeviceAuthorized(OutputDeviceStatus device_status, |
117 const media::AudioParameters& output_params) override; | 112 const media::AudioParameters& output_params) override; |
118 void OnStreamCreated(base::SharedMemoryHandle handle, | 113 void OnStreamCreated(base::SharedMemoryHandle handle, |
119 base::SyncSocket::Handle socket_handle, | 114 base::SyncSocket::Handle socket_handle, |
120 int length) override; | 115 int length) override; |
121 void OnIPCClosed() override; | 116 void OnIPCClosed() override; |
122 | 117 |
123 protected: | 118 protected: |
124 // Magic required by ref_counted.h to avoid any code deleting the object | 119 // Magic required by ref_counted.h to avoid any code deleting the object |
125 // accidentally while there are references to it. | 120 // accidentally while there are references to it. |
126 friend class base::RefCountedThreadSafe<AudioOutputDevice>; | 121 friend class base::RefCountedThreadSafe<AudioOutputDevice>; |
127 ~AudioOutputDevice() override; | 122 ~AudioOutputDevice() override; |
128 | 123 |
129 private: | 124 private: |
130 // Note: The ordering of members in this enum is critical to correct behavior! | 125 // Note: The ordering of members in this enum is critical to correct behavior! |
131 enum State { | 126 enum State { |
132 IPC_CLOSED, // No more IPCs can take place. | 127 IPC_CLOSED, // No more IPCs can take place. |
133 IDLE, // Not started. | 128 IDLE, // Not started. |
134 AUTHORIZING, // Sent device authorization request, waiting for reply. | 129 AUTHORIZING, // Sent device authorization request, waiting for reply. |
135 AUTHORIZED, // Successful device authorization received. | 130 AUTHORIZED, // Successful device authorization received. |
136 CREATING_STREAM, // Waiting for OnStreamCreated() to be called back. | 131 CREATING_STREAM, // Waiting for OnStreamCreated() to be called back. |
137 PAUSED, // Paused. OnStreamCreated() has been called. Can Play()/Stop(). | 132 PAUSED, // Paused. OnStreamCreated() has been called. Can Play()/Stop(). |
138 PLAYING, // Playing back. Can Pause()/Stop(). | 133 PLAYING, // Playing back. Can Pause()/Stop(). |
139 }; | 134 }; |
140 | 135 |
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 ---------------------------------------------- | 136 // Methods called on IO thread ---------------------------------------------- |
147 // The following methods are tasks posted on the IO thread that need to | 137 // 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 | 138 // be executed on that thread. They use AudioOutputIPC to send IPC messages |
149 // upon state changes. | 139 // upon state changes. |
150 void RequestDeviceAuthorizationOnIOThread(); | 140 void RequestDeviceAuthorizationOnIOThread(); |
151 void CreateStreamOnIOThread(const AudioParameters& params); | 141 void CreateStreamOnIOThread(const AudioParameters& params); |
152 void PlayOnIOThread(); | 142 void PlayOnIOThread(); |
153 void PauseOnIOThread(); | 143 void PauseOnIOThread(); |
154 void ShutDownOnIOThread(); | 144 void ShutDownOnIOThread(); |
155 void SetVolumeOnIOThread(double volume); | 145 void SetVolumeOnIOThread(double volume); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 | 186 |
197 // Temporary hack to ignore OnStreamCreated() due to the user calling Stop() | 187 // 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 | 188 // so we don't start the audio thread pointing to a potentially freed |
199 // |callback_|. | 189 // |callback_|. |
200 // | 190 // |
201 // TODO(scherkus): Replace this by changing AudioRendererSink to either accept | 191 // TODO(scherkus): Replace this by changing AudioRendererSink to either accept |
202 // the callback via Start(). See http://crbug.com/151051 for details. | 192 // the callback via Start(). See http://crbug.com/151051 for details. |
203 bool stopping_hack_; | 193 bool stopping_hack_; |
204 | 194 |
205 base::WaitableEvent did_receive_auth_; | 195 base::WaitableEvent did_receive_auth_; |
206 media::AudioParameters output_params_; | 196 AudioParameters output_params_; |
207 OutputDeviceStatus device_status_; | 197 OutputDeviceStatus device_status_; |
208 | 198 |
209 DISALLOW_COPY_AND_ASSIGN(AudioOutputDevice); | 199 DISALLOW_COPY_AND_ASSIGN(AudioOutputDevice); |
210 }; | 200 }; |
211 | 201 |
212 } // namespace media | 202 } // namespace media |
213 | 203 |
214 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_ | 204 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_ |
OLD | NEW |