]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - mp4.c
mp4: Remove member moov_read of struct mp4ff.
[paraslash.git] / mp4.c
diff --git a/mp4.c b/mp4.c
index 58838d55261ebb7e73a48ce77cf4e9b66abb07c4..cdcfa6511abdae0ffc0dbfd8ac77be1288d39427 100644 (file)
--- a/mp4.c
+++ b/mp4.c
@@ -8,13 +8,12 @@
 #include "para.h"
 #include "mp4.h"
 
-#define USE_TAGGING
 int32_t mp4ff_total_tracks(const mp4ff_t * f)
 {
        return f->total_tracks;
 }
 
-int32_t mp4ff_read_data(mp4ff_t * f, void *data, uint32_t size)
+static int32_t mp4ff_read_data(mp4ff_t * f, void *data, uint32_t size)
 {
        int32_t result = 1;
 
@@ -40,12 +39,10 @@ static int32_t mp4ff_atom_get_size(const int8_t * data)
        d = (uint8_t) data[3];
 
        result = (a << 24) | (b << 16) | (c << 8) | d;
-       //if (result > 0 && result < 8) result = 8;
-
        return (int32_t) result;
 }
 
-uint64_t mp4ff_read_int64(mp4ff_t * f)
+static uint64_t mp4ff_read_int64(mp4ff_t * f)
 {
        uint8_t data[8];
        uint64_t result = 0;
@@ -324,7 +321,7 @@ static uint8_t mp4ff_atom_name_to_type(const int8_t a, const int8_t b,
 }
 
 /* read atom header, return atom size, atom size is with header included */
-uint64_t mp4ff_atom_read_header(mp4ff_t * f, uint8_t * atom_type,
+static uint64_t mp4ff_atom_read_header(mp4ff_t * f, uint8_t * atom_type,
                                uint8_t * header_size)
 {
        uint64_t size;
@@ -343,14 +340,12 @@ uint64_t mp4ff_atom_read_header(mp4ff_t * f, uint8_t * atom_type,
                *header_size = 16;
                size = mp4ff_read_int64(f);
        }
-       //printf("%c%c%c%c\n", atom_header[4], atom_header[5], atom_header[6], atom_header[7]);
-
        *atom_type = mp4ff_atom_name_to_type(atom_header[4], atom_header[5],
                atom_header[6], atom_header[7]);
        return size;
 }
 
-int64_t mp4ff_position(const mp4ff_t * f)
+static int64_t mp4ff_position(const mp4ff_t * f)
 {
        return f->current_position;
 }
@@ -359,19 +354,14 @@ static int need_parse_when_meta_only(uint8_t atom_type)
 {
        switch (atom_type) {
        case ATOM_EDTS:
-//      case ATOM_MDIA:
-//      case ATOM_MINF:
        case ATOM_DRMS:
        case ATOM_SINF:
        case ATOM_SCHI:
-//      case ATOM_STBL:
-//      case ATOM_STSD:
        case ATOM_STTS:
        case ATOM_STSZ:
        case ATOM_STZ2:
        case ATOM_STCO:
        case ATOM_STSC:
-//      case ATOM_CTTS:
        case ATOM_FRMA:
        case ATOM_IVIV:
        case ATOM_PRIV:
@@ -381,7 +371,7 @@ static int need_parse_when_meta_only(uint8_t atom_type)
        }
 }
 
-int32_t mp4ff_set_position(mp4ff_t * f, const int64_t position)
+static int32_t mp4ff_set_position(mp4ff_t * f, const int64_t position)
 {
        f->stream->seek(f->stream->user_data, position);
        f->current_position = position;
@@ -404,14 +394,14 @@ static void mp4ff_track_add(mp4ff_t * f)
        memset(f->track[f->total_tracks - 1], 0, sizeof (mp4ff_track_t));
 }
 
-uint8_t mp4ff_read_char(mp4ff_t * f)
+static uint8_t mp4ff_read_char(mp4ff_t * f)
 {
        uint8_t output;
        mp4ff_read_data(f, &output, 1);
        return output;
 }
 
-uint32_t mp4ff_read_int24(mp4ff_t * f)
+static uint32_t mp4ff_read_int24(mp4ff_t * f)
 {
        uint32_t result;
        uint32_t a, b, c;
@@ -426,7 +416,7 @@ uint32_t mp4ff_read_int24(mp4ff_t * f)
        return (uint32_t) result;
 }
 
-uint32_t mp4ff_read_int32(mp4ff_t * f)
+static uint32_t mp4ff_read_int32(mp4ff_t * f)
 {
        uint32_t result;
        uint32_t a, b, c, d;
@@ -630,7 +620,7 @@ static int32_t mp4ff_read_stco(mp4ff_t * f)
        return 0;
 }
 
-uint16_t mp4ff_read_int16(mp4ff_t * f)
+static uint16_t mp4ff_read_int16(mp4ff_t * f)
 {
        uint32_t result;
        uint32_t a, b;
@@ -644,7 +634,7 @@ uint16_t mp4ff_read_int16(mp4ff_t * f)
        return (uint16_t) result;
 }
 
-uint32_t mp4ff_read_mp4_descr_length(mp4ff_t * f)
+static uint32_t mp4ff_read_mp4_descr_length(mp4ff_t * f)
 {
        uint8_t b;
        uint8_t numBytes = 0;
@@ -900,7 +890,7 @@ static const char *ID3v1GenreList[] = {
        "Anime", "JPop", "SynthPop",
 };
 
-const char *mp4ff_meta_index_to_genre(uint32_t idx)
+static const char *mp4ff_meta_index_to_genre(uint32_t idx)
 {
        if (idx > 0 && idx <= sizeof (ID3v1GenreList) / sizeof (ID3v1GenreList[0])) {
                return ID3v1GenreList[idx - 1];
@@ -909,7 +899,7 @@ const char *mp4ff_meta_index_to_genre(uint32_t idx)
        }
 }
 
-char *mp4ff_read_string(mp4ff_t * f, uint32_t length)
+static char *mp4ff_read_string(mp4ff_t * f, uint32_t length)
 {
        char *str = (char *) malloc(length + 1);
        if (str != 0) {
@@ -1079,8 +1069,6 @@ static int32_t mp4ff_parse_tag(mp4ff_t * f, const uint8_t parent_atom_type,
                                                done = 1;
                                        }
                                } else if (parent_atom_type == ATOM_TRACK || parent_atom_type == ATOM_DISC) {
-                                       /* if (!done && subsize - header_size >= 8 + 8) */
-                                       /* modified by AJS */
                                        if (!done && (subsize - header_size) >= (sizeof (char) + sizeof (uint8_t) * 3 + sizeof (uint32_t) +     /* version + flags + reserved */
                                                                                 +(parent_atom_type == ATOM_TRACK ? sizeof (uint16_t) : 0)      /* leading uint16_t if ATOM_TRACK */
                                                                                 +sizeof (uint16_t)     /* track / disc */
@@ -1170,7 +1158,7 @@ static int32_t mp4ff_read_mdhd(mp4ff_t * f)
        return 1;
 }
 
-int32_t mp4ff_parse_metadata(mp4ff_t * f, const int32_t size)
+static int32_t mp4ff_parse_metadata(mp4ff_t * f, const int32_t size)
 {
        uint64_t subsize, sumsize = 0;
        uint8_t atom_type;
@@ -1212,7 +1200,7 @@ static int32_t mp4ff_read_meta(mp4ff_t * f, const uint64_t size)
        return 0;
 }
 
-int32_t mp4ff_atom_read(mp4ff_t * f, const int32_t size,
+static int32_t mp4ff_atom_read(mp4ff_t * f, const int32_t size,
                        const uint8_t atom_type)
 {
        uint64_t dest_position = mp4ff_position(f) + size - 8;
@@ -1240,11 +1228,9 @@ int32_t mp4ff_atom_read(mp4ff_t * f, const int32_t size,
        } else if (atom_type == ATOM_MDHD) {
                /* track header */
                mp4ff_read_mdhd(f);
-#ifdef USE_TAGGING
        } else if (atom_type == ATOM_META) {
                /* iTunes Metadata box */
                mp4ff_read_meta(f, size);
-#endif
        }
 
        mp4ff_set_position(f, dest_position);
@@ -1252,7 +1238,7 @@ int32_t mp4ff_atom_read(mp4ff_t * f, const int32_t size,
 }
 
 /* parse atoms that are sub atoms of other atoms */
-int32_t parse_sub_atoms(mp4ff_t * f, const uint64_t total_size, int meta_only)
+static int32_t parse_sub_atoms(mp4ff_t * f, const uint64_t total_size, int meta_only)
 {
        uint64_t size;
        uint8_t atom_type = 0;
@@ -1288,7 +1274,7 @@ int32_t parse_sub_atoms(mp4ff_t * f, const uint64_t total_size, int meta_only)
 }
 
 /* parse root atoms */
-int32_t parse_atoms(mp4ff_t * f, int meta_only)
+static int32_t parse_atoms(mp4ff_t * f, int meta_only)
 {
        uint64_t size;
        uint8_t atom_type = 0;
@@ -1302,14 +1288,7 @@ int32_t parse_atoms(mp4ff_t * f, int meta_only)
                f->file_size += size;
                f->last_atom = atom_type;
 
-               if (atom_type == ATOM_MDAT && f->moov_read) {
-                       /* moov atom is before mdat, we can stop reading when mdat is encountered */
-                       /* file position will stay at beginning of mdat data */
-//            break;
-               }
-
                if (atom_type == ATOM_MOOV && size > header_size) {
-                       f->moov_read = 1;
                        f->moov_offset = mp4ff_position(f) - header_size;
                        f->moov_size = size;
                }
@@ -1371,7 +1350,7 @@ mp4ff_t *mp4ff_open_read(mp4ff_callback_t * f)
        return ff;
 }
 
-int32_t mp4ff_tag_delete(mp4ff_metadata_t * tags)
+static int32_t mp4ff_tag_delete(mp4ff_metadata_t * tags)
 {
        uint32_t i;
 
@@ -1417,17 +1396,11 @@ void mp4ff_close(mp4ff_t * ff)
                                free(ff->track[i]->ctts_sample_count);
                        if (ff->track[i]->ctts_sample_offset)
                                free(ff->track[i]->ctts_sample_offset);
-#ifdef ITUNES_DRM
-                       if (ff->track[i]->p_drms)
-                               drms_free(ff->track[i]->p_drms);
-#endif
                        free(ff->track[i]);
                }
        }
 
-#ifdef USE_TAGGING
        mp4ff_tag_delete(&(ff->tags));
-#endif
 
        if (ff)
                free(ff);
@@ -1528,39 +1501,20 @@ static int32_t mp4ff_sample_to_offset(const mp4ff_t * f, const int32_t track,
        return chunk_offset2;
 }
 
-int32_t mp4ff_set_sample_position(mp4ff_t * f, const int32_t track,
-                                 const int32_t sample)
+void mp4ff_set_sample_position(mp4ff_t *f, const int32_t track,
+               const int32_t sample)
 {
-       int32_t offset;
-
-       offset = mp4ff_sample_to_offset(f, track, sample);
+       int32_t offset = mp4ff_sample_to_offset(f, track, sample);
        mp4ff_set_position(f, offset);
-
-       return 0;
 }
 
-int32_t mp4ff_audio_frame_size(const mp4ff_t * f, const int32_t track,
-               const int32_t sample)
+int32_t mp4ff_get_sample_size(const mp4ff_t *f, int track, int sample)
 {
-       int32_t bytes;
-       const mp4ff_track_t *p_track = f->track[track];
+       const mp4ff_track_t *t = f->track[track];
 
-       if (p_track->stsz_sample_size) {
-               bytes = p_track->stsz_sample_size;
-       } else {
-               bytes = p_track->stsz_table[sample];
-       }
-
-       return bytes;
-}
-
-int32_t mp4ff_read_sample_getsize(mp4ff_t * f, const int track,
-                                 const int sample)
-{
-       int32_t temp = mp4ff_audio_frame_size(f, track, sample);
-       if (temp < 0)
-               temp = 0;
-       return temp;
+       if (t->stsz_sample_size != 0)
+               return t->stsz_sample_size;
+       return t->stsz_table[sample];
 }
 
 uint32_t mp4ff_get_sample_rate(const mp4ff_t * f, const int32_t track)
@@ -1694,7 +1648,7 @@ typedef struct {
 
 #define stricmp strcasecmp
 
-membuffer *membuffer_create(void)
+static membuffer *membuffer_create(void)
 {
        const unsigned initial_size = 256;
 
@@ -1707,7 +1661,7 @@ membuffer *membuffer_create(void)
        return buf;
 }
 
-unsigned membuffer_write(membuffer * buf, const void *ptr, unsigned bytes)
+static unsigned membuffer_write(membuffer * buf, const void *ptr, unsigned bytes)
 {
        unsigned dest_size = buf->written + bytes;
 
@@ -1736,24 +1690,22 @@ unsigned membuffer_write(membuffer * buf, const void *ptr, unsigned bytes)
        return bytes;
 }
 
-#define membuffer_write_data membuffer_write
-
-unsigned membuffer_write_atom_name(membuffer * buf, const char *data)
+static unsigned membuffer_write_atom_name(membuffer * buf, const char *data)
 {
-       return membuffer_write_data(buf, data, 4) == 4 ? 1 : 0;
+       return membuffer_write(buf, data, 4) == 4 ? 1 : 0;
 }
 
-unsigned membuffer_write_int16(membuffer * buf, uint16_t data)
+static unsigned membuffer_write_int16(membuffer * buf, uint16_t data)
 {
        uint8_t temp[2] = { (uint8_t) (data >> 8), (uint8_t) data };
-       return membuffer_write_data(buf, temp, 2);
+       return membuffer_write(buf, temp, 2);
 }
 
-unsigned membuffer_write_int32(membuffer * buf, uint32_t data)
+static unsigned membuffer_write_int32(membuffer * buf, uint32_t data)
 {
        uint8_t temp[4] = { (uint8_t) (data >> 24), (uint8_t) (data >> 16),
                (uint8_t) (data >> 8), (uint8_t) data };
-       return membuffer_write_data(buf, temp, 4);
+       return membuffer_write(buf, temp, 4);
 }
 
 static void membuffer_write_track_tag(membuffer * buf, const char *name,
@@ -1796,7 +1748,7 @@ static uint32_t myatoi(const char *param)
        return param ? atoi(param) : 0;
 }
 
-uint32_t mp4ff_meta_genre_to_index(const char *genrestr)
+static uint32_t mp4ff_meta_genre_to_index(const char *genrestr)
 {
        unsigned n;
        for (n = 0; n < sizeof (ID3v1GenreList) / sizeof (ID3v1GenreList[0]); n++) {
@@ -1819,13 +1771,8 @@ static stdmeta_entry stdmetas[] = {
        {"\xA9" "day", "date"},
        {"\xA9" "too", "tool"},
        {"\xA9" "cmt", "comment"},
-//      {"\xA9" "gen","genre"},
        {"cpil", "compilation"},
-//      {"trkn","track"},
-//      {"disk","disc"},
-//      {"gnre","genre"},
        {"covr", "cover"},
-       /* added by AJS */
        {"aART", "album_artist"},
 };
 
@@ -1842,7 +1789,6 @@ static const char *find_standard_meta(const char *name)   //returns atom name if f
 static void membuffer_write_std_tag(membuffer * buf, const char *name,
                const char *value)
 {
-       /* added by AJS */
        uint32_t flags = 1;
 
        /* special check for compilation flag */
@@ -1860,7 +1806,7 @@ static void membuffer_write_std_tag(membuffer * buf, const char *name,
        membuffer_write_atom_name(buf, "data");
        membuffer_write_int32(buf, flags);      //flags
        membuffer_write_int32(buf, 0);  //reserved
-       membuffer_write_data(buf, value, strlen(value));
+       membuffer_write(buf, value, strlen(value));
 }
 
 static void membuffer_write_custom_tag(membuffer * buf, const char *name,
@@ -1875,38 +1821,38 @@ static void membuffer_write_custom_tag(membuffer * buf, const char *name,
        membuffer_write_int32(buf, 0x1C);       //weirdo itunes atom
        membuffer_write_atom_name(buf, "mean");
        membuffer_write_int32(buf, 0);
-       membuffer_write_data(buf, "com.apple.iTunes", 16);
+       membuffer_write(buf, "com.apple.iTunes", 16);
        membuffer_write_int32(buf, 12 + strlen(name));
        membuffer_write_atom_name(buf, "name");
        membuffer_write_int32(buf, 0);
-       membuffer_write_data(buf, name, strlen(name));
+       membuffer_write(buf, name, strlen(name));
        membuffer_write_int32(buf,
                8 /*data atom header */  +
                8 /*flags + reserved */  + strlen(value));
        membuffer_write_atom_name(buf, "data");
        membuffer_write_int32(buf, 1);  //flags
        membuffer_write_int32(buf, 0);  //reserved
-       membuffer_write_data(buf, value, strlen(value));
+       membuffer_write(buf, value, strlen(value));
 }
 
-unsigned membuffer_error(const membuffer * buf)
+static unsigned membuffer_error(const membuffer * buf)
 {
        return buf->error;
 }
 
-void membuffer_free(membuffer * buf)
+static void membuffer_free(membuffer * buf)
 {
        if (buf->data)
                free(buf->data);
        free(buf);
 }
 
-unsigned membuffer_get_size(const membuffer * buf)
+static unsigned membuffer_get_size(const membuffer * buf)
 {
        return buf->written;
 }
 
-void *membuffer_detach(membuffer * buf)
+static void *membuffer_detach(membuffer * buf)
 {
        void *ret;
 
@@ -2018,32 +1964,32 @@ static uint32_t create_ilst(const mp4ff_metadata_t * data, void **out_buffer,
        return 1;
 }
 
-void membuffer_write_atom(membuffer * buf, const char *name, unsigned size,
+static void membuffer_write_atom(membuffer * buf, const char *name, unsigned size,
                          const void *data)
 {
        membuffer_write_int32(buf, size + 8);
        membuffer_write_atom_name(buf, name);
-       membuffer_write_data(buf, data, size);
+       membuffer_write(buf, data, size);
 }
 
-void *membuffer_get_ptr(const membuffer * buf)
+static void *membuffer_get_ptr(const membuffer * buf)
 {
        return buf->data;
 }
 
-void membuffer_set_error(membuffer * buf)
+static void membuffer_set_error(membuffer * buf)
 {
        buf->error = 1;
 }
 
-unsigned membuffer_transfer_from_file(membuffer * buf, mp4ff_t * src,
+static unsigned membuffer_transfer_from_file(membuffer * buf, mp4ff_t * src,
                unsigned bytes)
 {
        unsigned oldsize;
        void *bufptr;
 
        oldsize = membuffer_get_size(buf);
-       if (membuffer_write_data(buf, 0, bytes) != bytes)
+       if (membuffer_write(buf, 0, bytes) != bytes)
                return 0;
 
        bufptr = membuffer_get_ptr(buf);
@@ -2238,7 +2184,7 @@ static uint32_t modify_moov(mp4ff_t * f, const mp4ff_metadata_t * data,
        return 1;
 }
 
-int32_t mp4ff_write_data(mp4ff_t * f, void *data, uint32_t size)
+static int32_t mp4ff_write_data(mp4ff_t * f, void *data, uint32_t size)
 {
        int32_t result = 1;
 
@@ -2249,7 +2195,7 @@ int32_t mp4ff_write_data(mp4ff_t * f, void *data, uint32_t size)
        return result;
 }
 
-int32_t mp4ff_write_int32(mp4ff_t * f, const uint32_t data)
+static int32_t mp4ff_write_int32(mp4ff_t * f, const uint32_t data)
 {
        uint32_t result;
        uint32_t a, b, c, d;
@@ -2266,7 +2212,7 @@ int32_t mp4ff_write_int32(mp4ff_t * f, const uint32_t data)
        return mp4ff_write_data(f, (uint8_t *) & result, sizeof (result));
 }
 
-int32_t mp4ff_truncate(mp4ff_t * f)
+static int32_t mp4ff_truncate(mp4ff_t * f)
 {
        return f->stream->truncate(f->stream->user_data);
 }