| 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 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_RENDERER_HOST_H_ | 24 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_RENDERER_HOST_H_ |
| 25 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_RENDERER_HOST_H_ | 25 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_RENDERER_HOST_H_ |
| 26 | 26 |
| 27 #include <stdint.h> | 27 #include <stdint.h> |
| 28 | 28 |
| 29 #include <map> | 29 #include <map> |
| 30 #include <memory> | 30 #include <memory> |
| 31 #include <string> | 31 #include <string> |
| 32 | 32 |
| 33 #include "base/compiler_specific.h" | |
| 34 #include "base/macros.h" | |
| 35 #include "base/memory/ref_counted.h" | 33 #include "base/memory/ref_counted.h" |
| 36 #include "base/memory/weak_ptr.h" | |
| 37 #include "base/process/process.h" | |
| 38 #include "base/sequenced_task_runner_helpers.h" | |
| 39 #include "content/common/media/audio_messages.h" | 34 #include "content/common/media/audio_messages.h" |
| 40 #include "content/public/browser/browser_message_filter.h" | 35 #include "content/public/browser/browser_message_filter.h" |
| 41 #include "content/public/browser/browser_thread.h" | |
| 42 #include "media/audio/audio_input_controller.h" | 36 #include "media/audio/audio_input_controller.h" |
| 43 #include "media/audio/audio_io.h" | |
| 44 #include "media/audio/audio_logging.h" | |
| 45 #include "media/audio/simple_sources.h" | |
| 46 #include "media/media_features.h" | |
| 47 | 37 |
| 48 namespace media { | 38 namespace media { |
| 49 class AudioManager; | 39 class AudioManager; |
| 50 class UserInputMonitor; | 40 class UserInputMonitor; |
| 51 } | 41 } |
| 52 | 42 |
| 53 namespace content { | 43 namespace content { |
| 54 class AudioMirroringManager; | 44 class AudioMirroringManager; |
| 55 class MediaStreamManager; | 45 class MediaStreamManager; |
| 56 class RenderProcessHost; | |
| 57 | 46 |
| 58 class CONTENT_EXPORT AudioInputRendererHost | 47 class CONTENT_EXPORT AudioInputRendererHost |
| 59 : public BrowserMessageFilter, | 48 : public BrowserMessageFilter, |
| 60 public media::AudioInputController::EventHandler { | 49 public media::AudioInputController::EventHandler { |
| 61 public: | 50 public: |
| 62 // Error codes to make native loggin more clear. These error codes are added | 51 // Error codes to make native logging more clear. These error codes are added |
| 63 // to generic error strings to provide a higher degree of details. | 52 // to generic error strings to provide a higher degree of details. |
| 64 // Changing these values can lead to problems when matching native debug | 53 // Changing these values can lead to problems when matching native debug |
| 65 // logs with the actual cause of error. | 54 // logs with the actual cause of error. |
| 66 enum ErrorCode { | 55 enum ErrorCode { |
| 67 // An unspecified error occured. | 56 // An unspecified error occured. |
| 68 UNKNOWN_ERROR = 0, | 57 UNKNOWN_ERROR = 0, |
| 69 | 58 |
| 70 // Failed to look up audio intry for the provided stream id. | 59 // Failed to look up audio intry for the provided stream id. |
| 71 INVALID_AUDIO_ENTRY, // = 1 | 60 INVALID_AUDIO_ENTRY, // = 1 |
| 72 | 61 |
| 73 // A stream with the specified stream id already exists. | 62 // A stream with the specified stream id already exists. |
| 74 STREAM_ALREADY_EXISTS, // = 2 | 63 STREAM_ALREADY_EXISTS, // = 2 |
| 75 | 64 |
| 76 // The page does not have permission to open the specified capture device. | 65 // The page does not have permission to open the specified capture device. |
| 77 PERMISSION_DENIED, // = 3 | 66 PERMISSION_DENIED, // = 3 |
| 78 | 67 |
| 79 // Failed to create shared memory. | 68 // Failed to create shared memory. |
| 80 SHARED_MEMORY_CREATE_FAILED, // = 4 | 69 SHARED_MEMORY_CREATE_FAILED, // = 4 |
| 81 | 70 |
| 82 // Failed to initialize the AudioInputSyncWriter instance. | 71 // Failed to initialize the AudioInputSyncWriter instance. |
| 83 SYNC_WRITER_INIT_FAILED, // = 5 | 72 SYNC_WRITER_INIT_FAILED, // = 5 |
| 84 | 73 |
| 85 // Failed to create native audio input stream. | 74 // Failed to create native audio input stream. |
| 86 STREAM_CREATE_ERROR, // = 6 | 75 STREAM_CREATE_ERROR, // = 6 |
| 87 | 76 |
| 88 // Renderer process handle is invalid. | |
| 89 INVALID_PEER_HANDLE, // = 7 | |
| 90 | |
| 91 // Only low-latency mode is supported. | |
| 92 INVALID_LATENCY_MODE, // = 8 | |
| 93 | |
| 94 // Failed to map and share the shared memory. | 77 // Failed to map and share the shared memory. |
| 95 MEMORY_SHARING_FAILED, // = 9 | 78 MEMORY_SHARING_FAILED, // = 7, |
| 96 | 79 |
| 97 // Unable to prepare the foreign socket handle. | 80 // Unable to prepare the foreign socket handle. |
| 98 SYNC_SOCKET_ERROR, // = 10 | 81 SYNC_SOCKET_ERROR, // = 8, |
| 99 | 82 |
| 100 // This error message comes from the AudioInputController instance. | 83 // This error message comes from the AudioInputController instance. |
| 101 AUDIO_INPUT_CONTROLLER_ERROR, // = 11 | 84 AUDIO_INPUT_CONTROLLER_ERROR, // = 9, |
| 102 }; | 85 }; |
| 103 | 86 |
| 104 // Called from UI thread from the owner of this object. | 87 // Called from UI thread from the owner of this object. |
| 105 // |user_input_monitor| is used for typing detection and can be NULL. | 88 // |user_input_monitor| is used for typing detection and can be NULL. |
| 106 AudioInputRendererHost(int render_process_id, | 89 AudioInputRendererHost(int render_process_id, |
| 107 int32_t renderer_pid, | 90 int32_t renderer_pid, |
| 108 media::AudioManager* audio_manager, | 91 media::AudioManager* audio_manager, |
| 109 MediaStreamManager* media_stream_manager, | 92 MediaStreamManager* media_stream_manager, |
| 110 AudioMirroringManager* audio_mirroring_manager, | 93 AudioMirroringManager* audio_mirroring_manager, |
| 111 media::UserInputMonitor* user_input_monitor); | 94 media::UserInputMonitor* user_input_monitor); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 128 media::AudioInputController::ErrorCode error_code) override; | 111 media::AudioInputController::ErrorCode error_code) override; |
| 129 void OnData(media::AudioInputController* controller, | 112 void OnData(media::AudioInputController* controller, |
| 130 const media::AudioBus* data) override; | 113 const media::AudioBus* data) override; |
| 131 void OnLog(media::AudioInputController* controller, | 114 void OnLog(media::AudioInputController* controller, |
| 132 const std::string& message) override; | 115 const std::string& message) override; |
| 133 | 116 |
| 134 // Sets the PID renderer. This is used for constructing the debug recording | 117 // Sets the PID renderer. This is used for constructing the debug recording |
| 135 // filename. | 118 // filename. |
| 136 void set_renderer_pid(int32_t renderer_pid); | 119 void set_renderer_pid(int32_t renderer_pid); |
| 137 | 120 |
| 121 protected: |
| 122 ~AudioInputRendererHost() override; |
| 123 |
| 138 private: | 124 private: |
| 139 // TODO(henrika): extend test suite (compare AudioRenderHost) | |
| 140 friend class BrowserThread; | 125 friend class BrowserThread; |
| 141 friend class TestAudioInputRendererHost; | |
| 142 friend class base::DeleteHelper<AudioInputRendererHost>; | 126 friend class base::DeleteHelper<AudioInputRendererHost>; |
| 143 | 127 |
| 144 struct AudioEntry; | 128 struct AudioEntry; |
| 145 typedef std::map<int, AudioEntry*> AudioEntryMap; | 129 typedef std::map<int, AudioEntry*> AudioEntryMap; |
| 146 | 130 |
| 147 ~AudioInputRendererHost() override; | |
| 148 | |
| 149 // Methods called on IO thread ---------------------------------------------- | 131 // Methods called on IO thread ---------------------------------------------- |
| 150 | 132 |
| 151 // Audio related IPC message handlers. | 133 // Audio related IPC message handlers. |
| 152 | 134 |
| 153 // For ChromeOS: Checks if the stream should contain keyboard mic, if so | 135 // For ChromeOS: Checks if the stream should contain keyboard mic, if so |
| 154 // registers to AudioInputDeviceManager. Then calls DoCreateStream. | 136 // registers to AudioInputDeviceManager. Then calls DoCreateStream. |
| 155 // For non-ChromeOS: Just calls DoCreateStream. | 137 // For non-ChromeOS: Just calls DoCreateStream. |
| 156 void OnCreateStream(int stream_id, | 138 void OnCreateStream(int stream_id, |
| 157 int render_frame_id, | 139 int render_frame_id, |
| 158 int session_id, | 140 int session_id, |
| 159 const AudioInputHostMsg_CreateStream_Config& config); | 141 const AudioInputHostMsg_CreateStream_Config& config); |
| 160 | 142 |
| 161 // Creates an audio input stream with the specified format whose data is | 143 // Creates an audio input stream with the specified format whose data is |
| 162 // consumed by an entity in the RenderFrame referenced by |render_frame_id|. | 144 // consumed by an entity in the RenderFrame referenced by |render_frame_id|. |
| 163 // |session_id| is used to find out which device to be used for the stream. | 145 // |session_id| is used to identify the device that should be used for the |
| 164 // Upon success/failure, the peer is notified via the | 146 // stream. Upon success/failure, the peer is notified via the |
| 165 // NotifyStreamCreated message. | 147 // NotifyStreamCreated message. |
| 166 void DoCreateStream(int stream_id, | 148 void DoCreateStream(int stream_id, |
| 167 int render_frame_id, | 149 int render_frame_id, |
| 168 int session_id, | 150 int session_id, |
| 169 const AudioInputHostMsg_CreateStream_Config& config); | 151 const AudioInputHostMsg_CreateStream_Config& config); |
| 170 | 152 |
| 171 // Record the audio input stream referenced by |stream_id|. | 153 // Record the audio input stream referenced by |stream_id|. |
| 172 void OnRecordStream(int stream_id); | 154 void OnRecordStream(int stream_id); |
| 173 | 155 |
| 174 // Close the audio stream referenced by |stream_id|. | 156 // Close the audio stream referenced by |stream_id|. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 189 void DoHandleError(media::AudioInputController* controller, | 171 void DoHandleError(media::AudioInputController* controller, |
| 190 media::AudioInputController::ErrorCode error_code); | 172 media::AudioInputController::ErrorCode error_code); |
| 191 | 173 |
| 192 // Log audio level of captured audio stream. | 174 // Log audio level of captured audio stream. |
| 193 void DoLog(media::AudioInputController* controller, | 175 void DoLog(media::AudioInputController* controller, |
| 194 const std::string& message); | 176 const std::string& message); |
| 195 | 177 |
| 196 // Send an error message to the renderer. | 178 // Send an error message to the renderer. |
| 197 void SendErrorMessage(int stream_id, ErrorCode error_code); | 179 void SendErrorMessage(int stream_id, ErrorCode error_code); |
| 198 | 180 |
| 199 // Delete all audio entry and all audio streams | 181 // Delete all audio entries and all audio streams. |
| 200 void DeleteEntries(); | 182 void DeleteEntries(); |
| 201 | 183 |
| 202 // Closes the stream. The stream is then deleted in DeleteEntry() after it | 184 // Closes the stream. The stream is then deleted in DeleteEntry() after it |
| 203 // is closed. | 185 // is closed. |
| 204 void CloseAndDeleteStream(AudioEntry* entry); | 186 void CloseAndDeleteStream(AudioEntry* entry); |
| 205 | 187 |
| 206 // Delete an audio entry and close the related audio stream. | 188 // Delete an audio entry and close the related audio stream. |
| 207 void DeleteEntry(AudioEntry* entry); | 189 void DeleteEntry(AudioEntry* entry); |
| 208 | 190 |
| 209 // Delete audio entry and close the related audio input stream. | 191 // Delete audio entry and close the related audio input stream. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 AudioMirroringManager* audio_mirroring_manager_; | 236 AudioMirroringManager* audio_mirroring_manager_; |
| 255 | 237 |
| 256 // A map of stream IDs to audio sources. | 238 // A map of stream IDs to audio sources. |
| 257 AudioEntryMap audio_entries_; | 239 AudioEntryMap audio_entries_; |
| 258 | 240 |
| 259 // Raw pointer of the UserInputMonitor. | 241 // Raw pointer of the UserInputMonitor. |
| 260 media::UserInputMonitor* user_input_monitor_; | 242 media::UserInputMonitor* user_input_monitor_; |
| 261 | 243 |
| 262 std::unique_ptr<media::AudioLog> audio_log_; | 244 std::unique_ptr<media::AudioLog> audio_log_; |
| 263 | 245 |
| 264 base::WeakPtrFactory<AudioInputRendererHost> weak_factory_; | |
| 265 | |
| 266 DISALLOW_COPY_AND_ASSIGN(AudioInputRendererHost); | 246 DISALLOW_COPY_AND_ASSIGN(AudioInputRendererHost); |
| 267 }; | 247 }; |
| 268 | 248 |
| 269 } // namespace content | 249 } // namespace content |
| 270 | 250 |
| 271 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_RENDERER_HOST_H_ | 251 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_RENDERER_HOST_H_ |
| OLD | NEW |