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/synchronization/lock.h"
13 #include "content/common/content_export.h"
14 #include "third_party/libjingle/source/talk/app/webrtc/mediastreamtrack.h"
15 #include "third_party/libjingle/source/talk/media/base/audiorenderer.h"
22 class AudioSourceInterface
;
23 class AudioProcessorInterface
;
28 class MediaStreamAudioProcessor
;
29 class WebRtcAudioSinkAdapter
;
30 class WebRtcLocalAudioTrack
;
32 class CONTENT_EXPORT WebRtcLocalAudioTrackAdapter
33 : NON_EXPORTED_BASE(public cricket::AudioRenderer
),
35 public webrtc::MediaStreamTrack
<webrtc::AudioTrackInterface
>) {
37 static scoped_refptr
<WebRtcLocalAudioTrackAdapter
> Create(
38 const std::string
& label
,
39 webrtc::AudioSourceInterface
* track_source
);
41 WebRtcLocalAudioTrackAdapter(
42 const std::string
& label
,
43 webrtc::AudioSourceInterface
* track_source
);
45 virtual ~WebRtcLocalAudioTrackAdapter();
47 void Initialize(WebRtcLocalAudioTrack
* owner
);
49 std::vector
<int> VoeChannels() const;
51 // Called on the audio thread by the WebRtcLocalAudioTrack to set the signal
52 // level of the audio data.
53 void SetSignalLevel(int signal_level
);
55 // Method called by the WebRtcLocalAudioTrack to set the processor that
56 // applies signal processing on the data of the track.
57 // This class will keep a reference of the |processor|.
58 // Called on the main render thread.
59 void SetAudioProcessor(
60 const scoped_refptr
<MediaStreamAudioProcessor
>& processor
);
63 // webrtc::MediaStreamTrack implementation.
64 virtual std::string
kind() const override
;
66 // webrtc::AudioTrackInterface implementation.
67 virtual void AddSink(webrtc::AudioTrackSinkInterface
* sink
) override
;
68 virtual void RemoveSink(webrtc::AudioTrackSinkInterface
* sink
) override
;
69 virtual bool GetSignalLevel(int* level
) override
;
70 virtual rtc::scoped_refptr
<webrtc::AudioProcessorInterface
>
71 GetAudioProcessor() override
;
73 // cricket::AudioCapturer implementation.
74 virtual void AddChannel(int channel_id
) override
;
75 virtual void RemoveChannel(int channel_id
) override
;
77 // webrtc::AudioTrackInterface implementation.
78 virtual webrtc::AudioSourceInterface
* GetSource() const override
;
79 virtual cricket::AudioRenderer
* GetRenderer() override
;
82 WebRtcLocalAudioTrack
* owner_
;
84 // The source of the audio track which handles the audio constraints.
85 // TODO(xians): merge |track_source_| to |capturer_| in WebRtcLocalAudioTrack.
86 rtc::scoped_refptr
<webrtc::AudioSourceInterface
> track_source_
;
88 // The audio processsor that applies audio processing on the data of audio
90 scoped_refptr
<MediaStreamAudioProcessor
> audio_processor_
;
92 // A vector of WebRtc VoE channels that the capturer sends data to.
93 std::vector
<int> voe_channels_
;
95 // A vector of the peer connection sink adapters which receive the audio data
96 // from the audio track.
97 ScopedVector
<WebRtcAudioSinkAdapter
> sink_adapters_
;
99 // The amplitude of the signal.
102 // Protects |voe_channels_|, |audio_processor_| and |signal_level_|.
103 mutable base::Lock lock_
;
106 } // namespace content
108 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_LOCAL_AUDIO_TRACK_ADAPTER_H_