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. 62
      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; while (chunk_samples > 0) {
frames = chunk_samples / sc->samples_per_frame; unsigned size, samples;
chunk_samples = sc->samples_per_frame;
} if (sc->samples_per_frame >= 160) { // gsm
} else samples = sc->samples_per_frame;
chunk_size = chunk_samples * sc->sample_size; size = sc->bytes_per_frame;
for (j = 0; j < frames; j++) { } else {
av_add_index_entry(st, current_offset, current_dts, chunk_size, 0, AVINDEX_KEYFRAME); if (sc->samples_per_frame > 1) {
/* get chunk duration */ samples = FFMIN((1024 / sc->samples_per_frame)*
chunk_duration = 0; sc->samples_per_frame, chunk_samples);
while (chunk_samples > 0) { size = (samples / sc->samples_per_frame) * sc->bytes_per_frame;
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;
} else { } else {
chunk_duration += sc->stts_data[stts_index].duration * chunk_samples; samples = FFMIN(1024, chunk_samples);
chunk_samples -= sc->stts_data[stts_index].count; size = samples * sc->sample_size;
if (stts_index + 1 < sc->stts_count)
stts_index++;
} }
} }
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