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

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

Issue 1834323002: MediaStream audio: Refactor 3 separate "glue" implementations into one. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: REBASE + Workaround to ensure MediaStreamAudioProcessor is destroyed on the main thread. Created 4 years, 7 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
OLDNEW
(Empty)
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.
4
5 #ifndef CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_
6 #define CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_
7
8 #include <stddef.h>
9
10 #include "base/macros.h"
11 #include "base/synchronization/lock.h"
12 #include "base/threading/thread_checker.h"
13 #include "base/time/time.h"
14 #include "media/base/audio_bus.h"
15 #include "media/base/audio_capturer_source.h"
16 #include "media/base/audio_parameters.h"
17 #include "media/base/audio_push_fifo.h"
18 #include "third_party/WebKit/public/platform/WebAudioDestinationConsumer.h"
19 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
20 #include "third_party/WebKit/public/platform/WebVector.h"
21
22 namespace content {
23
24 class WebRtcLocalAudioTrack;
25
26 // WebAudioCapturerSource is the missing link between
27 // WebAudio's MediaStreamAudioDestinationNode and WebRtcLocalAudioTrack.
28 //
29 // 1. WebKit calls the setFormat() method setting up the basic stream format
30 // (channels, and sample-rate).
31 // 2. consumeAudio() is called periodically by WebKit which dispatches the
32 // audio stream to the WebRtcLocalAudioTrack::Capture() method.
33 class WebAudioCapturerSource : public blink::WebAudioDestinationConsumer {
34 public:
35 explicit WebAudioCapturerSource(blink::WebMediaStreamSource* blink_source);
36
37 ~WebAudioCapturerSource() override;
38
39 // WebAudioDestinationConsumer implementation.
40 // setFormat() is called early on, so that we can configure the audio track.
41 void setFormat(size_t number_of_channels, float sample_rate) override;
42 // MediaStreamAudioDestinationNode periodically calls consumeAudio().
43 // Called on the WebAudio audio thread.
44 void consumeAudio(const blink::WebVector<const float*>& audio_data,
45 size_t number_of_frames) override;
46
47 // Called when the WebAudioCapturerSource is hooking to a media audio track.
48 // |track| is the sink of the data flow and must remain alive until Stop() is
49 // called.
50 void Start(WebRtcLocalAudioTrack* track);
51
52 // Called when the media audio track is stopping.
53 void Stop();
54
55 private:
56 // Called by AudioPushFifo zero or more times during the call to
57 // consumeAudio(). Delivers audio data with the required buffer size to the
58 // track.
59 void DeliverRebufferedAudio(const media::AudioBus& audio_bus,
60 int frame_delay);
61
62 // Deregisters this object from its blink::WebMediaStreamSource.
63 void DeregisterFromBlinkSource();
64
65 // Used to DCHECK that some methods are called on the correct thread.
66 base::ThreadChecker thread_checker_;
67
68 // The audio track this WebAudioCapturerSource is feeding data to.
69 WebRtcLocalAudioTrack* track_;
70
71 media::AudioParameters params_;
72
73 // Flag to help notify the |track_| when the audio format has changed.
74 bool audio_format_changed_;
75
76 // A wrapper used for providing audio to |fifo_|.
77 std::unique_ptr<media::AudioBus> wrapper_bus_;
78
79 // Takes in the audio data passed to consumeAudio() and re-buffers it into 10
80 // ms chunks for the track. This ensures each chunk of audio delivered to the
81 // track has the required buffer size, regardless of the amount of audio
82 // provided via each consumeAudio() call.
83 media::AudioPushFifo fifo_;
84
85 // Used to pass the reference timestamp between DeliverDecodedAudio() and
86 // DeliverRebufferedAudio().
87 base::TimeTicks current_reference_time_;
88
89 // Synchronizes HandleCapture() with AudioCapturerSource calls.
90 base::Lock lock_;
91
92 // This object registers with a blink::WebMediaStreamSource. We keep track of
93 // that in order to be able to deregister before stopping the audio track.
94 blink::WebMediaStreamSource blink_source_;
95
96 DISALLOW_COPY_AND_ASSIGN(WebAudioCapturerSource);
97 };
98
99 } // namespace content
100
101 #endif // CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_
OLDNEW
« no previous file with comments | « content/renderer/media/user_media_client_impl_unittest.cc ('k') | content/renderer/media/webaudio_capturer_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698