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