Replace FINAL and OVERRIDE with their C++11 counterparts in content/renderer
[chromium-blink-merge.git] / content / renderer / media / webrtc_local_audio_track.h
blob7697ddf1d1248f2f0779b340f7105fa9f6426da8
1 // Copyright 2013 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_LOCAL_AUDIO_TRACK_H_
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_
8 #include <list>
9 #include <string>
11 #include "base/memory/ref_counted.h"
12 #include "base/synchronization/lock.h"
13 #include "base/threading/thread_checker.h"
14 #include "content/renderer/media/media_stream_track.h"
15 #include "content/renderer/media/tagged_list.h"
16 #include "content/renderer/media/webrtc_audio_device_impl.h"
18 namespace content {
20 class MediaStreamAudioLevelCalculator;
21 class MediaStreamAudioProcessor;
22 class MediaStreamAudioSink;
23 class MediaStreamAudioSinkOwner;
24 class MediaStreamAudioTrackSink;
25 class PeerConnectionAudioSink;
26 class WebAudioCapturerSource;
27 class WebRtcAudioCapturer;
28 class WebRtcLocalAudioTrackAdapter;
30 // A WebRtcLocalAudioTrack instance contains the implementations of
31 // MediaStreamTrackExtraData.
32 // When an instance is created, it will register itself as a track to the
33 // WebRtcAudioCapturer to get the captured data, and forward the data to
34 // its |sinks_|. The data flow can be stopped by disabling the audio track.
35 class CONTENT_EXPORT WebRtcLocalAudioTrack
36 : NON_EXPORTED_BASE(public MediaStreamTrack) {
37 public:
38 WebRtcLocalAudioTrack(WebRtcLocalAudioTrackAdapter* adapter,
39 const scoped_refptr<WebRtcAudioCapturer>& capturer,
40 WebAudioCapturerSource* webaudio_source);
42 virtual ~WebRtcLocalAudioTrack();
44 // Add a sink to the track. This function will trigger a OnSetFormat()
45 // call on the |sink|.
46 // Called on the main render thread.
47 void AddSink(MediaStreamAudioSink* sink);
49 // Remove a sink from the track.
50 // Called on the main render thread.
51 void RemoveSink(MediaStreamAudioSink* sink);
53 // Add/remove PeerConnection sink to/from the track.
54 // TODO(xians): Remove these two methods after PeerConnection can use the
55 // same sink interface as MediaStreamAudioSink.
56 void AddSink(PeerConnectionAudioSink* sink);
57 void RemoveSink(PeerConnectionAudioSink* sink);
59 // Starts the local audio track. Called on the main render thread and
60 // should be called only once when audio track is created.
61 void Start();
63 // Stops the local audio track. Called on the main render thread and
64 // should be called only once when audio track going away.
65 virtual void Stop() override;
67 // Method called by the capturer to deliver the capture data.
68 // Called on the capture audio thread.
69 void Capture(const int16* audio_data,
70 base::TimeDelta delay,
71 int volume,
72 bool key_pressed,
73 bool need_audio_processing);
75 // Method called by the capturer to set the audio parameters used by source
76 // of the capture data..
77 // Called on the capture audio thread.
78 void OnSetFormat(const media::AudioParameters& params);
80 // Method called by the capturer to set the processor that applies signal
81 // processing on the data of the track.
82 // Called on the capture audio thread.
83 void SetAudioProcessor(
84 const scoped_refptr<MediaStreamAudioProcessor>& processor);
86 private:
87 typedef TaggedList<MediaStreamAudioTrackSink> SinkList;
89 // All usage of libjingle is through this adapter. The adapter holds
90 // a reference on this object, but not vice versa.
91 WebRtcLocalAudioTrackAdapter* adapter_;
93 // The provider of captured data to render.
94 scoped_refptr<WebRtcAudioCapturer> capturer_;
96 // The source of the audio track which is used by WebAudio, which provides
97 // data to the audio track when hooking up with WebAudio.
98 scoped_refptr<WebAudioCapturerSource> webaudio_source_;
100 // A tagged list of sinks that the audio data is fed to. Tags
101 // indicate tracks that need to be notified that the audio format
102 // has changed.
103 SinkList sinks_;
105 // Used to DCHECK that some methods are called on the main render thread.
106 base::ThreadChecker main_render_thread_checker_;
108 // Used to DCHECK that some methods are called on the capture audio thread.
109 base::ThreadChecker capture_thread_checker_;
111 // Protects |params_| and |sinks_|.
112 mutable base::Lock lock_;
114 // Audio parameters of the audio capture stream.
115 // Accessed on only the audio capture thread.
116 media::AudioParameters audio_parameters_;
118 // Used to calculate the signal level that shows in the UI.
119 // Accessed on only the audio thread.
120 scoped_ptr<MediaStreamAudioLevelCalculator> level_calculator_;
122 DISALLOW_COPY_AND_ASSIGN(WebRtcLocalAudioTrack);
125 } // namespace content
127 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_