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 "base/threading/thread_checker.h" | 10 #include "base/threading/thread_checker.h" |
11 #include "media/audio/audio_parameters.h" | 11 #include "media/audio/audio_parameters.h" |
12 #include "media/base/audio_capturer_source.h" | 12 #include "media/base/audio_capturer_source.h" |
13 #include "media/base/audio_fifo.h" | 13 #include "media/base/audio_fifo.h" |
14 #include "third_party/WebKit/public/platform/WebAudioDestinationConsumer.h" | 14 #include "third_party/WebKit/public/platform/WebAudioDestinationConsumer.h" |
15 #include "third_party/WebKit/public/platform/WebVector.h" | 15 #include "third_party/WebKit/public/platform/WebVector.h" |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 | 18 |
| 19 class WebRtcAudioCapturer; |
19 class WebRtcLocalAudioTrack; | 20 class WebRtcLocalAudioTrack; |
20 class WebRtcLocalAudioSourceProvider; | |
21 | 21 |
22 // WebAudioCapturerSource is the missing link between | 22 // WebAudioCapturerSource is the missing link between |
23 // WebAudio's MediaStreamAudioDestinationNode and WebRtcLocalAudioTrack. | 23 // WebAudio's MediaStreamAudioDestinationNode and WebRtcLocalAudioTrack. |
24 // | 24 // |
25 // 1. WebKit calls the setFormat() method setting up the basic stream format | 25 // 1. WebKit calls the setFormat() method setting up the basic stream format |
26 // (channels, and sample-rate). | 26 // (channels, and sample-rate). |
27 // 2. consumeAudio() is called periodically by WebKit which dispatches the | 27 // 2. consumeAudio() is called periodically by WebKit which dispatches the |
28 // audio stream to the WebRtcLocalAudioTrack::Capture() method. | 28 // audio stream to the WebRtcLocalAudioTrack::Capture() method. |
29 class WebAudioCapturerSource | 29 class WebAudioCapturerSource |
30 : public base::RefCountedThreadSafe<WebAudioCapturerSource>, | 30 : public base::RefCountedThreadSafe<WebAudioCapturerSource>, |
31 public WebKit::WebAudioDestinationConsumer { | 31 public WebKit::WebAudioDestinationConsumer { |
32 public: | 32 public: |
33 WebAudioCapturerSource(); | 33 WebAudioCapturerSource(); |
34 | 34 |
35 // WebAudioDestinationConsumer implementation. | 35 // WebAudioDestinationConsumer implementation. |
36 // setFormat() is called early on, so that we can configure the audio track. | 36 // setFormat() is called early on, so that we can configure the audio track. |
37 virtual void setFormat(size_t number_of_channels, float sample_rate) OVERRIDE; | 37 virtual void setFormat(size_t number_of_channels, float sample_rate) OVERRIDE; |
38 // MediaStreamAudioDestinationNode periodically calls consumeAudio(). | 38 // MediaStreamAudioDestinationNode periodically calls consumeAudio(). |
39 // Called on the WebAudio audio thread. | 39 // Called on the WebAudio audio thread. |
40 virtual void consumeAudio(const WebKit::WebVector<const float*>& audio_data, | 40 virtual void consumeAudio(const WebKit::WebVector<const float*>& audio_data, |
41 size_t number_of_frames) OVERRIDE; | 41 size_t number_of_frames) OVERRIDE; |
42 | 42 |
43 // Called when the WebAudioCapturerSource is hooking to a media audio track. | 43 // Called when the WebAudioCapturerSource is hooking to a media audio track. |
44 // |track| is the sink of the data flow. |source_provider| is the source of | 44 // |track| is the sink of the data flow. |source_provider| is the source of |
45 // the data flow where stream information like delay, volume, key_pressed, | 45 // the data flow where stream information like delay, volume, key_pressed, |
46 // is stored. | 46 // is stored. |
47 void Start(WebRtcLocalAudioTrack* track, | 47 void Start(WebRtcLocalAudioTrack* track, WebRtcAudioCapturer* capturer); |
48 WebRtcLocalAudioSourceProvider* source_provider); | |
49 | 48 |
50 // Called when the media audio track is stopping. | 49 // Called when the media audio track is stopping. |
51 void Stop(); | 50 void Stop(); |
52 | 51 |
53 protected: | 52 protected: |
54 friend class base::RefCountedThreadSafe<WebAudioCapturerSource>; | 53 friend class base::RefCountedThreadSafe<WebAudioCapturerSource>; |
55 virtual ~WebAudioCapturerSource(); | 54 virtual ~WebAudioCapturerSource(); |
56 | 55 |
57 private: | 56 private: |
58 // Used to DCHECK that some methods are called on the correct thread. | 57 // Used to DCHECK that some methods are called on the correct thread. |
59 base::ThreadChecker thread_checker_; | 58 base::ThreadChecker thread_checker_; |
60 | 59 |
61 // The audio track this WebAudioCapturerSource is feeding data to. | 60 // The audio track this WebAudioCapturerSource is feeding data to. |
62 // WebRtcLocalAudioTrack is reference counted, and owning this object. | 61 // WebRtcLocalAudioTrack is reference counted, and owning this object. |
63 // To avoid circular reference, a raw pointer is kept here. | 62 // To avoid circular reference, a raw pointer is kept here. |
64 WebRtcLocalAudioTrack* track_; | 63 WebRtcLocalAudioTrack* track_; |
65 | 64 |
66 // A raw pointer to the source provider to get audio processing params like | 65 // A raw pointer to the capturer to get audio processing params like |
67 // delay, volume, key_pressed information. | 66 // delay, volume, key_pressed information. |
68 // This |source_provider_| is guaranteed to outlive this object. | 67 // This |capturer_| is guaranteed to outlive this object. |
69 WebRtcLocalAudioSourceProvider* source_provider_; | 68 WebRtcAudioCapturer* capturer_; |
70 | 69 |
71 media::AudioParameters params_; | 70 media::AudioParameters params_; |
72 | 71 |
73 // Wraps data coming from HandleCapture(). | 72 // Wraps data coming from HandleCapture(). |
74 scoped_ptr<media::AudioBus> wrapper_bus_; | 73 scoped_ptr<media::AudioBus> wrapper_bus_; |
75 | 74 |
76 // Bus for reading from FIFO and calling the CaptureCallback. | 75 // Bus for reading from FIFO and calling the CaptureCallback. |
77 scoped_ptr<media::AudioBus> capture_bus_; | 76 scoped_ptr<media::AudioBus> capture_bus_; |
78 | 77 |
79 // Handles mismatch between WebAudio buffer size and WebRTC. | 78 // Handles mismatch between WebAudio buffer size and WebRTC. |
80 scoped_ptr<media::AudioFifo> fifo_; | 79 scoped_ptr<media::AudioFifo> fifo_; |
81 | 80 |
82 // Synchronizes HandleCapture() with AudioCapturerSource calls. | 81 // Synchronizes HandleCapture() with AudioCapturerSource calls. |
83 base::Lock lock_; | 82 base::Lock lock_; |
84 bool started_; | 83 bool started_; |
85 | 84 |
86 DISALLOW_COPY_AND_ASSIGN(WebAudioCapturerSource); | 85 DISALLOW_COPY_AND_ASSIGN(WebAudioCapturerSource); |
87 }; | 86 }; |
88 | 87 |
89 } // namespace content | 88 } // namespace content |
90 | 89 |
91 #endif // CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_ | 90 #endif // CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_ |
OLD | NEW |