Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: content/renderer/media/webrtc_audio_capturer.h

Issue 11783059: Ensures that WebRTC works for device selection using a different sample rate than default (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Had to restore usage of UTF16ToUTF8() in MediaStreamImpl::OnCreateNativeSourcesComplete to build on… Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "content/renderer/media/webrtc_audio_device_impl.h" 15 #include "content/renderer/media/webrtc_audio_device_impl.h"
15 #include "content/renderer/media/webrtc_local_audio_renderer.h" 16 #include "content/renderer/media/webrtc_local_audio_renderer.h"
16 #include "media/audio/audio_input_device.h" 17 #include "media/audio/audio_input_device.h"
17 #include "media/base/audio_capturer_source.h" 18 #include "media/base/audio_capturer_source.h"
18 #include "media/base/audio_fifo.h" 19 #include "media/base/audio_fifo.h"
19 20
20 namespace media { 21 namespace media {
21 class AudioBus; 22 class AudioBus;
22 } 23 }
23 24
24 namespace content { 25 namespace content {
25 26
26 class WebRtcAudioCapturerSink; 27 class WebRtcAudioCapturerSink;
27 class WebRtcLocalAudioRenderer; 28 class WebRtcLocalAudioRenderer;
28 29
29 // This class manages the capture data flow by getting data from its 30 // This class manages the capture data flow by getting data from its
30 // |source_|, and passing it to its |sink_|. 31 // |source_|, and passing it to its |sink_|.
31 // It allows clients to inject their own capture data source by calling 32 // It allows clients to inject their own capture data source by calling
32 // SetCapturerSource(). It is also possible to enable a local sink and 33 // SetCapturerSource(). It is also possible to enable a local sink and
33 // register a callback which the sink can call when it wants to read captured 34 // register a callback which the sink can call when it wants to read captured
34 // data cached in a FIFO for local loopback rendering. 35 // data cached in a FIFO for local loopback rendering.
35 // The threading model for this class is rather messy since it will be 36 // The threading model for this class is rather complex since it will be
36 // created on a Libjingle thread, captured data is provided on a dedicated 37 // created on the main render thread, captured data is provided on a dedicated
37 // AudioInputDevice thread, and methods can be called either on the Libjingle 38 // AudioInputDevice thread, and methods can be called either on the Libjingle
38 // thread or on the main render thread but also other client threads 39 // thread or on the main render thread but also other client threads
39 // if an alternative AudioCapturerSource has been set. In addition, the 40 // if an alternative AudioCapturerSource has been set. In addition, the
40 // AudioCapturerSource::CaptureEventHandler methods are called on the IO thread 41 // AudioCapturerSource::CaptureEventHandler methods are called on the IO thread
41 // and requests for data to render is done on the AudioOutputDevice thread. 42 // and requests for data to render is done on the AudioOutputDevice thread.
42 class WebRtcAudioCapturer 43 class CONTENT_EXPORT WebRtcAudioCapturer
43 : public base::RefCountedThreadSafe<WebRtcAudioCapturer>, 44 : public base::RefCountedThreadSafe<WebRtcAudioCapturer>,
44 public media::AudioCapturerSource::CaptureCallback, 45 NON_EXPORTED_BASE(public media::AudioCapturerSource::CaptureCallback),
45 public media::AudioCapturerSource::CaptureEventHandler, 46 NON_EXPORTED_BASE(public media::AudioCapturerSource::CaptureEventHandler),
46 public content::WebRtcLocalAudioRenderer::LocalRenderCallback { 47 NON_EXPORTED_BASE(
48 public content::WebRtcLocalAudioRenderer::LocalRenderCallback) {
47 public: 49 public:
48 // Use to construct the audio capturer. 50 // Use to construct the audio capturer.
51 // Called on the main render thread.
49 static scoped_refptr<WebRtcAudioCapturer> CreateCapturer(); 52 static scoped_refptr<WebRtcAudioCapturer> CreateCapturer();
50 53
54 // Creates and configures the default audio capturing source using the
55 // provided audio parameters.
56 // Called on the main render thread.
57 bool Initialize(media::ChannelLayout channel_layout, int sample_rate);
58
51 // Called by the client on the sink side to add a sink. 59 // Called by the client on the sink side to add a sink.
60 // WebRtcAudioDeviceImpl calls this method on the main render thread but
61 // other clients may call it from other threads. The current implementation
62 // does not support multi-thread calling.
63 // TODO(henrika): add lock if we extend number of supported sinks.
64 // Called on the main render thread.
52 void AddCapturerSink(WebRtcAudioCapturerSink* sink); 65 void AddCapturerSink(WebRtcAudioCapturerSink* sink);
53 66
54 // Called by the client on the sink side to remove a sink. 67 // Called by the client on the sink side to remove a sink.
68 // Called on the main render thread.
69 // TODO(henrika): add lock if we extend number of supported sinks.
70 // Called on the main render thread.
55 void RemoveCapturerSink(WebRtcAudioCapturerSink* sink); 71 void RemoveCapturerSink(WebRtcAudioCapturerSink* sink);
56 72
57 // SetCapturerSource() is called if the client on the source side desires to 73 // SetCapturerSource() is called if the client on the source side desires to
58 // provide their own captured audio data. Client is responsible for calling 74 // provide their own captured audio data. Client is responsible for calling
59 // Start() on its own source to have the ball rolling. 75 // Start() on its own source to have the ball rolling.
76 // Called on the main render thread.
60 void SetCapturerSource( 77 void SetCapturerSource(
61 const scoped_refptr<media::AudioCapturerSource>& source); 78 const scoped_refptr<media::AudioCapturerSource>& source);
62 79
63 // The |on_device_stopped_cb| callback will be called in OnDeviceStopped(). 80 // The |on_device_stopped_cb| callback will be called in OnDeviceStopped().
81 // Called on the main render thread.
64 void SetStopCallback(const base::Closure& on_device_stopped_cb); 82 void SetStopCallback(const base::Closure& on_device_stopped_cb);
65 83
66 // Informs this class that a local sink shall be used in addition to the 84 // Informs this class that a local sink shall be used in addition to the
67 // registered WebRtcAudioCapturerSink sink(s). The capturer will enter a 85 // registered WebRtcAudioCapturerSink sink(s). The capturer will enter a
68 // buffering mode and store all incoming audio frames in a local FIFO. 86 // buffering mode and store all incoming audio frames in a local FIFO.
69 // The renderer will read data from this buffer using the ProvideInput() 87 // The renderer will read data from this buffer using the ProvideInput()
70 // method. Called on the main render thread. 88 // method.
89 // Called on the main render thread.
71 void PrepareLoopback(); 90 void PrepareLoopback();
72 91
73 // Cancels loopback mode and stops buffering local copies of captured 92 // Cancels loopback mode and stops buffering local copies of captured
74 // data in the FIFO. 93 // data in the FIFO.
75 // Called on the main render thread. 94 // Called on the main render thread.
76 void CancelLoopback(); 95 void CancelLoopback();
77 96
78 // Pauses buffering of captured data. Does only have an effect if a local 97 // Pauses buffering of captured data. Does only have an effect if a local
79 // sink is used. 98 // sink is used.
80 // Called on the main render thread. 99 // Called on the main render thread.
81 void PauseBuffering(); 100 void PauseBuffering();
82 101
83 // Resumes buffering of captured data. Does only have an effect if a local 102 // Resumes buffering of captured data. Does only have an effect if a local
84 // sink is used. 103 // sink is used.
85 // Called on the main render thread. 104 // Called on the main render thread.
86 void ResumeBuffering(); 105 void ResumeBuffering();
87 106
88 // Starts recording audio. 107 // Starts recording audio.
108 // Called on the main render thread or a Libjingle working thread.
89 void Start(); 109 void Start();
90 110
91 // Stops recording audio. 111 // Stops recording audio.
112 // Called on the main render thread or a Libjingle working thread.
92 void Stop(); 113 void Stop();
93 114
94 // Sets the microphone volume. 115 // Sets the microphone volume.
116 // Called on the AudioInputDevice audio thread.
95 void SetVolume(double volume); 117 void SetVolume(double volume);
96 118
97 // Specifies the |session_id| to query which device to use. 119 // Specifies the |session_id| to query which device to use.
120 // Called on the main render thread.
98 void SetDevice(int session_id); 121 void SetDevice(int session_id);
99 122
100 // Enables or disables the WebRtc AGC control. 123 // Enables or disables the WebRtc AGC control.
124 // Called from a Libjingle working thread.
101 void SetAutomaticGainControl(bool enable); 125 void SetAutomaticGainControl(bool enable);
102 126
103 bool is_recording() const { return running_; } 127 bool is_recording() const { return running_; }
104 128
105 // Returns true if a local renderer has called PrepareLoopback() and it can 129 // Returns true if a local renderer has called PrepareLoopback() and it can
106 // be utilized to prevent more than one local renderer. 130 // be utilized to prevent more than one local renderer.
131 // Called on the main render thread.
107 bool IsInLoopbackMode(); 132 bool IsInLoopbackMode();
108 133
109 // Audio parameters utilized by the audio capturer. Can be utilized by 134 // Audio parameters utilized by the audio capturer. Can be utilized by
110 // a local renderer to set up a renderer using identical parameters as the 135 // a local renderer to set up a renderer using identical parameters as the
111 // capturer. 136 // capturer.
112 const media::AudioParameters& audio_parameter() const { return params_; } 137 const media::AudioParameters& audio_parameter() const { return params_; }
113 138
114 // AudioCapturerSource::CaptureCallback implementation. 139 // AudioCapturerSource::CaptureCallback implementation.
115 // Called on the AudioInputDevice audio thread. 140 // Called on the AudioInputDevice audio thread.
116 virtual void Capture(media::AudioBus* audio_source, 141 virtual void Capture(media::AudioBus* audio_source,
(...skipping 14 matching lines...) Expand all
131 156
132 protected: 157 protected:
133 friend class base::RefCountedThreadSafe<WebRtcAudioCapturer>; 158 friend class base::RefCountedThreadSafe<WebRtcAudioCapturer>;
134 virtual ~WebRtcAudioCapturer(); 159 virtual ~WebRtcAudioCapturer();
135 160
136 private: 161 private:
137 typedef std::list<WebRtcAudioCapturerSink*> SinkList; 162 typedef std::list<WebRtcAudioCapturerSink*> SinkList;
138 163
139 WebRtcAudioCapturer(); 164 WebRtcAudioCapturer();
140 165
141 // Initializes the capturer, called right after the object is created. 166 // Used to DCHECK that we are called on the correct thread.
142 // Returns false if the initialization fails. 167 base::ThreadChecker thread_checker_;
143 bool Initialize();
144 168
145 // Protects |source_|, |sinks_|, |running_|, |on_device_stopped_cb_|, 169 // Protects |source_|, |sinks_|, |running_|, |on_device_stopped_cb_|,
146 // |loopback_fifo_| and |buffering_|. 170 // |loopback_fifo_| and |buffering_|.
147 base::Lock lock_; 171 base::Lock lock_;
148 172
149 // A list of sinks that the audio data is fed to. 173 // A list of sinks that the audio data is fed to.
150 SinkList sinks_; 174 SinkList sinks_;
151 175
152 // The audio data source from the browser process. 176 // The audio data source from the browser process.
153 scoped_refptr<media::AudioCapturerSource> source_; 177 scoped_refptr<media::AudioCapturerSource> source_;
(...skipping 17 matching lines...) Expand all
171 195
172 // True when FIFO is utilized, false otherwise. 196 // True when FIFO is utilized, false otherwise.
173 bool buffering_; 197 bool buffering_;
174 198
175 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioCapturer); 199 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioCapturer);
176 }; 200 };
177 201
178 } // namespace content 202 } // namespace content
179 203
180 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ 204 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698