rtph264depay: Preserve SPS/PPS arrival order.

Even if SPS/PPS haven't changed, make sure to move them to the
end of the tracking array if needed, so we always know what the
most recent entries are, in case we need to discard the oldest
when generating codec_data.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/775>
This commit is contained in:
Jan Schmidt 2020-10-20 23:22:36 +11:00 committed by GStreamer Merge Bot
parent 2623404744
commit b066441e21

View file

@ -581,14 +581,16 @@ gst_rtp_h264_add_sps_pps (GstElement * rtph264, GPtrArray * sps_array,
parse_sps (&spsmap, &tmp_sps_id);
if (sps_id == tmp_sps_id) {
if (map.size == spsmap.size &&
/* If this is already the most recent SPS and unchanged, nothing to do */
if (i == (sps_array->len - 1) && map.size == spsmap.size &&
memcmp (map.data, spsmap.data, spsmap.size) == 0) {
GST_LOG_OBJECT (rtph264, "Unchanged SPS %u, not updating", sps_id);
GST_LOG_OBJECT (rtph264,
"Unchanged SPS %u already most recent, not updating", sps_id);
gst_buffer_unmap (sps, &spsmap);
goto drop;
} else {
gst_buffer_unmap (sps, &spsmap);
g_ptr_array_remove_index_fast (sps_array, i);
g_ptr_array_remove_index (sps_array, i);
g_ptr_array_add (sps_array, nal);
GST_LOG_OBJECT (rtph264, "Modified SPS %u, replacing", sps_id);
goto done;
@ -619,15 +621,17 @@ gst_rtp_h264_add_sps_pps (GstElement * rtph264, GPtrArray * sps_array,
parse_pps (&ppsmap, &tmp_sps_id, &tmp_pps_id);
if (pps_id == tmp_pps_id) {
if (map.size == ppsmap.size &&
/* If this is already the most recent PPS and unchanged, nothing to do */
if (i == (pps_array->len - 1) && map.size == ppsmap.size &&
memcmp (map.data, ppsmap.data, ppsmap.size) == 0) {
GST_LOG_OBJECT (rtph264, "Unchanged PPS %u:%u, not updating", sps_id,
GST_LOG_OBJECT (rtph264,
"Unchanged PPS %u:%u already most recent, not updating", sps_id,
pps_id);
gst_buffer_unmap (pps, &ppsmap);
goto drop;
} else {
gst_buffer_unmap (pps, &ppsmap);
g_ptr_array_remove_index_fast (pps_array, i);
g_ptr_array_remove_index (pps_array, i);
g_ptr_array_add (pps_array, nal);
GST_LOG_OBJECT (rtph264, "Modified PPS %u:%u, replacing",
sps_id, pps_id);