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/synchronization/lock.h" | |
14 #include "base/threading/thread_checker.h" | |
15 #include "content/renderer/media/media_stream_audio_track.h" | |
16 #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" | |
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 | |
32 // A WebRtcLocalAudioTrack manages thread-safe connects/disconnects to sinks, | |
33 // and the delivery of audio data from the source to the sinks. | |
34 class CONTENT_EXPORT WebRtcLocalAudioTrack | |
35 : NON_EXPORTED_BASE(public MediaStreamAudioTrack) { | |
36 public: | |
37 explicit WebRtcLocalAudioTrack( | |
38 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter); | |
39 | |
40 ~WebRtcLocalAudioTrack() override; | |
41 | |
42 // Add a sink to the track. This function will trigger a OnSetFormat() | |
43 // call on the |sink|. | |
44 // Called on the main render thread. | |
45 void AddSink(MediaStreamAudioSink* sink) override; | |
46 | |
47 // Remove a sink from the track. | |
48 // Called on the main render thread. | |
49 void RemoveSink(MediaStreamAudioSink* sink) override; | |
50 | |
51 // Overrides for MediaStreamTrack. | |
52 void SetEnabled(bool enabled) override; | |
53 webrtc::AudioTrackInterface* GetAudioAdapter() override; | |
54 media::AudioParameters GetOutputFormat() const override; | |
55 | |
56 // Method called by the capturer to deliver the capture data. | |
57 // Called on the capture audio thread. | |
58 void Capture(const media::AudioBus& audio_bus, | |
59 base::TimeTicks estimated_capture_time); | |
60 | |
61 // Method called by the capturer to set the audio parameters used by source | |
62 // of the capture data.. | |
63 // Called on the capture audio thread. | |
64 void OnSetFormat(const media::AudioParameters& params); | |
65 | |
66 // Called by the capturer before the audio data flow begins to set the object | |
67 // that provides shared access to the current audio signal level. | |
68 void SetLevel(scoped_refptr<MediaStreamAudioLevelCalculator::Level> level); | |
69 | |
70 // Called by the capturer before the audio data flow begins to provide a | |
71 // reference to the audio processor so that the track can query stats from it. | |
72 void SetAudioProcessor(scoped_refptr<MediaStreamAudioProcessor> processor); | |
73 | |
74 private: | |
75 typedef TaggedList<MediaStreamAudioTrackSink> SinkList; | |
76 | |
77 // MediaStreamAudioTrack override. | |
78 void OnStop() final; | |
79 | |
80 // All usage of libjingle is through this adapter. The adapter holds | |
81 // a pointer to this object, but no reference. | |
82 const scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_; | |
83 | |
84 // 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 | |
86 // has changed. | |
87 SinkList sinks_; | |
88 | |
89 // Tests that methods are called on libjingle's signaling thread. | |
90 base::ThreadChecker signal_thread_checker_; | |
91 | |
92 // Used to DCHECK that some methods are called on the capture audio thread. | |
93 base::ThreadChecker capture_thread_checker_; | |
94 | |
95 // Protects |params_| and |sinks_|. | |
96 mutable base::Lock lock_; | |
97 | |
98 // Audio parameters of the audio capture stream. | |
99 media::AudioParameters audio_parameters_; | |
100 | |
101 DISALLOW_COPY_AND_ASSIGN(WebRtcLocalAudioTrack); | |
102 }; | |
103 | |
104 } // namespace content | |
105 | |
106 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_ | |
OLD | NEW |