Index: gstrtph264pay.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-good/gst/rtp/gstrtph264pay.c,v
retrieving revision 1.15
diff -r1.15 gstrtph264pay.c
189a190,193
>   rtph264pay->sps_len = 0;
>   rtph264pay->pps_len = 0;
>   rtph264pay->profile_level_id = NULL;
>   rtph264pay->sprop_parameter_sets = NULL;
468,470d471
<   guint8 *sps = NULL, *pps = NULL;
<   guint sps_len = 0, pps_len = 0;
< 
477,509c478
<     GST_DEBUG ("NAL payload len=%u", size);
< 
<     /* loop through all NAL units and save the locations of any
<      * SPS / PPS for later processing. Only the last seen SPS
<      * or PPS will be considered */
<     while (size > 5) {
<       guint8 header, type;
<       guint len;
< 
<       len = next_start_code (data, size);
<       header = data[0];
<       type = header & 0x1f;
< 
<       /* keep sps & pps separately so that we can update either one 
<        * independently */
<       if (SPS_TYPE_ID == type) {
<         /* encode the entire SPS NAL in base64 */
<         GST_DEBUG ("Found SPS %x %x %x Len=%u", (header >> 7),
<             (header >> 5) & 3, type, len);
< 
<         sps = data;
<         sps_len = len;
<       } else if (PPS_TYPE_ID == type) {
<         /* encoder the entire PPS NAL in base64 */
<         GST_DEBUG ("Found PPS %x %x %x Len = %u",
<             (header >> 7), (header >> 5) & 3, type, len);
< 
<         pps = data;
<         pps_len = len;
<       } else {
<         GST_DEBUG ("NAL: %x %x %x Len = %u", (header >> 7),
<             (header >> 5) & 3, type, len);
<       }
---
>     guint8 header, type;
511,514c480
<       /* end of loop */
<       if (len >= size - 4) {
<         break;
<       }
---
>     GST_DEBUG ("NAL payload size=%u", size);
516,528c482,500
<       /* next NAL start */
<       data += len + 4;
<       size -= len + 4;
<     }
< 
<     /* If we encountered an SPS and/or a PPS, check if it's the
<      * same as the one we have. If not, update our version and
<      * set *updated to TRUE
<      */
<     if (sps_len > 0) {
<       if ((payloader->sps_len != sps_len)
<           || !is_nal_equal (payloader->sps, sps, sps_len)) {
<         payloader->profile = (sps[1] << 16) + (sps[2] << 8) + sps[3];
---
>     /* save the locations of any SPS / PPS for later processing. Only the 
> 	 * last seen SPS or PPS will be considered */
>     header = data[0];
>     type = header & 0x1f;
> 
>     /* keep sps & pps separately so that we can update either one 
>      * independently */
>     if (SPS_TYPE_ID == type) {
>       /* encode the entire SPS NAL in base64 */
>       GST_DEBUG ("Found SPS %x %x %x Len=%u", (header >> 7),
>           (header >> 5) & 3, type, size);
> 
>       /* If we encountered an SPS, check if it's the
>        * same as the one we have. If not, update our version and
>        * set *updated to TRUE
>        */
>       if ((payloader->sps_len != size)
>           || !is_nal_equal (payloader->sps, data, size)) {
>         payloader->profile = (data[1] << 16) + (data[2] << 8) + data[3];
532,533c504
<         if (payloader->sps_len)
<           g_free (payloader->sps);
---
>         g_free (payloader->sps);
535,537c506,508
<         payloader->sps = sps_len ? g_new (guint8, sps_len) : NULL;
<         memcpy (payloader->sps, sps, sps_len);
<         payloader->sps_len = sps_len;
---
>         payloader->sps = g_new (guint8, size);
>         memcpy (payloader->sps, data, size);
>         payloader->sps_len = size;
540,550c511,526
<     }
< 
<     if (pps_len > 0) {
<       if ((payloader->pps_len != pps_len)
<           || !is_nal_equal (payloader->pps, pps, pps_len)) {
<         if (payloader->pps_len)
<           g_free (payloader->pps);
< 
<         payloader->pps = pps_len ? g_new (guint8, pps_len) : NULL;
<         memcpy (payloader->pps, pps, pps_len);
<         payloader->pps_len = pps_len;
---
>     } else if (PPS_TYPE_ID == type) {
>       /* encoder the entire PPS NAL in base64 */
>       GST_DEBUG ("Found PPS %x %x %x Len = %u",
>           (header >> 7), (header >> 5) & 3, type, size);
> 
>       /* If we encountered an PPS, check if it's the
>        * same as the one we have. If not, update our version and
>        * set *updated to TRUE
>        */
>       if ((payloader->pps_len != size)
>           || !is_nal_equal (payloader->pps, data, size)) {
>         g_free (payloader->pps);
> 
>         payloader->pps = g_new (guint8, size);
>         memcpy (payloader->pps, data, size);
>         payloader->pps_len = size;
552a529,531
>     } else {
>       GST_DEBUG ("NAL: %x %x %x Len = %u", (header >> 7),
>           (header >> 5) & 3, type, size);
567,568c546,547
<   if (update) {
<     gchar *profile;
---
>   if (update && payloader->sps && payloader->pps) {
>     guint len;
571,572d549
<     gchar *sprops;
<     guint len;
574,575c551,554
<     /* profile is 24 bit. Force it to respect the limit */
<     profile = g_strdup_printf ("%06x", payloader->profile & 0xffffff);
---
> 	/* profile is 24 bit. Force it to respect the limit */
>     if (payloader->profile_level_id)
> 	  g_free (payloader->profile_level_id);
>     payloader->profile_level_id = g_strdup_printf ("%06x", payloader->profile & 0xffffff);
578,586c557,558
<     sps = (payloader->sps_len > 0)
<         ? encode_base64 (payloader->sps, payloader->sps_len, &len) : NULL;
<     pps = (payloader->pps_len > 0)
<         ? encode_base64 (payloader->pps, payloader->pps_len, &len) : NULL;
< 
<     if (sps)
<       sprops = g_strjoin (",", sps, pps, NULL);
<     else
<       sprops = g_strdup (pps);
---
>     sps = encode_base64 (payloader->sps, payloader->sps_len, &len);
>     pps = encode_base64 (payloader->pps, payloader->pps_len, &len);
588,590c560,562
<     gst_basertppayload_set_outcaps (basepayload, "profile-level-id",
<         G_TYPE_STRING, profile,
<         "sprop-parameter-sets", G_TYPE_STRING, sprops, NULL);
---
>     if (payloader->sprop_parameter_sets)
> 	  g_free (payloader->sprop_parameter_sets);
>     payloader->sprop_parameter_sets = g_strjoin (",", sps, pps, NULL);
592,593c564
<     GST_DEBUG ("outcaps udpate: profile=%s, sps=%s, pps=%s",
<         profile, GST_STR_NULL (sps), GST_STR_NULL (pps));
---
>     payloader->update_caps = TRUE;
595,597c566
<     g_free (sprops);
<     g_free (profile);
<     g_free (sps);
---
> 	g_free (sps);
764,767c733,738
<     /* skip to start code, if no start code is found, next will be size and we
<      * will not collect data. */
<     data += next;
<     size -= next;
---
>     if (next > 0)
>       {
>         /* skip to start code, if no start code is found, next will be size and we
>          * will not collect data. */
>         data += next;
>         size -= next;
769,770c740,742
<     GST_DEBUG_OBJECT (basepayload, "found first start at %u, bytes left %u",
<         next, size);
---
>         GST_WARNING_OBJECT (basepayload, "found first start at %u, bytes left %u",
>             next, size);
>       }
798,800c770,776
<       if (rtph264pay->profile_level_id != NULL &&
<           rtph264pay->sprop_parameter_sets != NULL) {
<         if (rtph264pay->update_caps) {
---
>       /* We know our stream is a valid H264 NAL packet,
>        * go parse it for SPS/PPS to enrich the caps */
>       gst_rtp_h264_pay_parse_sps_pps (basepayload, data, nal_len);
> 
>       if (rtph264pay->update_caps) {
> 	    if (rtph264pay->profile_level_id != NULL &&
>             rtph264pay->sprop_parameter_sets != NULL) {
811,814d786
<       } else {
<         /* We know our stream is a valid H264 NAL packet,
<          * go parse it for SPS/PPS to enrich the caps */
<         gst_rtp_h264_pay_parse_sps_pps (basepayload, data, nal_len);
