[FFmpeg-devel] [PATCH 09/11] avcodec/decode: check for global side data in AVCodecContext side data
James Almer
jamrial at gmail.com
Wed Sep 27 16:12:40 EEST 2023
Signed-off-by: James Almer <jamrial at gmail.com>
---
libavcodec/decode.c | 48 +++++++++++++++++++++++++++++++++++++--------
1 file changed, 40 insertions(+), 8 deletions(-)
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index a7196b5740..3b4bb70689 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1422,6 +1422,20 @@ static int add_metadata_from_side_data(const AVPacket *avpkt, AVFrame *frame)
return av_packet_unpack_dictionary(side_metadata, size, frame_md);
}
+static const struct {
+ enum AVPacketSideDataType packet;
+ enum AVFrameSideDataType frame;
+} sd_global_map[] = {
+ { AV_PKT_DATA_REPLAYGAIN , AV_FRAME_DATA_REPLAYGAIN },
+ { AV_PKT_DATA_SPHERICAL, AV_FRAME_DATA_SPHERICAL },
+ { AV_PKT_DATA_STEREO3D, AV_FRAME_DATA_STEREO3D },
+ { AV_PKT_DATA_AUDIO_SERVICE_TYPE, AV_FRAME_DATA_AUDIO_SERVICE_TYPE },
+ { AV_PKT_DATA_MASTERING_DISPLAY_METADATA, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA },
+ { AV_PKT_DATA_CONTENT_LIGHT_LEVEL, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL },
+ { AV_PKT_DATA_ICC_PROFILE, AV_FRAME_DATA_ICC_PROFILE },
+ { AV_PKT_DATA_DYNAMIC_HDR10_PLUS, AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
+};
+
int ff_decode_frame_props_from_pkt(const AVCodecContext *avctx,
AVFrame *frame, const AVPacket *pkt)
{
@@ -1429,18 +1443,10 @@ int ff_decode_frame_props_from_pkt(const AVCodecContext *avctx,
enum AVPacketSideDataType packet;
enum AVFrameSideDataType frame;
} sd[] = {
- { AV_PKT_DATA_REPLAYGAIN , AV_FRAME_DATA_REPLAYGAIN },
{ AV_PKT_DATA_DISPLAYMATRIX, AV_FRAME_DATA_DISPLAYMATRIX },
- { AV_PKT_DATA_SPHERICAL, AV_FRAME_DATA_SPHERICAL },
- { AV_PKT_DATA_STEREO3D, AV_FRAME_DATA_STEREO3D },
- { AV_PKT_DATA_AUDIO_SERVICE_TYPE, AV_FRAME_DATA_AUDIO_SERVICE_TYPE },
- { AV_PKT_DATA_MASTERING_DISPLAY_METADATA, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA },
- { AV_PKT_DATA_CONTENT_LIGHT_LEVEL, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL },
{ AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC },
{ AV_PKT_DATA_AFD, AV_FRAME_DATA_AFD },
- { AV_PKT_DATA_ICC_PROFILE, AV_FRAME_DATA_ICC_PROFILE },
{ AV_PKT_DATA_S12M_TIMECODE, AV_FRAME_DATA_S12M_TIMECODE },
- { AV_PKT_DATA_DYNAMIC_HDR10_PLUS, AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
{ AV_PKT_DATA_SKIP_SAMPLES, AV_FRAME_DATA_SKIP_SAMPLES },
};
@@ -1453,6 +1459,18 @@ FF_DISABLE_DEPRECATION_WARNINGS
FF_ENABLE_DEPRECATION_WARNINGS
#endif
+ for (int i = 0; i < FF_ARRAY_ELEMS(sd_global_map); i++) {
+ size_t size;
+ const uint8_t *packet_sd = av_packet_get_side_data(pkt, sd_global_map[i].packet, &size);
+ if (packet_sd) {
+ AVFrameSideData *frame_sd;
+
+ frame_sd = av_frame_new_side_data(frame, sd_global_map[i].frame, size);
+ if (!frame_sd)
+ return AVERROR(ENOMEM);
+ memcpy(frame_sd->data, packet_sd, size);
+ }
+ }
for (int i = 0; i < FF_ARRAY_ELEMS(sd); i++) {
size_t size;
uint8_t *packet_sd = av_packet_get_side_data(pkt, sd[i].packet, &size);
@@ -1489,6 +1507,20 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
const AVPacket *pkt = avctx->internal->last_pkt_props;
int ret;
+ for (int i = 0; i < FF_ARRAY_ELEMS(sd_global_map); i++) {
+ const AVPacketSideData *packet_sd = ff_get_coded_side_data(avctx,
+ sd_global_map[i].packet);
+ if (packet_sd) {
+ AVFrameSideData *frame_sd = av_frame_new_side_data(frame,
+ sd_global_map[i].frame,
+ packet_sd->size);
+ if (!frame_sd)
+ return AVERROR(ENOMEM);
+
+ memcpy(frame_sd->data, packet_sd->data, packet_sd->size);
+ }
+ }
+
if (!(ffcodec(avctx->codec)->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS)) {
ret = ff_decode_frame_props_from_pkt(avctx, frame, pkt);
if (ret < 0)
--
2.42.0
More information about the ffmpeg-devel
mailing list