Skip to content

Commit

Permalink
Merge AudioRendererImpl and AudioRendererBase; add NullAudioSink
Browse files Browse the repository at this point in the history
This CL removes AudioRendererImpl and replaces it with AudioRendererBase.
NullAudioRenderer is also removed and replaced with NullAudioSink.
Also, a subtle bug is fixed in AudioRendererBase to allow for smooth
video playback when running Chrome with the --disable-audio flag.

BUG=119549,116645
TEST=media_unittests, playing video on Chrome/content_shell with and without --disable-audio flag should look identical


Review URL: http://codereview.chromium.org/9826023

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131089 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
vrk@chromium.org committed Apr 6, 2012
1 parent f2ebbf0 commit e4fc09e
Show file tree
Hide file tree
Showing 33 changed files with 633 additions and 978 deletions.
2 changes: 0 additions & 2 deletions content/content_renderer.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@
'renderer/media/audio_input_message_filter.h',
'renderer/media/audio_message_filter.cc',
'renderer/media/audio_message_filter.h',
'renderer/media/audio_renderer_impl.cc',
'renderer/media/audio_renderer_impl.h',
'renderer/media/capture_video_decoder.cc',
'renderer/media/capture_video_decoder.h',
'renderer/media/media_stream_center.h',
Expand Down
1 change: 0 additions & 1 deletion content/content_tests.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@
'renderer/active_notification_tracker_unittest.cc',
'renderer/gpu/input_event_filter_unittest.cc',
'renderer/media/audio_message_filter_unittest.cc',
'renderer/media/audio_renderer_impl_unittest.cc',
'renderer/media/capture_video_decoder_unittest.cc',
'renderer/media/video_capture_impl_unittest.cc',
'renderer/media/video_capture_message_filter_unittest.cc',
Expand Down
9 changes: 3 additions & 6 deletions content/renderer/media/audio_device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ void AudioDevice::Initialize(const media::AudioParameters& params,
CHECK(!callback_); // Calling Initialize() twice?

audio_parameters_ = params;
audio_parameters_.Reset(
params.format(),
params.channel_layout(), params.sample_rate(), params.bits_per_sample(),
params.frames_per_buffer());
callback_ = callback;
}

Expand All @@ -85,7 +81,8 @@ AudioDevice::~AudioDevice() {
void AudioDevice::Start() {
DCHECK(callback_) << "Initialize hasn't been called";
message_loop()->PostTask(FROM_HERE,
base::Bind(&AudioDevice::InitializeOnIOThread, this, audio_parameters_));
base::Bind(&AudioDevice::CreateStreamOnIOThread, this,
audio_parameters_));
}

void AudioDevice::Stop() {
Expand Down Expand Up @@ -127,7 +124,7 @@ void AudioDevice::GetVolume(double* volume) {
*volume = volume_;
}

void AudioDevice::InitializeOnIOThread(const media::AudioParameters& params) {
void AudioDevice::CreateStreamOnIOThread(const media::AudioParameters& params) {
DCHECK(message_loop()->BelongsToCurrentThread());
// Make sure we don't create the stream more than once.
DCHECK_EQ(0, stream_id_);
Expand Down
20 changes: 2 additions & 18 deletions content/renderer/media/audio_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
//
// Task [IO thread] IPC [IO thread]
//
// Start -> InitializeOnIOThread ------> AudioHostMsg_CreateStream -------->
// Start -> CreateStreamOnIOThread -----> AudioHostMsg_CreateStream ------>
// <- OnStreamCreated <- AudioMsg_NotifyStreamCreated <-
// ---> PlayOnIOThread -----------> AudioHostMsg_PlayStream -------->
//
Expand Down Expand Up @@ -96,27 +96,11 @@ class CONTENT_EXPORT AudioDevice

virtual void Initialize(const media::AudioParameters& params,
RenderCallback* callback) OVERRIDE;
// Starts audio playback.
virtual void Start() OVERRIDE;

// Stops audio playback.
virtual void Stop() OVERRIDE;

// Resumes playback if currently paused.
virtual void Play() OVERRIDE;

// Pauses playback.
// If |flush| is true then any pending audio that is in the pipeline
// (has not yet reached the hardware) will be discarded. In this case,
// when Play() is later called, no previous pending audio will be
// rendered.
virtual void Pause(bool flush) OVERRIDE;

// Sets the playback volume, with range [0.0, 1.0] inclusive.
// Returns |true| on success.
virtual bool SetVolume(double volume) OVERRIDE;

// Gets the playback volume, with range [0.0, 1.0] inclusive.
virtual void GetVolume(double* volume) OVERRIDE;

// Methods called on IO thread ----------------------------------------------
Expand All @@ -136,7 +120,7 @@ class CONTENT_EXPORT AudioDevice
// The following methods are tasks posted on the IO thread that needs to
// be executed on that thread. They interact with AudioMessageFilter and
// sends IPC messages on that thread.
void InitializeOnIOThread(const media::AudioParameters& params);
void CreateStreamOnIOThread(const media::AudioParameters& params);
void PlayOnIOThread();
void PauseOnIOThread(bool flush);
void ShutDownOnIOThread();
Expand Down
30 changes: 0 additions & 30 deletions content/renderer/media/audio_hardware.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,36 +48,6 @@ size_t GetOutputBufferSize() {
return output_buffer_size;
}

size_t GetHighLatencyOutputBufferSize(int sample_rate) {
// TODO(vrk/crogers): The buffer sizes that this function computes is probably
// overly conservative. However, reducing the buffer size to 2048-8192 bytes
// caused crbug.com/108396. This computation should be revisited while making
// sure crbug.com/108396 doesn't happen again.

// The minimum number of samples in a hardware packet.
// This value is selected so that we can handle down to 5khz sample rate.
static const size_t kMinSamplesPerHardwarePacket = 1024;

// The maximum number of samples in a hardware packet.
// This value is selected so that we can handle up to 192khz sample rate.
static const size_t kMaxSamplesPerHardwarePacket = 64 * 1024;

// This constant governs the hardware audio buffer size, this value should be
// chosen carefully.
// This value is selected so that we have 8192 samples for 48khz streams.
static const size_t kMillisecondsPerHardwarePacket = 170;

// Select the number of samples that can provide at least
// |kMillisecondsPerHardwarePacket| worth of audio data.
size_t samples = kMinSamplesPerHardwarePacket;
while (samples <= kMaxSamplesPerHardwarePacket &&
samples * base::Time::kMillisecondsPerSecond <
sample_rate * kMillisecondsPerHardwarePacket) {
samples *= 2;
}
return samples;
}

ChannelLayout GetInputChannelLayout() {
DCHECK(RenderThreadImpl::current() != NULL);

Expand Down
4 changes: 0 additions & 4 deletions content/renderer/media/audio_hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ CONTENT_EXPORT int GetInputSampleRate();
// Must be used in conjunction with AUDIO_PCM_LOW_LATENCY.
CONTENT_EXPORT size_t GetOutputBufferSize();

// Computes a buffer size based on the given |sample_rate|. Must be used in
// conjunction with AUDIO_PCM_LINEAR.
CONTENT_EXPORT size_t GetHighLatencyOutputBufferSize(int sample_rate);

// Fetch the audio channel layout for the default input device.
// Must be called from RenderThreadImpl::current().
CONTENT_EXPORT ChannelLayout GetInputChannelLayout();
Expand Down
6 changes: 3 additions & 3 deletions content/renderer/media/audio_input_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class CONTENT_EXPORT AudioInputDevice
class CONTENT_EXPORT CaptureCallback {
public:
virtual void Capture(const std::vector<float*>& audio_data,
size_t number_of_frames,
size_t audio_delay_milliseconds,
int number_of_frames,
int audio_delay_milliseconds,
double volume) = 0;
virtual void OnCaptureError() = 0;
protected:
Expand Down Expand Up @@ -148,7 +148,7 @@ class CONTENT_EXPORT AudioInputDevice
return audio_parameters_.sample_rate();
}

size_t buffer_size() const {
int buffer_size() const {
return audio_parameters_.frames_per_buffer();
}

Expand Down
229 changes: 0 additions & 229 deletions content/renderer/media/audio_renderer_impl.cc

This file was deleted.

Loading

0 comments on commit e4fc09e

Please sign in to comment.