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

Unified Diff: services/media/audio/platform/generic/output_formatter.h

Issue 1471813002: Mix to an intermediate buffer. (Closed) Base URL: https://github.com/domokit/mojo.git@change7
Patch Set: Final rebase before landing Created 4 years, 11 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: services/media/audio/platform/generic/output_formatter.h
diff --git a/services/media/audio/platform/generic/output_formatter.h b/services/media/audio/platform/generic/output_formatter.h
new file mode 100644
index 0000000000000000000000000000000000000000..940c834a0fcfc824f47b8d66bd71136349dcaf78
--- /dev/null
+++ b/services/media/audio/platform/generic/output_formatter.h
@@ -0,0 +1,76 @@
+// Copyright 2015 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 SERVICES_MEDIA_AUDIO_PLATFORM_GENERIC_OUTPUT_FORMATTER_H_
+#define SERVICES_MEDIA_AUDIO_PLATFORM_GENERIC_OUTPUT_FORMATTER_H_
+
+#include <memory>
+
+#include "mojo/services/media/common/interfaces/media_types.mojom.h"
+
+namespace mojo {
+namespace media {
+namespace audio {
+
+class OutputFormatter;
+using OutputFormatterPtr = std::unique_ptr<OutputFormatter>;
+
+class OutputFormatter {
+ public:
+ static OutputFormatterPtr Select(
+ const LpcmMediaTypeDetailsPtr& output_format);
+
+ ~OutputFormatter();
+
+ /**
+ * Take frames of audio from the source intermediate buffer and convert them
+ * to the proper sample format for the output buffer, clipping the audio as
+ * needed in the process.
+ *
+ * @note It is assumed that the source intermediate mixing buffer has the same
+ * number of channels and channel ordering as the output buffer.
+ *
+ * @param source A pointer to the normalized frames of audio to use as the
+ * source.
+ *
+ * @param dest A pointer to the destination buffer whose frames match the
+ * format described by output_format during the call to Select.
+ *
+ * @param frames The number of frames to produce.
+ */
+ virtual void ProduceOutput(const int32_t* source,
+ void* dest,
+ uint32_t frames) const = 0;
+
+ /**
+ * Fill a destination buffer with silence.
+ *
+ * @param dest A pointer to the destination buffer whose frames match the
+ * format described by output_format during the call to Select.
+ *
+ * @param frames The number of frames to produce.
+ */
+ virtual void FillWithSilence(void* dest, uint32_t frames) const = 0;
+
+ const LpcmMediaTypeDetailsPtr& format() const { return format_; }
+ uint32_t channels() const { return channels_; }
+ uint32_t bytes_per_sample() const { return bytes_per_sample_; }
+ uint32_t bytes_per_frame() const { return bytes_per_frame_; }
+
+ protected:
+ OutputFormatter(const LpcmMediaTypeDetailsPtr& output_format,
+ uint32_t bytes_per_sample,
+ uint32_t channels);
+
+ LpcmMediaTypeDetailsPtr format_;
+ uint32_t channels_ = 0;
+ uint32_t bytes_per_sample_ = 0;
+ uint32_t bytes_per_frame_ = 0;
+};
+
+} // namespace audio
+} // namespace media
+} // namespace mojo
+
+#endif // SERVICES_MEDIA_AUDIO_PLATFORM_GENERIC_OUTPUT_FORMATTER_H_

Powered by Google App Engine
This is Rietveld 408576698