| 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 -> | 
| 11 //   <- AudioInputMsg_NotifyStreamCreated <- DoCompleteCreation <- OnCreated <- | 11 //   <- AudioInputMsg_NotifyStreamCreated <- DoCompleteCreation <- OnCreated <- | 
| 12 // | 12 // | 
| 13 // Close stream sequence: | 13 // Close stream sequence: | 
| 14 // | 14 // | 
| 15 // AudioInputHostMsg_CloseStream -> OnCloseStream -> AIC::Close -> | 15 // AudioInputHostMsg_CloseStream -> OnCloseStream -> AIC::Close -> | 
| 16 // | 16 // | 
| 17 // For the OnStartDevice() request, AudioInputRendererHost starts the device |  | 
| 18 // referenced by the session id, and an OnDeviceStarted() callback with the |  | 
| 19 // id of the opened device will be received later. Then it will send a |  | 
| 20 // IPC message to notify the renderer that the device is ready, so that |  | 
| 21 // renderer can continue with the OnCreateStream() request. |  | 
| 22 // |  | 
| 23 // OnDeviceStopped() is called when the user closes the device through |  | 
| 24 // AudioInputDeviceManager without calling Stop() before. What |  | 
| 25 // AudioInputRenderHost::OnDeviceStopped() does is to send a IPC mesaage to |  | 
| 26 // notify the renderer in order to stop the stream. |  | 
| 27 // |  | 
| 28 // Start device sequence: |  | 
| 29 // |  | 
| 30 // OnStartDevice -> AudioInputDeviceManager::Start -> |  | 
| 31 // AudioInputDeviceManagerEventHandler::OnDeviceStarted -> |  | 
| 32 // AudioInputMsg_NotifyDeviceStarted |  | 
| 33 // |  | 
| 34 // Shutdown device sequence: |  | 
| 35 // |  | 
| 36 // OnDeviceStopped -> CloseAndDeleteStream |  | 
| 37 //                    AudioInputMsg_NotifyStreamStateChanged |  | 
| 38 // |  | 
| 39 // This class is owned by BrowserRenderProcessHost and instantiated on UI | 17 // This class is owned by BrowserRenderProcessHost and instantiated on UI | 
| 40 // thread. All other operations and method calls happen on IO thread, so we | 18 // thread. All other operations and method calls happen on IO thread, so we | 
| 41 // need to be extra careful about the lifetime of this object. | 19 // need to be extra careful about the lifetime of this object. | 
| 42 // | 20 // | 
| 43 // To ensure low latency audio, a SyncSocket pair is used to signal buffer | 21 // To ensure low latency audio, a SyncSocket pair is used to signal buffer | 
| 44 // readiness without having to route messages using the IO thread. | 22 // readiness without having to route messages using the IO thread. | 
| 45 | 23 | 
| 46 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_RENDERER_HOST_H_ | 24 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_RENDERER_HOST_H_ | 
| 47 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_RENDERER_HOST_H_ | 25 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_RENDERER_HOST_H_ | 
| 48 | 26 | 
| 49 #include <map> | 27 #include <map> | 
| 50 #include <string> | 28 #include <string> | 
| 51 | 29 | 
| 52 #include "base/compiler_specific.h" | 30 #include "base/compiler_specific.h" | 
| 53 #include "base/gtest_prod_util.h" | 31 #include "base/gtest_prod_util.h" | 
| 54 #include "base/memory/ref_counted.h" | 32 #include "base/memory/ref_counted.h" | 
| 55 #include "base/memory/scoped_ptr.h" | 33 #include "base/memory/scoped_ptr.h" | 
| 56 #include "base/process.h" | 34 #include "base/process.h" | 
| 57 #include "base/sequenced_task_runner_helpers.h" | 35 #include "base/sequenced_task_runner_helpers.h" | 
| 58 #include "base/shared_memory.h" | 36 #include "base/shared_memory.h" | 
| 59 #include "content/browser/renderer_host/media/audio_input_device_manager_event_h
     andler.h" |  | 
| 60 #include "content/public/browser/browser_message_filter.h" | 37 #include "content/public/browser/browser_message_filter.h" | 
| 61 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" | 
| 62 #include "media/audio/audio_input_controller.h" | 39 #include "media/audio/audio_input_controller.h" | 
| 63 #include "media/audio/audio_io.h" | 40 #include "media/audio/audio_io.h" | 
| 64 #include "media/audio/simple_sources.h" | 41 #include "media/audio/simple_sources.h" | 
| 65 | 42 | 
| 66 namespace media { | 43 namespace media { | 
| 67 class AudioManager; | 44 class AudioManager; | 
| 68 class AudioParameters; | 45 class AudioParameters; | 
| 69 } | 46 } | 
| 70 | 47 | 
| 71 namespace content { | 48 namespace content { | 
| 72 class MediaStreamManager; | 49 class MediaStreamManager; | 
| 73 | 50 | 
| 74 class CONTENT_EXPORT AudioInputRendererHost | 51 class CONTENT_EXPORT AudioInputRendererHost | 
| 75     : public BrowserMessageFilter, | 52     : public BrowserMessageFilter, | 
| 76       public media::AudioInputController::EventHandler, | 53       public media::AudioInputController::EventHandler { | 
| 77       public AudioInputDeviceManagerEventHandler { |  | 
| 78  public: | 54  public: | 
| 79   // Called from UI thread from the owner of this object. | 55   // Called from UI thread from the owner of this object. | 
| 80   AudioInputRendererHost( | 56   AudioInputRendererHost( | 
| 81       media::AudioManager* audio_manager, | 57       media::AudioManager* audio_manager, | 
| 82       MediaStreamManager* media_stream_manager); | 58       MediaStreamManager* media_stream_manager); | 
| 83 | 59 | 
| 84   // BrowserMessageFilter implementation. | 60   // BrowserMessageFilter implementation. | 
| 85   virtual void OnChannelClosing() OVERRIDE; | 61   virtual void OnChannelClosing() OVERRIDE; | 
| 86   virtual void OnDestruct() const OVERRIDE; | 62   virtual void OnDestruct() const OVERRIDE; | 
| 87   virtual bool OnMessageReceived(const IPC::Message& message, | 63   virtual bool OnMessageReceived(const IPC::Message& message, | 
| 88                                  bool* message_was_ok) OVERRIDE; | 64                                  bool* message_was_ok) OVERRIDE; | 
| 89 | 65 | 
| 90   // AudioInputController::EventHandler implementation. | 66   // AudioInputController::EventHandler implementation. | 
| 91   virtual void OnCreated(media::AudioInputController* controller) OVERRIDE; | 67   virtual void OnCreated(media::AudioInputController* controller) OVERRIDE; | 
| 92   virtual void OnRecording(media::AudioInputController* controller) OVERRIDE; | 68   virtual void OnRecording(media::AudioInputController* controller) OVERRIDE; | 
| 93   virtual void OnError(media::AudioInputController* controller, | 69   virtual void OnError(media::AudioInputController* controller, | 
| 94                        int error_code) OVERRIDE; | 70                        int error_code) OVERRIDE; | 
| 95   virtual void OnData(media::AudioInputController* controller, | 71   virtual void OnData(media::AudioInputController* controller, | 
| 96                       const uint8* data, | 72                       const uint8* data, | 
| 97                       uint32 size) OVERRIDE; | 73                       uint32 size) OVERRIDE; | 
| 98 | 74 | 
| 99   // AudioInputDeviceManagerEventHandler implementation. |  | 
| 100   virtual void OnDeviceStarted(int session_id, |  | 
| 101                                const std::string& device_id) OVERRIDE; |  | 
| 102   virtual void OnDeviceStopped(int session_id) OVERRIDE; |  | 
| 103 |  | 
| 104  private: | 75  private: | 
| 105   // TODO(henrika): extend test suite (compare AudioRenderHost) | 76   // TODO(henrika): extend test suite (compare AudioRenderHost) | 
| 106   friend class BrowserThread; | 77   friend class BrowserThread; | 
| 107   friend class base::DeleteHelper<AudioInputRendererHost>; | 78   friend class base::DeleteHelper<AudioInputRendererHost>; | 
| 108 | 79 | 
| 109   struct AudioEntry; | 80   struct AudioEntry; | 
| 110   typedef std::map<int, AudioEntry*> AudioEntryMap; | 81   typedef std::map<int, AudioEntry*> AudioEntryMap; | 
| 111   typedef std::map<int, int> SessionEntryMap; |  | 
| 112 | 82 | 
| 113   virtual ~AudioInputRendererHost(); | 83   virtual ~AudioInputRendererHost(); | 
| 114 | 84 | 
| 115   // Methods called on IO thread ---------------------------------------------- | 85   // Methods called on IO thread ---------------------------------------------- | 
| 116 | 86 | 
| 117   // Start the audio input device with the session id. If the device |  | 
| 118   // starts successfully, it will trigger OnDeviceStarted() callback. |  | 
| 119   void OnStartDevice(int stream_id, int session_id); |  | 
| 120 |  | 
| 121   // Audio related IPC message handlers. | 87   // Audio related IPC message handlers. | 
| 122   // Creates an audio input stream with the specified format. If this call is | 88   // Creates an audio input stream with the specified session id and format. | 
| 123   // successful this object would keep an internal entry of the stream for the | 89   // |session_id| is used to find out which device to be used for the stream, | 
| 124   // required properties. | 90   // when it is AudioInputDeviceManager::kFakeOpenSessionId, it uses the | 
|  | 91   // the default device. If this call is successful this object would keep an | 
|  | 92   // internal entry of the stream for the required properties. | 
| 125   void OnCreateStream(int stream_id, | 93   void OnCreateStream(int stream_id, | 
|  | 94                       int session_id, | 
| 126                       const media::AudioParameters& params, | 95                       const media::AudioParameters& params, | 
| 127                       const std::string& device_id, |  | 
| 128                       bool automatic_gain_control, | 96                       bool automatic_gain_control, | 
| 129                       int shared_memory_count); | 97                       int shared_memory_count); | 
| 130 | 98 | 
| 131   // Track that the data for the audio stream referenced by |stream_id| is | 99   // Track that the data for the audio stream referenced by |stream_id| is | 
| 132   // consumed by an entity in the render view referenced by |render_view_id|. | 100   // consumed by an entity in the render view referenced by |render_view_id|. | 
| 133   void OnAssociateStreamWithConsumer(int stream_id, int render_view_id); | 101   void OnAssociateStreamWithConsumer(int stream_id, int render_view_id); | 
| 134 | 102 | 
| 135   // Record the audio input stream referenced by |stream_id|. | 103   // Record the audio input stream referenced by |stream_id|. | 
| 136   void OnRecordStream(int stream_id); | 104   void OnRecordStream(int stream_id); | 
| 137 | 105 | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
| 160   // Closes the stream. The stream is then deleted in DeleteEntry() after it | 128   // Closes the stream. The stream is then deleted in DeleteEntry() after it | 
| 161   // is closed. | 129   // is closed. | 
| 162   void CloseAndDeleteStream(AudioEntry* entry); | 130   void CloseAndDeleteStream(AudioEntry* entry); | 
| 163 | 131 | 
| 164   // Delete an audio entry and close the related audio stream. | 132   // Delete an audio entry and close the related audio stream. | 
| 165   void DeleteEntry(AudioEntry* entry); | 133   void DeleteEntry(AudioEntry* entry); | 
| 166 | 134 | 
| 167   // Delete audio entry and close the related audio input stream. | 135   // Delete audio entry and close the related audio input stream. | 
| 168   void DeleteEntryOnError(AudioEntry* entry); | 136   void DeleteEntryOnError(AudioEntry* entry); | 
| 169 | 137 | 
| 170   // Stop the device and delete its audio session entry. |  | 
| 171   void StopAndDeleteDevice(int stream_id); |  | 
| 172 |  | 
| 173   // A helper method to look up a AudioEntry identified by |stream_id|. | 138   // A helper method to look up a AudioEntry identified by |stream_id|. | 
| 174   // Returns NULL if not found. | 139   // Returns NULL if not found. | 
| 175   AudioEntry* LookupById(int stream_id); | 140   AudioEntry* LookupById(int stream_id); | 
| 176 | 141 | 
| 177   // Search for a AudioEntry having the reference to |controller|. | 142   // Search for a AudioEntry having the reference to |controller|. | 
| 178   // This method is used to look up an AudioEntry after a controller | 143   // This method is used to look up an AudioEntry after a controller | 
| 179   // event is received. | 144   // event is received. | 
| 180   AudioEntry* LookupByController(media::AudioInputController* controller); | 145   AudioEntry* LookupByController(media::AudioInputController* controller); | 
| 181 | 146 | 
| 182   // A helper method to look up a session identified by |stream_id|. |  | 
| 183   // Returns 0 if not found. |  | 
| 184   int LookupSessionById(int stream_id); |  | 
| 185 |  | 
| 186   // Used to create an AudioInputController. | 147   // Used to create an AudioInputController. | 
| 187   media::AudioManager* audio_manager_; | 148   media::AudioManager* audio_manager_; | 
| 188 | 149 | 
| 189   // Used to access to AudioInputDeviceManager. | 150   // Used to access to AudioInputDeviceManager. | 
| 190   MediaStreamManager* media_stream_manager_; | 151   MediaStreamManager* media_stream_manager_; | 
| 191 | 152 | 
| 192   // A map of stream IDs to audio sources. | 153   // A map of stream IDs to audio sources. | 
| 193   AudioEntryMap audio_entries_; | 154   AudioEntryMap audio_entries_; | 
| 194 | 155 | 
| 195   // A map of session IDs to audio session sources. |  | 
| 196   SessionEntryMap session_entries_; |  | 
| 197 |  | 
| 198   DISALLOW_COPY_AND_ASSIGN(AudioInputRendererHost); | 156   DISALLOW_COPY_AND_ASSIGN(AudioInputRendererHost); | 
| 199 }; | 157 }; | 
| 200 | 158 | 
| 201 }  // namespace content | 159 }  // namespace content | 
| 202 | 160 | 
| 203 #endif  // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_RENDERER_HOST_H_ | 161 #endif  // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_RENDERER_HOST_H_ | 
| OLD | NEW | 
|---|