Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2735)

Side by Side Diff: media/audio/audio_output_device.h

Issue 1184473002: Add support for the audio-output-device switching IPC mechanism to the renderer lower layers (media… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build dependencies for audio_unittests Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/audio/BUILD.gn ('k') | media/audio/audio_output_device.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // turn calls AudioRendererSink::RenderCallback which feeds audio samples to 51 // turn calls AudioRendererSink::RenderCallback which feeds audio samples to
52 // the audio layer in the browser process using sync sockets and shared 52 // the audio layer in the browser process using sync sockets and shared
53 // memory. 53 // memory.
54 // 54 //
55 // Implementation notes: 55 // Implementation notes:
56 // - The user must call Stop() before deleting the class instance. 56 // - The user must call Stop() before deleting the class instance.
57 57
58 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_ 58 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_
59 #define MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_ 59 #define MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_
60 60
61 #include <string>
62
61 #include "base/basictypes.h" 63 #include "base/basictypes.h"
62 #include "base/bind.h" 64 #include "base/bind.h"
63 #include "base/memory/scoped_ptr.h" 65 #include "base/memory/scoped_ptr.h"
64 #include "base/memory/shared_memory.h" 66 #include "base/memory/shared_memory.h"
65 #include "media/audio/audio_device_thread.h" 67 #include "media/audio/audio_device_thread.h"
66 #include "media/audio/audio_output_ipc.h" 68 #include "media/audio/audio_output_ipc.h"
67 #include "media/audio/audio_parameters.h" 69 #include "media/audio/audio_parameters.h"
68 #include "media/audio/scoped_task_runner_observer.h" 70 #include "media/audio/scoped_task_runner_observer.h"
69 #include "media/base/audio_renderer_sink.h" 71 #include "media/base/audio_renderer_sink.h"
70 #include "media/base/media_export.h" 72 #include "media/base/media_export.h"
(...skipping 17 matching lines...) Expand all
88 int session_id); 90 int session_id);
89 91
90 // AudioRendererSink implementation. 92 // AudioRendererSink implementation.
91 void Initialize(const AudioParameters& params, 93 void Initialize(const AudioParameters& params,
92 RenderCallback* callback) override; 94 RenderCallback* callback) override;
93 void Start() override; 95 void Start() override;
94 void Stop() override; 96 void Stop() override;
95 void Play() override; 97 void Play() override;
96 void Pause() override; 98 void Pause() override;
97 bool SetVolume(double volume) override; 99 bool SetVolume(double volume) override;
100 void SwitchOutputDevice(const std::string& device_id,
101 const GURL& security_origin,
102 const SwitchOutputDeviceCB& callback) override;
98 103
99 // Methods called on IO thread ---------------------------------------------- 104 // Methods called on IO thread ----------------------------------------------
100 // AudioOutputIPCDelegate methods. 105 // AudioOutputIPCDelegate methods.
101 void OnStateChanged(AudioOutputIPCDelegateState state) override; 106 void OnStateChanged(AudioOutputIPCDelegateState state) override;
102 void OnStreamCreated(base::SharedMemoryHandle handle, 107 void OnStreamCreated(base::SharedMemoryHandle handle,
103 base::SyncSocket::Handle socket_handle, 108 base::SyncSocket::Handle socket_handle,
104 int length) override; 109 int length) override;
110 void OnOutputDeviceSwitched(int request_id,
111 SwitchOutputDeviceResult result) override;
105 void OnIPCClosed() override; 112 void OnIPCClosed() override;
106 113
107 protected: 114 protected:
108 // Magic required by ref_counted.h to avoid any code deleting the object 115 // Magic required by ref_counted.h to avoid any code deleting the object
109 // accidentally while there are references to it. 116 // accidentally while there are references to it.
110 friend class base::RefCountedThreadSafe<AudioOutputDevice>; 117 friend class base::RefCountedThreadSafe<AudioOutputDevice>;
111 ~AudioOutputDevice() override; 118 ~AudioOutputDevice() override;
112 119
113 private: 120 private:
114 // Note: The ordering of members in this enum is critical to correct behavior! 121 // Note: The ordering of members in this enum is critical to correct behavior!
115 enum State { 122 enum State {
116 IPC_CLOSED, // No more IPCs can take place. 123 IPC_CLOSED, // No more IPCs can take place.
117 IDLE, // Not started. 124 IDLE, // Not started.
118 CREATING_STREAM, // Waiting for OnStreamCreated() to be called back. 125 CREATING_STREAM, // Waiting for OnStreamCreated() to be called back.
119 PAUSED, // Paused. OnStreamCreated() has been called. Can Play()/Stop(). 126 PAUSED, // Paused. OnStreamCreated() has been called. Can Play()/Stop().
120 PLAYING, // Playing back. Can Pause()/Stop(). 127 PLAYING, // Playing back. Can Pause()/Stop().
121 }; 128 };
122 129
123 // Methods called on IO thread ---------------------------------------------- 130 // Methods called on IO thread ----------------------------------------------
124 // The following methods are tasks posted on the IO thread that need to 131 // The following methods are tasks posted on the IO thread that need to
125 // be executed on that thread. They use AudioOutputIPC to send IPC messages 132 // be executed on that thread. They use AudioOutputIPC to send IPC messages
126 // upon state changes. 133 // upon state changes.
127 void CreateStreamOnIOThread(const AudioParameters& params); 134 void CreateStreamOnIOThread(const AudioParameters& params);
128 void PlayOnIOThread(); 135 void PlayOnIOThread();
129 void PauseOnIOThread(); 136 void PauseOnIOThread();
130 void ShutDownOnIOThread(); 137 void ShutDownOnIOThread();
131 void SetVolumeOnIOThread(double volume); 138 void SetVolumeOnIOThread(double volume);
139 void SwitchOutputDeviceOnIOThread(const std::string& device_id,
140 const GURL& security_origin,
141 const SwitchOutputDeviceCB& callback);
132 142
133 // base::MessageLoop::DestructionObserver implementation for the IO loop. 143 // base::MessageLoop::DestructionObserver implementation for the IO loop.
134 // If the IO loop dies before we do, we shut down the audio thread from here. 144 // If the IO loop dies before we do, we shut down the audio thread from here.
135 void WillDestroyCurrentMessageLoop() override; 145 void WillDestroyCurrentMessageLoop() override;
136 146
147 void SetCurrentSwitchRequest(const SwitchOutputDeviceCB& callback);
148
137 AudioParameters audio_parameters_; 149 AudioParameters audio_parameters_;
138 150
139 RenderCallback* callback_; 151 RenderCallback* callback_;
140 152
141 // A pointer to the IPC layer that takes care of sending requests over to 153 // A pointer to the IPC layer that takes care of sending requests over to
142 // the AudioRendererHost. Only valid when state_ != IPC_CLOSED and must only 154 // the AudioRendererHost. Only valid when state_ != IPC_CLOSED and must only
143 // be accessed on the IO thread. 155 // be accessed on the IO thread.
144 scoped_ptr<AudioOutputIPC> ipc_; 156 scoped_ptr<AudioOutputIPC> ipc_;
145 157
146 // Current state (must only be accessed from the IO thread). See comments for 158 // Current state (must only be accessed from the IO thread). See comments for
(...skipping 17 matching lines...) Expand all
164 scoped_ptr<AudioOutputDevice::AudioThreadCallback> audio_callback_; 176 scoped_ptr<AudioOutputDevice::AudioThreadCallback> audio_callback_;
165 177
166 // Temporary hack to ignore OnStreamCreated() due to the user calling Stop() 178 // Temporary hack to ignore OnStreamCreated() due to the user calling Stop()
167 // so we don't start the audio thread pointing to a potentially freed 179 // so we don't start the audio thread pointing to a potentially freed
168 // |callback_|. 180 // |callback_|.
169 // 181 //
170 // TODO(scherkus): Replace this by changing AudioRendererSink to either accept 182 // TODO(scherkus): Replace this by changing AudioRendererSink to either accept
171 // the callback via Start(). See http://crbug.com/151051 for details. 183 // the callback via Start(). See http://crbug.com/151051 for details.
172 bool stopping_hack_; 184 bool stopping_hack_;
173 185
186 int current_switch_request_id_;
187 SwitchOutputDeviceCB current_switch_callback_;
188
174 DISALLOW_COPY_AND_ASSIGN(AudioOutputDevice); 189 DISALLOW_COPY_AND_ASSIGN(AudioOutputDevice);
175 }; 190 };
176 191
177 } // namespace media 192 } // namespace media
178 193
179 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_ 194 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_
OLDNEW
« no previous file with comments | « media/audio/BUILD.gn ('k') | media/audio/audio_output_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698