Chromium Code Reviews| 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 "base/threading/thread_checker.h" |
| 15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 16 #include "content/renderer/media/media_stream_audio_level_calculator.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 const scoped_refptr<base::SingleThreadTaskRunner>& signaling_thread); |
| 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. |
| 53 void SetSignalLevel(int signal_level); | 58 void SetLevel(scoped_refptr<MediaStreamAudioLevelCalculator::Level> level); |
| 54 | 59 |
| 55 // Method called by the WebRtcLocalAudioTrack to set the processor that | 60 // Method called by the WebRtcLocalAudioTrack to set the processor that |
| 56 // applies signal processing on the data of the track. | 61 // applies signal processing on the data of the track. |
| 57 // This class will keep a reference of the |processor|. | 62 // This class will keep a reference of the |processor|. |
| 58 // Called on the main render thread. | 63 // Called on the main render thread. |
| 59 void SetAudioProcessor( | 64 void SetAudioProcessor( |
| 60 const scoped_refptr<MediaStreamAudioProcessor>& processor); | 65 const scoped_refptr<MediaStreamAudioProcessor>& processor); |
| 61 | 66 |
| 62 // webrtc::MediaStreamTrack implementation. | 67 // webrtc::MediaStreamTrack implementation. |
| 63 std::string kind() const override; | 68 std::string kind() const override; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 77 | 82 |
| 78 // The source of the audio track which handles the audio constraints. | 83 // The source of the audio track which handles the audio constraints. |
| 79 // TODO(xians): merge |track_source_| to |capturer_| in WebRtcLocalAudioTrack. | 84 // TODO(xians): merge |track_source_| to |capturer_| in WebRtcLocalAudioTrack. |
| 80 rtc::scoped_refptr<webrtc::AudioSourceInterface> track_source_; | 85 rtc::scoped_refptr<webrtc::AudioSourceInterface> track_source_; |
| 81 | 86 |
| 82 // Libjingle's signaling thread. | 87 // Libjingle's signaling thread. |
| 83 const scoped_refptr<base::SingleThreadTaskRunner> signaling_thread_; | 88 const scoped_refptr<base::SingleThreadTaskRunner> signaling_thread_; |
| 84 | 89 |
| 85 // The audio processsor that applies audio processing on the data of audio | 90 // The audio processsor that applies audio processing on the data of audio |
| 86 // track. | 91 // track. |
| 87 scoped_refptr<MediaStreamAudioProcessor> audio_processor_; | 92 scoped_refptr<MediaStreamAudioProcessor> audio_processor_; |
|
mcasas
2016/02/26 01:28:19
This variable is only set in SetAudioProcessor() a
miu
2016/02/27 03:46:36
Acknowledged.
| |
| 88 | 93 |
| 89 // A vector of WebRtc VoE channels that the capturer sends data to. | 94 // A vector of WebRtc VoE channels that the capturer sends data to. |
| 90 std::vector<int> voe_channels_; | 95 std::vector<int> voe_channels_; |
|
miu
2016/02/27 03:46:36
Removed this since it's not used at all.
| |
| 91 | 96 |
| 92 // A vector of the peer connection sink adapters which receive the audio data | 97 // A vector of the peer connection sink adapters which receive the audio data |
| 93 // from the audio track. | 98 // from the audio track. |
| 94 ScopedVector<WebRtcAudioSinkAdapter> sink_adapters_; | 99 ScopedVector<WebRtcAudioSinkAdapter> sink_adapters_; |
| 95 | 100 |
| 96 // The amplitude of the signal. | 101 // Thread-safe accessor to current audio signal level. |
|
mcasas
2016/02/26 01:28:19
If this is thread-safe, we don't need to protect i
miu
2016/02/27 03:46:36
Done. Actually, that's an interesting point. If
| |
| 97 int signal_level_; | 102 scoped_refptr<MediaStreamAudioLevelCalculator::Level> level_; |
| 98 | 103 |
| 99 // Thread checker for libjingle's signaling thread. | 104 // Thread checker for libjingle's signaling thread. |
| 100 base::ThreadChecker signaling_thread_checker_; | 105 base::ThreadChecker signaling_thread_checker_; |
|
mcasas
2016/02/26 01:28:19
We don't need |signaling_thread_checker_| is we ha
miu
2016/02/27 03:46:36
Done. Removed both since the latter is only used
| |
| 101 base::ThreadChecker capture_thread_; | 106 base::ThreadChecker capture_thread_; |
| 102 | 107 |
| 103 // Protects |voe_channels_|, |audio_processor_| and |signal_level_|. | 108 // Protects |voe_channels_|, |audio_processor_| and |signal_level_|. |
|
mcasas
2016/02/26 01:28:19
|signal_level_| is no more.
miu
2016/02/27 03:46:36
Done. |lock_| is no more too (see above comment).
| |
| 104 mutable base::Lock lock_; | 109 mutable base::Lock lock_; |
| 105 }; | 110 }; |
| 106 | 111 |
| 107 } // namespace content | 112 } // namespace content |
| 108 | 113 |
| 109 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_LOCAL_AUDIO_TRACK_ADAPTER_H_ | 114 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_LOCAL_AUDIO_TRACK_ADAPTER_H_ |
| OLD | NEW |