Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3153)

Unified Diff: content/renderer/media/webrtc_audio_capturer.h

Issue 133903004: Cleaned up the WebRtcAudioCapturer a bit. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased and fixed the comment. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/webrtc_audio_capturer.h
diff --git a/content/renderer/media/webrtc_audio_capturer.h b/content/renderer/media/webrtc_audio_capturer.h
index 1763a371386b7b095d79cd63b11cabbbaf6731d3..986016d38711df24e72b4cfdc5cb31797637b5de 100644
--- a/content/renderer/media/webrtc_audio_capturer.h
+++ b/content/renderer/media/webrtc_audio_capturer.h
@@ -13,8 +13,8 @@
#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/base/audio_capturer_source.h"
#include "third_party/WebKit/public/platform/WebMediaConstraints.h"
@@ -26,13 +26,12 @@ class AudioBus;
namespace content {
class MediaStreamAudioProcessor;
+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
@@ -42,35 +41,28 @@ 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();
+ static scoped_refptr<WebRtcAudioCapturer> CreateCapturer(
+ int render_view_id,
+ const StreamDeviceInfo& device_info,
+ const blink::WebMediaConstraints& constraints,
+ WebRtcAudioDeviceImpl* audio_device);
- // 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.
- // TODO(xians): Implement the interface for the audio source and move the
- // |constraints| to AddTrack().
- 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,
- const blink::WebMediaConstraints& constraints);
// 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.
- // TODO(xians): Pass the track constraints via AddTrack().
void AddTrack(WebRtcLocalAudioTrack* track);
// Remove a audio track from the sinks of the capturer.
@@ -79,17 +71,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,
- const blink::WebMediaConstraints& constraints);
-
// 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.
@@ -101,7 +82,6 @@ class CONTENT_EXPORT WebRtcAudioCapturer
int Volume() const;
int MaxVolume() const;
- bool is_recording() const { return running_; }
// Audio parameters utilized by the source of the audio capturer.
// TODO(phoglund): Think over the implications of this accessor and if we can
@@ -114,8 +94,8 @@ 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.
@@ -137,15 +117,24 @@ class CONTENT_EXPORT WebRtcAudioCapturer
int number_of_frames,
base::TimeDelta render_delay);
+ // Use 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);
+
// AudioCapturerSource::CaptureCallback implementation.
// Called on the AudioInputDevice audio thread.
virtual void Capture(media::AudioBus* audio_source,
@@ -154,6 +143,21 @@ class CONTENT_EXPORT WebRtcAudioCapturer
bool key_pressed) OVERRIDE;
virtual void OnCaptureError() OVERRIDE;
+ // 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,
+ int effects,
+ const blink::WebMediaConstraints& constraints);
+
// Starts recording audio.
// Triggered by AddSink() on the main render thread or a Libjingle working
// thread. It should NOT be called under |lock_|.
@@ -189,16 +193,8 @@ class CONTENT_EXPORT WebRtcAudioCapturer
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].
@@ -207,9 +203,6 @@ 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_;
@@ -217,6 +210,10 @@ class CONTENT_EXPORT WebRtcAudioCapturer
// 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_;
+
DISALLOW_COPY_AND_ASSIGN(WebRtcAudioCapturer);
};
« no previous file with comments | « content/renderer/media/rtc_peer_connection_handler.cc ('k') | content/renderer/media/webrtc_audio_capturer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698