X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=mp4.c;h=372d5f4929f29422cb156262df6a7146c8829c77;hb=89a86169a6b96ccd3829c5600b667ec40bb56e47;hp=869b80fa966dbcef2d039935a4a44053d21f963b;hpb=83607bd0556f3c7aa5880567e3d089e76c0d9746;p=paraslash.git diff --git a/mp4.c b/mp4.c index 869b80fa..372d5f49 100644 --- a/mp4.c +++ b/mp4.c @@ -567,6 +567,21 @@ static int parse_sub_atoms(struct mp4 *f, uint64_t total_size, bool meta_only) 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; @@ -592,32 +607,34 @@ static int open_file(const struct mp4_callback *cb, bool meta_only, struct mp4 * 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; + *result = f; + return 1; +fail: + mp4_close(f); + return ret; } static int32_t chunk_of_sample(const struct mp4 *f, int32_t sample, @@ -680,29 +697,33 @@ int mp4_set_sample_position(struct mp4 *f, uint32_t 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; + uint32_t total = 0; for (uint32_t n = 0; n < t->stts_entry_count; n++) total += t->stts_sample_count[n];