From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 307924A9A2 for ; Mon, 6 May 2024 21:52:56 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1A62968D6D5; Tue, 7 May 2024 00:52:51 +0300 (EEST) Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03olkn2102.outbound.protection.outlook.com [40.92.58.102]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4762768D6F0 for ; Tue, 7 May 2024 00:52:44 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MXdpUZtqnmHr2HqR94WHliakJw8PE92Uid3OJcRH6oh9UGrfDFB2wrowaxSpqJ7o8rcSEfSB9tt+iwk6EYLGrlU6QVbB7jiCDS6aQCGAc+KaAXKoIjGoPDT4DGKLTbEQHmYL5yaRKvGO/o+/2IQEQ6izZcfN8VJu1cxfO2UaGeeB7R7fVnQbbXABx7SjZkD6eR68Q5IAMf9rqhrljDRdMsJyuztQOoslZScOu2vOVrOW2DgMkI04SD8r7dRYRpzze+KvvHki5hUvdeOu/RsZ3YLf+swLN/RYqc0720zCJchvmoBGQugZFbBGBPCDtPWoRwqknpbLf55AhzSk/bj6qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=eKk58Zx00yQ/cP9ILIwbQwuPfurSlmNTMQBUokYD0cc=; b=VzyeUsMPeSfl/9YBqn5azJYZB+HVh6ihfbqugjyXaSXrMF0tV4RuANiQMs21t2VruYorPfptup4aiuTSv9iiXsGi9Z3PS2ANH+m2TG9dtaahs5pWPV1ntWyRAzXZckEZCZvekxZOb3lL5H5vL0cYcVJtOb89Y3gX/CTxq5gji6hD6B/tG0RTaycg3MRdIY9z7/xuAUhJ2YKpwQqn5dpJ8SI66ZvPKl4agi4t4SisV+0GnMXkEhdRXMB7p2O/NofxmHy5k7lL6wBlre2moq7/PsTTGE5hUiLdNb5k7qohJX2rBxpYtXLCznYtZwYeHdNFtJHQO7DpkTzMdTOWeqenfg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eKk58Zx00yQ/cP9ILIwbQwuPfurSlmNTMQBUokYD0cc=; b=fC6jlfrTPpGsQAOb26gtD46UeUXOUOraDWpoxZNkM7vNQVPVFZ2c7laAuJrOIWIbDldkaeJ72hnRMvBpGw//6eGiHj+fBYRSdNdhsP/gQ7BxJaT5plkFjxvQYUafdiFh9DGZmDUFuqf1rIy9KY3yW7fFd1B7o5LoHQ2V4uylOrDzo9pXaV7ErjkLmsb491GLZyO/7PDOuxWMLBYZ1oeasb112+wTRv+qRyhIfNpl8q7+80OdJwNp6esq+BP7OW/mBipqxGT3PVn2hkV/0U1JFvDKN3xfVLn5p09VM0T3Rl4aaraINF9kDWtIAkkd7iZbuy2SiBIjhP5iw1RjrAUr8g== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by PRAP250MB0592.EURP250.PROD.OUTLOOK.COM (2603:10a6:102:29f::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.41; Mon, 6 May 2024 21:52:42 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::d6a1:e3af:a5f1:b614]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::d6a1:e3af:a5f1:b614%7]) with mapi id 15.20.7544.041; Mon, 6 May 2024 21:52:42 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 6 May 2024 23:52:25 +0200 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: X-TMN: [Hv5i1DHkXzXowV5v9HpehpoovykvqkcysrpxnuWsxkc=] X-ClientProxiedBy: ZR0P278CA0042.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:1d::11) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20240506215227.1260832-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|PRAP250MB0592:EE_ X-MS-Office365-Filtering-Correlation-Id: 8554c9cf-9a90-4489-86a4-08dc6e16daee X-Microsoft-Antispam: BCL:0; ARA:14566002|461199019|3412199016|440099019|1710799017; X-Microsoft-Antispam-Message-Info: T2BbkVRdEZTb2DeB0rts5XvJA4syanR+mvb4hUtfYKER7k1W6viFtQ4l7ItTvDR3sEJqleTpahCqOIu+pK7G4N9zSmraz7MEdDsuwVJHvQRWRk28VQjDx3lbvjNOQLp7bk7Pr0B/vsl6qplnAkTPCdw8W3aOl0pOG0hcWP2BiCjBH5heSNMt0to0G3DxCfP5HR55afVL8WQtKtKgFEZxlfZxWMM4ljbzp3zbQmfQsCgN7uQ+gWGB7XRRGf0Be4aoYPeB04wxpnlyolNWxWgz8G8S6lnRve2yg9Tbm6zG6XWS6pUJ2VwD9lLGuo60NvPdjxI1Tv96G06m4N117pBf5RPHxPj20UPUXXEdCd3apE7mUEmGoWco5L26i1TzYlnuUUeckv/XoDiW16euZlua1DaKOvfp2ttTRtPsqXlJQ0QQcT+rL+PaFWm2YQzuJzTsMJnYVacSYpNs38Ukiy3RWGOS732Byuy71QvPZdYbIj/IOQYXg5TcNGR0qRHc31WcYFDbGSJ6FgllRamHZU/TJrYhcj8VZ9kXfTV+VP4zpAQKWq20q1+qDVR/PxMDALJXbLu/gZ5nVtD+wRC21FubmbD3ZMLyv7V8rexdW4TscI3X07DirlnUb8ZIqcVfl7tx X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?HiaN8/2MsF8chcMiNu0jurhGOW/cxEPKDK0ijefz1B7Y2g5ejqtwmU+ETuRK?= =?us-ascii?Q?FWzJNymw31ifaBur9pW8praakFswv7KO66dvbk6JcN72pdN3bcPjFh4CB8Lu?= =?us-ascii?Q?7m8IOpQGHIVobJLcPirPgfKE74AVV/InD/a3ktFfiLYnLo6ASfv3EC0P7Yzv?= =?us-ascii?Q?ix+qgMtArBO18Wgb6wqJR4RkXxJ8j3LneP756l5HNCmoWnGX7iylv4oMTXCQ?= =?us-ascii?Q?pjbXTaVqVcsE3oorUSBgacQNJJydpkV0SLxwefnuDawpBSFy7h7poJtDoMNM?= =?us-ascii?Q?75tXWv026CbauIYsggN5C1yz21NSGx8+SMyRDyj8zRbEUXgD17KPgzAPEmLV?= =?us-ascii?Q?nFsb4dNv6zO5IpiTaSttRinAsUm+hvjnDaHh9/avO5P2Jdd9ahL2Y2DOMbBE?= =?us-ascii?Q?zV1CSC1jng/qwgqULke7T1G1PVRqKroIqkrspFTj6TVAxfeGJzts6qYS/gv/?= =?us-ascii?Q?Fnz9irV8zu0MWszMM5Naxn2q0NrCeoaUv5rW5St1aLXcN0W4DpW6tvd7ndzG?= =?us-ascii?Q?TjgQSmwBk+GUK/RJ7s2D2Xup+rxk1ry1QWkumLS5SUJwlyYe1JeyR7/4MFAu?= =?us-ascii?Q?VtfD3gLa898S7J6iBRgvQhi8ccwl7Br76bwxlxPaWdPwtnT1yYK3fvJLZJuR?= =?us-ascii?Q?ZuUEDFVXEira7CoF+XSZBqzz00vV0dZ0P54TbNdIfOk5zDdv4JAtxuiyAN3q?= =?us-ascii?Q?Z5swf2+FOXx+41gr2hFRSZol9UseGfhTDMepZNDqL+yVP7cxVyW5pP2bjMFv?= =?us-ascii?Q?3ViMihUoHZtdITSfdmmGFgacIGQRIxODUp8vkeYkQpij4c30QxH/saYNe/RA?= =?us-ascii?Q?VOzqSovpHDNLmBBu5xgW54scd81jkdzBoU7/oOEGt8jfl4KFF8lXdfCGhhv3?= =?us-ascii?Q?4cy0EWV/9vq0+vmQgTks0jJR4PVzEzmjRvxDg1sDYUY707oPrYCqO9icPtWi?= =?us-ascii?Q?+QUxUqjuCh0C/D1jb6NLVrsR8MtWZ4dUQ7NiH6PlLk1IjYLholgKKIG/5NdG?= =?us-ascii?Q?w+Mw2yWqIQzC3GgbOwI826MKFHJ8p0IIsoTkKgTKYGmEzyz2hwmj6/bGSPAr?= =?us-ascii?Q?LCF0YBfBPEXBvIPBxWTJ3bSxuCpsXCYeS2u9jrt2qe4EB6vyolnSKI7ENrwM?= =?us-ascii?Q?t/2mWpBSsHQqrkc5EKVEcRHtzIxNQQNIhDXFquI4mJomR2jbWvCRRANdkJOB?= =?us-ascii?Q?Td99nmBH6MskfNCe8/xCd3KJeicozyGpObM+gzax7hkoQKDUPRqDFS3gwI6V?= =?us-ascii?Q?aBtizuOL/BTgje8Tf0LbHQt2lsgS421OUKYVJC9rbQ=3D=3D?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8554c9cf-9a90-4489-86a4-08dc6e16daee X-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 May 2024 21:52:42.4505 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PRAP250MB0592 Subject: [FFmpeg-devel] [PATCH 26/28] avcodec/mpegvideoencdsp: Factor draw_edges out in its own context 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: Andreas Rheinhardt Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: This allows to remove a dependency of the dirac decoder (!) on mpegvideoenc. Signed-off-by: Andreas Rheinhardt --- configure | 7 +- libavcodec/Makefile | 1 + libavcodec/diracdec.c | 14 +-- libavcodec/drawedgesdsp.c | 61 ++++++++++ libavcodec/drawedgesdsp.h | 35 ++++++ libavcodec/mpegvideo.h | 2 + libavcodec/mpegvideo_enc.c | 9 +- libavcodec/mpegvideoencdsp.c | 32 ------ libavcodec/mpegvideoencdsp.h | 6 - libavcodec/snowenc.c | 13 ++- libavcodec/x86/Makefile | 1 + libavcodec/x86/drawedgesdsp.c | 157 ++++++++++++++++++++++++++ libavcodec/x86/mpegvideo.c | 2 +- libavcodec/x86/mpegvideoencdsp_init.c | 118 ------------------- 14 files changed, 281 insertions(+), 177 deletions(-) create mode 100644 libavcodec/drawedgesdsp.c create mode 100644 libavcodec/drawedgesdsp.h create mode 100644 libavcodec/x86/drawedgesdsp.c diff --git a/configure b/configure index bea4547e20..edb1ddca33 100755 --- a/configure +++ b/configure @@ -2552,6 +2552,7 @@ CONFIG_EXTRA=" dnn dovi_rpudec dovi_rpuenc + drawedgesdsp dvprofile evcparse exif @@ -2868,7 +2869,7 @@ mpeg_er_select="error_resilience" mpegaudio_select="mpegaudiodsp mpegaudioheader" mpegvideo_select="blockdsp hpeldsp idctdsp videodsp" mpegvideodec_select="h264chroma mpegvideo mpeg_er" -mpegvideoenc_select="aandcttables fdctdsp me_cmp mpegvideo pixblockdsp" +mpegvideoenc_select="aandcttables drawedgesdsp fdctdsp me_cmp mpegvideo pixblockdsp" msmpeg4dec_select="h263_decoder" msmpeg4enc_select="h263_encoder" vc1dsp_select="h264chroma qpeldsp startcode" @@ -2918,7 +2919,7 @@ cook_decoder_select="audiodsp sinewin" cri_decoder_select="mjpeg_decoder" cscd_decoder_suggest="zlib" dds_decoder_select="texturedsp" -dirac_decoder_select="dirac_parse dwt golomb mpegvideoenc qpeldsp videodsp" +dirac_decoder_select="dirac_parse drawedgesdsp dwt golomb qpeldsp videodsp" dnxhd_decoder_select="blockdsp idctdsp" dnxhd_encoder_select="blockdsp fdctdsp idctdsp mpegvideoenc pixblockdsp videodsp" dvvideo_decoder_select="dvprofile idctdsp" @@ -3060,7 +3061,7 @@ shorten_decoder_select="bswapdsp" sipr_decoder_select="lsp" smvjpeg_decoder_select="mjpeg_decoder" snow_decoder_select="dwt h264qpel rangecoder videodsp" -snow_encoder_select="dwt h264qpel hpeldsp me_cmp mpegvideoenc rangecoder videodsp" +snow_encoder_select="drawedgesdsp dwt h264qpel hpeldsp me_cmp mpegvideoenc rangecoder videodsp" sonic_decoder_select="golomb rangecoder" sonic_encoder_select="golomb rangecoder" sonic_ls_encoder_select="golomb rangecoder" diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 3e8a44e89c..dff6193bc2 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -89,6 +89,7 @@ OBJS-$(CONFIG_CBS_VP9) += cbs_vp9.o OBJS-$(CONFIG_DEFLATE_WRAPPER) += zlib_wrapper.o OBJS-$(CONFIG_DOVI_RPUDEC) += dovi_rpu.o dovi_rpudec.o OBJS-$(CONFIG_DOVI_RPUENC) += dovi_rpu.o dovi_rpuenc.o +OBJS-$(CONFIG_DRAWEDGESDSP) += drawedgesdsp.o OBJS-$(CONFIG_ERROR_RESILIENCE) += error_resilience.o OBJS-$(CONFIG_EVCPARSE) += evc_parse.o evc_ps.o OBJS-$(CONFIG_EXIF) += exif.o tiff_common.o diff --git a/libavcodec/diracdec.c b/libavcodec/diracdec.c index f1fde0b339..f0df74e131 100644 --- a/libavcodec/diracdec.c +++ b/libavcodec/diracdec.c @@ -34,11 +34,11 @@ #include "get_bits.h" #include "codec_internal.h" #include "decode.h" +#include "drawedgesdsp.h" #include "golomb.h" #include "dirac_arith.h" #include "dirac_vlc.h" #include "mpegpicture.h" -#include "mpegvideoencdsp.h" #include "dirac_dwt.h" #include "dirac.h" #include "diractab.h" @@ -135,7 +135,7 @@ typedef struct DiracSlice { typedef struct DiracContext { AVCodecContext *avctx; - MpegvideoEncDSPContext mpvencdsp; + DrawEdgesDSPContext drawedges; VideoDSPContext vdsp; DiracDSPContext diracdsp; DiracVersionInfo version; @@ -397,7 +397,7 @@ static av_cold int dirac_decode_init(AVCodecContext *avctx) s->thread_buf_size = -1; ff_diracdsp_init(&s->diracdsp); - ff_mpegvideoencdsp_init(&s->mpvencdsp, avctx); + ff_drawedgesdsp_init(&s->drawedges); ff_videodsp_init(&s->vdsp, 8); for (i = 0; i < MAX_FRAMES; i++) { @@ -1836,7 +1836,7 @@ static int interpolate_refplane(DiracContext *s, DiracFrame *ref, int plane, int int i, edge = EDGE_WIDTH/2; ref->hpel[plane][0] = ref->avframe->data[plane]; - s->mpvencdsp.draw_edges(ref->hpel[plane][0], ref->avframe->linesize[plane], width, height, edge, edge, EDGE_TOP | EDGE_BOTTOM); /* EDGE_TOP | EDGE_BOTTOM values just copied to make it build, this needs to be ensured */ + s->drawedges.draw_edges(ref->hpel[plane][0], ref->avframe->linesize[plane], width, height, edge, edge, EDGE_TOP | EDGE_BOTTOM); /* EDGE_TOP | EDGE_BOTTOM values just copied to make it build, this needs to be ensured */ /* no need for hpel if we only have fpel vectors */ if (!s->mv_precision) @@ -1856,9 +1856,9 @@ static int interpolate_refplane(DiracContext *s, DiracFrame *ref, int plane, int s->diracdsp.dirac_hpel_filter(ref->hpel[plane][1], ref->hpel[plane][2], ref->hpel[plane][3], ref->hpel[plane][0], ref->avframe->linesize[plane], width, height); - s->mpvencdsp.draw_edges(ref->hpel[plane][1], ref->avframe->linesize[plane], width, height, edge, edge, EDGE_TOP | EDGE_BOTTOM); - s->mpvencdsp.draw_edges(ref->hpel[plane][2], ref->avframe->linesize[plane], width, height, edge, edge, EDGE_TOP | EDGE_BOTTOM); - s->mpvencdsp.draw_edges(ref->hpel[plane][3], ref->avframe->linesize[plane], width, height, edge, edge, EDGE_TOP | EDGE_BOTTOM); + s->drawedges.draw_edges(ref->hpel[plane][1], ref->avframe->linesize[plane], width, height, edge, edge, EDGE_TOP | EDGE_BOTTOM); + s->drawedges.draw_edges(ref->hpel[plane][2], ref->avframe->linesize[plane], width, height, edge, edge, EDGE_TOP | EDGE_BOTTOM); + s->drawedges.draw_edges(ref->hpel[plane][3], ref->avframe->linesize[plane], width, height, edge, edge, EDGE_TOP | EDGE_BOTTOM); } ref->interpolated[plane] = 1; diff --git a/libavcodec/drawedgesdsp.c b/libavcodec/drawedgesdsp.c new file mode 100644 index 0000000000..3306bb9f6d --- /dev/null +++ b/libavcodec/drawedgesdsp.c @@ -0,0 +1,61 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + +#include "config.h" + +#include "drawedgesdsp.h" +#include "libavutil/attributes.h" + +/* draw the edges of width 'w' of an image of size width, height */ +// FIXME: Check that this is OK for MPEG-4 interlaced. +static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, + int w, int h, int sides) +{ + uint8_t *ptr = buf, *last_line; + + /* left and right */ + for (int i = 0; i < height; i++) { + memset(ptr - w, ptr[0], w); + memset(ptr + width, ptr[width - 1], w); + ptr += wrap; + } + + /* top and bottom + corners */ + buf -= w; + last_line = buf + (height - 1) * wrap; + if (sides & EDGE_TOP) + for (int i = 0; i < h; i++) + // top + memcpy(buf - (i + 1) * wrap, buf, width + w + w); + if (sides & EDGE_BOTTOM) + for (int i = 0; i < h; i++) + // bottom + memcpy(last_line + (i + 1) * wrap, last_line, width + w + w); +} + +av_cold void ff_drawedgesdsp_init(DrawEdgesDSPContext *c) +{ + c->draw_edges = draw_edges_c; + +#if ARCH_X86 + ff_drawedgesdsp_init_x86(c); +#endif +} diff --git a/libavcodec/drawedgesdsp.h b/libavcodec/drawedgesdsp.h new file mode 100644 index 0000000000..a57275809c --- /dev/null +++ b/libavcodec/drawedgesdsp.h @@ -0,0 +1,35 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_DRAWEDGESDSP_H +#define AVCODEC_DRAWEDGESDSP_H + +#include + +#define EDGE_TOP 1 +#define EDGE_BOTTOM 2 + +typedef struct DrawEdgesDSPContext { + void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, + int w, int h, int sides); +} DrawEdgesDSPContext; + +void ff_drawedgesdsp_init(DrawEdgesDSPContext *c); +void ff_drawedgesdsp_init_x86(DrawEdgesDSPContext *c); + +#endif /* AVCODEC_DRAWEDGESDSP_H */ diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 215df0fd5b..4635172732 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -29,6 +29,7 @@ #define AVCODEC_MPEGVIDEO_H #include "blockdsp.h" +#include "drawedgesdsp.h" #include "error_resilience.h" #include "fdctdsp.h" #include "get_bits.h" @@ -222,6 +223,7 @@ typedef struct MpegEncContext { HpelDSPContext hdsp; IDCTDSPContext idsp; MECmpContext mecc; + DrawEdgesDSPContext drawedges; MpegvideoEncDSPContext mpvencdsp; PixblockDSPContext pdsp; QpelDSPContext qdsp; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 2a75973ac4..ab14538b33 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -810,6 +810,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) ff_fdctdsp_init(&s->fdsp, avctx); ff_me_cmp_init(&s->mecc, avctx); ff_mpegvideoencdsp_init(&s->mpvencdsp, avctx); + ff_drawedgesdsp_init(&s->drawedges); ff_pixblockdsp_init(&s->pdsp, avctx); if (!(avctx->stats_out = av_mallocz(256)) || @@ -1224,7 +1225,7 @@ static int load_input_picture(MpegEncContext *s, const AVFrame *pic_arg) } } if ((s->width & 15) || (s->height & (vpad-1))) { - s->mpvencdsp.draw_edges(dst, dst_stride, + s->drawedges.draw_edges(dst, dst_stride, w, h, 16 >> h_shift, vpad >> v_shift, @@ -1655,19 +1656,19 @@ static void frame_end(MpegEncContext *s) !s->intra_only) { int hshift = s->chroma_x_shift; int vshift = s->chroma_y_shift; - s->mpvencdsp.draw_edges(s->current_picture.f->data[0], + s->drawedges.draw_edges(s->current_picture.f->data[0], s->current_picture.f->linesize[0], s->h_edge_pos, s->v_edge_pos, EDGE_WIDTH, EDGE_WIDTH, EDGE_TOP | EDGE_BOTTOM); - s->mpvencdsp.draw_edges(s->current_picture.f->data[1], + s->drawedges.draw_edges(s->current_picture.f->data[1], s->current_picture.f->linesize[1], s->h_edge_pos >> hshift, s->v_edge_pos >> vshift, EDGE_WIDTH >> hshift, EDGE_WIDTH >> vshift, EDGE_TOP | EDGE_BOTTOM); - s->mpvencdsp.draw_edges(s->current_picture.f->data[2], + s->drawedges.draw_edges(s->current_picture.f->data[2], s->current_picture.f->linesize[2], s->h_edge_pos >> hshift, s->v_edge_pos >> vshift, diff --git a/libavcodec/mpegvideoencdsp.c b/libavcodec/mpegvideoencdsp.c index 997d048663..a6de93456d 100644 --- a/libavcodec/mpegvideoencdsp.c +++ b/libavcodec/mpegvideoencdsp.c @@ -16,9 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include #include -#include #include "config.h" #include "libavutil/avassert.h" @@ -114,34 +112,6 @@ static int pix_norm1_c(const uint8_t *pix, int line_size) return s; } -/* draw the edges of width 'w' of an image of size width, height */ -// FIXME: Check that this is OK for MPEG-4 interlaced. -static void draw_edges_8_c(uint8_t *buf, int wrap, int width, int height, - int w, int h, int sides) -{ - uint8_t *ptr = buf, *last_line; - int i; - - /* left and right */ - for (i = 0; i < height; i++) { - memset(ptr - w, ptr[0], w); - memset(ptr + width, ptr[width - 1], w); - ptr += wrap; - } - - /* top and bottom + corners */ - buf -= w; - last_line = buf + (height - 1) * wrap; - if (sides & EDGE_TOP) - for (i = 0; i < h; i++) - // top - memcpy(buf - (i + 1) * wrap, buf, width + w + w); - if (sides & EDGE_BOTTOM) - for (i = 0; i < h; i++) - // bottom - memcpy(last_line + (i + 1) * wrap, last_line, width + w + w); -} - /* 2x2 -> 1x1 */ static void shrink22(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, @@ -243,8 +213,6 @@ av_cold void ff_mpegvideoencdsp_init(MpegvideoEncDSPContext *c, c->pix_sum = pix_sum_c; c->pix_norm1 = pix_norm1_c; - c->draw_edges = draw_edges_8_c; - #if ARCH_ARM ff_mpegvideoencdsp_init_arm(c, avctx); #elif ARCH_PPC diff --git a/libavcodec/mpegvideoencdsp.h b/libavcodec/mpegvideoencdsp.h index 95084679d9..46b40cf30e 100644 --- a/libavcodec/mpegvideoencdsp.h +++ b/libavcodec/mpegvideoencdsp.h @@ -26,9 +26,6 @@ #define BASIS_SHIFT 16 #define RECON_SHIFT 6 -#define EDGE_TOP 1 -#define EDGE_BOTTOM 2 - typedef struct MpegvideoEncDSPContext { int (*try_8x8basis)(const int16_t rem[64], const int16_t weight[64], const int16_t basis[64], int scale); @@ -39,9 +36,6 @@ typedef struct MpegvideoEncDSPContext { void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height); - - void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, - int w, int h, int sides); } MpegvideoEncDSPContext; void ff_mpegvideoencdsp_init(MpegvideoEncDSPContext *c, diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c index 43ca602762..ec708cebcc 100644 --- a/libavcodec/snowenc.c +++ b/libavcodec/snowenc.c @@ -27,6 +27,7 @@ #include "libavutil/pixdesc.h" #include "avcodec.h" #include "codec_internal.h" +#include "drawedgesdsp.h" #include "encode.h" #include "internal.h" //For AVCodecInternal.recon_frame #include "me_cmp.h" @@ -46,7 +47,7 @@ typedef struct SnowEncContext { SnowContext com; QpelDSPContext qdsp; - MpegvideoEncDSPContext mpvencdsp; + DrawEdgesDSPContext drawedges; int lambda; int lambda2; @@ -216,7 +217,7 @@ static av_cold int encode_init(AVCodecContext *avctx) mcf(12,12) ff_me_cmp_init(&enc->mecc, avctx); - ff_mpegvideoencdsp_init(&enc->mpvencdsp, avctx); + ff_drawedgesdsp_init(&enc->drawedges); ff_snow_alloc_blocks(s); @@ -1775,7 +1776,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, memcpy(&s->input_picture->data[i][y * s->input_picture->linesize[i]], &pict->data[i][y * pict->linesize[i]], AV_CEIL_RSHIFT(width, hshift)); - enc->mpvencdsp.draw_edges(s->input_picture->data[i], s->input_picture->linesize[i], + enc->drawedges.draw_edges(s->input_picture->data[i], s->input_picture->linesize[i], AV_CEIL_RSHIFT(width, hshift), AV_CEIL_RSHIFT(height, vshift), EDGE_WIDTH >> hshift, EDGE_WIDTH >> vshift, EDGE_TOP | EDGE_BOTTOM); @@ -1815,14 +1816,14 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, int w = s->avctx->width; int h = s->avctx->height; - enc->mpvencdsp.draw_edges(s->current_picture->data[0], + enc->drawedges.draw_edges(s->current_picture->data[0], s->current_picture->linesize[0], w , h , EDGE_WIDTH , EDGE_WIDTH , EDGE_TOP | EDGE_BOTTOM); if (s->current_picture->data[2]) { - enc->mpvencdsp.draw_edges(s->current_picture->data[1], + enc->drawedges.draw_edges(s->current_picture->data[1], s->current_picture->linesize[1], w>>s->chroma_h_shift, h>>s->chroma_v_shift, EDGE_WIDTH>>s->chroma_h_shift, EDGE_WIDTH>>s->chroma_v_shift, EDGE_TOP | EDGE_BOTTOM); - enc->mpvencdsp.draw_edges(s->current_picture->data[2], + enc->drawedges.draw_edges(s->current_picture->data[2], s->current_picture->linesize[2], w>>s->chroma_h_shift, h>>s->chroma_v_shift, EDGE_WIDTH>>s->chroma_h_shift, EDGE_WIDTH>>s->chroma_v_shift, EDGE_TOP | EDGE_BOTTOM); } diff --git a/libavcodec/x86/Makefile b/libavcodec/x86/Makefile index 331183f450..2b6c6659fd 100644 --- a/libavcodec/x86/Makefile +++ b/libavcodec/x86/Makefile @@ -7,6 +7,7 @@ OBJS-$(CONFIG_BLOCKDSP) += x86/blockdsp_init.o OBJS-$(CONFIG_BSWAPDSP) += x86/bswapdsp_init.o OBJS-$(CONFIG_DIRAC_DECODER) += x86/diracdsp_init.o \ x86/dirac_dwt_init.o +OBJS-$(CONFIG_DRAWEDGESDSP) += x86/drawedgesdsp.o OBJS-$(CONFIG_FDCTDSP) += x86/fdctdsp_init.o OBJS-$(CONFIG_FMTCONVERT) += x86/fmtconvert_init.o OBJS-$(CONFIG_H263DSP) += x86/h263dsp_init.o diff --git a/libavcodec/x86/drawedgesdsp.c b/libavcodec/x86/drawedgesdsp.c new file mode 100644 index 0000000000..1d059b3806 --- /dev/null +++ b/libavcodec/x86/drawedgesdsp.c @@ -0,0 +1,157 @@ +/* + * draw_edges by Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include "config.h" + +#include "libavcodec/drawedgesdsp.h" +#include "libavutil/attributes.h" +#include "libavutil/avassert.h" +#include "libavutil/cpu.h" +#include "libavutil/x86/asm.h" +#include "libavutil/x86/cpu.h" + +#if HAVE_INLINE_ASM + +/* Draw the edges of width 'w' of an image of size width, height + * this MMX version can only handle w == 8 || w == 16. */ +static void draw_edges_mmx(uint8_t *buf, int wrap, int width, int height, + int w, int h, int sides) +{ + uint8_t *ptr, *last_line; + + last_line = buf + (height - 1) * wrap; + /* left and right */ + ptr = buf; + if (w == 8) { + __asm__ volatile ( + "1: \n\t" + "movd (%0), %%mm0 \n\t" + "punpcklbw %%mm0, %%mm0 \n\t" + "punpcklwd %%mm0, %%mm0 \n\t" + "punpckldq %%mm0, %%mm0 \n\t" + "movq %%mm0, -8(%0) \n\t" + "movq -8(%0, %2), %%mm1 \n\t" + "punpckhbw %%mm1, %%mm1 \n\t" + "punpckhwd %%mm1, %%mm1 \n\t" + "punpckhdq %%mm1, %%mm1 \n\t" + "movq %%mm1, (%0, %2) \n\t" + "add %1, %0 \n\t" + "cmp %3, %0 \n\t" + "jb 1b \n\t" + : "+r" (ptr) + : "r" ((x86_reg) wrap), "r" ((x86_reg) width), + "r" (ptr + wrap * height)); + } else if (w == 16) { + __asm__ volatile ( + "1: \n\t" + "movd (%0), %%mm0 \n\t" + "punpcklbw %%mm0, %%mm0 \n\t" + "punpcklwd %%mm0, %%mm0 \n\t" + "punpckldq %%mm0, %%mm0 \n\t" + "movq %%mm0, -8(%0) \n\t" + "movq %%mm0, -16(%0) \n\t" + "movq -8(%0, %2), %%mm1 \n\t" + "punpckhbw %%mm1, %%mm1 \n\t" + "punpckhwd %%mm1, %%mm1 \n\t" + "punpckhdq %%mm1, %%mm1 \n\t" + "movq %%mm1, (%0, %2) \n\t" + "movq %%mm1, 8(%0, %2) \n\t" + "add %1, %0 \n\t" + "cmp %3, %0 \n\t" + "jb 1b \n\t" + : "+r"(ptr) + : "r"((x86_reg)wrap), "r"((x86_reg)width), "r"(ptr + wrap * height) + ); + } else { + av_assert1(w == 4); + __asm__ volatile ( + "1: \n\t" + "movd (%0), %%mm0 \n\t" + "punpcklbw %%mm0, %%mm0 \n\t" + "punpcklwd %%mm0, %%mm0 \n\t" + "movd %%mm0, -4(%0) \n\t" + "movd -4(%0, %2), %%mm1 \n\t" + "punpcklbw %%mm1, %%mm1 \n\t" + "punpckhwd %%mm1, %%mm1 \n\t" + "punpckhdq %%mm1, %%mm1 \n\t" + "movd %%mm1, (%0, %2) \n\t" + "add %1, %0 \n\t" + "cmp %3, %0 \n\t" + "jb 1b \n\t" + : "+r" (ptr) + : "r" ((x86_reg) wrap), "r" ((x86_reg) width), + "r" (ptr + wrap * height)); + } + + /* top and bottom (and hopefully also the corners) */ + if (sides & EDGE_TOP) { + for (int i = 0; i < h; i += 4) { + ptr = buf - (i + 1) * wrap - w; + __asm__ volatile ( + "1: \n\t" + "movq (%1, %0), %%mm0 \n\t" + "movq %%mm0, (%0) \n\t" + "movq %%mm0, (%0, %2) \n\t" + "movq %%mm0, (%0, %2, 2) \n\t" + "movq %%mm0, (%0, %3) \n\t" + "add $8, %0 \n\t" + "cmp %4, %0 \n\t" + "jb 1b \n\t" + : "+r" (ptr) + : "r" ((x86_reg) buf - (x86_reg) ptr - w), + "r" ((x86_reg) - wrap), "r" ((x86_reg) - wrap * 3), + "r" (ptr + width + 2 * w)); + } + } + + if (sides & EDGE_BOTTOM) { + for (int i = 0; i < h; i += 4) { + ptr = last_line + (i + 1) * wrap - w; + __asm__ volatile ( + "1: \n\t" + "movq (%1, %0), %%mm0 \n\t" + "movq %%mm0, (%0) \n\t" + "movq %%mm0, (%0, %2) \n\t" + "movq %%mm0, (%0, %2, 2) \n\t" + "movq %%mm0, (%0, %3) \n\t" + "add $8, %0 \n\t" + "cmp %4, %0 \n\t" + "jb 1b \n\t" + : "+r" (ptr) + : "r" ((x86_reg) last_line - (x86_reg) ptr - w), + "r" ((x86_reg) wrap), "r" ((x86_reg) wrap * 3), + "r" (ptr + width + 2 * w)); + } + } +} + +#endif + +av_cold void ff_drawedgesdsp_init_x86(DrawEdgesDSPContext *c) +{ +#if HAVE_INLINE_ASM + int cpu_flags = av_get_cpu_flags(); + + if (INLINE_MMX(cpu_flags)) + c->draw_edges = draw_edges_mmx; +#endif +} diff --git a/libavcodec/x86/mpegvideo.c b/libavcodec/x86/mpegvideo.c index 73967cafda..a4ab2bb308 100644 --- a/libavcodec/x86/mpegvideo.c +++ b/libavcodec/x86/mpegvideo.c @@ -1,6 +1,6 @@ /* * Optimized for ia32 CPUs by Nick Kurshev - * H.263, MPEG-1, MPEG-2 dequantizer & draw_edges by Michael Niedermayer + * H.263, MPEG-1, MPEG-2 dequantizer by Michael Niedermayer * * This file is part of FFmpeg. * diff --git a/libavcodec/x86/mpegvideoencdsp_init.c b/libavcodec/x86/mpegvideoencdsp_init.c index 9fa7ee4824..c816ca2ee7 100644 --- a/libavcodec/x86/mpegvideoencdsp_init.c +++ b/libavcodec/x86/mpegvideoencdsp_init.c @@ -17,7 +17,6 @@ */ #include "libavutil/attributes.h" -#include "libavutil/avassert.h" #include "libavutil/cpu.h" #include "libavutil/x86/cpu.h" #include "libavcodec/avcodec.h" @@ -94,121 +93,6 @@ int ff_pix_norm1_sse2(const uint8_t *pix, int line_size); #undef PMULHRW #undef PHADDD #endif /* HAVE_SSSE3_INLINE */ - -/* Draw the edges of width 'w' of an image of size width, height - * this MMX version can only handle w == 8 || w == 16. */ -static void draw_edges_mmx(uint8_t *buf, int wrap, int width, int height, - int w, int h, int sides) -{ - uint8_t *ptr, *last_line; - int i; - - last_line = buf + (height - 1) * wrap; - /* left and right */ - ptr = buf; - if (w == 8) { - __asm__ volatile ( - "1: \n\t" - "movd (%0), %%mm0 \n\t" - "punpcklbw %%mm0, %%mm0 \n\t" - "punpcklwd %%mm0, %%mm0 \n\t" - "punpckldq %%mm0, %%mm0 \n\t" - "movq %%mm0, -8(%0) \n\t" - "movq -8(%0, %2), %%mm1 \n\t" - "punpckhbw %%mm1, %%mm1 \n\t" - "punpckhwd %%mm1, %%mm1 \n\t" - "punpckhdq %%mm1, %%mm1 \n\t" - "movq %%mm1, (%0, %2) \n\t" - "add %1, %0 \n\t" - "cmp %3, %0 \n\t" - "jb 1b \n\t" - : "+r" (ptr) - : "r" ((x86_reg) wrap), "r" ((x86_reg) width), - "r" (ptr + wrap * height)); - } else if (w == 16) { - __asm__ volatile ( - "1: \n\t" - "movd (%0), %%mm0 \n\t" - "punpcklbw %%mm0, %%mm0 \n\t" - "punpcklwd %%mm0, %%mm0 \n\t" - "punpckldq %%mm0, %%mm0 \n\t" - "movq %%mm0, -8(%0) \n\t" - "movq %%mm0, -16(%0) \n\t" - "movq -8(%0, %2), %%mm1 \n\t" - "punpckhbw %%mm1, %%mm1 \n\t" - "punpckhwd %%mm1, %%mm1 \n\t" - "punpckhdq %%mm1, %%mm1 \n\t" - "movq %%mm1, (%0, %2) \n\t" - "movq %%mm1, 8(%0, %2) \n\t" - "add %1, %0 \n\t" - "cmp %3, %0 \n\t" - "jb 1b \n\t" - : "+r"(ptr) - : "r"((x86_reg)wrap), "r"((x86_reg)width), "r"(ptr + wrap * height) - ); - } else { - av_assert1(w == 4); - __asm__ volatile ( - "1: \n\t" - "movd (%0), %%mm0 \n\t" - "punpcklbw %%mm0, %%mm0 \n\t" - "punpcklwd %%mm0, %%mm0 \n\t" - "movd %%mm0, -4(%0) \n\t" - "movd -4(%0, %2), %%mm1 \n\t" - "punpcklbw %%mm1, %%mm1 \n\t" - "punpckhwd %%mm1, %%mm1 \n\t" - "punpckhdq %%mm1, %%mm1 \n\t" - "movd %%mm1, (%0, %2) \n\t" - "add %1, %0 \n\t" - "cmp %3, %0 \n\t" - "jb 1b \n\t" - : "+r" (ptr) - : "r" ((x86_reg) wrap), "r" ((x86_reg) width), - "r" (ptr + wrap * height)); - } - - /* top and bottom (and hopefully also the corners) */ - if (sides & EDGE_TOP) { - for (i = 0; i < h; i += 4) { - ptr = buf - (i + 1) * wrap - w; - __asm__ volatile ( - "1: \n\t" - "movq (%1, %0), %%mm0 \n\t" - "movq %%mm0, (%0) \n\t" - "movq %%mm0, (%0, %2) \n\t" - "movq %%mm0, (%0, %2, 2) \n\t" - "movq %%mm0, (%0, %3) \n\t" - "add $8, %0 \n\t" - "cmp %4, %0 \n\t" - "jb 1b \n\t" - : "+r" (ptr) - : "r" ((x86_reg) buf - (x86_reg) ptr - w), - "r" ((x86_reg) - wrap), "r" ((x86_reg) - wrap * 3), - "r" (ptr + width + 2 * w)); - } - } - - if (sides & EDGE_BOTTOM) { - for (i = 0; i < h; i += 4) { - ptr = last_line + (i + 1) * wrap - w; - __asm__ volatile ( - "1: \n\t" - "movq (%1, %0), %%mm0 \n\t" - "movq %%mm0, (%0) \n\t" - "movq %%mm0, (%0, %2) \n\t" - "movq %%mm0, (%0, %2, 2) \n\t" - "movq %%mm0, (%0, %3) \n\t" - "add $8, %0 \n\t" - "cmp %4, %0 \n\t" - "jb 1b \n\t" - : "+r" (ptr) - : "r" ((x86_reg) last_line - (x86_reg) ptr - w), - "r" ((x86_reg) wrap), "r" ((x86_reg) wrap * 3), - "r" (ptr + width + 2 * w)); - } - } -} - #endif /* HAVE_INLINE_ASM */ av_cold void ff_mpegvideoencdsp_init_x86(MpegvideoEncDSPContext *c, @@ -232,8 +116,6 @@ av_cold void ff_mpegvideoencdsp_init_x86(MpegvideoEncDSPContext *c, c->try_8x8basis = try_8x8basis_mmx; } c->add_8x8basis = add_8x8basis_mmx; - - c->draw_edges = draw_edges_mmx; } if (INLINE_AMD3DNOW(cpu_flags)) { -- 2.40.1 _______________________________________________ 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".