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