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

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

Issue 671793004: Clean up the media stream audio track code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 6 years, 1 month 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_DEVICE_IMPL_H_ 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_ 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 int audio_delay_milliseconds, 192 int audio_delay_milliseconds,
193 base::TimeDelta* current_time) = 0; 193 base::TimeDelta* current_time) = 0;
194 194
195 // Callback to notify the client that the renderer is going away. 195 // Callback to notify the client that the renderer is going away.
196 virtual void RemoveAudioRenderer(WebRtcAudioRenderer* renderer) = 0; 196 virtual void RemoveAudioRenderer(WebRtcAudioRenderer* renderer) = 0;
197 197
198 protected: 198 protected:
199 virtual ~WebRtcAudioRendererSource() {} 199 virtual ~WebRtcAudioRendererSource() {}
200 }; 200 };
201 201
202 class PeerConnectionAudioSink {
203 public:
204 // Callback to deliver the captured interleaved data.
205 // |channels| contains a vector of WebRtc VoE channels.
206 // |audio_data| is the pointer to the audio data.
207 // |sample_rate| is the sample frequency of audio data.
208 // |number_of_channels| is the number of channels reflecting the order of
209 // surround sound channels.
210 // |audio_delay_milliseconds| is recording delay value.
211 // |current_volume| is current microphone volume, in range of |0, 255].
212 // |need_audio_processing| indicates if the audio needs WebRtc AEC/NS/AGC
213 // audio processing.
214 // The return value is the new microphone volume, in the range of |0, 255].
215 // When the volume does not need to be updated, it returns 0.
216 virtual int OnData(const int16* audio_data,
217 int sample_rate,
218 int number_of_channels,
219 int number_of_frames,
220 const std::vector<int>& channels,
221 int audio_delay_milliseconds,
222 int current_volume,
223 bool need_audio_processing,
224 bool key_pressed) = 0;
225
226 // Set the format for the capture audio parameters.
227 // This is called when the capture format has changed, and it must be called
228 // on the same thread as calling CaptureData().
229 virtual void OnSetFormat(const media::AudioParameters& params) = 0;
230
231 protected:
232 virtual ~PeerConnectionAudioSink() {}
233 };
234
235 // TODO(xians): Merge this interface with WebRtcAudioRendererSource. 202 // TODO(xians): Merge this interface with WebRtcAudioRendererSource.
236 // The reason why we could not do it today is that WebRtcAudioRendererSource 203 // The reason why we could not do it today is that WebRtcAudioRendererSource
237 // gets the data by pulling, while the data is pushed into 204 // gets the data by pulling, while the data is pushed into
238 // WebRtcPlayoutDataSource::Sink. 205 // WebRtcPlayoutDataSource::Sink.
239 class WebRtcPlayoutDataSource { 206 class WebRtcPlayoutDataSource {
240 public: 207 public:
241 class Sink { 208 class Sink {
242 public: 209 public:
243 // Callback to get the playout data. 210 // Callback to get the playout data.
244 // Called on the render audio thread. 211 // Called on the render audio thread.
(...skipping 16 matching lines...) Expand all
261 virtual void RemovePlayoutSink(Sink* sink) = 0; 228 virtual void RemovePlayoutSink(Sink* sink) = 0;
262 229
263 protected: 230 protected:
264 virtual ~WebRtcPlayoutDataSource() {} 231 virtual ~WebRtcPlayoutDataSource() {}
265 }; 232 };
266 233
267 // Note that this class inherits from webrtc::AudioDeviceModule but due to 234 // Note that this class inherits from webrtc::AudioDeviceModule but due to
268 // the high number of non-implemented methods, we move the cruft over to the 235 // the high number of non-implemented methods, we move the cruft over to the
269 // WebRtcAudioDeviceNotImpl. 236 // WebRtcAudioDeviceNotImpl.
270 class CONTENT_EXPORT WebRtcAudioDeviceImpl 237 class CONTENT_EXPORT WebRtcAudioDeviceImpl
271 : NON_EXPORTED_BASE(public PeerConnectionAudioSink), 238 : NON_EXPORTED_BASE(public WebRtcAudioDeviceNotImpl),
272 NON_EXPORTED_BASE(public WebRtcAudioDeviceNotImpl),
273 NON_EXPORTED_BASE(public WebRtcAudioRendererSource), 239 NON_EXPORTED_BASE(public WebRtcAudioRendererSource),
274 NON_EXPORTED_BASE(public WebRtcPlayoutDataSource) { 240 NON_EXPORTED_BASE(public WebRtcPlayoutDataSource) {
275 public: 241 public:
276 // The maximum volume value WebRtc uses. 242 // The maximum volume value WebRtc uses.
277 static const int kMaxVolumeLevel = 255; 243 static const int kMaxVolumeLevel = 255;
278 244
279 // Instances of this object are created on the main render thread. 245 // Instances of this object are created on the main render thread.
280 WebRtcAudioDeviceImpl(); 246 WebRtcAudioDeviceImpl();
281 247
282 // webrtc::RefCountedModule implementation. 248 // webrtc::RefCountedModule implementation.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 } 322 }
357 323
358 private: 324 private:
359 typedef std::list<scoped_refptr<WebRtcAudioCapturer> > CapturerList; 325 typedef std::list<scoped_refptr<WebRtcAudioCapturer> > CapturerList;
360 typedef std::list<WebRtcPlayoutDataSource::Sink*> PlayoutDataSinkList; 326 typedef std::list<WebRtcPlayoutDataSource::Sink*> PlayoutDataSinkList;
361 class RenderBuffer; 327 class RenderBuffer;
362 328
363 // Make destructor private to ensure that we can only be deleted by Release(). 329 // Make destructor private to ensure that we can only be deleted by Release().
364 ~WebRtcAudioDeviceImpl() override; 330 ~WebRtcAudioDeviceImpl() override;
365 331
366 // PeerConnectionAudioSink implementation.
367
368 // Called on the AudioInputDevice worker thread.
369 int OnData(const int16* audio_data,
370 int sample_rate,
371 int number_of_channels,
372 int number_of_frames,
373 const std::vector<int>& channels,
374 int audio_delay_milliseconds,
375 int current_volume,
376 bool need_audio_processing,
377 bool key_pressed) override;
378
379 // Called on the AudioInputDevice worker thread.
380 void OnSetFormat(const media::AudioParameters& params) override;
381
382 // WebRtcAudioRendererSource implementation. 332 // WebRtcAudioRendererSource implementation.
383 333
384 // Called on the AudioOutputDevice worker thread. 334 // Called on the AudioOutputDevice worker thread.
385 void RenderData(media::AudioBus* audio_bus, 335 void RenderData(media::AudioBus* audio_bus,
386 int sample_rate, 336 int sample_rate,
387 int audio_delay_milliseconds, 337 int audio_delay_milliseconds,
388 base::TimeDelta* current_time) override; 338 base::TimeDelta* current_time) override;
389 339
390 // Called on the main render thread. 340 // Called on the main render thread.
391 void RemoveAudioRenderer(WebRtcAudioRenderer* renderer) override; 341 void RemoveAudioRenderer(WebRtcAudioRenderer* renderer) override;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 bool recording_; 388 bool recording_;
439 389
440 // Stores latest microphone volume received in a CaptureData() callback. 390 // Stores latest microphone volume received in a CaptureData() callback.
441 // Range is [0, 255]. 391 // Range is [0, 255].
442 uint32_t microphone_volume_; 392 uint32_t microphone_volume_;
443 393
444 // Buffer used for temporary storage during render callback. 394 // Buffer used for temporary storage during render callback.
445 // It is only accessed by the audio render thread. 395 // It is only accessed by the audio render thread.
446 std::vector<int16> render_buffer_; 396 std::vector<int16> render_buffer_;
447 397
448 // Flag to tell if audio processing is enabled in MediaStreamAudioProcessor.
449 const bool is_audio_track_processing_enabled_;
450
451 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioDeviceImpl); 398 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioDeviceImpl);
452 }; 399 };
453 400
454 } // namespace content 401 } // namespace content
455 402
456 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_ 403 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_
OLDNEW
« no previous file with comments | « content/renderer/media/webrtc_audio_capturer_unittest.cc ('k') | content/renderer/media/webrtc_audio_device_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698