#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, int8_t * data, uint32_t size)
+static int32_t mp4ff_read_data(mp4ff_t * f, void *data, uint32_t size)
{
int32_t result = 1;
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;
}
/* 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;
*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;
}
{
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:
}
}
-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;
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;
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;
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;
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;
}
static int32_t mp4ff_read_mp4a(mp4ff_t * f)
{
- uint64_t size;
int32_t i;
uint8_t atom_type = 0;
uint8_t header_size = 0;
mp4ff_read_int16(f);
- size = mp4ff_atom_read_header(f, &atom_type, &header_size);
+ mp4ff_atom_read_header(f, &atom_type, &header_size);
if (atom_type == ATOM_ESDS) {
mp4ff_read_esds(f);
}
}
static int32_t mp4ff_tag_add_field(mp4ff_metadata_t * tags, const char *item,
- char *value, int32_t len)
+ const char *value, int32_t len)
{
void *backup = (void *) tags->tags;
"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];
}
}
-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) {
return str;
}
-static int32_t mp4ff_set_metadata_name(mp4ff_t * f, const uint8_t atom_type,
- char **name)
+static int32_t mp4ff_set_metadata_name(const uint8_t atom_type, char **name)
{
static char *tag_names[] = {
"unknown", "title", "artist", "writer", "album",
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 */
if (data) {
if (!done) {
if (name == NULL)
- mp4ff_set_metadata_name(f, parent_atom_type,
- &name);
+ mp4ff_set_metadata_name(parent_atom_type, &name);
if (name)
mp4ff_tag_add_field(&(f->tags), name, data, len);
}
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;
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;
} 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);
}
/* 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;
}
/* 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;
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;
}
return 0;
}
-int32_t mp4ff_get_decoder_config(const mp4ff_t * f, const int track,
+void mp4ff_get_decoder_config(const mp4ff_t * f, const int track,
unsigned char **ppBuf, unsigned int *pBufSize)
{
if (track >= f->total_tracks) {
*ppBuf = NULL;
*pBufSize = 0;
- return 1;
+ return;
}
if (f->track[track]->decoderConfig == NULL
*ppBuf = malloc(f->track[track]->decoderConfigLen);
if (*ppBuf == NULL) {
*pBufSize = 0;
- return 1;
+ return;
}
memcpy(*ppBuf, f->track[track]->decoderConfig,
f->track[track]->decoderConfigLen);
return ff;
}
-int32_t mp4ff_tag_delete(mp4ff_metadata_t * tags)
+static int32_t mp4ff_tag_delete(mp4ff_metadata_t * tags)
{
uint32_t i;
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);
int32_t chunk2entry;
int32_t chunk1, chunk2, chunk1samples, range_samples, total = 0;
+ *chunk_sample = 0;
+ *chunk = 1;
if (f->track[track] == NULL) {
return -1;
}
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];
-
- if (p_track->stsz_sample_size) {
- bytes = p_track->stsz_sample_size;
- } else {
- bytes = p_track->stsz_table[sample];
- }
+ const mp4ff_track_t *t = f->track[track];
- 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)
#define stricmp strcasecmp
-membuffer *membuffer_create()
+static membuffer *membuffer_create(void)
{
const unsigned initial_size = 256;
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;
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,
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++) {
{"\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"},
};
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 */
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,
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;
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);
return 1;
}
-int32_t mp4ff_write_data(mp4ff_t * f, int8_t * data, uint32_t size)
+static int32_t mp4ff_write_data(mp4ff_t * f, void *data, uint32_t size)
{
int32_t result = 1;
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;
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);
}