[vlc-commits] [Git][videolan/vlc][master] 3 commits: codec/videotoolbox: fix a leak of repeated HEVC pic timing SEI
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Thu Oct 29 16:24:51 UTC 2026
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
e262993d by Felix Paul Kühne at 2026-10-29T17:03:57+01:00
codec/videotoolbox: fix a leak of repeated HEVC pic timing SEI
- - - - -
37e20a25 by Felix Paul Kühne at 2026-10-29T17:03:57+01:00
codec/videotoolbox: parse the HDR static metadata SEI for HEVC & H.264
The information will be given to the vout and its output format.
- - - - -
86262aac by Felix Paul Kühne at 2026-10-29T17:03:57+01:00
vout/vsbd: attach the HDR static metadata
Pass the mastering display and content light level to the pixel
buffers so the system tone maps against the stream metadata instead
of its defaults.
- - - - -
3 changed files:
- modules/codec/videotoolbox/decoder.c
- modules/codec/videotoolbox/dpb.h
- modules/video_output/apple/VLCSampleBufferDisplay.m
Changes:
=====================================
modules/codec/videotoolbox/decoder.c
=====================================
@@ -183,6 +183,25 @@ static OSType GetBestChromaFromHxxx(struct hxxx_helper *hh)
return GetBestChroma(a, b, c);
}
+static void ParseHxxxHDRSEI(const hxxx_sei_data_t *p_sei_data,
+ frame_info_t *p_info)
+{
+ if (p_sei_data->i_type == HXXX_SEI_MASTERING_DISPLAY_COLOUR_VOLUME)
+ {
+ for (size_t i = 0; i < ARRAY_SIZE(p_info->mastering.primaries); i++)
+ p_info->mastering.primaries[i] = p_sei_data->colour_volume.primaries[i];
+ for (size_t i = 0; i < ARRAY_SIZE(p_info->mastering.white_point); i++)
+ p_info->mastering.white_point[i] = p_sei_data->colour_volume.white_point[i];
+ p_info->mastering.max_luminance = p_sei_data->colour_volume.max_luminance;
+ p_info->mastering.min_luminance = p_sei_data->colour_volume.min_luminance;
+ }
+ else if (p_sei_data->i_type == HXXX_SEI_CONTENT_LIGHT_LEVEL)
+ {
+ p_info->lighting.MaxCLL = p_sei_data->content_light_lvl.MaxCLL;
+ p_info->lighting.MaxFALL = p_sei_data->content_light_lvl.MaxFALL;
+ }
+}
+
/** H264 Specific */
struct vt_h264_context
@@ -208,13 +227,14 @@ struct sei_callback_h264_s
{
uint8_t i_pic_struct;
const h264_sequence_parameter_set_t *p_sps;
+ frame_info_t *p_info;
};
static bool ParseH264SEI(const hxxx_sei_data_t *p_sei_data, void *priv)
{
+ struct sei_callback_h264_s *s = priv;
if (p_sei_data->i_type == HXXX_SEI_PIC_TIMING)
{
- struct sei_callback_h264_s *s = priv;
if (s->p_sps)
{
uint8_t i_dpb_output_delay;
@@ -223,8 +243,9 @@ static bool ParseH264SEI(const hxxx_sei_data_t *p_sei_data, void *priv)
&i_dpb_output_delay );
VLC_UNUSED(i_dpb_output_delay);
}
- return false;
}
+ else
+ ParseHxxxHDRSEI(p_sei_data, s->p_info);
return true;
}
@@ -277,6 +298,7 @@ static bool FillReorderInfoH264(decoder_t *p_dec, const block_t *p_block,
struct sei_callback_h264_s sei;
sei.p_sps = p_sps;
sei.i_pic_struct = UINT8_MAX;
+ sei.p_info = p_info;
for (size_t i = 0; i < i_sei_count; i++)
HxxxParseSEI(sei_array[i].p_nal, sei_array[i].i_nal, 1,
@@ -606,17 +628,22 @@ struct hevc_sei_callback_s
{
hevc_sei_pic_timing_t *p_timing;
const hevc_sequence_parameter_set_t *p_sps;
+ frame_info_t *p_info;
};
static bool ParseHEVCSEI(const hxxx_sei_data_t *p_sei_data, void *priv)
{
+ struct hevc_sei_callback_s *s = priv;
if (p_sei_data->i_type == HXXX_SEI_PIC_TIMING)
{
- struct hevc_sei_callback_s *s = priv;
if (likely(s->p_sps))
+ {
+ hevc_release_sei_pic_timing(s->p_timing);
s->p_timing = hevc_decode_sei_pic_timing(p_sei_data->p_bs, s->p_sps);
- return false;
+ }
}
+ else
+ ParseHxxxHDRSEI(p_sei_data, s->p_info);
return true;
}
@@ -676,6 +703,7 @@ static bool FillReorderInfoHEVC(decoder_t *p_dec, const block_t *p_block,
struct hevc_sei_callback_s sei;
sei.p_sps = p_sps;
sei.p_timing = NULL;
+ sei.p_info = p_info;
const int POC = hevc_compute_picture_order_count(p_sps, p_sli,
&hevcctx->poc);
@@ -2010,6 +2038,43 @@ skip:
return VLCDEC_SUCCESS;
}
+static bool UpdateHDRMetadata(decoder_t *p_dec, const frame_info_t *p_info)
+{
+ video_format_t *fmt = &p_dec->fmt_out.video;
+ bool changed = false;
+
+ if (p_info->mastering.max_luminance)
+ {
+ if (fmt->mastering.max_luminance != p_info->mastering.max_luminance ||
+ fmt->mastering.min_luminance != p_info->mastering.min_luminance)
+ {
+ msg_Dbg(p_dec, "mastering display: max %.4f min %.4f cd/m2",
+ p_info->mastering.max_luminance / 10000.f,
+ p_info->mastering.min_luminance / 10000.f);
+ changed = true;
+ }
+ for (size_t i = 0; i < ARRAY_SIZE(fmt->mastering.primaries); i++)
+ fmt->mastering.primaries[i] = p_info->mastering.primaries[i];
+ for (size_t i = 0; i < ARRAY_SIZE(fmt->mastering.white_point); i++)
+ fmt->mastering.white_point[i] = p_info->mastering.white_point[i];
+ fmt->mastering.max_luminance = p_info->mastering.max_luminance;
+ fmt->mastering.min_luminance = p_info->mastering.min_luminance;
+ }
+ if (p_info->lighting.MaxCLL || p_info->lighting.MaxFALL)
+ {
+ if (fmt->lighting.MaxCLL != p_info->lighting.MaxCLL ||
+ fmt->lighting.MaxFALL != p_info->lighting.MaxFALL)
+ {
+ msg_Dbg(p_dec, "content light level: MaxCLL %u MaxFALL %u",
+ p_info->lighting.MaxCLL, p_info->lighting.MaxFALL);
+ changed = true;
+ }
+ fmt->lighting.MaxCLL = p_info->lighting.MaxCLL;
+ fmt->lighting.MaxFALL = p_info->lighting.MaxFALL;
+ }
+ return changed;
+}
+
static int UpdateVideoFormat(decoder_t *p_dec, CVPixelBufferRef imageBuffer)
{
decoder_sys_t *p_sys = p_dec->p_sys;
@@ -2115,6 +2180,8 @@ static void DecoderCallback(void *decompressionOutputRefCon,
if (p_sys->b_discard_decoder_output)
goto end;
+ const bool b_hdr_changed = UpdateHDRMetadata(p_dec, p_info);
+
enum vtsession_status vtsession_status;
if (HandleVTStatus(p_dec, status, &vtsession_status) != VLC_SUCCESS)
{
@@ -2146,6 +2213,12 @@ static void DecoderCallback(void *decompressionOutputRefCon,
goto end;
assert(p_dec->fmt_out.i_codec != 0);
}
+ else if (b_hdr_changed &&
+ decoder_UpdateVideoOutput(p_dec, p_sys->vctx) != 0)
+ {
+ p_sys->vtsession_status = VTSESSION_STATUS_VOUT_FAILURE;
+ goto end;
+ }
if (infoFlags & kVTDecodeInfo_FrameDropped)
{
@@ -2194,6 +2267,12 @@ static void DecoderCallback(void *decompressionOutputRefCon,
vlc_mutex_lock(&p_sys->lock);
+ if (p_pic)
+ {
+ p_pic->format.mastering = p_dec->fmt_out.video.mastering;
+ p_pic->format.lighting = p_dec->fmt_out.video.lighting;
+ }
+
if (p_sys->b_discard_decoder_output)
picture_Release(p_pic);
else
=====================================
modules/codec/videotoolbox/dpb.h
=====================================
@@ -53,6 +53,18 @@ struct frame_info_t
uint8_t i_max_latency_pics;
uint8_t i_latency;
unsigned i_length;
+ struct
+ {
+ uint16_t primaries[3*2];
+ uint16_t white_point[2];
+ uint32_t max_luminance;
+ uint32_t min_luminance;
+ } mastering;
+ struct
+ {
+ uint16_t MaxCLL;
+ uint16_t MaxFALL;
+ } lighting;
frame_info_t *p_next;
};
=====================================
modules/video_output/apple/VLCSampleBufferDisplay.m
=====================================
@@ -863,6 +863,9 @@ API_AVAILABLE(tvos(17.0), visionos(1.0))
+ (instancetype)new NS_UNAVAILABLE;
- (instancetype)initWithVoutDisplay:(vout_display_t *)vd;
- (void)placeVideo:(vout_display_place_t)newPlace;
+ - (void)attachHDRMetadataFromFormat:(const video_format_t *)format
+ toPixelBuffer:(CVPixelBufferRef)pixelBuffer
+ API_AVAILABLE(ios(11.0));
@end
@implementation VLCSampleBufferDisplay
@@ -1024,6 +1027,52 @@ API_AVAILABLE(tvos(17.0), visionos(1.0))
self.displayView.frame = [self frameForPlace:&newPlace];
}
+- (void)attachHDRMetadataFromFormat:(const video_format_t *)format
+ toPixelBuffer:(CVPixelBufferRef)pixelBuffer {
+ if (format->mastering.max_luminance) {
+ struct {
+ uint16_t primaries[6];
+ uint16_t white_point[2];
+ uint32_t max_luminance;
+ uint32_t min_luminance;
+ } __attribute__((packed)) mastering;
+ _Static_assert(sizeof(mastering) == 24,
+ "Mismatch with the mastering display color volume size");
+ for (size_t i = 0; i < ARRAY_SIZE(mastering.primaries); i++)
+ mastering.primaries[i] = hton16(format->mastering.primaries[i]);
+ for (size_t i = 0; i < ARRAY_SIZE(mastering.white_point); i++)
+ mastering.white_point[i] = hton16(format->mastering.white_point[i]);
+ mastering.max_luminance = hton32(format->mastering.max_luminance);
+ mastering.min_luminance = hton32(format->mastering.min_luminance);
+
+ NSData *data = [[NSData alloc] initWithBytes:&mastering
+ length:sizeof(mastering)];
+ CVBufferSetAttachment(pixelBuffer,
+ kCVImageBufferMasteringDisplayColorVolumeKey,
+ (__bridge CFDataRef)data,
+ kCVAttachmentMode_ShouldPropagate);
+ }
+
+ if (format->lighting.MaxCLL || format->lighting.MaxFALL) {
+ struct {
+ uint16_t max_cll;
+ uint16_t max_fall;
+ } __attribute__((packed)) lighting = {
+ hton16(format->lighting.MaxCLL),
+ hton16(format->lighting.MaxFALL),
+ };
+ _Static_assert(sizeof(lighting) == 4,
+ "Mismatch with the content light level info size");
+
+ NSData *data = [[NSData alloc] initWithBytes:&lighting
+ length:sizeof(lighting)];
+ CVBufferSetAttachment(pixelBuffer,
+ kCVImageBufferContentLightLevelInfoKey,
+ (__bridge CFDataRef)data,
+ kCVAttachmentMode_ShouldPropagate);
+ }
+}
+
- (void)close {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self.displayModeMatcher close];
@@ -1136,6 +1185,9 @@ static void RenderPicture(vout_display_t *vd, picture_t *pic, vlc_tick_t date) {
kCVAttachmentMode_ShouldPropagate
);
+ if (@available(iOS 11.0, *))
+ [sys attachHDRMetadataFromFormat:&pic->format toPixelBuffer:pixelBuffer];
+
CMSampleBufferRef sampleBuffer = NULL;
CMVideoFormatDescriptionRef formatDesc = NULL;
OSStatus err = CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, pixelBuffer, &formatDesc);
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/12023233efcb90bbd409f36f3f0f483a08339623...86262aaceebf24429db5a5bd759c17b7434b8498
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/12023233efcb90bbd409f36f3f0f483a08339623...86262aaceebf24429db5a5bd759c17b7434b8498
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help
More information about the vlc-commits
mailing list