From patchwork Sun Jun 12 17:18:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 36182 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp97253pzb; Sun, 12 Jun 2022 10:19:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiEI5+j99qOeipjEqPNbtMMUrZnNgOVwfDwFMZy2jFIeVx2Xa/He72RTlm/E7XfS7k5myY X-Received: by 2002:a17:906:561a:b0:711:cfa2:6a35 with SMTP id f26-20020a170906561a00b00711cfa26a35mr32461408ejq.251.1655054397281; Sun, 12 Jun 2022 10:19:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655054397; cv=none; d=google.com; s=arc-20160816; b=Ps4eDr49psAexDWMXeS7dHHAsoM+jIKKGAWyesMF3Yy7+JJBrtcASJCZj8biyffPcf GNThVdTUd9LnHQcsrNOCYjHseWjGxZs82J/r2/jWe/9Ov35aageEKaNcUOqTA+MTOkGM /wx1pYxJJq79YabEEvrNq5SutEbcDOmuwTUsjc+oL8kaWxmM7yrlFdglNuIP8EEdgDuF F0OYXhXMy28WICJWTFpv6PQWuKsPw2N4xe1n3hNG1Bmgi5qz6B8ZXtvey8BpavX4dpR2 DZwxmsHapZqfUbfzOjQ+z5LpwN1ehiHyBqPMbq/PB2rhNIlPpDZtVFk/IkLfZYyKlZTj WMKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=StKS2z4KJhGi6K4lSvQEmfpUTSgpHQOITvuytznG+/8=; b=v5BdGBKhLm2v2lMa2BXJ9X/XzEx1iQmBeHKbJ8AAxOYtCdvFhwdhqIMimDz8WcivO+ A5a/ZwbR2GHwuyqUXFfcgHWYzWoy1jf1B1gcdu7vQJHjjXHlJ4KtTCXyzWovsjy9TBpu OIFFzx6Is3q5aUR4SOHrra22zpxBxvcX6mxV2kj2haMLywdh1RqMyd24v3IrSu/60lo3 GBRGoD/JGOCLbBXCXH1URXKQexwWh58XBflBif2q14qYUGHXjWRtS7wfWZX9O/CYjSE9 xG7lTorSW9q9Pli3BH/HjJ5eGCTSmBGf+hoJTq1S+XC5CPbzZZBSG/u+mtLlFFQcWHej 1YeQ== 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 m7-20020a056402430700b00425f8164d96si6703988edc.9.2022.06.12.10.19.56; Sun, 12 Jun 2022 10:19:57 -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 78B9C68B4B3; Sun, 12 Jun 2022 20:19:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 416A468B583 for ; Sun, 12 Jun 2022 20:19:09 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id B2147E6EA7; Sun, 12 Jun 2022 19:19:09 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6HLuKwviS2js; Sun, 12 Jun 2022 19:19:08 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id EF311E6DC2; Sun, 12 Jun 2022 19:19:07 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sun, 12 Jun 2022 19:18:44 +0200 Message-Id: <20220612171845.8122-6-cus@passwd.hu> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220612171845.8122-1-cus@passwd.hu> References: <20220612171845.8122-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/7] avcodec/v210dec: add support for strideless v210 as in BOXX files 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 Cc: Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: iq/iQcKUIxSa Fixes ticket #1838. Signed-off-by: Marton Balint --- libavcodec/v210dec.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/libavcodec/v210dec.c b/libavcodec/v210dec.c index ba48bb6fe4..bf84cd4428 100644 --- a/libavcodec/v210dec.c +++ b/libavcodec/v210dec.c @@ -26,6 +26,7 @@ #include "v210dec.h" #include "v210dec_init.h" #include "libavutil/bswap.h" +#include "libavutil/imgutils.h" #include "libavutil/internal.h" #include "libavutil/intreadwrite.h" #include "thread.h" @@ -140,7 +141,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *pic, const uint8_t *psrc = avpkt->data; if (s->custom_stride ) - stride = s->custom_stride; + stride = s->custom_stride > 0 ? s->custom_stride : 0; else { stride = v210_stride(avctx->width, 48); if (avpkt->size < stride * avctx->height) { @@ -155,14 +156,21 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *pic, break; } } + if (align < 6 && avctx->codec_tag == MKTAG('b', 'x', 'y', '2')) + stride = 0; } } - if (avpkt->size < (int64_t)stride * avctx->height) { + if (stride == 0 && ((avctx->width & 1) || (int64_t)avctx->width * avctx->height > INT_MAX / 6)) { + av_log(avctx, AV_LOG_ERROR, "Strideless v210 is not supported for size %dx%d\n", avctx->width, avctx->height); + return AVERROR_INVALIDDATA; + } + + if (stride > 0 && avpkt->size < (int64_t)stride * avctx->height || + stride == 0 && avpkt->size < v210_stride(avctx->width * avctx->height, 6)) { av_log(avctx, AV_LOG_ERROR, "packet too small\n"); return AVERROR_INVALIDDATA; } - td.stride = stride; if ( avctx->codec_tag == MKTAG('C', '2', '1', '0') && avpkt->size > 64 && AV_RN32(psrc) == AV_RN32("INFO") @@ -181,9 +189,21 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *pic, pic->pict_type = AV_PICTURE_TYPE_I; pic->key_frame = 1; - td.buf = (uint8_t*)psrc; - td.frame = pic; - avctx->execute2(avctx, v210_decode_slice, &td, NULL, s->thread_count); + if (stride) { + td.stride = stride; + td.buf = (uint8_t*)psrc; + td.frame = pic; + avctx->execute2(avctx, v210_decode_slice, &td, NULL, s->thread_count); + } else { + uint8_t *pointers[4]; + int linesizes[4]; + int ret = av_image_alloc(pointers, linesizes, avctx->width, avctx->height, avctx->pix_fmt, 1); + if (ret < 0) + return ret; + decode_row((const uint32_t *)psrc, (uint16_t *)pointers[0], (uint16_t *)pointers[1], (uint16_t *)pointers[2], avctx->width * avctx->height, s->unpack_frame); + av_image_copy(pic->data, pic->linesize, (const uint8_t **)pointers, linesizes, avctx->pix_fmt, avctx->width, avctx->height); + av_freep(&pointers[0]); + } if (avctx->field_order > AV_FIELD_PROGRESSIVE) { /* we have interlaced material flagged in container */ @@ -200,7 +220,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *pic, #define V210DEC_FLAGS AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM static const AVOption v210dec_options[] = { {"custom_stride", "Custom V210 stride", offsetof(V210DecContext, custom_stride), AV_OPT_TYPE_INT, - {.i64 = 0}, 0, INT_MAX, V210DEC_FLAGS}, + {.i64 = 0}, -1, INT_MAX, V210DEC_FLAGS}, {NULL} };