From 30d29618b156057bcfee08019164c15330deb174 Mon Sep 17 00:00:00 2001 From: Ryan Foster Date: Sun, 27 Oct 2019 01:05:54 -0400 Subject: [PATCH] mac-vth264: Manually mark priority bits for frames This commit is the mac-vth264 version of edfc2be in obs-qsv11. --- plugins/mac-vth264/encoder.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/plugins/mac-vth264/encoder.c b/plugins/mac-vth264/encoder.c index 07a05c74c..11ff76a7a 100644 --- a/plugins/mac-vth264/encoder.c +++ b/plugins/mac-vth264/encoder.c @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -671,6 +672,10 @@ static bool is_sample_keyframe(CMSampleBufferRef buffer) static bool parse_sample(struct vt_h264_encoder *enc, CMSampleBufferRef buffer, struct encoder_packet *packet, CMTime off) { + uint8_t *start; + uint8_t *end; + int type; + CMTime pts = CMSampleBufferGetPresentationTimeStamp(buffer); CMTime dts = CMSampleBufferGetDecodeTimeStamp(buffer); @@ -703,6 +708,37 @@ static bool parse_sample(struct vt_h264_encoder *enc, CMSampleBufferRef buffer, packet->size = enc->packet_data.num; packet->keyframe = keyframe; + /* ------------------------------------ */ + + start = enc->packet_data.array; + end = start + enc->packet_data.num; + + start = (uint8_t *)obs_avc_find_startcode(start, end); + while (true) { + while (start < end && !*(start++)) + ; + + if (start == end) + break; + + type = start[0] & 0x1F; + if (type == OBS_NAL_SLICE_IDR || type == OBS_NAL_SLICE) { + uint8_t prev_type = (start[0] >> 5) & 0x3; + start[0] &= ~(3 << 5); + + if (type & OBS_NAL_SLICE) + start[0] |= OBS_NAL_PRIORITY_HIGHEST << 5; + else if (type & OBS_NAL_SLICE_IDR) + start[0] |= OBS_NAL_PRIORITY_HIGH << 5; + else + start[0] |= prev_type << 5; + } + + start = (uint8_t *)obs_avc_find_startcode(start, end); + } + + /* ------------------------------------ */ + CFRelease(buffer); return true;