OLD | NEW |
---|---|
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_WEBAUDIO_CAPTURER_SOURCE_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_ |
6 #define CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
10 #include "media/audio/audio_parameters.h" | 10 #include "media/audio/audio_parameters.h" |
11 #include "media/base/audio_capturer_source.h" | |
12 #include "media/base/audio_fifo.h" | 11 #include "media/base/audio_fifo.h" |
13 #include "third_party/WebKit/public/platform/WebAudioDestinationConsumer.h" | 12 #include "third_party/WebKit/public/platform/WebAudioDestinationConsumer.h" |
14 #include "third_party/WebKit/public/platform/WebVector.h" | 13 #include "third_party/WebKit/public/platform/WebVector.h" |
15 | 14 |
16 namespace content { | 15 namespace content { |
17 | 16 |
18 class WebRtcAudioCapturer; | 17 class WebRtcLocalAudioTrack; |
18 class WebRtcLocalAudioSourceProvider; | |
19 | 19 |
20 // WebAudioCapturerSource is the missing link between | 20 // WebAudioCapturerSource is the missing link between |
21 // WebAudio's MediaStreamAudioDestinationNode and WebRtcAudioCapturer. | 21 // WebAudio's MediaStreamAudioDestinationNode and WebRtcLocalAudioTrack. |
22 // | 22 // |
23 // 1. WebKit calls the setFormat() method setting up the basic stream format | 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 | 24 // (channels, and sample-rate). At this time, it dispatches this information |
25 // to the WebRtcAudioCapturer by calling its SetCapturerSource() method. | 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 | 26 // 3. consumeAudio() is called periodically by WebKit which dispatches the |
29 // audio stream to the CaptureCallback::Capture() method. | 27 // audio stream to the CaptureCallback::Capture() method. |
30 class WebAudioCapturerSource | 28 class WebAudioCapturerSource |
31 : public media::AudioCapturerSource, | 29 : public base::RefCountedThreadSafe<WebAudioCapturerSource>, |
32 public WebKit::WebAudioDestinationConsumer { | 30 public WebKit::WebAudioDestinationConsumer { |
33 public: | 31 public: |
34 explicit WebAudioCapturerSource(WebRtcAudioCapturer* capturer); | 32 WebAudioCapturerSource(); |
35 | 33 |
36 // WebAudioDestinationConsumer implementation. | 34 // WebAudioDestinationConsumer implementation. |
37 // setFormat() is called early on, so that we can configure the capturer. | 35 // 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; | 36 virtual void setFormat(size_t number_of_channels, float sample_rate) OVERRIDE; |
39 // MediaStreamAudioDestinationNode periodically calls consumeAudio(). | 37 // MediaStreamAudioDestinationNode periodically calls consumeAudio(). |
40 virtual void consumeAudio(const WebKit::WebVector<const float*>& audio_data, | 38 virtual void consumeAudio(const WebKit::WebVector<const float*>& audio_data, |
41 size_t number_of_frames) OVERRIDE; | 39 size_t number_of_frames) OVERRIDE; |
42 | 40 |
43 // AudioCapturerSource implementation. | 41 // Called when the WebAudioCapturerSource is hooking to a media audio track. |
44 virtual void Initialize( | 42 void Start(WebRtcLocalAudioTrack* track, |
tommi (sloooow) - chröme
2013/09/06 11:20:30
can you add documentation about the parameters and
no longer working on chromium
2013/09/10 12:43:15
Done.
| |
45 const media::AudioParameters& params, | 43 WebRtcLocalAudioSourceProvider* source_provider); |
46 media::AudioCapturerSource::CaptureCallback* callback, | |
47 int session_id) OVERRIDE; | |
48 | 44 |
49 virtual void Start() OVERRIDE; | 45 // Called when the media audio track is stopping. |
50 virtual void Stop() OVERRIDE; | 46 void Stop(); |
51 virtual void SetVolume(double volume) OVERRIDE { } | 47 |
52 virtual void SetAutomaticGainControl(bool enable) OVERRIDE { } | 48 protected: |
49 friend class base::RefCountedThreadSafe<WebAudioCapturerSource>; | |
tommi (sloooow) - chröme
2013/09/06 11:20:30
indent seems off
no longer working on chromium
2013/09/10 12:43:15
Done.
| |
50 virtual ~WebAudioCapturerSource(); | |
53 | 51 |
54 private: | 52 private: |
55 virtual ~WebAudioCapturerSource(); | 53 // a weak pointer to the audio track this WebAudioCapturerSource is feeding |
tommi (sloooow) - chröme
2013/09/06 11:20:30
this isn't a weak pointer, it's a raw pointer. "we
no longer working on chromium
2013/09/10 12:43:15
Done.
| |
54 // data to. | |
55 WebRtcLocalAudioTrack* track_; | |
56 | 56 |
57 WebRtcAudioCapturer* capturer_; | 57 // A weak pointer to the source provider to get the delay, volume, |
58 // key_pressed information. | |
59 WebRtcLocalAudioSourceProvider* source_provider_; | |
tommi (sloooow) - chröme
2013/09/06 11:20:30
this is also a raw pointer. please add comments t
no longer working on chromium
2013/09/10 12:43:15
Done.
| |
58 | 60 |
59 int set_format_channels_; | |
60 media::AudioParameters params_; | 61 media::AudioParameters params_; |
61 media::AudioCapturerSource::CaptureCallback* callback_; | |
62 | 62 |
63 // Wraps data coming from HandleCapture(). | 63 // Wraps data coming from HandleCapture(). |
64 scoped_ptr<media::AudioBus> wrapper_bus_; | 64 scoped_ptr<media::AudioBus> wrapper_bus_; |
65 | 65 |
66 // Bus for reading from FIFO and calling the CaptureCallback. | 66 // Bus for reading from FIFO and calling the CaptureCallback. |
67 scoped_ptr<media::AudioBus> capture_bus_; | 67 scoped_ptr<media::AudioBus> capture_bus_; |
68 | 68 |
69 // Handles mismatch between WebAudio buffer size and WebRTC. | 69 // Handles mismatch between WebAudio buffer size and WebRTC. |
70 scoped_ptr<media::AudioFifo> fifo_; | 70 scoped_ptr<media::AudioFifo> fifo_; |
71 | 71 |
72 // Synchronizes HandleCapture() with AudioCapturerSource calls. | 72 // Synchronizes HandleCapture() with AudioCapturerSource calls. |
73 base::Lock lock_; | 73 base::Lock lock_; |
74 bool started_; | 74 bool started_; |
75 | 75 |
76 DISALLOW_COPY_AND_ASSIGN(WebAudioCapturerSource); | 76 DISALLOW_COPY_AND_ASSIGN(WebAudioCapturerSource); |
77 }; | 77 }; |
78 | 78 |
79 } // namespace content | 79 } // namespace content |
80 | 80 |
81 #endif // CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_ | 81 #endif // CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_ |
OLD | NEW |