| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 virtual void OnDeviceStarted(const std::string& device_id) = 0; | 109 virtual void OnDeviceStarted(const std::string& device_id) = 0; |
| 110 | 110 |
| 111 // Notification to the client that the device has been stopped. | 111 // Notification to the client that the device has been stopped. |
| 112 virtual void OnDeviceStopped() = 0; | 112 virtual void OnDeviceStopped() = 0; |
| 113 | 113 |
| 114 protected: | 114 protected: |
| 115 virtual ~CaptureEventHandler() {} | 115 virtual ~CaptureEventHandler() {} |
| 116 }; | 116 }; |
| 117 | 117 |
| 118 // Methods called on main render thread ------------------------------------- | 118 // Methods called on main render thread ------------------------------------- |
| 119 AudioInputDevice(size_t buffer_size, | 119 AudioInputDevice(const AudioParameters& params, CaptureCallback* callback, |
| 120 int channels, | |
| 121 double sample_rate, | |
| 122 CaptureCallback* callback, | |
| 123 CaptureEventHandler* event_handler); | 120 CaptureEventHandler* event_handler); |
| 124 virtual ~AudioInputDevice(); | 121 virtual ~AudioInputDevice(); |
| 125 | 122 |
| 126 // Specify the |session_id| to query which device to use. This method is | 123 // Specify the |session_id| to query which device to use. This method is |
| 127 // asynchronous/non-blocking. | 124 // asynchronous/non-blocking. |
| 128 // Start() will use the second sequence if this method is called before. | 125 // Start() will use the second sequence if this method is called before. |
| 129 void SetDevice(int session_id); | 126 void SetDevice(int session_id); |
| 130 | 127 |
| 131 // Starts audio capturing. This method is asynchronous/non-blocking. | 128 // Starts audio capturing. This method is asynchronous/non-blocking. |
| 132 // TODO(henrika): add support for notification when recording has started. | 129 // TODO(henrika): add support for notification when recording has started. |
| 133 void Start(); | 130 void Start(); |
| 134 | 131 |
| 135 // Stops audio capturing. This method is synchronous/blocking. | 132 // Stops audio capturing. This method is synchronous/blocking. |
| 136 // TODO(henrika): add support for notification when recording has stopped. | 133 // TODO(henrika): add support for notification when recording has stopped. |
| 137 void Stop(); | 134 void Stop(); |
| 138 | 135 |
| 139 // Sets the capture volume scaling, with range [0.0, 1.0] inclusive. | 136 // Sets the capture volume scaling, with range [0.0, 1.0] inclusive. |
| 140 // Returns |true| on success. | 137 // Returns |true| on success. |
| 141 bool SetVolume(double volume); | 138 bool SetVolume(double volume); |
| 142 | 139 |
| 143 // Gets the capture volume scaling, with range [0.0, 1.0] inclusive. | 140 // Gets the capture volume scaling, with range [0.0, 1.0] inclusive. |
| 144 // Returns |true| on success. | 141 // Returns |true| on success. |
| 145 bool GetVolume(double* volume); | 142 bool GetVolume(double* volume); |
| 146 | 143 |
| 147 double sample_rate() const { return audio_parameters_.sample_rate; } | 144 double sample_rate() const { |
| 148 size_t buffer_size() const { return audio_parameters_.samples_per_packet; } | 145 return audio_parameters_.sample_rate(); |
| 146 } |
| 147 |
| 148 size_t buffer_size() const { |
| 149 return audio_parameters_.frames_per_buffer(); |
| 150 } |
| 149 | 151 |
| 150 // Methods called on IO thread ---------------------------------------------- | 152 // Methods called on IO thread ---------------------------------------------- |
| 151 // AudioInputMessageFilter::Delegate impl., called by AudioInputMessageFilter | 153 // AudioInputMessageFilter::Delegate impl., called by AudioInputMessageFilter |
| 152 virtual void OnStreamCreated(base::SharedMemoryHandle handle, | 154 virtual void OnStreamCreated(base::SharedMemoryHandle handle, |
| 153 base::SyncSocket::Handle socket_handle, | 155 base::SyncSocket::Handle socket_handle, |
| 154 uint32 length) OVERRIDE; | 156 uint32 length) OVERRIDE; |
| 155 virtual void OnVolume(double volume) OVERRIDE; | 157 virtual void OnVolume(double volume) OVERRIDE; |
| 156 virtual void OnStateChanged(AudioStreamState state) OVERRIDE; | 158 virtual void OnStateChanged(AudioStreamState state) OVERRIDE; |
| 157 virtual void OnDeviceReady(const std::string& device_id) OVERRIDE; | 159 virtual void OnDeviceReady(const std::string& device_id) OVERRIDE; |
| 158 | 160 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 // In order to avoid a race between OnStreamCreated and Stop(), we use this | 204 // In order to avoid a race between OnStreamCreated and Stop(), we use this |
| 203 // guard to control stopping and starting the audio thread. | 205 // guard to control stopping and starting the audio thread. |
| 204 base::Lock audio_thread_lock_; | 206 base::Lock audio_thread_lock_; |
| 205 AudioDeviceThread audio_thread_; | 207 AudioDeviceThread audio_thread_; |
| 206 scoped_ptr<AudioInputDevice::AudioThreadCallback> audio_callback_; | 208 scoped_ptr<AudioInputDevice::AudioThreadCallback> audio_callback_; |
| 207 | 209 |
| 208 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputDevice); | 210 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputDevice); |
| 209 }; | 211 }; |
| 210 | 212 |
| 211 #endif // CONTENT_RENDERER_MEDIA_AUDIO_INPUT_DEVICE_H_ | 213 #endif // CONTENT_RENDERER_MEDIA_AUDIO_INPUT_DEVICE_H_ |
| OLD | NEW |