]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - mp4.c
mp4: Rename mp4_open_read() to mp4_open().
[paraslash.git] / mp4.c
diff --git a/mp4.c b/mp4.c
index 1c33a176e2fafd1d174017cea25edcfba536a5fb..2121155ccebeed885c78221e994e81acca3de846 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;
@@ -567,6 +566,21 @@ static int parse_sub_atoms(struct mp4 *f, uint64_t total_size, bool meta_only)
        return 1;
 }
 
+void mp4_close(struct mp4 *f)
+{
+       free(f->track.stsz_table);
+       free(f->track.stts_sample_count);
+       free(f->track.stsc_first_chunk);
+       free(f->track.stsc_samples_per_chunk);
+       free(f->track.stco_chunk_offset);
+       for (uint32_t n = 0; n < f->meta.count; n++) {
+               free(f->meta.tags[n].item);
+               free(f->meta.tags[n].value);
+       }
+       free(f->meta.tags);
+       free(f);
+}
+
 static int open_file(const struct mp4_callback *cb, bool meta_only, struct mp4 **result)
 {
        int ret;
@@ -599,11 +613,11 @@ static int open_file(const struct mp4_callback *cb, bool meta_only, struct mp4 *
        return 1;
 fail:
        *result = NULL;
-       free(f);
+       mp4_close(f);
        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;
@@ -615,6 +629,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:
@@ -622,21 +639,6 @@ fail:
        return ret;
 }
 
-void mp4_close(struct mp4 *f)
-{
-       free(f->track.stsz_table);
-       free(f->track.stts_sample_count);
-       free(f->track.stsc_first_chunk);
-       free(f->track.stsc_samples_per_chunk);
-       free(f->track.stco_chunk_offset);
-       for (uint32_t n = 0; n < f->meta.count; n++) {
-               free(f->meta.tags[n].item);
-               free(f->meta.tags[n].value);
-       }
-       free(f->meta.tags);
-       free(f);
-}
-
 static int32_t chunk_of_sample(const struct mp4 *f, int32_t sample,
                int32_t *chunk)
 {
@@ -667,8 +669,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 +722,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)
@@ -797,7 +792,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 +869,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;