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

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

Issue 1780653002: Revert of MediaStream audio object graph untangling and clean-ups. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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"
13 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
14 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
15 #include "content/renderer/media/media_stream_audio_track.h" 16 #include "content/renderer/media/media_stream_audio_track.h"
16 #include "content/renderer/media/tagged_list.h" 17 #include "content/renderer/media/tagged_list.h"
17 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h"
18 #include "media/audio/audio_parameters.h" 18 #include "media/audio/audio_parameters.h"
19 19
20 namespace media { 20 namespace media {
21 class AudioBus; 21 class AudioBus;
22 } 22 }
23 23
24 namespace content { 24 namespace content {
25 25
26 class MediaStreamAudioLevelCalculator; 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;
31 34
32 // A WebRtcLocalAudioTrack manages thread-safe connects/disconnects to sinks, 35 // A WebRtcLocalAudioTrack instance contains the implementations of
33 // and the delivery of audio data from the source to the sinks. 36 // MediaStreamTrackExtraData.
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.
34 class CONTENT_EXPORT WebRtcLocalAudioTrack 41 class CONTENT_EXPORT WebRtcLocalAudioTrack
35 : NON_EXPORTED_BASE(public MediaStreamAudioTrack) { 42 : NON_EXPORTED_BASE(public MediaStreamAudioTrack) {
36 public: 43 public:
37 explicit WebRtcLocalAudioTrack( 44 WebRtcLocalAudioTrack(WebRtcLocalAudioTrackAdapter* adapter,
38 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter); 45 const scoped_refptr<WebRtcAudioCapturer>& capturer,
46 WebAudioCapturerSource* webaudio_source);
39 47
40 ~WebRtcLocalAudioTrack() override; 48 ~WebRtcLocalAudioTrack() override;
41 49
42 // Add a sink to the track. This function will trigger a OnSetFormat() 50 // Add a sink to the track. This function will trigger a OnSetFormat()
43 // call on the |sink|. 51 // call on the |sink|.
44 // Called on the main render thread. 52 // Called on the main render thread.
45 void AddSink(MediaStreamAudioSink* sink) override; 53 void AddSink(MediaStreamAudioSink* sink) override;
46 54
47 // Remove a sink from the track. 55 // Remove a sink from the track.
48 // Called on the main render thread. 56 // Called on the main render thread.
49 void RemoveSink(MediaStreamAudioSink* sink) override; 57 void RemoveSink(MediaStreamAudioSink* sink) override;
50 58
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
51 // Overrides for MediaStreamTrack. 63 // Overrides for MediaStreamTrack.
64
52 void SetEnabled(bool enabled) override; 65 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
53 webrtc::AudioTrackInterface* GetAudioAdapter() override; 71 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.
54 media::AudioParameters GetOutputFormat() const override; 76 media::AudioParameters GetOutputFormat() const override;
55 77
56 // Method called by the capturer to deliver the capture data. 78 // Method called by the capturer to deliver the capture data.
57 // Called on the capture audio thread. 79 // Called on the capture audio thread.
58 void Capture(const media::AudioBus& audio_bus, 80 void Capture(const media::AudioBus& audio_bus,
59 base::TimeTicks estimated_capture_time); 81 base::TimeTicks estimated_capture_time,
82 bool force_report_nonzero_energy);
60 83
61 // Method called by the capturer to set the audio parameters used by source 84 // Method called by the capturer to set the audio parameters used by source
62 // of the capture data.. 85 // of the capture data..
63 // Called on the capture audio thread. 86 // Called on the capture audio thread.
64 void OnSetFormat(const media::AudioParameters& params); 87 void OnSetFormat(const media::AudioParameters& params);
65 88
66 // Called by the capturer before the audio data flow begins to set the object 89 // Method called by the capturer to set the processor that applies signal
67 // that provides shared access to the current audio signal level. 90 // processing on the data of the track.
68 void SetLevel(scoped_refptr<MediaStreamAudioLevelCalculator::Level> level); 91 // Called on the capture audio thread.
69 92 void SetAudioProcessor(
70 // Called by the capturer before the audio data flow begins to provide a 93 const scoped_refptr<MediaStreamAudioProcessor>& processor);
71 // reference to the audio processor so that the track can query stats from it.
72 void SetAudioProcessor(scoped_refptr<MediaStreamAudioProcessor> processor);
73 94
74 private: 95 private:
75 typedef TaggedList<MediaStreamAudioTrackSink> SinkList; 96 typedef TaggedList<MediaStreamAudioTrackSink> SinkList;
76 97
77 // MediaStreamAudioTrack override.
78 void OnStop() final;
79
80 // All usage of libjingle is through this adapter. The adapter holds 98 // All usage of libjingle is through this adapter. The adapter holds
81 // a pointer to this object, but no reference. 99 // a pointer to this object, but no reference.
82 const scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_; 100 const scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_;
83 101
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
84 // A tagged list of sinks that the audio data is fed to. Tags 109 // A tagged list of sinks that the audio data is fed to. Tags
85 // indicate tracks that need to be notified that the audio format 110 // indicate tracks that need to be notified that the audio format
86 // has changed. 111 // has changed.
87 SinkList sinks_; 112 SinkList sinks_;
88 113
89 // Tests that methods are called on libjingle's signaling thread. 114 // Tests that methods are called on libjingle's signaling thread.
90 base::ThreadChecker signal_thread_checker_; 115 base::ThreadChecker signal_thread_checker_;
91 116
92 // Used to DCHECK that some methods are called on the capture audio thread. 117 // Used to DCHECK that some methods are called on the capture audio thread.
93 base::ThreadChecker capture_thread_checker_; 118 base::ThreadChecker capture_thread_checker_;
94 119
95 // Protects |params_| and |sinks_|. 120 // Protects |params_| and |sinks_|.
96 mutable base::Lock lock_; 121 mutable base::Lock lock_;
97 122
98 // Audio parameters of the audio capture stream. 123 // Audio parameters of the audio capture stream.
124 // Accessed on only the audio capture thread.
99 media::AudioParameters audio_parameters_; 125 media::AudioParameters audio_parameters_;
100 126
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
101 DISALLOW_COPY_AND_ASSIGN(WebRtcLocalAudioTrack); 131 DISALLOW_COPY_AND_ASSIGN(WebRtcLocalAudioTrack);
102 }; 132 };
103 133
104 } // namespace content 134 } // namespace content
105 135
106 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_ 136 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698