]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - mp4.c
mp4: Remove two unused fields of struct mp4.
[paraslash.git] / mp4.c
diff --git a/mp4.c b/mp4.c
index 5eef09de489829a3284d0eef36339e74a857e366..9c8e41881c3e163d5ac00014100f83f552a6b228 100644 (file)
--- a/mp4.c
+++ b/mp4.c
@@ -13,7 +13,7 @@
 #include "mp4.h"
 
 struct mp4_track {
-       int32_t type;
+       bool is_audio;
        int32_t channelCount;
        int32_t sampleSize;
        uint16_t sampleRate;
@@ -41,14 +41,6 @@ struct mp4_track {
        int32_t stco_entry_count;
        int32_t *stco_chunk_offset;
 
-       /* ctts */
-       int32_t ctts_entry_count;
-       int32_t *ctts_sample_count;
-       int32_t *ctts_sample_offset;
-
-       uint32_t maxBitrate;
-       uint32_t avgBitrate;
-
        uint32_t timeScale;
        uint64_t duration;
 };
@@ -66,10 +58,6 @@ struct mp4 {
        uint64_t file_size;
        uint32_t error;
 
-       /* mvhd */
-       int32_t time_scale;
-       int32_t duration;
-
        /* incremental track index while reading the file */
        int32_t total_tracks;
 
@@ -107,23 +95,12 @@ static uint64_t read_int64(struct mp4 *f)
        return read_u64_be(data);
 }
 
-/* comnapre 2 atom names, returns 1 for equal, 0 for unequal */
-static int32_t atom_compare(int8_t a1, int8_t b1, int8_t c1, int8_t d1,
+static bool atom_compare(int8_t a1, int8_t b1, int8_t c1, int8_t d1,
                int8_t a2, int8_t b2, int8_t c2, int8_t d2)
 {
-       if (a1 == a2 && b1 == b2 && c1 == c2 && d1 == d2)
-               return 1;
-       else
-               return 0;
+       return a1 == a2 && b1 == b2 && c1 == c2 && d1 == d2;
 }
 
-enum tracks {
-       TRACK_UNKNOWN = 0,
-       TRACK_AUDIO  = 1,
-       TRACK_VIDEO = 2,
-       TRACK_SYSTEM = 3
-};
-
 enum atoms {
        /* atoms with subatoms */
        ATOM_MOOV = 1,
@@ -503,34 +480,6 @@ static int32_t read_stts(struct mp4 *f)
        return 1;
 }
 
-static int32_t read_ctts(struct mp4 *f)
-{
-       int32_t i;
-       struct mp4_track *t;
-
-       if (f->total_tracks == 0)
-               return f->error++;
-       t = f->track[f->total_tracks - 1];
-       if (t->ctts_entry_count)
-               return 0;
-
-       read_char(f);   /* version */
-       read_int24(f);  /* flags */
-       t->ctts_entry_count = read_int32(f);
-
-       t->ctts_sample_count = para_malloc(t->ctts_entry_count
-               * sizeof (int32_t));
-       t->ctts_sample_offset = para_malloc(t->ctts_entry_count
-               * sizeof (int32_t));
-
-       /* CVE-2017-9257 */
-       for (i = 0; i < t->ctts_entry_count && !f->stream->read_error; i++) {
-               t->ctts_sample_count[i] = read_int32(f);
-               t->ctts_sample_offset[i] = read_int32(f);
-       }
-       return 1;
-}
-
 static int32_t read_stsc(struct mp4 *f)
 {
        int32_t i;
@@ -642,49 +591,15 @@ static int32_t read_stsd(struct mp4 *f)
                uint8_t atom_type = 0;
                size = atom_read_header(f, &atom_type, &header_size);
                skip += size;
-
-               if (atom_type == ATOM_MP4A) {
-                       t->type = TRACK_AUDIO;
+               t->is_audio = atom_type == ATOM_MP4A;
+               if (t->is_audio)
                        read_mp4a(f);
-               } else if (atom_type == ATOM_MP4V) {
-                       t->type = TRACK_VIDEO;
-               } else if (atom_type == ATOM_MP4S) {
-                       t->type = TRACK_SYSTEM;
-               } else {
-                       t->type = TRACK_UNKNOWN;
-               }
                set_position(f, skip);
        }
 
        return 0;
 }
 
-static int32_t read_mvhd(struct mp4 *f)
-{
-       int32_t i;
-
-       read_char(f);   /* version */
-       read_int24(f);  /* flags */
-       read_int32(f); /* creation_time */
-       read_int32(f); /* modification_time */
-       f->time_scale = read_int32(f);
-       f->duration = read_int32(f);
-       read_int32(f); /* preferred_rate */
-       read_int16(f); /* preferred_volume */
-       for (i = 0; i < 10; i++)
-               read_char(f); /* reserved */
-       for (i = 0; i < 9; i++)
-               read_int32(f); /* matrix */
-       read_int32(f); /* preview_time */
-       read_int32(f); /* preview_duration */
-       read_int32(f); /* poster_time */
-       read_int32(f); /* selection_time */
-       read_int32(f); /* selection_duration */
-       read_int32(f); /* current_time */
-       read_int32(f); /* next_track_id */
-       return 0;
-}
-
 static int32_t tag_add_field(struct mp4_metadata *tags, const char *item,
                const char *value, int32_t len)
 {
@@ -1065,9 +980,6 @@ static int32_t atom_read(struct mp4 *f, int32_t size, uint8_t atom_type)
        } else if (atom_type == ATOM_STTS) {
                /* time to sample box */
                read_stts(f);
-       } else if (atom_type == ATOM_CTTS) {
-               /* composition offset box */
-               read_ctts(f);
        } else if (atom_type == ATOM_STSC) {
                /* sample to chunk box */
                read_stsc(f);
@@ -1077,9 +989,6 @@ static int32_t atom_read(struct mp4 *f, int32_t size, uint8_t atom_type)
        } else if (atom_type == ATOM_STSD) {
                /* sample description box */
                read_stsd(f);
-       } else if (atom_type == ATOM_MVHD) {
-               /* movie header box */
-               read_mvhd(f);
        } else if (atom_type == ATOM_MDHD) {
                /* track header */
                read_mdhd(f);
@@ -1204,8 +1113,6 @@ void mp4_close(struct mp4 *ff)
                        free(ff->track[i]->stsc_samples_per_chunk);
                        free(ff->track[i]->stsc_sample_desc_index);
                        free(ff->track[i]->stco_chunk_offset);
-                       free(ff->track[i]->ctts_sample_count);
-                       free(ff->track[i]->ctts_sample_offset);
                        free(ff->track[i]);
                }
        }
@@ -1339,7 +1246,7 @@ uint64_t mp4_get_duration(const struct mp4 *f, int32_t track)
  */
 bool mp4_is_audio_track(const struct mp4 *f, int32_t track)
 {
-       return f->track[track]->type == TRACK_AUDIO;
+       return f->track[track]->is_audio;
 }
 
 void mp4_set_sample_position(struct mp4 *f, int32_t track, int32_t sample)