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

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

Issue 1721273002: MediaStream audio object graph untangling and clean-ups. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed mcasas's 1st round comments, plus REBASE. 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 2013 The Chromium Authors. All rights reserved. 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 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_WEBRTC_LOCAL_AUDIO_TRACK_H_ 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_ 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_
7 7
8 #include <list> 8 #include <list>
9 #include <string> 9 #include <string>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
15 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
15 #include "content/renderer/media/media_stream_audio_level_calculator.h"
16 #include "content/renderer/media/media_stream_audio_track.h" 16 #include "content/renderer/media/media_stream_audio_track.h"
17 #include "content/renderer/media/tagged_list.h" 17 #include "content/renderer/media/tagged_list.h"
18 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h"
18 #include "media/audio/audio_parameters.h" 19 #include "media/audio/audio_parameters.h"
19 20
20 namespace media { 21 namespace media {
21 class AudioBus; 22 class AudioBus;
22 } 23 }
23 24
24 namespace content { 25 namespace content {
25 26
26 class MediaStreamAudioLevelCalculator;
27 class MediaStreamAudioProcessor; 27 class MediaStreamAudioProcessor;
28 class MediaStreamAudioSink; 28 class MediaStreamAudioSink;
29 class MediaStreamAudioSinkOwner; 29 class MediaStreamAudioSinkOwner;
30 class MediaStreamAudioTrackSink; 30 class MediaStreamAudioTrackSink;
31 class WebAudioCapturerSource;
32 class WebRtcAudioCapturer;
33 class WebRtcLocalAudioTrackAdapter;
34 31
35 // A WebRtcLocalAudioTrack instance contains the implementations of 32 // A WebRtcLocalAudioTrack manages thread-safe connects/disconnects to sinks,
36 // MediaStreamTrackExtraData. 33 // and the delivery of audio data from the source to the sinks.
37 // When an instance is created, it will register itself as a track to the
38 // WebRtcAudioCapturer to get the captured data, and forward the data to
39 // its |sinks_|. The data flow can be stopped by disabling the audio track.
40 // TODO(tommi): Rename to MediaStreamLocalAudioTrack.
o1ka 2016/02/29 14:28:05 Can we indeed make MediaStreamLocalAudioTrack and
miu 2016/03/01 09:43:55 I'll be addressing this is my next CL. (BTW, for
o1ka 2016/03/01 14:18:59 Acknowledged.
41 class CONTENT_EXPORT WebRtcLocalAudioTrack 34 class CONTENT_EXPORT WebRtcLocalAudioTrack
42 : NON_EXPORTED_BASE(public MediaStreamAudioTrack) { 35 : NON_EXPORTED_BASE(public MediaStreamAudioTrack) {
43 public: 36 public:
44 WebRtcLocalAudioTrack(WebRtcLocalAudioTrackAdapter* adapter, 37 explicit WebRtcLocalAudioTrack(
45 const scoped_refptr<WebRtcAudioCapturer>& capturer, 38 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter);
46 WebAudioCapturerSource* webaudio_source);
47 39
48 ~WebRtcLocalAudioTrack() override; 40 ~WebRtcLocalAudioTrack() override;
49 41
50 // Add a sink to the track. This function will trigger a OnSetFormat() 42 // Add a sink to the track. This function will trigger a OnSetFormat()
51 // call on the |sink|. 43 // call on the |sink|.
52 // Called on the main render thread. 44 // Called on the main render thread.
53 void AddSink(MediaStreamAudioSink* sink) override; 45 void AddSink(MediaStreamAudioSink* sink) override;
54 46
55 // Remove a sink from the track. 47 // Remove a sink from the track.
56 // Called on the main render thread. 48 // Called on the main render thread.
57 void RemoveSink(MediaStreamAudioSink* sink) override; 49 void RemoveSink(MediaStreamAudioSink* sink) override;
58 50
59 // Starts the local audio track. Called on the main render thread and
60 // should be called only once when audio track is created.
61 void Start();
62
63 // Overrides for MediaStreamTrack. 51 // Overrides for MediaStreamTrack.
64
65 void SetEnabled(bool enabled) override; 52 void SetEnabled(bool enabled) override;
66
67 // Stops the local audio track. Called on the main render thread and
68 // should be called only once when audio track going away.
69 void Stop() override;
70
71 webrtc::AudioTrackInterface* GetAudioAdapter() override; 53 webrtc::AudioTrackInterface* GetAudioAdapter() override;
72
73 // Returns the output format of the capture source. May return an invalid
74 // AudioParameters if the format is not yet available.
75 // Called on the main render thread.
76 media::AudioParameters GetOutputFormat() const override; 54 media::AudioParameters GetOutputFormat() const override;
77 55
78 // Method called by the capturer to deliver the capture data. 56 // Method called by the capturer to deliver the capture data.
79 // Called on the capture audio thread. 57 // Called on the capture audio thread.
80 void Capture(const media::AudioBus& audio_bus, 58 void Capture(const media::AudioBus& audio_bus,
81 base::TimeTicks estimated_capture_time, 59 base::TimeTicks estimated_capture_time);
82 bool force_report_nonzero_energy);
83 60
84 // Method called by the capturer to set the audio parameters used by source 61 // Method called by the capturer to set the audio parameters used by source
85 // of the capture data.. 62 // of the capture data..
86 // Called on the capture audio thread. 63 // Called on the capture audio thread.
87 void OnSetFormat(const media::AudioParameters& params); 64 void OnSetFormat(const media::AudioParameters& params);
88 65
89 // Method called by the capturer to set the processor that applies signal 66 // Called by the capturer before the audio data flow begins to set the object
90 // processing on the data of the track. 67 // that provides shared access to the current audio signal level.
91 // Called on the capture audio thread. 68 void SetLevel(scoped_refptr<MediaStreamAudioLevelCalculator::Level> level) {
69 adapter_->SetLevel(level);
70 }
71
72 // Called by the capturer before the audio data flow begins to provide a
73 // reference to the audio processor so that the track can query stats from it.
92 void SetAudioProcessor( 74 void SetAudioProcessor(
93 const scoped_refptr<MediaStreamAudioProcessor>& processor); 75 const scoped_refptr<MediaStreamAudioProcessor>& processor) {
76 adapter_->SetAudioProcessor(processor);
77 }
94 78
95 private: 79 private:
96 typedef TaggedList<MediaStreamAudioTrackSink> SinkList; 80 typedef TaggedList<MediaStreamAudioTrackSink> SinkList;
97 81
82 // Called when this MediaStreamAudioTrack is stopped to notify all sinks the
83 // stream has ended, and to remove all references to the sinks.
84 void RemoveAllSinks();
85
98 // All usage of libjingle is through this adapter. The adapter holds 86 // All usage of libjingle is through this adapter. The adapter holds
99 // a pointer to this object, but no reference. 87 // a pointer to this object, but no reference.
100 const scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_; 88 const scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_;
101 89
102 // The provider of captured data to render.
103 scoped_refptr<WebRtcAudioCapturer> capturer_;
104
105 // The source of the audio track which is used by WebAudio, which provides
106 // data to the audio track when hooking up with WebAudio.
107 scoped_refptr<WebAudioCapturerSource> webaudio_source_;
108
109 // A tagged list of sinks that the audio data is fed to. Tags 90 // A tagged list of sinks that the audio data is fed to. Tags
110 // indicate tracks that need to be notified that the audio format 91 // indicate tracks that need to be notified that the audio format
111 // has changed. 92 // has changed.
112 SinkList sinks_; 93 SinkList sinks_;
113 94
114 // Tests that methods are called on libjingle's signaling thread. 95 // Tests that methods are called on libjingle's signaling thread.
115 base::ThreadChecker signal_thread_checker_; 96 base::ThreadChecker signal_thread_checker_;
116 97
117 // Used to DCHECK that some methods are called on the capture audio thread. 98 // Used to DCHECK that some methods are called on the capture audio thread.
118 base::ThreadChecker capture_thread_checker_; 99 base::ThreadChecker capture_thread_checker_;
119 100
120 // Protects |params_| and |sinks_|. 101 // Protects |params_| and |sinks_|.
121 mutable base::Lock lock_; 102 mutable base::Lock lock_;
o1ka 2016/02/29 14:28:05 I know it's not your change and probably I am para
miu 2016/03/01 09:43:55 Totally agree. But, this is yet another thing tha
o1ka 2016/03/01 14:18:59 Acknowledged.
122 103
123 // Audio parameters of the audio capture stream. 104 // Audio parameters of the audio capture stream.
124 // Accessed on only the audio capture thread.
125 media::AudioParameters audio_parameters_; 105 media::AudioParameters audio_parameters_;
126 106
127 // Used to calculate the signal level that shows in the UI.
128 // Accessed on only the audio thread.
129 scoped_ptr<MediaStreamAudioLevelCalculator> level_calculator_;
130
131 DISALLOW_COPY_AND_ASSIGN(WebRtcLocalAudioTrack); 107 DISALLOW_COPY_AND_ASSIGN(WebRtcLocalAudioTrack);
132 }; 108 };
133 109
134 } // namespace content 110 } // namespace content
135 111
136 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_ 112 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698