From patchwork Sat May 7 11:28:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 35656 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a885:b0:7f:4be2:bd17 with SMTP id ca5csp2122045pzb; Sat, 7 May 2022 04:32:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx99PFSbIJdIbB6sKGgdjElSEomFHBisjKASkJ/rRt1ArYLayk6LFB7b822YeIBictgRGSm X-Received: by 2002:a17:907:9694:b0:6f4:92a4:7484 with SMTP id hd20-20020a170907969400b006f492a47484mr6949421ejc.603.1651923146473; Sat, 07 May 2022 04:32:26 -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 w6-20020a50c446000000b00423f2d8e1a3si7363985edf.436.2022.05.07.04.32.26; Sat, 07 May 2022 04:32:26 -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=VnkktRG+; 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 C27A068B475; Sat, 7 May 2022 14:30:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-oln040092068058.outbound.protection.outlook.com [40.92.68.58]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CDEDF68B47C for ; Sat, 7 May 2022 14:30:00 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SD+aCUvouQRDoDWbq7vpR0ZArhaZz+bbLeO0LpFsJ/+IJjMBR1Z1xSVUuzOqm/z8QFMfbI/kNFf39jDxDCGFxwbu9j9OBwct1ukajG/zImbv73cygGE7O/uV6uH+xTYMhEV2OmTd+HRW/C9wzcl41yL8vs5xZN+LYvceprvu7vOtbV3h/R9i1fAHnKlEDt8C0am4CUPv+YmNxouyVEoBkX6P+H9gFWvTe/9LbYh/9yPPkqoNc3y/svC+ez2vmiyX+x9IOGlpvhQyLIQiLLAlet3VCxOQ1rpwx2YlUFOgmasGae4oc2bJQ1B/cLTFTxm/qlQ4ESG3nZSM13vyZcrU7A== 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=8NE/vxUr+9IEQUVzKumqTumCLeGt1/P9Z0YyfxNQ+54=; b=SGo/4Cmx0mH6Awm5q0FS67VxrKRzDUg+KJd4BoPktoFmtRpcagoKfG2sGFAMz01N6GOUeVIuOMwcyqze4fjyK9ZCHZ2ZDza2bG8GqTNqy0Z4qqKuUZjiXybvkx9Nlt/Mq85757tkfzRTpaIVj/XlVE49PK3bDuTzophWfoqvsFgC0/UzeEIolTFN2AuY9W2UJ9Ks+lyXu8zLAjMiutG/DySqH4gy0GQIOp7hM0GSeq2CuDeGMYmnsva5uGPNRbAF7uyLA1Nz8rpD3p+Vwm+7lNH9wJC7Y+XFt2JpErufTHxebwGsntPW/mYCL0DwB+PxhItFPSIbsr0O0kFYkywfzw== 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=8NE/vxUr+9IEQUVzKumqTumCLeGt1/P9Z0YyfxNQ+54=; b=VnkktRG+h/XccgY1Ty7RkLVOF5ZtjewC0LmFgFEq/98DloyekPq1TvHwAF+jW8DlqsTnG5UFzoRAQ8SUMUGVlfpZmqET6wVccgvGRxBvW0C2uxFoZmCV3Qa7xIQ4ZimvRt1WbmOcPHoT0d1qIvJ9DBED6sys5f+qNrF43AtGYgmCj79eYIvYfhPGaqAoJXe9f9Mz+oMfnjJIPQHGL4DYiq/xtc431k5s4T7vUvOY4HgKNZPiZiJpqpLn3ZSfAH2FcapG4WfpSO16WuAJq7fUXzL0A3nEteD/1UdAXPtrZoRhSXw3BU0FNATkk1cTPSyMxdbUM3dMc/8ly4Q+13rcQw== Received: from AS8PR01MB7944.eurprd01.prod.exchangelabs.com (2603:10a6:20b:373::5) by DB6PR01MB3895.eurprd01.prod.exchangelabs.com (2603:10a6:6:4b::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Sat, 7 May 2022 11:29:59 +0000 Received: from AS8PR01MB7944.eurprd01.prod.exchangelabs.com ([fe80::1854:2c30:7ba1:c431]) by AS8PR01MB7944.eurprd01.prod.exchangelabs.com ([fe80::1854:2c30:7ba1:c431%6]) with mapi id 15.20.5206.024; Sat, 7 May 2022 11:29:59 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 7 May 2022 13:28:08 +0200 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [4RzGNeSSc1iiXFCbnbcDHjg8qFHv+9gM] X-ClientProxiedBy: ZRAP278CA0004.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:10::14) To AS8PR01MB7944.eurprd01.prod.exchangelabs.com (2603:10a6:20b:373::5) X-Microsoft-Original-Message-ID: <20220507112830.406162-21-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ff1e0e9c-abc9-4919-f903-08da301ceb11 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiRIovyFjHwHllp74iOQFItwKYiNJ2RXwfk5TCAWbMgqfiHGcGgTSpqZ6eBiqceiFuMSWUhWtIjHTjJwlAKYRQ5JFU1ld0ebFfoQo+t0jcJZC7bnoj34vKovorlUuUMvz6grp0z37iIPZVYbdMnYb9JdNaTJlIIprNVF8MscNwEVe9g7dvBcX2Ppl/65yeoHC9J3lAv1BFYTxeLHsJGS2AwTK2Wpz4A6I+Bn2iUL/if7aakeaYh37BVJrBQcgvW8Dk/tWNWgjr43VvhBDDhRP6fTvP+csN/vYW9uIPmocfpnl1yYwam7Q0WDRLaTYS5hKgsyOqsBOMlkl+8QKTH7VZUpFyPXW9lNsUOmzk2ebf+LppgVtv1GPGtwsv4gIX5baBa65qCrgoT0HhPitZNY5SfXvu0y6cW5elGRu/U8Gv8E303IU1qlGI4N4knksqL93fWZRNuDxabyNnuJJyuqR20vXZ1jO50A7hhJDophzbwKBzDPsoXyINUgZCqFK3t4DukYuzHOeu+3AHrS6ai0gR0WYmStYpQ1j5KLkmxQqzr4d0jkfp64wexiRmfjd7anGnWFpd5nwU1aNHcZLCyTEp45QAsD4uDmUw/f8qd6usLcvFi44BdULfFxMRjO24QqkigiLrxtkkzGptKxOAQkzJRHTIyCHrFti1z0ksiC9ON8LmpAgb/DBpfI9M+V766Lfb5QjpXmebhYVfxP6XRdJpkQTLtvXH/QrYiDJqS1w3hDNmhIp8U/9m25MMzD3EMGHsE= X-MS-TrafficTypeDiagnostic: DB6PR01MB3895:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nlwu9nVamQ01E/My1IaQbaAU1oGT1u2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: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: ff1e0e9c-abc9-4919-f903-08da301ceb11 X-MS-Exchange-CrossTenant-AuthSource: AS8PR01MB7944.eurprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2022 11:29:59.0199 (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: DB6PR01MB3895 Subject: [FFmpeg-devel] [PATCH 22/44] avformat/utils: Move ff_add_attached_pic to demux_utils.c 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: 3J8Xj74rgJV0 It is demuxer-only: It potentially adds an AVStream and it sets AVStream.attached_pic. Signed-off-by: Andreas Rheinhardt --- libavformat/apetag.c | 1 + libavformat/asf.c | 1 + libavformat/demux.h | 16 ++++++++++++++++ libavformat/demux_utils.c | 36 ++++++++++++++++++++++++++++++++++++ libavformat/flac_picture.c | 1 + libavformat/internal.h | 16 ---------------- libavformat/utils.c | 35 ----------------------------------- 7 files changed, 55 insertions(+), 51 deletions(-) diff --git a/libavformat/apetag.c b/libavformat/apetag.c index cc6becc182..e861aac0f8 100644 --- a/libavformat/apetag.c +++ b/libavformat/apetag.c @@ -26,6 +26,7 @@ #include "avformat.h" #include "avio_internal.h" #include "apetag.h" +#include "demux.h" #include "internal.h" #include "mux.h" diff --git a/libavformat/asf.c b/libavformat/asf.c index 1ac8b5f078..6e3854eceb 100644 --- a/libavformat/asf.c +++ b/libavformat/asf.c @@ -19,6 +19,7 @@ */ #include "asf.h" +#include "demux.h" #include "id3v2.h" #include "internal.h" diff --git a/libavformat/demux.h b/libavformat/demux.h index d857e4dafb..546569ae6a 100644 --- a/libavformat/demux.h +++ b/libavformat/demux.h @@ -187,4 +187,20 @@ void avpriv_stream_set_need_parsing(AVStream *st, enum AVStreamParseType type); AVChapter *avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_base, int64_t start, int64_t end, const char *title); +/** + * Add an attached pic to an AVStream. + * + * @param st if set, the stream to add the attached pic to; + * if unset, a new stream will be added to s. + * @param pb AVIOContext to read data from if buf is unset. + * @param buf if set, it contains the data and size information to be used + * for the attached pic; if unset, data is read from pb. + * @param size the size of the data to read if buf is unset. + * + * @return 0 on success, < 0 on error. On error, this function removes + * the stream it has added (if any). + */ +int ff_add_attached_pic(AVFormatContext *s, AVStream *st, AVIOContext *pb, + AVBufferRef **buf, int size); + #endif /* AVFORMAT_DEMUX_H */ diff --git a/libavformat/demux_utils.c b/libavformat/demux_utils.c index ca5750d1ef..1fd634d1a2 100644 --- a/libavformat/demux_utils.c +++ b/libavformat/demux_utils.c @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/avassert.h" #include "libavcodec/packet_internal.h" #include "avformat.h" #include "demux.h" @@ -107,3 +108,38 @@ int avformat_queue_attached_pictures(AVFormatContext *s) } return 0; } + +int ff_add_attached_pic(AVFormatContext *s, AVStream *st0, AVIOContext *pb, + AVBufferRef **buf, int size) +{ + AVStream *st = st0; + AVPacket *pkt; + int ret; + + if (!st && !(st = avformat_new_stream(s, NULL))) + return AVERROR(ENOMEM); + pkt = &st->attached_pic; + if (buf) { + av_assert1(*buf); + av_packet_unref(pkt); + pkt->buf = *buf; + pkt->data = (*buf)->data; + pkt->size = (*buf)->size - AV_INPUT_BUFFER_PADDING_SIZE; + *buf = NULL; + } else { + ret = av_get_packet(pb, pkt, size); + if (ret < 0) + goto fail; + } + st->disposition |= AV_DISPOSITION_ATTACHED_PIC; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + + pkt->stream_index = st->index; + pkt->flags |= AV_PKT_FLAG_KEY; + + return 0; +fail: + if (!st0) + ff_remove_stream(s, st); + return ret; +} diff --git a/libavformat/flac_picture.c b/libavformat/flac_picture.c index 0effbf04f6..b33fee75b4 100644 --- a/libavformat/flac_picture.c +++ b/libavformat/flac_picture.c @@ -23,6 +23,7 @@ #include "libavcodec/bytestream.h" #include "libavcodec/png.h" #include "avformat.h" +#include "demux.h" #include "flac_picture.h" #include "id3v2.h" #include "internal.h" diff --git a/libavformat/internal.h b/libavformat/internal.h index 1a51c0dc97..4d80501eac 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -598,22 +598,6 @@ int ff_add_param_change(AVPacket *pkt, int32_t channels, */ int ff_framehash_write_header(AVFormatContext *s); -/** - * Add an attached pic to an AVStream. - * - * @param st if set, the stream to add the attached pic to; - * if unset, a new stream will be added to s. - * @param pb AVIOContext to read data from if buf is unset. - * @param buf if set, it contains the data and size information to be used - * for the attached pic; if unset, data is read from pb. - * @param size the size of the data to read if buf is unset. - * - * @return 0 on success, < 0 on error. On error, this function removes - * the stream it has added (if any). - */ -int ff_add_attached_pic(AVFormatContext *s, AVStream *st, AVIOContext *pb, - AVBufferRef **buf, int size); - /** * Frees a stream without modifying the corresponding AVFormatContext. * Must only be called if the latter doesn't matter or if the stream diff --git a/libavformat/utils.c b/libavformat/utils.c index 492fca000a..9e2e3335ac 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -175,41 +175,6 @@ int av_filename_number_test(const char *filename) (av_get_frame_filename(buf, sizeof(buf), filename, 1) >= 0); } -int ff_add_attached_pic(AVFormatContext *s, AVStream *st0, AVIOContext *pb, - AVBufferRef **buf, int size) -{ - AVStream *st = st0; - AVPacket *pkt; - int ret; - - if (!st && !(st = avformat_new_stream(s, NULL))) - return AVERROR(ENOMEM); - pkt = &st->attached_pic; - if (buf) { - av_assert1(*buf); - av_packet_unref(pkt); - pkt->buf = *buf; - pkt->data = (*buf)->data; - pkt->size = (*buf)->size - AV_INPUT_BUFFER_PADDING_SIZE; - *buf = NULL; - } else { - ret = av_get_packet(pb, pkt, size); - if (ret < 0) - goto fail; - } - st->disposition |= AV_DISPOSITION_ATTACHED_PIC; - st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; - - pkt->stream_index = st->index; - pkt->flags |= AV_PKT_FLAG_KEY; - - return 0; -fail: - if (!st0) - ff_remove_stream(s, st); - return ret; -} - /**********************************************************/ int ff_is_intra_only(enum AVCodecID id)