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.
5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_LOCAL_AUDIO_TRACK_ADAPTER_H_
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_LOCAL_AUDIO_TRACK_ADAPTER_H_
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 "base/threading/thread_checker.h"
15 #include "content/common/content_export.h"
16 #include "third_party/libjingle/source/talk/app/webrtc/mediastreamtrack.h"
17 #include "third_party/libjingle/source/talk/media/base/audiorenderer.h"
24 class AudioSourceInterface
;
25 class AudioProcessorInterface
;
30 class MediaStreamAudioProcessor
;
31 class WebRtcAudioSinkAdapter
;
32 class WebRtcLocalAudioTrack
;
34 class CONTENT_EXPORT WebRtcLocalAudioTrackAdapter
35 : NON_EXPORTED_BASE(public cricket::AudioRenderer
),
37 public webrtc::MediaStreamTrack
<webrtc::AudioTrackInterface
>) {
39 static scoped_refptr
<WebRtcLocalAudioTrackAdapter
> Create(
40 const std::string
& label
,
41 webrtc::AudioSourceInterface
* track_source
);
43 WebRtcLocalAudioTrackAdapter(
44 const std::string
& label
,
45 webrtc::AudioSourceInterface
* track_source
,
46 const scoped_refptr
<base::SingleThreadTaskRunner
>& signaling_thread
);
48 ~WebRtcLocalAudioTrackAdapter() override
;
50 void Initialize(WebRtcLocalAudioTrack
* owner
);
52 std::vector
<int> VoeChannels() const;
54 // Called on the audio thread by the WebRtcLocalAudioTrack to set the signal
55 // level of the audio data.
56 void SetSignalLevel(int signal_level
);
58 // Method called by the WebRtcLocalAudioTrack to set the processor that
59 // applies signal processing on the data of the track.
60 // This class will keep a reference of the |processor|.
61 // Called on the main render thread.
62 void SetAudioProcessor(
63 const scoped_refptr
<MediaStreamAudioProcessor
>& processor
);
65 // webrtc::MediaStreamTrack implementation.
66 std::string
kind() const override
;
67 bool set_enabled(bool enable
) override
;
70 // webrtc::AudioTrackInterface implementation.
71 void AddSink(webrtc::AudioTrackSinkInterface
* sink
) override
;
72 void RemoveSink(webrtc::AudioTrackSinkInterface
* sink
) override
;
73 bool GetSignalLevel(int* level
) override
;
74 rtc::scoped_refptr
<webrtc::AudioProcessorInterface
> GetAudioProcessor()
77 // cricket::AudioCapturer implementation.
78 void AddChannel(int channel_id
) override
;
79 void RemoveChannel(int channel_id
) override
;
81 // webrtc::AudioTrackInterface implementation.
82 webrtc::AudioSourceInterface
* GetSource() const override
;
83 cricket::AudioRenderer
* GetRenderer() override
;
86 WebRtcLocalAudioTrack
* owner_
;
88 // The source of the audio track which handles the audio constraints.
89 // TODO(xians): merge |track_source_| to |capturer_| in WebRtcLocalAudioTrack.
90 rtc::scoped_refptr
<webrtc::AudioSourceInterface
> track_source_
;
92 // Libjingle's signaling thread.
93 const scoped_refptr
<base::SingleThreadTaskRunner
> signaling_thread_
;
95 // The audio processsor that applies audio processing on the data of audio
97 scoped_refptr
<MediaStreamAudioProcessor
> audio_processor_
;
99 // A vector of WebRtc VoE channels that the capturer sends data to.
100 std::vector
<int> voe_channels_
;
102 // A vector of the peer connection sink adapters which receive the audio data
103 // from the audio track.
104 ScopedVector
<WebRtcAudioSinkAdapter
> sink_adapters_
;
106 // The amplitude of the signal.
109 // Thread checker for libjingle's signaling thread.
110 base::ThreadChecker signaling_thread_checker_
;
111 base::ThreadChecker capture_thread_
;
113 // Protects |voe_channels_|, |audio_processor_| and |signal_level_|.
114 mutable base::Lock lock_
;
117 } // namespace content
119 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_LOCAL_AUDIO_TRACK_ADAPTER_H_