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

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: added a lock to protect the |renderer_| 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 // Move this interface to WebRtc so that libjingle can own a reference of the
209 // object.
210 // TODO(xians): Move this interface to webrtc so that libjingle can own a
211 // reference to the capturer object.
wjia(left Chromium) 2012/10/24 22:05:15 repeating comments?
no longer working on chromium 2012/10/25 10:19:41 Done.
212 class WebRtcAudioRendererSource
213 : public base::RefCountedThreadSafe<WebRtcAudioRendererSource> {
214 public:
215 // Callback to get the rendered interleaved data.
wjia(left Chromium) 2012/10/24 22:05:15 indent.
no longer working on chromium 2012/10/25 10:19:41 Done.
216 virtual void RenderData(uint8* audio_data,
217 int number_of_channels,
218 int number_of_frames,
219 int audio_delay_milliseconds) = 0;
220
221 // Set the format for the capture audio parameters.
222 virtual void SetRenderFormat(media::AudioParameters params) = 0;
wjia(left Chromium) 2012/10/24 22:05:15 (const media::AudioParameters& params) ?
no longer working on chromium 2012/10/25 10:19:41 thanks, done.
223
224 protected:
225 friend class base::RefCountedThreadSafe<WebRtcAudioRendererSource>;
226 virtual ~WebRtcAudioRendererSource() {}
227 };
228
229 class WebRtcAudioRenderer;
230
207 class CONTENT_EXPORT WebRtcAudioDeviceImpl 231 class CONTENT_EXPORT WebRtcAudioDeviceImpl
208 : NON_EXPORTED_BASE(public webrtc::AudioDeviceModule), 232 : NON_EXPORTED_BASE(public webrtc::AudioDeviceModule),
209 NON_EXPORTED_BASE(public media::AudioRendererSink::RenderCallback),
210 NON_EXPORTED_BASE(public media::AudioInputDevice::CaptureCallback), 233 NON_EXPORTED_BASE(public media::AudioInputDevice::CaptureCallback),
211 NON_EXPORTED_BASE(public media::AudioInputDevice::CaptureEventHandler) { 234 NON_EXPORTED_BASE(public media::AudioInputDevice::CaptureEventHandler),
235 NON_EXPORTED_BASE(public WebRtcAudioRendererSource) {
212 public: 236 public:
213 // Methods called on main render thread. 237 // Methods called on main render thread.
214 WebRtcAudioDeviceImpl(); 238 WebRtcAudioDeviceImpl();
215 239
216 // webrtc::RefCountedModule implementation. 240 // webrtc::RefCountedModule implementation.
217 // The creator must call AddRef() after construction and use Release() 241 // The creator must call AddRef() after construction and use Release()
218 // to release the reference and delete this object. 242 // to release the reference and delete this object.
219 virtual int32_t AddRef() OVERRIDE; 243 virtual int32_t AddRef() OVERRIDE;
220 virtual int32_t Release() OVERRIDE; 244 virtual int32_t Release() OVERRIDE;
221 245
222 // media::AudioRendererSink::RenderCallback implementation. 246 // WebRtcAudioRendererSource implementation.
223 virtual int Render(media::AudioBus* audio_bus, 247 virtual void RenderData(uint8* audio_data,
224 int audio_delay_milliseconds) OVERRIDE; 248 int number_of_channels,
225 virtual void OnRenderError() OVERRIDE; 249 int number_of_frames,
250 int audio_delay_milliseconds) OVERRIDE;
251 virtual void SetRenderFormat(media::AudioParameters params) OVERRIDE;
wjia(left Chromium) 2012/10/24 22:05:15 ditto.
no longer working on chromium 2012/10/25 10:19:41 Done.
226 252
227 // AudioInputDevice::CaptureCallback implementation. 253 // AudioInputDevice::CaptureCallback implementation.
228 virtual void Capture(media::AudioBus* audio_bus, 254 virtual void Capture(media::AudioBus* audio_bus,
229 int audio_delay_milliseconds, 255 int audio_delay_milliseconds,
230 double volume) OVERRIDE; 256 double volume) OVERRIDE;
231 virtual void OnCaptureError() OVERRIDE; 257 virtual void OnCaptureError() OVERRIDE;
232 258
233 // AudioInputDevice::CaptureEventHandler implementation. 259 // AudioInputDevice::CaptureEventHandler implementation.
234 virtual void OnDeviceStarted(const std::string& device_id) OVERRIDE; 260 virtual void OnDeviceStarted(const std::string& device_id) OVERRIDE;
235 virtual void OnDeviceStopped() OVERRIDE; 261 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; 379 virtual int32_t SetPlayoutSampleRate(const uint32_t samples_per_sec) OVERRIDE;
354 virtual int32_t PlayoutSampleRate(uint32_t* samples_per_sec) const OVERRIDE; 380 virtual int32_t PlayoutSampleRate(uint32_t* samples_per_sec) const OVERRIDE;
355 381
356 virtual int32_t ResetAudioDevice() OVERRIDE; 382 virtual int32_t ResetAudioDevice() OVERRIDE;
357 virtual int32_t SetLoudspeakerStatus(bool enable) OVERRIDE; 383 virtual int32_t SetLoudspeakerStatus(bool enable) OVERRIDE;
358 virtual int32_t GetLoudspeakerStatus(bool* enabled) const OVERRIDE; 384 virtual int32_t GetLoudspeakerStatus(bool* enabled) const OVERRIDE;
359 385
360 // Sets the session id. 386 // Sets the session id.
361 void SetSessionId(int session_id); 387 void SetSessionId(int session_id);
362 388
389 // Sets the |renderer_|, this needs to be called before Initialize() or never.
390 void SetRenderer(WebRtcAudioRenderer* renderer);
391
363 // Accessors. 392 // Accessors.
364 int input_buffer_size() const { 393 int input_buffer_size() const {
365 return input_audio_parameters_.frames_per_buffer(); 394 return input_audio_parameters_.frames_per_buffer();
366 } 395 }
367 int output_buffer_size() const { 396 int output_buffer_size() const {
368 return output_audio_parameters_.frames_per_buffer(); 397 return output_audio_parameters_.frames_per_buffer();
369 } 398 }
370 int input_channels() const { 399 int input_channels() const {
371 return input_audio_parameters_.channels(); 400 return input_audio_parameters_.channels();
372 } 401 }
(...skipping 21 matching lines...) Expand all
394 423
395 int ref_count_; 424 int ref_count_;
396 425
397 // Gives access to the message loop of the render thread on which this 426 // Gives access to the message loop of the render thread on which this
398 // object is created. 427 // object is created.
399 scoped_refptr<base::MessageLoopProxy> render_loop_; 428 scoped_refptr<base::MessageLoopProxy> render_loop_;
400 429
401 // Provides access to the native audio input layer in the browser process. 430 // Provides access to the native audio input layer in the browser process.
402 scoped_refptr<media::AudioInputDevice> audio_input_device_; 431 scoped_refptr<media::AudioInputDevice> audio_input_device_;
403 432
404 // Provides access to the native audio output layer in the browser process. 433 // Provides access to the audio renderer in the browser process.
405 scoped_refptr<media::AudioRendererSink> audio_output_device_; 434 scoped_refptr<WebRtcAudioRenderer> renderer_;
406 435
407 // Weak reference to the audio callback. 436 // Weak reference to the audio callback.
408 // The webrtc client defines |audio_transport_callback_| by calling 437 // The webrtc client defines |audio_transport_callback_| by calling
409 // RegisterAudioCallback(). 438 // RegisterAudioCallback().
410 webrtc::AudioTransport* audio_transport_callback_; 439 webrtc::AudioTransport* audio_transport_callback_;
411 440
412 // Cached values of utilized audio parameters. Platform dependent. 441 // Cached values of utilized audio parameters. Platform dependent.
413 media::AudioParameters input_audio_parameters_; 442 media::AudioParameters input_audio_parameters_;
414 media::AudioParameters output_audio_parameters_; 443 media::AudioParameters output_audio_parameters_;
415 444
416 // Cached value of the current audio delay on the input/capture side. 445 // Cached value of the current audio delay on the input/capture side.
417 int input_delay_ms_; 446 int input_delay_ms_;
418 447
419 // Cached value of the current audio delay on the output/renderer side. 448 // Cached value of the current audio delay on the output/renderer side.
420 int output_delay_ms_; 449 int output_delay_ms_;
421 450
422 // Buffers used for temporary storage during capture/render callbacks. 451 // Buffers used for temporary storage during capture/render callbacks.
423 // Allocated during initialization to save stack. 452 // Allocated during initialization to save stack.
424 scoped_array<int16> input_buffer_; 453 scoped_array<int16> input_buffer_;
425 scoped_array<int16> output_buffer_;
426 454
427 webrtc::AudioDeviceModule::ErrorCode last_error_; 455 webrtc::AudioDeviceModule::ErrorCode last_error_;
428 456
429 base::TimeTicks last_process_time_; 457 base::TimeTicks last_process_time_;
430 458
431 // Id of the media session to be started, it tells which device to be used 459 // Id of the media session to be started, it tells which device to be used
432 // on the input/capture side. 460 // on the input/capture side.
433 int session_id_; 461 int session_id_;
434 462
435 // Protects |recording_|, |output_delay_ms_|, |input_delay_ms_|. 463 // Protects |recording_|, |output_delay_ms_|, |input_delay_ms_|, |renderer_|.
436 mutable base::Lock lock_; 464 mutable base::Lock lock_;
437 465
438 int bytes_per_sample_; 466 int bytes_per_sample_;
439 467
440 bool initialized_; 468 bool initialized_;
441 bool playing_; 469 bool playing_;
442 bool recording_; 470 bool recording_;
443 471
444 // Local copy of the current Automatic Gain Control state. 472 // Local copy of the current Automatic Gain Control state.
445 bool agc_is_enabled_; 473 bool agc_is_enabled_;
446 474
447 // Used for histograms of total recording and playout times. 475 // Used for histograms of total recording and playout times.
448 base::Time start_capture_time_; 476 base::Time start_capture_time_;
449 base::Time start_render_time_; 477 base::Time start_render_time_;
450 478
451 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioDeviceImpl); 479 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioDeviceImpl);
452 }; 480 };
453 481
454 } // namespace content 482 } // namespace content
455 483
456 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_ 484 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698