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

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

Issue 139303016: Feed the render data to MediaStreamAudioProcessor and used AudioBus in render callback (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: checked echo_control_mobile()->is_enabled()) for android and ios Created 6 years, 10 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_device_impl.h
diff --git a/content/renderer/media/webrtc_audio_device_impl.h b/content/renderer/media/webrtc_audio_device_impl.h
index 15790d269c993469cf50f025851514270b372608..34dcdfb3b71de7c084fc7459bafca6f29211ceec 100644
--- a/content/renderer/media/webrtc_audio_device_impl.h
+++ b/content/renderer/media/webrtc_audio_device_impl.h
@@ -185,16 +185,11 @@ class WebRtcAudioRenderer;
// libjingle can own references to the renderer and capturer.
class WebRtcAudioRendererSource {
public:
- // Callback to get the rendered interleaved data.
- // TODO(xians): Change uint8* to int16*.
- virtual void RenderData(uint8* audio_data,
- int number_of_channels,
- int number_of_frames,
+ // Callback to get the rendered data.
+ virtual void RenderData(media::AudioBus* audio_bus,
+ int sample_rate,
int audio_delay_milliseconds) = 0;
- // Set the format for the capture audio parameters.
- virtual void SetRenderFormat(const media::AudioParameters& params) = 0;
-
// Callback to notify the client that the renderer is going away.
virtual void RemoveAudioRenderer(WebRtcAudioRenderer* renderer) = 0;
@@ -235,13 +230,40 @@ class PeerConnectionAudioSink {
virtual ~PeerConnectionAudioSink() {}
};
+// TODO(xians): Merge this interface with WebRtcAudioRendererSource.
+// The reason why we could not do it today is that WebRtcAudioRendererSource
+// gets the data by pulling, while the data is pushed into
+// WebRtcPlayoutDataSource::Sink.
+class WebRtcPlayoutDataSource {
+ public:
+ class Sink {
+ public:
+ // Callback to get the playout data.
+ virtual void OnPlayoutData(media::AudioBus* audio_bus,
+ int sample_rate,
+ int audio_delay_milliseconds) = 0;
+ protected:
+ virtual ~Sink() {}
+ };
+
+ // Adds/Removes the sink of WebRtcAudioRendererSource to the ADM.
+ // These methods are used by the MediaStreamAudioProcesssor to get the
+ // rendered data for AEC.
+ virtual void AddPlayoutSink(Sink* sink) = 0;
+ virtual void RemovePlayoutSink(Sink* sink) = 0;
+
+ protected:
+ virtual ~WebRtcPlayoutDataSource() {}
+};
+
// Note that this class inherits from webrtc::AudioDeviceModule but due to
// the high number of non-implemented methods, we move the cruft over to the
// WebRtcAudioDeviceNotImpl.
class CONTENT_EXPORT WebRtcAudioDeviceImpl
: NON_EXPORTED_BASE(public PeerConnectionAudioSink),
NON_EXPORTED_BASE(public WebRtcAudioDeviceNotImpl),
- NON_EXPORTED_BASE(public WebRtcAudioRendererSource) {
+ NON_EXPORTED_BASE(public WebRtcAudioRendererSource),
+ NON_EXPORTED_BASE(public WebRtcPlayoutDataSource) {
public:
// The maximum volume value WebRtc uses.
static const int kMaxVolumeLevel = 255;
@@ -306,6 +328,7 @@ class CONTENT_EXPORT WebRtcAudioDeviceImpl
void RemoveAudioCapturer(const scoped_refptr<WebRtcAudioCapturer>& capturer);
// Gets the default capturer, which is the last capturer in |capturers_|.
+ // The method can be called by both Libjingle thread and main render thread.
scoped_refptr<WebRtcAudioCapturer> GetDefaultCapturer() const;
// Gets paired device information of the capture device for the audio
@@ -321,18 +344,11 @@ class CONTENT_EXPORT WebRtcAudioDeviceImpl
const scoped_refptr<WebRtcAudioRenderer>& renderer() const {
return renderer_;
}
- int output_buffer_size() const {
- return output_audio_parameters_.frames_per_buffer();
- }
- int output_channels() const {
- return output_audio_parameters_.channels();
- }
- int output_sample_rate() const {
- return output_audio_parameters_.sample_rate();
- }
private:
typedef std::list<scoped_refptr<WebRtcAudioCapturer> > CapturerList;
+ typedef std::list<WebRtcPlayoutDataSource::Sink*> PlayoutDataSinkList;
+ class RenderBuffer;
// Make destructor private to ensure that we can only be deleted by Release().
virtual ~WebRtcAudioDeviceImpl();
@@ -356,15 +372,17 @@ class CONTENT_EXPORT WebRtcAudioDeviceImpl
// WebRtcAudioRendererSource implementation.
// Called on the AudioInputDevice worker thread.
- virtual void RenderData(uint8* audio_data,
- int number_of_channels,
- int number_of_frames,
+ virtual void RenderData(media::AudioBus* audio_bus,
+ int sample_rate,
int audio_delay_milliseconds) OVERRIDE;
// Called on the main render thread.
- virtual void SetRenderFormat(const media::AudioParameters& params) OVERRIDE;
virtual void RemoveAudioRenderer(WebRtcAudioRenderer* renderer) OVERRIDE;
+ // WebRtcPlayoutDataSource implementation.
+ virtual void AddPlayoutSink(WebRtcPlayoutDataSource::Sink* sink) OVERRIDE;
+ virtual void RemovePlayoutSink(WebRtcPlayoutDataSource::Sink* sink) OVERRIDE;
+
// Used to DCHECK that we are called on the correct thread.
base::ThreadChecker thread_checker_;
@@ -377,14 +395,16 @@ class CONTENT_EXPORT WebRtcAudioDeviceImpl
// Provides access to the audio renderer in the browser process.
scoped_refptr<WebRtcAudioRenderer> renderer_;
+ // A list of raw pointer of WebRtcPlayoutDataSource::Sink objects which want
+ // to get the playout data, the sink need to call RemovePlayoutSink()
+ // before it goes away.
+ PlayoutDataSinkList playout_sinks_;
+
// Weak reference to the audio callback.
// The webrtc client defines |audio_transport_callback_| by calling
// RegisterAudioCallback().
webrtc::AudioTransport* audio_transport_callback_;
- // Cached values of used output audio parameters. Platform dependent.
- media::AudioParameters output_audio_parameters_;
-
// Cached value of the current audio delay on the input/capture side.
int input_delay_ms_;
@@ -411,6 +431,10 @@ class CONTENT_EXPORT WebRtcAudioDeviceImpl
// Range is [0, 255].
uint32_t microphone_volume_;
+ // Buffer used for temporary storage during render callback.
+ // It is only accessed by the audio render thread.
+ std::vector<int16> render_buffer_;
+
DISALLOW_COPY_AND_ASSIGN(WebRtcAudioDeviceImpl);
};

Powered by Google App Engine
This is Rietveld 408576698