[FFmpeg-devel] [PATCH 1/2] avutil/replaygain: add av_replaygain_alloc()
James Almer
jamrial at gmail.com
Mon Dec 12 05:23:00 EET 2016
Signed-off-by: James Almer <jamrial at gmail.com>
---
TODO: APIChanges entry and version bump.
libavutil/replaygain.c | 38 ++++++++++++++++++++++++++++++++++++++
libavutil/replaygain.h | 10 ++++++++++
2 files changed, 48 insertions(+)
create mode 100644 libavutil/replaygain.c
diff --git a/libavutil/replaygain.c b/libavutil/replaygain.c
new file mode 100644
index 0000000..2715cb2
--- /dev/null
+++ b/libavutil/replaygain.c
@@ -0,0 +1,38 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include "mem.h"
+#include "replaygain.h"
+
+AVReplayGain *av_replaygain_alloc(size_t *size)
+{
+ AVReplayGain *replaygain = av_mallocz(sizeof(AVReplayGain));
+ if (!replaygain)
+ return NULL;
+
+ replaygain->track_gain =
+ replaygain->album_gain = INT32_MIN;
+
+ if (size)
+ *size = sizeof(*replaygain);
+
+ return replaygain;
+}
diff --git a/libavutil/replaygain.h b/libavutil/replaygain.h
index b49bf1a..2ad6de6 100644
--- a/libavutil/replaygain.h
+++ b/libavutil/replaygain.h
@@ -19,6 +19,7 @@
#ifndef AVUTIL_REPLAYGAIN_H
#define AVUTIL_REPLAYGAIN_H
+#include <stddef.h>
#include <stdint.h>
/**
@@ -47,4 +48,13 @@ typedef struct AVReplayGain {
uint32_t album_peak;
} AVReplayGain;
+/**
+ * Allocate an AVReplayGain structure and set its fields to default values.
+ * The resulting struct can be freed using av_freep().
+ *
+ * @param size pointer for AVReplayGain structure size to store (optional)
+ * @return An AVReplayGain filled with default values or NULL on failure.
+ */
+AVReplayGain *av_replaygain_alloc(size_t *size);
+
#endif /* AVUTIL_REPLAYGAIN_H */
--
2.10.2
More information about the ffmpeg-devel
mailing list