From 5ff895d3ceaf25d90f55083f8e53c0098b4ba4e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Tue, 20 Apr 2021 19:11:12 +0100 Subject: openh264enc: fix broken sps/pps header generation This was putting a truncated SPS into the initial header instead of the PPS because it was always reading from the beginning of the bitstream buffer (pBsBuf) and not from the offset where the current NAL is at in the bitstream buffer (psBsBuf + nal_offset). This was broken in commit 17113695. Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/issues/1576 Part-of: --- ext/openh264/gstopenh264enc.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ext/openh264/gstopenh264enc.cpp b/ext/openh264/gstopenh264enc.cpp index c725138ef..90f7ca8eb 100644 --- a/ext/openh264/gstopenh264enc.cpp +++ b/ext/openh264/gstopenh264enc.cpp @@ -995,8 +995,13 @@ gst_openh264enc_handle_frame (GstVideoEncoder * encoder, if (j > 0) nal_offset = nal_offset + frame_info.sLayerInfo[i].pNalLengthInByte[j-1]; nal_type = ((* (frame_info.sLayerInfo[i].pBsBuf + nal_offset + 4)) & 0x1f); - if (nal_type == NAL_SPS || nal_type == NAL_PPS) - gst_buffer_fill (hdr, nal_offset, frame_info.sLayerInfo[i].pBsBuf, frame_info.sLayerInfo[i].pNalLengthInByte[j]); + /* Note: This only works if SPS/PPS are the first two NALs in which case + * nal_offset is the same for both the output and the bitstream buffer */ + if (nal_type == NAL_SPS || nal_type == NAL_PPS) { + gst_buffer_fill (hdr, nal_offset, + frame_info.sLayerInfo[i].pBsBuf + nal_offset, + frame_info.sLayerInfo[i].pNalLengthInByte[j]); + } } headers = g_list_append (headers, gst_buffer_ref (hdr)); } -- cgit v1.2.1