[FFmpeg-devel,2/2] avformat/replaygain: use av_replaygain_alloc()

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

Details

Message ID 20161212032301.2272-2-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>
---
 libavformat/replaygain.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavformat/replaygain.c b/libavformat/replaygain.c
index 707d3cd..b8658d6 100644
--- a/libavformat/replaygain.c
+++ b/libavformat/replaygain.c
@@ -71,12 +71,13 @@  int ff_replaygain_export_raw(AVStream *st, int32_t tg, uint32_t tp,
                              int32_t ag, uint32_t ap)
 {
     AVReplayGain *replaygain;
+    size_t replaygain_size;
+    int ret;
 
     if (tg == INT32_MIN && ag == INT32_MIN)
         return 0;
 
-    replaygain = (AVReplayGain*)av_stream_new_side_data(st, AV_PKT_DATA_REPLAYGAIN,
-                                                        sizeof(*replaygain));
+    replaygain = av_replaygain_alloc(&replaygain_size);
     if (!replaygain)
         return AVERROR(ENOMEM);
 
@@ -85,6 +86,13 @@  int ff_replaygain_export_raw(AVStream *st, int32_t tg, uint32_t tp,
     replaygain->album_gain = ag;
     replaygain->album_peak = ap;
 
+    ret = av_stream_add_side_data(st, AV_PKT_DATA_REPLAYGAIN, (uint8_t *)replaygain,
+                                  replaygain_size);
+    if (ret < 0) {
+        av_freep(&replaygain);
+        return ret;
+    }
+
     return 0;
 }