Enable right clicking on the applist doodle web contents and log the data.
[chromium-blink-merge.git] / content / renderer / media / webaudio_capturer_source.h
blob5769c92edeaf00d2b5f1bf893ce87ee88b334886
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_
6 #define CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/synchronization/lock.h"
10 #include "base/threading/thread_checker.h"
11 #include "media/audio/audio_parameters.h"
12 #include "media/base/audio_capturer_source.h"
13 #include "media/base/audio_fifo.h"
14 #include "third_party/WebKit/public/platform/WebAudioDestinationConsumer.h"
15 #include "third_party/WebKit/public/platform/WebVector.h"
17 namespace content {
19 class WebRtcLocalAudioTrack;
21 // WebAudioCapturerSource is the missing link between
22 // WebAudio's MediaStreamAudioDestinationNode and WebRtcLocalAudioTrack.
24 // 1. WebKit calls the setFormat() method setting up the basic stream format
25 // (channels, and sample-rate).
26 // 2. consumeAudio() is called periodically by WebKit which dispatches the
27 // audio stream to the WebRtcLocalAudioTrack::Capture() method.
28 class WebAudioCapturerSource
29 : public base::RefCountedThreadSafe<WebAudioCapturerSource>,
30 public blink::WebAudioDestinationConsumer {
31 public:
32 WebAudioCapturerSource();
34 // WebAudioDestinationConsumer implementation.
35 // setFormat() is called early on, so that we can configure the audio track.
36 virtual void setFormat(size_t number_of_channels, float sample_rate) override;
37 // MediaStreamAudioDestinationNode periodically calls consumeAudio().
38 // Called on the WebAudio audio thread.
39 virtual void consumeAudio(const blink::WebVector<const float*>& audio_data,
40 size_t number_of_frames) override;
42 // Called when the WebAudioCapturerSource is hooking to a media audio track.
43 // |track| is the sink of the data flow. |source_provider| is the source of
44 // the data flow where stream information like delay, volume, key_pressed,
45 // is stored.
46 void Start(WebRtcLocalAudioTrack* track);
48 // Called when the media audio track is stopping.
49 void Stop();
51 protected:
52 friend class base::RefCountedThreadSafe<WebAudioCapturerSource>;
53 virtual ~WebAudioCapturerSource();
55 private:
56 // Used to DCHECK that some methods are called on the correct thread.
57 base::ThreadChecker thread_checker_;
59 // The audio track this WebAudioCapturerSource is feeding data to.
60 // WebRtcLocalAudioTrack is reference counted, and owning this object.
61 // To avoid circular reference, a raw pointer is kept here.
62 WebRtcLocalAudioTrack* track_;
64 media::AudioParameters params_;
66 // Flag to help notify the |track_| when the audio format has changed.
67 bool audio_format_changed_;
69 // Wraps data coming from HandleCapture().
70 scoped_ptr<media::AudioBus> wrapper_bus_;
72 // Bus for reading from FIFO and calling the CaptureCallback.
73 scoped_ptr<media::AudioBus> capture_bus_;
75 // Handles mismatch between WebAudio buffer size and WebRTC.
76 scoped_ptr<media::AudioFifo> fifo_;
78 // Synchronizes HandleCapture() with AudioCapturerSource calls.
79 base::Lock lock_;
80 bool started_;
82 DISALLOW_COPY_AND_ASSIGN(WebAudioCapturerSource);
85 } // namespace content
87 #endif // CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_