tag = f->meta.tags + f->meta.count;
tag->item = para_strdup(get_metadata_name(parent));
tag->value = value;
- tag->len = len;
f->meta.count++;
return 1;
fail:
ret = read_int64(f, &t->duration);
if (ret <= 0)
return ret;
- } else { //version == 0
+ } else { /* version == 0 */
uint32_t temp;
skip_bytes(f, 8); /* creation time (4), modification time (4) */
return 1;
}
-static int32_t read_ilst(struct mp4 *f, int32_t size)
+static int read_ilst(struct mp4 *f, int32_t size)
{
int ret;
uint64_t sumsize = 0;
return 1;
}
-static int32_t read_meta(struct mp4 *f, uint64_t size)
+static int read_meta(struct mp4 *f, uint64_t size)
{
int ret;
uint64_t subsize, sumsize = 0;
return 1;
}
+void mp4_close(struct mp4 *f)
+{
+ free(f->track.stsz_table);
+ free(f->track.stts_sample_count);
+ free(f->track.stsc_first_chunk);
+ free(f->track.stsc_samples_per_chunk);
+ free(f->track.stco_chunk_offset);
+ for (uint32_t n = 0; n < f->meta.count; n++) {
+ free(f->meta.tags[n].item);
+ free(f->meta.tags[n].value);
+ }
+ free(f->meta.tags);
+ free(f);
+}
+
static int open_file(const struct mp4_callback *cb, bool meta_only, struct mp4 **result)
{
int ret;
ret = -E_MP4_TRACK;
if (f->track.channel_count == 0)
goto fail;
+ ret = -E_MP4_BAD_SAMPLERATE;
+ if (f->track.sample_rate == 0)
+ goto fail;
*result = f;
return 1;
fail:
*result = NULL;
- free(f);
+ mp4_close(f);
return ret;
}
int mp4_open_read(const struct mp4_callback *cb, struct mp4 **result)
{
- return open_file(cb, false, result);
-}
+ struct mp4 *f;
+ int ret;
-void mp4_close(struct mp4 *f)
-{
- free(f->track.stsz_table);
- free(f->track.stts_sample_count);
- free(f->track.stsc_first_chunk);
- free(f->track.stsc_samples_per_chunk);
- free(f->track.stco_chunk_offset);
- for (uint32_t n = 0; n < f->meta.count; n++) {
- free(f->meta.tags[n].item);
- free(f->meta.tags[n].value);
- }
- free(f->meta.tags);
- free(f);
+ *result = NULL;
+ ret = open_file(cb, false, &f);
+ if (ret < 0)
+ return ret;
+ ret = -E_MP4_BAD_SAMPLE_COUNT;
+ if (f->track.stsz_sample_count == 0)
+ goto fail;
+ ret = -E_MP4_CORRUPT;
+ if (f->track.time_scale == 0)
+ goto fail;
+ *result = f;
+ return 1;
+fail:
+ mp4_close(f);
+ return ret;
}
static int32_t chunk_of_sample(const struct mp4 *f, int32_t sample,
{
const struct mp4_track *t = &f->track;
- if (t->time_scale == 0)
- return 0;
return t->duration * 1000 / t->time_scale;
}
-int mp4_set_sample_position(struct mp4 *f, int32_t sample)
+int mp4_set_sample_position(struct mp4 *f, uint32_t sample)
{
const struct mp4_track *t = &f->track;
int32_t offset, chunk, chunk_sample;
return 1;
}
-int32_t mp4_get_sample_size(const struct mp4 *f, int sample)
+int mp4_get_sample_size(const struct mp4 *f, uint32_t sample, uint32_t *result)
{
const struct mp4_track *t = &f->track;
+ if (sample >= t->stsz_sample_count)
+ return -ERRNO_TO_PARA_ERROR(EINVAL);
if (t->stsz_sample_size != 0)
- return t->stsz_sample_size;
- return t->stsz_table[sample];
+ *result = t->stsz_sample_size;
+ else
+ *result = t->stsz_table[sample];
+ return 1;
}
-uint32_t mp4_get_sample_rate(const struct mp4 *f)
+uint16_t mp4_get_sample_rate(const struct mp4 *f)
{
return f->track.sample_rate;
}
-uint32_t mp4_get_channel_count(const struct mp4 *f)
+uint16_t mp4_get_channel_count(const struct mp4 *f)
{
return f->track.channel_count;
}
-int32_t mp4_num_samples(const struct mp4 *f)
+uint32_t mp4_num_samples(const struct mp4 *f)
{
- const struct mp4_track *t = &f->track;
- int32_t total = 0;
-
- for (uint32_t n = 0; n < t->stts_entry_count; n++)
- total += t->stts_sample_count[n];
- return total;
+ return f->track.stsz_sample_count;
}
int mp4_open_meta(const struct mp4_callback *cb, struct mp4 **result)
{
int ret;
uint64_t total_base = f->moov_offset + 8;
- uint32_t total_size = (uint32_t) (f->moov_size - 8);
+ uint32_t total_size = f->moov_size - 8;
uint32_t new_ilst_size = 0;
void *out_buffer;
uint8_t *p_out;
return 1;
}
-int mp4_meta_update(struct mp4 *f)
+int mp4_update_meta(struct mp4 *f)
{
void *new_moov_data;
uint32_t new_moov_size;