From patchwork Sun Jun 12 17:18:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 36176 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp97001pzb; Sun, 12 Jun 2022 10:19:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/DjI4KGtD8GkQaNDBcqPx+52uc7re/ppHbhR2StzhC7P7gbd/y9nWb5ddvl5icKHq2od5 X-Received: by 2002:a05:6402:84a:b0:423:fe99:8c53 with SMTP id b10-20020a056402084a00b00423fe998c53mr60569138edz.195.1655054346508; Sun, 12 Jun 2022 10:19:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655054346; cv=none; d=google.com; s=arc-20160816; b=T/Q9XX20KzyiRLXcCpR+EXEdsrUPgAyL5Ut6H8SSMAYlkh7yOWpwsdzdp64Y9ChIYH hAQg/pBkJDmtdi143FtZTpDif7JRViW4jZtByo+Uf03hH5aKyx7zyts1EWcMp4c4rvkv Y3DgY8vxRIn8IHvO1yo2pXI6tjTQvat9pVRDajzKCet3mNzlu2xcltPyM7Y9LVJO2Ezh ckpiPNluwFZnnbc0CLjTeDCojE3zy6lKFk22eRIzrHaEPA+oWPrJiCS98GNhHkG80oiO eeqpa8HzUFEkwZQSKwNq161okEUc4c37zs74AbU2z6ZgXFOTR8Rf51cDGyqDRub8nM0T F3FA== 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:message-id:date:to:from :delivered-to; bh=aYvG9pbhdJ3gET5VF/FRsfe6bf17f/so35NjAk1XYLU=; b=PP5zvXnSNnqSKfzcJaR989gcWMRXcXD+C1gERqB2q3y/US/3mNtewyVw6bUQ8TnPV5 9MUYuDbT+uZptBRgcGeVTp1Oovq+7AmoQijHWDRjxpn6wkRQNaJIG2Acwdls7vvyh1YR KBNaByGsdC7swG00etxxX4FRSv+lm0++ZhbXRj+8QUwKwsJGcKPf2QFimBgk9+u6/th5 uHNXdFMjeIQPzWz3A4fgK7AgwDO5wcgH0PaB3yjbruiOmIyG/72vA8MbsxwI+vGPKytY Ik0bV0k349q+EMoWIMIO2mNttHTAJGUKlum+cu6OEIHE9iBYMxMFn2e0BJ3JbugILqRv htgg== 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 y5-20020a056402358500b004314951d63esi6389720edc.518.2022.06.12.10.19.05; Sun, 12 Jun 2022 10:19:06 -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 72CEE68B4C5; Sun, 12 Jun 2022 20:19:02 +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 D08C56881AC for ; Sun, 12 Jun 2022 20:18:56 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 0BE2EE70F7; Sun, 12 Jun 2022 19:18:51 +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 zM1LqBr6dntr; Sun, 12 Jun 2022 19:18:49 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 914AAE6B25; Sun, 12 Jun 2022 19:18:49 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sun, 12 Jun 2022 19:18:39 +0200 Message-Id: <20220612171845.8122-1-cus@passwd.hu> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/7] avcodec/v210dec: properly support odd widths 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: Ag2l15wkZpYc Fixes ticket #5195. Signed-off-by: Marton Balint --- libavcodec/v210dec.c | 49 +++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/libavcodec/v210dec.c b/libavcodec/v210dec.c index 6c10ef6a7c..48ebe57100 100644 --- a/libavcodec/v210dec.c +++ b/libavcodec/v210dec.c @@ -60,14 +60,16 @@ static int v210_decode_slice(AVCodecContext *avctx, void *arg, int jobnr, int th int slice_start = (avctx->height * jobnr) / s->thread_count; int slice_end = (avctx->height * (jobnr+1)) / s->thread_count; uint8_t *psrc = td->buf + stride * slice_start; - uint16_t *y, *u, *v; + int16_t *py = (uint16_t*)frame->data[0] + slice_start * frame->linesize[0] / 2; + int16_t *pu = (uint16_t*)frame->data[1] + slice_start * frame->linesize[1] / 2; + int16_t *pv = (uint16_t*)frame->data[2] + slice_start * frame->linesize[2] / 2; - y = (uint16_t*)frame->data[0] + slice_start * frame->linesize[0] / 2; - u = (uint16_t*)frame->data[1] + slice_start * frame->linesize[1] / 2; - v = (uint16_t*)frame->data[2] + slice_start * frame->linesize[2] / 2; for (h = slice_start; h < slice_end; h++) { const uint32_t *src = (const uint32_t*)psrc; uint32_t val; + uint16_t *y = py; + uint16_t *u = pu; + uint16_t *v = pv; w = (avctx->width / 12) * 12; s->unpack_frame(src, y, u, v, w); @@ -85,25 +87,40 @@ static int v210_decode_slice(AVCodecContext *avctx, void *arg, int jobnr, int th w += 6; } - if (w < avctx->width - 1) { + if (w++ < avctx->width) { READ_PIXELS(u, y, v); - val = av_le2ne32(*src++); - *y++ = val & 0x3FF; - if (w < avctx->width - 3) { - *u++ = (val >> 10) & 0x3FF; - *y++ = (val >> 20) & 0x3FF; - + if (w++ < avctx->width) { val = av_le2ne32(*src++); - *v++ = val & 0x3FF; - *y++ = (val >> 10) & 0x3FF; + *y++ = val & 0x3FF; + + if (w++ < avctx->width) { + *u++ = (val >> 10) & 0x3FF; + *y++ = (val >> 20) & 0x3FF; + val = av_le2ne32(*src++); + *v++ = val & 0x3FF; + + if (w++ < avctx->width) { + *y++ = (val >> 10) & 0x3FF; + + if (w++ < avctx->width) { + *u++ = (val >> 20) & 0x3FF; + val = av_le2ne32(*src++); + *y++ = val & 0x3FF; + *v++ = (val >> 10) & 0x3FF; + + if (w++ < avctx->width) + *y++ = (val >> 20) & 0x3FF; + } + } + } } } psrc += stride; - y += frame->linesize[0] / 2 - avctx->width + (avctx->width & 1); - u += frame->linesize[1] / 2 - avctx->width / 2; - v += frame->linesize[2] / 2 - avctx->width / 2; + py += frame->linesize[0] / 2; + pu += frame->linesize[1] / 2; + pv += frame->linesize[2] / 2; } return 0; From patchwork Sun Jun 12 17:18:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 36178 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp97078pzb; Sun, 12 Jun 2022 10:19:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMTtGp08uDGCY32hQV81H4OeMvLIgfYOpWrowAB52mKXI1civBUxaCGPPzSiZMPcxfw5Nl X-Received: by 2002:a17:907:162c:b0:712:18e:33e4 with SMTP id hb44-20020a170907162c00b00712018e33e4mr16903321ejc.187.1655054363831; Sun, 12 Jun 2022 10:19:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655054363; cv=none; d=google.com; s=arc-20160816; b=DGVgmJzd7fpPXPQ1S6VrKShaH1Q9stiP+3ih8+UOrLlKg9kLvK2c5JwMRL8FS1rPo7 TLxjlTCOYw8Z/ujUydZXvoq95C2TIFZGcHBZyovqjyYc3wt2sekeKmEHFa2b5fJFuIwP VpxtyqeBBtHJNJW8Atwclsu5ZX5ec27s0h2yS+l7GOfBDtjMaESSN2Dt+NBHP3fdo4Wu PFZ3YH8vOBeJRWOTFgrvQdvNCIe2OAh9uoUEjNreUe5rH+vEVuCpS55BSxZ5F15vqykp kvQn0AcnO4vuMjNZoPOmdXC9wTjw9MItKEoTBDVTAkQ3wVCRFncItPgI5mfYsLjXko8r AShQ== 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=xBAzcls7RPrNJufSlGj6KKxCuWftsgmW7IXTQnhCN8M=; b=UzE9WuhMZeaqirLqJKCjqMwgTMYRADZPTGaVKDAmoUjcAi+I7uIXyoCC57+FdaEF97 /gSzXzzPo5bfX12jv4RJdZBT5IgYDWMqUUWiqTqIlPglEXqxOlq75fLqfBY80Iwtt5Nl wsK/U8B6PaebaKPVT6tySe89FR9Wzql3uyZOZXuDbWWPsizsHYqZRV9YvYoC0GVFMHah fKGxTuol5E+ajYqiwGTihyIRfXLn9Nuoy05b9re/ydgZYFy90zZiX6c//mDcroyN3yf5 +odh7RfZtg0I3rLGR/T1NoHWbb6+eJhCNBQyaGrn95MEwdnEOZROk96vquTX3l1y5PCt HWOA== 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 o12-20020a170906974c00b00715849159c7si3022851ejy.56.2022.06.12.10.19.23; Sun, 12 Jun 2022 10:19:23 -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 70A5368B549; Sun, 12 Jun 2022 20:19:04 +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 D4C1868B4B8 for ; Sun, 12 Jun 2022 20:18:56 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 7E4E8E7254; Sun, 12 Jun 2022 19:18:52 +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 AsppboHGuMoe; Sun, 12 Jun 2022 19:18:51 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id EF177E72B5; Sun, 12 Jun 2022 19:18:50 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sun, 12 Jun 2022 19:18:40 +0200 Message-Id: <20220612171845.8122-2-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 2/7] avcodec/v210dec: factorize row decoding 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: ODqHhDkjfJN0 Signed-off-by: Marton Balint --- libavcodec/v210dec.c | 108 +++++++++++++++++++++---------------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/libavcodec/v210dec.c b/libavcodec/v210dec.c index 48ebe57100..c89440658f 100644 --- a/libavcodec/v210dec.c +++ b/libavcodec/v210dec.c @@ -50,10 +50,61 @@ static av_cold int decode_init(AVCodecContext *avctx) return 0; } +static void decode_row(const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t *v, const int width, + void (*unpack_frame)(const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t *v, int width)) +{ + uint32_t val; + int w = (width / 12) * 12; + + unpack_frame(src, y, u, v, w); + + y += w; + u += w >> 1; + v += w >> 1; + src += (w << 1) / 3; + + if (w < width - 5) { + READ_PIXELS(u, y, v); + READ_PIXELS(y, u, y); + READ_PIXELS(v, y, u); + READ_PIXELS(y, v, y); + w += 6; + } + + if (w++ < width) { + READ_PIXELS(u, y, v); + + if (w++ < width) { + val = av_le2ne32(*src++); + *y++ = val & 0x3FF; + + if (w++ < width) { + *u++ = (val >> 10) & 0x3FF; + *y++ = (val >> 20) & 0x3FF; + val = av_le2ne32(*src++); + *v++ = val & 0x3FF; + + if (w++ < width) { + *y++ = (val >> 10) & 0x3FF; + + if (w++ < width) { + *u++ = (val >> 20) & 0x3FF; + val = av_le2ne32(*src++); + *y++ = val & 0x3FF; + *v++ = (val >> 10) & 0x3FF; + + if (w++ < width) + *y++ = (val >> 20) & 0x3FF; + } + } + } + } + } +} + static int v210_decode_slice(AVCodecContext *avctx, void *arg, int jobnr, int threadnr) { V210DecContext *s = avctx->priv_data; - int h, w; ThreadData *td = arg; AVFrame *frame = td->frame; int stride = td->stride; @@ -64,59 +115,8 @@ static int v210_decode_slice(AVCodecContext *avctx, void *arg, int jobnr, int th int16_t *pu = (uint16_t*)frame->data[1] + slice_start * frame->linesize[1] / 2; int16_t *pv = (uint16_t*)frame->data[2] + slice_start * frame->linesize[2] / 2; - for (h = slice_start; h < slice_end; h++) { - const uint32_t *src = (const uint32_t*)psrc; - uint32_t val; - uint16_t *y = py; - uint16_t *u = pu; - uint16_t *v = pv; - - w = (avctx->width / 12) * 12; - s->unpack_frame(src, y, u, v, w); - - y += w; - u += w >> 1; - v += w >> 1; - src += (w << 1) / 3; - - if (w < avctx->width - 5) { - READ_PIXELS(u, y, v); - READ_PIXELS(y, u, y); - READ_PIXELS(v, y, u); - READ_PIXELS(y, v, y); - w += 6; - } - - if (w++ < avctx->width) { - READ_PIXELS(u, y, v); - - if (w++ < avctx->width) { - val = av_le2ne32(*src++); - *y++ = val & 0x3FF; - - if (w++ < avctx->width) { - *u++ = (val >> 10) & 0x3FF; - *y++ = (val >> 20) & 0x3FF; - val = av_le2ne32(*src++); - *v++ = val & 0x3FF; - - if (w++ < avctx->width) { - *y++ = (val >> 10) & 0x3FF; - - if (w++ < avctx->width) { - *u++ = (val >> 20) & 0x3FF; - val = av_le2ne32(*src++); - *y++ = val & 0x3FF; - *v++ = (val >> 10) & 0x3FF; - - if (w++ < avctx->width) - *y++ = (val >> 20) & 0x3FF; - } - } - } - } - } - + for (int h = slice_start; h < slice_end; h++) { + decode_row((const uint32_t *)psrc, py, pu, pv, avctx->width, s->unpack_frame); psrc += stride; py += frame->linesize[0] / 2; pu += frame->linesize[1] / 2; From patchwork Sun Jun 12 17:18:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 36177 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp97046pzb; Sun, 12 Jun 2022 10:19:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzoCDX7N2VvPdxDirDmxZAWa2xo4+59ORFhWhTk61GIjwC6gno4AW0M5bo6Gk3BcUUKUezN X-Received: by 2002:a17:907:2c43:b0:715:85cb:21a with SMTP id hf3-20020a1709072c4300b0071585cb021amr3114794ejc.541.1655054355027; Sun, 12 Jun 2022 10:19:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655054355; cv=none; d=google.com; s=arc-20160816; b=yQxn4WruTIbYh2/k+qsR3JYt5rqzQOpIH1yRbDps+8pTKV6JuH4pwUpbxIddwcl6SY 8Kbquv2PRDXdsnSnKZLz+MKnObDUpygedH2KBOKPZVbNfei08GVFCn7uS1TurZzTih5X zxc5Ubmq/XsvqOf+k+CvSg9RzEpEXX2Va2+F/DUGW2RyZZI4wUShezgFAwyVxk/j9JIh /BD0pN8xWaKqNcSuPpB7Wl1KPCj3gw0bsdKQ0wKgpqVFmOBOhs8ZTikFEK4sfkv5DYMH IBDjtURB8yIR+JBNBgP8qsPHhbRK/X4gZHsWnNmQk4d5+9TaG7a3V+xzgTouyOtKIlPF TK1Q== 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=kumFyHbMKhWtt+uIecd25r9eTdcxbimB0zOW6MODMP8=; b=WnJwRpwmy7DV7EFgqvqwTT9ZnwtvSX85OzxLwKpMNqdDeaSa6luf1NgEhib0vXJkwn t1YupcU0JNoqm1Ab3OSwgUioEiZmhSidCOYCcNMaDNsTkBte+55XTGPtDKwTDOGRKKGo 8helBZdWJyp4+S7voa55xb9k5ZmBxL4b1dLus0PFue5H1tRoPMgtpkYwZLF3YwI0sVyJ zZnLgchUk6YYZT2W3MNxmkOVpk4bIAlJ+FKMmYU37NRK80ZkxjWEtZMm62k1597ygFcn yUxCpZ1eLw2A4vOS55guOjmkb0KISn+sWS6mhzQ8qcOtoYt5s1ov0yUkzYVQnOZPCaMy fraQ== 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 w12-20020a056402128c00b0042dd6491cd2si4872263edv.436.2022.06.12.10.19.14; Sun, 12 Jun 2022 10:19:15 -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 7138468B515; Sun, 12 Jun 2022 20:19:03 +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 D3CAA68B4B3 for ; Sun, 12 Jun 2022 20:18:56 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id B63E1E72B5; Sun, 12 Jun 2022 19:18:55 +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 JgJuH4-U8O2C; Sun, 12 Jun 2022 19:18:54 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 65DD7E6B25; Sun, 12 Jun 2022 19:18:54 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sun, 12 Jun 2022 19:18:41 +0200 Message-Id: <20220612171845.8122-3-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 3/7] avcodec/v210dec: disallow negative custom stride 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: MvKeD1ZtBLHR Also make sure a big custom stride does not overflow size check. Avoids segfaults. Signed-off-by: Marton Balint --- libavcodec/v210dec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/v210dec.c b/libavcodec/v210dec.c index c89440658f..e97f43a8e6 100644 --- a/libavcodec/v210dec.c +++ b/libavcodec/v210dec.c @@ -141,7 +141,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *pic, stride = aligned_width * 8 / 3; } - if (avpkt->size < stride * avctx->height) { + if (avpkt->size < (int64_t)stride * avctx->height) { if ((((avctx->width + 23) / 24) * 24 * 8) / 3 * avctx->height == avpkt->size) { stride = avpkt->size / avctx->height; if (!s->stride_warning_shown) @@ -190,7 +190,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}, INT_MIN, INT_MAX, V210DEC_FLAGS}, + {.i64 = 0}, 0, INT_MAX, V210DEC_FLAGS}, {NULL} }; From patchwork Sun Jun 12 17:18:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 36179 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp97130pzb; Sun, 12 Jun 2022 10:19:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0wI01EP2Rn8aRlp4sYcQ5O5LwBouYH0w9swgnN2pw4OAaLsk3iIpT0L/+Y50clZSRXgC3 X-Received: by 2002:a17:906:a858:b0:70e:a4d8:1c45 with SMTP id dx24-20020a170906a85800b0070ea4d81c45mr41636972ejb.213.1655054372440; Sun, 12 Jun 2022 10:19:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655054372; cv=none; d=google.com; s=arc-20160816; b=P5K3vZux8D5LGyv9/ktuO800+l0FspscGmPtPa1+8CvBu3nqYWv8ZAB4lIY5Qra2rY di1A/joR2tcANTB3kw7ZQAkmkTlVOXnaq2idHIGnGor3UzDwTIVM92qDb4aRkavz4osY eB3YyB5xu+EXwM1Fj7a5q9zllp3Tud3ppP/MzxH2rmosW1k6OIbBauaKglWXXrqI/CTI GIJGjlmlt8uLJzRK87Xnw6Pk3/CbpGXawwLnH6SoH92sD8v6/uewlaSUCDmGpsP++D0R xJy8fM5iSCSUYUD7fblhuFiUckXhCHRk7zJuQltCe/zqGoSxCo/G33uF8qyVodUprWXl AdKg== 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=B7zzx3jBrpDUEbFuMJyl75M2JMmkYsEko9FwCOPkJ0g=; b=MH/VbwOQ+bk5RktgF8qI7XpylZ3aZxokP/H/bmlM/VCy/NolahPqXMLpNDoiL5+X3a EgigncD5oJq8OjsbSW1H1wiAA5zAvW5mC81n3VH295YXDnFcGJMKomNqSQY9gL1Hk1Zi QzCC33YHDlBp29X97Cf+GktxVG/SJuGF3go5Zi/XeWF2Ksi5ss5uJSFz2nmw8hrWX3f6 ArsaVuT4kiC1KFqzVFjpMn5F2ocG0HX405STSusT9+7mUnbGnbXflubfrowhN9aPvTqq Xg6DyTq+ajgrG0Fw9kWLbPs7nZtPDOaoiBV832QxY9GEVG6qr68vUUxnjzmHgWW6yFS5 pAlg== 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 mm6-20020a170906cc4600b006ff453083c1si4310671ejb.189.2022.06.12.10.19.32; Sun, 12 Jun 2022 10:19:32 -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 7798968B56D; Sun, 12 Jun 2022 20:19:08 +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 2683368B3B5 for ; Sun, 12 Jun 2022 20:19:01 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 8F290E6DC2; Sun, 12 Jun 2022 19:19:01 +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 1CKQDfkvz__H; Sun, 12 Jun 2022 19:19:00 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id D955BE6B25; Sun, 12 Jun 2022 19:18:59 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sun, 12 Jun 2022 19:18:42 +0200 Message-Id: <20220612171845.8122-4-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 4/7] avcodec/v210dec: do not use accelerated code for the last pixels of a row 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: 4FoQKMH9hfBl ASM code tends to overwrite the buffers by 2-4 bytes and it can cause issues with slice threads. Signed-off-by: Marton Balint --- libavcodec/v210dec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/v210dec.c b/libavcodec/v210dec.c index e97f43a8e6..4268b5b748 100644 --- a/libavcodec/v210dec.c +++ b/libavcodec/v210dec.c @@ -54,7 +54,7 @@ static void decode_row(const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t * void (*unpack_frame)(const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t *v, int width)) { uint32_t val; - int w = (width / 12) * 12; + int w = (FFMAX(0, width - 12) / 12) * 12; unpack_frame(src, y, u, v, w); @@ -63,7 +63,7 @@ static void decode_row(const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t * v += w >> 1; src += (w << 1) / 3; - if (w < width - 5) { + while (w < width - 5) { READ_PIXELS(u, y, v); READ_PIXELS(y, u, y); READ_PIXELS(v, y, u); From patchwork Sun Jun 12 17:18:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 36180 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp97181pzb; Sun, 12 Jun 2022 10:19:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNGkaBfLYsIfAglM9EnvWTCubFZcvQXK/yDwUvQc4BWFO76nCL3d8wm4cFuHnbBv9ApWIu X-Received: by 2002:a17:907:a422:b0:705:e944:fd3e with SMTP id sg34-20020a170907a42200b00705e944fd3emr48489159ejc.309.1655054380440; Sun, 12 Jun 2022 10:19:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655054380; cv=none; d=google.com; s=arc-20160816; b=rd63EZMrR06qaFrjrmql0ZNqJZL2Shmq/4qjJdA5+okQqJ0tqxxPW2cI/Xe8Bn5BU6 VGWjPqRB3eHQ4RAlKUvbntdbevHAzUYmhl6EYvqOv9XqmbrX7h10upkZ4mAk8B4Gesai Ki6rzZRgRROpcIKTYfFuO8CeILdhDkLKt4O39f6biQz0LIj1vQMe77t8oL/yFkeeojVu IbU9vYGD7V/AO0TC9jDH6lLk4SE4fx46txXeqgsO01mWfl9ExYVIQt6zYzLzzgu2GRAd 8k1PiPTUk6US2ohqvbG0t2PCmXAmKX3k6jmNTc92Ea6bSMUlU73l4DJzV/KumsSfhvOy 4qsw== 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=3Vo7g9b3pwZxUmpdGkhGhvRiFI2+oCHy1O3rYzuiUAU=; b=d8KNiD4MAAvjJ4M2trITyAXhXY1wOG/hAtw8VM8V/qKdtqoywrq/tw7oVGs1l4s3iD 5iATrQBbx8uo1h5xZezxGg8SrqGSv4Y0m4YmMgJ585v7pk5B4zKdd3aRBnttbginKdMB ph4nyiK2SKPzOghnBHEYzN8zDXfV3oz64bvymX5GC1kbEAabpX0d/Y7GNn2aRALK0hF9 KvO5DchCxh1EZudySGQMN+dAh/DvuaU2n+00YyVUPbYzJzGpCotiMHejb8eSVghXwAyd thNLAoe89BnobgJI3XFKrKTOfDoD3zdrQkoJYx9MtjI4VmEjV2VZPj7GH99zGrwwNAMu t3XQ== 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 cs16-20020a170906dc9000b006f3d2558d4bsi6212622ejc.496.2022.06.12.10.19.40; Sun, 12 Jun 2022 10:19:40 -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 86C6868B587; Sun, 12 Jun 2022 20:19:12 +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 5440568B4DF for ; Sun, 12 Jun 2022 20:19:05 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id C37A9E70F7; Sun, 12 Jun 2022 19:19:05 +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 ndqPYwgSKvnA; Sun, 12 Jun 2022 19:19:04 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 616C3E6EA7; Sun, 12 Jun 2022 19:19:04 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sun, 12 Jun 2022 19:18:43 +0200 Message-Id: <20220612171845.8122-5-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 5/7] avcodec/v210dec: add support for invalid paddings up to 16 bytes 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: xbckQqNFF+77 Fixes ticket #1528. Signed-off-by: Marton Balint --- libavcodec/v210dec.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/libavcodec/v210dec.c b/libavcodec/v210dec.c index 4268b5b748..ba48bb6fe4 100644 --- a/libavcodec/v210dec.c +++ b/libavcodec/v210dec.c @@ -126,6 +126,11 @@ static int v210_decode_slice(AVCodecContext *avctx, void *arg, int jobnr, int th return 0; } +static int v210_stride(int width, int align) { + int aligned_width = ((width + align - 1) / align) * align; + return aligned_width * 8 / 3; +} + static int decode_frame(AVCodecContext *avctx, AVFrame *pic, int *got_frame, AVPacket *avpkt) { @@ -137,20 +142,25 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *pic, if (s->custom_stride ) stride = s->custom_stride; else { - int aligned_width = ((avctx->width + 47) / 48) * 48; - stride = aligned_width * 8 / 3; + stride = v210_stride(avctx->width, 48); + if (avpkt->size < stride * avctx->height) { + int align; + for (align = 24; align >= 6; align >>= 1) { + int small_stride = v210_stride(avctx->width, align); + if (avpkt->size == small_stride * avctx->height) { + stride = small_stride; + if (!s->stride_warning_shown) + av_log(avctx, AV_LOG_WARNING, "Broken v210 with too small padding (%d byte) detected\n", align * 8 / 3); + s->stride_warning_shown = 1; + break; + } + } + } } if (avpkt->size < (int64_t)stride * avctx->height) { - if ((((avctx->width + 23) / 24) * 24 * 8) / 3 * avctx->height == avpkt->size) { - stride = avpkt->size / avctx->height; - if (!s->stride_warning_shown) - av_log(avctx, AV_LOG_WARNING, "Broken v210 with too small padding (64 byte) detected\n"); - s->stride_warning_shown = 1; - } else { - av_log(avctx, AV_LOG_ERROR, "packet too small\n"); - return AVERROR_INVALIDDATA; - } + 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') 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} }; From patchwork Sun Jun 12 17:18:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 36181 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp97224pzb; Sun, 12 Jun 2022 10:19:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyI+7L6fElxOnm8N7OYFyo+O56WSGk6D1RlSgN8wZ1FMM0bjK72nqUXamnJrgGIcf4hIkBC X-Received: by 2002:a17:906:7a4a:b0:712:c6d:46df with SMTP id i10-20020a1709067a4a00b007120c6d46dfmr15613528ejo.314.1655054388875; Sun, 12 Jun 2022 10:19:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655054388; cv=none; d=google.com; s=arc-20160816; b=uAdWXHKmg4ORSKK+sxCuptI2qHV29HDdRbO6GJdthgAMXmWWgC/2k7OCQXbwmZvu3C bgZb91VXIgdJ0t2muACRVSPlvHC8FEs0n2swXC1p9i2Bq72moCClgruGoMM/oYmoKrUj OyHULUodWcOtdVvulL0pry1e0SKN5fsVxD2s+BOmOKBcmQBWuPqtPsTivoUMl3SxfqTq SpxTTgzam1cU7V691wVlvoZIeI0w+SL/oVi4MxIxhI7ko1K8Dml4X6kAgVT1qdhPlETF kueHv6jTNeLQ+PDPhaXwM13YG4M6cusgh1AGI2nM2vjb274bTxU5rXVMxNQjfvTvRxL8 r4rQ== 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=fVLZIVZ3bHxVRHrrTl9EiVxPYrHMTUgtQQa617nzlFU=; b=nkF/FpN7xiTPK/lGCFIXA4lobcVH2cCHsqF2liDX6tR4kv7VPBz8hlI+OZ1hE/8n/R wt/i8qmOYKnQwlU40YN7Zr5xAZ8W6D5GYDvErci8tCmpPSoFcV3Q9XT5yuLj8M6ljxY3 Xg84jQpetu4SaVUtpIpFCntAyXjmvShsmr3VqgvxQPoQy4VkLKGaJjJ8t+Khn7kOYyPT Gn+cjQtG8Bfr41+kh2ZrrvL7cVK1Nl1XjdbA5ltr1q16MA76/qMm5MWb3pz5+ECZQwxF Ijbw79dcD72wUzOERuT34Jo0D3qm0i9qz4ghjECjLp6WwBxpVPw3PqFjAXU8DZrWwu1s 8b5A== 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 c20-20020a056402121400b0042ee0cc482bsi4876494edw.170.2022.06.12.10.19.48; Sun, 12 Jun 2022 10:19:48 -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 99CEC68B58E; Sun, 12 Jun 2022 20:19:15 +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 D66FE68B583 for ; Sun, 12 Jun 2022 20:19:13 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 3CF52E70F7; Sun, 12 Jun 2022 19:19:14 +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 IF4456ki8bfw; Sun, 12 Jun 2022 19:19:13 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 83587E6DC2; Sun, 12 Jun 2022 19:19:12 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sun, 12 Jun 2022 19:18:45 +0200 Message-Id: <20220612171845.8122-7-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 7/7] doc/decoders: add docs for v210 decoder 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: /x+3CA/iWh3U Signed-off-by: Marton Balint --- doc/decoders.texi | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/doc/decoders.texi b/doc/decoders.texi index de2429abba..e2fcbf5dc9 100644 --- a/doc/decoders.texi +++ b/doc/decoders.texi @@ -168,6 +168,21 @@ A :-separate list of hexadecimal plugin UIDs to load in an internal session @end table +@section v210 + +Uncompressed 4:2:2 10-bit decoder. + +@subsection Options + +@table @option + +@item custom_stride +Set the line size of the v210 data in bytes. The default value is 0 +(autodetect). You can use the special -1 value for a strideless v210 as seen in +BOXX files. + +@end table + @c man end VIDEO DECODERS @chapter Audio Decoders