OLD | NEW |
| (Empty) |
1 // Copyright 2014 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_WEBRTC_LOCAL_AUDIO_TRACK_ADAPTER_H_ | |
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_LOCAL_AUDIO_TRACK_ADAPTER_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "base/memory/ref_counted.h" | |
11 #include "base/memory/scoped_vector.h" | |
12 #include "base/single_thread_task_runner.h" | |
13 #include "base/synchronization/lock.h" | |
14 #include "content/common/content_export.h" | |
15 #include "content/renderer/media/media_stream_audio_level_calculator.h" | |
16 #include "content/renderer/media/media_stream_audio_processor.h" | |
17 #include "third_party/webrtc/api/mediastreamtrack.h" | |
18 #include "third_party/webrtc/media/base/audiorenderer.h" | |
19 | |
20 namespace cricket { | |
21 class AudioRenderer; | |
22 } | |
23 | |
24 namespace webrtc { | |
25 class AudioSourceInterface; | |
26 class AudioProcessorInterface; | |
27 } | |
28 | |
29 namespace content { | |
30 | |
31 class MediaStreamAudioProcessor; | |
32 class WebRtcAudioSinkAdapter; | |
33 class WebRtcLocalAudioTrack; | |
34 | |
35 // Provides an implementation of the webrtc::AudioTrackInterface that can be | |
36 // bound/unbound to/from a MediaStreamAudioTrack. In other words, this is an | |
37 // adapter that sits between the media stream object graph and WebRtc's object | |
38 // graph and proxies between the two. | |
39 class CONTENT_EXPORT WebRtcLocalAudioTrackAdapter | |
40 : NON_EXPORTED_BASE( | |
41 public webrtc::MediaStreamTrack<webrtc::AudioTrackInterface>) { | |
42 public: | |
43 static scoped_refptr<WebRtcLocalAudioTrackAdapter> Create( | |
44 const std::string& label, | |
45 webrtc::AudioSourceInterface* track_source); | |
46 | |
47 WebRtcLocalAudioTrackAdapter( | |
48 const std::string& label, | |
49 webrtc::AudioSourceInterface* track_source, | |
50 scoped_refptr<base::SingleThreadTaskRunner> signaling_task_runner); | |
51 | |
52 ~WebRtcLocalAudioTrackAdapter() override; | |
53 | |
54 void Initialize(WebRtcLocalAudioTrack* owner); | |
55 | |
56 // Set the object that provides shared access to the current audio signal | |
57 // level. This method may only be called once, before the audio data flow | |
58 // starts, and before any calls to GetSignalLevel() might be made. | |
59 void SetLevel(scoped_refptr<MediaStreamAudioLevelCalculator::Level> level); | |
60 | |
61 // Method called by the WebRtcLocalAudioTrack to set the processor that | |
62 // applies signal processing on the data of the track. | |
63 // This class will keep a reference of the |processor|. | |
64 // Called on the main render thread. | |
65 // This method may only be called once, before the audio data flow starts, and | |
66 // before any calls to GetAudioProcessor() might be made. | |
67 void SetAudioProcessor(scoped_refptr<MediaStreamAudioProcessor> processor); | |
68 | |
69 // webrtc::MediaStreamTrack implementation. | |
70 std::string kind() const override; | |
71 bool set_enabled(bool enable) override; | |
72 | |
73 private: | |
74 // webrtc::AudioTrackInterface implementation. | |
75 void AddSink(webrtc::AudioTrackSinkInterface* sink) override; | |
76 void RemoveSink(webrtc::AudioTrackSinkInterface* sink) override; | |
77 bool GetSignalLevel(int* level) override; | |
78 rtc::scoped_refptr<webrtc::AudioProcessorInterface> GetAudioProcessor() | |
79 override; | |
80 webrtc::AudioSourceInterface* GetSource() const override; | |
81 | |
82 // Weak reference. | |
83 WebRtcLocalAudioTrack* owner_; | |
84 | |
85 // The source of the audio track which handles the audio constraints. | |
86 // TODO(xians): merge |track_source_| to |capturer_| in WebRtcLocalAudioTrack. | |
87 rtc::scoped_refptr<webrtc::AudioSourceInterface> track_source_; | |
88 | |
89 // Libjingle's signaling thread. | |
90 const scoped_refptr<base::SingleThreadTaskRunner> signaling_task_runner_; | |
91 | |
92 // The audio processsor that applies audio processing on the data of audio | |
93 // track. This must be set before calls to GetAudioProcessor() are made. | |
94 scoped_refptr<MediaStreamAudioProcessor> audio_processor_; | |
95 | |
96 // A vector of the peer connection sink adapters which receive the audio data | |
97 // from the audio track. | |
98 ScopedVector<WebRtcAudioSinkAdapter> sink_adapters_; | |
99 | |
100 // Thread-safe accessor to current audio signal level. This must be set | |
101 // before calls to GetSignalLevel() are made. | |
102 scoped_refptr<MediaStreamAudioLevelCalculator::Level> level_; | |
103 }; | |
104 | |
105 } // namespace content | |
106 | |
107 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_LOCAL_AUDIO_TRACK_ADAPTER_H_ | |
OLD | NEW |