Chromium Code Reviews| Index: media/base/audio_transform.h |
| diff --git a/media/base/audio_transform.h b/media/base/audio_transform.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..937b1ee6764ad47eb4cc53bd6a858084d8488869 |
| --- /dev/null |
| +++ b/media/base/audio_transform.h |
| @@ -0,0 +1,97 @@ |
| +// Copyright (c) 2012 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_TRANSFORM_H_ |
| +#define MEDIA_BASE_AUDIO_TRANSFORM_H_ |
| + |
| +#include <list> |
| + |
| +#include "base/callback.h" |
| +#include "base/time.h" |
| +#include "media/audio/audio_parameters.h" |
| +#include "media/base/media_export.h" |
| + |
| +namespace media { |
| + |
| +class AudioBus; |
| +class AudioPullFifo; |
| +class ChannelMixer; |
| +class MultiChannelResampler; |
| + |
| +// AudioTransform is a complete mixing, resampling, rebuffering, and channel |
| +// mixing solution for converting data from one set of AudioParameters to |
| +// another. For efficiency pieces are only invoked when necessary; e.g. the |
| +// resampler is only used if the input and output sample rates differ. Mixing |
| +// and channel down mixing are done prior to resampling to maximize efficiency. |
| +class MEDIA_EXPORT AudioTransform { |
|
Chris Rogers
2012/11/14 23:50:49
This is just a naming nit, but always good to get
DaleCurtis
2012/11/16 23:51:05
Done. I'll rename the file in the last patch set t
|
| + public: |
| + class MEDIA_EXPORT AudioTransformInput { |
|
scherkus (not reviewing)
2012/11/14 22:43:50
nit: this can be "Input" because its name is alrea
DaleCurtis
2012/11/15 00:30:59
Just what we discussed at dinner the other day. Yo
DaleCurtis
2012/11/16 23:51:05
Changed to InputCallback a la RenderCallback
|
| + public: |
| + // Method for providing more data into the transform. Expects |audio_bus| |
| + // to be completely filled with data upon return; zero padded if not enough |
| + // frames are available to satisfy the request. The return value is the |
| + // volume level of the provided audio data. If a volume level of zero is |
|
Chris Rogers
2012/11/14 23:50:49
can you elaborate a little more in this comment on
DaleCurtis
2012/11/16 23:51:05
Done.
|
| + // returned no further processing will be done on the provided data. |
| + virtual float ProvideAudioTransformInput(AudioBus* audio_bus, |
| + base::TimeDelta buffer_delay) = 0; |
| + |
| + protected: |
| + virtual ~AudioTransformInput() {} |
| + }; |
| + |
| + AudioTransform(const AudioParameters& input_params, |
| + const AudioParameters& output_params); |
| + ~AudioTransform(); |
| + |
| + // Transforms audio from all inputs into the |dest|. |dest| must be sized for |
| + // data matching the output AudioParameters provided during construction. |
| + void Transform(AudioBus* dest); |
| + |
| + // Add or remove an input from the transform. |
| + void AddInput(AudioTransformInput* input); |
|
justinlin
2012/11/12 20:29:38
Purely from an interface point of view, would it m
DaleCurtis
2012/11/12 20:48:18
Currently AudioRendererMixerManager does a similar
|
| + void RemoveInput(AudioTransformInput* input); |
| + |
| + // Flush all buffered data. Automatically called when all inputs are removed. |
| + void Reset(); |
| + |
| + private: |
| + // Called by MultiChannelResampler when more data is necessary. |
| + void ProvideInput(AudioBus* audio_bus); |
| + |
| + // Called by AudioPullFifo when more data is necessary. |
| + void SourceCallback(AudioBus* audio_bus); |
| + |
| + // Set of inputs for Transform(). |
| + typedef std::list<AudioTransformInput*> AudioTransformInputSet; |
| + AudioTransformInputSet transform_inputs_; |
| + |
| + // 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. |
| + 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_; |
| + |
| + // Temporary AudioBus destination for mixing inputs. |
| + scoped_ptr<AudioBus> mixer_input_audio_bus_; |
| + |
| + // Since resampling is expensive, figure out if we should downmix channels |
| + // before resampling. |
| + bool downmix_early_; |
| + |
| + // Used to calculate buffer delay information AudioTransformInputs. |
| + base::TimeDelta input_frame_duration_; |
| + base::TimeDelta output_frame_duration_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AudioTransform); |
| +}; |
| + |
| +} // namespace media |
| + |
| +#endif // MEDIA_BASE_AUDIO_TRANSFORM_H_ |