Mercurial > libavformat.hg
comparison mov.c @ 2902:cb12e3352bf5 libavformat
cosmetics, split overly long lines
author | bcoudurier |
---|---|
date | Sun, 06 Jan 2008 14:18:13 +0000 |
parents | 1caef0e2fb46 |
children | 354c859bbf66 |
comparison
equal
deleted
inserted
replaced
2901:0d0ffa1a0478 | 2902:cb12e3352bf5 |
---|---|
158 a.size = get_be32(pb); | 158 a.size = get_be32(pb); |
159 a.type = get_le32(pb); | 159 a.type = get_le32(pb); |
160 } | 160 } |
161 total_size += 8; | 161 total_size += 8; |
162 a.offset += 8; | 162 a.offset += 8; |
163 dprintf(c->fc, "type: %08x %.4s sz: %"PRIx64" %"PRIx64" %"PRIx64"\n", a.type, (char*)&a.type, a.size, atom.size, total_size); | 163 dprintf(c->fc, "type: %08x %.4s sz: %"PRIx64" %"PRIx64" %"PRIx64"\n", |
164 a.type, (char*)&a.type, a.size, atom.size, total_size); | |
164 if (a.size == 1) { /* 64 bit extended size */ | 165 if (a.size == 1) { /* 64 bit extended size */ |
165 a.size = get_be64(pb) - 8; | 166 a.size = get_be64(pb) - 8; |
166 a.offset += 8; | 167 a.offset += 8; |
167 total_size += 8; | 168 total_size += 8; |
168 } | 169 } |
215 | 216 |
216 /* component type */ | 217 /* component type */ |
217 ctype = get_le32(pb); | 218 ctype = get_le32(pb); |
218 type = get_le32(pb); /* component subtype */ | 219 type = get_le32(pb); /* component subtype */ |
219 | 220 |
220 dprintf(c->fc, "ctype= %c%c%c%c (0x%08x)\n", *((char *)&ctype), ((char *)&ctype)[1], ((char *)&ctype)[2], ((char *)&ctype)[3], (int) ctype); | 221 dprintf(c->fc, "ctype= %c%c%c%c (0x%08x)\n", *((char *)&ctype), ((char *)&ctype)[1], |
221 dprintf(c->fc, "stype= %c%c%c%c\n", *((char *)&type), ((char *)&type)[1], ((char *)&type)[2], ((char *)&type)[3]); | 222 ((char *)&ctype)[2], ((char *)&ctype)[3], (int) ctype); |
223 dprintf(c->fc, "stype= %c%c%c%c\n", | |
224 *((char *)&type), ((char *)&type)[1], ((char *)&type)[2], ((char *)&type)[3]); | |
222 if(!ctype) | 225 if(!ctype) |
223 c->isom = 1; | 226 c->isom = 1; |
224 if(type == MKTAG('v', 'i', 'd', 'e')) | 227 if(type == MKTAG('v', 'i', 'd', 'e')) |
225 st->codec->codec_type = CODEC_TYPE_VIDEO; | 228 st->codec->codec_type = CODEC_TYPE_VIDEO; |
226 else if(type == MKTAG('s', 'o', 'u', 'n')) | 229 else if(type == MKTAG('s', 'o', 'u', 'n')) |
617 id = codec_get_id(codec_bmp_tags, format); | 620 id = codec_get_id(codec_bmp_tags, format); |
618 if (id > 0) | 621 if (id > 0) |
619 st->codec->codec_type = CODEC_TYPE_VIDEO; | 622 st->codec->codec_type = CODEC_TYPE_VIDEO; |
620 } | 623 } |
621 | 624 |
622 dprintf(c->fc, "size=%d 4CC= %c%c%c%c codec_type=%d\n", | 625 dprintf(c->fc, "size=%d 4CC= %c%c%c%c codec_type=%d\n", size, |
623 size, | 626 (format >> 0) & 0xff, (format >> 8) & 0xff, (format >> 16) & 0xff, |
624 (format >> 0) & 0xff, (format >> 8) & 0xff, (format >> 16) & 0xff, (format >> 24) & 0xff, | 627 (format >> 24) & 0xff, st->codec->codec_type); |
625 st->codec->codec_type); | |
626 | 628 |
627 if(st->codec->codec_type==CODEC_TYPE_VIDEO) { | 629 if(st->codec->codec_type==CODEC_TYPE_VIDEO) { |
628 st->codec->codec_id = id; | 630 st->codec->codec_id = id; |
629 get_be16(pb); /* version */ | 631 get_be16(pb); /* version */ |
630 get_be16(pb); /* revision level */ | 632 get_be16(pb); /* revision level */ |
1321 unsigned int distance = 0; | 1323 unsigned int distance = 0; |
1322 | 1324 |
1323 st->nb_frames = sc->sample_count; | 1325 st->nb_frames = sc->sample_count; |
1324 for (i = 0; i < sc->chunk_count; i++) { | 1326 for (i = 0; i < sc->chunk_count; i++) { |
1325 current_offset = sc->chunk_offsets[i]; | 1327 current_offset = sc->chunk_offsets[i]; |
1326 if (stsc_index + 1 < sc->sample_to_chunk_sz && i + 1 == sc->sample_to_chunk[stsc_index + 1].first) | 1328 if (stsc_index + 1 < sc->sample_to_chunk_sz && |
1329 i + 1 == sc->sample_to_chunk[stsc_index + 1].first) | |
1327 stsc_index++; | 1330 stsc_index++; |
1328 for (j = 0; j < sc->sample_to_chunk[stsc_index].count; j++) { | 1331 for (j = 0; j < sc->sample_to_chunk[stsc_index].count; j++) { |
1329 if (current_sample >= sc->sample_count) { | 1332 if (current_sample >= sc->sample_count) { |
1330 av_log(mov->fc, AV_LOG_ERROR, "wrong sample count\n"); | 1333 av_log(mov->fc, AV_LOG_ERROR, "wrong sample count\n"); |
1331 goto out; | 1334 goto out; |
1335 distance = 0; | 1338 distance = 0; |
1336 if (stss_index + 1 < sc->keyframe_count) | 1339 if (stss_index + 1 < sc->keyframe_count) |
1337 stss_index++; | 1340 stss_index++; |
1338 } | 1341 } |
1339 sample_size = sc->sample_size > 0 ? sc->sample_size : sc->sample_sizes[current_sample]; | 1342 sample_size = sc->sample_size > 0 ? sc->sample_size : sc->sample_sizes[current_sample]; |
1340 dprintf(mov->fc, "AVIndex stream %d, sample %d, offset %"PRIx64", dts %"PRId64", size %d, distance %d, keyframe %d\n", | 1343 dprintf(mov->fc, "AVIndex stream %d, sample %d, offset %"PRIx64", dts %"PRId64", " |
1341 st->index, current_sample, current_offset, current_dts, sample_size, distance, keyframe); | 1344 "size %d, distance %d, keyframe %d\n", st->index, current_sample, |
1342 av_add_index_entry(st, current_offset, current_dts, sample_size, distance, keyframe ? AVINDEX_KEYFRAME : 0); | 1345 current_offset, current_dts, sample_size, distance, keyframe); |
1346 av_add_index_entry(st, current_offset, current_dts, sample_size, distance, | |
1347 keyframe ? AVINDEX_KEYFRAME : 0); | |
1343 current_offset += sample_size; | 1348 current_offset += sample_size; |
1344 assert(sc->stts_data[stts_index].duration % sc->time_rate == 0); | 1349 assert(sc->stts_data[stts_index].duration % sc->time_rate == 0); |
1345 current_dts += sc->stts_data[stts_index].duration / sc->time_rate; | 1350 current_dts += sc->stts_data[stts_index].duration / sc->time_rate; |
1346 distance++; | 1351 distance++; |
1347 stts_sample++; | 1352 stts_sample++; |
1354 } | 1359 } |
1355 } else { /* read whole chunk */ | 1360 } else { /* read whole chunk */ |
1356 unsigned int chunk_samples, chunk_size, chunk_duration; | 1361 unsigned int chunk_samples, chunk_size, chunk_duration; |
1357 for (i = 0; i < sc->chunk_count; i++) { | 1362 for (i = 0; i < sc->chunk_count; i++) { |
1358 current_offset = sc->chunk_offsets[i]; | 1363 current_offset = sc->chunk_offsets[i]; |
1359 if (stsc_index + 1 < sc->sample_to_chunk_sz && i + 1 == sc->sample_to_chunk[stsc_index + 1].first) | 1364 if (stsc_index + 1 < sc->sample_to_chunk_sz && |
1365 i + 1 == sc->sample_to_chunk[stsc_index + 1].first) | |
1360 stsc_index++; | 1366 stsc_index++; |
1361 chunk_samples = sc->sample_to_chunk[stsc_index].count; | 1367 chunk_samples = sc->sample_to_chunk[stsc_index].count; |
1362 /* get chunk size */ | 1368 /* get chunk size */ |
1363 if (sc->sample_size > 1 || st->codec->codec_id == CODEC_ID_PCM_U8 || st->codec->codec_id == CODEC_ID_PCM_S8) | 1369 if (sc->sample_size > 1 || |
1370 st->codec->codec_id == CODEC_ID_PCM_U8 || st->codec->codec_id == CODEC_ID_PCM_S8) | |
1364 chunk_size = chunk_samples * sc->sample_size; | 1371 chunk_size = chunk_samples * sc->sample_size; |
1365 else if (sc->samples_per_frame > 0 && (chunk_samples * sc->bytes_per_frame % sc->samples_per_frame == 0)) | 1372 else if (sc->samples_per_frame > 0 && |
1373 (chunk_samples * sc->bytes_per_frame % sc->samples_per_frame == 0)) | |
1366 chunk_size = chunk_samples * sc->bytes_per_frame / sc->samples_per_frame; | 1374 chunk_size = chunk_samples * sc->bytes_per_frame / sc->samples_per_frame; |
1367 else { /* workaround to find nearest next chunk offset */ | 1375 else { /* workaround to find nearest next chunk offset */ |
1368 chunk_size = INT_MAX; | 1376 chunk_size = INT_MAX; |
1369 for (j = 0; j < mov->fc->nb_streams; j++) { | 1377 for (j = 0; j < mov->fc->nb_streams; j++) { |
1370 MOVStreamContext *msc = mov->fc->streams[j]->priv_data; | 1378 MOVStreamContext *msc = mov->fc->streams[j]->priv_data; |
1371 for (k = msc->next_chunk; k < msc->chunk_count; k++) { | 1379 for (k = msc->next_chunk; k < msc->chunk_count; k++) { |
1372 if (msc->chunk_offsets[k] > current_offset && msc->chunk_offsets[k] - current_offset < chunk_size) { | 1380 if (msc->chunk_offsets[k] > current_offset && |
1381 msc->chunk_offsets[k] - current_offset < chunk_size) { | |
1373 chunk_size = msc->chunk_offsets[k] - current_offset; | 1382 chunk_size = msc->chunk_offsets[k] - current_offset; |
1374 msc->next_chunk = k; | 1383 msc->next_chunk = k; |
1375 break; | 1384 break; |
1376 } | 1385 } |
1377 } | 1386 } |
1379 /* check for last chunk */ | 1388 /* check for last chunk */ |
1380 if (chunk_size == INT_MAX) | 1389 if (chunk_size == INT_MAX) |
1381 for (j = 0; j < mov->mdat_count; j++) { | 1390 for (j = 0; j < mov->mdat_count; j++) { |
1382 dprintf(mov->fc, "mdat %d, offset %"PRIx64", size %"PRId64", current offset %"PRIx64"\n", | 1391 dprintf(mov->fc, "mdat %d, offset %"PRIx64", size %"PRId64", current offset %"PRIx64"\n", |
1383 j, mov->mdat_list[j].offset, mov->mdat_list[j].size, current_offset); | 1392 j, mov->mdat_list[j].offset, mov->mdat_list[j].size, current_offset); |
1384 if (mov->mdat_list[j].offset <= current_offset && mov->mdat_list[j].offset + mov->mdat_list[j].size > current_offset) | 1393 if (mov->mdat_list[j].offset <= current_offset && |
1394 mov->mdat_list[j].offset + mov->mdat_list[j].size > current_offset) | |
1385 chunk_size = mov->mdat_list[j].offset + mov->mdat_list[j].size - current_offset; | 1395 chunk_size = mov->mdat_list[j].offset + mov->mdat_list[j].size - current_offset; |
1386 } | 1396 } |
1387 assert(chunk_size != INT_MAX); | 1397 assert(chunk_size != INT_MAX); |
1388 for (j = 0; j < mov->fc->nb_streams; j++) { | 1398 for (j = 0; j < mov->fc->nb_streams; j++) { |
1389 MOVStreamContext *msc = mov->fc->streams[j]->priv_data; | 1399 MOVStreamContext *msc = mov->fc->streams[j]->priv_data; |
1404 if (stts_index + 1 < sc->stts_count) { | 1414 if (stts_index + 1 < sc->stts_count) { |
1405 stts_index++; | 1415 stts_index++; |
1406 } | 1416 } |
1407 } | 1417 } |
1408 } | 1418 } |
1409 dprintf(mov->fc, "AVIndex stream %d, chunk %d, offset %"PRIx64", dts %"PRId64", size %d, duration %d\n", | 1419 dprintf(mov->fc, "AVIndex stream %d, chunk %d, offset %"PRIx64", dts %"PRId64", size %d, " |
1410 st->index, i, current_offset, current_dts, chunk_size, chunk_duration); | 1420 "duration %d\n", st->index, i, current_offset, current_dts, chunk_size, chunk_duration); |
1411 assert(chunk_duration % sc->time_rate == 0); | 1421 assert(chunk_duration % sc->time_rate == 0); |
1412 current_dts += chunk_duration / sc->time_rate; | 1422 current_dts += chunk_duration / sc->time_rate; |
1413 } | 1423 } |
1414 } | 1424 } |
1415 out: | 1425 out: |
1491 for (i = 0; i < s->nb_streams; i++) { | 1501 for (i = 0; i < s->nb_streams; i++) { |
1492 AVStream *st = s->streams[i]; | 1502 AVStream *st = s->streams[i]; |
1493 MOVStreamContext *msc = st->priv_data; | 1503 MOVStreamContext *msc = st->priv_data; |
1494 if (st->discard != AVDISCARD_ALL && msc->current_sample < msc->sample_count) { | 1504 if (st->discard != AVDISCARD_ALL && msc->current_sample < msc->sample_count) { |
1495 AVIndexEntry *current_sample = &st->index_entries[msc->current_sample]; | 1505 AVIndexEntry *current_sample = &st->index_entries[msc->current_sample]; |
1496 int64_t dts = av_rescale(current_sample->timestamp * (int64_t)msc->time_rate, AV_TIME_BASE, msc->time_scale); | 1506 int64_t dts = av_rescale(current_sample->timestamp * (int64_t)msc->time_rate, |
1507 AV_TIME_BASE, msc->time_scale); | |
1497 dprintf(s, "stream %d, sample %d, dts %"PRId64"\n", i, msc->current_sample, dts); | 1508 dprintf(s, "stream %d, sample %d, dts %"PRId64"\n", i, msc->current_sample, dts); |
1498 if (!sample || (url_is_streamed(s->pb) && current_sample->pos < sample->pos) || | 1509 if (!sample || (url_is_streamed(s->pb) && current_sample->pos < sample->pos) || |
1499 (!url_is_streamed(s->pb) && | 1510 (!url_is_streamed(s->pb) && |
1500 ((FFABS(best_dts - dts) <= AV_TIME_BASE && current_sample->pos < sample->pos) || | 1511 ((FFABS(best_dts - dts) <= AV_TIME_BASE && current_sample->pos < sample->pos) || |
1501 (FFABS(best_dts - dts) > AV_TIME_BASE && dts < best_dts)))) { | 1512 (FFABS(best_dts - dts) > AV_TIME_BASE && dts < best_dts)))) { |
1508 if (!sample) | 1519 if (!sample) |
1509 return -1; | 1520 return -1; |
1510 /* must be done just before reading, to avoid infinite loop on sample */ | 1521 /* must be done just before reading, to avoid infinite loop on sample */ |
1511 sc->current_sample++; | 1522 sc->current_sample++; |
1512 if (url_fseek(s->pb, sample->pos, SEEK_SET) != sample->pos) { | 1523 if (url_fseek(s->pb, sample->pos, SEEK_SET) != sample->pos) { |
1513 av_log(mov->fc, AV_LOG_ERROR, "stream %d, offset 0x%"PRIx64": partial file\n", sc->ffindex, sample->pos); | 1524 av_log(mov->fc, AV_LOG_ERROR, "stream %d, offset 0x%"PRIx64": partial file\n", |
1525 sc->ffindex, sample->pos); | |
1514 return -1; | 1526 return -1; |
1515 } | 1527 } |
1516 #ifdef CONFIG_DV_DEMUXER | 1528 #ifdef CONFIG_DV_DEMUXER |
1517 if (sc->dv_audio_container) { | 1529 if (sc->dv_audio_container) { |
1518 dv_get_packet(mov->dv_demux, pkt); | 1530 dv_get_packet(mov->dv_demux, pkt); |
1533 if (sc->ctts_data) { | 1545 if (sc->ctts_data) { |
1534 assert(sc->ctts_data[sc->sample_to_ctime_index].duration % sc->time_rate == 0); | 1546 assert(sc->ctts_data[sc->sample_to_ctime_index].duration % sc->time_rate == 0); |
1535 pkt->pts = pkt->dts + sc->ctts_data[sc->sample_to_ctime_index].duration / sc->time_rate; | 1547 pkt->pts = pkt->dts + sc->ctts_data[sc->sample_to_ctime_index].duration / sc->time_rate; |
1536 /* update ctts context */ | 1548 /* update ctts context */ |
1537 sc->sample_to_ctime_sample++; | 1549 sc->sample_to_ctime_sample++; |
1538 if (sc->sample_to_ctime_index < sc->ctts_count && sc->ctts_data[sc->sample_to_ctime_index].count == sc->sample_to_ctime_sample) { | 1550 if (sc->sample_to_ctime_index < sc->ctts_count && |
1551 sc->ctts_data[sc->sample_to_ctime_index].count == sc->sample_to_ctime_sample) { | |
1539 sc->sample_to_ctime_index++; | 1552 sc->sample_to_ctime_index++; |
1540 sc->sample_to_ctime_sample = 0; | 1553 sc->sample_to_ctime_sample = 0; |
1541 } | 1554 } |
1542 } else { | 1555 } else { |
1543 pkt->pts = pkt->dts; | 1556 pkt->pts = pkt->dts; |
1544 } | 1557 } |
1545 pkt->flags |= sample->flags & AVINDEX_KEYFRAME ? PKT_FLAG_KEY : 0; | 1558 pkt->flags |= sample->flags & AVINDEX_KEYFRAME ? PKT_FLAG_KEY : 0; |
1546 pkt->pos = sample->pos; | 1559 pkt->pos = sample->pos; |
1547 dprintf(s, "stream %d, pts %"PRId64", dts %"PRId64", pos 0x%"PRIx64", duration %d\n", pkt->stream_index, pkt->pts, pkt->dts, pkt->pos, pkt->duration); | 1560 dprintf(s, "stream %d, pts %"PRId64", dts %"PRId64", pos 0x%"PRIx64", duration %d\n", |
1561 pkt->stream_index, pkt->pts, pkt->dts, pkt->pos, pkt->duration); | |
1548 return 0; | 1562 return 0; |
1549 } | 1563 } |
1550 | 1564 |
1551 static int mov_seek_stream(AVStream *st, int64_t timestamp, int flags) | 1565 static int mov_seek_stream(AVStream *st, int64_t timestamp, int flags) |
1552 { | 1566 { |