OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_ | |
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_ | |
7 | |
8 #include <list> | |
9 #include <string> | |
10 | |
11 #include "base/macros.h" | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/synchronization/lock.h" | |
15 #include "base/threading/thread_checker.h" | |
16 #include "content/renderer/media/media_stream_audio_track.h" | |
17 #include "content/renderer/media/tagged_list.h" | |
18 #include "media/audio/audio_parameters.h" | |
19 | |
20 namespace media { | |
21 class AudioBus; | |
22 } | |
23 | |
24 namespace content { | |
25 | |
26 class MediaStreamAudioLevelCalculator; | |
27 class MediaStreamAudioProcessor; | |
28 class MediaStreamAudioSink; | |
29 class MediaStreamAudioSinkOwner; | |
30 class MediaStreamAudioTrackSink; | |
31 class WebAudioCapturerSource; | |
32 class WebRtcAudioCapturer; | |
33 class WebRtcLocalAudioTrackAdapter; | |
34 | |
35 // A WebRtcLocalAudioTrack instance contains the implementations of | |
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. | |
41 class CONTENT_EXPORT WebRtcLocalAudioTrack | |
42 : NON_EXPORTED_BASE(public MediaStreamAudioTrack) { | |
43 public: | |
44 WebRtcLocalAudioTrack(WebRtcLocalAudioTrackAdapter* adapter, | |
45 const scoped_refptr<WebRtcAudioCapturer>& capturer, | |
46 WebAudioCapturerSource* webaudio_source); | |
47 | |
48 ~WebRtcLocalAudioTrack() override; | |
49 | |
50 // Add a sink to the track. This function will trigger a OnSetFormat() | |
51 // call on the |sink|. | |
52 // Called on the main render thread. | |
53 void AddSink(MediaStreamAudioSink* sink) override; | |
54 | |
55 // Remove a sink from the track. | |
56 // Called on the main render thread. | |
57 void RemoveSink(MediaStreamAudioSink* sink) override; | |
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 | |
63 // Overrides for MediaStreamTrack. | |
64 | |
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 | |
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. | |
76 media::AudioParameters GetOutputFormat() const override; | |
77 | |
78 // Method called by the capturer to deliver the capture data. | |
79 // Called on the capture audio thread. | |
80 void Capture(const media::AudioBus& audio_bus, | |
81 base::TimeTicks estimated_capture_time, | |
82 bool force_report_nonzero_energy); | |
83 | |
84 // Method called by the capturer to set the audio parameters used by source | |
85 // of the capture data.. | |
86 // Called on the capture audio thread. | |
87 void OnSetFormat(const media::AudioParameters& params); | |
88 | |
89 // Method called by the capturer to set the processor that applies signal | |
90 // processing on the data of the track. | |
91 // Called on the capture audio thread. | |
92 void SetAudioProcessor( | |
93 const scoped_refptr<MediaStreamAudioProcessor>& processor); | |
94 | |
95 private: | |
96 typedef TaggedList<MediaStreamAudioTrackSink> SinkList; | |
97 | |
98 // All usage of libjingle is through this adapter. The adapter holds | |
99 // a pointer to this object, but no reference. | |
100 const scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_; | |
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 | |
109 // 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 | |
111 // has changed. | |
112 SinkList sinks_; | |
113 | |
114 // Tests that methods are called on libjingle's signaling thread. | |
115 base::ThreadChecker signal_thread_checker_; | |
116 | |
117 // Used to DCHECK that some methods are called on the capture audio thread. | |
118 base::ThreadChecker capture_thread_checker_; | |
119 | |
120 // Protects |params_| and |sinks_|. | |
121 mutable base::Lock lock_; | |
122 | |
123 // Audio parameters of the audio capture stream. | |
124 // Accessed on only the audio capture thread. | |
125 media::AudioParameters audio_parameters_; | |
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 | |
131 DISALLOW_COPY_AND_ASSIGN(WebRtcLocalAudioTrack); | |
132 }; | |
133 | |
134 } // namespace content | |
135 | |
136 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_ | |
OLD | NEW |