| 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 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
| 14 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
| 15 #include "content/renderer/media/webrtc_audio_device_impl.h" | 15 #include "content/renderer/media/webrtc_audio_device_impl.h" |
| 16 #include "content/renderer/media/webrtc_local_audio_source_provider.h" | |
| 17 #include "media/audio/audio_input_device.h" | 16 #include "media/audio/audio_input_device.h" |
| 18 #include "media/base/audio_capturer_source.h" | 17 #include "media/base/audio_capturer_source.h" |
| 19 | 18 |
| 20 namespace media { | 19 namespace media { |
| 21 class AudioBus; | 20 class AudioBus; |
| 22 } | 21 } |
| 23 | 22 |
| 24 namespace content { | 23 namespace content { |
| 25 | 24 |
| 26 class WebRtcLocalAudioRenderer; | 25 class WebRtcLocalAudioRenderer; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 // WebRtcAudioDeviceImpl calls this method on the main render thread but | 60 // WebRtcAudioDeviceImpl calls this method on the main render thread but |
| 62 // other clients may call it from other threads. The current implementation | 61 // other clients may call it from other threads. The current implementation |
| 63 // does not support multi-thread calling. | 62 // does not support multi-thread calling. |
| 64 // Called on the main render thread or libjingle working thread. | 63 // Called on the main render thread or libjingle working thread. |
| 65 void AddTrack(WebRtcLocalAudioTrack* track); | 64 void AddTrack(WebRtcLocalAudioTrack* track); |
| 66 | 65 |
| 67 // Remove a audio track from the sinks of the capturer. | 66 // Remove a audio track from the sinks of the capturer. |
| 68 // Called on the main render thread or libjingle working thread. | 67 // Called on the main render thread or libjingle working thread. |
| 69 void RemoveTrack(WebRtcLocalAudioTrack* track); | 68 void RemoveTrack(WebRtcLocalAudioTrack* track); |
| 70 | 69 |
| 71 // SetCapturerSource() is called if the client on the source side desires to | 70 // InitializeCapturerSource() is called if the client on the source side |
| 72 // provide their own captured audio data. Client is responsible for calling | 71 // desires to provide their own captured audio data. Client is responsible |
| 73 // Start() on its own source to have the ball rolling. | 72 // for calling Start() on its own source to have the ball rolling. |
| 74 // Called on the main render thread. | 73 // Called on the main render thread. |
| 75 void SetCapturerSource( | 74 void InitializeCapturerSource( |
| 76 const scoped_refptr<media::AudioCapturerSource>& source, | 75 const scoped_refptr<media::AudioCapturerSource>& source, |
| 77 media::ChannelLayout channel_layout, | 76 media::ChannelLayout channel_layout, |
| 78 float sample_rate); | 77 float sample_rate); |
| 79 | 78 |
| 80 // Called when a stream is connecting to a peer connection. This will set | 79 // Called when a stream is connecting to a peer connection. This will set |
| 81 // up the native buffer size for the stream in order to optimize the | 80 // up the native buffer size for the stream in order to optimize the |
| 82 // performance for peer connection. | 81 // performance for peer connection. |
| 83 void EnablePeerConnectionMode(); | 82 void EnablePeerConnectionMode(); |
| 84 | 83 |
| 85 // Volume APIs used by WebRtcAudioDeviceImpl. | 84 // Volume APIs used by WebRtcAudioDeviceImpl. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 104 | 103 |
| 105 // Gets information about the paired output device. Returns true if such a | 104 // Gets information about the paired output device. Returns true if such a |
| 106 // device exists. | 105 // device exists. |
| 107 bool GetPairedOutputParameters(int* session_id, | 106 bool GetPairedOutputParameters(int* session_id, |
| 108 int* output_sample_rate, | 107 int* output_sample_rate, |
| 109 int* output_frames_per_buffer) const; | 108 int* output_frames_per_buffer) const; |
| 110 | 109 |
| 111 const std::string& device_id() const { return device_id_; } | 110 const std::string& device_id() const { return device_id_; } |
| 112 int session_id() const { return session_id_; } | 111 int session_id() const { return session_id_; } |
| 113 | 112 |
| 114 WebKit::WebAudioSourceProvider* audio_source_provider() const { | |
| 115 return source_provider_.get(); | |
| 116 } | |
| 117 | |
| 118 // Stops recording audio. | 113 // Stops recording audio. |
| 119 void Stop(); | 114 void Stop(); |
| 120 | 115 |
| 116 // Called by the WebAudioCapturerSource to get the audio processing params. |
| 117 // This function is triggered by provideInput() on the WebAudio audio thread, |
| 118 // so it has been under the protection of |lock_|. |
| 119 // TODO(xians): Remove after moving APM from WebRtc to Chrome. |
| 120 void GetAudioProcessingParams(int* delay_ms, int* volume, bool* key_pressed); |
| 121 |
| 121 protected: | 122 protected: |
| 122 friend class base::RefCountedThreadSafe<WebRtcAudioCapturer>; | 123 friend class base::RefCountedThreadSafe<WebRtcAudioCapturer>; |
| 123 WebRtcAudioCapturer(); | 124 WebRtcAudioCapturer(); |
| 124 virtual ~WebRtcAudioCapturer(); | 125 virtual ~WebRtcAudioCapturer(); |
| 125 | 126 |
| 126 private: | 127 private: |
| 127 class TrackOwner; | 128 class TrackOwner; |
| 128 typedef std::list<scoped_refptr<TrackOwner> > TrackList; | 129 typedef std::list<scoped_refptr<TrackOwner> > TrackList; |
| 129 | 130 |
| 130 // AudioCapturerSource::CaptureCallback implementation. | 131 // AudioCapturerSource::CaptureCallback implementation. |
| 131 // Called on the AudioInputDevice audio thread. | 132 // Called on the AudioInputDevice audio thread. |
| 132 virtual void Capture(media::AudioBus* audio_source, | 133 virtual void Capture(media::AudioBus* audio_source, |
| 133 int audio_delay_milliseconds, | 134 int audio_delay_milliseconds, |
| 134 double volume, | 135 double volume, |
| 135 bool key_pressed) OVERRIDE; | 136 bool key_pressed) OVERRIDE; |
| 136 virtual void OnCaptureError() OVERRIDE; | 137 virtual void OnCaptureError() OVERRIDE; |
| 137 | 138 |
| 138 // Reconfigures the capturer with a new capture parameters. | 139 // Reconfigures the capturer with a new capture parameters. |
| 139 // Must be called without holding the lock. | 140 // Must be called without holding the lock. |
| 140 void Reconfigure(int sample_rate, media::ChannelLayout channel_layout); | 141 void Reconfigure(int sample_rate, media::ChannelLayout channel_layout); |
| 141 | 142 |
| 142 // Starts recording audio. | 143 // Starts recording audio. |
| 143 // Triggered by AddSink() on the main render thread or a Libjingle working | 144 // Triggered by AddSink() on the main render thread or a Libjingle working |
| 144 // thread. It should NOT be called under |lock_|. | 145 // thread. It should NOT be called under |lock_|. |
| 145 void Start(); | 146 void Start(); |
| 146 | 147 |
| 147 | |
| 148 | |
| 149 // Helper function to get the buffer size based on |peer_connection_mode_| | 148 // Helper function to get the buffer size based on |peer_connection_mode_| |
| 150 // and sample rate; | 149 // and sample rate; |
| 151 int GetBufferSize(int sample_rate) const; | 150 int GetBufferSize(int sample_rate) const; |
| 152 | 151 |
| 153 // Used to DCHECK that we are called on the correct thread. | 152 // Used to DCHECK that we are called on the correct thread. |
| 154 base::ThreadChecker thread_checker_; | 153 base::ThreadChecker thread_checker_; |
| 155 | 154 |
| 156 // Protects |source_|, |audio_tracks_|, |running_|, |loopback_fifo_|, | 155 // Protects |source_|, |audio_tracks_|, |running_|, |loopback_fifo_|, |
| 157 // |params_|, |buffering_| and |agc_is_enabled_|. | 156 // |source_params_|, |buffering_| and |agc_is_enabled_|. |
| 158 mutable base::Lock lock_; | 157 mutable base::Lock lock_; |
| 159 | 158 |
| 160 // A list of audio tracks that the audio data is fed to. | 159 // A list of audio tracks that the audio data is fed to. |
| 161 TrackList tracks_; | 160 TrackList tracks_; |
| 162 | 161 |
| 163 // The audio data source from the browser process. | 162 // The audio data source from the browser process. |
| 164 scoped_refptr<media::AudioCapturerSource> source_; | 163 scoped_refptr<media::AudioCapturerSource> source_; |
| 165 | 164 |
| 166 // Cached audio parameters for output. | 165 // Cached audio parameters for output. |
| 167 media::AudioParameters params_; | 166 media::AudioParameters params_; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 181 // the browser. | 180 // the browser. |
| 182 int session_id_; | 181 int session_id_; |
| 183 | 182 |
| 184 // The device this capturer is given permission to use. | 183 // The device this capturer is given permission to use. |
| 185 std::string device_id_; | 184 std::string device_id_; |
| 186 | 185 |
| 187 // Stores latest microphone volume received in a CaptureData() callback. | 186 // Stores latest microphone volume received in a CaptureData() callback. |
| 188 // Range is [0, 255]. | 187 // Range is [0, 255]. |
| 189 int volume_; | 188 int volume_; |
| 190 | 189 |
| 191 // The source provider to feed the capture data to other clients like | |
| 192 // WebAudio. | |
| 193 // TODO(xians): Move the source provider to track once we don't need to feed | |
| 194 // delay, volume, key_pressed information to WebAudioCapturerSource. | |
| 195 const scoped_ptr<WebRtcLocalAudioSourceProvider> source_provider_; | |
| 196 | |
| 197 // Flag which affects the buffer size used by the capturer. | 190 // Flag which affects the buffer size used by the capturer. |
| 198 bool peer_connection_mode_; | 191 bool peer_connection_mode_; |
| 199 | 192 |
| 200 int output_sample_rate_; | 193 int output_sample_rate_; |
| 201 int output_frames_per_buffer_; | 194 int output_frames_per_buffer_; |
| 202 | 195 |
| 196 // Cache value for the audio processing params. |
| 197 int audio_delay_ms_; |
| 198 bool key_pressed_; |
| 199 |
| 203 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioCapturer); | 200 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioCapturer); |
| 204 }; | 201 }; |
| 205 | 202 |
| 206 } // namespace content | 203 } // namespace content |
| 207 | 204 |
| 208 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ | 205 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ |
| OLD | NEW |