[FFmpeg-devel,1/2] avutil/replaygain: add av_replaygain_alloc()

Submitted by James Almer on Dec. 12, 2016, 3:23 a.m.

Details

Message ID 20161212032301.2272-1-jamrial@gmail.com
State New
Headers show

Commit Message

James Almer Dec. 12, 2016, 3:23 a.m.
Signed-off-by: James Almer <jamrial@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

Comments

Michael Niedermayer Dec. 12, 2016, 10:24 p.m.
On Mon, Dec 12, 2016 at 12:23:00AM -0300, James Almer wrote:
> Signed-off-by: James Almer <jamrial@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

missing Makefile update

[...]
James Almer Dec. 12, 2016, 10:34 p.m.
On 12/12/2016 7:24 PM, Michael Niedermayer wrote:
> On Mon, Dec 12, 2016 at 12:23:00AM -0300, James Almer wrote:
>> Signed-off-by: James Almer <jamrial@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
> 
> missing Makefile update

Whoops, fixed locally.

Thanks for noticing.

Patch hide | download patch | download mbox

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 */