From patchwork Wed Mar 30 22:49:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 35096 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp1066454pzb; Wed, 30 Mar 2022 15:50:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1gbVUoQX81entGu6Re9qeHEUInoyQWw0dj/t93HuxsS7p+T9Mx2cUUnFYecrebPo4F+R4 X-Received: by 2002:a17:907:2d8d:b0:6df:a06c:7c55 with SMTP id gt13-20020a1709072d8d00b006dfa06c7c55mr2033210ejc.325.1648680620842; Wed, 30 Mar 2022 15:50:20 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w3-20020a170906480300b006dfbfcb1f69si21329519ejq.458.2022.03.30.15.50.20; Wed, 30 Mar 2022 15:50:20 -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; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=ZNaYkJBw; arc=fail (body hash mismatch); 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7A3DE68B21E; Thu, 31 Mar 2022 01:50:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2022.outbound.protection.outlook.com [40.92.89.22]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9B7986801DD for ; Thu, 31 Mar 2022 01:50:09 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BQi/X3pmfRaHYcwb10K4WizbUTFfdEkeSRFhcq1wsVG51Ldct+I5NrNe8KSGDUgGENOJffZTDIvPUObsOa5L+eSkTQUMp9A5wv6DSBZp5l5YqAWyZEk4Fb49lMLRGinqYvbp4MHgSluD/3hEY2YUbonexviguS6RQOlxVnjXCiie0WrlRBo2QEscxTWaFf+yZzCWRtkWnkaiMpA5wxMF/f0syLdOKep6BYdMAgpFlddjYpzLfxwT16JGv0pgjF0braY1Jvb6qQExagbmDFUUCcFLOHH+hOUWyMnukxkh0lv0hrlwZM5kTrABhSJ3KhHp28m0TyNg581o/vmIrLxeuw== 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=2UuOFni6f6K1N1JA1H+yBN2u8k+j6NaKUgrUZZRJovI=; b=DzpBIJ7OXUL0jYHvEH8fJPjCVDoX5UrqccXE61+LtpRBah3E6WmQipxKlnRPxnJhXBs3pDrGXOVqz+QRo24qUWGhqUSzVkgJPXZTDukBajJydXmFpmIRyKDCpsEXw7P84vYPcf1Ln/U72au2gCh87Tn3W37Hqv5OnqUNAPi70qzmxtHA2IGGN5ixQq4UGzTfLX+aw/RRBiHVYyIg9oUq1LmnTukah9JN50cK+/j3gghbRPU2BI0xZjbLoDKue5DOl1WnA4hpxgsPjT0tGtnHvpdHlanfIizDejgTerajnHZBPB3vwpJGlEFOcI2G+ta9HkGafU1/tinNvEBcskaxoA== 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=2UuOFni6f6K1N1JA1H+yBN2u8k+j6NaKUgrUZZRJovI=; b=ZNaYkJBwobDLNGwrmlHk/mBlYXHAvhkD9w2Q5eSRUiUgLOYbHcmIpMyoJLQ1qLxStlTpEf8mJBPV5WeBDC7rESimD7cyt7J74YgLPV6D8qG70NxLEJ9on4SjR3ZIOCXjgi7qWe7V0l9NDV2FM5EYrLL3nFYinLdaNT8QFONCTTBGC9CYxBrU6pfGD0lp6t8WStptrxC1DYBHw01tFRoMYYecdZutiAzIBEOAEJdtwTUpSMObKf0pCRwSOgJK+FBbrQxsOic7nPXhFkqvezuzxV6UT78iEbUPmhZBXYpsiXyPWzaiFYRA5rSpi7IvGjAfPHc0QmI4b9P6ZZhkO4gAYw== Received: from AS1PR01MB9564.eurprd01.prod.exchangelabs.com (2603:10a6:20b:4d1::16) by AM5PR0102MB2579.eurprd01.prod.exchangelabs.com (2603:10a6:206:d::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.17; Wed, 30 Mar 2022 22:50:08 +0000 Received: from AS1PR01MB9564.eurprd01.prod.exchangelabs.com ([fe80::9070:a5fd:e532:bdf8]) by AS1PR01MB9564.eurprd01.prod.exchangelabs.com ([fe80::9070:a5fd:e532:bdf8%3]) with mapi id 15.20.5102.022; Wed, 30 Mar 2022 22:50:07 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 31 Mar 2022 00:49:53 +0200 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [XPQ0uw6TcW+ohmv3kDrI+kLYYZViMl++] X-ClientProxiedBy: ZRAP278CA0002.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:10::12) To AS1PR01MB9564.eurprd01.prod.exchangelabs.com (2603:10a6:20b:4d1::16) X-Microsoft-Original-Message-ID: <20220330224958.538843-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c3838997-74d1-4e09-f195-08da129fa328 X-MS-Exchange-SLBlob-MailProps: gjx25WM8ZNUzzYYNSosKWVK5/sI4Jn4p3+0RytsPbwRsn+C/DRFlS2Q+G32JeRfwZXRB1cdONl65kdfhDKK/OvFTuNhfGGmDXCtlGwANfDsxt3hGzo8U2ixyZnhqPXx3BzNhCCNou1FpFyOn2851dNIR+R6ZGmHUqzACyXZXnkvandz1+vtbCGTglmUwDTnGjltz73hkLoJUAtoLcBTD6+AlcM3dmroi3aaZGBl/MJNraOPalQOHmjJ6pppxP/ySlZnyUetVOr208G9SssqpCyMVnEUFEg90hoUvWjA7IBctf1VZN1YZEsGkWsd2otVrhnUyv7LvFeywxUAZ5e9qyrDBap8Q6SxAd7CV60AtqoL9HFOTh4TEsW8vBSEd9Z5s190oekU9hTkCskWZ3YTfsr0FMVTmXDRJ37WVfU5usjc6koolmN+lPeH9UNPBB5H+C4kIl750WABQt575MX3BboRxu/SBjsmtHJ01G0Ddah+Rm2hvIp9PN6P5DT3uU8Y4B581Be6FLWzdO4LKAM+lhG0TysQ55z/YrvG1R4JdEo/fTtF+3ltayX0LI2Dpt1PY5Vn1UDpv9f7ouWfBT2Ja83EBEwipAFYptPvJKquYCJCaNtlXqevRwbhTi/1uu2MXR4vJ95golRDauQ/lh9gz2lBKMwcO66J5PDI9uzeAl5YsncMtuPVvTGIL+1CQFCiOhBswqp3zg4xgsxCpp0KxjlK1C0IVKppvDm1SLO6Wd8w= X-MS-TrafficTypeDiagnostic: AM5PR0102MB2579:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HRrKkd51AyREzI0xU8qZz2um7clInrLx3djgUBu81LmJKjy1+3LosfOJZroFoR2piPumLnKqIS2hnaGzIW5Fib4BD7dQ5dM0Xjr2v14bWppeg5QtbOSNuoTBNZZlHVScxakhsJ4DB3FtVZi4NPVZSNr66xUKoJx6n6+AR7FuXgspHzTWHaDylNsT3ZfHXXSKQTrnwnmlwEPThQBLujSGIJ2LY6t+VIuDerMDR4EuyvHkuxPAtn68YtzAjZ16PvhJBozE1TSqpHDXESbNE+kBmCrPxE1R15zvo0Jt6cEdefSsIVayTdBRRMNR2arYMKCT6hayWyAzT1/D1ln0VJV1a/bGznb2x3cDNz7R1xxvxY/z6tvtPFot3+3ch+XtxnyrCxXWL2a/Tlzv4accmULa0dA9WS2aaE45sPriWuQ5VYyGr27kC3QW7MCX3hP2hk6yZbPeUhkCPw5vBuJuq2mwcose2i2Ah8FM7lZdx4R0jkcvL1MWtb7aEsMTrt/pSXOnqP/Mno9rZpSkaCMK9zQFOYTaXpaITpuvQ3oz8UYfsW8cUMMgK9X2x0moxZNbP0rj89TOjKonAz/lltpo3MnQvQ== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qHgzcPDTZGwgnGKc5ysKa1CWd4oevYk4O4/0duqZKQjR2ZEFQZXmw00yTuovlp7LkzPfKqwTtHNKFZ7EXuNjO3DY57hhq8LYDJoayDDAh+JI2T9qaaa/M5nSJ/1G8xXd24wCuSbsWL8dHMyo0dIqnFBG/A4VBkk+bTlXxWImYDlBy5PpWjfUc0fwNC8LDPgvqEmNE8L7uk2JShfXsz1ZtLjjP8WJhGSiPyFkEYj1FrBebDlvOVyUQ7vmq5GUT+YI5tW1pH8TBXPtJLN5CLRa7pC1/336TuIrJhe1eHGUeiDew9VciH+Mar35W3biwbze+H6fpdbLe/19Sqc6LukLVUg6sEAeiVuZdms09ZWk8DrmUfX0lyAT+hH02H7FXGomuamQAFbXrGaqnU1w1DZ9GqfhIGaERbXCi4KgaMTRa3RxEzKjl8spmhIDy/RcbmEBYG/GQ9fy0CW2yUh33UCuskzwbXye5RCkNdsfgFieWeTStgq4dIGuGbKAFAB4fyAx7vmL1ykqmTW9V5FUNHyXmum3Nv962k34yv8tADrnKM9hwVjVw5W2od179GC2VbCLLRWiilrtbu05zu7t2z/C67buODCUrA17LMiJeffQIZ+YYLqWBessL/VAJV/XfgoF/C/pgX/be19IkZEc1canORwutFBtB1HjeTPCpfOK9bSrfjEzMAQB4DfPV5B8EeF8cGQPrESblA9ouPQvPZQih1Cr1XiWh8QRTlxY8xGiTCpwlvHNt3RLVuKPFr/qoNSAwPpEQ3Rmh3e0HZYaCXBb9K9FetaXsaRnKU2IIwGPfrash/5fyqjnhb9Oek8MRk2m20bkwjMpEiQivclsvgACRuVVWuc8fwDMLHKLHRiBfw9MFgF/T7+tnf61y1WwC++jEdglluaJrD5DHAsUgS9X9JEpU8cDBEBQA1lLVRJGLdpqcjZHkRxd3hlUzxV38/uFJfkdAc/QM4PabaNdVECsnmOinq4/qzFsO1jYOZ/1kvh47E+yyI0wQiHFhAw/Mhfc/q7b6z4+/72BFhGkULyc3WlEjAptSUNLjYKnb/VOFlsgJNx+lV6zWGwcuTGBKvECguJyxpHFYsLaTS58Tc9UxP1puNpZJ4jqnR40fHeKRe6J+1IybbqWasZpHcokjpglga3XfSZkl3tLhC1LWnKUiTf1Y5DnXi41bo0TLQe8y2rVKTZGFL9Q4YaQk1NFlSBEMupHQ7anYT4A62NE3gddmo5tigr76C4sE1is6PpyqV6SfOfMGAB9S6Ye74gq3MFcW3KLpG6B1+1/FigPTBwThEr3M/V3OORSNzQ7GBg1avKBnkaDV369E24x7t3V5FDwm7fYxaSoqtgd6leSWPLeCiDm/YShGY7riXyJi2kt4o2+hvYbx9XU6lbQ9WBMZrKYayCf2xLAaUe+LI8xm0fr7ERPoLydYxO8rfVVKRe7ACJqa+Mvx/T9aPGBbX8xdOAi X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c3838997-74d1-4e09-f195-08da129fa328 X-MS-Exchange-CrossTenant-AuthSource: AS1PR01MB9564.eurprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2022 22:50:07.5784 (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: AM5PR0102MB2579 Subject: [FFmpeg-devel] [PATCH 2/7] avcodec/codec_internal: Add FFCodec.decode_sub 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: BGA2C+E5i5X7 This increases type-safety by avoiding conversions from/through void*. It also avoids the boilerplate "AVSubtitle *sub = data;" line for subtitle decoders. Its only downside is that it increases sizeof(FFCodec), yet this can be more than offset lateron. Signed-off-by: Andreas Rheinhardt --- libavcodec/assdec.c | 10 ++++------ libavcodec/ccaption_dec.c | 6 +++--- libavcodec/codec_internal.h | 11 ++++++++--- libavcodec/decode.c | 2 +- libavcodec/dvbsubdec.c | 8 +++----- libavcodec/dvdsubdec.c | 8 +++----- libavcodec/jacosubdec.c | 7 +++---- libavcodec/libaribb24.c | 6 +++--- libavcodec/libzvbi-teletextdec.c | 6 +++--- libavcodec/microdvddec.c | 7 +++---- libavcodec/movtextdec.c | 7 +++---- libavcodec/mpl2dec.c | 5 ++--- libavcodec/pgssubdec.c | 13 ++++++------- libavcodec/realtextdec.c | 7 +++---- libavcodec/samidec.c | 7 +++---- libavcodec/srtdec.c | 9 ++++----- libavcodec/subviewerdec.c | 7 +++---- libavcodec/tests/avcodec.c | 7 ++++--- libavcodec/textdec.c | 13 ++++++------- libavcodec/utils.c | 2 +- libavcodec/webvttdec.c | 7 +++---- libavcodec/xsubdec.c | 8 ++++---- 22 files changed, 76 insertions(+), 87 deletions(-) diff --git a/libavcodec/assdec.c b/libavcodec/assdec.c index 86d3e3e5a8..bf1260a947 100644 --- a/libavcodec/assdec.c +++ b/libavcodec/assdec.c @@ -40,11 +40,9 @@ static av_cold int ass_decode_init(AVCodecContext *avctx) return 0; } -static int ass_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr, - AVPacket *avpkt) +static int ass_decode_frame(AVCodecContext *avctx, AVSubtitle *sub, + int *got_sub_ptr, AVPacket *avpkt) { - AVSubtitle *sub = data; - if (avpkt->size <= 0) return avpkt->size; @@ -70,7 +68,7 @@ const FFCodec ff_ssa_decoder = { .p.type = AVMEDIA_TYPE_SUBTITLE, .p.id = AV_CODEC_ID_ASS, .init = ass_decode_init, - .decode = ass_decode_frame, + .decode_sub = ass_decode_frame, .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, }; #endif @@ -82,7 +80,7 @@ const FFCodec ff_ass_decoder = { .p.type = AVMEDIA_TYPE_SUBTITLE, .p.id = AV_CODEC_ID_ASS, .init = ass_decode_init, - .decode = ass_decode_frame, + .decode_sub = ass_decode_frame, .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, }; #endif diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c index 371c8d18b7..32ee3a715d 100644 --- a/libavcodec/ccaption_dec.c +++ b/libavcodec/ccaption_dec.c @@ -838,10 +838,10 @@ static int process_cc608(CCaptionSubContext *ctx, uint8_t hi, uint8_t lo) return ret; } -static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt) +static int decode(AVCodecContext *avctx, AVSubtitle *sub, + int *got_sub, AVPacket *avpkt) { CCaptionSubContext *ctx = avctx->priv_data; - AVSubtitle *sub = data; int64_t in_time = sub->pts; int64_t start_time; int64_t end_time; @@ -955,6 +955,6 @@ const FFCodec ff_ccaption_decoder = { .init = init_decoder, .close = close_decoder, .flush = flush_decoder, - .decode = decode, + .decode_sub = decode, .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, }; diff --git a/libavcodec/codec_internal.h b/libavcodec/codec_internal.h index 596cdbebd2..5c57c438f9 100644 --- a/libavcodec/codec_internal.h +++ b/libavcodec/codec_internal.h @@ -148,19 +148,24 @@ typedef struct FFCodec { int (*encode2)(struct AVCodecContext *avctx, struct AVPacket *avpkt, const struct AVFrame *frame, int *got_packet_ptr); /** - * Decode picture or subtitle data. + * Decode picture data. * * @param avctx codec context * @param outdata codec type dependent output struct * @param[out] got_frame_ptr decoder sets to 0 or 1 to indicate that a - * non-empty frame or subtitle was returned in - * outdata. + * non-empty frame was returned in outdata. * @param[in] avpkt AVPacket containing the data to be decoded * @return amount of bytes read from the packet on success, negative error * code on failure */ int (*decode)(struct AVCodecContext *avctx, void *outdata, int *got_frame_ptr, struct AVPacket *avpkt); + /** + * Decode subtitle data. Same as decode except that it uses + * a struct AVSubtitle structure for output. + */ + int (*decode_sub)(struct AVCodecContext *avctx, struct AVSubtitle *sub, + int *got_frame_ptr, struct AVPacket *avpkt); int (*close)(struct AVCodecContext *); /** * Encode API with decoupled frame/packet dataflow. This function is called diff --git a/libavcodec/decode.c b/libavcodec/decode.c index f9fdb935f6..b5b78b9ca2 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -862,7 +862,7 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, if (avctx->pkt_timebase.num && avpkt->pts != AV_NOPTS_VALUE) sub->pts = av_rescale_q(avpkt->pts, avctx->pkt_timebase, AV_TIME_BASE_Q); - ret = ffcodec(avctx->codec)->decode(avctx, sub, got_sub_ptr, pkt); + ret = ffcodec(avctx->codec)->decode_sub(avctx, sub, got_sub_ptr, pkt); if (pkt == avci->buffer_pkt) // did we recode? av_packet_unref(avci->buffer_pkt); if (ret < 0) { diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c index 0731202aaf..c5391ea5ad 100644 --- a/libavcodec/dvbsubdec.c +++ b/libavcodec/dvbsubdec.c @@ -1607,14 +1607,12 @@ static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf, return 0; } -static int dvbsub_decode(AVCodecContext *avctx, - void *data, int *got_sub_ptr, - AVPacket *avpkt) +static int dvbsub_decode(AVCodecContext *avctx, AVSubtitle *sub, + int *got_sub_ptr, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; DVBSubContext *ctx = avctx->priv_data; - AVSubtitle *sub = data; const uint8_t *p, *p_end; int segment_type; int page_id; @@ -1748,7 +1746,7 @@ const FFCodec ff_dvbsub_decoder = { .priv_data_size = sizeof(DVBSubContext), .init = dvbsub_init_decoder, .close = dvbsub_close_decoder, - .decode = dvbsub_decode, + .decode_sub = dvbsub_decode, .p.priv_class = &dvbsubdec_class, .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, }; diff --git a/libavcodec/dvdsubdec.c b/libavcodec/dvdsubdec.c index 734a387223..713170cdc2 100644 --- a/libavcodec/dvdsubdec.c +++ b/libavcodec/dvdsubdec.c @@ -548,14 +548,12 @@ static int append_to_cached_buf(AVCodecContext *avctx, return 0; } -static int dvdsub_decode(AVCodecContext *avctx, - void *data, int *data_size, - AVPacket *avpkt) +static int dvdsub_decode(AVCodecContext *avctx, AVSubtitle *sub, + int *data_size, AVPacket *avpkt) { DVDSubContext *ctx = avctx->priv_data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; - AVSubtitle *sub = data; int appended = 0; int is_menu; @@ -762,7 +760,7 @@ const FFCodec ff_dvdsub_decoder = { .p.id = AV_CODEC_ID_DVD_SUBTITLE, .priv_data_size = sizeof(DVDSubContext), .init = dvdsub_init, - .decode = dvdsub_decode, + .decode_sub = dvdsub_decode, .flush = dvdsub_flush, .p.priv_class = &dvdsub_class, .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, diff --git a/libavcodec/jacosubdec.c b/libavcodec/jacosubdec.c index 17a837ae70..0d8e601b28 100644 --- a/libavcodec/jacosubdec.c +++ b/libavcodec/jacosubdec.c @@ -162,11 +162,10 @@ static void jacosub_to_ass(AVCodecContext *avctx, AVBPrint *dst, const char *src } } -static int jacosub_decode_frame(AVCodecContext *avctx, - void *data, int *got_sub_ptr, AVPacket *avpkt) +static int jacosub_decode_frame(AVCodecContext *avctx, AVSubtitle *sub, + int *got_sub_ptr, AVPacket *avpkt) { int ret; - AVSubtitle *sub = data; const char *ptr = avpkt->data; FFASSDecoderContext *s = avctx->priv_data; @@ -200,7 +199,7 @@ const FFCodec ff_jacosub_decoder = { .p.type = AVMEDIA_TYPE_SUBTITLE, .p.id = AV_CODEC_ID_JACOSUB, .init = ff_ass_subtitle_header_default, - .decode = jacosub_decode_frame, + .decode_sub = jacosub_decode_frame, .flush = ff_ass_decoder_flush, .priv_data_size = sizeof(FFASSDecoderContext), .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, diff --git a/libavcodec/libaribb24.c b/libavcodec/libaribb24.c index 1b565b2fc9..ab7e0e02d5 100644 --- a/libavcodec/libaribb24.c +++ b/libavcodec/libaribb24.c @@ -283,10 +283,10 @@ next_region: return ret; } -static int libaribb24_decode(AVCodecContext *avctx, void *data, int *got_sub_ptr, AVPacket *pkt) +static int libaribb24_decode(AVCodecContext *avctx, AVSubtitle *sub, + int *got_sub_ptr, AVPacket *pkt) { Libaribb24Context *b24 = avctx->priv_data; - AVSubtitle *sub = data; size_t parsed_data_size = 0; size_t decoded_subtitle_size = 0; const unsigned char *parsed_data = NULL; @@ -391,6 +391,6 @@ const FFCodec ff_libaribb24_decoder = { .priv_data_size = sizeof(Libaribb24Context), .init = libaribb24_init, .close = libaribb24_close, - .decode = libaribb24_decode, + .decode_sub = libaribb24_decode, .flush = libaribb24_flush, }; diff --git a/libavcodec/libzvbi-teletextdec.c b/libavcodec/libzvbi-teletextdec.c index 5ebf47f796..4920c61e0f 100644 --- a/libavcodec/libzvbi-teletextdec.c +++ b/libavcodec/libzvbi-teletextdec.c @@ -637,10 +637,10 @@ static int slice_to_vbi_lines(TeletextContext *ctx, uint8_t* buf, int size) return lines; } -static int teletext_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr, AVPacket *pkt) +static int teletext_decode_frame(AVCodecContext *avctx, AVSubtitle *sub, + int *got_sub_ptr, AVPacket *pkt) { TeletextContext *ctx = avctx->priv_data; - AVSubtitle *sub = data; int ret = 0; if (!ctx->vbi) { @@ -822,6 +822,6 @@ const FFCodec ff_libzvbi_teletext_decoder = { .priv_data_size = sizeof(TeletextContext), .init = teletext_init_decoder, .close = teletext_close_decoder, - .decode = teletext_decode_frame, + .decode_sub = teletext_decode_frame, .flush = teletext_flush, }; diff --git a/libavcodec/microdvddec.c b/libavcodec/microdvddec.c index 0863fe1494..1cd5d1d5f5 100644 --- a/libavcodec/microdvddec.c +++ b/libavcodec/microdvddec.c @@ -274,10 +274,9 @@ static void microdvd_close_no_persistent_tags(AVBPrint *new_line, } } -static int microdvd_decode_frame(AVCodecContext *avctx, - void *data, int *got_sub_ptr, AVPacket *avpkt) +static int microdvd_decode_frame(AVCodecContext *avctx, AVSubtitle *sub, + int *got_sub_ptr, AVPacket *avpkt) { - AVSubtitle *sub = data; AVBPrint new_line; char *line = avpkt->data; char *end = avpkt->data + avpkt->size; @@ -375,7 +374,7 @@ const FFCodec ff_microdvd_decoder = { .p.type = AVMEDIA_TYPE_SUBTITLE, .p.id = AV_CODEC_ID_MICRODVD, .init = microdvd_init, - .decode = microdvd_decode_frame, + .decode_sub = microdvd_decode_frame, .flush = ff_ass_decoder_flush, .priv_data_size = sizeof(FFASSDecoderContext), .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c index 3ba7043180..c3e0a75e57 100644 --- a/libavcodec/movtextdec.c +++ b/libavcodec/movtextdec.c @@ -472,10 +472,9 @@ static int mov_text_init(AVCodecContext *avctx) { return ff_ass_subtitle_header_default(avctx); } -static int mov_text_decode_frame(AVCodecContext *avctx, - void *data, int *got_sub_ptr, AVPacket *avpkt) +static int mov_text_decode_frame(AVCodecContext *avctx, AVSubtitle *sub, + int *got_sub_ptr, AVPacket *avpkt) { - AVSubtitle *sub = data; MovTextContext *m = avctx->priv_data; int ret; AVBPrint buf; @@ -600,7 +599,7 @@ const FFCodec ff_movtext_decoder = { .priv_data_size = sizeof(MovTextContext), .p.priv_class = &mov_text_decoder_class, .init = mov_text_init, - .decode = mov_text_decode_frame, + .decode_sub = mov_text_decode_frame, .close = mov_text_decode_close, .flush = mov_text_flush, .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, diff --git a/libavcodec/mpl2dec.c b/libavcodec/mpl2dec.c index bfcd72bf2d..490a3e6d45 100644 --- a/libavcodec/mpl2dec.c +++ b/libavcodec/mpl2dec.c @@ -63,12 +63,11 @@ static int mpl2_event_to_ass(AVBPrint *buf, const char *p) return 0; } -static int mpl2_decode_frame(AVCodecContext *avctx, void *data, +static int mpl2_decode_frame(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt) { int ret = 0; AVBPrint buf; - AVSubtitle *sub = data; const char *ptr = avpkt->data; FFASSDecoderContext *s = avctx->priv_data; @@ -87,7 +86,7 @@ const FFCodec ff_mpl2_decoder = { .p.long_name = NULL_IF_CONFIG_SMALL("MPL2 subtitle"), .p.type = AVMEDIA_TYPE_SUBTITLE, .p.id = AV_CODEC_ID_MPL2, - .decode = mpl2_decode_frame, + .decode_sub = mpl2_decode_frame, .init = ff_ass_subtitle_header_default, .flush = ff_ass_decoder_flush, .priv_data_size = sizeof(FFASSDecoderContext), diff --git a/libavcodec/pgssubdec.c b/libavcodec/pgssubdec.c index 4cd5e237f2..8b5eb5f816 100644 --- a/libavcodec/pgssubdec.c +++ b/libavcodec/pgssubdec.c @@ -494,10 +494,9 @@ static int parse_presentation_segment(AVCodecContext *avctx, * @param buf pointer to the packet to process * @param buf_size size of packet to process */ -static int display_end_segment(AVCodecContext *avctx, void *data, +static int display_end_segment(AVCodecContext *avctx, AVSubtitle *sub, const uint8_t *buf, int buf_size) { - AVSubtitle *sub = data; PGSSubContext *ctx = avctx->priv_data; int64_t pts; PGSSubPalette *palette; @@ -590,8 +589,8 @@ static int display_end_segment(AVCodecContext *avctx, void *data, return 1; } -static int decode(AVCodecContext *avctx, void *data, int *got_sub_ptr, - AVPacket *avpkt) +static int decode(AVCodecContext *avctx, AVSubtitle *sub, + int *got_sub_ptr, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; @@ -639,7 +638,7 @@ static int decode(AVCodecContext *avctx, void *data, int *got_sub_ptr, ret = parse_object_segment(avctx, buf, segment_length); break; case PRESENTATION_SEGMENT: - ret = parse_presentation_segment(avctx, buf, segment_length, ((AVSubtitle*)(data))->pts); + ret = parse_presentation_segment(avctx, buf, segment_length, sub->pts); break; case WINDOW_SEGMENT: /* @@ -657,7 +656,7 @@ static int decode(AVCodecContext *avctx, void *data, int *got_sub_ptr, ret = AVERROR_INVALIDDATA; break; } - ret = display_end_segment(avctx, data, buf, segment_length); + ret = display_end_segment(avctx, sub, buf, segment_length); if (ret >= 0) *got_sub_ptr = ret; break; @@ -699,7 +698,7 @@ const FFCodec ff_pgssub_decoder = { .priv_data_size = sizeof(PGSSubContext), .init = init_decoder, .close = close_decoder, - .decode = decode, + .decode_sub = decode, .p.priv_class = &pgsdec_class, .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, }; diff --git a/libavcodec/realtextdec.c b/libavcodec/realtextdec.c index 4c0694c8ed..1612554461 100644 --- a/libavcodec/realtextdec.c +++ b/libavcodec/realtextdec.c @@ -56,11 +56,10 @@ static int rt_event_to_ass(AVBPrint *buf, const char *p) return 0; } -static int realtext_decode_frame(AVCodecContext *avctx, - void *data, int *got_sub_ptr, AVPacket *avpkt) +static int realtext_decode_frame(AVCodecContext *avctx, AVSubtitle *sub, + int *got_sub_ptr, AVPacket *avpkt) { int ret = 0; - AVSubtitle *sub = data; const char *ptr = avpkt->data; FFASSDecoderContext *s = avctx->priv_data; AVBPrint buf; @@ -80,7 +79,7 @@ const FFCodec ff_realtext_decoder = { .p.long_name = NULL_IF_CONFIG_SMALL("RealText subtitle"), .p.type = AVMEDIA_TYPE_SUBTITLE, .p.id = AV_CODEC_ID_REALTEXT, - .decode = realtext_decode_frame, + .decode_sub = realtext_decode_frame, .init = ff_ass_subtitle_header_default, .flush = ff_ass_decoder_flush, .priv_data_size = sizeof(FFASSDecoderContext), diff --git a/libavcodec/samidec.c b/libavcodec/samidec.c index 2c8c31e4f6..f2cf5783af 100644 --- a/libavcodec/samidec.c +++ b/libavcodec/samidec.c @@ -132,10 +132,9 @@ end: return ret; } -static int sami_decode_frame(AVCodecContext *avctx, - void *data, int *got_sub_ptr, AVPacket *avpkt) +static int sami_decode_frame(AVCodecContext *avctx, AVSubtitle *sub, + int *got_sub_ptr, AVPacket *avpkt) { - AVSubtitle *sub = data; const char *ptr = avpkt->data; SAMIContext *sami = avctx->priv_data; @@ -189,7 +188,7 @@ const FFCodec ff_sami_decoder = { .priv_data_size = sizeof(SAMIContext), .init = sami_init, .close = sami_close, - .decode = sami_decode_frame, + .decode_sub = sami_decode_frame, .flush = sami_flush, .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, }; diff --git a/libavcodec/srtdec.c b/libavcodec/srtdec.c index 5de360b821..aa975d16c7 100644 --- a/libavcodec/srtdec.c +++ b/libavcodec/srtdec.c @@ -55,10 +55,9 @@ static int srt_to_ass(AVCodecContext *avctx, AVBPrint *dst, return ff_htmlmarkup_to_ass(avctx, dst, in); } -static int srt_decode_frame(AVCodecContext *avctx, - void *data, int *got_sub_ptr, AVPacket *avpkt) +static int srt_decode_frame(AVCodecContext *avctx, AVSubtitle *sub, + int *got_sub_ptr, AVPacket *avpkt) { - AVSubtitle *sub = data; AVBPrint buffer; int x1 = -1, y1 = -1, x2 = -1, y2 = -1; int ret; @@ -97,7 +96,7 @@ const FFCodec ff_srt_decoder = { .p.type = AVMEDIA_TYPE_SUBTITLE, .p.id = AV_CODEC_ID_SUBRIP, .init = ff_ass_subtitle_header_default, - .decode = srt_decode_frame, + .decode_sub = srt_decode_frame, .flush = ff_ass_decoder_flush, .priv_data_size = sizeof(FFASSDecoderContext), .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, @@ -111,7 +110,7 @@ const FFCodec ff_subrip_decoder = { .p.type = AVMEDIA_TYPE_SUBTITLE, .p.id = AV_CODEC_ID_SUBRIP, .init = ff_ass_subtitle_header_default, - .decode = srt_decode_frame, + .decode_sub = srt_decode_frame, .flush = ff_ass_decoder_flush, .priv_data_size = sizeof(FFASSDecoderContext), .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, diff --git a/libavcodec/subviewerdec.c b/libavcodec/subviewerdec.c index cbc3056c90..9001dd3d45 100644 --- a/libavcodec/subviewerdec.c +++ b/libavcodec/subviewerdec.c @@ -47,11 +47,10 @@ static int subviewer_event_to_ass(AVBPrint *buf, const char *p) return 0; } -static int subviewer_decode_frame(AVCodecContext *avctx, - void *data, int *got_sub_ptr, AVPacket *avpkt) +static int subviewer_decode_frame(AVCodecContext *avctx, AVSubtitle *sub, + int *got_sub_ptr, AVPacket *avpkt) { int ret = 0; - AVSubtitle *sub = data; const char *ptr = avpkt->data; FFASSDecoderContext *s = avctx->priv_data; AVBPrint buf; @@ -71,7 +70,7 @@ const FFCodec ff_subviewer_decoder = { .p.long_name = NULL_IF_CONFIG_SMALL("SubViewer subtitle"), .p.type = AVMEDIA_TYPE_SUBTITLE, .p.id = AV_CODEC_ID_SUBVIEWER, - .decode = subviewer_decode_frame, + .decode_sub = subviewer_decode_frame, .init = ff_ass_subtitle_header_default, .flush = ff_ass_decoder_flush, .priv_data_size = sizeof(FFASSDecoderContext), diff --git a/libavcodec/tests/avcodec.c b/libavcodec/tests/avcodec.c index 075ad632c4..f77d7aebe9 100644 --- a/libavcodec/tests/avcodec.c +++ b/libavcodec/tests/avcodec.c @@ -135,12 +135,13 @@ int main(void){ codec->capabilities & AV_CODEC_CAP_ENCODER_FLUSH) ERR("Frame-threaded encoder %s claims to support flushing\n"); } else { - if (codec->type == AVMEDIA_TYPE_SUBTITLE && !codec2->decode) - ERR("Subtitle decoder %s does not implement decode callback\n"); + if (codec->type == AVMEDIA_TYPE_SUBTITLE && !codec2->decode_sub) + ERR("Subtitle decoder %s does not implement decode_sub callback\n"); if (codec->type == AVMEDIA_TYPE_SUBTITLE && codec2->bsfs) ERR("Automatic bitstream filtering unsupported for subtitles; " "yet decoder %s has it set\n"); - if (!!codec2->decode + !!codec2->receive_frame != 1) + if (codec->type != AVMEDIA_TYPE_SUBTITLE != + !!codec2->decode + !!codec2->receive_frame) ERR("Decoder %s does not implement exactly one decode API.\n"); if (codec->capabilities & (AV_CODEC_CAP_SMALL_LAST_FRAME | AV_CODEC_CAP_VARIABLE_FRAME_SIZE | diff --git a/libavcodec/textdec.c b/libavcodec/textdec.c index 95450a18f7..48e7e14602 100644 --- a/libavcodec/textdec.c +++ b/libavcodec/textdec.c @@ -45,12 +45,11 @@ static const AVOption options[] = { { NULL } }; -static int text_decode_frame(AVCodecContext *avctx, void *data, +static int text_decode_frame(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt) { int ret = 0; AVBPrint buf; - AVSubtitle *sub = data; const char *ptr = avpkt->data; TextContext *text = avctx->priv_data; @@ -87,7 +86,7 @@ const FFCodec ff_text_decoder = { .priv_data_size = sizeof(TextContext), .p.type = AVMEDIA_TYPE_SUBTITLE, .p.id = AV_CODEC_ID_TEXT, - .decode = text_decode_frame, + .decode_sub = text_decode_frame, .init = ff_ass_subtitle_header_default, .p.priv_class = &textsub_decoder_class, .flush = text_flush, @@ -111,7 +110,7 @@ const FFCodec ff_vplayer_decoder = { .priv_data_size = sizeof(TextContext), .p.type = AVMEDIA_TYPE_SUBTITLE, .p.id = AV_CODEC_ID_VPLAYER, - .decode = text_decode_frame, + .decode_sub = text_decode_frame, .init = linebreak_init, .p.priv_class = &textsub_decoder_class, .flush = text_flush, @@ -126,7 +125,7 @@ const FFCodec ff_stl_decoder = { .priv_data_size = sizeof(TextContext), .p.type = AVMEDIA_TYPE_SUBTITLE, .p.id = AV_CODEC_ID_STL, - .decode = text_decode_frame, + .decode_sub = text_decode_frame, .init = linebreak_init, .p.priv_class = &textsub_decoder_class, .flush = text_flush, @@ -141,7 +140,7 @@ const FFCodec ff_pjs_decoder = { .priv_data_size = sizeof(TextContext), .p.type = AVMEDIA_TYPE_SUBTITLE, .p.id = AV_CODEC_ID_PJS, - .decode = text_decode_frame, + .decode_sub = text_decode_frame, .init = linebreak_init, .p.priv_class = &textsub_decoder_class, .flush = text_flush, @@ -156,7 +155,7 @@ const FFCodec ff_subviewer1_decoder = { .priv_data_size = sizeof(TextContext), .p.type = AVMEDIA_TYPE_SUBTITLE, .p.id = AV_CODEC_ID_SUBVIEWER1, - .decode = text_decode_frame, + .decode_sub = text_decode_frame, .init = linebreak_init, .p.priv_class = &textsub_decoder_class, .flush = text_flush, diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 1666f5dabb..34d97022b7 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -80,7 +80,7 @@ int av_codec_is_encoder(const AVCodec *avcodec) int av_codec_is_decoder(const AVCodec *avcodec) { const FFCodec *const codec = ffcodec(avcodec); - return codec && (codec->decode || codec->receive_frame); + return codec && (codec->decode || codec->decode_sub || codec->receive_frame); } int ff_set_dimensions(AVCodecContext *s, int width, int height) diff --git a/libavcodec/webvttdec.c b/libavcodec/webvttdec.c index 4ebbc63074..8cb7fea070 100644 --- a/libavcodec/webvttdec.c +++ b/libavcodec/webvttdec.c @@ -80,11 +80,10 @@ static int webvtt_event_to_ass(AVBPrint *buf, const char *p) return 0; } -static int webvtt_decode_frame(AVCodecContext *avctx, - void *data, int *got_sub_ptr, AVPacket *avpkt) +static int webvtt_decode_frame(AVCodecContext *avctx, AVSubtitle *sub, + int *got_sub_ptr, AVPacket *avpkt) { int ret = 0; - AVSubtitle *sub = data; const char *ptr = avpkt->data; FFASSDecoderContext *s = avctx->priv_data; AVBPrint buf; @@ -104,7 +103,7 @@ const FFCodec ff_webvtt_decoder = { .p.long_name = NULL_IF_CONFIG_SMALL("WebVTT subtitle"), .p.type = AVMEDIA_TYPE_SUBTITLE, .p.id = AV_CODEC_ID_WEBVTT, - .decode = webvtt_decode_frame, + .decode_sub = webvtt_decode_frame, .init = ff_ass_subtitle_header_default, .flush = ff_ass_decoder_flush, .priv_data_size = sizeof(FFASSDecoderContext), diff --git a/libavcodec/xsubdec.c b/libavcodec/xsubdec.c index cb7b7b7cab..c2c1b920cc 100644 --- a/libavcodec/xsubdec.c +++ b/libavcodec/xsubdec.c @@ -47,11 +47,11 @@ static int64_t parse_timecode(const uint8_t *buf, int64_t packet_time) { return ms - packet_time; } -static int decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr, - AVPacket *avpkt) { +static int decode_frame(AVCodecContext *avctx, AVSubtitle *sub, + int *got_sub_ptr, AVPacket *avpkt) +{ const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; - AVSubtitle *sub = data; AVSubtitleRect *rect; const uint8_t *buf_end = buf + buf_size; uint8_t *bitmap; @@ -160,6 +160,6 @@ const FFCodec ff_xsub_decoder = { .p.type = AVMEDIA_TYPE_SUBTITLE, .p.id = AV_CODEC_ID_XSUB, .init = decode_init, - .decode = decode_frame, + .decode_sub = decode_frame, .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, };