summaryrefslogtreecommitdiffstats
path: root/chromium/content/renderer/media/webrtc_audio_capturer.h
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/content/renderer/media/webrtc_audio_capturer.h')
-rw-r--r--chromium/content/renderer/media/webrtc_audio_capturer.h150
1 files changed, 85 insertions, 65 deletions
diff --git a/chromium/content/renderer/media/webrtc_audio_capturer.h b/chromium/content/renderer/media/webrtc_audio_capturer.h
index 23391140411..d77a107dbca 100644
--- a/chromium/content/renderer/media/webrtc_audio_capturer.h
+++ b/chromium/content/renderer/media/webrtc_audio_capturer.h
@@ -9,14 +9,17 @@
#include <string>
#include "base/callback.h"
+#include "base/files/file.h"
#include "base/memory/ref_counted.h"
#include "base/synchronization/lock.h"
#include "base/threading/thread_checker.h"
#include "base/time/time.h"
+#include "content/common/media/media_stream_options.h"
#include "content/renderer/media/tagged_list.h"
-#include "content/renderer/media/webrtc_audio_device_impl.h"
#include "media/audio/audio_input_device.h"
+#include "media/audio/audio_power_monitor.h"
#include "media/base/audio_capturer_source.h"
+#include "third_party/WebKit/public/platform/WebMediaConstraints.h"
namespace media {
class AudioBus;
@@ -24,13 +27,14 @@ class AudioBus;
namespace content {
+class MediaStreamAudioProcessor;
+class MediaStreamAudioSource;
+class WebRtcAudioDeviceImpl;
class WebRtcLocalAudioRenderer;
class WebRtcLocalAudioTrack;
// This class manages the capture data flow by getting data from its
// |source_|, and passing it to its |tracks_|.
-// It allows clients to inject their own capture data source by calling
-// SetCapturerSource().
// The threading model for this class is rather complex since it will be
// created on the main render thread, captured data is provided on a dedicated
// AudioInputDevice thread, and methods can be called either on the Libjingle
@@ -40,31 +44,29 @@ class CONTENT_EXPORT WebRtcAudioCapturer
: public base::RefCountedThreadSafe<WebRtcAudioCapturer>,
NON_EXPORTED_BASE(public media::AudioCapturerSource::CaptureCallback) {
public:
- // Use to construct the audio capturer.
+ // Used to construct the audio capturer. |render_view_id| specifies the
+ // render view consuming audio for capture, |render_view_id| as -1 is used
+ // by the unittests to skip creating a source via
+ // AudioDeviceFactory::NewInputDevice(), and allow injecting their own source
+ // via SetCapturerSourceForTesting() at a later state. |device_info|
+ // contains all the device information that the capturer is created for.
+ // |constraints| contains the settings for audio processing.
+ // TODO(xians): Implement the interface for the audio source and move the
+ // |constraints| to ApplyConstraints().
// Called on the main render thread.
- static scoped_refptr<WebRtcAudioCapturer> CreateCapturer();
-
- // Creates and configures the default audio capturing source using the
- // provided audio parameters. |render_view_id| specifies the render view
- // consuming audio for capture. |session_id| is passed to the browser to
- // decide which device to use. |device_id| is used to identify which device
- // the capturer is created for. Called on the main render thread.
- bool Initialize(int render_view_id,
- media::ChannelLayout channel_layout,
- int sample_rate,
- int buffer_size,
- int session_id,
- const std::string& device_id,
- int paired_output_sample_rate,
- int paired_output_frames_per_buffer,
- int effects);
+ static scoped_refptr<WebRtcAudioCapturer> CreateCapturer(
+ int render_view_id,
+ const StreamDeviceInfo& device_info,
+ const blink::WebMediaConstraints& constraints,
+ WebRtcAudioDeviceImpl* audio_device,
+ MediaStreamAudioSource* audio_source);
+
// Add a audio track to the sinks of the capturer.
// WebRtcAudioDeviceImpl calls this method on the main render thread but
// other clients may call it from other threads. The current implementation
// does not support multi-thread calling.
// The first AddTrack will implicitly trigger the Start() of this object.
- // Called on the main render thread or libjingle working thread.
void AddTrack(WebRtcLocalAudioTrack* track);
// Remove a audio track from the sinks of the capturer.
@@ -73,16 +75,6 @@ class CONTENT_EXPORT WebRtcAudioCapturer
// Called on the main render thread or libjingle working thread.
void RemoveTrack(WebRtcLocalAudioTrack* track);
- // SetCapturerSource() is called if the client on the source side desires to
- // provide their own captured audio data. Client is responsible for calling
- // Start() on its own source to have the ball rolling.
- // Called on the main render thread.
- void SetCapturerSource(
- const scoped_refptr<media::AudioCapturerSource>& source,
- media::ChannelLayout channel_layout,
- float sample_rate,
- int effects);
-
// Called when a stream is connecting to a peer connection. This will set
// up the native buffer size for the stream in order to optimize the
// performance for peer connection.
@@ -94,15 +86,10 @@ class CONTENT_EXPORT WebRtcAudioCapturer
int Volume() const;
int MaxVolume() const;
- bool is_recording() const { return running_; }
-
- // Audio parameters utilized by the audio capturer. Can be utilized by
- // a local renderer to set up a renderer using identical parameters as the
- // capturer.
- // TODO(phoglund): This accessor is inherently unsafe since the returned
- // parameters can become outdated at any time. Think over the implications
- // of this accessor and if we can remove it.
- media::AudioParameters audio_parameters() const;
+ // Audio parameters utilized by the source of the audio capturer.
+ // TODO(phoglund): Think over the implications of this accessor and if we can
+ // remove it.
+ media::AudioParameters source_audio_parameters() const;
// Gets information about the paired output device. Returns true if such a
// device exists.
@@ -110,13 +97,13 @@ class CONTENT_EXPORT WebRtcAudioCapturer
int* output_sample_rate,
int* output_frames_per_buffer) const;
- const std::string& device_id() const { return device_id_; }
- int session_id() const { return session_id_; }
+ const std::string& device_id() const { return device_info_.device.id; }
+ int session_id() const { return device_info_.session_id; }
// Stops recording audio. This method will empty its track lists since
// stopping the capturer will implicitly invalidate all its tracks.
- // This method is exposed to the public because the media stream track can
- // call Stop() on its source.
+ // This method is exposed to the public because the MediaStreamAudioSource can
+ // call Stop()
void Stop();
// Called by the WebAudioCapturerSource to get the audio processing params.
@@ -125,27 +112,45 @@ class CONTENT_EXPORT WebRtcAudioCapturer
void GetAudioProcessingParams(base::TimeDelta* delay, int* volume,
bool* key_pressed);
+ // Used by the unittests to inject their own source to the capturer.
+ void SetCapturerSourceForTesting(
+ const scoped_refptr<media::AudioCapturerSource>& source,
+ media::AudioParameters params);
+
protected:
friend class base::RefCountedThreadSafe<WebRtcAudioCapturer>;
- WebRtcAudioCapturer();
virtual ~WebRtcAudioCapturer();
private:
class TrackOwner;
typedef TaggedList<TrackOwner> TrackList;
+ WebRtcAudioCapturer(int render_view_id,
+ const StreamDeviceInfo& device_info,
+ const blink::WebMediaConstraints& constraints,
+ WebRtcAudioDeviceImpl* audio_device,
+ MediaStreamAudioSource* audio_source);
+
// AudioCapturerSource::CaptureCallback implementation.
// Called on the AudioInputDevice audio thread.
- virtual void Capture(media::AudioBus* audio_source,
+ virtual void Capture(const media::AudioBus* audio_source,
int audio_delay_milliseconds,
double volume,
bool key_pressed) OVERRIDE;
virtual void OnCaptureError() OVERRIDE;
- // Reconfigures the capturer with a new capture parameters.
- // Must be called without holding the lock.
- void Reconfigure(int sample_rate, media::ChannelLayout channel_layout,
- int effects);
+ // Initializes the default audio capturing source using the provided render
+ // view id and device information. Return true if success, otherwise false.
+ bool Initialize();
+
+ // SetCapturerSource() is called if the client on the source side desires to
+ // provide their own captured audio data. Client is responsible for calling
+ // Start() on its own source to have the ball rolling.
+ // Called on the main render thread.
+ void SetCapturerSource(
+ const scoped_refptr<media::AudioCapturerSource>& source,
+ media::ChannelLayout channel_layout,
+ float sample_rate);
// Starts recording audio.
// Triggered by AddSink() on the main render thread or a Libjingle working
@@ -171,23 +176,19 @@ class CONTENT_EXPORT WebRtcAudioCapturer
// The audio data source from the browser process.
scoped_refptr<media::AudioCapturerSource> source_;
- // Cached audio parameters for output.
- media::AudioParameters params_;
+ // Cached audio constraints for the capturer.
+ blink::WebMediaConstraints constraints_;
+
+ // Audio processor doing processing like FIFO, AGC, AEC and NS. Its output
+ // data is in a unit of 10 ms data chunk.
+ scoped_refptr<MediaStreamAudioProcessor> audio_processor_;
bool running_;
int render_view_id_;
- // Cached value for the hardware native buffer size, used when
- // |peer_connection_mode_| is set to false.
- int hardware_buffer_size_;
-
- // The media session ID used to identify which input device to be started by
- // the browser.
- int session_id_;
-
- // The device this capturer is given permission to use.
- std::string device_id_;
+ // Cached information of the device used by the capturer.
+ const StreamDeviceInfo device_info_;
// Stores latest microphone volume received in a CaptureData() callback.
// Range is [0, 255].
@@ -196,13 +197,32 @@ class CONTENT_EXPORT WebRtcAudioCapturer
// Flag which affects the buffer size used by the capturer.
bool peer_connection_mode_;
- int output_sample_rate_;
- int output_frames_per_buffer_;
-
// Cache value for the audio processing params.
base::TimeDelta audio_delay_;
bool key_pressed_;
+ // Flag to help deciding if the data needs audio processing.
+ bool need_audio_processing_;
+
+ // Raw pointer to the WebRtcAudioDeviceImpl, which is valid for the lifetime
+ // of RenderThread.
+ WebRtcAudioDeviceImpl* audio_device_;
+
+ // Raw pointer to the MediaStreamAudioSource object that holds a reference
+ // to this WebRtcAudioCapturer.
+ // Since |audio_source_| is owned by a blink::WebMediaStreamSource object and
+ // blink guarantees that the blink::WebMediaStreamSource outlives any
+ // blink::WebMediaStreamTrack connected to the source, |audio_source_| is
+ // guaranteed to exist as long as a WebRtcLocalAudioTrack is connected to this
+ // WebRtcAudioCapturer.
+ MediaStreamAudioSource* const audio_source_;
+
+ // Audio power monitor for logging audio power level.
+ media::AudioPowerMonitor audio_power_monitor_;
+
+ // Records when the last time audio power level is logged.
+ base::TimeTicks last_audio_level_log_time_;
+
DISALLOW_COPY_AND_ASSIGN(WebRtcAudioCapturer);
};