X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=mp4.c;h=9f11a66e52aca8b9e561542be7ba6d65b36d9d0b;hb=8cad8d7112afc13a906f5c20026262bccecd95b5;hp=1b387534d6adcbca4521472d473ebad49c7973cb;hpb=b3ac1dc38bb8366ece6cbaf2adf95e964e0295c7;p=paraslash.git diff --git a/mp4.c b/mp4.c index 1b387534..9f11a66e 100644 --- a/mp4.c +++ b/mp4.c @@ -8,6 +8,7 @@ #include #include "para.h" +#include "error.h" #include "portable_io.h" #include "string.h" #include "mp4.h" @@ -988,9 +989,6 @@ static int32_t chunk_of_sample(const struct mp4 *f, int32_t track, *chunk_sample = 0; *chunk = 1; - if (f->track[track] == NULL) { - return -1; - } total_entries = f->track[track]->stsc_entry_count; @@ -1042,26 +1040,6 @@ static int32_t chunk_to_offset(const struct mp4 *f, int32_t track, return 0; } -static int32_t sample_range_size(const struct mp4 *f, int32_t track, - int32_t chunk_sample, int32_t sample) -{ - int32_t i, total; - const struct mp4_track *p_track = f->track[track]; - - if (p_track->stsz_sample_size) { - return (sample - chunk_sample) * p_track->stsz_sample_size; - } else { - if (sample >= p_track->stsz_sample_count) - return 0; //error - - for (i = chunk_sample, total = 0; i < sample; i++) { - total += p_track->stsz_table[i]; - } - } - - return total; -} - /** * Return the number of milliseconds of the given track. * @@ -1099,14 +1077,24 @@ bool mp4_is_audio_track(const struct mp4 *f, int32_t track) return f->track[track]->is_audio; } -void mp4_set_sample_position(struct mp4 *f, int32_t track, int32_t sample) +int mp4_set_sample_position(struct mp4 *f, uint32_t track, int32_t sample) { + const struct mp4_track *t = f->track[track]; int32_t offset, chunk, chunk_sample; + uint32_t n, srs; /* sample range size */ + if (sample >= t->stsz_sample_count || track >= f->total_tracks) + return -ERRNO_TO_PARA_ERROR(EINVAL); chunk_of_sample(f, track, sample, &chunk_sample, &chunk); - offset = chunk_to_offset(f, track, chunk) - + sample_range_size(f, track, chunk_sample, sample); + if (t->stsz_sample_size > 0) + srs = (sample - chunk_sample) * t->stsz_sample_size; + else { + for (srs = 0, n = chunk_sample; n < sample; n++) + srs += t->stsz_table[n]; + } + offset = chunk_to_offset(f, track, chunk) + srs; set_position(f, offset); + return 1; } int32_t mp4_get_sample_size(const struct mp4 *f, int track, int sample)