Index: media/audio/audio_output_resampler.h |
diff --git a/media/audio/audio_output_resampler.h b/media/audio/audio_output_resampler.h |
index 764343777b3bcf888fd1700b6b72c47361dd464b..926198858b1b31d830dee4c1c39e6fe5e87b5402 100644 |
--- a/media/audio/audio_output_resampler.h |
+++ b/media/audio/audio_output_resampler.h |
@@ -9,15 +9,91 @@ |
#include "base/basictypes.h" |
#include "base/memory/ref_counted.h" |
+#include "base/message_loop.h" |
#include "base/time.h" |
#include "media/audio/audio_io.h" |
#include "media/audio/audio_manager.h" |
#include "media/audio/audio_output_dispatcher.h" |
#include "media/audio/audio_parameters.h" |
+#include "media/base/audio_pull_fifo.h" |
+#include "media/base/channel_mixer.h" |
+#include "media/base/multi_channel_resampler.h" |
namespace media { |
-class OnMoreDataResampler; |
+class OnMoreDataResampler : public AudioOutputStream::AudioSourceCallback { |
+ public: |
+ OnMoreDataResampler(double io_ratio, |
+ const AudioParameters& input_params, |
+ const AudioParameters& output_params); |
+ virtual ~OnMoreDataResampler(); |
+ |
+ // AudioSourceCallback interface. |
+ virtual int OnMoreData(AudioBus* dest, |
+ AudioBuffersState buffers_state) OVERRIDE; |
+ virtual int OnMoreIOData(AudioBus* source, |
+ AudioBus* dest, |
+ AudioBuffersState buffers_state) OVERRIDE; |
+ virtual void OnError(AudioOutputStream* stream, int code) OVERRIDE; |
+ virtual void WaitTillDataReady() OVERRIDE; |
+ |
+ // Sets |source_callback_|. If this is not a new object, then Stop() must be |
+ // called before Start(). |
+ void Start(AudioOutputStream::AudioSourceCallback* callback); |
+ |
+ // Clears |source_callback_| and flushes the resampler. |
+ void Stop(); |
+ |
+ private: |
+ // Called by MultiChannelResampler when more data is necessary. |
+ void ProvideInput(AudioBus* audio_bus); |
+ |
+ // Called by AudioPullFifo when more data is necessary. Requires |
+ // |source_lock_| to have been acquired. |
+ void SourceCallback_Locked(AudioBus* audio_bus); |
+ |
+ // Passes through |source| to the |source_callback_| OnMoreIOData() call. |
+ void SourceIOCallback_Locked(AudioBus* source, AudioBus* dest); |
+ |
+ // Ratio of input bytes to output bytes used to correct playback delay with |
+ // regard to buffering and resampling. |
+ double io_ratio_; |
+ |
+ // Source callback and associated lock. |
+ base::Lock source_lock_; |
+ AudioOutputStream::AudioSourceCallback* source_callback_; |
+ |
+ // Last AudioBuffersState object received via OnMoreData(), used to correct |
+ // playback delay by ProvideInput() and passed on to |source_callback_|. |
+ AudioBuffersState current_buffers_state_; |
+ |
+ // Total number of bytes (in terms of output parameters) stored in resampler |
+ // or FIFO buffers which have not been sent to the audio device. |
+ int outstanding_audio_bytes_; |
+ |
+ // Used to buffer data between the client and the output device in cases where |
+ // the client buffer size is not the same as the output device buffer size. |
+ // Bound to SourceCallback_Locked() so must only be used when |source_lock_| |
+ // has already been acquired. |
+ scoped_ptr<AudioPullFifo> audio_fifo_; |
+ |
+ // Handles resampling. |
+ scoped_ptr<MultiChannelResampler> resampler_; |
+ |
+ // Handles channel transforms. |unmixed_audio_| is a temporary destination |
+ // for audio data before it goes into the channel mixer. |
+ scoped_ptr<ChannelMixer> channel_mixer_; |
+ scoped_ptr<AudioBus> unmixed_audio_; |
+ |
+ int output_bytes_per_frame_; |
+ int input_bytes_per_frame_; |
+ |
+ // Since resampling is expensive, figure out if we should downmix channels |
+ // before resampling. |
+ bool downmix_early_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(OnMoreDataResampler); |
+}; |
// AudioOutputResampler is a browser-side resampling and rebuffering solution |
// which ensures audio data is always output at given parameters. The rough |