From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 01/17] avcodec/avcodec: add side data to AVCodecContext
Date: Mon, 4 Sep 2023 12:03:54 -0300
Message-ID: <20230904150411.56777-2-jamrial@gmail.com> (raw)
In-Reply-To: <20230904150411.56777-1-jamrial@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
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".
next prev parent reply other threads:[~2023-09-04 15:04 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-04 15:03 [FFmpeg-devel] [PATCH 00/17 v3] AVCodecContext and AVCodecParameters side data James Almer
2023-09-04 15:03 ` James Almer [this message]
2023-09-04 22:08 ` [FFmpeg-devel] [PATCH 01/17] avcodec/avcodec: add side data to AVCodecContext James Almer
2023-09-05 11:07 ` Anton Khirnov
2023-09-05 11:26 ` James Almer
2023-09-05 11:37 ` Anton Khirnov
2023-09-05 11:52 ` James Almer
2023-09-04 15:03 ` [FFmpeg-devel] [PATCH 02/17] avcodec/codec_par: add side data to AVCodecParameters James Almer
2023-09-04 15:03 ` [FFmpeg-devel] [PATCH 03/17] avformat/avformat: use the side data from AVStream.codecpar James Almer
2023-09-04 22:09 ` James Almer
2023-09-04 15:03 ` [FFmpeg-devel] [PATCH 04/17] fftools/ffmpeg: stop using AVStream.side_data James Almer
2023-09-04 15:03 ` [FFmpeg-devel] [PATCH 05/17] fftools/ffplay: " James Almer
2023-09-04 15:03 ` [FFmpeg-devel] [PATCH 06/17] fftools/ffprobe: " James Almer
2023-09-04 15:04 ` [FFmpeg-devel] [PATCH 07/17] avcodec/hevcdec: check for DOVI configuration record in AVCodecContext side data James Almer
2023-09-04 15:04 ` [FFmpeg-devel] [PATCH 08/17] avcodec/decode: check for global side data " James Almer
2023-09-04 15:04 ` [FFmpeg-devel] [PATCH 09/17] fftools/ffmpeg: stop injecting stream side data in packets James Almer
2023-09-04 15:04 ` [FFmpeg-devel] [PATCH 10/17] fftools/ffplay: " James Almer
2023-09-04 15:04 ` [FFmpeg-devel] [PATCH 11/17] Revert "avcodec/mpeg12dec: Do not alter avctx->rc_buffer_size" James Almer
2023-09-04 15:37 ` Andreas Rheinhardt
2023-09-04 22:10 ` James Almer
2023-09-04 15:04 ` [FFmpeg-devel] [PATCH 12/17] avformat/demux: propagate the internal decoder's bitrate properties James Almer
2023-09-04 22:11 ` James Almer
2023-09-04 15:04 ` [FFmpeg-devel] [PATCH 13/17] avcodec/mpeg12dec: stop propagating AVCPBProperties side data James Almer
2023-09-04 22:11 ` [FFmpeg-devel] [PATCH 14/17] avcodec/avcodec: deprecate coded_side_data James Almer
2023-09-04 15:04 ` James Almer
2023-09-04 15:04 ` [FFmpeg-devel] [PATCH 15/17] avcodec/utils: move ff_add_cpb_side_data() to encoder code James Almer
2023-09-04 15:04 ` [FFmpeg-devel] [PATCH 16/17] avformat/demux: stop copying the internal AVCodecContext coded_side_data James Almer
2023-09-04 15:04 ` [FFmpeg-devel] [PATCH 17/17] fftools: stop propagating the encoder's coded_side_data James Almer
2023-09-04 15:37 ` [FFmpeg-devel] [PATCH 00/17 v3] AVCodecContext and AVCodecParameters side data Derek Buitenhuis
2023-09-04 16:10 ` James Almer
2023-09-05 13:19 ` Derek Buitenhuis
2023-09-05 13:31 ` James Almer
2023-09-05 14:06 ` Derek Buitenhuis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230904150411.56777-2-jamrial@gmail.com \
--to=jamrial@gmail.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git