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