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

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: fixed the bots. 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 // will be rendered to a matching output device. 333 // will be rendered to a matching output device.
312 // Returns true if the capture device has a paired output device, otherwise 334 // Returns true if the capture device has a paired output device, otherwise
313 // false. Note that if there are more than one open capture device the 335 // false. Note that if there are more than one open capture device the
314 // function will not be able to pick an appropriate device and return false. 336 // function will not be able to pick an appropriate device and return false.
315 bool GetAuthorizedDeviceInfoForAudioRenderer( 337 bool GetAuthorizedDeviceInfoForAudioRenderer(
316 int* session_id, int* output_sample_rate, int* output_buffer_size); 338 int* session_id, int* output_sample_rate, int* output_buffer_size);
317 339
318 const scoped_refptr<WebRtcAudioRenderer>& renderer() const { 340 const scoped_refptr<WebRtcAudioRenderer>& renderer() const {
319 return renderer_; 341 return renderer_;
320 } 342 }
321 int output_buffer_size() const {
322 return output_audio_parameters_.frames_per_buffer();
323 }
324 int output_channels() const {
325 return output_audio_parameters_.channels();
326 }
327 int output_sample_rate() const {
328 return output_audio_parameters_.sample_rate();
329 }
330 343
331 private: 344 private:
332 typedef std::list<scoped_refptr<WebRtcAudioCapturer> > CapturerList; 345 typedef std::list<scoped_refptr<WebRtcAudioCapturer> > CapturerList;
346 typedef std::list<WebRtcPlayoutDataSource::Sink*> PlayoutDataSinkList;
347 class RenderBuffer;
333 348
334 // Make destructor private to ensure that we can only be deleted by Release(). 349 // Make destructor private to ensure that we can only be deleted by Release().
335 virtual ~WebRtcAudioDeviceImpl(); 350 virtual ~WebRtcAudioDeviceImpl();
336 351
337 // PeerConnectionAudioSink implementation. 352 // PeerConnectionAudioSink implementation.
338 353
339 // Called on the AudioInputDevice worker thread. 354 // Called on the AudioInputDevice worker thread.
340 virtual int OnData(const int16* audio_data, 355 virtual int OnData(const int16* audio_data,
341 int sample_rate, 356 int sample_rate,
342 int number_of_channels, 357 int number_of_channels,
343 int number_of_frames, 358 int number_of_frames,
344 const std::vector<int>& channels, 359 const std::vector<int>& channels,
345 int audio_delay_milliseconds, 360 int audio_delay_milliseconds,
346 int current_volume, 361 int current_volume,
347 bool need_audio_processing, 362 bool need_audio_processing,
348 bool key_pressed) OVERRIDE; 363 bool key_pressed) OVERRIDE;
349 364
350 // Called on the AudioInputDevice worker thread. 365 // Called on the AudioInputDevice worker thread.
351 virtual void OnSetFormat(const media::AudioParameters& params) OVERRIDE; 366 virtual void OnSetFormat(const media::AudioParameters& params) OVERRIDE;
352 367
353 // WebRtcAudioRendererSource implementation. 368 // WebRtcAudioRendererSource implementation.
354 369
355 // Called on the AudioInputDevice worker thread. 370 // Called on the AudioInputDevice worker thread.
356 virtual void RenderData(uint8* audio_data, 371 virtual void RenderData(media::AudioBus* audio_bus,
357 int number_of_channels, 372 int sample_rate,
358 int number_of_frames,
359 int audio_delay_milliseconds) OVERRIDE; 373 int audio_delay_milliseconds) OVERRIDE;
360 374
361 // Called on the main render thread. 375 // Called on the main render thread.
362 virtual void SetRenderFormat(const media::AudioParameters& params) OVERRIDE;
363 virtual void RemoveAudioRenderer(WebRtcAudioRenderer* renderer) OVERRIDE; 376 virtual void RemoveAudioRenderer(WebRtcAudioRenderer* renderer) OVERRIDE;
364 377
378 // WebRtcPlayoutDataSource implementation.
379 virtual void AddPlayoutSink(WebRtcPlayoutDataSource::Sink* sink) OVERRIDE;
380 virtual void RemovePlayoutSink(WebRtcPlayoutDataSource::Sink* sink) OVERRIDE;
381
365 // Helper to get the default capturer, which is the last capturer in 382 // Helper to get the default capturer, which is the last capturer in
366 // |capturers_|. 383 // |capturers_|.
367 scoped_refptr<WebRtcAudioCapturer> GetDefaultCapturer() const; 384 scoped_refptr<WebRtcAudioCapturer> GetDefaultCapturer() const;
368 385
369 // Used to DCHECK that we are called on the correct thread. 386 // Used to DCHECK that we are called on the correct thread.
370 base::ThreadChecker thread_checker_; 387 base::ThreadChecker thread_checker_;
371 388
372 int ref_count_; 389 int ref_count_;
373 390
374 // 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
375 // in the browser process. 392 // in the browser process.
376 CapturerList capturers_; 393 CapturerList capturers_;
377 394
378 // Provides access to the audio renderer in the browser process. 395 // Provides access to the audio renderer in the browser process.
379 scoped_refptr<WebRtcAudioRenderer> renderer_; 396 scoped_refptr<WebRtcAudioRenderer> renderer_;
380 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
381 // Weak reference to the audio callback. 403 // Weak reference to the audio callback.
382 // The webrtc client defines |audio_transport_callback_| by calling 404 // The webrtc client defines |audio_transport_callback_| by calling
383 // RegisterAudioCallback(). 405 // RegisterAudioCallback().
384 webrtc::AudioTransport* audio_transport_callback_; 406 webrtc::AudioTransport* audio_transport_callback_;
385 407
386 // Cached values of used output audio parameters. Platform dependent.
387 media::AudioParameters output_audio_parameters_;
388
389 // 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.
390 int input_delay_ms_; 409 int input_delay_ms_;
391 410
392 // 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.
393 int output_delay_ms_; 412 int output_delay_ms_;
394 413
395 // Protects |recording_|, |output_delay_ms_|, |input_delay_ms_|, |renderer_| 414 // Protects |recording_|, |output_delay_ms_|, |input_delay_ms_|, |renderer_|
396 // |recording_| and |microphone_volume_|. 415 // |recording_| and |microphone_volume_|.
397 mutable base::Lock lock_; 416 mutable base::Lock lock_;
398 417
399 // 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
400 // than one input stream calling OnData(). 419 // than one input stream calling OnData().
401 mutable base::Lock capture_callback_lock_; 420 mutable base::Lock capture_callback_lock_;
402 421
403 bool initialized_; 422 bool initialized_;
404 bool playing_; 423 bool playing_;
405 bool recording_; 424 bool recording_;
406 425
407 // Used for histograms of total recording and playout times. 426 // Used for histograms of total recording and playout times.
408 base::Time start_capture_time_; 427 base::Time start_capture_time_;
409 base::Time start_render_time_; 428 base::Time start_render_time_;
410 429
411 // Stores latest microphone volume received in a CaptureData() callback. 430 // Stores latest microphone volume received in a CaptureData() callback.
412 // Range is [0, 255]. 431 // Range is [0, 255].
413 uint32_t microphone_volume_; 432 uint32_t microphone_volume_;
414 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
415 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioDeviceImpl); 438 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioDeviceImpl);
416 }; 439 };
417 440
418 } // namespace content 441 } // namespace content
419 442
420 #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