From patchwork Thu Apr 1 23:27:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26702 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 917E744B298 for ; Fri, 2 Apr 2021 02:28:53 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7DA9568A48F; Fri, 2 Apr 2021 02:28:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1306568A03E for ; Fri, 2 Apr 2021 02:28:47 +0300 (EEST) Received: by mail-qt1-f177.google.com with SMTP id g24so2739370qts.6 for ; Thu, 01 Apr 2021 16:28:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=TgIgLRx8hm1/+qaz2g8rG1ccAgBDgXHPcWWRtlAwZik=; b=YFMGTra6wFITFktLQ1+2TJyM/DyXoctEpORWds5ziZdpNqybtLNmjvM31pyqRCIXoP 3YZfMieICDqOgQpXe+02Bb9oNucTn+d0JrbCY6Qj1Rm58dudt5rsbj3TKekSK1HQEJFr Bh1ssn6ZUS5LMCSctbi+MkUSH6l/VlQCjKTbzps4RpOIElbEFrnu/qx9PBUINk7jsM1X gwc82sq2VwKO6EUf2JML7UC4crwO3InZ9y8A0tadSPyDlJbjD0sMT3lZQx0JwNR+QZce BgXpAcENTLMUhs7/MkmrkmXFm5p7/F2HwCRGu/1AOQ9YLtX0nb80U77nFXoEngP49Q0V Sl8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TgIgLRx8hm1/+qaz2g8rG1ccAgBDgXHPcWWRtlAwZik=; b=OdSOcARQsPG3qaeQ7FtAgLvcpMtkl5fhLiKIe4ZxlGwaKx/eUN5OpNulCrU7TFhGA6 HLo33h12thVnmPAXxhuNS8zlfK3ttRvLc01Uym+Lfnab8n+53/m/CAJwxvEk9i3HQ2De 5K0xAS1MjvJQ5xk+AUMk7LOcd9BMCKUjXzyEFS3mbWeiErDX+X09hWnqbTwk4Hm3t1eL Jn0d83+FAZjk0Q5Av0hqMUm1Vn44hkuRsu+sztiTh3LQagRr4bnAfk47WKtvrbA2GYVL SzcRkdiODeFEvr8LFERwWr5lNlaKD10NppJwpPZf+BZ+6mThAQ4wNJrt44runk6I3K9y EWHQ== X-Gm-Message-State: AOAM532N/Pn0v88trA2+x31WzwkQcpoRqiNW1G1CE/BZfpyAil/m1LaA NkXTuhFDdAFJ0YKfvI40HbTnV7qbBJ0= X-Google-Smtp-Source: ABdhPJyRfvFD+3MOsFnlSArC4yRVj14zhT+5NJS/iBF0/8gWskrI17nWgSuKltyna/yhs9TtuZ2vjA== X-Received: by 2002:ac8:6789:: with SMTP id b9mr9250573qtp.103.1617319725325; Thu, 01 Apr 2021 16:28:45 -0700 (PDT) Received: from localhost.localdomain ([191.83.218.26]) by smtp.gmail.com with ESMTPSA id v6sm5108392qkf.132.2021.04.01.16.28.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Apr 2021 16:28:45 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 1 Apr 2021 20:27:38 -0300 Message-Id: <20210401232738.4908-3-jamrial@gmail.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210401232738.4908-1-jamrial@gmail.com> References: <20210401232738.4908-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3 v2] avformat: add apic to AVStream 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: James Almer --- Now allocated only on attached_pic disposition streams. Added muxer usage doxy for the new field as well since Andreas has a patchset meant for this purpose. But i can make it say unused instead and let the aforementioned patchset change it as its own API change. Still using apic since i want other people's opinion on what the name should be, since Lynne didn't like it. Another option is simply picture. I don't want it to be too long. libavformat/avformat.h | 24 ++++++++++++++++++------ libavformat/hls.c | 6 +++--- libavformat/id3v2.c | 2 +- libavformat/mov.c | 4 ++-- libavformat/utils.c | 27 ++++++++++++++++++++++----- libavformat/version.h | 3 +++ 6 files changed, 49 insertions(+), 17 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 11e993eacb..6a9b09160c 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -838,7 +838,7 @@ typedef struct AVIndexEntry { * APIC frame in ID3v2). The first (usually only) packet associated with it * will be returned among the first few packets read from the file unless * seeking takes place. It can also be accessed at any time in - * AVStream.attached_pic. + * AVStream.apic. */ #define AV_DISPOSITION_ATTACHED_PIC 0x0400 /** @@ -947,14 +947,19 @@ typedef struct AVStream { */ AVRational avg_frame_rate; +#if FF_API_ATTACHED_PIC /** * For streams with AV_DISPOSITION_ATTACHED_PIC disposition, this packet * will contain the attached picture. * * decoding: set by libavformat, must not be modified by the caller. * encoding: unused + * + * @deprecated Use apic instead. */ + attribute_deprecated AVPacket attached_pic; +#endif /** * An array of side data that applies to the whole stream (i.e. the @@ -1039,6 +1044,18 @@ typedef struct AVStream { */ AVCodecParameters *codecpar; + /** + * Packet containing the attached picture. Used on streams with + * AV_DISPOSITION_ATTACHED_PIC disposition. + * + * - demuxing: Allocated and filled by libavformat on stream creation. Must + * not be modified by the caller. Freed by libavformat in + * avformat_free_context() + * - muxing: Allocated and filled by the caller before avformat_write_header() + * Freed by libavformat in avformat_free_context() + */ + AVPacket *apic; + /***************************************************************** * All fields below this line are not part of the public API. They * may not be used outside of libavformat and can be changed and @@ -1049,11 +1066,6 @@ typedef struct AVStream { ***************************************************************** */ -#if LIBAVFORMAT_VERSION_MAJOR < 59 - // kept for ABI compatibility only, do not access in any way - void *unused; -#endif - int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */ // Timestamp generation support: diff --git a/libavformat/hls.c b/libavformat/hls.c index 90e2a2b43a..8ac094acbe 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -1068,15 +1068,15 @@ static int id3_has_changed_values(struct playlist *pls, AVDictionary *metadata, } /* check if apic appeared */ - if (apic && (pls->ctx->nb_streams != 2 || !pls->ctx->streams[1]->attached_pic.data)) + if (apic && (pls->ctx->nb_streams != 2 || !pls->ctx->streams[1]->apic)) return 1; if (apic) { - int size = pls->ctx->streams[1]->attached_pic.size; + int size = pls->ctx->streams[1]->apic->size; if (size != apic->buf->size - AV_INPUT_BUFFER_PADDING_SIZE) return 1; - if (memcmp(apic->buf->data, pls->ctx->streams[1]->attached_pic.data, size) != 0) + if (memcmp(apic->buf->data, pls->ctx->streams[1]->apic->data, size) != 0) return 1; } diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c index 863709abbf..49de81ba24 100644 --- a/libavformat/id3v2.c +++ b/libavformat/id3v2.c @@ -1154,7 +1154,7 @@ int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta *extra_meta) st = s->streams[s->nb_streams - 1]; st->codecpar->codec_id = apic->id; - if (AV_RB64(st->attached_pic.data) == PNGSIG) + if (AV_RB64(st->apic->data) == PNGSIG) st->codecpar->codec_id = AV_CODEC_ID_PNG; if (apic->description[0]) diff --git a/libavformat/mov.c b/libavformat/mov.c index 08dcb10df4..e9e9a674b7 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -210,8 +210,8 @@ static int mov_read_covr(MOVContext *c, AVIOContext *pb, int type, int len) st = c->fc->streams[c->fc->nb_streams - 1]; st->priv_data = sc; - if (st->attached_pic.size >= 8 && id != AV_CODEC_ID_BMP) { - if (AV_RB64(st->attached_pic.data) == 0x89504e470d0a1a0a) { + if (st->apic->size >= 8 && id != AV_CODEC_ID_BMP) { + if (AV_RB64(st->apic->data) == 0x89504e470d0a1a0a) { id = AV_CODEC_ID_PNG; } else { id = AV_CODEC_ID_MJPEG; diff --git a/libavformat/utils.c b/libavformat/utils.c index 3624678193..580f67c39d 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -457,7 +457,7 @@ int avformat_queue_attached_pictures(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) if (s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC && s->streams[i]->discard < AVDISCARD_ALL) { - if (s->streams[i]->attached_pic.size <= 0) { + if (s->streams[i]->apic->size <= 0) { av_log(s, AV_LOG_WARNING, "Attached picture on stream %d has invalid size, " "ignoring\n", i); @@ -466,7 +466,7 @@ int avformat_queue_attached_pictures(AVFormatContext *s) ret = avpriv_packet_list_put(&s->internal->raw_packet_buffer, &s->internal->raw_packet_buffer_end, - &s->streams[i]->attached_pic, + s->streams[i]->apic, av_packet_ref, 0); if (ret < 0) return ret; @@ -478,12 +478,13 @@ int ff_add_attached_pic(AVFormatContext *s, AVStream *st0, AVIOContext *pb, AVBufferRef **buf, int size) { AVStream *st = st0; - AVPacket *pkt; + AVPacket *pkt = av_packet_alloc(); int ret; - if (!st && !(st = avformat_new_stream(s, NULL))) + if (!pkt || (!st && !(st = avformat_new_stream(s, NULL)))) { + av_packet_free(&pkt); return AVERROR(ENOMEM); - pkt = &st->attached_pic; + } if (buf) { av_assert1(*buf); av_packet_unref(pkt); @@ -502,10 +503,20 @@ int ff_add_attached_pic(AVFormatContext *s, AVStream *st0, AVIOContext *pb, pkt->stream_index = st->index; pkt->flags |= AV_PKT_FLAG_KEY; +#if FF_API_ATTACHED_PIC +FF_DISABLE_DEPRECATION_WARNINGS + if (av_packet_ref(&st->attached_pic, pkt) < 0) + goto fail; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + av_assert0(!st0 || !st0->apic); + st->apic = pkt; + return 0; fail: if (!st0) ff_free_stream(s, st); + av_packet_free(&pkt); return ret; } @@ -4408,8 +4419,14 @@ static void free_stream(AVStream **pst) if (st->parser) av_parser_close(st->parser); +#if FF_API_ATTACHED_PIC +FF_DISABLE_DEPRECATION_WARNINGS if (st->attached_pic.data) av_packet_unref(&st->attached_pic); +FF_ENABLE_DEPRECATION_WARNINGS +#endif + + av_packet_free(&st->apic); if (st->internal) { avcodec_free_context(&st->internal->avctx); diff --git a/libavformat/version.h b/libavformat/version.h index ced5600034..dce936794a 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -115,6 +115,9 @@ #ifndef FF_API_LAVF_PRIV_OPT #define FF_API_LAVF_PRIV_OPT (LIBAVFORMAT_VERSION_MAJOR < 60) #endif +#ifndef FF_API_ATTACHED_PIC +#define FF_API_ATTACHED_PIC (LIBAVFORMAT_VERSION_MAJOR < 60) +#endif #ifndef FF_API_R_FRAME_RATE