[FFmpeg-devel] [PATCH 1/2] avformat/mov: merge mov_read_custom functions
Marton Balint
cus at passwd.hu
Sat Feb 20 02:11:49 CET 2016
This also fixes reading gapless metadata when the entries do not start with the
mean atom. Such samples can be found here:
https://hydrogenaud.io/index.php/topic,93310.0.html
Signed-off-by: Marton Balint <cus at passwd.hu>
---
libavformat/mov.c | 50 ++++++++++++--------------------------------------
1 file changed, 12 insertions(+), 38 deletions(-)
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 1d0077e..7d9a3f3 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3172,10 +3172,10 @@ static int mov_read_keys(MOVContext *c, AVIOContext *pb, MOVAtom atom)
return 0;
}
-static int mov_read_custom_2plus(MOVContext *c, AVIOContext *pb, int64_t size)
+static int mov_read_custom(MOVContext *c, AVIOContext *pb, MOVAtom atom)
{
- int64_t end = avio_tell(pb) + size;
- uint8_t *key = NULL, *val = NULL;
+ int64_t end = avio_tell(pb) + atom.size;
+ uint8_t *key = NULL, *val = NULL, *mean = NULL;
int i;
AVStream *st;
MOVStreamContext *sc;
@@ -3185,7 +3185,7 @@ static int mov_read_custom_2plus(MOVContext *c, AVIOContext *pb, int64_t size)
st = c->fc->streams[c->fc->nb_streams-1];
sc = st->priv_data;
- for (i = 0; i < 2; i++) {
+ for (i = 0; i < 3; i++) {
uint8_t **p;
uint32_t len, tag;
int ret;
@@ -3201,7 +3201,9 @@ static int mov_read_custom_2plus(MOVContext *c, AVIOContext *pb, int64_t size)
break;
len -= 12;
- if (tag == MKTAG('n', 'a', 'm', 'e'))
+ if (tag == MKTAG('m', 'e', 'a', 'n'))
+ p = &mean;
+ else if (tag == MKTAG('n', 'a', 'm', 'e'))
p = &key;
else if (tag == MKTAG('d', 'a', 't', 'a') && len > 4) {
avio_skip(pb, 4);
@@ -3221,7 +3223,7 @@ static int mov_read_custom_2plus(MOVContext *c, AVIOContext *pb, int64_t size)
(*p)[len] = 0;
}
- if (key && val) {
+ if (mean && key && val) {
if (strcmp(key, "iTunSMPB") == 0) {
int priming, remainder, samples;
if(sscanf(val, "%*X %X %X %X", &priming, &remainder, &samples) == 3){
@@ -3234,43 +3236,15 @@ static int mov_read_custom_2plus(MOVContext *c, AVIOContext *pb, int64_t size)
AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
key = val = NULL;
}
+ } else {
+ av_log(c->fc, AV_LOG_VERBOSE,
+ "Unhandled or malformed custom metadata of size %"PRId64"\n", atom.size);
}
avio_seek(pb, end, SEEK_SET);
av_freep(&key);
av_freep(&val);
- return 0;
-}
-
-static int mov_read_custom(MOVContext *c, AVIOContext *pb, MOVAtom atom)
-{
- int64_t end = avio_tell(pb) + atom.size;
- uint32_t tag, len;
-
- if (atom.size < 8)
- goto fail;
-
- len = avio_rb32(pb);
- tag = avio_rl32(pb);
-
- if (len > atom.size)
- goto fail;
-
- if (tag == MKTAG('m', 'e', 'a', 'n') && len > 12) {
- uint8_t domain[128];
- int domain_len;
-
- avio_skip(pb, 4); // flags
- len -= 12;
-
- domain_len = avio_get_str(pb, len, domain, sizeof(domain));
- avio_skip(pb, len - domain_len);
- return mov_read_custom_2plus(c, pb, end - avio_tell(pb));
- }
-
-fail:
- av_log(c->fc, AV_LOG_VERBOSE,
- "Unhandled or malformed custom metadata of size %"PRId64"\n", atom.size);
+ av_freep(&mean);
return 0;
}
--
2.6.2
More information about the ffmpeg-devel
mailing list