Chromium Code Reviews| Index: content/renderer/media/webrtc_local_audio_source_provider.h |
| diff --git a/content/renderer/media/webrtc_local_audio_source_provider.h b/content/renderer/media/webrtc_local_audio_source_provider.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2cea29e4f5ad0df62a6ce251617c0369b6e0f96c |
| --- /dev/null |
| +++ b/content/renderer/media/webrtc_local_audio_source_provider.h |
| @@ -0,0 +1,94 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_SOURCE_PROVIDER_H_ |
| +#define CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_SOURCE_PROVIDER_H_ |
| + |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/synchronization/lock.h" |
| +#include "base/threading/thread_checker.h" |
| +#include "base/time/time.h" |
| +#include "content/common/content_export.h" |
| +#include "media/base/audio_converter.h" |
| +#include "third_party/WebKit/public/platform/WebVector.h" |
| +#include "third_party/WebKit/public/web/WebAudioSourceProvider.h" |
| + |
| +namespace media { |
| +class AudioBus; |
| +class AudioConverter; |
| +class AudioFifo; |
| +class AudioParameters; |
| +} |
| + |
| +namespace WebKit { |
| +class WebAudioSourceProviderClient; |
| +} |
| + |
| +namespace content { |
| + |
| +// WebRtcLocalAudioSourceProvider provides a bridge between classes: |
| +// WebKit::WebAudioSourceProvider <---> WebRtcAudioCapturer |
|
tommi (sloooow) - chröme
2013/09/06 11:20:30
is the flow of data bidirectional or unidirectiona
no longer working on chromium
2013/09/10 12:43:15
It is one way, from WebRtcAudioCapturer to WebKit:
|
| +// |
| +// WebRtcLocalAudioSourceProvider works as a sink to the WebRtcAudiocapturer |
| +// and store the capture data to a FIFO. When the media stream is connected to |
| +// WebAudio as a source provider, WebAudio will periodically call |
| +// provideInput() to get the data from the FIFO. |
| +// |
| +// All calls are protected by a lock. |
| +class CONTENT_EXPORT WebRtcLocalAudioSourceProvider |
| + : NON_EXPORTED_BASE(public media::AudioConverter::InputCallback), |
|
tommi (sloooow) - chröme
2013/09/06 11:20:30
nit: public NON_EXPORTED_BASE(media::AudioConverte
no longer working on chromium
2013/09/10 12:43:15
Ignore as discussed offline.
|
| + NON_EXPORTED_BASE(public WebKit::WebAudioSourceProvider) { |
| + public: |
| + WebRtcLocalAudioSourceProvider(); |
| + ~WebRtcLocalAudioSourceProvider(); |
|
tommi (sloooow) - chröme
2013/09/06 11:20:30
virtual?
no longer working on chromium
2013/09/10 12:43:15
:) why not? Done.
|
| + |
| + // Initialize function for the souce provider. This can be called multiple |
| + // times if the source format has changed. |
| + void Initialize(const media::AudioParameters& source_params); |
| + |
| + // Called by the WebRtcAudioCapturer to deliever captured data into fifo. |
| + void DeliverData(media::AudioBus* audio_source, |
| + int audio_delay_milliseconds, |
| + int volume, |
| + bool key_pressed); |
| + |
| + // Called by the WebAudioCapturerSource to get the information of the stream. |
| + // This function is triggered by provideInput(), so it has been under the |
| + // protection of |lock_|. |
| + void GetStreamInfo(int* delay_ms, int* volume, bool* key_pressed); |
|
tommi (sloooow) - chröme
2013/09/06 11:20:30
Can we call this something to indicate audio proce
no longer working on chromium
2013/09/10 12:43:15
Done.
|
| + |
| + // WebKit::WebAudioSourceProvider implementation. |
| + virtual void setClient(WebKit::WebAudioSourceProviderClient* client) OVERRIDE; |
| + virtual void provideInput(const WebKit::WebVector<float*>& audio_data, |
| + size_t number_of_frames) OVERRIDE; |
| + |
| + // media::AudioConverter::Inputcallback implementation. |
| + // This function is triggered by provideInput(), so it has been under the |
| + // protection of |lock_|. |
| + virtual double ProvideInput(media::AudioBus* audio_bus, |
| + base::TimeDelta buffer_delay) OVERRIDE; |
| + |
| + private: |
| + // Used to DCHECK that we are called on the correct thread. |
| + base::ThreadChecker thread_checker_; |
| + |
| + scoped_ptr<media::AudioConverter> audio_converter_; |
| + scoped_ptr<media::AudioFifo> fifo_; |
| + scoped_ptr<media::AudioBus> bus_wrapper_; |
| + int audio_delay_ms_; |
| + int volume_; |
| + bool key_pressed_; |
| + bool is_enabled_; |
| + base::Lock lock_; |
|
tommi (sloooow) - chröme
2013/09/06 11:20:30
document what the lock is used to protect?
no longer working on chromium
2013/09/10 12:43:15
The lock is protecting all the member variables.
D
|
| + media::AudioParameters source_params_; |
| + |
| + // Used to report the correct delay to |webaudio_source_|. |
| + base::TimeTicks last_fill_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(WebRtcLocalAudioSourceProvider); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_SOURCE_PROVIDER_H_ |