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

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

Issue 12440027: Do not pass the string device_id via IPC message to create an audio input stream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed palmer's comments Created 7 years, 9 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
(...skipping 15 matching lines...) Expand all
26 class WebRtcLocalAudioRenderer; 26 class WebRtcLocalAudioRenderer;
27 27
28 // This class manages the capture data flow by getting data from its 28 // This class manages the capture data flow by getting data from its
29 // |source_|, and passing it to its |sink_|. 29 // |source_|, and passing it to its |sink_|.
30 // It allows clients to inject their own capture data source by calling 30 // It allows clients to inject their own capture data source by calling
31 // SetCapturerSource(). 31 // SetCapturerSource().
32 // The threading model for this class is rather complex since it will be 32 // 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 33 // 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 34 // AudioInputDevice thread, and methods can be called either on the Libjingle
35 // thread or on the main render thread but also other client threads 35 // thread or on the main render thread but also other client threads
36 // if an alternative AudioCapturerSource has been set. In addition, the 36 // if an alternative AudioCapturerSource has been set.
37 // AudioCapturerSource::CaptureEventHandler methods are called on the IO thread
38 // and requests for data to render is done on the AudioOutputDevice thread.
39 class CONTENT_EXPORT WebRtcAudioCapturer 37 class CONTENT_EXPORT WebRtcAudioCapturer
40 : public base::RefCountedThreadSafe<WebRtcAudioCapturer>, 38 : public base::RefCountedThreadSafe<WebRtcAudioCapturer>,
41 NON_EXPORTED_BASE(public media::AudioCapturerSource::CaptureCallback), 39 NON_EXPORTED_BASE(public media::AudioCapturerSource::CaptureCallback) {
42 NON_EXPORTED_BASE(
43 public media::AudioCapturerSource::CaptureEventHandler) {
44 public: 40 public:
45 // Use to construct the audio capturer. 41 // Use to construct the audio capturer.
46 // Called on the main render thread. 42 // Called on the main render thread.
47 static scoped_refptr<WebRtcAudioCapturer> CreateCapturer(); 43 static scoped_refptr<WebRtcAudioCapturer> CreateCapturer();
48 44
49 // Creates and configures the default audio capturing source using the 45 // Creates and configures the default audio capturing source using the
50 // provided audio parameters. 46 // provided audio parameters, |session_id| is used to be passed to the
47 // browser to decide which device to use.
51 // Called on the main render thread. 48 // Called on the main render thread.
52 bool Initialize(media::ChannelLayout channel_layout, int sample_rate); 49 bool Initialize(media::ChannelLayout channel_layout,
50 int sample_rate,
51 int session_id);
53 52
54 // Called by the client on the sink side to add a sink. 53 // Called by the client on the sink side to add a sink.
55 // WebRtcAudioDeviceImpl calls this method on the main render thread but 54 // WebRtcAudioDeviceImpl calls this method on the main render thread but
56 // other clients may call it from other threads. The current implementation 55 // other clients may call it from other threads. The current implementation
57 // does not support multi-thread calling. 56 // does not support multi-thread calling.
58 // Called on the main render thread. 57 // Called on the main render thread.
59 void AddCapturerSink(WebRtcAudioCapturerSink* sink); 58 void AddCapturerSink(WebRtcAudioCapturerSink* sink);
60 59
61 // Called by the client on the sink side to remove a sink. 60 // Called by the client on the sink side to remove a sink.
62 // Called on the main render thread. 61 // Called on the main render thread.
(...skipping 14 matching lines...) Expand all
77 void Start(); 76 void Start();
78 77
79 // Stops recording audio. 78 // Stops recording audio.
80 // Called on the main render thread or a Libjingle working thread. 79 // Called on the main render thread or a Libjingle working thread.
81 void Stop(); 80 void Stop();
82 81
83 // Sets the microphone volume. 82 // Sets the microphone volume.
84 // Called on the AudioInputDevice audio thread. 83 // Called on the AudioInputDevice audio thread.
85 void SetVolume(double volume); 84 void SetVolume(double volume);
86 85
87 // Specifies the |session_id| to query which device to use.
88 // Called on the main render thread.
89 void SetDevice(int session_id);
90
91 // Enables or disables the WebRtc AGC control. 86 // Enables or disables the WebRtc AGC control.
92 // Called from a Libjingle working thread. 87 // Called from a Libjingle working thread.
93 void SetAutomaticGainControl(bool enable); 88 void SetAutomaticGainControl(bool enable);
94 89
95 bool is_recording() const { return running_; } 90 bool is_recording() const { return running_; }
96 91
97 // Audio parameters utilized by the audio capturer. Can be utilized by 92 // Audio parameters utilized by the audio capturer. Can be utilized by
98 // a local renderer to set up a renderer using identical parameters as the 93 // a local renderer to set up a renderer using identical parameters as the
99 // capturer. 94 // capturer.
100 // TODO(phoglund): This accessor is inherently unsafe since the returned 95 // TODO(phoglund): This accessor is inherently unsafe since the returned
101 // parameters can become outdated at any time. Think over the implications 96 // parameters can become outdated at any time. Think over the implications
102 // of this accessor and if we can remove it. 97 // of this accessor and if we can remove it.
103 media::AudioParameters audio_parameters() const; 98 media::AudioParameters audio_parameters() const;
104 99
105 // AudioCapturerSource::CaptureCallback implementation. 100 // AudioCapturerSource::CaptureCallback implementation.
106 // Called on the AudioInputDevice audio thread. 101 // Called on the AudioInputDevice audio thread.
107 virtual void Capture(media::AudioBus* audio_source, 102 virtual void Capture(media::AudioBus* audio_source,
108 int audio_delay_milliseconds, 103 int audio_delay_milliseconds,
109 double volume) OVERRIDE; 104 double volume) OVERRIDE;
110 virtual void OnCaptureError() OVERRIDE; 105 virtual void OnCaptureError() OVERRIDE;
111 106
112 // AudioCapturerSource::CaptureEventHandler implementation.
113 // Called on the IO thread.
114 virtual void OnDeviceStarted(const std::string& device_id) OVERRIDE;
115 virtual void OnDeviceStopped() OVERRIDE;
116
117 protected: 107 protected:
118 friend class base::RefCountedThreadSafe<WebRtcAudioCapturer>; 108 friend class base::RefCountedThreadSafe<WebRtcAudioCapturer>;
119 virtual ~WebRtcAudioCapturer(); 109 virtual ~WebRtcAudioCapturer();
120 110
121 private: 111 private:
122 typedef std::list<WebRtcAudioCapturerSink*> SinkList; 112 typedef std::list<WebRtcAudioCapturerSink*> SinkList;
123 113
124 WebRtcAudioCapturer(); 114 WebRtcAudioCapturer();
125 115
126 // Reconfigures the capturer with a new buffer size and capture parameters. 116 // Reconfigures the capturer with a new buffer size and capture parameters.
127 // Must be called without holding the lock. Returns true on success. 117 // Must be called without holding the lock. Returns true on success.
128 bool Reconfigure(int sample_rate, media::ChannelLayout channel_layout); 118 bool Reconfigure(int sample_rate, media::ChannelLayout channel_layout);
129 119
130 // Distributes information about a stopped capture device to all registered
131 // capture sinks.
132 // Runs on the main render thread.
133 void DoOnDeviceStopped();
134
135 // Used to DCHECK that we are called on the correct thread. 120 // Used to DCHECK that we are called on the correct thread.
136 base::ThreadChecker thread_checker_; 121 base::ThreadChecker thread_checker_;
137 122
138 // Message loop for the main render thread. Utilized in OnDeviceStopped() to 123 // Protects |source_|, |sinks_|, |running_|, |loopback_fifo_|, |params_|,
139 // ensure that OnSourceCaptureDeviceStopped() is called on the main thread 124 // |buffering_| and |agc_is_enabled_|.
140 // instead of the originating IO thread.
141 scoped_refptr<base::MessageLoopProxy> main_loop_;
142
143 // Protects |source_|, |sinks_|, |running_|, |on_device_stopped_cb_|,
144 // |loopback_fifo_|, |params_|, |buffering_| and |agc_is_enabled_|.
145 mutable base::Lock lock_; 125 mutable base::Lock lock_;
146 126
147 // A list of sinks that the audio data is fed to. 127 // A list of sinks that the audio data is fed to.
148 SinkList sinks_; 128 SinkList sinks_;
149 129
150 // The audio data source from the browser process. 130 // The audio data source from the browser process.
151 scoped_refptr<media::AudioCapturerSource> source_; 131 scoped_refptr<media::AudioCapturerSource> source_;
152 132
153 // Buffers used for temporary storage during capture callbacks. 133 // Buffers used for temporary storage during capture callbacks.
154 // Allocated during initialization. 134 // Allocated during initialization.
155 class ConfiguredBuffer; 135 class ConfiguredBuffer;
156 scoped_refptr<ConfiguredBuffer> buffer_; 136 scoped_refptr<ConfiguredBuffer> buffer_;
157 std::string device_id_;
158 bool running_; 137 bool running_;
159 138
160 // True when automatic gain control is enabled, false otherwise. 139 // True when automatic gain control is enabled, false otherwise.
161 bool agc_is_enabled_; 140 bool agc_is_enabled_;
162 141
142 // The media session ID used to identify which input device to be started.
143 int session_id_;
144
163 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioCapturer); 145 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioCapturer);
164 }; 146 };
165 147
166 } // namespace content 148 } // namespace content
167 149
168 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ 150 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698