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
429429 static int rm_read_index(AVFormatContext *s)
430430 {
431431 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;
433434 AVStream *st;
434435
435436 do {
@@ -438,10 +439,14 @@ static int rm_read_index(AVFormatContext *s) · 2 unmodified lines
438439 size = avio_rb32(pb);
439440 if (size < 20)
440441 return -1;
441− avio_skip(pb, 2);
442+ ver = avio_rb16(pb);
443+ if (ver != 0 && ver != 2)
444+ return AVERROR_INVALIDDATA;
442445 n_pkts = avio_rb32(pb);
443446 str_id = avio_rb16(pb);
444447 next_off = avio_rb32(pb);
448+ if (ver == 2)
449+ avio_skip(pb, 4);
445450 for (n = 0; n < s->nb_streams; n++)
446451 if (s->streams[n]->id == str_id) {
447452 st = s->streams[n];
@@ -466,7 +471,7 @@ static int rm_read_index(AVFormatContext *s) · 18 unmodified lines
466471 return AVERROR_INVALIDDATA;
467472 avio_skip(pb, 2);
468473 pts = avio_rb32(pb);
469− pos = avio_rb32(pb);
474+ pos = (ver == 0) ? avio_rb32(pb) : avio_rb64(pb);
470475 avio_skip(pb, 4); /* packet no. */
471476
472477 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
547552 AVIOContext *pb = s->pb;
548553 unsigned int tag;
549554 int tag_size;
555+ int ver;
550556 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;
552559 char buf[128], mime[128];
553560 int flags = 0;
554561 int ret;
@@ -559,7 +566,7 @@ static int rm_read_header(AVFormatContext *s) · 4 unmodified lines
559566 if (tag == MKTAG('.', 'r', 'a', 0xfd)) {
560567 /* very old .ra format */
561568 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')) {
563570 return AVERROR(EIO);
564571 }
565572
@@ -573,10 +580,11 @@ static int rm_read_header(AVFormatContext *s) · 7 unmodified lines
573580 return AVERROR_INVALIDDATA;
574581 tag = avio_rl32(pb);
575582 tag_size = avio_rb32(pb);
576− avio_rb16(pb);
583+ ver = avio_rb16(pb);
577584 av_log(s, AV_LOG_TRACE, "tag=%s size=%d\n",
578585 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))
580588 return AVERROR_INVALIDDATA;
581589 switch(tag) {
582590 case MKTAG('P', 'R', 'O', 'P'):
@@ -589,7 +597,7 @@ static int rm_read_header(AVFormatContext *s) · 6 unmodified lines
589597 duration = avio_rb32(pb); /* duration */
590598 s->duration = av_rescale(duration, AV_TIME_BASE, 1000);
591599 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 */
593601 data_off = avio_rb32(pb); /* data offset */
594602 avio_rb16(pb); /* nb streams */
595603 flags = avio_rb16(pb); /* flags */
@@ -651,15 +659,17 @@ static int rm_read_header(AVFormatContext *s) · 55 unmodified lines
651659 rm->nb_packets = avio_rb32(pb); /* number of packets */
652660 if (!rm->nb_packets && (flags & 4))
653661 rm->nb_packets = 3600 * 25;
662+ if (ver == 2)
663+ avio_skip(pb, 12);
654664 avio_rb32(pb); /* next data header */
655665
656666 if (!data_off)
657− data_off = avio_tell(pb) - 18;
667+ data_off = avio_tell(pb) - (ver == 0 ? 18 : 30);
658668 if (indx_off && (pb->seekable & AVIO_SEEKABLE_NORMAL) &&
659669 !(s->flags & AVFMT_FLAG_IGNIDX) &&
660670 avio_seek(pb, indx_off, SEEK_SET) >= 0) {
661671 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);
663673 }
664674
665675 return 0;
@@ -704,12 +714,19 @@ static int rm_sync(AVFormatContext *s, int64_t *timestamp, int *flags, int *stre · 38 unmodified lines
704714 state= (state<<8) + avio_r8(pb);
705715
706716 if(state == MKBETAG('I', 'N', 'D', 'X')){
717+ int ver;
707718 int n_pkts;
708719 int64_t expected_len;
709720 len = avio_rb32(pb);
710− avio_skip(pb, 2);
721+ ver = avio_rb16(pb);
722+ if (ver != 0 && ver != 2)
723+ return AVERROR_INVALIDDATA;
711724 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;
713730
714731 if (len == 20 && expected_len <= INT_MAX)
715732 /* some files don't add index entries to chunk size... */
@@ -1079,7 +1096,7 @@ static int rm_probe(const AVProbeData *p) · 363 unmodified lines
10791096 {
10801097 /* check file header */
10811098 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') &&
10831100 p->buf[4] == 0 && p->buf[5] == 0) ||
10841101 (p->buf[0] == '.' && p->buf[1] == 'r' &&
10851102 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