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 7CF68472C7 for ; Mon, 4 Sep 2023 15:04:39 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1569368C2DC; Mon, 4 Sep 2023 18:04:30 +0300 (EEST) Received: from mail-oi1-f173.google.com (mail-oi1-f173.google.com [209.85.167.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E470B68C6CB for ; Mon, 4 Sep 2023 18:04:21 +0300 (EEST) Received: by mail-oi1-f173.google.com with SMTP id 5614622812f47-3a9b41ffe11so1086945b6e.2 for ; Mon, 04 Sep 2023 08:04:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693839860; x=1694444660; 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=BL2uyZC51rv+9vhvIC8PAqLd/JH9UU8Vphj7MqGNoTo=; b=fSeWNUAJ9QJRhaIO2hz/++BTnwfmRFgIgsgePnv1eyv6xWFsT+gS2JwVCFCQcSfe4K /usT8eO37p4co/rjAbU3uVAt+1t7mrKDWKmTSs+TCEqn5MdnyYeyolFFJGeCo6E+cRuH gZYArLvX7oTXtQKW1zf6EPyTp9ih7ejuJgiCkG3EsltGk2Z5c1MiE4qWRTO7RgBwSGFA lhN0ovx3eZOkjH0iB7YugjVEsEZLhwYHrvH5SHx9qUEDFg7drc3UAGNP5k1YErkHnV87 1YmFAq2v4VfCwsfoiwe5PApBjDCWz+H1kh8EqAOrYwTbIE/UTrLZVzIeq8OrKu1cuuuf pbMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693839860; x=1694444660; 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=BL2uyZC51rv+9vhvIC8PAqLd/JH9UU8Vphj7MqGNoTo=; b=f/axbqx6JPzxCn55NYOzZvSw4U3mgDlzisStXpI1XocOd8y/ZRDVsUh4YabjqcuyIF za6RA/IF+uHEMHiYefXu7CTmY/N5ZQ9xctLaqIsOr4LW89W96hGPBZhAtsZ5NG6Dbi+H Ln8LZIqosjCNHq8bDbYhE+LroLzGLS8ff3GPIKS8sPgs69EIUjuLStTP52pMNvuzr04Y RyL6tiFUn5Ftf4GIUFrGjfgCeYx7dcFPTRD4cLnwPvGUAhV+e/1pswkAlU9WLx1Jp3lc n2yDv7N5uFC2F2I+CfhqHJyurnAUWQV8vA04jUnEulQcYN22rm+EkscYosLEWisJ/H/S ICKg== X-Gm-Message-State: AOJu0YwX8gpxNYaTHyrLZe39VOghOfvUljJs3QSVgWYa+QSc5o4cKVG5 awXWdL0nb+FzCK8JJDUHZlxXOjhOjVc= X-Google-Smtp-Source: AGHT+IEmrFb7QAvuWPceGNZIAbttP7etWrEq6iPSNkyQT0ObV2uQtFLb2Z2TyTPYrnszdJbMc8vOIA== X-Received: by 2002:a05:6808:bc2:b0:3a4:1c16:b1bc with SMTP id o2-20020a0568080bc200b003a41c16b1bcmr13628789oik.12.1693839859882; Mon, 04 Sep 2023 08:04:19 -0700 (PDT) Received: from localhost.localdomain (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id z14-20020a54458e000000b003a9cd23980esm4946286oib.8.2023.09.04.08.04.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Sep 2023 08:04:19 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 Sep 2023 12:03:54 -0300 Message-ID: <20230904150411.56777-2-jamrial@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230904150411.56777-1-jamrial@gmail.com> References: <20230904150411.56777-1-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: 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".