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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 // turn calls AudioRendererSink::RenderCallback which feeds audio samples to | 55 // turn calls AudioRendererSink::RenderCallback which feeds audio samples to |
56 // the audio layer in the browser process using sync sockets and shared | 56 // the audio layer in the browser process using sync sockets and shared |
57 // memory. | 57 // memory. |
58 // | 58 // |
59 // Implementation notes: | 59 // Implementation notes: |
60 // - The user must call Stop() before deleting the class instance. | 60 // - The user must call Stop() before deleting the class instance. |
61 | 61 |
62 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_ | 62 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_ |
63 #define MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_ | 63 #define MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_ |
64 | 64 |
| 65 #include <memory> |
65 #include <string> | 66 #include <string> |
66 | 67 |
67 #include "base/bind.h" | 68 #include "base/bind.h" |
68 #include "base/macros.h" | 69 #include "base/macros.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/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 AudioRendererSink), |
84 NON_EXPORTED_BASE(public AudioOutputIPCDelegate), | 84 NON_EXPORTED_BASE(public AudioOutputIPCDelegate), |
85 NON_EXPORTED_BASE(public ScopedTaskRunnerObserver) { | 85 NON_EXPORTED_BASE(public ScopedTaskRunnerObserver) { |
86 public: | 86 public: |
87 // NOTE: Clients must call Initialize() before using. | 87 // NOTE: Clients must call Initialize() before using. |
88 AudioOutputDevice( | 88 AudioOutputDevice( |
89 scoped_ptr<AudioOutputIPC> ipc, | 89 std::unique_ptr<AudioOutputIPC> ipc, |
90 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 90 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
91 int session_id, | 91 int session_id, |
92 const std::string& device_id, | 92 const std::string& device_id, |
93 const url::Origin& security_origin); | 93 const url::Origin& security_origin); |
94 | 94 |
95 // Request authorization to use the device specified in the constructor. | 95 // Request authorization to use the device specified in the constructor. |
96 void RequestDeviceAuthorization(); | 96 void RequestDeviceAuthorization(); |
97 | 97 |
98 // AudioRendererSink implementation. | 98 // AudioRendererSink implementation. |
99 void Initialize(const AudioParameters& params, | 99 void Initialize(const AudioParameters& params, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 // If the IO loop dies before we do, we shut down the audio thread from here. | 149 // If the IO loop dies before we do, we shut down the audio thread from here. |
150 void WillDestroyCurrentMessageLoop() override; | 150 void WillDestroyCurrentMessageLoop() override; |
151 | 151 |
152 AudioParameters audio_parameters_; | 152 AudioParameters audio_parameters_; |
153 | 153 |
154 RenderCallback* callback_; | 154 RenderCallback* callback_; |
155 | 155 |
156 // A pointer to the IPC layer that takes care of sending requests over to | 156 // 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 | 157 // the AudioRendererHost. Only valid when state_ != IPC_CLOSED and must only |
158 // be accessed on the IO thread. | 158 // be accessed on the IO thread. |
159 scoped_ptr<AudioOutputIPC> ipc_; | 159 std::unique_ptr<AudioOutputIPC> ipc_; |
160 | 160 |
161 // Current state (must only be accessed from the IO thread). See comments for | 161 // Current state (must only be accessed from the IO thread). See comments for |
162 // State enum above. | 162 // State enum above. |
163 State state_; | 163 State state_; |
164 | 164 |
165 // State of Start() calls before OnDeviceAuthorized() is called. | 165 // State of Start() calls before OnDeviceAuthorized() is called. |
166 bool start_on_authorized_; | 166 bool start_on_authorized_; |
167 | 167 |
168 // State of Play() / Pause() calls before OnStreamCreated() is called. | 168 // State of Play() / Pause() calls before OnStreamCreated() is called. |
169 bool play_on_start_; | 169 bool play_on_start_; |
(...skipping 10 matching lines...) Expand all Loading... |
180 // received in OnDeviceAuthorized(). | 180 // received in OnDeviceAuthorized(). |
181 std::string matched_device_id_; | 181 std::string matched_device_id_; |
182 | 182 |
183 // Our audio thread callback class. See source file for details. | 183 // Our audio thread callback class. See source file for details. |
184 class AudioThreadCallback; | 184 class AudioThreadCallback; |
185 | 185 |
186 // In order to avoid a race between OnStreamCreated and Stop(), we use this | 186 // In order to avoid a race between OnStreamCreated and Stop(), we use this |
187 // guard to control stopping and starting the audio thread. | 187 // guard to control stopping and starting the audio thread. |
188 base::Lock audio_thread_lock_; | 188 base::Lock audio_thread_lock_; |
189 AudioDeviceThread audio_thread_; | 189 AudioDeviceThread audio_thread_; |
190 scoped_ptr<AudioOutputDevice::AudioThreadCallback> audio_callback_; | 190 std::unique_ptr<AudioOutputDevice::AudioThreadCallback> audio_callback_; |
191 | 191 |
192 // Temporary hack to ignore OnStreamCreated() due to the user calling Stop() | 192 // Temporary hack to ignore OnStreamCreated() due to the user calling Stop() |
193 // so we don't start the audio thread pointing to a potentially freed | 193 // so we don't start the audio thread pointing to a potentially freed |
194 // |callback_|. | 194 // |callback_|. |
195 // | 195 // |
196 // TODO(scherkus): Replace this by changing AudioRendererSink to either accept | 196 // TODO(scherkus): Replace this by changing AudioRendererSink to either accept |
197 // the callback via Start(). See http://crbug.com/151051 for details. | 197 // the callback via Start(). See http://crbug.com/151051 for details. |
198 bool stopping_hack_; | 198 bool stopping_hack_; |
199 | 199 |
200 base::WaitableEvent did_receive_auth_; | 200 base::WaitableEvent did_receive_auth_; |
201 AudioParameters output_params_; | 201 AudioParameters output_params_; |
202 OutputDeviceStatus device_status_; | 202 OutputDeviceStatus device_status_; |
203 | 203 |
204 DISALLOW_COPY_AND_ASSIGN(AudioOutputDevice); | 204 DISALLOW_COPY_AND_ASSIGN(AudioOutputDevice); |
205 }; | 205 }; |
206 | 206 |
207 } // namespace media | 207 } // namespace media |
208 | 208 |
209 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_ | 209 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_ |
OLD | NEW |