comparison mov.c @ 3030:5064dffc46b7 libavformat

split chunks in the case of big compressed audio frames, might be tweaked, fix qt_dv_pal_test.mov.
author bcoudurier
date Mon, 11 Feb 2008 22:32:35 +0000
parents 10abe8748ec2
children cc71bdb747fe
comparison
equal deleted inserted replaced
3029:10abe8748ec2 3030:5064dffc46b7
1373 } 1373 }
1374 } 1374 }
1375 } 1375 }
1376 } else { /* read whole chunk */ 1376 } else { /* read whole chunk */
1377 unsigned int chunk_samples, chunk_size, chunk_duration; 1377 unsigned int chunk_samples, chunk_size, chunk_duration;
1378 unsigned int frames = 1;
1378 for (i = 0; i < sc->chunk_count; i++) { 1379 for (i = 0; i < sc->chunk_count; i++) {
1379 current_offset = sc->chunk_offsets[i]; 1380 current_offset = sc->chunk_offsets[i];
1380 if (stsc_index + 1 < sc->sample_to_chunk_sz && 1381 if (stsc_index + 1 < sc->sample_to_chunk_sz &&
1381 i + 1 == sc->sample_to_chunk[stsc_index + 1].first) 1382 i + 1 == sc->sample_to_chunk[stsc_index + 1].first)
1382 stsc_index++; 1383 stsc_index++;
1385 if (sc->sample_size > 1 || 1386 if (sc->sample_size > 1 ||
1386 st->codec->codec_id == CODEC_ID_PCM_U8 || st->codec->codec_id == CODEC_ID_PCM_S8) 1387 st->codec->codec_id == CODEC_ID_PCM_U8 || st->codec->codec_id == CODEC_ID_PCM_S8)
1387 chunk_size = chunk_samples * sc->sample_size; 1388 chunk_size = chunk_samples * sc->sample_size;
1388 else if (sc->samples_per_frame > 0 && 1389 else if (sc->samples_per_frame > 0 &&
1389 (chunk_samples * sc->bytes_per_frame % sc->samples_per_frame == 0)) 1390 (chunk_samples * sc->bytes_per_frame % sc->samples_per_frame == 0))
1391 {
1392 if (sc->samples_per_frame < 1024)
1390 chunk_size = chunk_samples * sc->bytes_per_frame / sc->samples_per_frame; 1393 chunk_size = chunk_samples * sc->bytes_per_frame / sc->samples_per_frame;
1394 else {
1395 chunk_size = sc->bytes_per_frame;
1396 frames = chunk_samples / sc->samples_per_frame;
1397 chunk_samples = sc->samples_per_frame;
1398 }
1399 }
1391 else { /* workaround to find nearest next chunk offset */ 1400 else { /* workaround to find nearest next chunk offset */
1392 chunk_size = INT_MAX; 1401 chunk_size = INT_MAX;
1393 for (j = 0; j < mov->fc->nb_streams; j++) { 1402 for (j = 0; j < mov->fc->nb_streams; j++) {
1394 MOVStreamContext *msc = mov->fc->streams[j]->priv_data; 1403 MOVStreamContext *msc = mov->fc->streams[j]->priv_data;
1395 for (k = msc->next_chunk; k < msc->chunk_count; k++) { 1404 for (k = msc->next_chunk; k < msc->chunk_count; k++) {
1414 for (j = 0; j < mov->fc->nb_streams; j++) { 1423 for (j = 0; j < mov->fc->nb_streams; j++) {
1415 MOVStreamContext *msc = mov->fc->streams[j]->priv_data; 1424 MOVStreamContext *msc = mov->fc->streams[j]->priv_data;
1416 msc->next_chunk = 0; 1425 msc->next_chunk = 0;
1417 } 1426 }
1418 } 1427 }
1428 for (j = 0; j < frames; j++) {
1419 av_add_index_entry(st, current_offset, current_dts, chunk_size, 0, AVINDEX_KEYFRAME); 1429 av_add_index_entry(st, current_offset, current_dts, chunk_size, 0, AVINDEX_KEYFRAME);
1420 /* get chunk duration */ 1430 /* get chunk duration */
1421 chunk_duration = 0; 1431 chunk_duration = 0;
1422 while (chunk_samples > 0) { 1432 while (chunk_samples > 0) {
1423 if (chunk_samples < sc->stts_data[stts_index].count) { 1433 if (chunk_samples < sc->stts_data[stts_index].count) {
1430 if (stts_index + 1 < sc->stts_count) { 1440 if (stts_index + 1 < sc->stts_count) {
1431 stts_index++; 1441 stts_index++;
1432 } 1442 }
1433 } 1443 }
1434 } 1444 }
1445 current_offset += sc->bytes_per_frame;
1435 dprintf(mov->fc, "AVIndex stream %d, chunk %d, offset %"PRIx64", dts %"PRId64", size %d, " 1446 dprintf(mov->fc, "AVIndex stream %d, chunk %d, offset %"PRIx64", dts %"PRId64", size %d, "
1436 "duration %d\n", st->index, i, current_offset, current_dts, chunk_size, chunk_duration); 1447 "duration %d\n", st->index, i, current_offset, current_dts, chunk_size, chunk_duration);
1437 assert(chunk_duration % sc->time_rate == 0); 1448 assert(chunk_duration % sc->time_rate == 0);
1438 current_dts += chunk_duration / sc->time_rate; 1449 current_dts += chunk_duration / sc->time_rate;
1450 }
1439 } 1451 }
1440 } 1452 }
1441 out: 1453 out:
1442 /* adjust sample count to avindex entries */ 1454 /* adjust sample count to avindex entries */
1443 sc->sample_count = st->nb_index_entries; 1455 sc->sample_count = st->nb_index_entries;