| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_AUDIO_CAPTURER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "media/base/audio_capturer_source.h" | 21 #include "media/base/audio_capturer_source.h" |
| 22 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 22 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
| 23 | 23 |
| 24 namespace media { | 24 namespace media { |
| 25 class AudioBus; | 25 class AudioBus; |
| 26 } | 26 } |
| 27 | 27 |
| 28 namespace content { | 28 namespace content { |
| 29 | 29 |
| 30 class MediaStreamAudioProcessor; | 30 class MediaStreamAudioProcessor; |
| 31 class MediaStreamAudioSource; |
| 31 class WebRtcAudioDeviceImpl; | 32 class WebRtcAudioDeviceImpl; |
| 32 class WebRtcLocalAudioRenderer; | 33 class WebRtcLocalAudioRenderer; |
| 33 class WebRtcLocalAudioTrack; | 34 class WebRtcLocalAudioTrack; |
| 34 | 35 |
| 35 // This class manages the capture data flow by getting data from its | 36 // This class manages the capture data flow by getting data from its |
| 36 // |source_|, and passing it to its |tracks_|. | 37 // |source_|, and passing it to its |tracks_|. |
| 37 // The threading model for this class is rather complex since it will be | 38 // The threading model for this class is rather complex since it will be |
| 38 // created on the main render thread, captured data is provided on a dedicated | 39 // created on the main render thread, captured data is provided on a dedicated |
| 39 // AudioInputDevice thread, and methods can be called either on the Libjingle | 40 // AudioInputDevice thread, and methods can be called either on the Libjingle |
| 40 // thread or on the main render thread but also other client threads | 41 // thread or on the main render thread but also other client threads |
| 41 // if an alternative AudioCapturerSource has been set. | 42 // if an alternative AudioCapturerSource has been set. |
| 42 class CONTENT_EXPORT WebRtcAudioCapturer | 43 class CONTENT_EXPORT WebRtcAudioCapturer |
| 43 : public base::RefCountedThreadSafe<WebRtcAudioCapturer>, | 44 : public base::RefCountedThreadSafe<WebRtcAudioCapturer>, |
| 44 NON_EXPORTED_BASE(public media::AudioCapturerSource::CaptureCallback) { | 45 NON_EXPORTED_BASE(public media::AudioCapturerSource::CaptureCallback) { |
| 45 public: | 46 public: |
| 46 // Used to construct the audio capturer. |render_view_id| specifies the | 47 // Used to construct the audio capturer. |render_view_id| specifies the |
| 47 // render view consuming audio for capture, |render_view_id| as -1 is used | 48 // render view consuming audio for capture, |render_view_id| as -1 is used |
| 48 // by the unittests to skip creating a source via | 49 // by the unittests to skip creating a source via |
| 49 // AudioDeviceFactory::NewInputDevice(), and allow injecting their own source | 50 // AudioDeviceFactory::NewInputDevice(), and allow injecting their own source |
| 50 // via SetCapturerSourceForTesting() at a later state. |device_info| | 51 // via SetCapturerSourceForTesting() at a later state. |device_info| |
| 51 // contains all the device information that the capturer is created for. | 52 // contains all the device information that the capturer is created for. |
| 52 // |constraints| contains the settings for audio processing. | 53 // |constraints| contains the settings for audio processing. |
| 53 // TODO(xians): Implement the interface for the audio source and move the | 54 // TODO(xians): Implement the interface for the audio source and move the |
| 54 // |constraints| to ApplyConstraints(). | 55 // |constraints| to ApplyConstraints(). |
| 55 // Called on the main render thread. | 56 // Called on the main render thread. |
| 56 static scoped_refptr<WebRtcAudioCapturer> CreateCapturer( | 57 static scoped_refptr<WebRtcAudioCapturer> CreateCapturer( |
| 57 int render_view_id, | 58 int render_view_id, |
| 58 const StreamDeviceInfo& device_info, | 59 const StreamDeviceInfo& device_info, |
| 59 const blink::WebMediaConstraints& constraints, | 60 const blink::WebMediaConstraints& constraints, |
| 60 WebRtcAudioDeviceImpl* audio_device); | 61 WebRtcAudioDeviceImpl* audio_device, |
| 62 MediaStreamAudioSource* audio_source); |
| 61 | 63 |
| 62 | 64 |
| 63 // Add a audio track to the sinks of the capturer. | 65 // Add a audio track to the sinks of the capturer. |
| 64 // WebRtcAudioDeviceImpl calls this method on the main render thread but | 66 // WebRtcAudioDeviceImpl calls this method on the main render thread but |
| 65 // other clients may call it from other threads. The current implementation | 67 // other clients may call it from other threads. The current implementation |
| 66 // does not support multi-thread calling. | 68 // does not support multi-thread calling. |
| 67 // The first AddTrack will implicitly trigger the Start() of this object. | 69 // The first AddTrack will implicitly trigger the Start() of this object. |
| 68 void AddTrack(WebRtcLocalAudioTrack* track); | 70 void AddTrack(WebRtcLocalAudioTrack* track); |
| 69 | 71 |
| 70 // Remove a audio track from the sinks of the capturer. | 72 // Remove a audio track from the sinks of the capturer. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 93 // device exists. | 95 // device exists. |
| 94 bool GetPairedOutputParameters(int* session_id, | 96 bool GetPairedOutputParameters(int* session_id, |
| 95 int* output_sample_rate, | 97 int* output_sample_rate, |
| 96 int* output_frames_per_buffer) const; | 98 int* output_frames_per_buffer) const; |
| 97 | 99 |
| 98 const std::string& device_id() const { return device_info_.device.id; } | 100 const std::string& device_id() const { return device_info_.device.id; } |
| 99 int session_id() const { return device_info_.session_id; } | 101 int session_id() const { return device_info_.session_id; } |
| 100 | 102 |
| 101 // Stops recording audio. This method will empty its track lists since | 103 // Stops recording audio. This method will empty its track lists since |
| 102 // stopping the capturer will implicitly invalidate all its tracks. | 104 // stopping the capturer will implicitly invalidate all its tracks. |
| 103 // This method is exposed to the public because the media stream track can | 105 // This method is exposed to the public because the MediaStreamAudioSource can |
| 104 // call Stop() on its source. | 106 // call Stop() |
| 105 void Stop(); | 107 void Stop(); |
| 106 | 108 |
| 107 // Called by the WebAudioCapturerSource to get the audio processing params. | 109 // Called by the WebAudioCapturerSource to get the audio processing params. |
| 108 // This function is triggered by provideInput() on the WebAudio audio thread, | 110 // This function is triggered by provideInput() on the WebAudio audio thread, |
| 109 // TODO(xians): Remove after moving APM from WebRtc to Chrome. | 111 // TODO(xians): Remove after moving APM from WebRtc to Chrome. |
| 110 void GetAudioProcessingParams(base::TimeDelta* delay, int* volume, | 112 void GetAudioProcessingParams(base::TimeDelta* delay, int* volume, |
| 111 bool* key_pressed); | 113 bool* key_pressed); |
| 112 | 114 |
| 113 // Used by the unittests to inject their own source to the capturer. | 115 // Used by the unittests to inject their own source to the capturer. |
| 114 void SetCapturerSourceForTesting( | 116 void SetCapturerSourceForTesting( |
| 115 const scoped_refptr<media::AudioCapturerSource>& source, | 117 const scoped_refptr<media::AudioCapturerSource>& source, |
| 116 media::AudioParameters params); | 118 media::AudioParameters params); |
| 117 | 119 |
| 118 void StartAecDump(const base::PlatformFile& aec_dump_file); | 120 void StartAecDump(const base::PlatformFile& aec_dump_file); |
| 119 void StopAecDump(); | 121 void StopAecDump(); |
| 120 | 122 |
| 121 protected: | 123 protected: |
| 122 friend class base::RefCountedThreadSafe<WebRtcAudioCapturer>; | 124 friend class base::RefCountedThreadSafe<WebRtcAudioCapturer>; |
| 123 virtual ~WebRtcAudioCapturer(); | 125 virtual ~WebRtcAudioCapturer(); |
| 124 | 126 |
| 125 private: | 127 private: |
| 126 class TrackOwner; | 128 class TrackOwner; |
| 127 typedef TaggedList<TrackOwner> TrackList; | 129 typedef TaggedList<TrackOwner> TrackList; |
| 128 | 130 |
| 129 WebRtcAudioCapturer(int render_view_id, | 131 WebRtcAudioCapturer(int render_view_id, |
| 130 const StreamDeviceInfo& device_info, | 132 const StreamDeviceInfo& device_info, |
| 131 const blink::WebMediaConstraints& constraints, | 133 const blink::WebMediaConstraints& constraints, |
| 132 WebRtcAudioDeviceImpl* audio_device); | 134 WebRtcAudioDeviceImpl* audio_device, |
| 135 MediaStreamAudioSource* audio_source); |
| 133 | 136 |
| 134 // AudioCapturerSource::CaptureCallback implementation. | 137 // AudioCapturerSource::CaptureCallback implementation. |
| 135 // Called on the AudioInputDevice audio thread. | 138 // Called on the AudioInputDevice audio thread. |
| 136 virtual void Capture(media::AudioBus* audio_source, | 139 virtual void Capture(media::AudioBus* audio_source, |
| 137 int audio_delay_milliseconds, | 140 int audio_delay_milliseconds, |
| 138 double volume, | 141 double volume, |
| 139 bool key_pressed) OVERRIDE; | 142 bool key_pressed) OVERRIDE; |
| 140 virtual void OnCaptureError() OVERRIDE; | 143 virtual void OnCaptureError() OVERRIDE; |
| 141 | 144 |
| 142 // Initializes the default audio capturing source using the provided render | 145 // Initializes the default audio capturing source using the provided render |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 base::TimeDelta audio_delay_; | 204 base::TimeDelta audio_delay_; |
| 202 bool key_pressed_; | 205 bool key_pressed_; |
| 203 | 206 |
| 204 // Flag to help deciding if the data needs audio processing. | 207 // Flag to help deciding if the data needs audio processing. |
| 205 bool need_audio_processing_; | 208 bool need_audio_processing_; |
| 206 | 209 |
| 207 // Raw pointer to the WebRtcAudioDeviceImpl, which is valid for the lifetime | 210 // Raw pointer to the WebRtcAudioDeviceImpl, which is valid for the lifetime |
| 208 // of RenderThread. | 211 // of RenderThread. |
| 209 WebRtcAudioDeviceImpl* audio_device_; | 212 WebRtcAudioDeviceImpl* audio_device_; |
| 210 | 213 |
| 211 // Audio power monitor for logging audio power level. | 214 // Raw pointer to the MediaStreamAudioSource object that holds a reference |
| 215 // to this WebRtcAudioCapturer. |
| 216 // Since |audio_source_| is owned by a blink::WebMediaStreamSource object and |
| 217 // blink guarantees that the blink::WebMediaStreamSource outlives any |
| 218 // blink::WebMediaStreamTrack connected to the source, |audio_source_| is |
| 219 // guaranteed to exist as long as a WebRtcLocalAudioTrack is connected to this |
| 220 // WebRtcAudioCapturer. |
| 221 MediaStreamAudioSource* const audio_source_; |
| 222 |
| 223 // Audio power monitor for logging audio power level. |
| 212 media::AudioPowerMonitor audio_power_monitor_; | 224 media::AudioPowerMonitor audio_power_monitor_; |
| 213 | 225 |
| 214 // Records when the last time audio power level is logged. | 226 // Records when the last time audio power level is logged. |
| 215 base::TimeTicks last_audio_level_log_time_; | 227 base::TimeTicks last_audio_level_log_time_; |
| 216 | 228 |
| 217 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioCapturer); | 229 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioCapturer); |
| 218 }; | 230 }; |
| 219 | 231 |
| 220 } // namespace content | 232 } // namespace content |
| 221 | 233 |
| 222 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ | 234 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ |
| OLD | NEW |