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

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

Issue 1647773002: MediaStream audio sourcing: Bypass audio processing for non-WebRTC cases. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: NOT FOR REVIEW -- This will be broken-up across multiple CLs. Created 4 years, 10 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/memory/ref_counted.h"
12 #include "base/synchronization/lock.h"
13 #include "base/threading/thread_checker.h"
14 #include "media/audio/audio_parameters.h"
15 #include "media/base/audio_capturer_source.h"
16 #include "media/base/audio_fifo.h"
17 #include "third_party/WebKit/public/platform/WebAudioDestinationConsumer.h"
18 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
19 #include "third_party/WebKit/public/platform/WebVector.h"
20
21 namespace content {
22
23 class WebRtcLocalAudioTrack;
24
25 // WebAudioCapturerSource is the missing link between
26 // WebAudio's MediaStreamAudioDestinationNode and WebRtcLocalAudioTrack.
27 //
28 // 1. WebKit calls the setFormat() method setting up the basic stream format
29 // (channels, and sample-rate).
30 // 2. consumeAudio() is called periodically by WebKit which dispatches the
31 // audio stream to the WebRtcLocalAudioTrack::Capture() method.
32 class WebAudioCapturerSource
33 : public base::RefCountedThreadSafe<WebAudioCapturerSource>,
34 public blink::WebAudioDestinationConsumer {
35 public:
36 explicit WebAudioCapturerSource(
37 const blink::WebMediaStreamSource& blink_source);
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. |source_provider| is the source of
49 // the data flow where stream information like delay, volume, key_pressed,
50 // is stored.
51 void Start(WebRtcLocalAudioTrack* track);
52
53 // Called when the media audio track is stopping.
54 void Stop();
55
56 protected:
57 friend class base::RefCountedThreadSafe<WebAudioCapturerSource>;
58 ~WebAudioCapturerSource() override;
59
60 private:
61 // Removes this object from a blink::WebMediaStreamSource with which it
62 // might be registered. The goal is to avoid dangling pointers.
63 void removeFromBlinkSource();
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 is reference counted, and owning this object.
70 // To avoid circular reference, a raw pointer is kept here.
71 WebRtcLocalAudioTrack* track_;
72
73 media::AudioParameters params_;
74
75 // Flag to help notify the |track_| when the audio format has changed.
76 bool audio_format_changed_;
77
78 // Wraps data coming from HandleCapture().
79 scoped_ptr<media::AudioBus> wrapper_bus_;
80
81 // Bus for reading from FIFO and calling the CaptureCallback.
82 scoped_ptr<media::AudioBus> capture_bus_;
83
84 // Handles mismatch between WebAudio buffer size and WebRTC.
85 scoped_ptr<media::AudioFifo> fifo_;
86
87 // Synchronizes HandleCapture() with AudioCapturerSource calls.
88 base::Lock lock_;
89 bool started_;
90
91 // This object registers with a blink::WebMediaStreamSource. We keep track of
92 // that in order to be able to deregister before stopping the audio track.
93 blink::WebMediaStreamSource blink_source_;
94
95 DISALLOW_COPY_AND_ASSIGN(WebAudioCapturerSource);
96 };
97
98 } // namespace content
99
100 #endif // CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_
OLDNEW
« no previous file with comments | « content/renderer/media/user_media_client_impl.cc ('k') | content/renderer/media/webaudio_capturer_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698