OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // AudioRendererHost serves audio related requests from AudioRenderer which | 5 // AudioRendererHost serves audio related requests from AudioRenderer which |
6 // lives inside the render process and provide access to audio hardware. | 6 // lives inside the render process and provide access to audio hardware. |
7 // | 7 // |
8 // This class is owned by BrowserRenderProcessHost, and instantiated on UI | 8 // This class is owned by BrowserRenderProcessHost, and instantiated on UI |
9 // thread, but all other operations and method calls happen on IO thread, so we | 9 // thread, but all other operations and method calls happen on IO thread, so we |
10 // need to be extra careful about the lifetime of this object. AudioManager is a | 10 // need to be extra careful about the lifetime of this object. AudioManager is a |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 #include "media/audio/audio_io.h" | 65 #include "media/audio/audio_io.h" |
66 #include "media/audio/audio_output_controller.h" | 66 #include "media/audio/audio_output_controller.h" |
67 #include "media/audio/simple_sources.h" | 67 #include "media/audio/simple_sources.h" |
68 | 68 |
69 class AudioManager; | 69 class AudioManager; |
70 struct AudioParameters; | 70 struct AudioParameters; |
71 | 71 |
72 class AudioRendererHost : public BrowserMessageFilter, | 72 class AudioRendererHost : public BrowserMessageFilter, |
73 public media::AudioOutputController::EventHandler { | 73 public media::AudioOutputController::EventHandler { |
74 public: | 74 public: |
75 typedef std::pair<int32, int> AudioEntryId; | |
76 | |
77 struct AudioEntry { | 75 struct AudioEntry { |
78 AudioEntry(); | 76 AudioEntry(); |
79 ~AudioEntry(); | 77 ~AudioEntry(); |
80 | 78 |
81 // The AudioOutputController that manages the audio stream. | 79 // The AudioOutputController that manages the audio stream. |
82 scoped_refptr<media::AudioOutputController> controller; | 80 scoped_refptr<media::AudioOutputController> controller; |
83 | 81 |
84 // Render view ID that requested the audio stream. | 82 // The audio stream ID. |
85 int32 render_view_id; | |
86 | |
87 // The audio stream ID in the render view. | |
88 int stream_id; | 83 int stream_id; |
89 | 84 |
90 // Shared memory for transmission of the audio data. | 85 // Shared memory for transmission of the audio data. |
91 base::SharedMemory shared_memory; | 86 base::SharedMemory shared_memory; |
92 | 87 |
93 // The synchronous reader to be used by the controller. We have the | 88 // The synchronous reader to be used by the controller. We have the |
94 // ownership of the reader. | 89 // ownership of the reader. |
95 scoped_ptr<media::AudioOutputController::SyncReader> reader; | 90 scoped_ptr<media::AudioOutputController::SyncReader> reader; |
96 | 91 |
97 bool pending_buffer_request; | 92 bool pending_buffer_request; |
98 | 93 |
99 // Set to true after we called Close() for the controller. | 94 // Set to true after we called Close() for the controller. |
100 bool pending_close; | 95 bool pending_close; |
101 }; | 96 }; |
102 | 97 |
103 typedef std::map<AudioEntryId, AudioEntry*> AudioEntryMap; | 98 typedef std::map<int, AudioEntry*> AudioEntryMap; |
104 | 99 |
105 // Called from UI thread from the owner of this object. | 100 // Called from UI thread from the owner of this object. |
106 AudioRendererHost(); | 101 AudioRendererHost(); |
107 | 102 |
108 | 103 |
109 // BrowserMessageFilter implementation. | 104 // BrowserMessageFilter implementation. |
110 virtual void OnChannelClosing(); | 105 virtual void OnChannelClosing(); |
111 virtual void OnDestruct() const; | 106 virtual void OnDestruct() const; |
112 virtual bool OnMessageReceived(const IPC::Message& message, | 107 virtual bool OnMessageReceived(const IPC::Message& message, |
113 bool* message_was_ok); | 108 bool* message_was_ok); |
114 | 109 |
115 ///////////////////////////////////////////////////////////////////////////// | |
116 // AudioOutputController::EventHandler implementations. | 110 // AudioOutputController::EventHandler implementations. |
117 virtual void OnCreated(media::AudioOutputController* controller); | 111 virtual void OnCreated(media::AudioOutputController* controller); |
118 virtual void OnPlaying(media::AudioOutputController* controller); | 112 virtual void OnPlaying(media::AudioOutputController* controller); |
119 virtual void OnPaused(media::AudioOutputController* controller); | 113 virtual void OnPaused(media::AudioOutputController* controller); |
120 virtual void OnError(media::AudioOutputController* controller, | 114 virtual void OnError(media::AudioOutputController* controller, |
121 int error_code); | 115 int error_code); |
122 virtual void OnMoreData(media::AudioOutputController* controller, | 116 virtual void OnMoreData(media::AudioOutputController* controller, |
123 AudioBuffersState buffers_state); | 117 AudioBuffersState buffers_state); |
124 | 118 |
125 private: | 119 private: |
126 friend class AudioRendererHostTest; | 120 friend class AudioRendererHostTest; |
127 friend class BrowserThread; | 121 friend class BrowserThread; |
128 friend class DeleteTask<AudioRendererHost>; | 122 friend class DeleteTask<AudioRendererHost>; |
129 friend class MockAudioRendererHost; | 123 friend class MockAudioRendererHost; |
130 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream); | 124 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream); |
131 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, MockStreamDataConversation); | 125 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, MockStreamDataConversation); |
132 | 126 |
133 virtual ~AudioRendererHost(); | 127 virtual ~AudioRendererHost(); |
134 | 128 |
135 //////////////////////////////////////////////////////////////////////////// | 129 // Methods called on IO thread ---------------------------------------------- |
136 // Methods called on IO thread. | |
137 // Returns true if the message is an audio related message and should be | |
138 // handled by this class. | |
139 bool IsAudioRendererHostMessage(const IPC::Message& message); | |
140 | 130 |
141 // Audio related IPC message handlers. | 131 // Audio related IPC message handlers. |
142 // Creates an audio output stream with the specified format. If this call is | 132 // Creates an audio output stream with the specified format. If this call is |
143 // successful this object would keep an internal entry of the stream for the | 133 // successful this object would keep an internal entry of the stream for the |
144 // required properties. | 134 // required properties. |
145 void OnCreateStream(const IPC::Message& msg, int stream_id, | 135 void OnCreateStream(int stream_id, |
146 const AudioParameters& params, | 136 const AudioParameters& params, |
147 bool low_latency); | 137 bool low_latency); |
148 | 138 |
149 // Play the audio stream referenced by |stream_id|. | 139 // Play the audio stream referenced by |stream_id|. |
150 void OnPlayStream(const IPC::Message& msg, int stream_id); | 140 void OnPlayStream(int stream_id); |
151 | 141 |
152 // Pause the audio stream referenced by |stream_id|. | 142 // Pause the audio stream referenced by |stream_id|. |
153 void OnPauseStream(const IPC::Message& msg, int stream_id); | 143 void OnPauseStream(int stream_id); |
154 | 144 |
155 // Discard all audio data in stream referenced by |stream_id|. | 145 // Discard all audio data in stream referenced by |stream_id|. |
156 void OnFlushStream(const IPC::Message& msg, int stream_id); | 146 void OnFlushStream(int stream_id); |
157 | 147 |
158 // Close the audio stream referenced by |stream_id|. | 148 // Close the audio stream referenced by |stream_id|. |
159 void OnCloseStream(const IPC::Message& msg, int stream_id); | 149 void OnCloseStream(int stream_id); |
160 | 150 |
161 // Set the volume of the audio stream referenced by |stream_id|. | 151 // Set the volume of the audio stream referenced by |stream_id|. |
162 void OnSetVolume(const IPC::Message& msg, int stream_id, double volume); | 152 void OnSetVolume(int stream_id, double volume); |
163 | 153 |
164 // Get the volume of the audio stream referenced by |stream_id|. | 154 // Get the volume of the audio stream referenced by |stream_id|. |
165 void OnGetVolume(const IPC::Message& msg, int stream_id); | 155 void OnGetVolume(int stream_id); |
166 | 156 |
167 // Notify packet has been prepared for the audio stream. | 157 // Notify packet has been prepared for the audio stream. |
168 void OnNotifyPacketReady(const IPC::Message& msg, int stream_id, | 158 void OnNotifyPacketReady(int stream_id, uint32 packet_size); |
169 uint32 packet_size); | |
170 | 159 |
171 // Complete the process of creating an audio stream. This will set up the | 160 // Complete the process of creating an audio stream. This will set up the |
172 // shared memory or shared socket in low latency mode. | 161 // shared memory or shared socket in low latency mode. |
173 void DoCompleteCreation(media::AudioOutputController* controller); | 162 void DoCompleteCreation(media::AudioOutputController* controller); |
174 | 163 |
175 // Send a state change message to the renderer. | 164 // Send a state change message to the renderer. |
176 void DoSendPlayingMessage(media::AudioOutputController* controller); | 165 void DoSendPlayingMessage(media::AudioOutputController* controller); |
177 void DoSendPausedMessage(media::AudioOutputController* controller); | 166 void DoSendPausedMessage(media::AudioOutputController* controller); |
178 | 167 |
179 // Request more data from the renderer. This method is used only in normal | 168 // Request more data from the renderer. This method is used only in normal |
180 // latency mode. | 169 // latency mode. |
181 void DoRequestMoreData(media::AudioOutputController* controller, | 170 void DoRequestMoreData(media::AudioOutputController* controller, |
182 AudioBuffersState buffers_state); | 171 AudioBuffersState buffers_state); |
183 | 172 |
184 // Handle error coming from audio stream. | 173 // Handle error coming from audio stream. |
185 void DoHandleError(media::AudioOutputController* controller, int error_code); | 174 void DoHandleError(media::AudioOutputController* controller, int error_code); |
186 | 175 |
187 // Send an error message to the renderer. | 176 // Send an error message to the renderer. |
188 void SendErrorMessage(int32 render_view_id, int32 stream_id); | 177 void SendErrorMessage(int32 stream_id); |
wjia(left Chromium)
2011/06/23 19:43:22
int32 --> int?
henrika_dont_use
2011/06/27 15:05:44
Done.
| |
189 | 178 |
190 // Delete all audio entry and all audio streams | 179 // Delete all audio entry and all audio streams |
191 void DeleteEntries(); | 180 void DeleteEntries(); |
192 | 181 |
193 // Closes the stream. The stream is then deleted in DeleteEntry() after it | 182 // Closes the stream. The stream is then deleted in DeleteEntry() after it |
194 // is closed. | 183 // is closed. |
195 void CloseAndDeleteStream(AudioEntry* entry); | 184 void CloseAndDeleteStream(AudioEntry* entry); |
196 | 185 |
197 // Called on the audio thread after the audio stream is closed. | 186 // Called on the audio thread after the audio stream is closed. |
198 void OnStreamClosed(AudioEntry* entry); | 187 void OnStreamClosed(AudioEntry* entry); |
199 | 188 |
200 // Delete an audio entry and close the related audio stream. | 189 // Delete an audio entry and close the related audio stream. |
201 void DeleteEntry(AudioEntry* entry); | 190 void DeleteEntry(AudioEntry* entry); |
202 | 191 |
203 // Delete audio entry and close the related audio stream due to an error, | 192 // Delete audio entry and close the related audio stream due to an error, |
204 // and error message is send to the renderer. | 193 // and error message is send to the renderer. |
205 void DeleteEntryOnError(AudioEntry* entry); | 194 void DeleteEntryOnError(AudioEntry* entry); |
206 | 195 |
207 // A helper method to look up a AudioEntry with a tuple of render view | 196 // A helper method to look up a AudioEntry identified by |stream_id|. |
208 // id and stream id. Returns NULL if not found. | 197 // Returns NULL if not found. |
209 AudioEntry* LookupById(int render_view_id, int stream_id); | 198 AudioEntry* LookupById(int stream_id); |
210 | 199 |
211 // Search for a AudioEntry having the reference to |controller|. | 200 // Search for a AudioEntry having the reference to |controller|. |
212 // This method is used to look up an AudioEntry after a controller | 201 // This method is used to look up an AudioEntry after a controller |
213 // event is received. | 202 // event is received. |
214 AudioEntry* LookupByController(media::AudioOutputController* controller); | 203 AudioEntry* LookupByController(media::AudioOutputController* controller); |
215 | 204 |
216 // A map of id to audio sources. | 205 // A map of stream IDs to audio sources. |
217 AudioEntryMap audio_entries_; | 206 AudioEntryMap audio_entries_; |
218 | 207 |
219 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); | 208 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); |
220 }; | 209 }; |
221 | 210 |
222 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ | 211 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ |
OLD | NEW |