Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / content / renderer / media / webrtc / webrtc_local_audio_track_adapter.h
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.
4
5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_LOCAL_AUDIO_TRACK_ADAPTER_H_
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_LOCAL_AUDIO_TRACK_ADAPTER_H_
7
8 #include <vector>
9
10 #include "base/memory/ref_counted.h"
11 #include "base/synchronization/lock.h"
12 #include "content/common/content_export.h"
13 #include "third_party/libjingle/source/talk/app/webrtc/mediastreamtrack.h"
14 #include "third_party/libjingle/source/talk/media/base/audiorenderer.h"
15
16 namespace cricket {
17 class AudioRenderer;
18 }
19
20 namespace webrtc {
21 class AudioSourceInterface;
22 }
23
24 namespace content {
25
26 class WebRtcLocalAudioTrack;
27
28 class CONTENT_EXPORT WebRtcLocalAudioTrackAdapter
29     : NON_EXPORTED_BASE(public cricket::AudioRenderer),
30       NON_EXPORTED_BASE(
31           public webrtc::MediaStreamTrack<webrtc::AudioTrackInterface>) {
32  public:
33   static scoped_refptr<WebRtcLocalAudioTrackAdapter> Create(
34       const std::string& label,
35       webrtc::AudioSourceInterface* track_source);
36
37   WebRtcLocalAudioTrackAdapter(
38       const std::string& label,
39       webrtc::AudioSourceInterface* track_source);
40
41   virtual ~WebRtcLocalAudioTrackAdapter();
42
43   void Initialize(WebRtcLocalAudioTrack* owner);
44
45   std::vector<int> VoeChannels() const;
46
47  private:
48   // webrtc::MediaStreamTrack implementation.
49   virtual std::string kind() const OVERRIDE;
50
51   // cricket::AudioCapturer implementation.
52   virtual void AddChannel(int channel_id) OVERRIDE;
53   virtual void RemoveChannel(int channel_id) OVERRIDE;
54
55   // webrtc::AudioTrackInterface implementation.
56   virtual webrtc::AudioSourceInterface* GetSource() const OVERRIDE;
57   virtual cricket::AudioRenderer* GetRenderer() OVERRIDE;
58
59   // Weak reference.
60   WebRtcLocalAudioTrack* owner_;
61
62   // The source of the audio track which handles the audio constraints.
63   // TODO(xians): merge |track_source_| to |capturer_| in WebRtcLocalAudioTrack.
64   talk_base::scoped_refptr<webrtc::AudioSourceInterface> track_source_;
65
66   // A vector of WebRtc VoE channels that the capturer sends data to.
67   std::vector<int> voe_channels_;
68
69   // Protects |voe_channels_|.
70   mutable base::Lock lock_;
71 };
72
73 }  // namespace content
74
75 #endif  // CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_LOCAL_AUDIO_TRACK_ADAPTER_H_