[FFmpeg-devel] [PATCH v1 2/5] avcodec/hevc_sei: add support for user data unregistered SEI message
lance.lmwang at gmail.com
lance.lmwang at gmail.com
Tue Dec 17 12:22:14 EET 2019
From: Limin Wang <lance.lmwang at gmail.com>
Signed-off-by: Limin Wang <lance.lmwang at gmail.com>
---
libavcodec/hevc_sei.c | 28 ++++++++++++++++++++++++++++
libavcodec/hevc_sei.h | 7 +++++++
libavcodec/hevcdec.c | 10 ++++++++++
3 files changed, 45 insertions(+)
diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
index c59bd4321e..1af9594607 100644
--- a/libavcodec/hevc_sei.c
+++ b/libavcodec/hevc_sei.c
@@ -206,6 +206,28 @@ static int decode_registered_user_data_closed_caption(HEVCSEIA53Caption *s, GetB
return 0;
}
+static int decode_nal_sei_user_data_unregistered(HEVCSEIUnregistered *s, GetBitContext *gb,
+ int size)
+{
+ const int uuid_size = 16;
+ int i;
+
+ if (size < uuid_size || size > INT_MAX - uuid_size)
+ return AVERROR(EINVAL);
+
+ s->user_data = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE);
+ if (!s->user_data)
+ return AVERROR(ENOMEM);
+ s->user_data_size = size;
+
+ for (i = 0; i < size; i++)
+ s->user_data[i] = get_bits(gb, 8);
+ memset(s->user_data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
+
+ s->present = 1;
+ return 0;
+}
+
static int decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s, GetBitContext *gb,
int size)
{
@@ -293,6 +315,8 @@ static int decode_nal_sei_prefix(GetBitContext *gb, void *logctx, HEVCSEI *s,
return decode_nal_sei_active_parameter_sets(s, gb, logctx);
case HEVC_SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35:
return decode_nal_sei_user_data_registered_itu_t_t35(s, gb, size);
+ case HEVC_SEI_TYPE_USER_DATA_UNREGISTERED:
+ return decode_nal_sei_user_data_unregistered(&s->unregistered, gb, size);
case HEVC_SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS:
return decode_nal_sei_alternative_transfer(&s->alternative_transfer, gb);
default:
@@ -365,4 +389,8 @@ void ff_hevc_reset_sei(HEVCSEI *s)
{
s->a53_caption.a53_caption_size = 0;
av_freep(&s->a53_caption.a53_caption);
+
+ s->unregistered.user_data_size = 0;
+ s->unregistered.present = 0;
+ av_freep(&s->unregistered.user_data);
}
diff --git a/libavcodec/hevc_sei.h b/libavcodec/hevc_sei.h
index f6516ae982..1d312392e9 100644
--- a/libavcodec/hevc_sei.h
+++ b/libavcodec/hevc_sei.h
@@ -87,6 +87,12 @@ typedef struct HEVCSEIA53Caption {
uint8_t *a53_caption;
} HEVCSEIA53Caption;
+typedef struct HEVCSEIUnregistered {
+ int present;
+ int user_data_size;
+ uint8_t *user_data;
+} HEVCSEIUnregistered;
+
typedef struct HEVCSEIMasteringDisplay {
int present;
uint16_t display_primaries[3][2];
@@ -112,6 +118,7 @@ typedef struct HEVCSEI {
HEVCSEIDisplayOrientation display_orientation;
HEVCSEIPictureTiming picture_timing;
HEVCSEIA53Caption a53_caption;
+ HEVCSEIUnregistered unregistered;
HEVCSEIMasteringDisplay mastering_display;
HEVCSEIContentLight content_light;
int active_seq_parameter_set_id;
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 8f1c162ace..bc9ab7ceb7 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -2789,6 +2789,16 @@ static int set_side_data(HEVCContext *s)
s->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
}
+ if (s->sei.unregistered.present) {
+ AVFrameSideData *sd = av_frame_new_side_data(out, AV_FRAME_DATA_USER_DATA_UNREGISTERED,
+ s->sei.unregistered.user_data_size);
+ if (sd)
+ memcpy(sd->data, s->sei.unregistered.user_data, s->sei.unregistered.user_data_size);
+ av_freep(&s->sei.unregistered.user_data);
+ s->sei.unregistered.user_data_size = 0;
+ s->sei.unregistered.present = 0;
+ }
+
return 0;
}
--
2.21.0
More information about the ffmpeg-devel
mailing list