From patchwork Wed Oct 18 07:54:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Ross X-Patchwork-Id: 44287 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:3e0b:b0:15d:8365:d4b8 with SMTP id bk11csp900623pzc; Wed, 18 Oct 2023 00:55:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHx4c6P/K+jK2wmNRsQ5VEo37kPn1g6RMXHB0ziVoS/XUL5NeMpFm+2sa72b+6Nki309TAw X-Received: by 2002:a50:8dc6:0:b0:532:b974:671e with SMTP id s6-20020a508dc6000000b00532b974671emr3020653edh.41.1697615699858; Wed, 18 Oct 2023 00:54:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697615699; cv=none; d=google.com; s=arc-20160816; b=HGI5subU8tHVoBNF1wogCeyBmakgxCsH77Cd2iBhM+A2jpgMMKqO1Rba26Det3+t1/ p1UjST5eCYCs4RdYKhG9UNaDDEKo9YtjhuaCNnjTqWToyTQlvYAXkEALsQErg+6NdMNZ kgoAsgAL9YEMAZ+HGvIgW83zxvvUd59o7gl/qwrR79aPONAPoAQuS5crHEc1lclar3W0 pwSdxpEoF0lV1iHrMrQVh//9H2IBkhvdV6CLJYoIXneZb4+Fa4nQUwRZ0CdwoPy2PQsu FTBAsSk/Wo3OV60O6yCNn6e7omAvZR/cvtWaHxvnIqYvW3Na8yq7EBWlQGuscXDZNk48 sxVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:message-id:to:from:date:delivered-to; bh=hCRI7KbhOgx5UN47p1Bb0W5IuFyV4sTHl2TydKBa+JY=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=AqH2dKaCD76uhfFTz5nLtS48VbY4ZJb8qSUvyS+HDjo3Vh+wj/BAtoWwGWX3dBtO6g 5H0TaBI0ibxri854l8fTiO29GQR/JEYkBXFVU4UGY2DdO9SpAT+1k8vuB1YpA+JTrvIt atU/SoZMGnt5wEhKpPxdbCWC8N0NAwgNA+vc707mwfwo1vuuRkbgzb986tBT9YE+JGkW 6vQGdGCXoHO/QzRsexZdVGM8/13zhyz0Jio+9h9MThAbMEJSmv76848yx/EDc03k+lAL 7DmXcvfYnxfnAG7/3DIK9PQu2kMsItnTIfWpAGVKmVmHNTvkh0a5XUU/flmfQiqR+ggs sipA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 28-20020a50875c000000b005342ec1e69fsi1603787edv.157.2023.10.18.00.54.58; Wed, 18 Oct 2023 00:54:59 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E65DB68CA11; Wed, 18 Oct 2023 10:54:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mx.sdf.org (mx.sdf.org [205.166.94.24]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C96D968C8A5 for ; Wed, 18 Oct 2023 10:54:47 +0300 (EEST) Received: from 4a26a8a13dc63fff52050b6f577ab8b8 ([1.145.133.77]) (authenticated (0 bits)) by mx.sdf.org (8.16.1/8.14.5) with ESMTPSA id 39I7sbLF028025 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO) for ; Wed, 18 Oct 2023 07:54:43 GMT Date: Wed, 18 Oct 2023 18:54:33 +1100 From: Peter Ross To: ffmpeg-devel@ffmpeg.org Message-ID: <04cb126b825dc1e39c3b4140af8813ddfd03dfdb.1697615459.git.pross@xvid.org> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] avformat/rmdec: support RMHD file format X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: q/sxdg0vHMcQ --- libavformat/rmdec.c | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c index 0f1534b582..8e2ef7cc41 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; @@ -706,9 +716,15 @@ static int rm_sync(AVFormatContext *s, int64_t *timestamp, int *flags, int *stre int n_pkts; int64_t expected_len; len = avio_rb32(pb); - avio_skip(pb, 2); + int 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 +1094,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))