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 2EC4B4318D for ; Fri, 14 Jan 2022 17:54:00 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B4DC368B56C; Fri, 14 Jan 2022 19:53:58 +0200 (EET) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2045.outbound.protection.outlook.com [40.92.91.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E6C7168B2D8 for ; Fri, 14 Jan 2022 19:53:52 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=io3MbS2mhUBMdCrL2dHmFEYy5d5vyv4NQj8MHvKrGMDyvLUSgs8CszG4WQ8PA6ZmMW44g90btvUBtpJ1EG1w94xEfsXMUgreIpLBikkCerRtbvfzztXklgMV6kWouQgcCuRuIEhz5NPz8zjjCYxJl/M3R/N1ROSEa3shQcg2JIxjjpbk+WVQmq0aWqI5Q7hiugBPxhcyyQ+i1yCspav99IcpvnJ/eHmHEZLw5idtbRaRHsG/09FW7MJ6s2YGumEzKa32gPDed/iGvnG5rpVeX1StPoPvcyquxvfIpVzZBDMkzkkimVDmwP48XCaE6P7PjA7TqiljzahjnFk8LEdEeg== 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=yg1NLOetI7AzRF7iKGKs8gDrpZbJuxbcPN5mp15evTc=; b=EpJS1Quo9BAx+IfGeVH52XJ7bdiDPlo+JWnuVrXR2ANZ/EJ7VctnEpLlxGGsQux2ZpDSujK/QPbVIKAR3+UcVn7ERpHHilO6p2tFYE0iSCR3+79zFxzZqo+PDAp/NgkncoLjzhDLw+hdxFrZZ2f1bY8B/Nkq68eOxrqfwtiiT4sE5XWETlMBXjpDSB4eYTKYPATvOUe7e49NjlAofKz6htZJaXIzPkhC/+FVHS04k/SeYoVV2ez2vofyzk6H5fEIHcXYWGUblYY+9M9korX3S/LBG3q+tTcFTveLjWUdOF3erE2GwqTJmN0wt4HAzNamRuR9I8DCSwtC9OMlOtt3vw== 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=yg1NLOetI7AzRF7iKGKs8gDrpZbJuxbcPN5mp15evTc=; b=MGVJumygE6BdF7VWNz5RggpiTXSdLEEsjZE/LzcqKGODT6bXH68NwV8LdF2T15w+wI1gQbU6l801Inz1HPKx3pfNI1f1xnFgP8wigd/5K1100TnFhRz4JZxhZtvctTqttxNZ+E+9LwRph66dsLXRkn3wmTiwfv8Qlj6UVeTbUSSgI6424WP2WD1DXnww3ggzG5maWpxSaIfJ9DFmebK+G5la9w1aOAT3/TXIsd7E7mWD5HAEqEicC++xa9O5vixyniuyHbOQLy7JeabuHfmySHVZ2ZoUNepvQnoeAIeXIPcM/S3mSD6qP3Mi2pqet3lZb7tpP88NscZ7FtYK2/PgTg== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR0302MB3447.eurprd03.prod.outlook.com (2603:10a6:209:1d::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.11; Fri, 14 Jan 2022 17:53:51 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::19fc:be9f:2c9c:53f5]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::19fc:be9f:2c9c:53f5%9]) with mapi id 15.20.4888.012; Fri, 14 Jan 2022 17:53:51 +0000 Message-ID: Date: Fri, 14 Jan 2022 18:53:45 +0100 Content-Language: en-US To: ffmpeg-devel@ffmpeg.org References: From: Andreas Rheinhardt In-Reply-To: X-TMN: [p5JEBRXfp2Ima4g4cHH7bb9IA+OoDvMB] X-ClientProxiedBy: AM0PR02CA0076.eurprd02.prod.outlook.com (2603:10a6:208:154::17) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <76d728d1-f4c1-cf9b-80e4-75a744e36bce@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e0e37b4a-69bd-48c9-b818-08d9d786d2b3 X-MS-TrafficTypeDiagnostic: AM6PR0302MB3447:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VsOlj93XFn6Y8F5TK/tRbdV4NRBq6Rt7kR2jMkStcnwKVi4sqwkcpzrbXdwK6QXjgoh2vcEJ6HyUcFutddDWNyvrH8lZ8p/MGSALo/y/Kd/Oqaxe+QNcJI2o+tZjkk7znKZctpWe+G+II/x6wrdwfgP+l8UIeQOJAmeqtnn9tBZHxYuftZD6jTl0ymT6hXEPNpQnrxyXwPfalsOnk8Tf32mnPbcO4rrOL3H1ja/GjOG3EQMQKx/UiEegaKZGJ60wNQYsApIrQ+CzxqhqiVEFkmZDPpEYkb9N/ubgySB315l0UbqH5hGDMCLIp8FzUDDSJJU50Gl3FSJxHCoDBTaiI1Wkq371TArHgQ6bzUxWjePu0FT2he7APwRIUr7tDYK0UpStWQWVXy81BjAfWBD7f4DNoD3H370xs5kNhaRmRk8h8L//HInqifeyou46PX+etCeCb+ukGlie2WUpJTRYuve+VqyPhvnJNUDFmI3/c3UldzckZISGxzPRRihBU7NT7cAeRGjjjrtn5A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htcE1aTUxFT0tTSERBajdS?= =?utf-8?B?WW5PVDZRTU00alJ3ZDFSdWdvWnJTOHFickw2aytRTkUzVDFLVlVPTzBZQytx?= =?utf-8?B?ME8vRTM0YUVJYmgyWUFta3RyZXZUUjFCN3Q3RS9qaW5hcUhGbE5VSWpGMDEz?= =?utf-8?B?ZjFvTjdDUlJkYXVXL1FZelQrd0tTS0xFSWIwdE5OV1ZyajA3eVYrdmhwb3U5?= =?utf-8?B?TUdFekJrYVRwVkFURDJSTDRkeE5zSHJ2enJqcEpnTmZrbEtjTm9uaU9NcmJw?= =?utf-8?B?SkNxMDdKekhHVkFNcS8xYWgzV1hkOTErTW9CbC8zdWE0MFN3Q2hVc2drSHU2?= =?utf-8?B?eExPenkzK1lSOEt4YWNSWkhmalZ6OTYyWTdlTStoUVlwOTJYbk1IQW4yWCtx?= =?utf-8?B?K05Yd3h6b3hoeGVXbVlvUStmZGRKbTl2M1BMVWxFUTlEWTZoZGxoRnBuanNP?= =?utf-8?B?bndUQVROZElwdk4zMk5nZERRMHFaaTUwSklBa0ZDRm04eWFWNlpSdCtTUDBm?= =?utf-8?B?MGJoMlhUR3M3enF1emhNbFo5SzBpYnJXZEhvWTNuUkdvdHdZQjN0dFJRUWVq?= =?utf-8?B?dFo4dGswRlBsNUtSMTFuNDl2bTA3OFNINXVPdzREZVJYWFhjdz09?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e0e37b4a-69bd-48c9-b818-08d9d786d2b3 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jan 2022 17:53:51.2887 (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: AM6PR0302MB3447 Subject: Re: [FFmpeg-devel] [PATCH 03/24] avcodec/subtitles: Introduce new frame-based subtitle decoding API 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 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: ffmpegagent: > From: softworkz > > - Add avcodec_decode_subtitle3 which takes subtitle frames, > serving as compatibility shim to legacy subtitle decoding > - Add additional methods for conversion between old and new API This commit message is completely wrong. > > Signed-off-by: softworkz > --- > libavcodec/avcodec.h | 8 +- > libavcodec/codec_desc.c | 11 +++ > libavcodec/codec_desc.h | 8 ++ > libavcodec/decode.c | 56 ++++++++++-- > libavcodec/internal.h | 22 +++++ > libavcodec/utils.c | 184 ++++++++++++++++++++++++++++++++++++++++ > 6 files changed, 280 insertions(+), 9 deletions(-) > > diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h > index fe5a83cf85..9d59f6e840 100644 > --- a/libavcodec/avcodec.h > +++ b/libavcodec/avcodec.h > @@ -1675,7 +1675,7 @@ typedef struct AVCodecContext { > > /** > * Header containing style information for text subtitles. > - * For SUBTITLE_ASS subtitle type, it should contain the whole ASS > + * For AV_SUBTITLE_FMT_ASS subtitle type, it should contain the whole ASS > * [Script Info] and [V4+ Styles] section, plus the [Events] line and > * the Format line following. It shouldn't include any Dialogue line. > * - encoding: Set/allocated/freed by user (before avcodec_open2()) > @@ -2415,7 +2415,10 @@ int avcodec_close(AVCodecContext *avctx); > * Free all allocated data in the given subtitle struct. > * > * @param sub AVSubtitle to free. > + * > + * @deprecated Use the regular frame based encode and decode APIs instead. > */ > +attribute_deprecated > void avsubtitle_free(AVSubtitle *sub); > > /** > @@ -2508,7 +2511,10 @@ enum AVChromaLocation avcodec_chroma_pos_to_enum(int xpos, int ypos); > * must be freed with avsubtitle_free if *got_sub_ptr is set. > * @param[in,out] got_sub_ptr Zero if no subtitle could be decompressed, otherwise, it is nonzero. > * @param[in] avpkt The input AVPacket containing the input buffer. > + * > + * @deprecated Use the new decode API (avcodec_send_packet, avcodec_receive_frame) instead. > */ > +attribute_deprecated > int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, > int *got_sub_ptr, > AVPacket *avpkt); > diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c > index 0974ee03de..e48e4532ba 100644 > --- a/libavcodec/codec_desc.c > +++ b/libavcodec/codec_desc.c > @@ -3548,3 +3548,14 @@ enum AVMediaType avcodec_get_type(enum AVCodecID codec_id) > const AVCodecDescriptor *desc = avcodec_descriptor_get(codec_id); > return desc ? desc->type : AVMEDIA_TYPE_UNKNOWN; > } > + > +enum AVSubtitleType avcodec_descriptor_get_subtitle_format(const AVCodecDescriptor *codec_descriptor) > +{ > + if(codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB) > + return AV_SUBTITLE_FMT_BITMAP; > + > + if(codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB) > + return AV_SUBTITLE_FMT_ASS; > + > + return AV_SUBTITLE_FMT_UNKNOWN; > +} > diff --git a/libavcodec/codec_desc.h b/libavcodec/codec_desc.h > index 126b52df47..ba68d24e0e 100644 > --- a/libavcodec/codec_desc.h > +++ b/libavcodec/codec_desc.h > @@ -121,6 +121,14 @@ const AVCodecDescriptor *avcodec_descriptor_next(const AVCodecDescriptor *prev); > */ > const AVCodecDescriptor *avcodec_descriptor_get_by_name(const char *name); > > +/** > + * Return subtitle format from a codec descriptor > + * > + * @param codec_descriptor codec descriptor > + * @return the subtitle type (e.g. bitmap, text) > + */ > +enum AVSubtitleType avcodec_descriptor_get_subtitle_format(const AVCodecDescriptor *codec_descriptor); > + > /** > * @} > */ > diff --git a/libavcodec/decode.c b/libavcodec/decode.c > index 0912f86a14..ab8a6ea6ff 100644 > --- a/libavcodec/decode.c > +++ b/libavcodec/decode.c > @@ -576,6 +576,39 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) > return ret; > } > > +static int decode_subtitle2_priv(AVCodecContext *avctx, AVSubtitle *sub, > + int *got_sub_ptr, AVPacket *avpkt); > + > +static int decode_subtitle_shim(AVCodecContext *avctx, AVFrame *frame, AVPacket *avpkt) > +{ > + int ret, got_sub_ptr = 0; > + AVSubtitle subtitle = { 0 }; > + > + if (frame->buf[0]) > + return AVERROR(EAGAIN); > + > + av_frame_unref(frame); > + > + ret = decode_subtitle2_priv(avctx, &subtitle, &got_sub_ptr, avpkt); > + > + if (ret >= 0 && got_sub_ptr) { > + frame->type = AVMEDIA_TYPE_SUBTITLE; > + frame->format = subtitle.format; > + ret = av_frame_get_buffer2(frame, 0); > + > + if (ret >= 0) > + ret = ff_frame_put_subtitle(frame, &subtitle); > + > + frame->width = avctx->width; > + frame->height = avctx->height; > + frame->pkt_dts = avpkt->dts; > + } > + > + avsubtitle_free(&subtitle); > + > + return ret; > +} > + > int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt) > { > AVCodecInternal *avci = avctx->internal; > @@ -590,6 +623,9 @@ int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const AVPacke > if (avpkt && !avpkt->size && avpkt->data) > return AVERROR(EINVAL); > > + if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) > + return decode_subtitle_shim(avctx, avci->buffer_frame, avpkt); With the avcodec_send_packet/avcodec_receive_frame API the user is supposed to send the packet only once (unless we have the EAGAIN case). Libavcodec takes care to buffer the packet in case this is necessary even if the packet leads to multiple returned frames. In contrast to this, the old API required the user to send the packet again, but with data offsetted and size decremented to reflect this. Some decoders (at least pgssubdec*) seem to be designed to only consume partial packets; if that is the case, then your approach above won't work and you will need to buffer the packet. In other words: The subtitle decoding codepath will become more like the codepaths for audio and video. The old API is btw even more broken, in particular in case the subtitles are recoded: Typically the size of the recoded UTF-8 is returned which is an API abuse on part of lavc. See https://github.com/mkver/FFmpeg/commit/ba1564c532654888015d67b70bf73d117c2d9f75 (part of https://github.com/mkver/FFmpeg/commits/subs) for more. *: It seems that libzvbi currently always fully consumes the AVPacket; yet looking at the history I don't know whether this is actually intended and correct. > + > av_packet_unref(avci->buffer_pkt); > if (avpkt && (avpkt->data || avpkt->side_data_elems)) { > ret = av_packet_ref(avci->buffer_pkt, avpkt); > @@ -651,7 +687,9 @@ int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *fr > > if (avci->buffer_frame->buf[0]) { > av_frame_move_ref(frame, avci->buffer_frame); > - } else { > + } else if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) > + return AVERROR(EAGAIN); > + else { > ret = decode_receive_frame_internal(avctx, frame); > if (ret < 0) > return ret; > @@ -802,9 +840,8 @@ static int utf8_check(const uint8_t *str) > return 1; > } > > -int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, > - int *got_sub_ptr, > - AVPacket *avpkt) > +static int decode_subtitle2_priv(AVCodecContext *avctx, AVSubtitle *sub, > + int *got_sub_ptr, AVPacket *avpkt) > { > int ret = 0; > > @@ -850,10 +887,7 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, > avctx->pkt_timebase, ms); > } > > - if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB) > - sub->format = 0; > - else if (avctx->codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB) > - sub->format = 1; > + sub->format = avcodec_descriptor_get_subtitle_format(avctx->codec_descriptor); > > for (unsigned i = 0; i < sub->num_rects; i++) { > if (avctx->sub_charenc_mode != FF_SUB_CHARENC_MODE_IGNORE && > @@ -874,6 +908,12 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, > return ret; > } > > +int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, > + int *got_sub_ptr, AVPacket *avpkt) > +{ > + return decode_subtitle2_priv(avctx, sub, got_sub_ptr, avpkt); > +} > + > enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *avctx, > const enum AVPixelFormat *fmt) > { > diff --git a/libavcodec/internal.h b/libavcodec/internal.h > index 72ca1553f6..ff63974f7f 100644 > --- a/libavcodec/internal.h > +++ b/libavcodec/internal.h > @@ -363,4 +363,26 @@ int ff_int_from_list_or_default(void *ctx, const char * val_name, int val, > > void ff_dvdsub_parse_palette(uint32_t *palette, const char *p); > > +/** > + * Copies subtitle data from AVSubtitle to AVFrame. > + * > + * @deprecated This is a compatibility method for interoperability with > + * the legacy subtitle API. > + */ > +int ff_frame_put_subtitle(AVFrame* frame, const AVSubtitle* sub); > + > +/** > + * Copies subtitle data from AVFrame to AVSubtitle. > + * > + * @deprecated This is a compatibility method for interoperability with > + * the legacy subtitle API. > + */ > +int ff_frame_get_subtitle(AVSubtitle* sub, AVFrame* frame); > + > +#if defined(_WIN32) && CONFIG_SHARED && !defined(BUILDING_avcodec) > +# define av_export_avcodec __declspec(dllimport) > +#else > +# define av_export_avcodec > +#endif This seems like a rebase problem. > + > #endif /* AVCODEC_INTERNAL_H */ _______________________________________________ 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".