diff --git a/doc/APIchanges b/doc/APIchanges index 7c2ab3cc03..7de9072a47 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2025-03-28 API changes, most recent first: +2025-10-30 - xxxxxxxxxx - lavc 62.17.100 - packet.h + Add av_packet_side_data_from_frame() and av_packet_side_data_to_frame(). + 2025-10-xx - xxxxxxxxxx - lavu 60.16.100 - pixfmt.h Add AVCOL_TRC_EXT_BASE, AVCOL_TRC_V_LOG, AVCOL_PRI_EXT_BASE and AVCOL_PRI_V_GAMUT. diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index 0355b7c338..db24b4ed52 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -815,3 +815,53 @@ int avcodec_get_supported_config(const AVCodecContext *avctx, const AVCodec *cod return ff_default_get_supported_config(avctx, codec, config, flags, out, out_num); } } + +int av_packet_side_data_from_frame(AVPacketSideData **psd, int *pnb_sd, + const AVFrameSideData *src, unsigned int flags) +{ + AVPacketSideData *sd = NULL; + + for (unsigned j = 0; ff_sd_global_map[j].packet < AV_PKT_DATA_NB; j++) { + if (ff_sd_global_map[j].frame != src->type) + continue; + + sd = av_packet_side_data_new(psd, pnb_sd, ff_sd_global_map[j].packet, + src->size, 0); + + if (!sd) + return AVERROR(ENOMEM); + + memcpy(sd->data, src->data, src->size); + break; + } + + if (!sd) + return AVERROR(EINVAL); + + return 0; +} + +int av_packet_side_data_to_frame(AVFrameSideData ***psd, int *pnb_sd, + const AVPacketSideData *src, unsigned int flags) +{ + AVFrameSideData *sd = NULL; + + for (unsigned j = 0; ff_sd_global_map[j].packet < AV_PKT_DATA_NB; j++) { + if (ff_sd_global_map[j].packet != src->type) + continue; + + sd = av_frame_side_data_new(psd, pnb_sd, ff_sd_global_map[j].frame, + src->size, flags); + + if (!sd) + return AVERROR(ENOMEM); + + memcpy(sd->data, src->data, src->size); + break; + } + + if (!sd) + return AVERROR(EINVAL); + + return 0; +} diff --git a/libavcodec/packet.h b/libavcodec/packet.h index 5e27f9ceb5..59bfddf4cc 100644 --- a/libavcodec/packet.h +++ b/libavcodec/packet.h @@ -489,6 +489,36 @@ void av_packet_side_data_remove(AVPacketSideData *sd, int *nb_sd, */ void av_packet_side_data_free(AVPacketSideData **sd, int *nb_sd); +struct AVFrameSideData; + +/** + * Add a new packet side data entry to an array based on existing frame + * side data, if a matching type exists for packet side data. + * + * @param flags Currently unused. Must be 0. + * @retval >= 0 Success + * @retval AVERROR(EINVAL) The frame side data type does not have a matching + * packet side data type. + * @retval AVERROR(ENOMEM) Failed to add a side data entry to the array, or + * similar. + */ +int av_packet_side_data_from_frame(AVPacketSideData **sd, int *nb_sd, + const struct AVFrameSideData *src, unsigned int flags); +/** + * Add a new frame side data entry to an array based on existing packet + * side data, if a matching type exists for frame side data. + * + * @param flags Some combination of AV_FRAME_SIDE_DATA_FLAG_* flags, + * or 0. + * @retval >= 0 Success + * @retval AVERROR(EINVAL) The packet side data type does not have a matching + * frame side data type. + * @retval AVERROR(ENOMEM) Failed to add a side data entry to the array, or + * similar. + */ +int av_packet_side_data_to_frame(struct AVFrameSideData ***sd, int *nb_sd, + const AVPacketSideData *src, unsigned int flags); + const char *av_packet_side_data_name(enum AVPacketSideDataType type); /** diff --git a/libavcodec/version.h b/libavcodec/version.h index 82a86fe9d9..2618016a83 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -29,7 +29,7 @@ #include "version_major.h" -#define LIBAVCODEC_VERSION_MINOR 16 +#define LIBAVCODEC_VERSION_MINOR 17 #define LIBAVCODEC_VERSION_MICRO 100 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \