From patchwork Thu Apr 15 02:04:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26921 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 367A844A46B for ; Thu, 15 Apr 2021 05:04:28 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 24CA768A78A; Thu, 15 Apr 2021 05:04:28 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-oln040092064075.outbound.protection.outlook.com [40.92.64.75]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C27BA68A3BD for ; Thu, 15 Apr 2021 05:04:26 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SMprnA3thxA17nmLu5E1ZwNViLv6DLLWWBJnsLT6Hh5f5CRm45y6y5P21hVfd1VrOWt3ifACvd7rFb+QSYbh+Z/sjv3wTE0aQa/BebEetKwI1nbAKuR+9bnCKfPpTaxScJpXBU5/l+TP8nu9EKMuDfPFcA+H5744nVAZolEJDNdheYncWswtjYbBmbWFFD4E/aKX6Y2lmygO/dINDIylJhh3svAjGAqYrbFnVzubuMjG3gVjuMNCmIMG4k9GuFwsB0o6NJl6oYFQRPntWJKKjyixzkJ1nacKOy5+9qyIb+wf3sY4IVcBhpRFebk29avH2pMwJJXkcSc3Xi5fmVtB3Q== 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-SenderADCheck; bh=hHHfUzzWkAAu94vGvx5oOI5GbdobLk3on/akFLEE86o=; b=iAHp8AT1TD+erDheoKXDa9toJW8OHcnX4miCA4Npjtmjlr4HJ1J7haO05CjXKJvarLKgqQgKlYsoze3mDzhQUqERbb1SeB35w2NH1WkSl1gQw/yt96qYoQu+fgQnjB84s6IErog9EDNUf8YmhbFXKDICCUK1aLXMLCMu83EujdE+SWMcYYDczPjCOcCltgCFTIsPEKP7ZyYW8cLxOUwWCoxKgCd3OSk7mKEU7gYZXUfTLqbjF+tCN1Ab22GIdkJRhyyrbHLfzAXsszY7rIyXA+WJ5LrwhciXewmN/uvcdxlQLH8YWWeCLgQ/3xV7iMh6NYp5je/cJTMwbwk70ojsaw== 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=hHHfUzzWkAAu94vGvx5oOI5GbdobLk3on/akFLEE86o=; b=Y5r/IIRuWQBtLzRI1s350tOq8O3jAQYmkr4o8VLF6vzSZsZ5lXYmdSWhN4gj0aB7IcTIi7vBK52mduEHPO/CeZpNsOi0BZ7+uhJKRA2yFSexCiWdtus7yZTauvd6nSwpGw7dIqjQ2C995EBJY9FV0SM0kTNXFljHUhjgZy6NM6T3cxGr72oIv7Sj/VnTy0l2P9aNDXQJsss/jUHVkFgTcjeoJgAH7X70z7wNvNbeMtPWOSHOTuH3R2vvvB/1xL+309E5xvFQdq/I89FipoZASmWeN404WSoSuqcvCR3KofMDvphbvomBpiujV4AxmHekYf33fMon6NhKMYO5TpPoyA== Received: from DB5EUR01FT021.eop-EUR01.prod.protection.outlook.com (2a01:111:e400:7e1a::51) by DB5EUR01HT019.eop-EUR01.prod.protection.outlook.com (2a01:111:e400:7e1a::456) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16; Thu, 15 Apr 2021 02:04:25 +0000 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com (2a01:111:e400:7e1a::42) by DB5EUR01FT021.mail.protection.outlook.com (2a01:111:e400:7e1a::245) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Thu, 15 Apr 2021 02:04:25 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:B41451E83283408E1BE128888DE403A8813E458680A62C3865E8FB26DECD5B05; UpperCasedChecksum:0EF601DCA0ABCB7C45D863BEADC482BF30540DE311FD997C3DC4B7606949FF65; SizeAsReceived:7580; Count:48 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::45bb:c44f:2b75:23b7]) by HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::45bb:c44f:2b75:23b7%5]) with mapi id 15.20.4042.018; Thu, 15 Apr 2021 02:04:25 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 15 Apr 2021 04:04:11 +0200 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-TMN: [aqxeKL9W9vXFqsErouacEn/T/DaVpzmO] X-ClientProxiedBy: AM9P192CA0002.EURP192.PROD.OUTLOOK.COM (2603:10a6:20b:21d::7) To HE1PR0301MB2154.eurprd03.prod.outlook.com (2603:10a6:3:2a::22) X-Microsoft-Original-Message-ID: <20210415020411.1411024-3-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.137.96) by AM9P192CA0002.EURP192.PROD.OUTLOOK.COM (2603:10a6:20b:21d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Thu, 15 Apr 2021 02:04:24 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 48 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 5d850037-db95-4128-c371-08d8ffb2cb37 X-MS-Exchange-SLBlob-MailProps: q+fD6XS3/ULVtCBeMNItAFjvDQNF2Y82FiD6/S//8WZ4gydwW6tjbE1rrlELMQT2F22HESWNleDVgp6Wcb/pqfX74xTGIPCxWHhaWVLR86nNs8zbGSRm4Zutbs++pkZruYOwv/HbN2mUwINUIanlF3nYA8Ne9Jgszg8LLa2R//kSntNx/jtqBSlNPV4zPlrPazoXNQAVqkSlUQLBAkduH//Xys/gvmRtk4ty7SnnqQGMJlyi+hTWKioXJmcc6sr/U4iVdqJpGaeHWkxzwOAxa/rQSgfXg4fz4+EicRxefQA+sgSpIKL3q4EJHy2P2T8tIUDIGHxINEtm9X+jmsPPTvr0mRLMroTYi5Y+Gx5G9YTtluuucCCaSKLOmxho/7YfLBcF5ITabVD3IH6TwQHvN4SK5VmA+bwqV0na+DE5zmr2zMMW8VwK6QVDbFN785McWwiUrcp6DdIPkMO+sSSmO7wNxFeAos3IP3RY6YwhOh0jmeedycDR+JFMXgqPt/LIwKIobg/RikcsxyErGpJL6OgLmnaVXRzl3HtN4sgSQmdSqe/fxuNxT5NHIRkl9vZeIIXI/jZanO2omnhDIypwZ2e8WgnCYtYRZiBpoa27iZhGd8cV3LgPUno59hKWrXMTvSUDerjvJB3Wr04NXaSX838+Zq7YX0xOSj0a5x1R7QT/fX0cfGbbzaExRFFpdUrTz8S/WvkUxR5E/NqL3Otanw== X-MS-TrafficTypeDiagnostic: DB5EUR01HT019: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TTpU90GMwzrww2TLKoHOxCB7KxzxAE+2830ItcRCt9fHPgdlpQOfid81F31peezg7x+/Whaju6MK8NxQT5TblloT1Wr0cKsW03YEbbogLfliDq1Bho1ciVSJXv5NXJF6NQLoPydLJI+xhwsxBc4hQtVheN915thGWC4ey1k241qSeD8hdpetiF1HGLIs1O9xfKcw5huMK8AqY+3hoSyKk9EDYAzF0yVQ2SwlotuP0L8ZbzlnMPT14AqKFXFwEtJkx8kStbR+PLT2JPooBL2Au0uL+UIXOsugF0H28xNarD3YaOc3HjYmI9uE9b7hPJUUbSw87QvCu+8oEiBr8IhsCM2qVR2vazSRxQz7ArMS6HyBN9EqPSaDybBjWR+Zp0VLakmrWDZecLKDd3bYTUufiA== X-MS-Exchange-AntiSpam-MessageData: hbh1OnD7ZWrafwN3XdStePc6kTfhITWWQI2xSpyLgxhy+piviFzLhHfokafsQ2zr6TaH08rhmWgdLe8coiSLKbVN/zF5Ap1kJOGfjbmu0zAUeDmXfz53wm3hnV5Vata3LEz1w6sVDTLm9MK8z3AShA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5d850037-db95-4128-c371-08d8ffb2cb37 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2021 02:04:25.3395 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: DB5EUR01FT021.eop-EUR01.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5EUR01HT019 Subject: [FFmpeg-devel] [PATCH 5/5] avcodec/vorbis_parser: Improve returned error codes X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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" av_vorbis_parse_init() doesn't return an error code which is a slight problem in libvorbisenc.c. Fix this by making the internal initialization function behind av_vorbis_parse_init() available. This also avoids allocations and frees (for users inside of this inside libavcodec). Signed-off-by: Andreas Rheinhardt --- libavcodec/libvorbisenc.c | 12 +++++------- libavcodec/vorbis_parser.c | 29 +++++++++-------------------- libavcodec/vorbis_parser_internal.h | 3 +++ 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/libavcodec/libvorbisenc.c b/libavcodec/libvorbisenc.c index 061a4e9da7..b111379e10 100644 --- a/libavcodec/libvorbisenc.c +++ b/libavcodec/libvorbisenc.c @@ -28,6 +28,7 @@ #include "internal.h" #include "vorbis.h" #include "vorbis_parser.h" +#include "vorbis_parser_internal.h" /* Number of samples the user should send in each call. @@ -48,7 +49,7 @@ typedef struct LibvorbisEncContext { int eof; /**< end-of-file flag */ int dsp_initialized; /**< vd has been initialized */ double iblock; /**< impulse block bias option */ - AVVorbisParseContext *vp; /**< parse context to get durations */ + AVVorbisParseContext vp; /**< parse context to get durations */ AudioFrameQueue afq; /**< frame queue for timestamps */ } LibvorbisEncContext; @@ -196,8 +197,6 @@ static av_cold int libvorbis_encode_close(AVCodecContext *avctx) av_fifo_freep(&s->pkt_fifo); ff_af_queue_close(&s->afq); - av_vorbis_parse_free(&s->vp); - return 0; } @@ -260,10 +259,9 @@ static av_cold int libvorbis_encode_init(AVCodecContext *avctx) offset += header_code.bytes; av_assert0(offset == avctx->extradata_size); - s->vp = av_vorbis_parse_init(avctx->extradata, avctx->extradata_size); - if (!s->vp) { + ret = ff_vorbis_parse_init(&s->vp, avctx->extradata, avctx->extradata_size); + if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "invalid extradata\n"); - ret = AVERROR_UNKNOWN; goto error; } @@ -355,7 +353,7 @@ static int libvorbis_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, avpkt->pts = ff_samples_to_time_base(avctx, op.granulepos); - duration = av_vorbis_parse_frame(s->vp, avpkt->data, avpkt->size); + duration = av_vorbis_parse_frame(&s->vp, avpkt->data, avpkt->size); if (duration > 0) { /* we do not know encoder delay until we get the first packet from * libvorbis, so we have to update the AudioFrameQueue counts */ diff --git a/libavcodec/vorbis_parser.c b/libavcodec/vorbis_parser.c index 0b2c97cde5..0d87102adc 100644 --- a/libavcodec/vorbis_parser.c +++ b/libavcodec/vorbis_parser.c @@ -181,8 +181,8 @@ bad_header: return ret; } -static int vorbis_parse_init(AVVorbisParseContext *s, - const uint8_t *extradata, int extradata_size) +int ff_vorbis_parse_init(AVVorbisParseContext *s, + const uint8_t *extradata, int extradata_size) { const uint8_t *header_start[3]; int header_len[3]; @@ -287,7 +287,7 @@ AVVorbisParseContext *av_vorbis_parse_init(const uint8_t *extradata, if (!s) return NULL; - ret = vorbis_parse_init(s, extradata, extradata_size); + ret = ff_vorbis_parse_init(s, extradata, extradata_size); if (ret < 0) { av_vorbis_parse_free(&s); return NULL; @@ -298,24 +298,20 @@ AVVorbisParseContext *av_vorbis_parse_init(const uint8_t *extradata, #if CONFIG_VORBIS_PARSER -typedef struct VorbisParseContext { - AVVorbisParseContext *vp; -} VorbisParseContext; - static int vorbis_parse(AVCodecParserContext *s1, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size) { - VorbisParseContext *s = s1->priv_data; + AVVorbisParseContext *s = s1->priv_data; int duration; - if (!s->vp && avctx->extradata && avctx->extradata_size) { - s->vp = av_vorbis_parse_init(avctx->extradata, avctx->extradata_size); + if (!s->valid_extradata && avctx->extradata && avctx->extradata_size) { + ff_vorbis_parse_init(s, avctx->extradata, avctx->extradata_size); } - if (!s->vp) + if (!s->valid_extradata) goto end; - if ((duration = av_vorbis_parse_frame(s->vp, buf, buf_size)) >= 0) + if ((duration = av_vorbis_parse_frame(s, buf, buf_size)) >= 0) s1->duration = duration; end: @@ -326,16 +322,9 @@ end: return buf_size; } -static void vorbis_parser_close(AVCodecParserContext *ctx) -{ - VorbisParseContext *s = ctx->priv_data; - av_vorbis_parse_free(&s->vp); -} - AVCodecParser ff_vorbis_parser = { .codec_ids = { AV_CODEC_ID_VORBIS }, - .priv_data_size = sizeof(VorbisParseContext), + .priv_data_size = sizeof(AVVorbisParseContext), .parser_parse = vorbis_parse, - .parser_close = vorbis_parser_close, }; #endif /* CONFIG_VORBIS_PARSER */ diff --git a/libavcodec/vorbis_parser_internal.h b/libavcodec/vorbis_parser_internal.h index 691a842385..c0158a210c 100644 --- a/libavcodec/vorbis_parser_internal.h +++ b/libavcodec/vorbis_parser_internal.h @@ -43,4 +43,7 @@ struct AVVorbisParseContext { int prev_mask; ///< bitmask used to get the previous mode flag in each packet }; +int ff_vorbis_parse_init(AVVorbisParseContext *s, + const uint8_t *extradata, int extradata_size); + #endif /* AVCODEC_VORBIS_PARSER_INTERNAL_H */