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

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

Issue 11270012: Adding audio support to the new webmediaplyer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased and fixed some comments in rtc_audio_renderer.h Created 8 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 | 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_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 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop_proxy.h" 14 #include "base/message_loop_proxy.h"
15 #include "base/time.h" 15 #include "base/time.h"
16 #include "content/common/content_export.h" 16 #include "content/common/content_export.h"
17 #include "content/renderer/media/webrtc_audio_renderer.h"
17 #include "media/audio/audio_input_device.h" 18 #include "media/audio/audio_input_device.h"
18 #include "media/base/audio_renderer_sink.h" 19 #include "media/base/audio_renderer_sink.h"
19 #include "third_party/webrtc/modules/audio_device/include/audio_device.h" 20 #include "third_party/webrtc/modules/audio_device/include/audio_device.h"
20 21
21 // A WebRtcAudioDeviceImpl instance implements the abstract interface 22 // A WebRtcAudioDeviceImpl instance implements the abstract interface
22 // webrtc::AudioDeviceModule which makes it possible for a user (e.g. webrtc:: 23 // webrtc::AudioDeviceModule which makes it possible for a user (e.g. webrtc::
23 // VoiceEngine) to register this class as an external AudioDeviceModule (ADM). 24 // VoiceEngine) to register this class as an external AudioDeviceModule (ADM).
24 // Then WebRtcAudioDeviceImpl::SetSessionId() needs to be called to set the 25 // Then WebRtcAudioDeviceImpl::SetSessionId() needs to be called to set the
25 // session id that tells which device to use. The user can either get the 26 // session id that tells which device to use. The user can either get the
26 // session id from the MediaStream or use a value of 1 (AudioInputDeviceManager 27 // session id from the MediaStream or use a value of 1 (AudioInputDeviceManager
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 // - AGC is only supported in combination with the WASAPI-based audio layer 198 // - AGC is only supported in combination with the WASAPI-based audio layer
198 // on Windows, i.e., it is not supported on Windows XP. 199 // on Windows, i.e., it is not supported on Windows XP.
199 // - All volume levels required for the AGC scheme are transfered in a 200 // - All volume levels required for the AGC scheme are transfered in a
200 // normalized range [0.0, 1.0]. Scaling takes place in both endpoints 201 // normalized range [0.0, 1.0]. Scaling takes place in both endpoints
201 // (WebRTC client a media layer). This approach ensures that we can avoid 202 // (WebRTC client a media layer). This approach ensures that we can avoid
202 // transferring maximum levels between the renderer and the browser. 203 // transferring maximum levels between the renderer and the browser.
203 // 204 //
204 205
205 namespace content { 206 namespace content {
206 207
208 // TODO(xians): Move this interface to webrtc so that libjingle can own a
209 // reference to the renderer object.
210 class WebRtcAudioRendererSource {
211 public:
212 // Callback to get the rendered interleaved data.
213 virtual void RenderData(uint8* audio_data,
214 int number_of_channels,
215 int number_of_frames,
216 int audio_delay_milliseconds) = 0;
217
218 // Set the format for the capture audio parameters.
219 virtual void SetRenderFormat(const media::AudioParameters& params) = 0;
scherkus (not reviewing) 2012/10/25 17:47:39 fix indent
no longer working on chromium 2012/10/26 09:35:29 Done.
220
221 protected:
222 virtual ~WebRtcAudioRendererSource() {}
223 };
224
225 class WebRtcAudioRenderer;
226
207 class CONTENT_EXPORT WebRtcAudioDeviceImpl 227 class CONTENT_EXPORT WebRtcAudioDeviceImpl
208 : NON_EXPORTED_BASE(public webrtc::AudioDeviceModule), 228 : NON_EXPORTED_BASE(public webrtc::AudioDeviceModule),
209 NON_EXPORTED_BASE(public media::AudioRendererSink::RenderCallback),
210 NON_EXPORTED_BASE(public media::AudioInputDevice::CaptureCallback), 229 NON_EXPORTED_BASE(public media::AudioInputDevice::CaptureCallback),
211 NON_EXPORTED_BASE(public media::AudioInputDevice::CaptureEventHandler) { 230 NON_EXPORTED_BASE(public media::AudioInputDevice::CaptureEventHandler),
231 public WebRtcAudioRendererSource {
212 public: 232 public:
213 // Methods called on main render thread. 233 // Methods called on main render thread.
214 WebRtcAudioDeviceImpl(); 234 WebRtcAudioDeviceImpl();
215 235
216 // webrtc::RefCountedModule implementation. 236 // webrtc::RefCountedModule implementation.
217 // The creator must call AddRef() after construction and use Release() 237 // The creator must call AddRef() after construction and use Release()
218 // to release the reference and delete this object. 238 // to release the reference and delete this object.
219 virtual int32_t AddRef() OVERRIDE; 239 virtual int32_t AddRef() OVERRIDE;
220 virtual int32_t Release() OVERRIDE; 240 virtual int32_t Release() OVERRIDE;
221 241
222 // media::AudioRendererSink::RenderCallback implementation. 242 // WebRtcAudioRendererSource implementation.
223 virtual int Render(media::AudioBus* audio_bus, 243 virtual void RenderData(uint8* audio_data,
224 int audio_delay_milliseconds) OVERRIDE; 244 int number_of_channels,
225 virtual void OnRenderError() OVERRIDE; 245 int number_of_frames,
246 int audio_delay_milliseconds) OVERRIDE;
247 virtual void SetRenderFormat(const media::AudioParameters& params) OVERRIDE;
226 248
227 // AudioInputDevice::CaptureCallback implementation. 249 // AudioInputDevice::CaptureCallback implementation.
228 virtual void Capture(media::AudioBus* audio_bus, 250 virtual void Capture(media::AudioBus* audio_bus,
229 int audio_delay_milliseconds, 251 int audio_delay_milliseconds,
230 double volume) OVERRIDE; 252 double volume) OVERRIDE;
231 virtual void OnCaptureError() OVERRIDE; 253 virtual void OnCaptureError() OVERRIDE;
232 254
233 // AudioInputDevice::CaptureEventHandler implementation. 255 // AudioInputDevice::CaptureEventHandler implementation.
234 virtual void OnDeviceStarted(const std::string& device_id) OVERRIDE; 256 virtual void OnDeviceStarted(const std::string& device_id) OVERRIDE;
235 virtual void OnDeviceStopped() OVERRIDE; 257 virtual void OnDeviceStopped() OVERRIDE;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 virtual int32_t SetPlayoutSampleRate(const uint32_t samples_per_sec) OVERRIDE; 375 virtual int32_t SetPlayoutSampleRate(const uint32_t samples_per_sec) OVERRIDE;
354 virtual int32_t PlayoutSampleRate(uint32_t* samples_per_sec) const OVERRIDE; 376 virtual int32_t PlayoutSampleRate(uint32_t* samples_per_sec) const OVERRIDE;
355 377
356 virtual int32_t ResetAudioDevice() OVERRIDE; 378 virtual int32_t ResetAudioDevice() OVERRIDE;
357 virtual int32_t SetLoudspeakerStatus(bool enable) OVERRIDE; 379 virtual int32_t SetLoudspeakerStatus(bool enable) OVERRIDE;
358 virtual int32_t GetLoudspeakerStatus(bool* enabled) const OVERRIDE; 380 virtual int32_t GetLoudspeakerStatus(bool* enabled) const OVERRIDE;
359 381
360 // Sets the session id. 382 // Sets the session id.
361 void SetSessionId(int session_id); 383 void SetSessionId(int session_id);
362 384
385 // Sets the |renderer_|, returns false if |renderer_| has already existed.
386 bool SetRenderer(WebRtcAudioRenderer* renderer);
387
363 // Accessors. 388 // Accessors.
364 int input_buffer_size() const { 389 int input_buffer_size() const {
365 return input_audio_parameters_.frames_per_buffer(); 390 return input_audio_parameters_.frames_per_buffer();
366 } 391 }
367 int output_buffer_size() const { 392 int output_buffer_size() const {
368 return output_audio_parameters_.frames_per_buffer(); 393 return output_audio_parameters_.frames_per_buffer();
369 } 394 }
370 int input_channels() const { 395 int input_channels() const {
371 return input_audio_parameters_.channels(); 396 return input_audio_parameters_.channels();
372 } 397 }
(...skipping 21 matching lines...) Expand all
394 419
395 int ref_count_; 420 int ref_count_;
396 421
397 // Gives access to the message loop of the render thread on which this 422 // Gives access to the message loop of the render thread on which this
398 // object is created. 423 // object is created.
399 scoped_refptr<base::MessageLoopProxy> render_loop_; 424 scoped_refptr<base::MessageLoopProxy> render_loop_;
400 425
401 // Provides access to the native audio input layer in the browser process. 426 // Provides access to the native audio input layer in the browser process.
402 scoped_refptr<media::AudioInputDevice> audio_input_device_; 427 scoped_refptr<media::AudioInputDevice> audio_input_device_;
403 428
404 // Provides access to the native audio output layer in the browser process. 429 // Provides access to the audio renderer in the browser process.
405 scoped_refptr<media::AudioRendererSink> audio_output_device_; 430 scoped_refptr<WebRtcAudioRenderer> renderer_;
406 431
407 // Weak reference to the audio callback. 432 // Weak reference to the audio callback.
408 // The webrtc client defines |audio_transport_callback_| by calling 433 // The webrtc client defines |audio_transport_callback_| by calling
409 // RegisterAudioCallback(). 434 // RegisterAudioCallback().
410 webrtc::AudioTransport* audio_transport_callback_; 435 webrtc::AudioTransport* audio_transport_callback_;
411 436
412 // Cached values of utilized audio parameters. Platform dependent. 437 // Cached values of utilized audio parameters. Platform dependent.
413 media::AudioParameters input_audio_parameters_; 438 media::AudioParameters input_audio_parameters_;
414 media::AudioParameters output_audio_parameters_; 439 media::AudioParameters output_audio_parameters_;
415 440
416 // Cached value of the current audio delay on the input/capture side. 441 // Cached value of the current audio delay on the input/capture side.
417 int input_delay_ms_; 442 int input_delay_ms_;
418 443
419 // Cached value of the current audio delay on the output/renderer side. 444 // Cached value of the current audio delay on the output/renderer side.
420 int output_delay_ms_; 445 int output_delay_ms_;
421 446
422 // Buffers used for temporary storage during capture/render callbacks. 447 // Buffers used for temporary storage during capture/render callbacks.
423 // Allocated during initialization to save stack. 448 // Allocated during initialization to save stack.
424 scoped_array<int16> input_buffer_; 449 scoped_array<int16> input_buffer_;
425 scoped_array<int16> output_buffer_;
426 450
427 webrtc::AudioDeviceModule::ErrorCode last_error_; 451 webrtc::AudioDeviceModule::ErrorCode last_error_;
428 452
429 base::TimeTicks last_process_time_; 453 base::TimeTicks last_process_time_;
430 454
431 // Id of the media session to be started, it tells which device to be used 455 // Id of the media session to be started, it tells which device to be used
432 // on the input/capture side. 456 // on the input/capture side.
433 int session_id_; 457 int session_id_;
434 458
435 // Protects |recording_|, |output_delay_ms_|, |input_delay_ms_|. 459 // Protects |recording_|, |output_delay_ms_|, |input_delay_ms_|, |renderer_|.
436 mutable base::Lock lock_; 460 mutable base::Lock lock_;
437 461
438 int bytes_per_sample_; 462 int bytes_per_sample_;
439 463
440 bool initialized_; 464 bool initialized_;
441 bool playing_; 465 bool playing_;
442 bool recording_; 466 bool recording_;
443 467
444 // Local copy of the current Automatic Gain Control state. 468 // Local copy of the current Automatic Gain Control state.
445 bool agc_is_enabled_; 469 bool agc_is_enabled_;
446 470
447 // Used for histograms of total recording and playout times. 471 // Used for histograms of total recording and playout times.
448 base::Time start_capture_time_; 472 base::Time start_capture_time_;
449 base::Time start_render_time_; 473 base::Time start_render_time_;
450 474
451 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioDeviceImpl); 475 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioDeviceImpl);
452 }; 476 };
453 477
454 } // namespace content 478 } // namespace content
455 479
456 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_ 480 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698