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