]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/replaygain.c
Merge commit '32d05934abc7427bb90380a4c1ab20a15fd7d821'
[ffmpeg] / libavformat / replaygain.c
index c123a6398539803121a0493b248951820f928a8e..eccbb0179c2c42e2106ec4eaa65bee65ce27fc45 100644 (file)
@@ -1,18 +1,18 @@
 /*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
  *
- * Libav is free software; you can redistribute it and/or
+ * 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.
  *
- * Libav is distributed in the hope that it will be useful,
+ * 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 Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
@@ -66,24 +66,22 @@ static int32_t parse_value(const char *value, int32_t min)
     return db * 100000 + sign * mb;
 }
 
-static int replaygain_export(AVStream *st,
-                             const uint8_t *track_gain, const uint8_t *track_peak,
-                             const uint8_t *album_gain, const uint8_t *album_peak)
+int ff_replaygain_export_raw(AVStream *st, int32_t tg, uint32_t tp,
+                             int32_t ag, uint32_t ap)
 {
     AVPacketSideData *sd, *tmp;
     AVReplayGain *replaygain;
-    uint8_t *data;
-    int32_t tg, ag;
-    uint32_t tp, ap;
-
-    tg = parse_value(track_gain, INT32_MIN);
-    ag = parse_value(album_gain, INT32_MIN);
-    tp = parse_value(track_peak, 0);
-    ap = parse_value(album_peak, 0);
 
     if (tg == INT32_MIN && ag == INT32_MIN)
         return 0;
 
+    for (int i = 0; i < st->nb_side_data; i++) {
+        AVPacketSideData *src_sd = &st->side_data[i];
+
+        if (src_sd->type == AV_PKT_DATA_REPLAYGAIN)
+            return 0;
+    }
+
     replaygain = av_mallocz(sizeof(*replaygain));
     if (!replaygain)
         return AVERROR(ENOMEM);
@@ -118,9 +116,9 @@ int ff_replaygain_export(AVStream *st, AVDictionary *metadata)
     ag = av_dict_get(metadata, "REPLAYGAIN_ALBUM_GAIN", NULL, 0);
     ap = av_dict_get(metadata, "REPLAYGAIN_ALBUM_PEAK", NULL, 0);
 
-    return replaygain_export(st,
-                             tg ? tg->value : NULL,
-                             tp ? tp->value : NULL,
-                             ag ? ag->value : NULL,
-                             ap ? ap->value : NULL);
+    return ff_replaygain_export_raw(st,
+                             parse_value(tg ? tg->value : NULL, INT32_MIN),
+                             parse_value(tp ? tp->value : NULL, 0),
+                             parse_value(ag ? ag->value : NULL, INT32_MIN),
+                             parse_value(ap ? ap->value : NULL, 0));
 }