#include "string.h"
#include "mp4.h"
-int32_t mp4ff_total_tracks(const mp4ff_t * f)
+struct mp4ff_track {
+ int32_t type;
+ int32_t channelCount;
+ int32_t sampleSize;
+ uint16_t sampleRate;
+ int32_t audioType;
+
+ /* stsd */
+ int32_t stsd_entry_count;
+
+ /* stsz */
+ int32_t stsz_sample_size;
+ int32_t stsz_sample_count;
+ int32_t *stsz_table;
+
+ /* stts */
+ int32_t stts_entry_count;
+ int32_t *stts_sample_count;
+ int32_t *stts_sample_delta;
+
+ /* stsc */
+ int32_t stsc_entry_count;
+ int32_t *stsc_first_chunk;
+ int32_t *stsc_samples_per_chunk;
+ int32_t *stsc_sample_desc_index;
+
+ /* stsc */
+ 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;
+
+ /* esde */
+ uint8_t *decoderConfig;
+ int32_t decoderConfigLen;
+
+ uint32_t maxBitrate;
+ uint32_t avgBitrate;
+
+ uint32_t timeScale;
+ uint64_t duration;
+};
+
+#define MAX_TRACKS 1024
+
+struct mp4ff {
+ /* stream to read from */
+ struct mp4ff_callback *stream;
+ int64_t current_position;
+
+ uint64_t moov_offset;
+ uint64_t moov_size;
+ uint8_t last_atom;
+ 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;
+
+ /* track data */
+ struct mp4ff_track *track[MAX_TRACKS];
+
+ /* metadata */
+ struct mp4ff_metadata tags;
+};
+
+int32_t mp4ff_total_tracks(const struct mp4ff *f)
{
return f->total_tracks;
}
-static int32_t read_data(mp4ff_t * f, void *data, uint32_t size)
+static int32_t read_data(struct mp4ff *f, void *data, uint32_t size)
{
int32_t result = 1;
return result;
}
-static uint64_t read_int64(mp4ff_t * f)
+static uint64_t read_int64(struct mp4ff *f)
{
uint8_t data[8];
return 0;
}
-#define TRACK_AUDIO 1
-#define TRACK_VIDEO 2
-#define TRACK_SYSTEM 3
-#define TRACK_UNKNOWN 0
-
-/* atoms with subatoms */
-#define ATOM_MOOV 1
-#define ATOM_TRAK 2
-#define ATOM_EDTS 3
-#define ATOM_MDIA 4
-#define ATOM_MINF 5
-#define ATOM_STBL 6
-#define ATOM_UDTA 7
-#define ATOM_ILST 8 /* iTunes Metadata list */
-#define ATOM_TITLE 9
-#define ATOM_ARTIST 10
-#define ATOM_WRITER 11
-#define ATOM_ALBUM 12
-#define ATOM_DATE 13
-#define ATOM_TOOL 14
-#define ATOM_COMMENT 15
-#define ATOM_GENRE1 16
-#define ATOM_TRACK 17
-#define ATOM_DISC 18
-#define ATOM_COMPILATION 19
-#define ATOM_GENRE2 20
-#define ATOM_TEMPO 21
-#define ATOM_COVER 22
-#define ATOM_DRMS 23
-#define ATOM_SINF 24
-#define ATOM_SCHI 25
-
-#define SUBATOMIC 128
-
-/* atoms without subatoms */
-#define ATOM_FTYP 129
-#define ATOM_MDAT 130
-#define ATOM_MVHD 131
-#define ATOM_TKHD 132
-#define ATOM_TREF 133
-#define ATOM_MDHD 134
-#define ATOM_VMHD 135
-#define ATOM_SMHD 136
-#define ATOM_HMHD 137
-#define ATOM_STSD 138
-#define ATOM_STTS 139
-#define ATOM_STSZ 140
-#define ATOM_STZ2 141
-#define ATOM_STCO 142
-#define ATOM_STSC 143
-#define ATOM_MP4A 144
-#define ATOM_MP4V 145
-#define ATOM_MP4S 146
-#define ATOM_ESDS 147
-#define ATOM_META 148 /* iTunes Metadata box */
-#define ATOM_NAME 149 /* iTunes Metadata name box */
-#define ATOM_DATA 150 /* iTunes Metadata data box */
-#define ATOM_CTTS 151
-#define ATOM_FRMA 152
-#define ATOM_IVIV 153
-#define ATOM_PRIV 154
-#define ATOM_USER 155
-#define ATOM_KEY 156
-#define ATOM_ALBUM_ARTIST 157
-#define ATOM_CONTENTGROUP 158
-#define ATOM_LYRICS 159
-#define ATOM_DESCRIPTION 160
-#define ATOM_NETWORK 161
-#define ATOM_SHOW 162
-#define ATOM_EPISODENAME 163
-#define ATOM_SORTTITLE 164
-#define ATOM_SORTALBUM 165
-#define ATOM_SORTARTIST 166
-#define ATOM_SORTALBUMARTIST 167
-#define ATOM_SORTWRITER 168
-#define ATOM_SORTSHOW 169
-#define ATOM_SEASON 170
-#define ATOM_EPISODE 171
-#define ATOM_PODCAST 172
-
-#define ATOM_UNKNOWN 255
+enum tracks {
+ TRACK_UNKNOWN = 0,
+ TRACK_AUDIO = 1,
+ TRACK_VIDEO = 2,
+ TRACK_SYSTEM = 3
+};
+
+enum atoms {
+ /* atoms with subatoms */
+ ATOM_MOOV = 1,
+ ATOM_TRAK = 2,
+ ATOM_EDTS = 3,
+ ATOM_MDIA = 4,
+ ATOM_MINF = 5,
+ ATOM_STBL = 6,
+ ATOM_UDTA = 7,
+ ATOM_ILST = 8, /* iTunes Metadata list */
+ ATOM_TITLE = 9,
+ ATOM_ARTIST = 10,
+ ATOM_WRITER = 11,
+ ATOM_ALBUM = 12,
+ ATOM_DATE = 13,
+ ATOM_TOOL = 14,
+ ATOM_COMMENT = 15,
+ ATOM_GENRE1 = 16,
+ ATOM_TRACK = 17,
+ ATOM_DISC = 18,
+ ATOM_COMPILATION = 19,
+ ATOM_GENRE2 = 20,
+ ATOM_TEMPO = 21,
+ ATOM_COVER = 22,
+ ATOM_DRMS = 23,
+ ATOM_SINF = 24,
+ ATOM_SCHI = 25,
+
+ SUBATOMIC = 128,
+
+ /* atoms without subatoms */
+ ATOM_FTYP = 129,
+ ATOM_MDAT = 130,
+ ATOM_MVHD = 131,
+ ATOM_TKHD = 132,
+ ATOM_TREF = 133,
+ ATOM_MDHD = 134,
+ ATOM_VMHD = 135,
+ ATOM_SMHD = 136,
+ ATOM_HMHD = 137,
+ ATOM_STSD = 138,
+ ATOM_STTS = 139,
+ ATOM_STSZ = 140,
+ ATOM_STZ2 = 141,
+ ATOM_STCO = 142,
+ ATOM_STSC = 143,
+ ATOM_MP4A = 144,
+ ATOM_MP4V = 145,
+ ATOM_MP4S = 146,
+ ATOM_ESDS = 147,
+ ATOM_META = 148, /* iTunes Metadata box */
+ ATOM_NAME = 149, /* iTunes Metadata name box */
+ ATOM_DATA = 150, /* iTunes Metadata data box */
+ ATOM_CTTS = 151,
+ ATOM_FRMA = 152,
+ ATOM_IVIV = 153,
+ ATOM_PRIV = 154,
+ ATOM_USER = 155,
+ ATOM_KEY = 156,
+ ATOM_ALBUM_ARTIST = 157,
+ ATOM_CONTENTGROUP = 158,
+ ATOM_LYRICS = 159,
+ ATOM_DESCRIPTION = 160,
+ ATOM_NETWORK = 161,
+ ATOM_SHOW = 162,
+ ATOM_EPISODENAME = 163,
+ ATOM_SORTTITLE = 164,
+ ATOM_SORTALBUM = 165,
+ ATOM_SORTARTIST = 166,
+ ATOM_SORTALBUMARTIST = 167,
+ ATOM_SORTWRITER = 168,
+ ATOM_SORTSHOW = 169,
+ ATOM_SEASON = 170,
+ ATOM_EPISODE = 171,
+ ATOM_PODCAST = 172,
+
+ ATOM_UNKNOWN = 255
+};
+
#define ATOM_FREE ATOM_UNKNOWN
#define ATOM_SKIP ATOM_UNKNOWN
}
/* read atom header, return atom size, atom size is with header included */
-static uint64_t atom_read_header(mp4ff_t * f, uint8_t * atom_type,
+static uint64_t atom_read_header(struct mp4ff *f, uint8_t * atom_type,
uint8_t * header_size)
{
uint64_t size;
return size;
}
-static int64_t get_position(const mp4ff_t * f)
+static int64_t get_position(const struct mp4ff *f)
{
return f->current_position;
}
}
}
-static int32_t set_position(mp4ff_t * f, const int64_t position)
+static int32_t set_position(struct mp4ff *f, const int64_t position)
{
f->stream->seek(f->stream->user_data, position);
f->current_position = position;
return 0;
}
-static void track_add(mp4ff_t * f)
+static void track_add(struct mp4ff *f)
{
f->total_tracks++;
f->error++;
return;
}
- f->track[f->total_tracks - 1] = para_calloc(sizeof (mp4ff_track_t));
+ f->track[f->total_tracks - 1] = para_calloc(sizeof(struct mp4ff_track));
}
-static uint8_t read_char(mp4ff_t * f)
+static uint8_t read_char(struct mp4ff *f)
{
uint8_t output;
read_data(f, &output, 1);
return output;
}
-static uint32_t read_int24(mp4ff_t * f)
+static uint32_t read_int24(struct mp4ff *f)
{
int8_t data[4];
return read_u24_be(data);
}
-static uint32_t read_int32(mp4ff_t * f)
+static uint32_t read_int32(struct mp4ff *f)
{
int8_t data[4];
return read_u32_be(data);
}
-static int32_t read_stsz(mp4ff_t * f)
+static int32_t read_stsz(struct mp4ff *f)
{
int32_t i;
- mp4ff_track_t *t;
+ struct mp4ff_track *t;
if (f->total_tracks == 0)
return f->error++;
return 0;
}
-static int32_t read_stts(mp4ff_t * f)
+static int32_t read_stts(struct mp4ff *f)
{
int32_t i;
- mp4ff_track_t *t;
+ struct mp4ff_track *t;
/* CVE-2017-9223 */
if (f->total_tracks == 0)
return 1;
}
-static int32_t read_ctts(mp4ff_t * f)
+static int32_t read_ctts(struct mp4ff *f)
{
int32_t i;
- mp4ff_track_t *t;
+ struct mp4ff_track *t;
if (f->total_tracks == 0)
return f->error++;
return 1;
}
-static int32_t read_stsc(mp4ff_t * f)
+static int32_t read_stsc(struct mp4ff *f)
{
int32_t i;
- mp4ff_track_t *t;
+ struct mp4ff_track *t;
if (f->total_tracks == 0)
return f->error++;
return 0;
}
-static int32_t read_stco(mp4ff_t * f)
+static int32_t read_stco(struct mp4ff *f)
{
int32_t i;
- mp4ff_track_t *t;
+ struct mp4ff_track *t;
if (f->total_tracks == 0)
return f->error++;
return 0;
}
-static uint16_t read_int16(mp4ff_t * f)
+static uint16_t read_int16(struct mp4ff *f)
{
int8_t data[2];
return read_u16_be(data);
}
-static uint32_t read_mp4_descr_length(mp4ff_t * f)
+static uint32_t read_mp4_descr_length(struct mp4ff *f)
{
uint8_t b;
uint8_t numBytes = 0;
return length;
}
-static int32_t read_esds(mp4ff_t * f)
+static int32_t read_esds(struct mp4ff *f)
{
uint8_t tag;
uint32_t temp;
- mp4ff_track_t *t;
+ struct mp4ff_track *t;
if (f->total_tracks == 0)
return f->error++;
return 0;
}
-static int32_t read_mp4a(mp4ff_t * f)
+static int32_t read_mp4a(struct mp4ff *f)
{
int32_t i;
uint8_t atom_type = 0;
uint8_t header_size = 0;
- mp4ff_track_t *t;
+ struct mp4ff_track *t;
if (f->total_tracks == 0)
return f->error++;
return 0;
}
-static int32_t read_stsd(mp4ff_t * f)
+static int32_t read_stsd(struct mp4ff *f)
{
int32_t i;
uint8_t header_size = 0;
- mp4ff_track_t *t;
+ struct mp4ff_track *t;
/* CVE-2017-9218 */
if (f->total_tracks == 0)
return 0;
}
-static int32_t read_mvhd(mp4ff_t * f)
+static int32_t read_mvhd(struct mp4ff *f)
{
int32_t i;
read_char(f); /* version */
read_int24(f); /* flags */
- /* creation_time */ read_int32(f);
- /* modification_time */ read_int32(f);
+ read_int32(f); /* creation_time */
+ read_int32(f); /* modification_time */
f->time_scale = read_int32(f);
f->duration = read_int32(f);
- /* preferred_rate */ read_int32(f);
- /*mp4ff_read_fixed32(f); */
- /* preferred_volume */ read_int16(f);
- /*mp4ff_read_fixed16(f); */
- for (i = 0; i < 10; i++) {
- /* reserved */ read_char(f);
- }
- for (i = 0; i < 9; i++) {
- read_int32(f); /* matrix */
- }
- /* 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 */ 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(mp4ff_metadata_t * tags, const char *item,
+static int32_t tag_add_field(struct mp4ff_metadata *tags, const char *item,
const char *value, int32_t len)
{
void *backup = (void *) tags->tags;
if (!item || (item && !*item) || !value)
return 0;
- tags->tags = (mp4ff_tag_t *) realloc(tags->tags,
- (tags->count + 1) * sizeof (mp4ff_tag_t));
+ tags->tags = (struct mp4ff_tag *)realloc(tags->tags,
+ (tags->count + 1) * sizeof(struct mp4ff_tag));
if (!tags->tags) {
free(backup);
return 0;
}
}
-static char *read_string(mp4ff_t *f, uint32_t length)
+static char *read_string(struct mp4ff *f, uint32_t length)
{
char *str = para_malloc(length + 1);
if ((uint32_t)read_data(f, str, length) != length) {
}
}
-static int32_t parse_tag(mp4ff_t * f, const uint8_t parent,
+static int32_t parse_tag(struct mp4ff *f, const uint8_t parent,
const int32_t size)
{
uint8_t atom_type;
return 1;
}
-static int32_t read_mdhd(mp4ff_t * f)
+static int32_t read_mdhd(struct mp4ff *f)
{
uint32_t version;
- mp4ff_track_t *t;
+ struct mp4ff_track *t;
/* CVE-2017-9221 */
if (f->total_tracks == 0)
return 1;
}
-static int32_t parse_metadata(mp4ff_t * f, const int32_t size)
+static int32_t parse_metadata(struct mp4ff *f, const int32_t size)
{
uint64_t subsize, sumsize = 0;
uint8_t atom_type;
return 0;
}
-static int32_t read_meta(mp4ff_t * f, const uint64_t size)
+static int32_t read_meta(struct mp4ff *f, const uint64_t size)
{
uint64_t subsize, sumsize = 0;
uint8_t atom_type;
return 0;
}
-static int32_t atom_read(mp4ff_t *f, const int32_t size,
+static int32_t atom_read(struct mp4ff *f, const int32_t size,
const uint8_t atom_type)
{
uint64_t dest_position = get_position(f) + size - 8;
}
/* parse atoms that are sub atoms of other atoms */
-static int32_t parse_sub_atoms(mp4ff_t * f, const uint64_t total_size, int meta_only)
+static int32_t parse_sub_atoms(struct mp4ff *f, const uint64_t total_size, int meta_only)
{
uint64_t size;
uint8_t atom_type = 0;
}
/* parse root atoms */
-static int32_t parse_atoms(mp4ff_t * f, int meta_only)
+static int32_t parse_atoms(struct mp4ff *f, int meta_only)
{
uint64_t size;
uint8_t atom_type = 0;
return 0;
}
-void mp4ff_get_decoder_config(const mp4ff_t * f, const int track,
+void mp4ff_get_decoder_config(const struct mp4ff *f, const int track,
unsigned char **ppBuf, unsigned int *pBufSize)
{
if (track >= f->total_tracks) {
}
}
-mp4ff_t *mp4ff_open_read(mp4ff_callback_t * f)
+struct mp4ff *mp4ff_open_read(struct mp4ff_callback *f)
{
- mp4ff_t *ff = para_calloc(sizeof(mp4ff_t));
+ struct mp4ff *ff = para_calloc(sizeof(struct mp4ff));
ff->stream = f;
return ff;
}
-static int32_t tag_delete(mp4ff_metadata_t * tags)
+static int32_t tag_delete(struct mp4ff_metadata *tags)
{
uint32_t i;
return 0;
}
-void mp4ff_close(mp4ff_t * ff)
+void mp4ff_close(struct mp4ff *ff)
{
int32_t i;
free(ff);
}
-static int32_t chunk_of_sample(const mp4ff_t * f, const int32_t track,
+static int32_t chunk_of_sample(const struct mp4ff *f, const int32_t track,
const int32_t sample, int32_t * chunk_sample, int32_t * chunk)
{
int32_t total_entries = 0;
return 0;
}
-static int32_t chunk_to_offset(const mp4ff_t * f, const int32_t track,
+static int32_t chunk_to_offset(const struct mp4ff *f, const int32_t track,
const int32_t chunk)
{
- const mp4ff_track_t *p_track = f->track[track];
+ const struct mp4ff_track *p_track = f->track[track];
if (p_track->stco_entry_count && (chunk > p_track->stco_entry_count)) {
return p_track->stco_chunk_offset[p_track->stco_entry_count -
return 0;
}
-static int32_t sample_range_size(const mp4ff_t * f, const int32_t track,
+static int32_t sample_range_size(const struct mp4ff *f, const int32_t track,
const int32_t chunk_sample, const int32_t sample)
{
int32_t i, total;
- const mp4ff_track_t *p_track = f->track[track];
+ const struct mp4ff_track *p_track = f->track[track];
if (p_track->stsz_sample_size) {
return (sample - chunk_sample) * p_track->stsz_sample_size;
return total;
}
-static int32_t sample_to_offset(const mp4ff_t * f, const int32_t track,
+static int32_t sample_to_offset(const struct mp4ff *f, const int32_t track,
const int32_t sample)
{
int32_t chunk, chunk_sample, chunk_offset1, chunk_offset2;
return chunk_offset2;
}
-void mp4ff_set_sample_position(mp4ff_t *f, const int32_t track,
+void mp4ff_set_sample_position(struct mp4ff *f, const int32_t track,
const int32_t sample)
{
int32_t offset = sample_to_offset(f, track, sample);
set_position(f, offset);
}
-int32_t mp4ff_get_sample_size(const mp4ff_t *f, int track, int sample)
+int32_t mp4ff_get_sample_size(const struct mp4ff *f, int track, int sample)
{
- const mp4ff_track_t *t = f->track[track];
+ const struct mp4ff_track *t = f->track[track];
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)
+uint32_t mp4ff_get_sample_rate(const struct mp4ff *f, const int32_t track)
{
return f->track[track]->sampleRate;
}
-uint32_t mp4ff_get_channel_count(const mp4ff_t * f, const int32_t track)
+uint32_t mp4ff_get_channel_count(const struct mp4ff *f, const int32_t track)
{
return f->track[track]->channelCount;
}
-int32_t mp4ff_num_samples(const mp4ff_t * f, const int32_t track)
+int32_t mp4ff_num_samples(const struct mp4ff *f, const int32_t track)
{
int32_t i;
int32_t total = 0;
return total;
}
-mp4ff_t *mp4ff_open_read_metaonly(mp4ff_callback_t * f)
+struct mp4ff *mp4ff_open_read_metaonly(struct mp4ff_callback *f)
{
- mp4ff_t *ff = para_calloc(sizeof(mp4ff_t));
+ struct mp4ff *ff = para_calloc(sizeof(struct mp4ff));
ff->stream = f;
return ff;
}
-int32_t mp4ff_meta_get_num_items(const mp4ff_t * f)
+int32_t mp4ff_meta_get_num_items(const struct mp4ff *f)
{
return f->tags.count;
}
-int32_t mp4ff_meta_get_by_index(const mp4ff_t * f, uint32_t index,
+int32_t mp4ff_meta_get_by_index(const struct mp4ff *f, uint32_t index,
char **item, char **value)
{
if (index >= f->tags.count) {
}
}
-static uint32_t find_atom(mp4ff_t * f, uint64_t base, uint32_t size,
+static uint32_t find_atom(struct mp4ff *f, uint64_t base, uint32_t size,
const char *name)
{
uint32_t remaining = size;
return 0;
}
-static uint32_t find_atom_v2(mp4ff_t * f, uint64_t base, uint32_t size,
+static uint32_t find_atom_v2(struct mp4ff *f, uint64_t base, uint32_t size,
const char *name, uint32_t extraheaders, const char *name_inside)
{
uint64_t first_base = (uint64_t) (-1);
return 0;
}
-typedef struct {
+struct membuffer {
void *data;
unsigned written;
unsigned allocated;
unsigned error;
-} membuffer;
-
-#define stricmp strcasecmp
+};
-static membuffer *membuffer_create(void)
+static struct membuffer *membuffer_create(void)
{
const unsigned initial_size = 256;
- membuffer *buf = para_malloc(sizeof (membuffer));
+ struct membuffer *buf = para_malloc(sizeof(*buf));
buf->data = para_malloc(initial_size);
buf->written = 0;
buf->allocated = initial_size;
return buf;
}
-static unsigned membuffer_write(membuffer * buf, const void *ptr, unsigned bytes)
+static unsigned membuffer_write(struct membuffer *buf, const void *ptr, unsigned bytes)
{
unsigned dest_size = buf->written + bytes;
return bytes;
}
-static unsigned membuffer_write_atom_name(membuffer * buf, const char *data)
+static unsigned membuffer_write_atom_name(struct membuffer *buf, const char *data)
{
return membuffer_write(buf, data, 4) == 4 ? 1 : 0;
}
-static unsigned membuffer_write_int16(membuffer * buf, uint16_t data)
+static unsigned membuffer_write_int16(struct membuffer *buf, uint16_t data)
{
uint8_t temp[2];
return membuffer_write(buf, temp, 2);
}
-static unsigned membuffer_write_int32(membuffer * buf, uint32_t data)
+static unsigned membuffer_write_int32(struct membuffer *buf, uint32_t data)
{
uint8_t temp[4];
write_u32_be(temp, data);
return membuffer_write(buf, temp, 4);
}
-static void membuffer_write_track_tag(membuffer * buf, const char *name,
+static void membuffer_write_track_tag(struct membuffer *buf, const char *name,
uint32_t index, uint32_t total)
{
membuffer_write_int32(buf,
membuffer_write_int16(buf, 0);
}
-static void membuffer_write_int16_tag(membuffer * buf, const char *name,
+static void membuffer_write_int16_tag(struct membuffer *buf, const char *name,
uint16_t value)
{
membuffer_write_int32(buf,
{
unsigned n;
for (n = 0; n < sizeof (ID3v1GenreList) / sizeof (ID3v1GenreList[0]); n++) {
- if (!stricmp(genrestr, ID3v1GenreList[n]))
+ if (!strcasecmp(genrestr, ID3v1GenreList[n]))
return n + 1;
}
return 0;
}
-typedef struct {
+struct stdmeta_entry {
const char *atom;
const char *name;
-} stdmeta_entry;
+};
-static stdmeta_entry stdmetas[] = {
+struct stdmeta_entry stdmetas[] = {
{"\xA9" "nam", "title"},
{"\xA9" "ART", "artist"},
{"\xA9" "wrt", "writer"},
{
unsigned n;
for (n = 0; n < sizeof (stdmetas) / sizeof (stdmetas[0]); n++) {
- if (!stricmp(name, stdmetas[n].name))
+ if (!strcasecmp(name, stdmetas[n].name))
return stdmetas[n].atom;
}
return 0;
}
-static void membuffer_write_std_tag(membuffer * buf, const char *name,
+static void membuffer_write_std_tag(struct membuffer *buf, const char *name,
const char *value)
{
uint32_t flags = 1;
membuffer_write(buf, value, strlen(value));
}
-static void membuffer_write_custom_tag(membuffer * buf, const char *name,
+static void membuffer_write_custom_tag(struct membuffer *buf, const char *name,
const char *value)
{
membuffer_write_int32(buf,
membuffer_write(buf, value, strlen(value));
}
-static unsigned membuffer_error(const membuffer * buf)
+static unsigned membuffer_error(const struct membuffer *buf)
{
return buf->error;
}
-static void membuffer_free(membuffer * buf)
+static void membuffer_free(struct membuffer *buf)
{
free(buf->data);
free(buf);
}
-static unsigned membuffer_get_size(const membuffer * buf)
+static unsigned membuffer_get_size(const struct membuffer *buf)
{
return buf->written;
}
-static void *membuffer_detach(membuffer * buf)
+static void *membuffer_detach(struct membuffer *buf)
{
void *ret;
return ret;
}
-static uint32_t create_ilst(const mp4ff_metadata_t * data, void **out_buffer,
+static uint32_t create_ilst(const struct mp4ff_metadata *data, void **out_buffer,
uint32_t * out_size)
{
- membuffer *buf = membuffer_create();
+ struct membuffer *buf = membuffer_create();
unsigned metaptr;
char *mask = para_calloc(data->count);
- {
- const char *tracknumber_ptr = 0, *totaltracks_ptr = 0;
- const char *discnumber_ptr = 0, *totaldiscs_ptr = 0;
- const char *genre_ptr = 0, *tempo_ptr = 0;
- for (metaptr = 0; metaptr < data->count; metaptr++) {
- mp4ff_tag_t *tag = &data->tags[metaptr];
- if (!stricmp(tag->item, "tracknumber") || !stricmp(tag->item, "track")) {
- if (tracknumber_ptr == 0)
- tracknumber_ptr = tag->value;
- mask[metaptr] = 1;
- } else if (!stricmp(tag->item, "totaltracks")) {
- if (totaltracks_ptr == 0)
- totaltracks_ptr = tag->value;
- mask[metaptr] = 1;
- } else if (!stricmp(tag->item, "discnumber")
- || !stricmp(tag->item, "disc")) {
- if (discnumber_ptr == 0)
- discnumber_ptr = tag->value;
- mask[metaptr] = 1;
- } else if (!stricmp(tag->item, "totaldiscs")) {
- if (totaldiscs_ptr == 0)
- totaldiscs_ptr = tag->value;
- mask[metaptr] = 1;
- } else if (!stricmp(tag->item, "genre")) {
- if (genre_ptr == 0)
- genre_ptr = tag->value;
- mask[metaptr] = 1;
- } else if (!stricmp(tag->item, "tempo")) {
- if (tempo_ptr == 0)
- tempo_ptr = tag->value;
- mask[metaptr] = 1;
- }
-
- }
+ const char *tracknumber_ptr = 0, *totaltracks_ptr = 0;
+ const char *discnumber_ptr = 0, *totaldiscs_ptr = 0;
+ const char *genre_ptr = 0, *tempo_ptr = 0;
- if (tracknumber_ptr)
- membuffer_write_track_tag(buf, "trkn",
- myatoi(tracknumber_ptr),
- myatoi(totaltracks_ptr));
- if (discnumber_ptr)
- membuffer_write_track_tag(buf, "disk",
- myatoi(discnumber_ptr),
- myatoi(totaldiscs_ptr));
- if (tempo_ptr)
- membuffer_write_int16_tag(buf, "tmpo",
- (uint16_t) myatoi(tempo_ptr));
-
- if (genre_ptr) {
- uint32_t index = meta_genre_to_index(genre_ptr);
- if (index == 0)
- membuffer_write_std_tag(buf, "©gen",
- genre_ptr);
- else
- membuffer_write_int16_tag(buf, "gnre",
- (uint16_t) index);
+ for (metaptr = 0; metaptr < data->count; metaptr++) {
+ struct mp4ff_tag *tag = &data->tags[metaptr];
+ if (!strcasecmp(tag->item, "tracknumber")
+ || !strcasecmp(tag->item, "track")) {
+ if (tracknumber_ptr == 0)
+ tracknumber_ptr = tag->value;
+ mask[metaptr] = 1;
+ } else if (!strcasecmp(tag->item, "totaltracks")) {
+ if (totaltracks_ptr == 0)
+ totaltracks_ptr = tag->value;
+ mask[metaptr] = 1;
+ } else if (!strcasecmp(tag->item, "discnumber")
+ || !strcasecmp(tag->item, "disc")) {
+ if (discnumber_ptr == 0)
+ discnumber_ptr = tag->value;
+ mask[metaptr] = 1;
+ } else if (!strcasecmp(tag->item, "totaldiscs")) {
+ if (totaldiscs_ptr == 0)
+ totaldiscs_ptr = tag->value;
+ mask[metaptr] = 1;
+ } else if (!strcasecmp(tag->item, "genre")) {
+ if (genre_ptr == 0)
+ genre_ptr = tag->value;
+ mask[metaptr] = 1;
+ } else if (!strcasecmp(tag->item, "tempo")) {
+ if (tempo_ptr == 0)
+ tempo_ptr = tag->value;
+ mask[metaptr] = 1;
}
}
- for (metaptr = 0; metaptr < data->count; metaptr++) {
- if (!mask[metaptr]) {
- mp4ff_tag_t *tag = &data->tags[metaptr];
- const char *std_meta_atom = find_standard_meta(tag->item);
- if (std_meta_atom) {
- membuffer_write_std_tag(buf, std_meta_atom,
- tag->value);
- } else {
- membuffer_write_custom_tag(buf, tag->item,
- tag->value);
- }
- }
+ if (tracknumber_ptr)
+ membuffer_write_track_tag(buf, "trkn", myatoi(tracknumber_ptr),
+ myatoi(totaltracks_ptr));
+ if (discnumber_ptr)
+ membuffer_write_track_tag(buf, "disk", myatoi(discnumber_ptr),
+ myatoi(totaldiscs_ptr));
+ if (tempo_ptr)
+ membuffer_write_int16_tag(buf, "tmpo", myatoi(tempo_ptr));
+
+ if (genre_ptr) {
+ uint32_t index = meta_genre_to_index(genre_ptr);
+ if (index == 0)
+ membuffer_write_std_tag(buf, "©gen", genre_ptr);
+ else
+ membuffer_write_int16_tag(buf, "gnre", index);
}
+ for (metaptr = 0; metaptr < data->count; metaptr++) {
+ struct mp4ff_tag *tag;
+ const char *std_meta_atom;
+ if (mask[metaptr])
+ continue;
+ tag = &data->tags[metaptr];
+ std_meta_atom = find_standard_meta(tag->item);
+ if (std_meta_atom)
+ membuffer_write_std_tag(buf, std_meta_atom, tag->value);
+ else
+ membuffer_write_custom_tag(buf, tag->item, tag->value);
+ }
free(mask);
if (membuffer_error(buf)) {
return 1;
}
-static void membuffer_write_atom(membuffer * buf, const char *name, unsigned size,
+static void membuffer_write_atom(struct membuffer *buf, const char *name, unsigned size,
const void *data)
{
membuffer_write_int32(buf, size + 8);
membuffer_write(buf, data, size);
}
-static void *membuffer_get_ptr(const membuffer * buf)
+static void *membuffer_get_ptr(const struct membuffer *buf)
{
return buf->data;
}
-static void membuffer_set_error(membuffer * buf)
+static void membuffer_set_error(struct membuffer *buf)
{
buf->error = 1;
}
-static unsigned membuffer_transfer_from_file(membuffer * buf, mp4ff_t * src,
+static unsigned membuffer_transfer_from_file(struct membuffer *buf, struct mp4ff *src,
unsigned bytes)
{
unsigned oldsize;
return bytes;
}
-static uint32_t create_meta(const mp4ff_metadata_t * data, void **out_buffer,
+static uint32_t create_meta(const struct mp4ff_metadata *data, void **out_buffer,
uint32_t * out_size)
{
- membuffer *buf;
+ struct membuffer *buf;
uint32_t ilst_size;
void *ilst_buffer;
return 1;
}
-static uint32_t create_udta(const mp4ff_metadata_t * data, void **out_buffer,
+static uint32_t create_udta(const struct mp4ff_metadata *data, void **out_buffer,
uint32_t * out_size)
{
- membuffer *buf;
+ struct membuffer *buf;
uint32_t meta_size;
void *meta_buffer;
return read_u32_be(&src);
}
-static uint32_t modify_moov(mp4ff_t * f, const mp4ff_metadata_t * data,
+static uint32_t modify_moov(struct mp4ff *f, const struct mp4ff_metadata *data,
void **out_buffer, uint32_t * out_size)
{
uint64_t total_base = f->moov_offset + 8;
int32_t size_delta;
if (!find_atom_v2(f, total_base, total_size, "udta", 0, "meta")) {
- membuffer *buf;
+ struct membuffer *buf;
void *new_udta_buffer;
uint32_t new_udta_size;
if (!create_udta(data, &new_udta_buffer, &new_udta_size))
udta_offset = get_position(f);
udta_size = read_int32(f);
if (!find_atom_v2 (f, udta_offset + 8, udta_size - 8, "meta", 4, "ilst")) {
- membuffer *buf;
+ struct membuffer *buf;
void *new_meta_buffer;
uint32_t new_meta_size;
if (!create_meta(data, &new_meta_buffer, &new_meta_size))
return 1;
}
-static int32_t write_data(mp4ff_t * f, void *data, uint32_t size)
+static int32_t write_data(struct mp4ff *f, void *data, uint32_t size)
{
int32_t result = 1;
return result;
}
-static int32_t write_int32(mp4ff_t * f, const uint32_t data)
+static int32_t write_int32(struct mp4ff *f, const uint32_t data)
{
int8_t temp[4];
write_u32_be(temp, data);
return write_data(f, temp, sizeof(temp));
}
-static int32_t truncate_stream(mp4ff_t * f)
+static int32_t truncate_stream(struct mp4ff *f)
{
return f->stream->truncate(f->stream->user_data);
}
-int32_t mp4ff_meta_update(mp4ff_callback_t * f, const mp4ff_metadata_t * data)
+int32_t mp4ff_meta_update(struct mp4ff_callback *f, const struct mp4ff_metadata *data)
{
void *new_moov_data;
uint32_t new_moov_size;
- mp4ff_t *ff = para_calloc(sizeof(mp4ff_t));
+ struct mp4ff *ff = para_calloc(sizeof(struct mp4ff));
ff->stream = f;
set_position(ff, 0);
/* find a metadata item by name */
/* returns 0 if item found, 1 if no such item */
-static int32_t meta_find_by_name(const mp4ff_t * f, const char *item,
+static int32_t meta_find_by_name(const struct mp4ff *f, const char *item,
char **value)
{
uint32_t i;
for (i = 0; i < f->tags.count; i++) {
- if (!stricmp(f->tags.tags[i].item, item)) {
+ if (!strcasecmp(f->tags.tags[i].item, item)) {
*value = para_strdup(f->tags.tags[i].value);
return 1;
}
return 0;
}
-int32_t mp4ff_meta_get_artist(const mp4ff_t * f, char **value)
+int32_t mp4ff_meta_get_artist(const struct mp4ff *f, char **value)
{
return meta_find_by_name(f, "artist", value);
}
-int32_t mp4ff_meta_get_title(const mp4ff_t * f, char **value)
+int32_t mp4ff_meta_get_title(const struct mp4ff *f, char **value)
{
return meta_find_by_name(f, "title", value);
}
-int32_t mp4ff_meta_get_date(const mp4ff_t * f, char **value)
+int32_t mp4ff_meta_get_date(const struct mp4ff *f, char **value)
{
return meta_find_by_name(f, "date", value);
}
-int32_t mp4ff_meta_get_album(const mp4ff_t * f, char **value)
+int32_t mp4ff_meta_get_album(const struct mp4ff *f, char **value)
{
return meta_find_by_name(f, "album", value);
}
-int32_t mp4ff_meta_get_comment(const mp4ff_t * f, char **value)
+int32_t mp4ff_meta_get_comment(const struct mp4ff *f, char **value)
{
return meta_find_by_name(f, "comment", value);
}