Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Peter Ross <pross@xvid.org>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 1/3] avformat/rmdec: support RMHD file format
Date: Sun, 3 Mar 2024 10:36:42 +1100
Message-ID: <85a99241dc108fad30290ffc7524541227c7dfdd.1709422402.git.pross@xvid.org> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 5705 bytes --]

Signed-off-by: Peter Ross <pross@xvid.org>
---
 libavformat/rmdec.c | 43 ++++++++++++++++++++++++++++++-------------
 1 file changed, 30 insertions(+), 13 deletions(-)

diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c
index 0f1534b582..e7f2480464 100644
--- a/libavformat/rmdec.c
+++ b/libavformat/rmdec.c
@@ -428,7 +428,8 @@ skip:
 static int rm_read_index(AVFormatContext *s)
 {
     AVIOContext *pb = s->pb;
-    unsigned int size, n_pkts, str_id, next_off, n, pos, pts;
+    unsigned int size, ver, n_pkts, str_id, next_off, n, pts;
+    uint64_t pos;
     AVStream *st;
 
     do {
@@ -437,10 +438,14 @@ static int rm_read_index(AVFormatContext *s)
         size     = avio_rb32(pb);
         if (size < 20)
             return -1;
-        avio_skip(pb, 2);
+        ver = avio_rb16(pb);
+        if (ver != 0 && ver != 2)
+            return AVERROR_INVALIDDATA;
         n_pkts   = avio_rb32(pb);
         str_id   = avio_rb16(pb);
         next_off = avio_rb32(pb);
+        if (ver == 2)
+            avio_skip(pb, 4);
         for (n = 0; n < s->nb_streams; n++)
             if (s->streams[n]->id == str_id) {
                 st = s->streams[n];
@@ -465,7 +470,7 @@ static int rm_read_index(AVFormatContext *s)
                 return AVERROR_INVALIDDATA;
             avio_skip(pb, 2);
             pts = avio_rb32(pb);
-            pos = avio_rb32(pb);
+            pos = (ver == 0) ? avio_rb32(pb) : avio_rb64(pb);
             avio_skip(pb, 4); /* packet no. */
 
             av_add_index_entry(st, pos, pts, 0, 0, AVINDEX_KEYFRAME);
@@ -546,8 +551,10 @@ static int rm_read_header(AVFormatContext *s)
     AVIOContext *pb = s->pb;
     unsigned int tag;
     int tag_size;
+    int ver;
     unsigned int start_time, duration;
-    unsigned int data_off = 0, indx_off = 0;
+    unsigned int data_off = 0;
+    uint64_t indx_off = 0;
     char buf[128], mime[128];
     int flags = 0;
     int ret;
@@ -558,7 +565,7 @@ static int rm_read_header(AVFormatContext *s)
     if (tag == MKTAG('.', 'r', 'a', 0xfd)) {
         /* very old .ra format */
         return rm_read_header_old(s);
-    } else if (tag != MKTAG('.', 'R', 'M', 'F')) {
+    } else if (tag != MKTAG('.', 'R', 'M', 'F') && tag != MKTAG('.', 'R', 'M', 'P')) {
         return AVERROR(EIO);
     }
 
@@ -572,10 +579,11 @@ static int rm_read_header(AVFormatContext *s)
             return AVERROR_INVALIDDATA;
         tag = avio_rl32(pb);
         tag_size = avio_rb32(pb);
-        avio_rb16(pb);
+        ver = avio_rb16(pb);
         av_log(s, AV_LOG_TRACE, "tag=%s size=%d\n",
                av_fourcc2str(tag), tag_size);
-        if (tag_size < 10 && tag != MKTAG('D', 'A', 'T', 'A'))
+        if ((tag_size < 10 && tag != MKTAG('D', 'A', 'T', 'A')) ||
+            (ver != 0 && ver != 2))
             return AVERROR_INVALIDDATA;
         switch(tag) {
         case MKTAG('P', 'R', 'O', 'P'):
@@ -588,7 +596,7 @@ static int rm_read_header(AVFormatContext *s)
             duration = avio_rb32(pb); /* duration */
             s->duration = av_rescale(duration, AV_TIME_BASE, 1000);
             avio_rb32(pb); /* preroll */
-            indx_off = avio_rb32(pb); /* index offset */
+            indx_off = (ver == 0) ? avio_rb32(pb) : avio_rb64(pb); /* index offset */
             data_off = avio_rb32(pb); /* data offset */
             avio_rb16(pb); /* nb streams */
             flags = avio_rb16(pb); /* flags */
@@ -650,15 +658,17 @@ static int rm_read_header(AVFormatContext *s)
     rm->nb_packets = avio_rb32(pb); /* number of packets */
     if (!rm->nb_packets && (flags & 4))
         rm->nb_packets = 3600 * 25;
+    if (ver == 2)
+        avio_skip(pb, 12);
     avio_rb32(pb); /* next data header */
 
     if (!data_off)
-        data_off = avio_tell(pb) - 18;
+        data_off = avio_tell(pb) - (ver == 0 ? 18 : 30);
     if (indx_off && (pb->seekable & AVIO_SEEKABLE_NORMAL) &&
         !(s->flags & AVFMT_FLAG_IGNIDX) &&
         avio_seek(pb, indx_off, SEEK_SET) >= 0) {
         rm_read_index(s);
-        avio_seek(pb, data_off + 18, SEEK_SET);
+        avio_seek(pb, data_off + (ver == 0 ? 18 : 30), SEEK_SET);
     }
 
     return 0;
@@ -703,12 +713,19 @@ static int rm_sync(AVFormatContext *s, int64_t *timestamp, int *flags, int *stre
             state= (state<<8) + avio_r8(pb);
 
             if(state == MKBETAG('I', 'N', 'D', 'X')){
+                int ver;
                 int n_pkts;
                 int64_t expected_len;
                 len = avio_rb32(pb);
-                avio_skip(pb, 2);
+                ver = avio_rb16(pb);
+                if (ver != 0 && ver != 2)
+                    return AVERROR_INVALIDDATA;
                 n_pkts = avio_rb32(pb);
-                expected_len = 20 + n_pkts * 14LL;
+
+                if (ver == 0)
+                    expected_len = 20 + n_pkts * 14LL;
+                else if (ver == 2)
+                    expected_len = 24 + n_pkts * 18LL;
 
                 if (len == 20 && expected_len <= INT_MAX)
                     /* some files don't add index entries to chunk size... */
@@ -1078,7 +1095,7 @@ static int rm_probe(const AVProbeData *p)
 {
     /* check file header */
     if ((p->buf[0] == '.' && p->buf[1] == 'R' &&
-         p->buf[2] == 'M' && p->buf[3] == 'F' &&
+         p->buf[2] == 'M' && (p->buf[3] == 'F' || p->buf[3] == 'P') &&
          p->buf[4] == 0 && p->buf[5] == 0) ||
         (p->buf[0] == '.' && p->buf[1] == 'r' &&
          p->buf[2] == 'a' && p->buf[3] == 0xfd))
-- 
2.43.0

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

             reply	other threads:[~2024-03-02 23:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-02 23:36 Peter Ross [this message]
2024-03-02 23:37 ` [FFmpeg-devel] [PATCH 2/3] avcodec/rv60: RealVideo 6.0 decoder Peter Ross
2024-03-03  7:55   ` Andreas Rheinhardt
2024-03-02 23:38 ` [FFmpeg-devel] [PATCH 3/3] fate: rv60 test cases Peter Ross
  -- strict thread matches above, loose matches on Subject: below --
2023-10-18  7:54 [FFmpeg-devel] [PATCH 1/3] avformat/rmdec: support RMHD file format Peter Ross

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=85a99241dc108fad30290ffc7524541227c7dfdd.1709422402.git.pross@xvid.org \
    --to=pross@xvid.org \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git