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 // Low-latency audio capturing unit utilizing audio input stream provided | 5 // Low-latency audio capturing unit utilizing audio input stream provided |
6 // by browser process through IPC. | 6 // by browser process through IPC. |
7 // | 7 // |
8 // Relationship of classes: | 8 // Relationship of classes: |
9 // | 9 // |
10 // AudioInputController AudioInputDevice | 10 // AudioInputController AudioInputDevice |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 71 |
72 #include <vector> | 72 #include <vector> |
73 | 73 |
74 #include "base/basictypes.h" | 74 #include "base/basictypes.h" |
75 #include "base/compiler_specific.h" | 75 #include "base/compiler_specific.h" |
76 #include "base/memory/scoped_ptr.h" | 76 #include "base/memory/scoped_ptr.h" |
77 #include "base/shared_memory.h" | 77 #include "base/shared_memory.h" |
78 #include "base/threading/simple_thread.h" | 78 #include "base/threading/simple_thread.h" |
79 #include "content/common/content_export.h" | 79 #include "content/common/content_export.h" |
80 #include "content/renderer/media/audio_input_message_filter.h" | 80 #include "content/renderer/media/audio_input_message_filter.h" |
| 81 #include "content/renderer/media/audio_device.h" |
81 #include "media/audio/audio_parameters.h" | 82 #include "media/audio/audio_parameters.h" |
82 | 83 |
83 // TODO(henrika): This class is based on the AudioDevice class and it has | 84 // TODO(henrika): This class is based on the AudioDevice class and it has |
84 // many components in common. Investigate potential for re-factoring. | 85 // many components in common. Investigate potential for re-factoring. |
85 // TODO(henrika): Add support for event handling (e.g. OnStateChanged, | 86 // TODO(henrika): Add support for event handling (e.g. OnStateChanged, |
86 // OnCaptureStopped etc.) and ensure that we can deliver these notifications | 87 // OnCaptureStopped etc.) and ensure that we can deliver these notifications |
87 // to any clients using this class. | 88 // to any clients using this class. |
88 class CONTENT_EXPORT AudioInputDevice | 89 class CONTENT_EXPORT AudioInputDevice |
89 : public AudioInputMessageFilter::Delegate, | 90 : public AudioInputMessageFilter::Delegate, |
90 public base::DelegateSimpleThread::Delegate, | 91 public base::DelegateSimpleThread::Delegate, |
| 92 public AudioDeviceIOLoopObserver<AudioInputDevice>, |
91 public base::RefCountedThreadSafe<AudioInputDevice> { | 93 public base::RefCountedThreadSafe<AudioInputDevice> { |
92 public: | 94 public: |
93 class CONTENT_EXPORT CaptureCallback { | 95 class CONTENT_EXPORT CaptureCallback { |
94 public: | 96 public: |
95 virtual void Capture(const std::vector<float*>& audio_data, | 97 virtual void Capture(const std::vector<float*>& audio_data, |
96 size_t number_of_frames, | 98 size_t number_of_frames, |
97 size_t audio_delay_milliseconds) = 0; | 99 size_t audio_delay_milliseconds) = 0; |
98 protected: | 100 protected: |
99 virtual ~CaptureCallback() {} | 101 virtual ~CaptureCallback() {} |
100 }; | 102 }; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 virtual void OnDeviceReady(const std::string& device_id) OVERRIDE; | 157 virtual void OnDeviceReady(const std::string& device_id) OVERRIDE; |
156 | 158 |
157 private: | 159 private: |
158 // Methods called on IO thread ---------------------------------------------- | 160 // Methods called on IO thread ---------------------------------------------- |
159 // The following methods are tasks posted on the IO thread that needs to | 161 // The following methods are tasks posted on the IO thread that needs to |
160 // be executed on that thread. They interact with AudioInputMessageFilter and | 162 // be executed on that thread. They interact with AudioInputMessageFilter and |
161 // sends IPC messages on that thread. | 163 // sends IPC messages on that thread. |
162 void InitializeOnIOThread(); | 164 void InitializeOnIOThread(); |
163 void SetSessionIdOnIOThread(int session_id); | 165 void SetSessionIdOnIOThread(int session_id); |
164 void StartOnIOThread(); | 166 void StartOnIOThread(); |
| 167 // Allow AudioDeviceIOLoopObserver to call ShutDownOnIOThread. |
| 168 friend class AudioDeviceIOLoopObserver<AudioInputDevice>; |
165 void ShutDownOnIOThread(base::WaitableEvent* completion); | 169 void ShutDownOnIOThread(base::WaitableEvent* completion); |
166 void SetVolumeOnIOThread(double volume); | 170 void SetVolumeOnIOThread(double volume); |
167 // Closes socket and joins with the audio thread. | 171 // Closes socket and joins with the audio thread. |
168 void ShutDownAudioThread(); | 172 void ShutDownAudioThread(); |
169 | 173 |
170 void Send(IPC::Message* message); | 174 void Send(IPC::Message* message); |
171 | 175 |
172 // Method called on the audio thread ---------------------------------------- | 176 // Method called on the audio thread ---------------------------------------- |
173 // Calls the client's callback for capturing audio. | 177 // Calls the client's callback for capturing audio. |
174 void FireCaptureCallback(int16* input_audio); | 178 void FireCaptureCallback(int16* input_audio); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 bool pending_device_ready_; | 215 bool pending_device_ready_; |
212 | 216 |
213 base::SharedMemoryHandle shared_memory_handle_; | 217 base::SharedMemoryHandle shared_memory_handle_; |
214 scoped_ptr<base::CancelableSyncSocket> audio_socket_; | 218 scoped_ptr<base::CancelableSyncSocket> audio_socket_; |
215 int memory_length_; | 219 int memory_length_; |
216 | 220 |
217 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputDevice); | 221 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputDevice); |
218 }; | 222 }; |
219 | 223 |
220 #endif // CONTENT_RENDERER_MEDIA_AUDIO_INPUT_DEVICE_H_ | 224 #endif // CONTENT_RENDERER_MEDIA_AUDIO_INPUT_DEVICE_H_ |
OLD | NEW |