#include "string.h"
#include "mp4.h"
-int32_t mp4ff_total_tracks(const mp4ff_t * f)
+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];
}
/* 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;
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,
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"},
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 *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];
+ struct mp4ff_tag *tag = &data->tags[metaptr];
if (!stricmp(tag->item, "tracknumber") || !stricmp(tag->item, "track")) {
if (tracknumber_ptr == 0)
tracknumber_ptr = tag->value;
for (metaptr = 0; metaptr < data->count; metaptr++) {
if (!mask[metaptr]) {
- mp4ff_tag_t *tag = &data->tags[metaptr];
+ struct mp4ff_tag *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,
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;
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);
}