summaryrefslogtreecommitdiff
path: root/libavformat/mov.c
diff options
context:
space:
mode:
authorMarton Balint <cus@passwd.hu>2016-02-20 01:34:42 +0100
committerMarton Balint <cus@passwd.hu>2016-02-28 23:00:45 +0100
commit4840effe4222e5cf3fe78840f9815a613a64c9f8 (patch)
treef51a8d964eab987683bde72c3074cd12b4863e60 /libavformat/mov.c
parentc66a6369e4880434c3476866aa8996c3c309edae (diff)
avformat/mov: merge mov_read_custom functions
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 Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Marton Balint <cus@passwd.hu>
Diffstat (limited to 'libavformat/mov.c')
-rw-r--r--libavformat/mov.c50
1 files changed, 12 insertions, 38 deletions
diff --git a/libavformat/mov.c b/libavformat/mov.c
index adf1fbe347..248a155e9b 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3173,10 +3173,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;
@@ -3186,7 +3186,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;
@@ -3202,7 +3202,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);
@@ -3222,7 +3224,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){
@@ -3235,43 +3237,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;
}