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 |
11 // singleton and created in IO thread, audio output streams are also created in | 11 // singleton and created in IO thread, audio output streams are also created in |
12 // the IO thread, so we need to destroy them also in IO thread. After this class | 12 // the IO thread, so we need to destroy them also in IO thread. After this class |
13 // is created, a task of OnInitialized() is posted on IO thread in which | 13 // is created, a task of OnInitialized() is posted on IO thread in which |
14 // singleton of AudioManager is created and. | 14 // singleton of AudioManager is created and. |
15 // | 15 // |
16 // Here's an example of a typical IPC dialog for audio: | 16 // Here's an example of a typical IPC dialog for audio: |
henrika (OOO until Aug 14)
2012/01/29 20:54:00
I assume that these comments must be updated since
vrk (LEFT CHROMIUM)
2012/01/31 23:53:08
Good catch! Done.
| |
17 // | 17 // |
18 // Renderer AudioRendererHost | 18 // Renderer AudioRendererHost |
19 // | | | 19 // | | |
20 // | CreateStream > | | 20 // | CreateStream > | |
21 // | < Created | | 21 // | < Created | |
22 // | | | 22 // | | |
23 // | Play > | | 23 // | Play > | |
24 // | < Playing | time | 24 // | < Playing | time |
25 // | | | 25 // | | |
26 // | < RequestAudioPacket | | 26 // | < RequestAudioPacket | |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 // The audio stream ID. | 90 // The audio stream ID. |
91 int stream_id; | 91 int stream_id; |
92 | 92 |
93 // Shared memory for transmission of the audio data. | 93 // Shared memory for transmission of the audio data. |
94 base::SharedMemory shared_memory; | 94 base::SharedMemory shared_memory; |
95 | 95 |
96 // The synchronous reader to be used by the controller. We have the | 96 // The synchronous reader to be used by the controller. We have the |
97 // ownership of the reader. | 97 // ownership of the reader. |
98 scoped_ptr<media::AudioOutputController::SyncReader> reader; | 98 scoped_ptr<media::AudioOutputController::SyncReader> reader; |
99 | 99 |
100 bool pending_buffer_request; | |
101 | |
102 // Set to true after we called Close() for the controller. | 100 // Set to true after we called Close() for the controller. |
103 bool pending_close; | 101 bool pending_close; |
104 }; | 102 }; |
105 | 103 |
106 typedef std::map<int, AudioEntry*> AudioEntryMap; | 104 typedef std::map<int, AudioEntry*> AudioEntryMap; |
107 | 105 |
108 // Called from UI thread from the owner of this object. | 106 // Called from UI thread from the owner of this object. |
109 AudioRendererHost(const content::ResourceContext* resource_context); | 107 AudioRendererHost(const content::ResourceContext* resource_context); |
110 | 108 |
111 // content::BrowserMessageFilter implementation. | 109 // content::BrowserMessageFilter implementation. |
112 virtual void OnChannelClosing() OVERRIDE; | 110 virtual void OnChannelClosing() OVERRIDE; |
113 virtual void OnDestruct() const OVERRIDE; | 111 virtual void OnDestruct() const OVERRIDE; |
114 virtual bool OnMessageReceived(const IPC::Message& message, | 112 virtual bool OnMessageReceived(const IPC::Message& message, |
115 bool* message_was_ok) OVERRIDE; | 113 bool* message_was_ok) OVERRIDE; |
116 | 114 |
117 // AudioOutputController::EventHandler implementations. | 115 // AudioOutputController::EventHandler implementations. |
118 virtual void OnCreated(media::AudioOutputController* controller) OVERRIDE; | 116 virtual void OnCreated(media::AudioOutputController* controller) OVERRIDE; |
119 virtual void OnPlaying(media::AudioOutputController* controller) OVERRIDE; | 117 virtual void OnPlaying(media::AudioOutputController* controller) OVERRIDE; |
120 virtual void OnPaused(media::AudioOutputController* controller) OVERRIDE; | 118 virtual void OnPaused(media::AudioOutputController* controller) OVERRIDE; |
121 virtual void OnError(media::AudioOutputController* controller, | 119 virtual void OnError(media::AudioOutputController* controller, |
122 int error_code) OVERRIDE; | 120 int error_code) OVERRIDE; |
123 virtual void OnMoreData(media::AudioOutputController* controller, | |
124 AudioBuffersState buffers_state) OVERRIDE; | |
125 | 121 |
126 private: | 122 private: |
127 friend class AudioRendererHostTest; | 123 friend class AudioRendererHostTest; |
128 friend class content::BrowserThread; | 124 friend class content::BrowserThread; |
129 friend class base::DeleteHelper<AudioRendererHost>; | 125 friend class base::DeleteHelper<AudioRendererHost>; |
130 friend class MockAudioRendererHost; | 126 friend class MockAudioRendererHost; |
131 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream); | 127 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream); |
132 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, MockStreamDataConversation); | 128 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, MockStreamDataConversation); |
133 | 129 |
134 virtual ~AudioRendererHost(); | 130 virtual ~AudioRendererHost(); |
135 | 131 |
136 // Methods called on IO thread ---------------------------------------------- | 132 // Methods called on IO thread ---------------------------------------------- |
137 | 133 |
138 // Audio related IPC message handlers. | 134 // Audio related IPC message handlers. |
139 // Creates an audio output stream with the specified format. If this call is | 135 // Creates an audio output stream with the specified format. If this call is |
140 // successful this object would keep an internal entry of the stream for the | 136 // successful this object would keep an internal entry of the stream for the |
141 // required properties. | 137 // required properties. |
142 void OnCreateStream(int stream_id, | 138 void OnCreateStream(int stream_id, const AudioParameters& params); |
143 const AudioParameters& params, | |
144 bool low_latency); | |
145 | 139 |
146 // Play the audio stream referenced by |stream_id|. | 140 // Play the audio stream referenced by |stream_id|. |
147 void OnPlayStream(int stream_id); | 141 void OnPlayStream(int stream_id); |
148 | 142 |
149 // Pause the audio stream referenced by |stream_id|. | 143 // Pause the audio stream referenced by |stream_id|. |
150 void OnPauseStream(int stream_id); | 144 void OnPauseStream(int stream_id); |
151 | 145 |
152 // Discard all audio data in stream referenced by |stream_id|. | 146 // Discard all audio data in stream referenced by |stream_id|. |
153 void OnFlushStream(int stream_id); | 147 void OnFlushStream(int stream_id); |
154 | 148 |
155 // Close the audio stream referenced by |stream_id|. | 149 // Close the audio stream referenced by |stream_id|. |
156 void OnCloseStream(int stream_id); | 150 void OnCloseStream(int stream_id); |
157 | 151 |
158 // Set the volume of the audio stream referenced by |stream_id|. | 152 // Set the volume of the audio stream referenced by |stream_id|. |
159 void OnSetVolume(int stream_id, double volume); | 153 void OnSetVolume(int stream_id, double volume); |
henrika (OOO until Aug 14)
2012/01/29 20:54:00
Why has OnGetVolume() been removed?
vrk (LEFT CHROMIUM)
2012/01/31 23:53:08
As I was deleting unused code, I noticed that OnGe
| |
160 | 154 |
161 // Get the volume of the audio stream referenced by |stream_id|. | |
162 void OnGetVolume(int stream_id); | |
163 | |
164 // Notify packet has been prepared for the audio stream. | |
165 void OnNotifyPacketReady(int stream_id, uint32 packet_size); | |
166 | |
167 // Complete the process of creating an audio stream. This will set up the | 155 // Complete the process of creating an audio stream. This will set up the |
168 // shared memory or shared socket in low latency mode. | 156 // shared memory or shared socket in low latency mode. |
169 void DoCompleteCreation(media::AudioOutputController* controller); | 157 void DoCompleteCreation(media::AudioOutputController* controller); |
170 | 158 |
171 // Send a state change message to the renderer. | 159 // Send a state change message to the renderer. |
172 void DoSendPlayingMessage(media::AudioOutputController* controller); | 160 void DoSendPlayingMessage(media::AudioOutputController* controller); |
173 void DoSendPausedMessage(media::AudioOutputController* controller); | 161 void DoSendPausedMessage(media::AudioOutputController* controller); |
174 | 162 |
175 // Request more data from the renderer. This method is used only in normal | |
176 // latency mode. | |
177 void DoRequestMoreData(media::AudioOutputController* controller, | |
178 AudioBuffersState buffers_state); | |
179 | |
180 // Handle error coming from audio stream. | 163 // Handle error coming from audio stream. |
181 void DoHandleError(media::AudioOutputController* controller, int error_code); | 164 void DoHandleError(media::AudioOutputController* controller, int error_code); |
182 | 165 |
183 // Send an error message to the renderer. | 166 // Send an error message to the renderer. |
184 void SendErrorMessage(int stream_id); | 167 void SendErrorMessage(int stream_id); |
185 | 168 |
186 // Delete all audio entry and all audio streams | 169 // Delete all audio entry and all audio streams |
187 void DeleteEntries(); | 170 void DeleteEntries(); |
188 | 171 |
189 // Closes the stream. The stream is then deleted in DeleteEntry() after it | 172 // Closes the stream. The stream is then deleted in DeleteEntry() after it |
(...skipping 28 matching lines...) Expand all Loading... | |
218 // A map of stream IDs to audio sources. | 201 // A map of stream IDs to audio sources. |
219 AudioEntryMap audio_entries_; | 202 AudioEntryMap audio_entries_; |
220 | 203 |
221 const content::ResourceContext* resource_context_; | 204 const content::ResourceContext* resource_context_; |
222 MediaObserver* media_observer_; | 205 MediaObserver* media_observer_; |
223 | 206 |
224 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); | 207 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); |
225 }; | 208 }; |
226 | 209 |
227 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ | 210 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ |
OLD | NEW |