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 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 // Creates and configures the default audio capturing source using the | 46 // Creates and configures the default audio capturing source using the |
47 // provided audio parameters. |render_view_id| specifies the render view | 47 // provided audio parameters. |render_view_id| specifies the render view |
48 // consuming audio for capture. |session_id| is passed to the browser to | 48 // consuming audio for capture. |session_id| is passed to the browser to |
49 // decide which device to use. Called on the main render thread. | 49 // decide which device to use. Called on the main render thread. |
50 bool Initialize(int render_view_id, | 50 bool Initialize(int render_view_id, |
51 media::ChannelLayout channel_layout, | 51 media::ChannelLayout channel_layout, |
52 int sample_rate, | 52 int sample_rate, |
53 int session_id); | 53 int session_id); |
54 | 54 |
| 55 // Called by the WebRtcAudioDeviceImpl to add the ADM as the default sink to |
| 56 // the capturer. This function is needed since WebRTC supports only one ADM |
| 57 // but multiple audio tracks, so the ADM can't be the sink of certain audio |
| 58 // track now. And we also need to distinguish the WebRtcAudioDeviceImpl from |
| 59 // the audio track in order to start/stop the source of the capturer |
| 60 // correctly. |
| 61 // TODO(xians): Remove this function after WebRtc supports multiple ADMs. |
| 62 void SetDefaultSink(WebRtcAudioCapturerSink* sink); |
| 63 |
55 // Add a audio track to the sinks of the capturer. | 64 // Add a audio track to the sinks of the capturer. |
56 // WebRtcAudioDeviceImpl calls this method on the main render thread but | 65 // WebRtcAudioDeviceImpl calls this method on the main render thread but |
57 // other clients may call it from other threads. The current implementation | 66 // other clients may call it from other threads. The current implementation |
58 // does not support multi-thread calling. | 67 // does not support multi-thread calling. |
59 // Called on the main render thread. | 68 // Called on the main render thread or libjingle working thread. |
60 void AddSink(WebRtcAudioCapturerSink* track); | 69 void AddSink(WebRtcAudioCapturerSink* track); |
61 | 70 |
62 // Remove a audio track from the sinks of the capturer. | 71 // Remove a audio track from the sinks of the capturer. |
63 // Called on the main render thread. | 72 // Called on the main render thread or libjingle working thread. |
64 void RemoveSink(WebRtcAudioCapturerSink* track); | 73 void RemoveSink(WebRtcAudioCapturerSink* track); |
65 | 74 |
66 // SetCapturerSource() is called if the client on the source side desires to | 75 // SetCapturerSource() is called if the client on the source side desires to |
67 // provide their own captured audio data. Client is responsible for calling | 76 // provide their own captured audio data. Client is responsible for calling |
68 // Start() on its own source to have the ball rolling. | 77 // Start() on its own source to have the ball rolling. |
69 // Called on the main render thread. | 78 // Called on the main render thread. |
70 void SetCapturerSource( | 79 void SetCapturerSource( |
71 const scoped_refptr<media::AudioCapturerSource>& source, | 80 const scoped_refptr<media::AudioCapturerSource>& source, |
72 media::ChannelLayout channel_layout, | 81 media::ChannelLayout channel_layout, |
73 float sample_rate); | 82 float sample_rate); |
74 | 83 |
75 // Starts recording audio. | |
76 // Called on the main render thread or a Libjingle working thread. | |
77 void Start(); | |
78 | |
79 // Stops recording audio. | |
80 // Called on the main render thread or a Libjingle working thread. | |
81 void Stop(); | |
82 | |
83 // Sets the microphone volume. | 84 // Sets the microphone volume. |
84 // Called on the AudioInputDevice audio thread. | 85 // Called on the AudioInputDevice audio thread. |
85 void SetVolume(double volume); | 86 void SetVolume(double volume); |
86 | 87 |
87 // Enables or disables the WebRtc AGC control. | 88 // Enables or disables the WebRtc AGC control. |
88 // Called from a Libjingle working thread. | 89 // Called from a Libjingle working thread. |
89 void SetAutomaticGainControl(bool enable); | 90 void SetAutomaticGainControl(bool enable); |
90 | 91 |
91 bool is_recording() const { return running_; } | 92 bool is_recording() const { return running_; } |
92 | 93 |
(...skipping 17 matching lines...) Expand all Loading... |
110 // Called on the AudioInputDevice audio thread. | 111 // Called on the AudioInputDevice audio thread. |
111 virtual void Capture(media::AudioBus* audio_source, | 112 virtual void Capture(media::AudioBus* audio_source, |
112 int audio_delay_milliseconds, | 113 int audio_delay_milliseconds, |
113 double volume) OVERRIDE; | 114 double volume) OVERRIDE; |
114 virtual void OnCaptureError() OVERRIDE; | 115 virtual void OnCaptureError() OVERRIDE; |
115 | 116 |
116 // Reconfigures the capturer with a new buffer size and capture parameters. | 117 // Reconfigures the capturer with a new buffer size and capture parameters. |
117 // Must be called without holding the lock. Returns true on success. | 118 // Must be called without holding the lock. Returns true on success. |
118 bool Reconfigure(int sample_rate, media::ChannelLayout channel_layout); | 119 bool Reconfigure(int sample_rate, media::ChannelLayout channel_layout); |
119 | 120 |
| 121 // Starts recording audio. |
| 122 // Triggered by AddSink() on the main render thread or a Libjingle working |
| 123 // thread. It should NOT be called under |lock_|. |
| 124 void Start(); |
| 125 |
| 126 // Stops recording audio. |
| 127 // Triggered by RemoveSink() on the main render thread or a Libjingle working |
| 128 // thread. It should NOT be called under |lock_|. |
| 129 void Stop(); |
| 130 |
| 131 |
120 // Used to DCHECK that we are called on the correct thread. | 132 // Used to DCHECK that we are called on the correct thread. |
121 base::ThreadChecker thread_checker_; | 133 base::ThreadChecker thread_checker_; |
122 | 134 |
123 // Protects |source_|, |audio_tracks_|, |running_|, |loopback_fifo_|, | 135 // Protects |source_|, |audio_tracks_|, |running_|, |loopback_fifo_|, |
124 // |params_|, |buffering_| and |agc_is_enabled_|. | 136 // |params_|, |buffering_| and |agc_is_enabled_|. |
125 mutable base::Lock lock_; | 137 mutable base::Lock lock_; |
126 | 138 |
127 // A list of audio tracks that the audio data is fed to. | 139 // A list of audio tracks that the audio data is fed to. |
128 TrackList tracks_; | 140 TrackList tracks_; |
129 | 141 |
| 142 // A pointer to WebRtcAudioDeviceImpl which is the default destination of |
| 143 // all the audio tracks data flow. |
| 144 WebRtcAudioCapturerSink* default_sink_; |
| 145 |
130 // The audio data source from the browser process. | 146 // The audio data source from the browser process. |
131 scoped_refptr<media::AudioCapturerSource> source_; | 147 scoped_refptr<media::AudioCapturerSource> source_; |
132 | 148 |
133 // Buffers used for temporary storage during capture callbacks. | 149 // Buffers used for temporary storage during capture callbacks. |
134 // Allocated during initialization. | 150 // Allocated during initialization. |
135 class ConfiguredBuffer; | 151 class ConfiguredBuffer; |
136 scoped_refptr<ConfiguredBuffer> buffer_; | 152 scoped_refptr<ConfiguredBuffer> buffer_; |
137 bool running_; | 153 bool running_; |
138 | 154 |
139 // True when automatic gain control is enabled, false otherwise. | 155 // True when automatic gain control is enabled, false otherwise. |
140 bool agc_is_enabled_; | 156 bool agc_is_enabled_; |
141 | 157 |
142 // The media session ID used to identify which input device to be started. | 158 // The media session ID used to identify which input device to be started. |
143 int session_id_; | 159 int session_id_; |
144 | 160 |
145 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioCapturer); | 161 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioCapturer); |
146 }; | 162 }; |
147 | 163 |
148 } // namespace content | 164 } // namespace content |
149 | 165 |
150 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ | 166 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ |
OLD | NEW |