From bc252d29ee3ab0164dc790559ab1dbb6934e3d51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Thu, 20 Sep 2012 17:28:47 -0400 Subject: [PATCH] rtph264pay: Make sure the caps don't have duplicated sps/pps --- gst/rtp/gstrtph264pay.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/gst/rtp/gstrtph264pay.c b/gst/rtp/gstrtph264pay.c index 7b085250ac..3016d5ad06 100644 --- a/gst/rtp/gstrtph264pay.c +++ b/gst/rtp/gstrtph264pay.c @@ -398,6 +398,30 @@ gst_rtp_h264_pay_set_sps_pps (GstRTPBasePayload * basepayload) return res; } +static GList * +add_sps_pps_without_duplicates (GList * list, GstBuffer * buffer) +{ + GList *walk; + GstMapInfo map; + + gst_buffer_map (buffer, &map, GST_MAP_READ); + + for (walk = list; walk; walk = walk->next) { + if (gst_buffer_get_size (walk->data) == map.size && + !gst_buffer_memcmp (walk->data, 0, map.data, map.size)) { + /* Same data */ + gst_buffer_unmap (buffer, &map); + gst_buffer_unref (buffer); + return list; + } + } + + gst_buffer_unmap (buffer, &map); + list = g_list_append (list, buffer); + + return list; +} + static gboolean gst_rtp_h264_pay_setcaps (GstRTPBasePayload * basepayload, GstCaps * caps) { @@ -493,7 +517,8 @@ gst_rtp_h264_pay_setcaps (GstRTPBasePayload * basepayload, GstCaps * caps) /* make a buffer out of it and add to SPS list */ sps_buf = gst_buffer_new_and_alloc (nal_size); gst_buffer_fill (sps_buf, 0, data, nal_size); - rtph264pay->sps = g_list_append (rtph264pay->sps, sps_buf); + rtph264pay->sps = add_sps_pps_without_duplicates (rtph264pay->sps, + sps_buf); data += nal_size; size -= nal_size; @@ -525,7 +550,8 @@ gst_rtp_h264_pay_setcaps (GstRTPBasePayload * basepayload, GstCaps * caps) /* make a buffer out of it and add to PPS list */ pps_buf = gst_buffer_new_and_alloc (nal_size); gst_buffer_fill (pps_buf, 0, data, nal_size); - rtph264pay->pps = g_list_append (rtph264pay->pps, pps_buf); + rtph264pay->pps = add_sps_pps_without_duplicates (rtph264pay->pps, + pps_buf); data += nal_size; size -= nal_size; @@ -615,11 +641,11 @@ gst_rtp_h264_pay_parse_sprop_parameter_sets (GstRtpH264Pay * rtph264pay) /* append to the right list */ if ((nal_type & 0x1f) == 7) { GST_DEBUG_OBJECT (rtph264pay, "adding param %d as SPS %d", i, num_sps); - rtph264pay->sps = g_list_append (rtph264pay->sps, buf); + rtph264pay->sps = add_sps_pps_without_duplicates (rtph264pay->sps, buf); num_sps++; } else { GST_DEBUG_OBJECT (rtph264pay, "adding param %d as PPS %d", i, num_pps); - rtph264pay->pps = g_list_append (rtph264pay->pps, buf); + rtph264pay->pps = add_sps_pps_without_duplicates (rtph264pay->pps, buf); num_pps++; } }