| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_LOCAL_AUDIO_SOURCE_PROVIDER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_SOURCE_PROVIDER_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_SOURCE_PROVIDER_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_SOURCE_PROVIDER_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.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 "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
| 13 #include "content/renderer/media/webrtc_audio_device_impl.h" |
| 13 #include "media/base/audio_converter.h" | 14 #include "media/base/audio_converter.h" |
| 14 #include "third_party/WebKit/public/platform/WebAudioSourceProvider.h" | 15 #include "third_party/WebKit/public/platform/WebAudioSourceProvider.h" |
| 15 #include "third_party/WebKit/public/platform/WebVector.h" | 16 #include "third_party/WebKit/public/platform/WebVector.h" |
| 16 | 17 |
| 17 namespace media { | 18 namespace media { |
| 18 class AudioBus; | 19 class AudioBus; |
| 19 class AudioConverter; | 20 class AudioConverter; |
| 20 class AudioFifo; | 21 class AudioFifo; |
| 21 class AudioParameters; | 22 class AudioParameters; |
| 22 } | 23 } |
| 23 | 24 |
| 24 namespace WebKit { | 25 namespace WebKit { |
| 25 class WebAudioSourceProviderClient; | 26 class WebAudioSourceProviderClient; |
| 26 } | 27 } |
| 27 | 28 |
| 28 namespace content { | 29 namespace content { |
| 29 | 30 |
| 30 // WebRtcLocalAudioSourceProvider provides a bridge between classes: | 31 // WebRtcLocalAudioSourceProvider provides a bridge between classes: |
| 31 // WebRtcAudioCapturer ---> WebKit::WebAudioSourceProvider | 32 // WebRtcAudioCapturer ---> WebKit::WebAudioSourceProvider |
| 32 // | 33 // |
| 33 // WebRtcLocalAudioSourceProvider works as a sink to the WebRtcAudiocapturer | 34 // WebRtcLocalAudioSourceProvider works as a sink to the WebRtcAudiocapturer |
| 34 // and store the capture data to a FIFO. When the media stream is connected to | 35 // and store the capture data to a FIFO. When the media stream is connected to |
| 35 // WebAudio as a source provider, WebAudio will periodically call | 36 // WebAudio as a source provider, WebAudio will periodically call |
| 36 // provideInput() to get the data from the FIFO. | 37 // provideInput() to get the data from the FIFO. |
| 37 // | 38 // |
| 38 // All calls are protected by a lock. | 39 // All calls are protected by a lock. |
| 39 class CONTENT_EXPORT WebRtcLocalAudioSourceProvider | 40 class CONTENT_EXPORT WebRtcLocalAudioSourceProvider |
| 40 : NON_EXPORTED_BASE(public media::AudioConverter::InputCallback), | 41 : NON_EXPORTED_BASE(public media::AudioConverter::InputCallback), |
| 41 NON_EXPORTED_BASE(public WebKit::WebAudioSourceProvider) { | 42 NON_EXPORTED_BASE(public WebKit::WebAudioSourceProvider), |
| 43 NON_EXPORTED_BASE(public WebRtcAudioCapturerSink) { |
| 42 public: | 44 public: |
| 43 static const size_t kWebAudioRenderBufferSize; | 45 static const size_t kWebAudioRenderBufferSize; |
| 44 | 46 |
| 45 WebRtcLocalAudioSourceProvider(); | 47 WebRtcLocalAudioSourceProvider(); |
| 46 virtual ~WebRtcLocalAudioSourceProvider(); | 48 virtual ~WebRtcLocalAudioSourceProvider(); |
| 47 | 49 |
| 48 // Initialize function for the souce provider. This can be called multiple | 50 // WebRtcAudioCapturerSink implementation. |
| 49 // times if the source format has changed. | 51 virtual int CaptureData(const std::vector<int>& channels, |
| 50 void Initialize(const media::AudioParameters& source_params); | 52 const int16* audio_data, |
| 53 int sample_rate, |
| 54 int number_of_channels, |
| 55 int number_of_frames, |
| 56 int audio_delay_milliseconds, |
| 57 int current_volume, |
| 58 bool need_audio_processing, |
| 59 bool key_pressed) OVERRIDE; |
| 51 | 60 |
| 52 // Called by the WebRtcAudioCapturer to deliever captured data into fifo on | 61 virtual void SetCaptureFormat(const media::AudioParameters& params) OVERRIDE; |
| 53 // the capture audio thread. | |
| 54 void DeliverData(media::AudioBus* audio_source, | |
| 55 int audio_delay_milliseconds, | |
| 56 int volume, | |
| 57 bool key_pressed); | |
| 58 | |
| 59 // Called by the WebAudioCapturerSource to get the audio processing params. | |
| 60 // This function is triggered by provideInput() on the WebAudio audio thread, | |
| 61 // so it has been under the protection of |lock_|. | |
| 62 void GetAudioProcessingParams(int* delay_ms, int* volume, bool* key_pressed); | |
| 63 | 62 |
| 64 // WebKit::WebAudioSourceProvider implementation. | 63 // WebKit::WebAudioSourceProvider implementation. |
| 65 virtual void setClient(WebKit::WebAudioSourceProviderClient* client) OVERRIDE; | 64 virtual void setClient(WebKit::WebAudioSourceProviderClient* client) OVERRIDE; |
| 66 virtual void provideInput(const WebKit::WebVector<float*>& audio_data, | 65 virtual void provideInput(const WebKit::WebVector<float*>& audio_data, |
| 67 size_t number_of_frames) OVERRIDE; | 66 size_t number_of_frames) OVERRIDE; |
| 68 | 67 |
| 69 // media::AudioConverter::Inputcallback implementation. | 68 // media::AudioConverter::Inputcallback implementation. |
| 70 // This function is triggered by provideInput()on the WebAudio audio thread, | 69 // This function is triggered by provideInput()on the WebAudio audio thread, |
| 71 // so it has been under the protection of |lock_|. | 70 // so it has been under the protection of |lock_|. |
| 72 virtual double ProvideInput(media::AudioBus* audio_bus, | 71 virtual double ProvideInput(media::AudioBus* audio_bus, |
| 73 base::TimeDelta buffer_delay) OVERRIDE; | 72 base::TimeDelta buffer_delay) OVERRIDE; |
| 74 | 73 |
| 75 // Method to allow the unittests to inject its own sink parameters to avoid | 74 // Method to allow the unittests to inject its own sink parameters to avoid |
| 76 // query the hardware. | 75 // query the hardware. |
| 77 // TODO(xians,tommi): Remove and instead offer a way to inject the sink | 76 // TODO(xians,tommi): Remove and instead offer a way to inject the sink |
| 78 // parameters so that the implementation doesn't rely on the global default | 77 // parameters so that the implementation doesn't rely on the global default |
| 79 // hardware config but instead gets the parameters directly from the sink | 78 // hardware config but instead gets the parameters directly from the sink |
| 80 // (WebAudio in this case). Ideally the unit test should be able to use that | 79 // (WebAudio in this case). Ideally the unit test should be able to use that |
| 81 // same mechanism to inject the sink parameters for testing. | 80 // same mechanism to inject the sink parameters for testing. |
| 82 void SetSinkParamsForTesting(const media::AudioParameters& sink_params); | 81 void SetSinkParamsForTesting(const media::AudioParameters& sink_params); |
| 83 | 82 |
| 84 private: | 83 private: |
| 85 // Used to DCHECK that we are called on the correct thread. | 84 // Used to DCHECK that we are called on the correct thread. |
| 86 base::ThreadChecker thread_checker_; | 85 base::ThreadChecker thread_checker_; |
| 87 | 86 |
| 88 scoped_ptr<media::AudioConverter> audio_converter_; | 87 scoped_ptr<media::AudioConverter> audio_converter_; |
| 89 scoped_ptr<media::AudioFifo> fifo_; | 88 scoped_ptr<media::AudioFifo> fifo_; |
| 90 scoped_ptr<media::AudioBus> bus_wrapper_; | 89 scoped_ptr<media::AudioBus> input_wrapper_; |
| 91 int audio_delay_ms_; | 90 scoped_ptr<media::AudioBus> output_wrapper_; |
| 92 int volume_; | |
| 93 bool key_pressed_; | |
| 94 bool is_enabled_; | 91 bool is_enabled_; |
| 95 media::AudioParameters source_params_; | 92 media::AudioParameters source_params_; |
| 96 media::AudioParameters sink_params_; | 93 media::AudioParameters sink_params_; |
| 97 | 94 |
| 98 // Protects all the member variables above. | 95 // Protects all the member variables above. |
| 99 base::Lock lock_; | 96 base::Lock lock_; |
| 100 | 97 |
| 101 // Used to report the correct delay to |webaudio_source_|. | 98 // Used to report the correct delay to |webaudio_source_|. |
| 102 base::TimeTicks last_fill_; | 99 base::TimeTicks last_fill_; |
| 103 | 100 |
| 104 DISALLOW_COPY_AND_ASSIGN(WebRtcLocalAudioSourceProvider); | 101 DISALLOW_COPY_AND_ASSIGN(WebRtcLocalAudioSourceProvider); |
| 105 }; | 102 }; |
| 106 | 103 |
| 107 } // namespace content | 104 } // namespace content |
| 108 | 105 |
| 109 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_SOURCE_PROVIDER_H_ | 106 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_SOURCE_PROVIDER_H_ |
| OLD | NEW |