Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Fix calling of AudioOutputStream::AudioSourceCallback API
Browse files Browse the repository at this point in the history
Before this change calling of AudioOutputStream::AudioSourceCallback
method without stream position ended up in an empty implementation.

BUG=XWALK-6703
  • Loading branch information
Mikhail Pozdnyakov authored and Mrunal Kapade committed May 13, 2016
1 parent 172493f commit a58a09a
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 47 deletions.
1 change: 0 additions & 1 deletion media/audio/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ source_set("audio") {
"audio_input_device.h",
"audio_input_ipc.cc",
"audio_input_ipc.h",
"audio_io.cc",
"audio_io.h",
"audio_manager.cc",
"audio_manager.h",
Expand Down
24 changes: 0 additions & 24 deletions media/audio/audio_io.cc

This file was deleted.

9 changes: 3 additions & 6 deletions media/audio/audio_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,12 @@ class MEDIA_EXPORT AudioOutputStream {
// the number of frames it filled. |total_bytes_delay| contains current
// number of bytes of delay buffered by the AudioOutputStream.
// |frames_skipped| contains the number of frames skipped by the consumer.
virtual int OnMoreData(AudioBus* dest,
uint32_t total_bytes_delay,
uint32_t frames_skipped);
// An alternate version which provides also device stream position,
// by default it just invokes the above method.
// |device_position| if provided, contains position of currently audible
// signal.
virtual int OnMoreData(AudioBus* dest,
uint32_t total_bytes_delay,
uint32_t frames_skipped,
const StreamPosition& device_position);
const StreamPosition& device_position = {0, 0}) = 0;

// There was an error while playing a buffer. Audio source cannot be
// destroyed yet. No direct action needed by the AudioStream, but it is
Expand Down
5 changes: 3 additions & 2 deletions media/audio/audio_output_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void AudioOutputController::DoPlay() {
return;

// Ask for first packet.
sync_reader_->UpdatePendingBytes(0, 0);
sync_reader_->UpdatePendingBytes(0, 0, {0, 0});

state_ = kPlaying;

Expand Down Expand Up @@ -217,7 +217,8 @@ void AudioOutputController::DoPause() {
// Let the renderer know we've stopped. Necessary to let PPAPI clients know
// audio has been shutdown. TODO(dalecurtis): This stinks. PPAPI should have
// a better way to know when it should exit PPB_Audio_Shared::Run().
sync_reader_->UpdatePendingBytes(std::numeric_limits<uint32_t>::max(), 0);
sync_reader_->UpdatePendingBytes(std::numeric_limits<uint32_t>::max(), 0,
{0, 0});

handler_->OnPaused();
}
Expand Down
7 changes: 3 additions & 4 deletions media/audio/audio_output_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ class MEDIA_EXPORT AudioOutputController
// frames has been skipped by the renderer (typically the OS). The renderer
// source can handle this appropriately depending on the type of source. An
// ordinary file playout would ignore this.
virtual void UpdatePendingBytes(
uint32_t bytes,
uint32_t frames_skipped,
const StreamPosition& position = StreamPosition()) = 0;
virtual void UpdatePendingBytes(uint32_t bytes,
uint32_t frames_skipped,
const StreamPosition& position) = 0;

// Attempts to completely fill |dest|, zeroing |dest| if the request can not
// be fulfilled (due to timeout).
Expand Down
3 changes: 2 additions & 1 deletion media/audio/audio_output_stream_sink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ OutputDevice* AudioOutputStreamSink::GetOutputDevice() {

int AudioOutputStreamSink::OnMoreData(AudioBus* dest,
uint32_t total_bytes_delay,
uint32_t frames_skipped) {
uint32_t frames_skipped,
const StreamPosition& position) {
// Note: Runs on the audio thread created by the OS.
base::AutoLock al(callback_lock_);
if (!active_render_callback_)
Expand Down
3 changes: 2 additions & 1 deletion media/audio/audio_output_stream_sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class MEDIA_EXPORT AudioOutputStreamSink
// AudioSourceCallback implementation.
int OnMoreData(AudioBus* dest,
uint32_t total_bytes_delay,
uint32_t frames_skipped) override;
uint32_t frames_skipped,
const StreamPosition& position) override;
void OnError(AudioOutputStream* stream) override;

private:
Expand Down
9 changes: 6 additions & 3 deletions media/audio/simple_sources.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ SineWaveAudioSource::~SineWaveAudioSource() {
// but it is efficient enough for our simple needs.
int SineWaveAudioSource::OnMoreData(AudioBus* audio_bus,
uint32_t total_bytes_delay,
uint32_t frames_skipped) {
uint32_t frames_skipped,
const StreamPosition& position) {
base::AutoLock auto_lock(time_lock_);
callbacks_++;

Expand Down Expand Up @@ -198,7 +199,8 @@ void FileSource::LoadWavFile(const base::FilePath& path_to_wav_file) {

int FileSource::OnMoreData(AudioBus* audio_bus,
uint32_t total_bytes_delay,
uint32_t frames_skipped) {
uint32_t frames_skipped,
const StreamPosition& position) {
// Load the file if we haven't already. This load needs to happen on the
// audio thread, otherwise we'll run on the UI thread on Mac for instance.
// This will massively delay the first OnMoreData, but we'll catch up.
Expand Down Expand Up @@ -248,7 +250,8 @@ BeepingSource::~BeepingSource() {

int BeepingSource::OnMoreData(AudioBus* audio_bus,
uint32_t total_bytes_delay,
uint32_t frames_skipped) {
uint32_t frames_skipped,
const StreamPosition& position) {
// Accumulate the time from the last beep.
interval_from_last_beep_ += base::TimeTicks::Now() - last_callback_time_;

Expand Down
9 changes: 6 additions & 3 deletions media/audio/simple_sources.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class MEDIA_EXPORT SineWaveAudioSource
// Implementation of AudioSourceCallback.
int OnMoreData(AudioBus* audio_bus,
uint32_t total_bytes_delay,
uint32_t frames_skipped) override;
uint32_t frames_skipped,
const StreamPosition& position) override;
void OnError(AudioOutputStream* stream) override;

// The number of OnMoreData() and OnError() calls respectively.
Expand All @@ -62,7 +63,8 @@ class MEDIA_EXPORT FileSource : public AudioOutputStream::AudioSourceCallback,
// Implementation of AudioSourceCallback.
int OnMoreData(AudioBus* audio_bus,
uint32_t total_bytes_delay,
uint32_t frames_skipped) override;
uint32_t frames_skipped,
const StreamPosition& position) override;
void OnError(AudioOutputStream* stream) override;

private:
Expand Down Expand Up @@ -95,7 +97,8 @@ class BeepingSource : public AudioOutputStream::AudioSourceCallback {
// Implementation of AudioSourceCallback.
int OnMoreData(AudioBus* audio_bus,
uint32_t total_bytes_delay,
uint32_t frames_skipped) override;
uint32_t frames_skipped,
const StreamPosition& position) override;
void OnError(AudioOutputStream* stream) override;

static void BeepOnce();
Expand Down
3 changes: 2 additions & 1 deletion media/audio/sounds/audio_stream_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ class AudioStreamHandler::AudioStreamContainer
// Following methods could be called from *ANY* thread.
int OnMoreData(AudioBus* dest,
uint32_t /* total_bytes_delay */,
uint32_t /* frames_skipped */) override {
uint32_t /* frames_skipped */,
const StreamPosition& /* position */) override {
base::AutoLock al(state_lock_);
size_t bytes_written = 0;

Expand Down
1 change: 0 additions & 1 deletion media/media.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@
'audio/audio_input_device.h',
'audio/audio_input_ipc.cc',
'audio/audio_input_ipc.h',
'audio/audio_io.cc',
'audio/audio_io.h',
'audio/audio_manager.cc',
'audio/audio_manager.h',
Expand Down

0 comments on commit a58a09a

Please sign in to comment.