]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - mp4.c
mp4: Check for missing metadata also for regular opens.
[paraslash.git] / mp4.c
diff --git a/mp4.c b/mp4.c
index 372d5f4929f29422cb156262df6a7146c8829c77..7145a47a829695e2cf82a46f58b18aa743c30246 100644 (file)
--- a/mp4.c
+++ b/mp4.c
@@ -394,7 +394,6 @@ static int parse_tag(struct mp4 *f, uint8_t parent, int32_t size)
        tag = f->meta.tags + f->meta.count;
        tag->item = para_strdup(get_metadata_name(parent));
        tag->value = value;
-       tag->len = len;
        f->meta.count++;
        return 1;
 fail:
@@ -421,7 +420,7 @@ static int read_mdhd(struct mp4 *f)
                ret = read_int64(f, &t->duration);
                if (ret <= 0)
                        return ret;
-       } else { //version == 0
+       } else { /* version == 0 */
                uint32_t temp;
 
                skip_bytes(f, 8); /* creation time (4), modification time (4) */
@@ -438,7 +437,7 @@ static int read_mdhd(struct mp4 *f)
        return 1;
 }
 
-static int32_t read_ilst(struct mp4 *f, int32_t size)
+static int read_ilst(struct mp4 *f, int32_t size)
 {
        int ret;
        uint64_t sumsize = 0;
@@ -467,7 +466,7 @@ static int32_t read_ilst(struct mp4 *f, int32_t size)
        return 1;
 }
 
-static int32_t read_meta(struct mp4 *f, uint64_t size)
+static int read_meta(struct mp4 *f, uint64_t size)
 {
        int ret;
        uint64_t subsize, sumsize = 0;
@@ -610,6 +609,9 @@ static int open_file(const struct mp4_callback *cb, bool meta_only, struct mp4 *
        ret = -E_MP4_BAD_SAMPLERATE;
        if (f->track.sample_rate == 0)
                goto fail;
+       ret = -E_MP4_MISSING_ATOM;
+       if (f->udta_size == 0 || f->meta_size == 0 || f->ilst_size == 0)
+               goto fail;
        *result = f;
        return 1;
 fail:
@@ -618,7 +620,7 @@ fail:
        return ret;
 }
 
-int mp4_open_read(const struct mp4_callback *cb, struct mp4 **result)
+int mp4_open(const struct mp4_callback *cb, struct mp4 **result)
 {
        struct mp4 *f;
        int ret;
@@ -630,6 +632,9 @@ int mp4_open_read(const struct mp4_callback *cb, struct mp4 **result)
        ret = -E_MP4_BAD_SAMPLE_COUNT;
        if (f->track.stsz_sample_count == 0)
                goto fail;
+       ret = -E_MP4_CORRUPT;
+       if (f->track.time_scale == 0)
+               goto fail;
        *result = f;
        return 1;
 fail:
@@ -667,8 +672,6 @@ uint64_t mp4_get_duration(const struct mp4 *f)
 {
        const struct mp4_track *t = &f->track;
 
-       if (t->time_scale == 0)
-               return 0;
        return t->duration * 1000 / t->time_scale;
 }
 
@@ -722,12 +725,7 @@ uint16_t mp4_get_channel_count(const struct mp4 *f)
 
 uint32_t mp4_num_samples(const struct mp4 *f)
 {
-       const struct mp4_track *t = &f->track;
-       uint32_t total = 0;
-
-       for (uint32_t n = 0; n < t->stts_entry_count; n++)
-               total += t->stts_sample_count[n];
-       return total;
+       return f->track.stsz_sample_count;
 }
 
 int mp4_open_meta(const struct mp4_callback *cb, struct mp4 **result)
@@ -737,11 +735,6 @@ int mp4_open_meta(const struct mp4_callback *cb, struct mp4 **result)
 
        if (ret < 0)
                return ret;
-       if (f->udta_size == 0 || f->meta_size == 0 || f->ilst_size == 0) {
-               mp4_close(f);
-               *result = NULL;
-               return -E_MP4_MISSING_ATOM;
-       }
        *result = f;
        return 1;
 }
@@ -797,7 +790,7 @@ static void *modify_moov(struct mp4 *f, uint32_t *out_size)
 {
        int ret;
        uint64_t total_base = f->moov_offset + 8;
-       uint32_t total_size = (uint32_t) (f->moov_size - 8);
+       uint32_t total_size = f->moov_size - 8;
        uint32_t new_ilst_size = 0;
        void *out_buffer;
        uint8_t *p_out;
@@ -874,7 +867,7 @@ static int write_data(struct mp4 *f, void *data, size_t size)
        return 1;
 }
 
-int mp4_meta_update(struct mp4 *f)
+int mp4_update_meta(struct mp4 *f)
 {
        void *new_moov_data;
        uint32_t new_moov_size;