Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Side by Side Diff: content/renderer/media/webrtc_local_audio_source_provider.h

Issue 23691038: Switch LiveAudio to source provider solution. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed Tommi's comments and added unittest Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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.
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);
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 bool use_sink_params_for_testing_;
91
92 // Protects all the member variables above.
93 base::Lock lock_;
94
95 // Used to report the correct delay to |webaudio_source_|.
96 base::TimeTicks last_fill_;
97
98 DISALLOW_COPY_AND_ASSIGN(WebRtcLocalAudioSourceProvider);
99 };
100
101 } // namespace content
102
103 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_SOURCE_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698