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

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

Issue 1714593003: Introduce media::AudioPushFifo and a couple of use cases (and clean-ups). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unittest compile breakage caused by recent method rename. Created 4 years, 9 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_ 5 #ifndef CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_
6 #define CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_ 6 #define CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/synchronization/lock.h" 12 #include "base/synchronization/lock.h"
13 #include "base/threading/thread_checker.h" 13 #include "base/threading/thread_checker.h"
14 #include "base/time/time.h"
14 #include "media/audio/audio_parameters.h" 15 #include "media/audio/audio_parameters.h"
16 #include "media/base/audio_bus.h"
15 #include "media/base/audio_capturer_source.h" 17 #include "media/base/audio_capturer_source.h"
16 #include "media/base/audio_fifo.h" 18 #include "media/base/audio_push_fifo.h"
17 #include "third_party/WebKit/public/platform/WebAudioDestinationConsumer.h" 19 #include "third_party/WebKit/public/platform/WebAudioDestinationConsumer.h"
18 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" 20 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
19 #include "third_party/WebKit/public/platform/WebVector.h" 21 #include "third_party/WebKit/public/platform/WebVector.h"
20 22
21 namespace content { 23 namespace content {
22 24
23 class WebRtcLocalAudioTrack; 25 class WebRtcLocalAudioTrack;
24 26
25 // WebAudioCapturerSource is the missing link between 27 // WebAudioCapturerSource is the missing link between
26 // WebAudio's MediaStreamAudioDestinationNode and WebRtcLocalAudioTrack. 28 // WebAudio's MediaStreamAudioDestinationNode and WebRtcLocalAudioTrack.
(...skipping 24 matching lines...) Expand all
51 void Start(WebRtcLocalAudioTrack* track); 53 void Start(WebRtcLocalAudioTrack* track);
52 54
53 // Called when the media audio track is stopping. 55 // Called when the media audio track is stopping.
54 void Stop(); 56 void Stop();
55 57
56 protected: 58 protected:
57 friend class base::RefCountedThreadSafe<WebAudioCapturerSource>; 59 friend class base::RefCountedThreadSafe<WebAudioCapturerSource>;
58 ~WebAudioCapturerSource() override; 60 ~WebAudioCapturerSource() override;
59 61
60 private: 62 private:
63 // Called by AudioPushFifo zero or more times during the call to
64 // consumeAudio(). Delivers audio data with the required buffer size to the
65 // track.
66 void DeliverRebufferedAudio(const media::AudioBus& audio_bus,
67 int frame_delay);
68
61 // Removes this object from a blink::WebMediaStreamSource with which it 69 // Removes this object from a blink::WebMediaStreamSource with which it
62 // might be registered. The goal is to avoid dangling pointers. 70 // might be registered. The goal is to avoid dangling pointers.
63 void removeFromBlinkSource(); 71 void removeFromBlinkSource();
64 72
65 // Used to DCHECK that some methods are called on the correct thread. 73 // Used to DCHECK that some methods are called on the correct thread.
66 base::ThreadChecker thread_checker_; 74 base::ThreadChecker thread_checker_;
67 75
68 // The audio track this WebAudioCapturerSource is feeding data to. 76 // The audio track this WebAudioCapturerSource is feeding data to.
69 // WebRtcLocalAudioTrack is reference counted, and owning this object. 77 // WebRtcLocalAudioTrack is reference counted, and owning this object.
70 // To avoid circular reference, a raw pointer is kept here. 78 // To avoid circular reference, a raw pointer is kept here.
71 WebRtcLocalAudioTrack* track_; 79 WebRtcLocalAudioTrack* track_;
72 80
73 media::AudioParameters params_; 81 media::AudioParameters params_;
74 82
75 // Flag to help notify the |track_| when the audio format has changed. 83 // Flag to help notify the |track_| when the audio format has changed.
76 bool audio_format_changed_; 84 bool audio_format_changed_;
77 85
78 // Wraps data coming from HandleCapture(). 86 // A wrapper used for providing audio to |fifo_|.
79 scoped_ptr<media::AudioBus> wrapper_bus_; 87 scoped_ptr<media::AudioBus> wrapper_bus_;
80 88
81 // Bus for reading from FIFO and calling the CaptureCallback. 89 // Takes in the audio data passed to consumeAudio() and re-buffers it into 10
82 scoped_ptr<media::AudioBus> capture_bus_; 90 // ms chunks for the track. This ensures each chunk of audio delivered to the
91 // track has the required buffer size, regardless of the amount of audio
92 // provided via each consumeAudio() call.
93 media::AudioPushFifo fifo_;
83 94
84 // Handles mismatch between WebAudio buffer size and WebRTC. 95 // Used to pass the reference timestamp between DeliverDecodedAudio() and
85 scoped_ptr<media::AudioFifo> fifo_; 96 // DeliverRebufferedAudio().
97 base::TimeTicks current_reference_time_;
86 98
87 // Synchronizes HandleCapture() with AudioCapturerSource calls. 99 // Synchronizes HandleCapture() with AudioCapturerSource calls.
88 base::Lock lock_; 100 base::Lock lock_;
89 bool started_; 101 bool started_;
90 102
91 // This object registers with a blink::WebMediaStreamSource. We keep track of 103 // 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. 104 // that in order to be able to deregister before stopping the audio track.
93 blink::WebMediaStreamSource blink_source_; 105 blink::WebMediaStreamSource blink_source_;
94 106
95 DISALLOW_COPY_AND_ASSIGN(WebAudioCapturerSource); 107 DISALLOW_COPY_AND_ASSIGN(WebAudioCapturerSource);
96 }; 108 };
97 109
98 } // namespace content 110 } // namespace content
99 111
100 #endif // CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_ 112 #endif // CONTENT_RENDERER_MEDIA_WEBAUDIO_CAPTURER_SOURCE_H_
OLDNEW
« no previous file with comments | « chrome/renderer/media/cast_rtp_stream.cc ('k') | content/renderer/media/webaudio_capturer_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698