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

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

Issue 139303016: Feed the render data to MediaStreamAudioProcessor and used AudioBus in render callback (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: checked echo_control_mobile()->is_enabled()) for android and ios Created 6 years, 10 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 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 178
179 namespace content { 179 namespace content {
180 180
181 class WebRtcAudioCapturer; 181 class WebRtcAudioCapturer;
182 class WebRtcAudioRenderer; 182 class WebRtcAudioRenderer;
183 183
184 // TODO(xians): Move the following two interfaces to webrtc so that 184 // TODO(xians): Move the following two interfaces to webrtc so that
185 // libjingle can own references to the renderer and capturer. 185 // libjingle can own references to the renderer and capturer.
186 class WebRtcAudioRendererSource { 186 class WebRtcAudioRendererSource {
187 public: 187 public:
188 // Callback to get the rendered interleaved data. 188 // Callback to get the rendered data.
189 // TODO(xians): Change uint8* to int16*. 189 virtual void RenderData(media::AudioBus* audio_bus,
190 virtual void RenderData(uint8* audio_data, 190 int sample_rate,
191 int number_of_channels,
192 int number_of_frames,
193 int audio_delay_milliseconds) = 0; 191 int audio_delay_milliseconds) = 0;
194 192
195 // Set the format for the capture audio parameters.
196 virtual void SetRenderFormat(const media::AudioParameters& params) = 0;
197
198 // Callback to notify the client that the renderer is going away. 193 // Callback to notify the client that the renderer is going away.
199 virtual void RemoveAudioRenderer(WebRtcAudioRenderer* renderer) = 0; 194 virtual void RemoveAudioRenderer(WebRtcAudioRenderer* renderer) = 0;
200 195
201 protected: 196 protected:
202 virtual ~WebRtcAudioRendererSource() {} 197 virtual ~WebRtcAudioRendererSource() {}
203 }; 198 };
204 199
205 class PeerConnectionAudioSink { 200 class PeerConnectionAudioSink {
206 public: 201 public:
207 // Callback to deliver the captured interleaved data. 202 // Callback to deliver the captured interleaved data.
(...skipping 20 matching lines...) Expand all
228 223
229 // Set the format for the capture audio parameters. 224 // Set the format for the capture audio parameters.
230 // This is called when the capture format has changed, and it must be called 225 // This is called when the capture format has changed, and it must be called
231 // on the same thread as calling CaptureData(). 226 // on the same thread as calling CaptureData().
232 virtual void OnSetFormat(const media::AudioParameters& params) = 0; 227 virtual void OnSetFormat(const media::AudioParameters& params) = 0;
233 228
234 protected: 229 protected:
235 virtual ~PeerConnectionAudioSink() {} 230 virtual ~PeerConnectionAudioSink() {}
236 }; 231 };
237 232
233 // TODO(xians): Merge this interface with WebRtcAudioRendererSource.
234 // The reason why we could not do it today is that WebRtcAudioRendererSource
235 // gets the data by pulling, while the data is pushed into
236 // WebRtcPlayoutDataSource::Sink.
237 class WebRtcPlayoutDataSource {
238 public:
239 class Sink {
240 public:
241 // Callback to get the playout data.
242 virtual void OnPlayoutData(media::AudioBus* audio_bus,
243 int sample_rate,
244 int audio_delay_milliseconds) = 0;
245 protected:
246 virtual ~Sink() {}
247 };
248
249 // Adds/Removes the sink of WebRtcAudioRendererSource to the ADM.
250 // These methods are used by the MediaStreamAudioProcesssor to get the
251 // rendered data for AEC.
252 virtual void AddPlayoutSink(Sink* sink) = 0;
253 virtual void RemovePlayoutSink(Sink* sink) = 0;
254
255 protected:
256 virtual ~WebRtcPlayoutDataSource() {}
257 };
258
238 // Note that this class inherits from webrtc::AudioDeviceModule but due to 259 // Note that this class inherits from webrtc::AudioDeviceModule but due to
239 // the high number of non-implemented methods, we move the cruft over to the 260 // the high number of non-implemented methods, we move the cruft over to the
240 // WebRtcAudioDeviceNotImpl. 261 // WebRtcAudioDeviceNotImpl.
241 class CONTENT_EXPORT WebRtcAudioDeviceImpl 262 class CONTENT_EXPORT WebRtcAudioDeviceImpl
242 : NON_EXPORTED_BASE(public PeerConnectionAudioSink), 263 : NON_EXPORTED_BASE(public PeerConnectionAudioSink),
243 NON_EXPORTED_BASE(public WebRtcAudioDeviceNotImpl), 264 NON_EXPORTED_BASE(public WebRtcAudioDeviceNotImpl),
244 NON_EXPORTED_BASE(public WebRtcAudioRendererSource) { 265 NON_EXPORTED_BASE(public WebRtcAudioRendererSource),
266 NON_EXPORTED_BASE(public WebRtcPlayoutDataSource) {
245 public: 267 public:
246 // The maximum volume value WebRtc uses. 268 // The maximum volume value WebRtc uses.
247 static const int kMaxVolumeLevel = 255; 269 static const int kMaxVolumeLevel = 255;
248 270
249 // Instances of this object are created on the main render thread. 271 // Instances of this object are created on the main render thread.
250 WebRtcAudioDeviceImpl(); 272 WebRtcAudioDeviceImpl();
251 273
252 // webrtc::RefCountedModule implementation. 274 // webrtc::RefCountedModule implementation.
253 // The creator must call AddRef() after construction and use Release() 275 // The creator must call AddRef() after construction and use Release()
254 // to release the reference and delete this object. 276 // to release the reference and delete this object.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 // Called on the main renderer thread. 321 // Called on the main renderer thread.
300 bool SetAudioRenderer(WebRtcAudioRenderer* renderer); 322 bool SetAudioRenderer(WebRtcAudioRenderer* renderer);
301 323
302 // Adds/Removes the capturer to the ADM. 324 // Adds/Removes the capturer to the ADM.
303 // TODO(xians): Remove these two methods once the ADM does not need to pass 325 // TODO(xians): Remove these two methods once the ADM does not need to pass
304 // hardware information up to WebRtc. 326 // hardware information up to WebRtc.
305 void AddAudioCapturer(const scoped_refptr<WebRtcAudioCapturer>& capturer); 327 void AddAudioCapturer(const scoped_refptr<WebRtcAudioCapturer>& capturer);
306 void RemoveAudioCapturer(const scoped_refptr<WebRtcAudioCapturer>& capturer); 328 void RemoveAudioCapturer(const scoped_refptr<WebRtcAudioCapturer>& capturer);
307 329
308 // Gets the default capturer, which is the last capturer in |capturers_|. 330 // Gets the default capturer, which is the last capturer in |capturers_|.
331 // The method can be called by both Libjingle thread and main render thread.
309 scoped_refptr<WebRtcAudioCapturer> GetDefaultCapturer() const; 332 scoped_refptr<WebRtcAudioCapturer> GetDefaultCapturer() const;
310 333
311 // Gets paired device information of the capture device for the audio 334 // Gets paired device information of the capture device for the audio
312 // renderer. This is used to pass on a session id, sample rate and buffer 335 // renderer. This is used to pass on a session id, sample rate and buffer
313 // size to a webrtc audio renderer (either local or remote), so that audio 336 // size to a webrtc audio renderer (either local or remote), so that audio
314 // will be rendered to a matching output device. 337 // will be rendered to a matching output device.
315 // Returns true if the capture device has a paired output device, otherwise 338 // Returns true if the capture device has a paired output device, otherwise
316 // false. Note that if there are more than one open capture device the 339 // false. Note that if there are more than one open capture device the
317 // function will not be able to pick an appropriate device and return false. 340 // function will not be able to pick an appropriate device and return false.
318 bool GetAuthorizedDeviceInfoForAudioRenderer( 341 bool GetAuthorizedDeviceInfoForAudioRenderer(
319 int* session_id, int* output_sample_rate, int* output_buffer_size); 342 int* session_id, int* output_sample_rate, int* output_buffer_size);
320 343
321 const scoped_refptr<WebRtcAudioRenderer>& renderer() const { 344 const scoped_refptr<WebRtcAudioRenderer>& renderer() const {
322 return renderer_; 345 return renderer_;
323 } 346 }
324 int output_buffer_size() const {
325 return output_audio_parameters_.frames_per_buffer();
326 }
327 int output_channels() const {
328 return output_audio_parameters_.channels();
329 }
330 int output_sample_rate() const {
331 return output_audio_parameters_.sample_rate();
332 }
333 347
334 private: 348 private:
335 typedef std::list<scoped_refptr<WebRtcAudioCapturer> > CapturerList; 349 typedef std::list<scoped_refptr<WebRtcAudioCapturer> > CapturerList;
350 typedef std::list<WebRtcPlayoutDataSource::Sink*> PlayoutDataSinkList;
351 class RenderBuffer;
336 352
337 // Make destructor private to ensure that we can only be deleted by Release(). 353 // Make destructor private to ensure that we can only be deleted by Release().
338 virtual ~WebRtcAudioDeviceImpl(); 354 virtual ~WebRtcAudioDeviceImpl();
339 355
340 // PeerConnectionAudioSink implementation. 356 // PeerConnectionAudioSink implementation.
341 357
342 // Called on the AudioInputDevice worker thread. 358 // Called on the AudioInputDevice worker thread.
343 virtual int OnData(const int16* audio_data, 359 virtual int OnData(const int16* audio_data,
344 int sample_rate, 360 int sample_rate,
345 int number_of_channels, 361 int number_of_channels,
346 int number_of_frames, 362 int number_of_frames,
347 const std::vector<int>& channels, 363 const std::vector<int>& channels,
348 int audio_delay_milliseconds, 364 int audio_delay_milliseconds,
349 int current_volume, 365 int current_volume,
350 bool need_audio_processing, 366 bool need_audio_processing,
351 bool key_pressed) OVERRIDE; 367 bool key_pressed) OVERRIDE;
352 368
353 // Called on the AudioInputDevice worker thread. 369 // Called on the AudioInputDevice worker thread.
354 virtual void OnSetFormat(const media::AudioParameters& params) OVERRIDE; 370 virtual void OnSetFormat(const media::AudioParameters& params) OVERRIDE;
355 371
356 // WebRtcAudioRendererSource implementation. 372 // WebRtcAudioRendererSource implementation.
357 373
358 // Called on the AudioInputDevice worker thread. 374 // Called on the AudioInputDevice worker thread.
359 virtual void RenderData(uint8* audio_data, 375 virtual void RenderData(media::AudioBus* audio_bus,
360 int number_of_channels, 376 int sample_rate,
361 int number_of_frames,
362 int audio_delay_milliseconds) OVERRIDE; 377 int audio_delay_milliseconds) OVERRIDE;
363 378
364 // Called on the main render thread. 379 // Called on the main render thread.
365 virtual void SetRenderFormat(const media::AudioParameters& params) OVERRIDE;
366 virtual void RemoveAudioRenderer(WebRtcAudioRenderer* renderer) OVERRIDE; 380 virtual void RemoveAudioRenderer(WebRtcAudioRenderer* renderer) OVERRIDE;
367 381
382 // WebRtcPlayoutDataSource implementation.
383 virtual void AddPlayoutSink(WebRtcPlayoutDataSource::Sink* sink) OVERRIDE;
384 virtual void RemovePlayoutSink(WebRtcPlayoutDataSource::Sink* sink) OVERRIDE;
385
368 // Used to DCHECK that we are called on the correct thread. 386 // Used to DCHECK that we are called on the correct thread.
369 base::ThreadChecker thread_checker_; 387 base::ThreadChecker thread_checker_;
370 388
371 int ref_count_; 389 int ref_count_;
372 390
373 // List of captures which provides access to the native audio input layer 391 // List of captures which provides access to the native audio input layer
374 // in the browser process. 392 // in the browser process.
375 CapturerList capturers_; 393 CapturerList capturers_;
376 394
377 // Provides access to the audio renderer in the browser process. 395 // Provides access to the audio renderer in the browser process.
378 scoped_refptr<WebRtcAudioRenderer> renderer_; 396 scoped_refptr<WebRtcAudioRenderer> renderer_;
379 397
398 // A list of raw pointer of WebRtcPlayoutDataSource::Sink objects which want
399 // to get the playout data, the sink need to call RemovePlayoutSink()
400 // before it goes away.
401 PlayoutDataSinkList playout_sinks_;
402
380 // Weak reference to the audio callback. 403 // Weak reference to the audio callback.
381 // The webrtc client defines |audio_transport_callback_| by calling 404 // The webrtc client defines |audio_transport_callback_| by calling
382 // RegisterAudioCallback(). 405 // RegisterAudioCallback().
383 webrtc::AudioTransport* audio_transport_callback_; 406 webrtc::AudioTransport* audio_transport_callback_;
384 407
385 // Cached values of used output audio parameters. Platform dependent.
386 media::AudioParameters output_audio_parameters_;
387
388 // Cached value of the current audio delay on the input/capture side. 408 // Cached value of the current audio delay on the input/capture side.
389 int input_delay_ms_; 409 int input_delay_ms_;
390 410
391 // Cached value of the current audio delay on the output/renderer side. 411 // Cached value of the current audio delay on the output/renderer side.
392 int output_delay_ms_; 412 int output_delay_ms_;
393 413
394 // Protects |recording_|, |output_delay_ms_|, |input_delay_ms_|, |renderer_| 414 // Protects |recording_|, |output_delay_ms_|, |input_delay_ms_|, |renderer_|
395 // |recording_| and |microphone_volume_|. 415 // |recording_| and |microphone_volume_|.
396 mutable base::Lock lock_; 416 mutable base::Lock lock_;
397 417
398 // Used to protect the racing of calling OnData() since there can be more 418 // Used to protect the racing of calling OnData() since there can be more
399 // than one input stream calling OnData(). 419 // than one input stream calling OnData().
400 mutable base::Lock capture_callback_lock_; 420 mutable base::Lock capture_callback_lock_;
401 421
402 bool initialized_; 422 bool initialized_;
403 bool playing_; 423 bool playing_;
404 bool recording_; 424 bool recording_;
405 425
406 // Used for histograms of total recording and playout times. 426 // Used for histograms of total recording and playout times.
407 base::Time start_capture_time_; 427 base::Time start_capture_time_;
408 base::Time start_render_time_; 428 base::Time start_render_time_;
409 429
410 // Stores latest microphone volume received in a CaptureData() callback. 430 // Stores latest microphone volume received in a CaptureData() callback.
411 // Range is [0, 255]. 431 // Range is [0, 255].
412 uint32_t microphone_volume_; 432 uint32_t microphone_volume_;
413 433
434 // Buffer used for temporary storage during render callback.
435 // It is only accessed by the audio render thread.
436 std::vector<int16> render_buffer_;
437
414 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioDeviceImpl); 438 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioDeviceImpl);
415 }; 439 };
416 440
417 } // namespace content 441 } // namespace content
418 442
419 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_ 443 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698