History

avformat/rmdec: support RMHD file format

Peter Ross committed 2 years ago

Commit ae829541 parent c325f9c1 file · +30 −13Browse files

Unified · Split

libavformat/rmdec.c+30−13
@@ -429,7 +429,8 @@ skip: · 428 unmodified lines
429static int rm_read_index(AVFormatContext *s)429static int rm_read_index(AVFormatContext *s)
430{430{
431 AVIOContext *pb = s->pb;431 AVIOContext *pb = s->pb;
432 unsigned int size, n_pkts, str_id, next_off, n, pos, pts;432 unsigned int size, ver, n_pkts, str_id, next_off, n, pts;
433 uint64_t pos;
433 AVStream *st;434 AVStream *st;
434 435
435 do {436 do {
@@ -438,10 +439,14 @@ static int rm_read_index(AVFormatContext *s) · 2 unmodified lines
438 size = avio_rb32(pb);439 size = avio_rb32(pb);
439 if (size < 20)440 if (size < 20)
440 return -1;441 return -1;
441 avio_skip(pb, 2);442 ver = avio_rb16(pb);
443 if (ver != 0 && ver != 2)
444 return AVERROR_INVALIDDATA;
442 n_pkts = avio_rb32(pb);445 n_pkts = avio_rb32(pb);
443 str_id = avio_rb16(pb);446 str_id = avio_rb16(pb);
444 next_off = avio_rb32(pb);447 next_off = avio_rb32(pb);
448 if (ver == 2)
449 avio_skip(pb, 4);
445 for (n = 0; n < s->nb_streams; n++)450 for (n = 0; n < s->nb_streams; n++)
446 if (s->streams[n]->id == str_id) {451 if (s->streams[n]->id == str_id) {
447 st = s->streams[n];452 st = s->streams[n];
@@ -466,7 +471,7 @@ static int rm_read_index(AVFormatContext *s) · 18 unmodified lines
466 return AVERROR_INVALIDDATA;471 return AVERROR_INVALIDDATA;
467 avio_skip(pb, 2);472 avio_skip(pb, 2);
468 pts = avio_rb32(pb);473 pts = avio_rb32(pb);
469 pos = avio_rb32(pb);474 pos = (ver == 0) ? avio_rb32(pb) : avio_rb64(pb);
470 avio_skip(pb, 4); /* packet no. */475 avio_skip(pb, 4); /* packet no. */
471 476
472 av_add_index_entry(st, pos, pts, 0, 0, AVINDEX_KEYFRAME);477 av_add_index_entry(st, pos, pts, 0, 0, AVINDEX_KEYFRAME);
@@ -547,8 +552,10 @@ static int rm_read_header(AVFormatContext *s) · 74 unmodified lines
547 AVIOContext *pb = s->pb;552 AVIOContext *pb = s->pb;
548 unsigned int tag;553 unsigned int tag;
549 int tag_size;554 int tag_size;
555 int ver;
550 unsigned int start_time, duration;556 unsigned int start_time, duration;
551 unsigned int data_off = 0, indx_off = 0;557 unsigned int data_off = 0;
558 uint64_t indx_off = 0;
552 char buf[128], mime[128];559 char buf[128], mime[128];
553 int flags = 0;560 int flags = 0;
554 int ret;561 int ret;
@@ -559,7 +566,7 @@ static int rm_read_header(AVFormatContext *s) · 4 unmodified lines
559 if (tag == MKTAG('.', 'r', 'a', 0xfd)) {566 if (tag == MKTAG('.', 'r', 'a', 0xfd)) {
560 /* very old .ra format */567 /* very old .ra format */
561 return rm_read_header_old(s);568 return rm_read_header_old(s);
562 } else if (tag != MKTAG('.', 'R', 'M', 'F')) {569 } else if (tag != MKTAG('.', 'R', 'M', 'F') && tag != MKTAG('.', 'R', 'M', 'P')) {
563 return AVERROR(EIO);570 return AVERROR(EIO);
564 }571 }
565 572
@@ -573,10 +580,11 @@ static int rm_read_header(AVFormatContext *s) · 7 unmodified lines
573 return AVERROR_INVALIDDATA;580 return AVERROR_INVALIDDATA;
574 tag = avio_rl32(pb);581 tag = avio_rl32(pb);
575 tag_size = avio_rb32(pb);582 tag_size = avio_rb32(pb);
576 avio_rb16(pb);583 ver = avio_rb16(pb);
577 av_log(s, AV_LOG_TRACE, "tag=%s size=%d\n",584 av_log(s, AV_LOG_TRACE, "tag=%s size=%d\n",
578 av_fourcc2str(tag), tag_size);585 av_fourcc2str(tag), tag_size);
579 if (tag_size < 10 && tag != MKTAG('D', 'A', 'T', 'A'))586 if ((tag_size < 10 && tag != MKTAG('D', 'A', 'T', 'A')) ||
587 (ver != 0 && ver != 2))
580 return AVERROR_INVALIDDATA;588 return AVERROR_INVALIDDATA;
581 switch(tag) {589 switch(tag) {
582 case MKTAG('P', 'R', 'O', 'P'):590 case MKTAG('P', 'R', 'O', 'P'):
@@ -589,7 +597,7 @@ static int rm_read_header(AVFormatContext *s) · 6 unmodified lines
589 duration = avio_rb32(pb); /* duration */597 duration = avio_rb32(pb); /* duration */
590 s->duration = av_rescale(duration, AV_TIME_BASE, 1000);598 s->duration = av_rescale(duration, AV_TIME_BASE, 1000);
591 avio_rb32(pb); /* preroll */599 avio_rb32(pb); /* preroll */
592 indx_off = avio_rb32(pb); /* index offset */600 indx_off = (ver == 0) ? avio_rb32(pb) : avio_rb64(pb); /* index offset */
593 data_off = avio_rb32(pb); /* data offset */601 data_off = avio_rb32(pb); /* data offset */
594 avio_rb16(pb); /* nb streams */602 avio_rb16(pb); /* nb streams */
595 flags = avio_rb16(pb); /* flags */603 flags = avio_rb16(pb); /* flags */
@@ -651,15 +659,17 @@ static int rm_read_header(AVFormatContext *s) · 55 unmodified lines
651 rm->nb_packets = avio_rb32(pb); /* number of packets */659 rm->nb_packets = avio_rb32(pb); /* number of packets */
652 if (!rm->nb_packets && (flags & 4))660 if (!rm->nb_packets && (flags & 4))
653 rm->nb_packets = 3600 * 25;661 rm->nb_packets = 3600 * 25;
662 if (ver == 2)
663 avio_skip(pb, 12);
654 avio_rb32(pb); /* next data header */664 avio_rb32(pb); /* next data header */
655 665
656 if (!data_off)666 if (!data_off)
657 data_off = avio_tell(pb) - 18;667 data_off = avio_tell(pb) - (ver == 0 ? 18 : 30);
658 if (indx_off && (pb->seekable & AVIO_SEEKABLE_NORMAL) &&668 if (indx_off && (pb->seekable & AVIO_SEEKABLE_NORMAL) &&
659 !(s->flags & AVFMT_FLAG_IGNIDX) &&669 !(s->flags & AVFMT_FLAG_IGNIDX) &&
660 avio_seek(pb, indx_off, SEEK_SET) >= 0) {670 avio_seek(pb, indx_off, SEEK_SET) >= 0) {
661 rm_read_index(s);671 rm_read_index(s);
662 avio_seek(pb, data_off + 18, SEEK_SET);672 avio_seek(pb, data_off + (ver == 0 ? 18 : 30), SEEK_SET);
663 }673 }
664 674
665 return 0;675 return 0;
@@ -704,12 +714,19 @@ static int rm_sync(AVFormatContext *s, int64_t *timestamp, int *flags, int *stre · 38 unmodified lines
704 state= (state<<8) + avio_r8(pb);714 state= (state<<8) + avio_r8(pb);
705 715
706 if(state == MKBETAG('I', 'N', 'D', 'X')){716 if(state == MKBETAG('I', 'N', 'D', 'X')){
717 int ver;
707 int n_pkts;718 int n_pkts;
708 int64_t expected_len;719 int64_t expected_len;
709 len = avio_rb32(pb);720 len = avio_rb32(pb);
710 avio_skip(pb, 2);721 ver = avio_rb16(pb);
722 if (ver != 0 && ver != 2)
723 return AVERROR_INVALIDDATA;
711 n_pkts = avio_rb32(pb);724 n_pkts = avio_rb32(pb);
712 expected_len = 20 + n_pkts * 14LL;725
726 if (ver == 0)
727 expected_len = 20 + n_pkts * 14LL;
728 else if (ver == 2)
729 expected_len = 24 + n_pkts * 18LL;
713 730
714 if (len == 20 && expected_len <= INT_MAX)731 if (len == 20 && expected_len <= INT_MAX)
715 /* some files don't add index entries to chunk size... */732 /* some files don't add index entries to chunk size... */
@@ -1079,7 +1096,7 @@ static int rm_probe(const AVProbeData *p) · 363 unmodified lines
1079{1096{
1080 /* check file header */1097 /* check file header */
1081 if ((p->buf[0] == '.' && p->buf[1] == 'R' &&1098 if ((p->buf[0] == '.' && p->buf[1] == 'R' &&
1082 p->buf[2] == 'M' && p->buf[3] == 'F' &&1099 p->buf[2] == 'M' && (p->buf[3] == 'F' || p->buf[3] == 'P') &&
1083 p->buf[4] == 0 && p->buf[5] == 0) ||1100 p->buf[4] == 0 && p->buf[5] == 0) ||
1084 (p->buf[0] == '.' && p->buf[1] == 'r' &&1101 (p->buf[0] == '.' && p->buf[1] == 'r' &&
1085 p->buf[2] == 'a' && p->buf[3] == 0xfd))1102 p->buf[2] == 'a' && p->buf[3] == 0xfd))

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t