OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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_LOCAL_AUDIO_TRACK_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_ |
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
12 #include "base/threading/thread_checker.h" | 12 #include "base/threading/thread_checker.h" |
13 #include "content/renderer/media/webrtc_audio_device_impl.h" | 13 #include "content/renderer/media/webrtc_audio_device_impl.h" |
14 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface
.h" | 14 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface
.h" |
15 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" | 15 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" |
16 #include "third_party/libjingle/source/talk/app/webrtc/mediastreamtrack.h" | 16 #include "third_party/libjingle/source/talk/app/webrtc/mediastreamtrack.h" |
17 #include "third_party/libjingle/source/talk/media/base/audiorenderer.h" | 17 #include "third_party/libjingle/source/talk/media/base/audiorenderer.h" |
18 | 18 |
19 namespace cricket { | 19 namespace cricket { |
20 class AudioRenderer; | 20 class AudioRenderer; |
21 } | 21 } |
22 | 22 |
| 23 namespace media { |
| 24 class AudioBus; |
| 25 } |
| 26 |
23 namespace content { | 27 namespace content { |
24 | 28 |
| 29 class WebAudioCapturerSource; |
25 class WebRtcAudioCapturer; | 30 class WebRtcAudioCapturer; |
26 class WebRtcAudioCapturerSinkOwner; | 31 class WebRtcAudioCapturerSinkOwner; |
27 | 32 |
28 // A WebRtcLocalAudioTrack instance contains the implementations of | 33 // A WebRtcLocalAudioTrack instance contains the implementations of |
29 // MediaStreamTrack and WebRtcAudioCapturerSink. | 34 // MediaStreamTrack and WebRtcAudioCapturerSink. |
30 // When an instance is created, it will register itself as a track to the | 35 // When an instance is created, it will register itself as a track to the |
31 // WebRtcAudioCapturer to get the captured data, and forward the data to | 36 // WebRtcAudioCapturer to get the captured data, and forward the data to |
32 // its |sinks_|. The data flow can be stopped by disabling the audio track. | 37 // its |sinks_|. The data flow can be stopped by disabling the audio track. |
33 class CONTENT_EXPORT WebRtcLocalAudioTrack | 38 class CONTENT_EXPORT WebRtcLocalAudioTrack |
34 : NON_EXPORTED_BASE(public cricket::AudioRenderer), | 39 : NON_EXPORTED_BASE(public cricket::AudioRenderer), |
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<WebRtcLocalAudioTrack> Create( | 43 static scoped_refptr<WebRtcLocalAudioTrack> Create( |
39 const std::string& id, | 44 const std::string& id, |
40 const scoped_refptr<WebRtcAudioCapturer>& capturer, | 45 const scoped_refptr<WebRtcAudioCapturer>& capturer, |
41 webrtc::AudioSourceInterface* stream_source, | 46 WebAudioCapturerSource* webaudio_source, |
| 47 webrtc::AudioSourceInterface* track_source, |
42 const webrtc::MediaConstraintsInterface* constraints); | 48 const webrtc::MediaConstraintsInterface* constraints); |
43 | 49 |
44 // Add a sink to the track. This function will trigger a SetCaptureFormat() | 50 // Add a sink to the track. This function will trigger a SetCaptureFormat() |
45 // call on the |sink|. | 51 // call on the |sink|. |
46 // Called on the main render thread. | 52 // Called on the main render thread. |
47 void AddSink(WebRtcAudioCapturerSink* sink); | 53 void AddSink(WebRtcAudioCapturerSink* sink); |
48 | 54 |
49 // Remove a sink from the track. | 55 // Remove a sink from the track. |
50 // Called on the main render thread. | 56 // Called on the main render thread. |
51 void RemoveSink(WebRtcAudioCapturerSink* sink); | 57 void RemoveSink(WebRtcAudioCapturerSink* sink); |
52 | 58 |
53 // Starts the local audio track. Called on the main render thread and | 59 // Starts the local audio track. Called on the main render thread and |
54 // should be called only once when audio track is created. | 60 // should be called only once when audio track is created. |
55 void Start(); | 61 void Start(); |
56 | 62 |
57 // Stops the local audio track. Called on the main render thread and | 63 // Stops the local audio track. Called on the main render thread and |
58 // should be called only once when audio track going away. | 64 // should be called only once when audio track going away. |
59 void Stop(); | 65 void Stop(); |
60 | 66 |
61 // Method called by the capturer to deliever the capture data. | 67 // Method called by the capturer to deliver the capture data. |
62 void CaptureData(const int16* audio_data, | 68 void Capture(media::AudioBus* audio_source, |
63 int number_of_channels, | 69 int audio_delay_milliseconds, |
64 int number_of_frames, | 70 int volume, |
65 int audio_delay_milliseconds, | 71 bool key_pressed); |
66 int volume, | |
67 bool key_pressed); | |
68 | 72 |
69 // Method called by the capturer to set the audio parameters used by source | 73 // Method called by the capturer to set the audio parameters used by source |
70 // of the capture data.. | 74 // of the capture data.. |
71 // Can be called on different user threads. | 75 // Can be called on different user threads. |
72 void SetCaptureFormat(const media::AudioParameters& params); | 76 void SetCaptureFormat(const media::AudioParameters& params); |
73 | 77 |
74 protected: | 78 protected: |
75 WebRtcLocalAudioTrack(const std::string& label, | 79 WebRtcLocalAudioTrack( |
76 const scoped_refptr<WebRtcAudioCapturer>& capturer, | 80 const std::string& label, |
77 webrtc::AudioSourceInterface* track_source, | 81 const scoped_refptr<WebRtcAudioCapturer>& capturer, |
78 const webrtc::MediaConstraintsInterface* constraints); | 82 WebAudioCapturerSource* webaudio_source, |
| 83 webrtc::AudioSourceInterface* track_source, |
| 84 const webrtc::MediaConstraintsInterface* constraints); |
| 85 |
79 virtual ~WebRtcLocalAudioTrack(); | 86 virtual ~WebRtcLocalAudioTrack(); |
80 | 87 |
81 private: | 88 private: |
82 typedef std::list<scoped_refptr<WebRtcAudioCapturerSinkOwner> > SinkList; | 89 typedef std::list<scoped_refptr<WebRtcAudioCapturerSinkOwner> > SinkList; |
83 | 90 |
84 // cricket::AudioCapturer implementation. | 91 // cricket::AudioCapturer implementation. |
85 virtual void AddChannel(int channel_id) OVERRIDE; | 92 virtual void AddChannel(int channel_id) OVERRIDE; |
86 virtual void RemoveChannel(int channel_id) OVERRIDE; | 93 virtual void RemoveChannel(int channel_id) OVERRIDE; |
87 | 94 |
88 // webrtc::AudioTrackInterface implementation. | 95 // webrtc::AudioTrackInterface implementation. |
89 virtual webrtc::AudioSourceInterface* GetSource() const OVERRIDE; | 96 virtual webrtc::AudioSourceInterface* GetSource() const OVERRIDE; |
90 virtual cricket::AudioRenderer* GetRenderer() OVERRIDE; | 97 virtual cricket::AudioRenderer* GetRenderer() OVERRIDE; |
91 | 98 |
92 // webrtc::MediaStreamTrack implementation. | 99 // webrtc::MediaStreamTrack implementation. |
93 virtual std::string kind() const OVERRIDE; | 100 virtual std::string kind() const OVERRIDE; |
94 | 101 |
95 // The provider of captured data to render. | 102 // The provider of captured data to render. |
96 // The WebRtcAudioCapturer is today created by WebRtcAudioDeviceImpl. | 103 // The WebRtcAudioCapturer is today created by WebRtcAudioDeviceImpl. |
97 scoped_refptr<WebRtcAudioCapturer> capturer_; | 104 scoped_refptr<WebRtcAudioCapturer> capturer_; |
98 | 105 |
| 106 // The source of the audio track which is used by WebAudio, which provides |
| 107 // data to the audio track when hooking up with WebAudio. |
| 108 scoped_refptr<WebAudioCapturerSource> webaudio_source_; |
| 109 |
99 // The source of the audio track which handles the audio constraints. | 110 // The source of the audio track which handles the audio constraints. |
100 // TODO(xians): merge |track_source_| to |capturer_|. | 111 // TODO(xians): merge |track_source_| to |capturer_|. |
101 talk_base::scoped_refptr<webrtc::AudioSourceInterface> track_source_; | 112 talk_base::scoped_refptr<webrtc::AudioSourceInterface> track_source_; |
102 | 113 |
103 // A list of sinks that the audio data is fed to. | 114 // A list of sinks that the audio data is fed to. |
104 SinkList sinks_; | 115 SinkList sinks_; |
105 | 116 |
106 // Used to DCHECK that we are called on the correct thread. | 117 // Used to DCHECK that we are called on the correct thread. |
107 base::ThreadChecker thread_checker_; | 118 base::ThreadChecker thread_checker_; |
108 | 119 |
109 // Cached values of the audio parameters used by the |source_| and |sinks_|. | |
110 media::AudioParameters params_; | |
111 | |
112 // Protects |params_| and |sinks_|. | 120 // Protects |params_| and |sinks_|. |
113 mutable base::Lock lock_; | 121 mutable base::Lock lock_; |
114 | 122 |
115 // A vector of WebRtc VoE channels that the capturer sends datat to. | 123 // A vector of WebRtc VoE channels that the capturer sends datat to. |
116 std::vector<int> voe_channels_; | 124 std::vector<int> voe_channels_; |
117 | 125 |
118 bool need_audio_processing_; | 126 bool need_audio_processing_; |
119 | 127 |
| 128 // Buffers used for temporary storage during capture callbacks. |
| 129 // Allocated during initialization. |
| 130 class ConfiguredBuffer; |
| 131 scoped_refptr<ConfiguredBuffer> buffer_; |
| 132 |
120 DISALLOW_COPY_AND_ASSIGN(WebRtcLocalAudioTrack); | 133 DISALLOW_COPY_AND_ASSIGN(WebRtcLocalAudioTrack); |
121 }; | 134 }; |
122 | 135 |
123 } // namespace content | 136 } // namespace content |
124 | 137 |
125 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_ | 138 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_ |
OLD | NEW |