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 EB394472F8 for ; Mon, 4 Sep 2023 22:09:07 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4655C68C7BB; Tue, 5 Sep 2023 01:09:04 +0300 (EEST) Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 748E268C464 for ; Tue, 5 Sep 2023 01:08:58 +0300 (EEST) Received: by mail-ot1-f48.google.com with SMTP id 46e09a7af769-6bc9811558cso1571321a34.0 for ; Mon, 04 Sep 2023 15:08:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693865336; x=1694470136; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=/H+bLTteE6jvSH6H1+0wp5IEoQMj43FD31STL/TLRl0=; b=rFR17DR1dk0Pf2jWNbYe/NYNqcOgPGhmC5kilXdJBBxiqBvN6DmEUv4CVPE2levlXS waqBsSLYIjsjyOvIBa5rSaq6qp/rYZY4z2FPhtDs5c+e7gh6RHoYSyUCWbi87cJCOAlu AYHqZrEI7dYmpHJGjUOzJUvMMWb0MbWSkmfFpxiG3dLJZr/aOfvlajPU/M43OkKdzh/n F3kPWkZDBwVwpb/MTeBivhzzD/bFHp4D2+uzl4xjHhOdndoUwK3z/W5tewB6U70iPN1+ wqi6El3UEnetYmyiKafPRYsmqCRq8kGyXqBIdjYiQc6D2pZ4AXfAdtKEAqwSFOdPNHQ5 Pljg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693865336; x=1694470136; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/H+bLTteE6jvSH6H1+0wp5IEoQMj43FD31STL/TLRl0=; b=mDFygSqLvC/5bofYnpRkdQE9cYDj+74AanoQSBa1+gMRKU7/nBrBZ5KJJYrbdY/wmY Ck7h5vc4iW/iiHFEbRaBO5BzI3tRYFEXbiNO07kHry97awdIQ6V7MIZ1DXuZBY70aXPo 3dPzqqestDvWARIoPuIexKcHlsO8jalAAJPGqgj77jTTXLOcF/aDmE1h57vOsv0LqgdO GxnlYIMf1c33YOaZM00LzFT9Yb21vYZej1RTKC8fmMxDDuJLY5xuSI8VDTkwAyazYhxp yrRnPfh9ohDXM4DQrmtAvGByBZIqun2/vaVVfz4JSZTo+lkGWlojGj3Me9pKterZW7MS do/w== X-Gm-Message-State: AOJu0YwJJgje/pZ6So6hqMzPYg6CONR8HpPLe3AsSnorxx6wyQ3O+r8V gkP55X+zv4TGFeWOwzi15Ytl1RMxzB4= X-Google-Smtp-Source: AGHT+IFw2Q1Qc4L1v4myYq+LjMGi1KyI8g8Kf8symGwxmTCax+9MtQ8cDFQV/spzTZYTIzhyXFxdGA== X-Received: by 2002:a9d:6d98:0:b0:6bd:c3f3:723a with SMTP id x24-20020a9d6d98000000b006bdc3f3723amr12193718otp.9.1693865336148; Mon, 04 Sep 2023 15:08:56 -0700 (PDT) Received: from localhost.localdomain (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id v24-20020a9d69d8000000b006b954f7f422sm4967590oto.6.2023.09.04.15.08.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Sep 2023 15:08:55 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 Sep 2023 19:08:48 -0300 Message-ID: <20230904220848.21900-1-jamrial@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230904150411.56777-2-jamrial@gmail.com> References: <20230904150411.56777-2-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/17] avcodec/avcodec: add side data to AVCodecContext 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: This will allow the propagation of global side data within the AVCodecContext instead of having to do it inside packets, and thus be available during init(). Global and frame specific side data will therefore be distinct. Signed-off-by: James Almer --- libavcodec/avcodec.c | 2 + libavcodec/avcodec.h | 8 ++++ libavcodec/avpacket.c | 99 +++++++++++++++++++++++++++++++++++++++++++ libavcodec/packet.h | 68 +++++++++++++++++++++++++++++ 4 files changed, 177 insertions(+) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index 131834b6de..7e1ef99234 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -475,6 +475,8 @@ av_cold int avcodec_close(AVCodecContext *avctx) av_freep(&avctx->internal); } + av_packet_side_data_set_free(&avctx->packet_side_data); + for (i = 0; i < avctx->nb_coded_side_data; i++) av_freep(&avctx->coded_side_data[i].data); av_freep(&avctx->coded_side_data); diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 649411ac79..dda8a2412b 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2100,6 +2100,14 @@ typedef struct AVCodecContext { * an error. */ int64_t frame_num; + + /** + * Additional data associated with the entire stream. + * + * - decoding: set by user + * - encoding: unused + */ + AVPacketSideDataSet packet_side_data; } AVCodecContext; /** diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c index 5fef65e97a..5b133c5d8a 100644 --- a/libavcodec/avpacket.c +++ b/libavcodec/avpacket.c @@ -645,3 +645,102 @@ int ff_side_data_set_prft(AVPacket *pkt, int64_t timestamp) return 0; } + +AVPacketSideData *av_packet_side_data_set_get(const AVPacketSideDataSet *set, + enum AVPacketSideDataType type) +{ + for (int i = 0; i < set->nb_sd; i++) + if (set->sd[i]->type == type) + return set->sd[i]; + + return NULL; +} + +static AVPacketSideData *add_side_data_to_set(AVPacketSideDataSet *set, + enum AVPacketSideDataType type, + uint8_t *data, size_t size) +{ + AVPacketSideData *sd, **tmp; + + for (int i = 0; i < set->nb_sd; i++) { + sd = set->sd[i]; + if (sd->type != type) + continue; + + av_freep(&sd->data); + sd->data = data; + sd->size = size; + return sd; + } + + if (set->nb_sd + 1U > INT_MAX) + return NULL; + + tmp = av_realloc_array(set->sd, set->nb_sd + 1, sizeof(*tmp)); + if (!tmp) + return NULL; + + set->sd = tmp; + + sd = av_mallocz(sizeof(*sd)); + if (!sd) + return NULL; + + sd->type = type; + sd->data = data; + sd->size = size; + + set->sd[set->nb_sd++] = sd; + + return sd; +} + +AVPacketSideData *av_packet_side_data_set_add(AVPacketSideDataSet *set, + enum AVPacketSideDataType type, + uint8_t *data, size_t size, + int flags) +{ + return add_side_data_to_set(set, type, data, size); +} + +AVPacketSideData *av_packet_side_data_set_new(AVPacketSideDataSet *set, + enum AVPacketSideDataType type, + size_t size, int flags) +{ + AVPacketSideData *sd = NULL; + uint8_t *data = av_malloc(size); + + if (!data) + return NULL; + + sd = add_side_data_to_set(set, type, data, size); + if (!sd) + av_freep(&data); + + return sd; +} + +void av_packet_side_data_set_remove(AVPacketSideDataSet *set, + enum AVPacketSideDataType type) +{ + for (int i = set->nb_sd - 1; i >= 0; i--) { + AVPacketSideData *sd = set->sd[i]; + if (sd->type != type) + continue; + av_free(set->sd[i]->data); + av_free(set->sd[i]); + set->sd[i] = set->sd[--set->nb_sd]; + break; + } +} + +void av_packet_side_data_set_free(AVPacketSideDataSet *set) +{ + for (int i = 0; i < set->nb_sd; i++) { + av_free(set->sd[i]->data); + av_free(set->sd[i]); + } + set->nb_sd = 0; + + av_freep(&set->sd); +} diff --git a/libavcodec/packet.h b/libavcodec/packet.h index f28e7e7011..63b402d7ea 100644 --- a/libavcodec/packet.h +++ b/libavcodec/packet.h @@ -318,6 +318,14 @@ typedef struct AVPacketSideData { enum AVPacketSideDataType type; } AVPacketSideData; +/** + * Structure to hold a set of AVPacketSideDataSet + */ +typedef struct AVPacketSideDataSet { + AVPacketSideData **sd; + int nb_sd; +} AVPacketSideDataSet; + /** * This structure stores compressed data. It is typically exported by demuxers * and then passed as input to decoders, or received as output from encoders and @@ -724,6 +732,66 @@ int av_packet_make_writable(AVPacket *pkt); */ void av_packet_rescale_ts(AVPacket *pkt, AVRational tb_src, AVRational tb_dst); +/** + * Allocate a new side data entry into to a set. + * + * @param set a set to which the side data should be added + * @param type side data type + * @param size side data size + * @param flags currently unused + * @return pointer to freshly allocated side data entry on success, or NULL + * otherwise. + */ +AVPacketSideData *av_packet_side_data_set_new(AVPacketSideDataSet *set, + enum AVPacketSideDataType type, + size_t size, int flags); + +/** + * Wrap an existing array as a packet side data into a set. + * + * @param set a set to which the side data should be added + * @param type side data type + * @param data a data array. It must be allocated with the av_malloc() family + * of functions. The ownership of the data is transferred to the + * set on success + * @param size size of the data array + * @param flags currently unused + * @return pointer to freshly allocated side data entry on success, or NULL + * otherwise. On failure, the set is unchanged and the data remains + * owned by the caller. + */ +AVPacketSideData *av_packet_side_data_set_add(AVPacketSideDataSet *set, + enum AVPacketSideDataType type, + uint8_t *data, size_t size, + int flags); + +/** + * Remove side data of the given type from a set. + * + * @param set a set from which the side data should be removed + * @param type side information type + */ +void av_packet_side_data_set_remove(AVPacketSideDataSet *set, + enum AVPacketSideDataType type); + +/** + * Get side information from set. + * + * @param set a set from which the side data should be fetched + * @param type desired side information type + * + * @return pointer to side data if present or NULL otherwise + */ +AVPacketSideData *av_packet_side_data_set_get(const AVPacketSideDataSet *set, + enum AVPacketSideDataType type); + +/** + * Convenience function to free all the side data stored in a set. + * + * @param set the set to free + */ +void av_packet_side_data_set_free(AVPacketSideDataSet *set); + /** * @} */ -- 2.42.0 _______________________________________________ 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".