various: fix pad template leaks
[platform/upstream/gstreamer.git] / gst / rtp / gstrtph263pdepay.c
index 7d77573..37e8989 100644 (file)
@@ -1,5 +1,5 @@
 /* GStreamer
- * Copyright (C) <2005> Wim Taymans <wim@fluendo.com>
+ * Copyright (C) <2005> Wim Taymans <wim.taymans@gmail.com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
 #include <gst/rtp/gstrtpbuffer.h>
 #include "gstrtph263pdepay.h"
 
-/* elementfactory information */
-static const GstElementDetails gst_rtp_h263pdepay_details =
-GST_ELEMENT_DETAILS ("RTP packet depayloader",
-    "Codec/Depayloader/Network",
-    "Extracts H263/+/++ video from RTP packets (RFC 4629)",
-    "Wim Taymans <wim@fluendo.com>");
-
 static GstStaticPadTemplate gst_rtp_h263p_depay_src_template =
 GST_STATIC_PAD_TEMPLATE ("src",
     GST_PAD_SRC,
@@ -47,7 +40,8 @@ static GstStaticPadTemplate gst_rtp_h263p_depay_sink_template =
     GST_STATIC_CAPS ("application/x-rtp, "
         "media = (string) \"video\", "
         "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
-        "clock-rate = (int) 90000, " "encoding-name = (string) \"H263-1998\"; "
+        "clock-rate = (int) [1, MAX], "
+        "encoding-name = (string) \"H263-1998\"; "
         /* optional params */
         /* NOTE all optional SDP params must be strings in the caps */
         /*
@@ -72,7 +66,8 @@ static GstStaticPadTemplate gst_rtp_h263p_depay_sink_template =
         "application/x-rtp, "
         "media = (string) \"video\", "
         "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
-        "clock-rate = (int) 90000, " "encoding-name = (string) \"H263-2000\" "
+        "clock-rate = (int) [1, MAX], "
+        "encoding-name = (string) \"H263-2000\" "
         /* optional params */
         /* NOTE all optional SDP params must be strings in the caps */
         /*
@@ -101,13 +96,16 @@ gst_rtp_h263p_depay_base_init (gpointer klass)
 {
   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
 
-  gst_element_class_add_pad_template (element_class,
-      gst_static_pad_template_get (&gst_rtp_h263p_depay_src_template));
-  gst_element_class_add_pad_template (element_class,
-      gst_static_pad_template_get (&gst_rtp_h263p_depay_sink_template));
+  gst_element_class_add_static_pad_template (element_class,
+      &gst_rtp_h263p_depay_src_template);
+  gst_element_class_add_static_pad_template (element_class,
+      &gst_rtp_h263p_depay_sink_template);
 
 
-  gst_element_class_set_details (element_class, &gst_rtp_h263pdepay_details);
+  gst_element_class_set_details_simple (element_class, "RTP H263 depayloader",
+      "Codec/Depayloader/Network/RTP",
+      "Extracts H263/+/++ video from RTP packets (RFC 4629)",
+      "Wim Taymans <wim.taymans@gmail.com>");
 }
 
 static void
@@ -121,8 +119,6 @@ gst_rtp_h263p_depay_class_init (GstRtpH263PDepayClass * klass)
   gstelement_class = (GstElementClass *) klass;
   gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass;
 
-  parent_class = g_type_class_peek_parent (klass);
-
   gstbasertpdepayload_class->process = gst_rtp_h263p_depay_process;
   gstbasertpdepayload_class->set_caps = gst_rtp_h263p_depay_setcaps;
 
@@ -156,10 +152,12 @@ gst_rtp_h263p_depay_setcaps (GstBaseRTPDepayload * filter, GstCaps * caps)
 {
   GstCaps *srccaps = NULL;
   GstStructure *structure = gst_caps_get_structure (caps, 0);
-  gint clock_rate = 90000;      /* default */
+  gint clock_rate;
   const gchar *encoding_name = NULL;
+  gboolean res;
 
-  gst_structure_get_int (structure, "clock-rate", &clock_rate);
+  if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
+    clock_rate = 90000;         /* default */
   filter->clock_rate = clock_rate;
 
   encoding_name = gst_structure_get_string (structure, "encoding-name");
@@ -179,19 +177,19 @@ gst_rtp_h263p_depay_setcaps (GstBaseRTPDepayload * filter, GstCaps * caps)
 
     F = gst_structure_get_string (structure, "f");
     if (F)
-      if (g_strcasecmp (F, "1") == 0)
+      if (g_ascii_strcasecmp (F, "1") == 0)
         is_h263p = TRUE;
     I = gst_structure_get_string (structure, "i");
     if (I)
-      if (g_strcasecmp (I, "1") == 0)
+      if (g_ascii_strcasecmp (I, "1") == 0)
         is_h263p = TRUE;
     J = gst_structure_get_string (structure, "j");
     if (J)
-      if (g_strcasecmp (J, "1") == 0)
+      if (g_ascii_strcasecmp (J, "1") == 0)
         is_h263p = TRUE;
     T = gst_structure_get_string (structure, "t");
     if (T)
-      if (g_strcasecmp (T, "1") == 0)
+      if (g_ascii_strcasecmp (T, "1") == 0)
         is_h263p = TRUE;
     K = gst_structure_get_string (structure, "k");
     if (K)
@@ -216,10 +214,10 @@ gst_rtp_h263p_depay_setcaps (GstBaseRTPDepayload * filter, GstCaps * caps)
   if (!srccaps)
     goto no_caps;
 
-  gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (filter), srccaps);
+  res = gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (filter), srccaps);
   gst_caps_unref (srccaps);
 
-  return TRUE;
+  return res;
 
   /* ERRORS */
 no_encoding_name:
@@ -237,17 +235,14 @@ no_caps:
 static GstBuffer *
 gst_rtp_h263p_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
 {
-
   GstRtpH263PDepay *rtph263pdepay;
   GstBuffer *outbuf;
 
   rtph263pdepay = GST_RTP_H263P_DEPAY (depayload);
 
-  if (!gst_rtp_buffer_validate (buf))
-    goto bad_packet;
-
   /* flush remaining data on discont */
   if (GST_BUFFER_IS_DISCONT (buf)) {
+    GST_LOG_OBJECT (depayload, "DISCONT, flushing adapter");
     gst_adapter_clear (rtph263pdepay->adapter);
     rtph263pdepay->wait_start = TRUE;
   }
@@ -256,7 +251,6 @@ gst_rtp_h263p_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
     gint payload_len;
     guint8 *payload;
     gboolean P, V, M;
-    guint32 timestamp;
     guint header_len;
     guint8 PLEN, PEBIT;
 
@@ -266,7 +260,7 @@ gst_rtp_h263p_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
     header_len = 2;
 
     if (payload_len < header_len)
-      goto bad_packet;
+      goto too_small;
 
     M = gst_rtp_buffer_get_marker (buf);
 
@@ -281,6 +275,9 @@ gst_rtp_h263p_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
     PLEN = ((payload[0] & 0x1) << 5) | (payload[1] >> 3);
     PEBIT = payload[1] & 0x7;
 
+    GST_LOG_OBJECT (depayload, "P %d, V %d, PLEN %d, PEBIT %d", P, V, PLEN,
+        PEBIT);
+
     if (V) {
       header_len++;
     }
@@ -289,9 +286,11 @@ gst_rtp_h263p_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
     }
 
     if ((!P && payload_len < header_len) || (P && payload_len < header_len - 2))
-      goto bad_packet;
+      goto too_small;
 
     if (P) {
+      /* FIXME, have to make the packet writable hear. Better to reset these
+       * bytes when we copy the packet below */
       rtph263pdepay->wait_start = FALSE;
       header_len -= 2;
       payload[header_len] = 0;
@@ -301,19 +300,22 @@ gst_rtp_h263p_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
     if (rtph263pdepay->wait_start)
       goto waiting_start;
 
+    if (payload_len < header_len)
+      goto too_small;
+
     /* FIXME do not ignore the VRC header (See RFC 2429 section 4.2) */
     /* FIXME actually use the RTP picture header when it is lost in the network */
     /* for now strip off header */
     payload += header_len;
     payload_len -= header_len;
 
-    timestamp = gst_rtp_buffer_get_timestamp (buf);
-
     if (M) {
       /* frame is completed: append to previous, push it out */
       guint len, padlen;
       guint avail;
 
+      GST_LOG_OBJECT (depayload, "Frame complete");
+
       avail = gst_adapter_available (rtph263pdepay->adapter);
 
       len = avail + payload_len;
@@ -336,6 +338,8 @@ gst_rtp_h263p_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
       /* frame not completed: store in adapter */
       outbuf = gst_buffer_new_and_alloc (payload_len);
 
+      GST_LOG_OBJECT (depayload, "Frame incomplete, storing %d", payload_len);
+
       memcpy (GST_BUFFER_DATA (outbuf), payload, payload_len);
 
       gst_adapter_push (rtph263pdepay->adapter, outbuf);
@@ -343,10 +347,10 @@ gst_rtp_h263p_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
   }
   return NULL;
 
-bad_packet:
+too_small:
   {
     GST_ELEMENT_WARNING (rtph263pdepay, STREAM, DECODE,
-        ("Packet did not validate"), (NULL));
+        ("Packet payload was too small"), (NULL));
     return NULL;
   }
 waiting_start:
@@ -391,5 +395,5 @@ gboolean
 gst_rtp_h263p_depay_plugin_init (GstPlugin * plugin)
 {
   return gst_element_register (plugin, "rtph263pdepay",
-      GST_RANK_MARGINAL, GST_TYPE_RTP_H263P_DEPAY);
+      GST_RANK_SECONDARY, GST_TYPE_RTP_H263P_DEPAY);
 }