From 4cff2e2c6788107c9a76daf379123ae854117d0f Mon Sep 17 00:00:00 2001 From: Mark Nauwelaerts Date: Mon, 10 May 2010 11:14:39 +0200 Subject: [PATCH] rtph264pay: extract SPS and PPS from property provided parameter set ... so it can also be regularly inserted into the stream if so configured. Fixes #617164. --- gst/rtp/gstrtph264pay.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/gst/rtp/gstrtph264pay.c b/gst/rtp/gstrtph264pay.c index 64eac0d..89da929 100644 --- a/gst/rtp/gstrtph264pay.c +++ b/gst/rtp/gstrtph264pay.c @@ -424,6 +424,60 @@ avcc_error: } } +static void +gst_rtp_h264_pay_parse_sprop_parameter_sets (GstRtpH264Pay * rtph264pay) +{ + const gchar *ps; + gchar **params; + guint len, num_sps, num_pps; + gint i; + GstBuffer *buf; + + ps = rtph264pay->sprop_parameter_sets; + if (ps == NULL) + return; + + gst_rtp_h264_pay_clear_sps_pps (rtph264pay); + + params = g_strsplit (ps, ",", 0); + len = g_strv_length (params); + + GST_DEBUG_OBJECT (rtph264pay, "we have %d params", len); + + num_sps = num_pps = 0; + + for (i = 0; params[i]; i++) { + gsize nal_len; + guint8 *nalp; + guint save = 0; + gint state = 0; + + nal_len = strlen (params[i]); + buf = gst_buffer_new_and_alloc (nal_len); + nalp = GST_BUFFER_DATA (buf); + + nal_len = g_base64_decode_step (params[i], nal_len, nalp, &state, &save); + GST_BUFFER_SIZE (buf) = nal_len; + + if (!nal_len) { + gst_buffer_unref (buf); + continue; + } + + /* append to the right list */ + if ((nalp[0] & 0x1f) == 7) { + GST_DEBUG_OBJECT (rtph264pay, "adding param %d as SPS %d", i, num_sps); + rtph264pay->sps = g_list_append (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); + num_pps++; + } + } + g_strfreev (params); +} + static guint next_start_code (guint8 * data, guint size) { @@ -963,6 +1017,9 @@ gst_rtp_h264_pay_handle_buffer (GstBaseRTPPayload * basepayload, rtph264pay->sprop_parameter_sets, NULL)) goto caps_rejected; + /* parse SPS and PPS from provided parameter set (for insertion) */ + gst_rtp_h264_pay_parse_sprop_parameter_sets (rtph264pay); + rtph264pay->update_caps = FALSE; GST_DEBUG ("outcaps update: sprop-parameter-sets=%s", -- 2.7.4