Chromium Code Reviews| Index: media/base/audio_buffer_converter.h |
| diff --git a/media/base/audio_buffer_converter.h b/media/base/audio_buffer_converter.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f369b9655a6ad370c857bcb1c78a660fa19ed17f |
| --- /dev/null |
| +++ b/media/base/audio_buffer_converter.h |
| @@ -0,0 +1,95 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef MEDIA_BASE_AUDIO_BUFFER_CONVERTER |
| +#define MEDIA_BASE_AUDIO_BUFFER_CONVERTER |
| + |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/time/time.h" |
| +#include "media/audio/audio_parameters.h" |
| +#include "media/base/audio_converter.h" |
| +#include "media/base/audio_timestamp_helper.h" |
| +#include "media/base/media_export.h" |
| + |
| +namespace media { |
| + |
| +class AudioBuffer; |
| +class AudioBus; |
| + |
| +// Takes AudioBuffers in any format and uses an AudioConverter to convert them |
| +// to a common format (usually the hardware output format). |
| +class AudioBufferConverter : public AudioConverter::InputCallback { |
| +public: |
|
DaleCurtis
2014/03/20 01:36:26
1 space indent, no line after. I'd just run "git
rileya (GONE FROM CHROMIUM)
2014/03/21 20:58:49
Fixed.
|
| + |
| + AudioBufferConverter(const AudioParameters& output_params); |
|
DaleCurtis
2014/03/20 01:36:26
explicit
rileya (GONE FROM CHROMIUM)
2014/03/21 20:58:49
Done.
|
| + virtual ~AudioBufferConverter(); |
| + |
| + void AddInput(const scoped_refptr<AudioBuffer>& buffer); |
| + |
| + bool HasNextBuffer(); |
| + scoped_refptr<AudioBuffer> GetNextBuffer(); |
| + |
| +private: |
|
DaleCurtis
2014/03/20 01:36:26
ditto on style
rileya (GONE FROM CHROMIUM)
2014/03/21 20:58:49
Fixed.
|
| + |
| + // Callback to provide data to the AudioConverter |
| + virtual double ProvideInput(AudioBus* audio_bus, base::TimeDelta buffer_delay) |
| + OVERRIDE; |
| + |
| + // Reset the converter in response to a configuration change. |
| + void ResetConverter(const AudioParameters& input_params); |
| + |
| + // Determine the AudioParameters of an AudioBuffer. |
| + AudioParameters AudioBufferToAudioParameters( |
| + const scoped_refptr<AudioBuffer>& buffer); |
| + |
| + // Get an AudioBuffer from |audio_converter_|. |
| + scoped_refptr<AudioBuffer> Convert(); |
| + |
| + // Flush remaining output |
| + void Flush(); |
| + |
| + // Is |new_params| a config change from |input_params_|? |
| + bool IsConfigChange(const AudioParameters& new_params); |
| + |
| + // The output parameters. |
| + AudioParameters output_params_; |
| + |
| + // The current input parameters (we cache these to detect configuration |
| + // changes, so we know when to reset the AudioConverter). |
| + AudioParameters input_params_; |
| + |
| + // Ratio of sample rates between input and output params (we use this to |
| + // compute how many frames of output we'll get out of a given number of |
| + // input frames). |
| + double sample_rate_ratio_; |
| + |
| + // Queued up inputs (there will never be all that much data stored here, as |
| + // soon as there's enough here to produce an output buffer we will do so. |
| + std::list<scoped_refptr<AudioBuffer> > queued_inputs_; |
| + |
| + // Offset into the front element of |queued_inputs_|. A ProvideInput() call |
| + // doesn't necessarily always consume an entire buffer. |
| + int offset_into_queue_; |
|
rileya (GONE FROM CHROMIUM)
2014/03/20 00:55:11
This probably needs a better name.
|
| + |
| + // Buffer of output frames, to be returned by GetNextBuffer(). |
| + std::list<scoped_refptr<AudioBuffer> > queued_outputs_; |
|
DaleCurtis
2014/03/20 01:36:26
deque?
rileya (GONE FROM CHROMIUM)
2014/03/21 20:58:49
Sounds good. Done.
|
| + |
| + // How many frames of input we have on hand. |
| + int input_frames_; |
| + |
| + // Compute timestamps in terms of the output sample rate. |
| + AudioTimestampHelper timestamp_helper_; |
| + |
| + // Are we flushing everything, without regard for providing AudioConverter |
| + // full AudioBuses in ProvideInput()? |
| + bool is_flushing_; |
| + |
| + // The AudioConverter which does the real work here. |
| + scoped_ptr<AudioConverter> audio_converter_; |
| +}; |
| + |
| +} // namespace media |
| + |
| +#endif // MEDIA_BASE_AUDIO_BUFFER_CONVERTER |