split audio chunks in mov demuxer

Originally committed as revision 19018 to svn://svn.ffmpeg.org/ffmpeg/trunk
release/0.6
Baptiste Coudurier 16 years ago
parent 84c7d45e02
commit 7e69621f56
  1. 58
      libavformat/mov.c

@ -1403,49 +1403,47 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
} }
} }
} }
} else { /* read whole chunk */ } else {
unsigned int chunk_samples, chunk_size, chunk_duration;
unsigned int frames = 1;
for (i = 0; i < sc->chunk_count; i++) { for (i = 0; i < sc->chunk_count; i++) {
unsigned chunk_samples;
current_offset = sc->chunk_offsets[i]; current_offset = sc->chunk_offsets[i];
if (stsc_index + 1 < sc->stsc_count && if (stsc_index + 1 < sc->stsc_count &&
i + 1 == sc->stsc_data[stsc_index + 1].first) i + 1 == sc->stsc_data[stsc_index + 1].first)
stsc_index++; stsc_index++;
chunk_samples = sc->stsc_data[stsc_index].count; chunk_samples = sc->stsc_data[stsc_index].count;
/* get chunk size, beware of alaw/ulaw/mace */
if (sc->samples_per_frame > 0 && if (sc->samples_per_frame && chunk_samples % sc->samples_per_frame) {
(chunk_samples * sc->bytes_per_frame % sc->samples_per_frame == 0)) { av_log(mov->fc, AV_LOG_ERROR, "error unaligned chunk\n");
if (sc->samples_per_frame < 160) return;
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) { while (chunk_samples > 0) {
if (chunk_samples < sc->stts_data[stts_index].count) { unsigned size, samples;
chunk_duration += sc->stts_data[stts_index].duration * chunk_samples;
sc->stts_data[stts_index].count -= chunk_samples; if (sc->samples_per_frame >= 160) { // gsm
break; samples = sc->samples_per_frame;
size = sc->bytes_per_frame;
} else { } else {
chunk_duration += sc->stts_data[stts_index].duration * chunk_samples; if (sc->samples_per_frame > 1) {
chunk_samples -= sc->stts_data[stts_index].count; samples = FFMIN((1024 / sc->samples_per_frame)*
if (stts_index + 1 < sc->stts_count) sc->samples_per_frame, chunk_samples);
stts_index++; size = (samples / sc->samples_per_frame) * sc->bytes_per_frame;
} else {
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", " dprintf(mov->fc, "AVIndex stream %d, chunk %d, offset %"PRIx64", dts %"PRId64", "
"size %d, duration %d\n", st->index, i, current_offset, current_dts, "size %d, duration %d\n", st->index, i, current_offset, current_dts,
chunk_size, chunk_duration); size, samples);
current_offset += sc->bytes_per_frame;
assert(chunk_duration % sc->time_rate == 0); current_offset += size;
current_dts += chunk_duration / sc->time_rate; assert(samples % sc->time_rate == 0);
current_dts += samples / sc->time_rate;
chunk_samples -= samples;
} }
} }
} }

Loading…
Cancel
Save