Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Unified Diff: media/base/audio_buffer_converter.h

Issue 177333003: Add support for midstream audio configuration changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ABS
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..baea94b2cb06c2dd64a7882e533b2a9a843a9ba9
--- /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 {
rileya (GONE FROM CHROMIUM) 2014/03/07 01:19:29 Not sure on the name...
+public:
+
+ AudioBufferConverter(const AudioParameters& output_params);
+ virtual ~AudioBufferConverter();
+
+ void AddInput(const scoped_refptr<AudioBuffer>& buffer);
+
+ bool HasNextBuffer();
+ scoped_refptr<AudioBuffer> GetNextBuffer();
+
+private:
+
+ // 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 RequiresConverterReset(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_;
+
+ // Buffer of output frames, to be returned by GetNextBuffer().
+ std::list<scoped_refptr<AudioBuffer> > queued_outputs_;
+
+ // How many frames of output queued_inputs_ would produce (*after* conversion)
+ int output_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

Powered by Google App Engine
This is Rietveld 408576698