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 // AudioInputRendererHost serves audio related requests from audio capturer | 5 // AudioInputRendererHost serves audio related requests from audio capturer |
6 // which lives inside the render process and provide access to audio hardware. | 6 // which lives inside the render process and provide access to audio hardware. |
7 // | 7 // |
8 // Create stream sequence (AudioInputController = AIC): | 8 // Create stream sequence (AudioInputController = AIC): |
9 // | 9 // |
10 // AudioInputHostMsg_CreateStream -> OnCreateStream -> AIC::CreateLowLatency -> | 10 // AudioInputHostMsg_CreateStream -> OnCreateStream -> AIC::CreateLowLatency -> |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 #include "content/public/browser/browser_message_filter.h" | 61 #include "content/public/browser/browser_message_filter.h" |
62 #include "content/public/browser/browser_thread.h" | 62 #include "content/public/browser/browser_thread.h" |
63 #include "media/audio/audio_input_controller.h" | 63 #include "media/audio/audio_input_controller.h" |
64 #include "media/audio/audio_io.h" | 64 #include "media/audio/audio_io.h" |
65 #include "media/audio/simple_sources.h" | 65 #include "media/audio/simple_sources.h" |
66 | 66 |
67 namespace content { | 67 namespace content { |
68 class ResourceContext; | 68 class ResourceContext; |
69 } | 69 } |
70 | 70 |
| 71 namespace media { |
71 class AudioManager; | 72 class AudioManager; |
72 class AudioParameters; | 73 class AudioParameters; |
| 74 } |
73 | 75 |
74 class CONTENT_EXPORT AudioInputRendererHost | 76 class CONTENT_EXPORT AudioInputRendererHost |
75 : public content::BrowserMessageFilter, | 77 : public content::BrowserMessageFilter, |
76 public media::AudioInputController::EventHandler, | 78 public media::AudioInputController::EventHandler, |
77 public media_stream::AudioInputDeviceManagerEventHandler { | 79 public media_stream::AudioInputDeviceManagerEventHandler { |
78 public: | 80 public: |
79 struct AudioEntry { | 81 struct AudioEntry { |
80 AudioEntry(); | 82 AudioEntry(); |
81 ~AudioEntry(); | 83 ~AudioEntry(); |
82 | 84 |
83 // The AudioInputController that manages the audio input stream. | 85 // The AudioInputController that manages the audio input stream. |
84 scoped_refptr<media::AudioInputController> controller; | 86 scoped_refptr<media::AudioInputController> controller; |
85 | 87 |
86 // The audio input stream ID in the render view. | 88 // The audio input stream ID in the render view. |
87 int stream_id; | 89 int stream_id; |
88 | 90 |
89 // Shared memory for transmission of the audio data. | 91 // Shared memory for transmission of the audio data. |
90 base::SharedMemory shared_memory; | 92 base::SharedMemory shared_memory; |
91 | 93 |
92 // The synchronous writer to be used by the controller. We have the | 94 // The synchronous writer to be used by the controller. We have the |
93 // ownership of the writer. | 95 // ownership of the writer. |
94 scoped_ptr<media::AudioInputController::SyncWriter> writer; | 96 scoped_ptr<media::AudioInputController::SyncWriter> writer; |
95 | 97 |
96 // Set to true after we called Close() for the controller. | 98 // Set to true after we called Close() for the controller. |
97 bool pending_close; | 99 bool pending_close; |
98 }; | 100 }; |
99 | 101 |
100 // Called from UI thread from the owner of this object. | 102 // Called from UI thread from the owner of this object. |
101 AudioInputRendererHost(content::ResourceContext* resource_context, | 103 AudioInputRendererHost(content::ResourceContext* resource_context, |
102 AudioManager* audio_manager); | 104 media::AudioManager* audio_manager); |
103 | 105 |
104 // content::BrowserMessageFilter implementation. | 106 // content::BrowserMessageFilter implementation. |
105 virtual void OnChannelClosing() OVERRIDE; | 107 virtual void OnChannelClosing() OVERRIDE; |
106 virtual void OnDestruct() const OVERRIDE; | 108 virtual void OnDestruct() const OVERRIDE; |
107 virtual bool OnMessageReceived(const IPC::Message& message, | 109 virtual bool OnMessageReceived(const IPC::Message& message, |
108 bool* message_was_ok) OVERRIDE; | 110 bool* message_was_ok) OVERRIDE; |
109 | 111 |
110 // AudioInputController::EventHandler implementation. | 112 // AudioInputController::EventHandler implementation. |
111 virtual void OnCreated(media::AudioInputController* controller) OVERRIDE; | 113 virtual void OnCreated(media::AudioInputController* controller) OVERRIDE; |
112 virtual void OnRecording(media::AudioInputController* controller) OVERRIDE; | 114 virtual void OnRecording(media::AudioInputController* controller) OVERRIDE; |
(...skipping 19 matching lines...) Expand all Loading... |
132 | 134 |
133 // Start the audio input device with the session id. If the device | 135 // Start the audio input device with the session id. If the device |
134 // starts successfully, it will trigger OnDeviceStarted() callback. | 136 // starts successfully, it will trigger OnDeviceStarted() callback. |
135 void OnStartDevice(int stream_id, int session_id); | 137 void OnStartDevice(int stream_id, int session_id); |
136 | 138 |
137 // Audio related IPC message handlers. | 139 // Audio related IPC message handlers. |
138 // Creates an audio input stream with the specified format. If this call is | 140 // Creates an audio input stream with the specified format. If this call is |
139 // successful this object would keep an internal entry of the stream for the | 141 // successful this object would keep an internal entry of the stream for the |
140 // required properties. | 142 // required properties. |
141 void OnCreateStream(int stream_id, | 143 void OnCreateStream(int stream_id, |
142 const AudioParameters& params, | 144 const media::AudioParameters& params, |
143 const std::string& device_id); | 145 const std::string& device_id); |
144 | 146 |
145 // Record the audio input stream referenced by |stream_id|. | 147 // Record the audio input stream referenced by |stream_id|. |
146 void OnRecordStream(int stream_id); | 148 void OnRecordStream(int stream_id); |
147 | 149 |
148 // Close the audio stream referenced by |stream_id|. | 150 // Close the audio stream referenced by |stream_id|. |
149 void OnCloseStream(int stream_id); | 151 void OnCloseStream(int stream_id); |
150 | 152 |
151 // Set the volume of the audio stream referenced by |stream_id|. | 153 // Set the volume of the audio stream referenced by |stream_id|. |
152 void OnSetVolume(int stream_id, double volume); | 154 void OnSetVolume(int stream_id, double volume); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 // This method is used to look up an AudioEntry after a controller | 197 // This method is used to look up an AudioEntry after a controller |
196 // event is received. | 198 // event is received. |
197 AudioEntry* LookupByController(media::AudioInputController* controller); | 199 AudioEntry* LookupByController(media::AudioInputController* controller); |
198 | 200 |
199 // A helper method to look up a session identified by |stream_id|. | 201 // A helper method to look up a session identified by |stream_id|. |
200 // Returns 0 if not found. | 202 // Returns 0 if not found. |
201 int LookupSessionById(int stream_id); | 203 int LookupSessionById(int stream_id); |
202 | 204 |
203 // Used to get an instance of AudioInputDeviceManager. | 205 // Used to get an instance of AudioInputDeviceManager. |
204 content::ResourceContext* resource_context_; | 206 content::ResourceContext* resource_context_; |
205 AudioManager* audio_manager_; | 207 media::AudioManager* audio_manager_; |
206 | 208 |
207 // A map of stream IDs to audio sources. | 209 // A map of stream IDs to audio sources. |
208 typedef std::map<int, AudioEntry*> AudioEntryMap; | 210 typedef std::map<int, AudioEntry*> AudioEntryMap; |
209 AudioEntryMap audio_entries_; | 211 AudioEntryMap audio_entries_; |
210 | 212 |
211 // A map of session IDs to audio session sources. | 213 // A map of session IDs to audio session sources. |
212 typedef std::map<int, int> SessionEntryMap; | 214 typedef std::map<int, int> SessionEntryMap; |
213 SessionEntryMap session_entries_; | 215 SessionEntryMap session_entries_; |
214 | 216 |
215 DISALLOW_COPY_AND_ASSIGN(AudioInputRendererHost); | 217 DISALLOW_COPY_AND_ASSIGN(AudioInputRendererHost); |
216 }; | 218 }; |
217 | 219 |
218 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_RENDERER_HOST_H_ | 220 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_RENDERER_HOST_H_ |
OLD | NEW |