OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_SOURCE_PROVIDER_H_ | |
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_SOURCE_PROVIDER_H_ | |
7 | |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "base/synchronization/lock.h" | |
10 #include "base/threading/thread_checker.h" | |
11 #include "base/time/time.h" | |
12 #include "content/common/content_export.h" | |
13 #include "media/base/audio_converter.h" | |
14 #include "third_party/WebKit/public/platform/WebVector.h" | |
15 #include "third_party/WebKit/public/web/WebAudioSourceProvider.h" | |
16 | |
17 namespace media { | |
18 class AudioBus; | |
19 class AudioConverter; | |
20 class AudioFifo; | |
21 class AudioParameters; | |
22 } | |
23 | |
24 namespace WebKit { | |
25 class WebAudioSourceProviderClient; | |
26 } | |
27 | |
28 namespace content { | |
29 | |
30 // WebRtcLocalAudioSourceProvider provides a bridge between classes: | |
31 // WebRtcAudioCapturer ---> WebKit::WebAudioSourceProvider | |
32 // | |
33 // 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 // WebAudio as a source provider, WebAudio will periodically call | |
36 // provideInput() to get the data from the FIFO. | |
37 // | |
38 // All calls are protected by a lock. | |
39 class CONTENT_EXPORT WebRtcLocalAudioSourceProvider | |
40 : NON_EXPORTED_BASE(public media::AudioConverter::InputCallback), | |
41 NON_EXPORTED_BASE(public WebKit::WebAudioSourceProvider) { | |
42 public: | |
43 WebRtcLocalAudioSourceProvider(); | |
44 virtual ~WebRtcLocalAudioSourceProvider(); | |
45 | |
46 // Initialize function for the souce provider. This can be called multiple | |
47 // times if the source format has changed. | |
tommi (sloooow) - chröme
2013/09/12 11:02:16
Multiple times for the same source? what would be
no longer working on chromium
2013/09/12 19:14:56
For example, Initialize() can be called again when
| |
48 void Initialize(const media::AudioParameters& source_params); | |
49 | |
50 // Called by the WebRtcAudioCapturer to deliever captured data into fifo on | |
51 // the capture audio thread. | |
52 void DeliverData(media::AudioBus* audio_source, | |
53 int audio_delay_milliseconds, | |
54 int volume, | |
55 bool key_pressed); | |
56 | |
57 // Called by the WebAudioCapturerSource to get the audio processing params. | |
58 // This function is triggered by provideInput() on the WebAudio audio thread, | |
59 // so it has been under the protection of |lock_|. | |
60 void GetAudioProcessingParams(int* delay_ms, int* volume, bool* key_pressed); | |
61 | |
62 // WebKit::WebAudioSourceProvider implementation. | |
63 virtual void setClient(WebKit::WebAudioSourceProviderClient* client) OVERRIDE; | |
64 virtual void provideInput(const WebKit::WebVector<float*>& audio_data, | |
65 size_t number_of_frames) OVERRIDE; | |
66 | |
67 // media::AudioConverter::Inputcallback implementation. | |
68 // This function is triggered by provideInput()on the WebAudio audio thread, | |
69 // so it has been under the protection of |lock_|. | |
70 virtual double ProvideInput(media::AudioBus* audio_bus, | |
71 base::TimeDelta buffer_delay) OVERRIDE; | |
72 | |
73 // Method to allow the unittests to inject its own sink parameters to avoid | |
74 // query the hardware. | |
75 void SetSinkParamsForTesting(const media::AudioParameters& sink_params); | |
tommi (sloooow) - chröme
2013/09/12 11:02:16
Can you add:
TODO(xians,tommi): Remove and instead
no longer working on chromium
2013/09/12 19:14:56
Done.
I would love to inject a new interface to we
| |
76 | |
77 private: | |
78 // Used to DCHECK that we are called on the correct thread. | |
79 base::ThreadChecker thread_checker_; | |
80 | |
81 scoped_ptr<media::AudioConverter> audio_converter_; | |
82 scoped_ptr<media::AudioFifo> fifo_; | |
83 scoped_ptr<media::AudioBus> bus_wrapper_; | |
84 int audio_delay_ms_; | |
85 int volume_; | |
86 bool key_pressed_; | |
87 bool is_enabled_; | |
88 media::AudioParameters source_params_; | |
89 media::AudioParameters sink_params_; | |
90 | |
91 // Protects all the member variables above. | |
92 base::Lock lock_; | |
93 | |
94 // Used to report the correct delay to |webaudio_source_|. | |
95 base::TimeTicks last_fill_; | |
96 | |
97 DISALLOW_COPY_AND_ASSIGN(WebRtcLocalAudioSourceProvider); | |
98 }; | |
99 | |
100 } // namespace content | |
101 | |
102 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_SOURCE_PROVIDER_H_ | |
OLD | NEW |