From ef53493e059e8f952cdb9faa338d1c70b8cb9856 Mon Sep 17 00:00:00 2001 From: Mattias Wadman Date: Mon, 11 Oct 2021 15:38:13 +0200 Subject: [PATCH 3/3] libavformat/flacdec: Export samples md5 as metadata Will be used by mal to compare metadat md5 with decoded samples md5. Part of fixing https://jira.spotify.net/browse/GOL-681 --- libavformat/flacdec.c | 6 ++++++ tests/ref/fate/cover-art-flac-remux | 1 + 2 files changed, 7 insertions(+) diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c index 3c317acaee..b4bfbc4f85 100644 --- a/libavformat/flacdec.c +++ b/libavformat/flacdec.c @@ -33,6 +33,7 @@ #include "replaygain.h" #define SEEKPOINT_SIZE 18 +#define MD5_BYTE_SIZE 16 typedef struct FLACDecContext { FFRawDemuxerContext rawctx; @@ -109,6 +110,7 @@ static int flac_read_header(AVFormatContext *s) if (metadata_type == FLAC_METADATA_TYPE_STREAMINFO) { uint32_t samplerate; uint64_t samples; + char md5hex[MD5_BYTE_SIZE*2+1]; // hex representation plus null terminator /* STREAMINFO can only occur once */ if (found_streaminfo) { @@ -133,6 +135,10 @@ static int flac_read_header(AVFormatContext *s) if (samples > 0) st->duration = samples; } + + ff_data_to_hex(md5hex, st->codecpar->extradata+18, MD5_BYTE_SIZE, 1 /* lowercase */); + md5hex[sizeof(md5hex)-1] = '\0'; + av_dict_set(&s->metadata, "info:samples_md5", md5hex, 0); } else if (metadata_type == FLAC_METADATA_TYPE_CUESHEET) { uint8_t isrc[13]; uint64_t start; diff --git a/tests/ref/fate/cover-art-flac-remux b/tests/ref/fate/cover-art-flac-remux index fa91975881..857f1a15ad 100644 --- a/tests/ref/fate/cover-art-flac-remux +++ b/tests/ref/fate/cover-art-flac-remux @@ -90,6 +90,7 @@ TAG:comment=Publisher/Studio logotype TAG:title=White King Granulated Soap [/STREAM] [FORMAT] +TAG:info:samples_md5=496206705f222f9a63bf23dc874d9d71 TAG:major_brand=M4A TAG:minor_version=0 TAG:compatible_brands=M4A mp42isom -- 2.39.5