avformat/framehash: add extradata checksum
authorJames Almer <jamrial@gmail.com>
Wed, 13 Apr 2016 13:49:16 +0000 (10:49 -0300)
committerJames Almer <jamrial@gmail.com>
Wed, 13 Apr 2016 14:41:20 +0000 (11:41 -0300)
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
libavformat/hashenc.c

index 614c815..4aa4fcf 100644 (file)
@@ -149,6 +149,27 @@ AVOutputFormat ff_md5_muxer = {
 #endif
 
 #if CONFIG_FRAMEHASH_MUXER || CONFIG_FRAMEMD5_MUXER
+static void framehash_print_extradata(struct AVFormatContext *s)
+{
+    int i;
+
+    for (i = 0; i < s->nb_streams; i++) {
+        AVStream *st = s->streams[i];
+        AVCodecParameters *par = st->codecpar;
+        if (par->extradata) {
+            struct HashContext *c = s->priv_data;
+            char buf[AV_HASH_MAX_SIZE*2+1];
+
+            avio_printf(s->pb, "#extradata %d, %31d, ", i, par->extradata_size);
+            av_hash_init(c->hash);
+            av_hash_update(c->hash, par->extradata, par->extradata_size);
+            av_hash_final_hex(c->hash, buf, sizeof(buf));
+            avio_write(s->pb, buf, strlen(buf));
+            avio_printf(s->pb, "\n");
+        }
+    }
+}
+
 static int framehash_write_header(struct AVFormatContext *s)
 {
     struct HashContext *c = s->priv_data;
@@ -158,6 +179,8 @@ static int framehash_write_header(struct AVFormatContext *s)
     avio_printf(s->pb, "#format: frame checksums\n");
     avio_printf(s->pb, "#version: %d\n", c->format_version);
     avio_printf(s->pb, "#hash: %s\n", av_hash_get_name(c->hash));
+    if (c->format_version > 1)
+        framehash_print_extradata(s);
     ff_framehash_write_header(s, c->format_version);
     avio_printf(s->pb, "#stream#, dts,        pts, duration,     size, hash\n");
     return 0;