[1/3] replaygain: allow exporting already decoded replaygain values

Message ID 1397062205-5162-2-git-send-email-alessandro@ghedini.me
State New
Headers show

Commit Message

Alessandro Ghedini April 9, 2014, 4:50 p.m.
This adds a function to export raw replaygain values (i.e. in the (u)int32_t
form). It first checks whether AV_PKT_DATA_REPLAYGAIN side data is present, in
which case it does nothing.
---
 doc/APIchanges           |  4 ++++
 libavformat/replaygain.c | 29 ++++++++++++++---------------
 libavformat/replaygain.h |  7 +++++++
 libavformat/version.h    |  2 +-
 4 files changed, 26 insertions(+), 16 deletions(-)

Comments

Anton Khirnov April 12, 2014, 6:22 a.m. | #1
Hi,
On Wed,  9 Apr 2014 18:50:03 +0200, Alessandro Ghedini <alessandro@ghedini.me> wrote:
> This adds a function to export raw replaygain values (i.e. in the (u)int32_t
> form). It first checks whether AV_PKT_DATA_REPLAYGAIN side data is present, in
> which case it does nothing.
> ---
>  doc/APIchanges           |  4 ++++
>  libavformat/replaygain.c | 29 ++++++++++++++---------------
>  libavformat/replaygain.h |  7 +++++++
>  libavformat/version.h    |  2 +-
>  4 files changed, 26 insertions(+), 16 deletions(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index ec1816a..7cd29b6 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -13,6 +13,10 @@ libavutil:     2013-12-xx
>  
>  API changes, most recent first:
>  
> +2014-04-xx - xxxxxxx - lavf 55.16.0 - replaygain.h
> +  Add ff_replaygain_export_raw() for exporting already decoded replaygain
> +  values.
> +

No need for this or the version bump, since this is just internal API, not
public.
You don't have to send a new patch for this, but keep it in mind for the future.

Otherwise looks fine.

Patch

diff --git a/doc/APIchanges b/doc/APIchanges
index ec1816a..7cd29b6 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,10 @@  libavutil:     2013-12-xx
 
 API changes, most recent first:
 
+2014-04-xx - xxxxxxx - lavf 55.16.0 - replaygain.h
+  Add ff_replaygain_export_raw() for exporting already decoded replaygain
+  values.
+
 2014-04-xx - xxxxxxx - lavu 53.11.0 - pixfmt.h
   Add AV_PIX_FMT_YVYU422 pixel format.
 
diff --git a/libavformat/replaygain.c b/libavformat/replaygain.c
index fb3bdc7..6c5b582 100644
--- a/libavformat/replaygain.c
+++ b/libavformat/replaygain.c
@@ -66,23 +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;
-    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);
@@ -117,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));
 }
diff --git a/libavformat/replaygain.h b/libavformat/replaygain.h
index 641b7a2..ea56c17 100644
--- a/libavformat/replaygain.h
+++ b/libavformat/replaygain.h
@@ -28,4 +28,11 @@ 
  */
 int ff_replaygain_export(AVStream *st, AVDictionary *metadata);
 
+
+/**
+ * Export already decoded replaygain values as per-stream side data.
+ */
+int ff_replaygain_export_raw(AVStream *st, int32_t tg, uint32_t tp,
+                             int32_t ag, uint32_t ap);
+
 #endif /* AVFORMAT_REPLAYGAIN_H */
diff --git a/libavformat/version.h b/libavformat/version.h
index ba53120..b09d49c 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -30,7 +30,7 @@ 
 #include "libavutil/version.h"
 
 #define LIBAVFORMAT_VERSION_MAJOR 55
-#define LIBAVFORMAT_VERSION_MINOR 15
+#define LIBAVFORMAT_VERSION_MINOR 16
 #define LIBAVFORMAT_VERSION_MICRO  0
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \