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

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

Issue 11359196: Associate audio streams with their source/destination RenderView. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Plus, removed CalledOnValidThread DCHECK from sampleRate() call since nothing mutates. Created 8 years 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 | Annotate | Revision Log
« no previous file with comments | « content/test/webrtc_audio_device_test.cc ('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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 // Methods called on IO thread ---------------------------------------------- 92 // Methods called on IO thread ----------------------------------------------
93 // AudioOutputIPCDelegate methods. 93 // AudioOutputIPCDelegate methods.
94 virtual void OnStateChanged(AudioOutputIPCDelegate::State state) OVERRIDE; 94 virtual void OnStateChanged(AudioOutputIPCDelegate::State state) OVERRIDE;
95 virtual void OnStreamCreated(base::SharedMemoryHandle handle, 95 virtual void OnStreamCreated(base::SharedMemoryHandle handle,
96 base::SyncSocket::Handle socket_handle, 96 base::SyncSocket::Handle socket_handle,
97 int length) OVERRIDE; 97 int length) OVERRIDE;
98 virtual void OnIPCClosed() OVERRIDE; 98 virtual void OnIPCClosed() OVERRIDE;
99 99
100 // Creates an uninitialized AudioOutputDevice. Clients must call Initialize() 100 // Creates an uninitialized AudioOutputDevice. Clients must call Initialize()
101 // before using. 101 // before using.
102 // TODO(tommi): When all dependencies on |content| have been removed
103 // from AudioOutputDevice, move this class over to media/audio.
104 AudioOutputDevice(AudioOutputIPC* ipc, 102 AudioOutputDevice(AudioOutputIPC* ipc,
105 const scoped_refptr<base::MessageLoopProxy>& io_loop); 103 const scoped_refptr<base::MessageLoopProxy>& io_loop);
106 104
107 protected: 105 protected:
108 // Magic required by ref_counted.h to avoid any code deleting the object 106 // Magic required by ref_counted.h to avoid any code deleting the object
109 // accidentally while there are references to it. 107 // accidentally while there are references to it.
110 friend class base::RefCountedThreadSafe<AudioOutputDevice>; 108 friend class base::RefCountedThreadSafe<AudioOutputDevice>;
111 virtual ~AudioOutputDevice(); 109 virtual ~AudioOutputDevice();
112 110
111 // Accessors for subclasses (via IO thread only).
112 int stream_id() const { return stream_id_; }
113 AudioOutputIPC* audio_output_ipc() const { return ipc_; }
114
113 private: 115 private:
116 // Note: The ordering of members in this enum is critical to correct behavior!
117 enum State {
118 IPC_CLOSED, // No more IPCs can take place.
119 IDLE, // Not started.
120 CREATING_STREAM, // Waiting for OnStreamCreated() to be called back.
121 PAUSED, // Paused. OnStreamCreated() has been called. Can Play()/Stop().
122 PLAYING, // Playing back. Can Pause()/Stop().
123 };
124
114 // Methods called on IO thread ---------------------------------------------- 125 // Methods called on IO thread ----------------------------------------------
115 // The following methods are tasks posted on the IO thread that needs to 126 // The following methods are tasks posted on the IO thread that needs to
116 // be executed on that thread. They interact with AudioMessageFilter and 127 // be executed on that thread. They interact with AudioMessageFilter and
117 // sends IPC messages on that thread. 128 // sends IPC messages on that thread.
118 void CreateStreamOnIOThread(const AudioParameters& params, 129 void CreateStreamOnIOThread(const AudioParameters& params,
119 int input_channels); 130 int input_channels);
120 void PlayOnIOThread(); 131 void PlayOnIOThread();
121 void PauseOnIOThread(bool flush); 132 void PauseOnIOThread(bool flush);
122 void ShutDownOnIOThread(); 133 void ShutDownOnIOThread();
123 void SetVolumeOnIOThread(double volume); 134 void SetVolumeOnIOThread(double volume);
(...skipping 11 matching lines...) Expand all
135 RenderCallback* callback_; 146 RenderCallback* callback_;
136 147
137 // A pointer to the IPC layer that takes care of sending requests over to 148 // A pointer to the IPC layer that takes care of sending requests over to
138 // the AudioRendererHost. 149 // the AudioRendererHost.
139 AudioOutputIPC* ipc_; 150 AudioOutputIPC* ipc_;
140 151
141 // Our stream ID on the message filter. Only accessed on the IO thread. 152 // Our stream ID on the message filter. Only accessed on the IO thread.
142 // Must only be modified on the IO thread. 153 // Must only be modified on the IO thread.
143 int stream_id_; 154 int stream_id_;
144 155
156 // Current state (must only be accessed from the IO thread). See comments for
157 // State enum above.
158 State state_;
159
145 // State of Play() / Pause() calls before OnStreamCreated() is called. 160 // State of Play() / Pause() calls before OnStreamCreated() is called.
146 bool play_on_start_; 161 bool play_on_start_;
147 162
148 // Set to |true| when OnStreamCreated() is called.
149 // Set to |false| when ShutDownOnIOThread() is called.
150 // This is for use with play_on_start_ to track Play() / Pause() state.
151 // Must only be touched from the IO thread.
152 bool is_started_;
153
154 // Our audio thread callback class. See source file for details. 163 // Our audio thread callback class. See source file for details.
155 class AudioThreadCallback; 164 class AudioThreadCallback;
156 165
157 // In order to avoid a race between OnStreamCreated and Stop(), we use this 166 // In order to avoid a race between OnStreamCreated and Stop(), we use this
158 // guard to control stopping and starting the audio thread. 167 // guard to control stopping and starting the audio thread.
159 base::Lock audio_thread_lock_; 168 base::Lock audio_thread_lock_;
160 AudioDeviceThread audio_thread_; 169 AudioDeviceThread audio_thread_;
161 scoped_ptr<AudioOutputDevice::AudioThreadCallback> audio_callback_; 170 scoped_ptr<AudioOutputDevice::AudioThreadCallback> audio_callback_;
162 171
163 // Temporary hack to ignore OnStreamCreated() due to the user calling Stop() 172 // Temporary hack to ignore OnStreamCreated() due to the user calling Stop()
164 // so we don't start the audio thread pointing to a potentially freed 173 // so we don't start the audio thread pointing to a potentially freed
165 // |callback_|. 174 // |callback_|.
166 // 175 //
167 // TODO(scherkus): Replace this by changing AudioRendererSink to either accept 176 // TODO(scherkus): Replace this by changing AudioRendererSink to either accept
168 // the callback via Start(). See http://crbug.com/151051 for details. 177 // the callback via Start(). See http://crbug.com/151051 for details.
169 bool stopping_hack_; 178 bool stopping_hack_;
170 179
171 DISALLOW_COPY_AND_ASSIGN(AudioOutputDevice); 180 DISALLOW_COPY_AND_ASSIGN(AudioOutputDevice);
172 }; 181 };
173 182
174 } // namespace media 183 } // namespace media
175 184
176 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_ 185 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_
OLDNEW
« no previous file with comments | « content/test/webrtc_audio_device_test.cc ('k') | media/audio/audio_output_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698