rtp: Update codes based on 1.18.4
[platform/upstream/gst-plugins-good.git] / gst / rtp / gstrtpspeexpay.c
index 994aee3..6f086b0 100644 (file)
@@ -1,5 +1,5 @@
 /* GStreamer
- * Copyright (C) <2005> Edgard Lima <edgard.lima@indt.org.br>
+ * Copyright (C) <2005> Edgard Lima <edgard.lima@gmail.com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -13,8 +13,8 @@
  *
  * You should have received a copy of the GNU Library General Public
  * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
  */
 
 #ifdef HAVE_CONFIG_H
 #include <stdlib.h>
 #include <string.h>
 #include <gst/rtp/gstrtpbuffer.h>
+#include <gst/audio/audio.h>
 
 #include "gstrtpspeexpay.h"
+#include "gstrtputils.h"
 
 GST_DEBUG_CATEGORY_STATIC (rtpspeexpay_debug);
 #define GST_CAT_DEFAULT (rtpspeexpay_debug)
@@ -78,14 +80,14 @@ gst_rtp_speex_pay_class_init (GstRtpSPEEXPayClass * klass)
   gstrtpbasepayload_class->get_caps = gst_rtp_speex_pay_getcaps;
   gstrtpbasepayload_class->handle_buffer = gst_rtp_speex_pay_handle_buffer;
 
-  gst_element_class_add_pad_template (gstelement_class,
-      gst_static_pad_template_get (&gst_rtp_speex_pay_sink_template));
-  gst_element_class_add_pad_template (gstelement_class,
-      gst_static_pad_template_get (&gst_rtp_speex_pay_src_template));
-  gst_element_class_set_details_simple (gstelement_class, "RTP Speex payloader",
-      "Codec/Payloader/Network/RTP",
+  gst_element_class_add_static_pad_template (gstelement_class,
+      &gst_rtp_speex_pay_sink_template);
+  gst_element_class_add_static_pad_template (gstelement_class,
+      &gst_rtp_speex_pay_src_template);
+  gst_element_class_set_static_metadata (gstelement_class,
+      "RTP Speex payloader", "Codec/Payloader/Network/RTP",
       "Payload-encodes Speex audio into a RTP packet",
-      "Edgard Lima <edgard.lima@indt.org.br>");
+      "Edgard Lima <edgard.lima@gmail.com>");
 
   GST_DEBUG_CATEGORY_INIT (rtpspeexpay_debug, "rtpspeexpay", 0,
       "Speex RTP Payloader");
@@ -236,13 +238,10 @@ gst_rtp_speex_pay_handle_buffer (GstRTPBasePayload * basepayload,
     GstBuffer * buffer)
 {
   GstRtpSPEEXPay *rtpspeexpay;
-  guint payload_len;
   GstMapInfo map;
   GstBuffer *outbuf;
-  guint8 *payload;
   GstClockTime timestamp, duration;
   GstFlowReturn ret;
-  GstRTPBuffer rtp = { NULL };
 
   rtpspeexpay = GST_RTP_SPEEX_PAY (basepayload);
 
@@ -252,53 +251,53 @@ gst_rtp_speex_pay_handle_buffer (GstRTPBasePayload * basepayload,
     case 0:
       /* ident packet. We need to parse the headers to construct the RTP
        * properties. */
-      if (!gst_rtp_speex_pay_parse_ident (rtpspeexpay, map.data, map.size))
+      if (!gst_rtp_speex_pay_parse_ident (rtpspeexpay, map.data, map.size)) {
+        gst_buffer_unmap (buffer, &map);
         goto parse_error;
+      }
 
       ret = GST_FLOW_OK;
+      gst_buffer_unmap (buffer, &map);
       goto done;
     case 1:
       /* comment packet, we ignore it */
       ret = GST_FLOW_OK;
+      gst_buffer_unmap (buffer, &map);
       goto done;
     default:
       /* other packets go in the payload */
       break;
   }
+  gst_buffer_unmap (buffer, &map);
 
   if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_GAP)) {
     ret = GST_FLOW_OK;
     goto done;
   }
 
-  timestamp = GST_BUFFER_TIMESTAMP (buffer);
+  timestamp = GST_BUFFER_PTS (buffer);
   duration = GST_BUFFER_DURATION (buffer);
 
   /* FIXME, only one SPEEX frame per RTP packet for now */
-  payload_len = map.size;
+  outbuf = gst_rtp_base_payload_allocate_output_buffer (basepayload, 0, 0, 0);
 
-  outbuf = gst_rtp_buffer_new_allocate (payload_len, 0, 0);
   /* FIXME, assert for now */
-  g_assert (payload_len <= GST_RTP_BASE_PAYLOAD_MTU (rtpspeexpay));
+  g_assert (gst_buffer_get_size (buffer) <=
+      GST_RTP_BASE_PAYLOAD_MTU (rtpspeexpay));
 
   /* copy timestamp and duration */
-  GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
+  GST_BUFFER_PTS (outbuf) = timestamp;
   GST_BUFFER_DURATION (outbuf) = duration;
 
-  gst_rtp_buffer_map (outbuf, GST_MAP_WRITE, &rtp);
-  /* get payload */
-  payload = gst_rtp_buffer_get_payload (&rtp);
-
-  /* copy data in payload */
-  memcpy (&payload[0], map.data, map.size);
-
-  gst_rtp_buffer_unmap (&rtp);
+  gst_rtp_copy_audio_meta (basepayload, outbuf, buffer);
+  outbuf = gst_buffer_append (outbuf, buffer);
+  buffer = NULL;
 
   ret = gst_rtp_base_payload_push (basepayload, outbuf);
 
 done:
-  gst_buffer_unmap (buffer, &map);
-  gst_buffer_unref (buffer);
+  if (buffer)
+    gst_buffer_unref (buffer);
 
   rtpspeexpay->packet++;
 
@@ -309,7 +308,6 @@ parse_error:
   {
     GST_ELEMENT_ERROR (rtpspeexpay, STREAM, DECODE, (NULL),
         ("Error parsing first identification packet."));
-    gst_buffer_unmap (buffer, &map);
     gst_buffer_unref (buffer);
     return GST_FLOW_ERROR;
   }