aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBaptiste Coudurier <baptiste.coudurier@gmail.com>2009-05-31 04:36:26 +0000
committerBaptiste Coudurier <baptiste.coudurier@gmail.com>2009-05-31 04:36:26 +0000
commit7e69621f56455f4f886e358c7e31a7a9b6e9b51e (patch)
treeea240fc2a7421ade84d3ddc3636095bcec202113
parent84c7d45e02f274297d2257e54cb838d50131e1b0 (diff)
downloadffmpeg-7e69621f56455f4f886e358c7e31a7a9b6e9b51e.tar.gz
split audio chunks in mov demuxer
Originally committed as revision 19018 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r--libavformat/mov.c62
1 files changed, 30 insertions, 32 deletions
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 95341e6309..1c51e8bec6 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1403,49 +1403,47 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
}
}
}
- } else { /* read whole chunk */
- unsigned int chunk_samples, chunk_size, chunk_duration;
- unsigned int frames = 1;
+ } else {
for (i = 0; i < sc->chunk_count; i++) {
+ unsigned chunk_samples;
+
current_offset = sc->chunk_offsets[i];
if (stsc_index + 1 < sc->stsc_count &&
i + 1 == sc->stsc_data[stsc_index + 1].first)
stsc_index++;
chunk_samples = sc->stsc_data[stsc_index].count;
- /* get chunk size, beware of alaw/ulaw/mace */
- if (sc->samples_per_frame > 0 &&
- (chunk_samples * sc->bytes_per_frame % sc->samples_per_frame == 0)) {
- if (sc->samples_per_frame < 160)
- chunk_size = chunk_samples * sc->bytes_per_frame / sc->samples_per_frame;
- else {
- chunk_size = sc->bytes_per_frame;
- frames = chunk_samples / sc->samples_per_frame;
- chunk_samples = sc->samples_per_frame;
- }
- } else
- chunk_size = chunk_samples * sc->sample_size;
- for (j = 0; j < frames; j++) {
- av_add_index_entry(st, current_offset, current_dts, chunk_size, 0, AVINDEX_KEYFRAME);
- /* get chunk duration */
- chunk_duration = 0;
- while (chunk_samples > 0) {
- if (chunk_samples < sc->stts_data[stts_index].count) {
- chunk_duration += sc->stts_data[stts_index].duration * chunk_samples;
- sc->stts_data[stts_index].count -= chunk_samples;
- break;
+
+ if (sc->samples_per_frame && chunk_samples % sc->samples_per_frame) {
+ av_log(mov->fc, AV_LOG_ERROR, "error unaligned chunk\n");
+ return;
+ }
+
+ while (chunk_samples > 0) {
+ unsigned size, samples;
+
+ if (sc->samples_per_frame >= 160) { // gsm
+ samples = sc->samples_per_frame;
+ size = sc->bytes_per_frame;
+ } else {
+ if (sc->samples_per_frame > 1) {
+ samples = FFMIN((1024 / sc->samples_per_frame)*
+ sc->samples_per_frame, chunk_samples);
+ size = (samples / sc->samples_per_frame) * sc->bytes_per_frame;
} else {
- chunk_duration += sc->stts_data[stts_index].duration * chunk_samples;
- chunk_samples -= sc->stts_data[stts_index].count;
- if (stts_index + 1 < sc->stts_count)
- stts_index++;
+ samples = FFMIN(1024, chunk_samples);
+ size = samples * sc->sample_size;
}
}
+
+ av_add_index_entry(st, current_offset, current_dts, size, 0, AVINDEX_KEYFRAME);
dprintf(mov->fc, "AVIndex stream %d, chunk %d, offset %"PRIx64", dts %"PRId64", "
"size %d, duration %d\n", st->index, i, current_offset, current_dts,
- chunk_size, chunk_duration);
- current_offset += sc->bytes_per_frame;
- assert(chunk_duration % sc->time_rate == 0);
- current_dts += chunk_duration / sc->time_rate;
+ size, samples);
+
+ current_offset += size;
+ assert(samples % sc->time_rate == 0);
+ current_dts += samples / sc->time_rate;
+ chunk_samples -= samples;
}
}
}