| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_ |
| 7 |
| 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/synchronization/lock.h" |
| 10 #include "media/audio/audio_parameters.h" |
| 11 #include "media/base/audio_capturer_source.h" |
| 12 #include "media/base/audio_fifo.h" |
| 13 #include "third_party/WebKit/Source/Platform/chromium/public/WebAudioDestination
Consumer.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
| 15 |
| 16 namespace content { |
| 17 |
| 18 class WebRtcAudioCapturer; |
| 19 |
| 20 // WebAudioCapturerSource is the missing link between |
| 21 // WebAudio's MediaStreamAudioDestinationNode and WebRtcAudioCapturer. |
| 22 // |
| 23 // 1. WebKit calls the setFormat() method setting up the basic stream format |
| 24 // (channels, and sample-rate). At this time, it dispatches this information |
| 25 // to the WebRtcAudioCapturer by calling its SetCapturerSource() method. |
| 26 // 2. Initialize() is called, where we should get back the same |
| 27 // stream format information as (1). We also get the CaptureCallback here. |
| 28 // 3. consumeAudio() is called periodically by WebKit which dispatches the |
| 29 // audio stream to the CaptureCallback::Capture() method. |
| 30 class WebAudioCapturerSource |
| 31 : public media::AudioCapturerSource, |
| 32 public WebKit::WebAudioDestinationConsumer { |
| 33 public: |
| 34 explicit WebAudioCapturerSource(WebRtcAudioCapturer* capturer); |
| 35 |
| 36 // WebAudioDestinationConsumer implementation. |
| 37 // setFormat() is called early on, so that we can configure the capturer. |
| 38 virtual void setFormat(size_t number_of_channels, float sample_rate) OVERRIDE; |
| 39 // MediaStreamAudioDestinationNode periodically calls consumeAudio(). |
| 40 virtual void consumeAudio(const WebKit::WebVector<const float*>& audio_data, |
| 41 size_t number_of_frames) OVERRIDE; |
| 42 |
| 43 // AudioCapturerSource implementation. |
| 44 virtual void Initialize( |
| 45 const media::AudioParameters& params, |
| 46 media::AudioCapturerSource::CaptureCallback* callback, |
| 47 media::AudioCapturerSource::CaptureEventHandler* event_handler) OVERRIDE; |
| 48 |
| 49 virtual void Start() OVERRIDE; |
| 50 virtual void Stop() OVERRIDE; |
| 51 virtual void SetVolume(double volume) OVERRIDE { } |
| 52 virtual void SetDevice(int session_id) OVERRIDE { } |
| 53 virtual void SetAutomaticGainControl(bool enable) OVERRIDE { } |
| 54 |
| 55 private: |
| 56 virtual ~WebAudioCapturerSource(); |
| 57 |
| 58 WebRtcAudioCapturer* capturer_; |
| 59 |
| 60 int set_format_channels_; |
| 61 media::AudioParameters params_; |
| 62 media::AudioCapturerSource::CaptureCallback* callback_; |
| 63 |
| 64 // Wraps data coming from HandleCapture(). |
| 65 scoped_ptr<media::AudioBus> wrapper_bus_; |
| 66 |
| 67 // Bus for reading from FIFO and calling the CaptureCallback. |
| 68 scoped_ptr<media::AudioBus> capture_bus_; |
| 69 |
| 70 // Handles mismatch between WebAudio buffer size and WebRTC. |
| 71 scoped_ptr<media::AudioFifo> fifo_; |
| 72 |
| 73 // Synchronizes HandleCapture() with AudioCapturerSource calls. |
| 74 base::Lock lock_; |
| 75 bool started_; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(WebAudioCapturerSource); |
| 78 }; |
| 79 |
| 80 } // namespace content |
| 81 |
| 82 #endif // CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_ |
| OLD | NEW |