Chromium Code Reviews| 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 "media/audio/audio_input_device.h" | 16 #include "media/audio/audio_input_device.h" |
| 17 #include "media/base/audio_capturer_source.h" | 17 #include "media/base/audio_capturer_source.h" |
| 18 | 18 |
| 19 namespace media { | 19 namespace media { |
| 20 class AudioBus; | 20 class AudioBus; |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace WebKit { | |
| 24 class WebAudioSourceProvider; | |
| 25 } | |
| 26 | |
| 23 namespace content { | 27 namespace content { |
| 24 | 28 |
| 25 class WebRtcLocalAudioRenderer; | 29 class WebRtcLocalAudioRenderer; |
| 30 class WebRtcLocalAudioSourceProvider; | |
| 26 class WebRtcLocalAudioTrack; | 31 class WebRtcLocalAudioTrack; |
| 27 | 32 |
| 28 // This class manages the capture data flow by getting data from its | 33 // This class manages the capture data flow by getting data from its |
| 29 // |source_|, and passing it to its |tracks_|. | 34 // |source_|, and passing it to its |tracks_|. |
| 30 // It allows clients to inject their own capture data source by calling | 35 // It allows clients to inject their own capture data source by calling |
| 31 // SetCapturerSource(). | 36 // SetCapturerSource(). |
| 32 // The threading model for this class is rather complex since it will be | 37 // The threading model for this class is rather complex since it will be |
| 33 // created on the main render thread, captured data is provided on a dedicated | 38 // created on the main render thread, captured data is provided on a dedicated |
| 34 // AudioInputDevice thread, and methods can be called either on the Libjingle | 39 // AudioInputDevice thread, and methods can be called either on the Libjingle |
| 35 // thread or on the main render thread but also other client threads | 40 // thread or on the main render thread but also other client threads |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 66 | 71 |
| 67 // SetCapturerSource() is called if the client on the source side desires to | 72 // SetCapturerSource() is called if the client on the source side desires to |
| 68 // provide their own captured audio data. Client is responsible for calling | 73 // provide their own captured audio data. Client is responsible for calling |
| 69 // Start() on its own source to have the ball rolling. | 74 // Start() on its own source to have the ball rolling. |
| 70 // Called on the main render thread. | 75 // Called on the main render thread. |
| 71 void SetCapturerSource( | 76 void SetCapturerSource( |
| 72 const scoped_refptr<media::AudioCapturerSource>& source, | 77 const scoped_refptr<media::AudioCapturerSource>& source, |
| 73 media::ChannelLayout channel_layout, | 78 media::ChannelLayout channel_layout, |
| 74 float sample_rate); | 79 float sample_rate); |
| 75 | 80 |
| 81 void EnablePeerConnectionMode(); | |
|
tommi (sloooow) - chröme
2013/09/06 11:20:30
documentation
no longer working on chromium
2013/09/10 12:43:15
Done.
| |
| 82 | |
| 76 // Volume APIs used by WebRtcAudioDeviceImpl. | 83 // Volume APIs used by WebRtcAudioDeviceImpl. |
| 77 // Called on the AudioInputDevice audio thread. | 84 // Called on the AudioInputDevice audio thread. |
| 78 void SetVolume(int volume); | 85 void SetVolume(int volume); |
| 79 int Volume() const; | 86 int Volume() const; |
| 80 int MaxVolume() const; | 87 int MaxVolume() const; |
| 81 | 88 |
| 82 // Enables or disables the WebRtc AGC control. | 89 // Enables or disables the WebRtc AGC control. |
| 83 // Called from a Libjingle working thread. | 90 // Called from a Libjingle working thread. |
| 84 void SetAutomaticGainControl(bool enable); | 91 void SetAutomaticGainControl(bool enable); |
| 85 | 92 |
| 86 bool is_recording() const { return running_; } | 93 bool is_recording() const { return running_; } |
| 87 | 94 |
| 88 // Audio parameters utilized by the audio capturer. Can be utilized by | 95 // Audio parameters utilized by the audio capturer. Can be utilized by |
| 89 // a local renderer to set up a renderer using identical parameters as the | 96 // a local renderer to set up a renderer using identical parameters as the |
| 90 // capturer. | 97 // capturer. |
| 91 // TODO(phoglund): This accessor is inherently unsafe since the returned | 98 // TODO(phoglund): This accessor is inherently unsafe since the returned |
| 92 // parameters can become outdated at any time. Think over the implications | 99 // parameters can become outdated at any time. Think over the implications |
| 93 // of this accessor and if we can remove it. | 100 // of this accessor and if we can remove it. |
| 94 media::AudioParameters audio_parameters() const; | 101 media::AudioParameters audio_parameters() const; |
| 95 | 102 |
| 96 const std::string& device_id() const { return device_id_; } | 103 const std::string& device_id() const { return device_id_; } |
| 97 | 104 |
| 105 WebKit::WebAudioSourceProvider* AudioSourceProvider() const; | |
|
tommi (sloooow) - chröme
2013/09/06 11:20:30
GetAudioSourceProvider
usually for inline getters
no longer working on chromium
2013/09/10 12:43:15
Done.
| |
| 106 | |
| 98 protected: | 107 protected: |
| 99 friend class base::RefCountedThreadSafe<WebRtcAudioCapturer>; | 108 friend class base::RefCountedThreadSafe<WebRtcAudioCapturer>; |
| 100 WebRtcAudioCapturer(); | 109 WebRtcAudioCapturer(); |
| 101 virtual ~WebRtcAudioCapturer(); | 110 virtual ~WebRtcAudioCapturer(); |
| 102 | 111 |
| 103 private: | 112 private: |
| 104 class TrackOwner; | 113 class TrackOwner; |
| 105 typedef std::list<scoped_refptr<TrackOwner> > TrackList; | 114 typedef std::list<scoped_refptr<TrackOwner> > TrackList; |
| 106 | 115 |
| 107 // AudioCapturerSource::CaptureCallback implementation. | 116 // AudioCapturerSource::CaptureCallback implementation. |
| 108 // Called on the AudioInputDevice audio thread. | 117 // Called on the AudioInputDevice audio thread. |
| 109 virtual void Capture(media::AudioBus* audio_source, | 118 virtual void Capture(media::AudioBus* audio_source, |
| 110 int audio_delay_milliseconds, | 119 int audio_delay_milliseconds, |
| 111 double volume, | 120 double volume, |
| 112 bool key_pressed) OVERRIDE; | 121 bool key_pressed) OVERRIDE; |
| 113 virtual void OnCaptureError() OVERRIDE; | 122 virtual void OnCaptureError() OVERRIDE; |
| 114 | 123 |
| 115 // Reconfigures the capturer with a new buffer size and capture parameters. | 124 // Reconfigures the capturer with a new capture parameters. |
| 116 // Must be called without holding the lock. Returns true on success. | 125 // Must be called without holding the lock. |
| 117 bool Reconfigure(int sample_rate, media::ChannelLayout channel_layout); | 126 void Reconfigure(int sample_rate, media::ChannelLayout channel_layout); |
| 118 | 127 |
| 119 // Starts recording audio. | 128 // Starts recording audio. |
| 120 // Triggered by AddSink() on the main render thread or a Libjingle working | 129 // Triggered by AddSink() on the main render thread or a Libjingle working |
| 121 // thread. It should NOT be called under |lock_|. | 130 // thread. It should NOT be called under |lock_|. |
| 122 void Start(); | 131 void Start(); |
| 123 | 132 |
| 124 // Stops recording audio. | 133 // Stops recording audio. |
| 125 // Triggered by RemoveSink() on the main render thread or a Libjingle working | 134 // Triggered by RemoveSink() on the main render thread or a Libjingle working |
| 126 // thread. It should NOT be called under |lock_|. | 135 // thread. It should NOT be called under |lock_|. |
| 127 void Stop(); | 136 void Stop(); |
| 128 | 137 |
| 138 // Helper function to get the buffer size based on |native_mode_| and | |
|
tommi (sloooow) - chröme
2013/09/06 11:20:30
s/native_mode_/peer_connection_mode_
no longer working on chromium
2013/09/10 12:43:15
Done.
| |
| 139 // sample rate; | |
| 140 int GetBufferSize(int sample_rate) const; | |
| 129 | 141 |
| 130 // Used to DCHECK that we are called on the correct thread. | 142 // Used to DCHECK that we are called on the correct thread. |
| 131 base::ThreadChecker thread_checker_; | 143 base::ThreadChecker thread_checker_; |
| 132 | 144 |
| 133 // Protects |source_|, |audio_tracks_|, |running_|, |loopback_fifo_|, | 145 // Protects |source_|, |audio_tracks_|, |running_|, |loopback_fifo_|, |
| 134 // |params_|, |buffering_| and |agc_is_enabled_|. | 146 // |params_|, |buffering_| and |agc_is_enabled_|. |
| 135 mutable base::Lock lock_; | 147 mutable base::Lock lock_; |
| 136 | 148 |
| 137 // A list of audio tracks that the audio data is fed to. | 149 // A list of audio tracks that the audio data is fed to. |
| 138 TrackList tracks_; | 150 TrackList tracks_; |
| 139 | 151 |
| 140 // The audio data source from the browser process. | 152 // The audio data source from the browser process. |
| 141 scoped_refptr<media::AudioCapturerSource> source_; | 153 scoped_refptr<media::AudioCapturerSource> source_; |
| 142 | 154 |
| 143 // Buffers used for temporary storage during capture callbacks. | 155 // Cached values of utilized audio parameters. |
|
tommi (sloooow) - chröme
2013/09/06 11:20:30
nit: utilized and used does not mean exactly the s
no longer working on chromium
2013/09/10 12:43:15
Done.
| |
| 144 // Allocated during initialization. | 156 media::AudioParameters params_; |
| 145 class ConfiguredBuffer; | 157 |
| 146 scoped_refptr<ConfiguredBuffer> buffer_; | |
| 147 bool running_; | 158 bool running_; |
| 148 | 159 |
| 149 // True when automatic gain control is enabled, false otherwise. | 160 // True when automatic gain control is enabled, false otherwise. |
| 150 bool agc_is_enabled_; | 161 bool agc_is_enabled_; |
| 151 | 162 |
| 163 int render_view_id_; | |
| 164 | |
| 152 // The media session ID used to identify which input device to be started by | 165 // The media session ID used to identify which input device to be started by |
| 153 // the browser. | 166 // the browser. |
| 154 int session_id_; | 167 int session_id_; |
| 155 | 168 |
| 156 // The device this capturer is given permission to use. | 169 // The device this capturer is given permission to use. |
| 157 std::string device_id_; | 170 std::string device_id_; |
| 158 | 171 |
| 159 // Stores latest microphone volume received in a CaptureData() callback. | 172 // Stores latest microphone volume received in a CaptureData() callback. |
| 160 // Range is [0, 255]. | 173 // Range is [0, 255]. |
| 161 int volume_; | 174 int volume_; |
| 162 | 175 |
| 176 // The source provider to feed the capture data to other clients like | |
| 177 // WebAudio. | |
| 178 // TODO(xians): Move the source provider to track once we don't need to feed | |
| 179 // delay, volume, key_pressed information to WebAudioCapturerSource. | |
| 180 scoped_ptr<WebRtcLocalAudioSourceProvider> source_provider_; | |
| 181 | |
| 182 // Flag which affects the buffer size used by the capturer. | |
| 183 bool peer_connection_mode_; | |
| 184 | |
| 163 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioCapturer); | 185 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioCapturer); |
| 164 }; | 186 }; |
| 165 | 187 |
| 166 } // namespace content | 188 } // namespace content |
| 167 | 189 |
| 168 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ | 190 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ |
| OLD | NEW |