From 8449839ab1f115b33594467daa81e6347e67055c Mon Sep 17 00:00:00 2001 From: Philippe Kalaf Date: Thu, 23 Feb 2006 12:21:25 +0000 Subject: rtp/gst/: Separated the G711 payloaders/depayloaders into separate elements for mulaw/alaw. Also removed the old g711... Original commit message from CVS: 2006-02-23 Philippe Kalaf * rtp/gst/gstrtppcmadepay.c: * rtp/gst/gstrtppcmadepay.h: * rtp/gst/gstgstrtppcmapay.c: * rtp/gst/gstgstrtppcmapay.h: * rtp/gst/gstrtppcmudepay.c: * rtp/gst/gstrtppcmudepay.h: * rtp/gst/gstrtppcmupay.c: * rtp/gst/gstrtppcmupay.h: * rtp/gst/Makefile.am: * rtp/gst/gstrtp.c: * rtp/gst/README: Separated the G711 payloaders/depayloaders into separate elements for mulaw/alaw. Also removed the old g711 payloaders/depayloaders. --- gst/rtp/Makefile.am | 12 ++- gst/rtp/README | 5 + gst/rtp/gstrtp.c | 16 ++- gst/rtp/gstrtpg711depay.c | 182 --------------------------------- gst/rtp/gstrtpg711depay.h | 51 ---------- gst/rtp/gstrtpg711pay.c | 251 ---------------------------------------------- gst/rtp/gstrtpg711pay.h | 57 ----------- gst/rtp/gstrtppcmadepay.c | 160 +++++++++++++++++++++++++++++ gst/rtp/gstrtppcmadepay.h | 51 ++++++++++ gst/rtp/gstrtppcmapay.c | 230 ++++++++++++++++++++++++++++++++++++++++++ gst/rtp/gstrtppcmapay.h | 57 +++++++++++ gst/rtp/gstrtppcmudepay.c | 161 +++++++++++++++++++++++++++++ gst/rtp/gstrtppcmudepay.h | 51 ++++++++++ gst/rtp/gstrtppcmupay.c | 230 ++++++++++++++++++++++++++++++++++++++++++ gst/rtp/gstrtppcmupay.h | 57 +++++++++++ 15 files changed, 1022 insertions(+), 549 deletions(-) delete mode 100644 gst/rtp/gstrtpg711depay.c delete mode 100644 gst/rtp/gstrtpg711depay.h delete mode 100644 gst/rtp/gstrtpg711pay.c delete mode 100644 gst/rtp/gstrtpg711pay.h create mode 100644 gst/rtp/gstrtppcmadepay.c create mode 100644 gst/rtp/gstrtppcmadepay.h create mode 100644 gst/rtp/gstrtppcmapay.c create mode 100644 gst/rtp/gstrtppcmapay.h create mode 100644 gst/rtp/gstrtppcmudepay.c create mode 100644 gst/rtp/gstrtppcmudepay.h create mode 100644 gst/rtp/gstrtppcmupay.c create mode 100644 gst/rtp/gstrtppcmupay.h (limited to 'gst/rtp') diff --git a/gst/rtp/Makefile.am b/gst/rtp/Makefile.am index 27022321..82648b51 100644 --- a/gst/rtp/Makefile.am +++ b/gst/rtp/Makefile.am @@ -5,8 +5,10 @@ libgstrtp_la_SOURCES = \ gstrtpdepay.c \ gstrtpmpadepay.c \ gstrtpmpapay.c \ - gstrtpg711depay.c \ - gstrtpg711pay.c \ + gstrtppcmadepay.c \ + gstrtppcmudepay.c \ + gstrtppcmupay.c \ + gstrtppcmapay.c \ gstrtpgsmdepay.c \ gstrtpgsmpay.c \ gstrtpamrdepay.c \ @@ -39,8 +41,10 @@ noinst_HEADERS = \ gstrtpL16pay.h \ gstrtpamrdepay.h \ gstrtpamrpay.h \ - gstrtpg711depay.h \ - gstrtpg711pay.h \ + gstrtppcmadepay.h \ + gstrtppcmudepay.h \ + gstrtppcmupay.h \ + gstrtppcmapay.h \ gstrtpgsmdepay.h \ gstrtpgsmpay.h \ gstrtpmpadepay.h \ diff --git a/gst/rtp/README b/gst/rtp/README index 0f73809d..146c55fa 100644 --- a/gst/rtp/README +++ b/gst/rtp/README @@ -1,3 +1,8 @@ +This directory contains some RTP payloaders/depayloaders for different payload +types. Use one payloader/depayloder pair per payload. If several payloads can be +payloaded/depayloaded by the same element, make different copies of it, one for +each payload. + The application/x-rtp mime type ------------------------------- diff --git a/gst/rtp/gstrtp.c b/gst/rtp/gstrtp.c index b412e787..e80d4d6d 100644 --- a/gst/rtp/gstrtp.c +++ b/gst/rtp/gstrtp.c @@ -22,8 +22,10 @@ #endif #include "gstrtpdepay.h" -#include "gstrtpg711pay.h" -#include "gstrtpg711depay.h" +#include "gstrtppcmupay.h" +#include "gstrtppcmapay.h" +#include "gstrtppcmadepay.h" +#include "gstrtppcmudepay.h" #include "gstrtpgsmpay.h" #include "gstrtpgsmdepay.h" #include "gstrtpamrpay.h" @@ -58,10 +60,16 @@ plugin_init (GstPlugin * plugin) if (!gst_rtp_amr_pay_plugin_init (plugin)) return FALSE; - if (!gst_rtp_g711_depay_plugin_init (plugin)) + if (!gst_rtp_pcma_depay_plugin_init (plugin)) return FALSE; - if (!gst_rtp_g711_pay_plugin_init (plugin)) + if (!gst_rtp_pcmu_depay_plugin_init (plugin)) + return FALSE; + + if (!gst_rtp_pcmu_pay_plugin_init (plugin)) + return FALSE; + + if (!gst_rtp_pcma_pay_plugin_init (plugin)) return FALSE; if (!gst_rtp_mpa_depay_plugin_init (plugin)) diff --git a/gst/rtp/gstrtpg711depay.c b/gst/rtp/gstrtpg711depay.c deleted file mode 100644 index e4cc6cef..00000000 --- a/gst/rtp/gstrtpg711depay.c +++ /dev/null @@ -1,182 +0,0 @@ -/* GStreamer - * Copyright (C) <1999> Erik Walthinsen - * Copyright (C) <2005> Edgard Lima - * Copyright (C) <2005> Zeeshan Ali - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include -#include "gstrtpg711depay.h" - -/* elementfactory information */ -static GstElementDetails gst_rtp_g711depay_details = { - "RTP packet parser", - "Codec/Depayr/Network", - "Extracts PCMU/PCMA audio from RTP packets", - "Edgard Lima , Zeeshan Ali " -}; - -/* RtpG711Depay signals and args */ -enum -{ - /* FILL ME */ - LAST_SIGNAL -}; - -enum -{ - ARG_0 -}; - -static GstStaticPadTemplate gst_rtp_g711_depay_sink_template = - GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("application/x-rtp, " - "media = (string) \"audio\", " - "clock-rate = (int) 8000, " - "encoding-name = (string) \"PCMU\"; " - "application/x-rtp, " - "media = (string) \"audio\", " - "clock-rate = (int) 8000, " "encoding-name = (string) \"PCMA\"") - - ); - -static GstStaticPadTemplate gst_rtp_g711_depay_src_template = - GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("audio/x-mulaw, " - "channels = (int) 1; " "audio/x-alaw, " "channels = (int) 1") - ); - -static GstBuffer *gst_rtp_g711_depay_process (GstBaseRTPDepayload * depayload, - GstBuffer * buf); -static gboolean gst_rtp_g711_depay_setcaps (GstBaseRTPDepayload * depayload, - GstCaps * caps); - -GST_BOILERPLATE (GstRtpG711Depay, gst_rtp_g711_depay, GstBaseRTPDepayload, - GST_TYPE_BASE_RTP_DEPAYLOAD); - -static void -gst_rtp_g711_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_g711_depay_src_template)); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&gst_rtp_g711_depay_sink_template)); - gst_element_class_set_details (element_class, &gst_rtp_g711depay_details); -} - -static void -gst_rtp_g711_depay_class_init (GstRtpG711DepayClass * klass) -{ - GObjectClass *gobject_class; - GstElementClass *gstelement_class; - GstBaseRTPDepayloadClass *gstbasertpdepayload_class; - - gobject_class = (GObjectClass *) klass; - gstelement_class = (GstElementClass *) klass; - gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass; - - parent_class = g_type_class_ref (GST_TYPE_BASE_RTP_DEPAYLOAD); - - gstbasertpdepayload_class->process = gst_rtp_g711_depay_process; - gstbasertpdepayload_class->set_caps = gst_rtp_g711_depay_setcaps; -} - -static void -gst_rtp_g711_depay_init (GstRtpG711Depay * rtpg711depay, - GstRtpG711DepayClass * klass) -{ - GstBaseRTPDepayload *depayload; - - depayload = GST_BASE_RTP_DEPAYLOAD (rtpg711depay); - - depayload->clock_rate = 8000; - gst_pad_use_fixed_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload)); -} - -static gboolean -gst_rtp_g711_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps) -{ - GstCaps *srccaps; - const gchar *pay_name; - GstStructure *structure; - gboolean ret; - - structure = gst_caps_get_structure (caps, 0); - pay_name = gst_structure_get_string (structure, "encoding-name"); - - if (NULL == pay_name) { - return FALSE; - } - - if (0 == strcmp ("PCMU", pay_name)) { - srccaps = gst_caps_new_simple ("audio/x-mulaw", - "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL); - } else if (0 == strcmp ("PCMA", pay_name)) { - srccaps = gst_caps_new_simple ("audio/x-alaw", - "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL); - } else { - return FALSE; - } - - ret = gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload), srccaps); - gst_caps_unref (srccaps); - - return ret; -} - -static GstBuffer * -gst_rtp_g711_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) -{ - GstCaps *srccaps; - GstBuffer *outbuf = NULL; - gint payload_len; - guint8 *payload; - - GST_DEBUG ("process : got %d bytes, mark %d ts %u seqn %d", - GST_BUFFER_SIZE (buf), - gst_rtp_buffer_get_marker (buf), - gst_rtp_buffer_get_timestamp (buf), gst_rtp_buffer_get_seq (buf)); - - srccaps = GST_PAD_CAPS (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload)); - if (!srccaps) { - /* Set the default caps */ - srccaps = gst_caps_new_simple ("audio/x-mulaw", - "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL); - gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload), srccaps); - gst_caps_unref (srccaps); - } - - payload_len = gst_rtp_buffer_get_payload_len (buf); - payload = gst_rtp_buffer_get_payload (buf); - - outbuf = gst_buffer_new_and_alloc (payload_len); - memcpy (GST_BUFFER_DATA (outbuf), payload, payload_len); - return outbuf; -} - -gboolean -gst_rtp_g711_depay_plugin_init (GstPlugin * plugin) -{ - return gst_element_register (plugin, "rtpg711depay", - GST_RANK_NONE, GST_TYPE_RTP_G711_DEPAY); -} diff --git a/gst/rtp/gstrtpg711depay.h b/gst/rtp/gstrtpg711depay.h deleted file mode 100644 index d4ca5fcf..00000000 --- a/gst/rtp/gstrtpg711depay.h +++ /dev/null @@ -1,51 +0,0 @@ -/* GStreamer - * Copyright (C) <2005> Edgard Lima - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more - */ - -#ifndef __GST_RTP_G711_DEPAY_H__ -#define __GST_RTP_G711_DEPAY_H__ - -#include -#include - -G_BEGIN_DECLS - -typedef struct _GstRtpG711Depay GstRtpG711Depay; -typedef struct _GstRtpG711DepayClass GstRtpG711DepayClass; - -#define GST_TYPE_RTP_G711_DEPAY \ - (gst_rtp_g711_depay_get_type()) -#define GST_RTP_G711_DEPAY(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_RTP_G711_DEPAY,GstRtpG711Depay)) -#define GST_RTP_G711_DEPAY_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_RTP_G711_DEPAY,GstRtpG711Depay)) -#define GST_IS_RTP_G711_DEPAY(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_RTP_G711_DEPAY)) -#define GST_IS_RTP_G711_DEPAY_CLASS(obj) \ - (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_RTP_G711_DEPAY)) - -struct _GstRtpG711Depay -{ - GstBaseRTPDepayload depayload; -}; - -struct _GstRtpG711DepayClass -{ - GstBaseRTPDepayloadClass parent_class; -}; - -gboolean gst_rtp_g711_depay_plugin_init (GstPlugin * plugin); - -G_END_DECLS - -#endif /* __GST_RTP_G711_DEPAY_H__ */ diff --git a/gst/rtp/gstrtpg711pay.c b/gst/rtp/gstrtpg711pay.c deleted file mode 100644 index cd936fca..00000000 --- a/gst/rtp/gstrtpg711pay.c +++ /dev/null @@ -1,251 +0,0 @@ -/* GStreamer - * Copyright (C) <1999> Erik Walthinsen - * Copyright (C) <2005> Edgard Lima - * Copyright (C) <2005> Nokia Corporation - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include -#include - -#include "gstrtpg711pay.h" - -/* elementfactory information */ -static GstElementDetails gst_rtp_g711_pay_details = { - "RTP packet parser", - "Codec/Payloader/Network", - "Payload-encodes PCMU/PCMA audio into a RTP packet", - "Edgard Lima " -}; - -static GstStaticPadTemplate gst_rtp_g711_pay_sink_template = - GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("audio/x-mulaw, channels=(int)1, rate=(int)8000 ;" - "audio/x-alaw, channels=(int)1, rate=(int)8000") - ); - -static GstStaticPadTemplate gst_rtp_g711_pay_src_template = - GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("application/x-rtp, " - "media = (string) \"audio\", " - "payload = (int) " GST_RTP_PAYLOAD_PCMU_STRING ", " - "clock-rate = (int) 8000, " - "encoding-name = (string) \"PCMU\"; " - "application/x-rtp, " - "media = (string) \"audio\", " - "payload = (int) " GST_RTP_PAYLOAD_PCMA_STRING ", " - "clock-rate = (int) 8000, " "encoding-name = (string) \"PCMA\"") - ); - -static gboolean gst_rtp_g711_pay_setcaps (GstBaseRTPPayload * payload, - GstCaps * caps); -static GstFlowReturn gst_rtp_g711_pay_handle_buffer (GstBaseRTPPayload * - payload, GstBuffer * buffer); -static void gst_rtp_g711_pay_finalize (GObject * object); - -GST_BOILERPLATE (GstRtpG711Pay, gst_rtp_g711_pay, GstBaseRTPPayload, - GST_TYPE_BASE_RTP_PAYLOAD); - -/* The lower limit for number of octet to put in one packet - * (clock-rate=8000, octet-per-sample=1). The default 80 is equal - * to to 10msec (see RFC3551) */ -#define GST_RTP_G711_MIN_PTIME_OCTETS 80 - -static void -gst_rtp_g711_pay_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_g711_pay_sink_template)); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&gst_rtp_g711_pay_src_template)); - gst_element_class_set_details (element_class, &gst_rtp_g711_pay_details); -} - -static void -gst_rtp_g711_pay_class_init (GstRtpG711PayClass * klass) -{ - GObjectClass *gobject_class; - GstElementClass *gstelement_class; - GstBaseRTPPayloadClass *gstbasertppayload_class; - - gobject_class = (GObjectClass *) klass; - gstelement_class = (GstElementClass *) klass; - gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass; - - parent_class = g_type_class_ref (GST_TYPE_BASE_RTP_PAYLOAD); - gobject_class->finalize = gst_rtp_g711_pay_finalize; - - gstbasertppayload_class->set_caps = gst_rtp_g711_pay_setcaps; - gstbasertppayload_class->handle_buffer = gst_rtp_g711_pay_handle_buffer; -} - -static void -gst_rtp_g711_pay_init (GstRtpG711Pay * rtpg711pay, GstRtpG711PayClass * klass) -{ - rtpg711pay->adapter = gst_adapter_new (); - GST_BASE_RTP_PAYLOAD (rtpg711pay)->clock_rate = 8000; -} - -static void -gst_rtp_g711_pay_finalize (GObject * object) -{ - GstRtpG711Pay *rtpg711pay; - - rtpg711pay = GST_RTP_G711_PAY (object); - - g_object_unref (rtpg711pay->adapter); - rtpg711pay->adapter = NULL; - - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -static gboolean -gst_rtp_g711_pay_setcaps (GstBaseRTPPayload * payload, GstCaps * caps) -{ - - const char *stname; - GstStructure *structure; - - structure = gst_caps_get_structure (caps, 0); - - stname = gst_structure_get_name (structure); - - if (0 == strcmp ("audio/x-mulaw", stname)) { - payload->pt = GST_RTP_PAYLOAD_PCMU; - gst_basertppayload_set_options (payload, "audio", FALSE, "PCMU", 8000); - } else if (0 == strcmp ("audio/x-alaw", stname)) { - payload->pt = GST_RTP_PAYLOAD_PCMA; - gst_basertppayload_set_options (payload, "audio", FALSE, "PCMA", 8000); - } else { - return FALSE; - } - - gst_basertppayload_set_outcaps (payload, NULL); - - return TRUE; -} - -static GstFlowReturn -gst_rtp_g711_pay_flush (GstRtpG711Pay * rtpg711pay) -{ - guint avail; - GstBuffer *outbuf; - GstFlowReturn ret; - guint maxptime_octets = G_MAXUINT; - guint minptime_octets = GST_RTP_G711_MIN_PTIME_OCTETS; - - if (GST_BASE_RTP_PAYLOAD (rtpg711pay)->max_ptime > 0) { - /* calculate octet count with: - maxptime-nsec * samples-per-sec / nsecs-per-sec * octets-per-sample */ - maxptime_octets = - GST_BASE_RTP_PAYLOAD (rtpg711pay)->max_ptime * - GST_BASE_RTP_PAYLOAD (rtpg711pay)->clock_rate / GST_SECOND; - } - - /* the data available in the adapter is either smaller - * than the MTU or bigger. In the case it is smaller, the complete - * adapter contents can be put in one packet. */ - avail = gst_adapter_available (rtpg711pay->adapter); - - ret = GST_FLOW_OK; - - while (avail >= minptime_octets) { - guint8 *payload; - guint8 *data; - guint payload_len; - guint packet_len; - - /* fill one MTU or all available bytes */ - payload_len = - MIN (MIN (GST_BASE_RTP_PAYLOAD_MTU (rtpg711pay), maxptime_octets), - avail); - - /* this will be the total lenght of the packet */ - packet_len = gst_rtp_buffer_calc_packet_len (payload_len, 0, 0); - - /* create buffer to hold the payload */ - outbuf = gst_rtp_buffer_new_allocate (payload_len, 0, 0); - - /* copy payload */ - gst_rtp_buffer_set_payload_type (outbuf, - GST_BASE_RTP_PAYLOAD_PT (rtpg711pay)); - payload = gst_rtp_buffer_get_payload (outbuf); - data = (guint8 *) gst_adapter_peek (rtpg711pay->adapter, payload_len); - memcpy (payload, data, payload_len); - gst_adapter_flush (rtpg711pay->adapter, payload_len); - - avail -= payload_len; - - GST_BUFFER_TIMESTAMP (outbuf) = rtpg711pay->first_ts; - ret = gst_basertppayload_push (GST_BASE_RTP_PAYLOAD (rtpg711pay), outbuf); - } - - return ret; -} - -static GstFlowReturn -gst_rtp_g711_pay_handle_buffer (GstBaseRTPPayload * basepayload, - GstBuffer * buffer) -{ - GstRtpG711Pay *rtpg711pay; - guint size, packet_len, avail; - GstFlowReturn ret; - GstClockTime duration; - - rtpg711pay = GST_RTP_G711_PAY (basepayload); - - size = GST_BUFFER_SIZE (buffer); - duration = GST_BUFFER_TIMESTAMP (buffer); - - avail = gst_adapter_available (rtpg711pay->adapter); - if (avail == 0) { - rtpg711pay->first_ts = GST_BUFFER_TIMESTAMP (buffer); - rtpg711pay->duration = 0; - } - - /* get packet length of data and see if we exceeded MTU. */ - packet_len = gst_rtp_buffer_calc_packet_len (avail + size, 0, 0); - - /* if this buffer is going to overflow the packet, flush what we - * have. */ - if (gst_basertppayload_is_filled (basepayload, - packet_len, rtpg711pay->duration + duration)) { - ret = gst_rtp_g711_pay_flush (rtpg711pay); - rtpg711pay->first_ts = GST_BUFFER_TIMESTAMP (buffer); - rtpg711pay->duration = 0; - } else { - ret = GST_FLOW_OK; - } - - gst_adapter_push (rtpg711pay->adapter, buffer); - rtpg711pay->duration += duration; - - return ret; -} - -gboolean -gst_rtp_g711_pay_plugin_init (GstPlugin * plugin) -{ - return gst_element_register (plugin, "rtpg711pay", - GST_RANK_NONE, GST_TYPE_RTP_G711_PAY); -} diff --git a/gst/rtp/gstrtpg711pay.h b/gst/rtp/gstrtpg711pay.h deleted file mode 100644 index c43c66bc..00000000 --- a/gst/rtp/gstrtpg711pay.h +++ /dev/null @@ -1,57 +0,0 @@ -/* GStreamer - * Copyright (C) <2005> Edgard Lima - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more - */ - - -#ifndef __GST_RTP_G711_PAY_H__ -#define __GST_RTP_G711_PAY_H__ - -#include -#include -#include - -G_BEGIN_DECLS - -typedef struct _GstRtpG711Pay GstRtpG711Pay; -typedef struct _GstRtpG711PayClass GstRtpG711PayClass; - -#define GST_TYPE_RTP_G711_PAY \ - (gst_rtp_g711_pay_get_type()) -#define GST_RTP_G711_PAY(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_RTP_G711_PAY,GstRtpG711Pay)) -#define GST_RTP_G711_PAY_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_RTP_G711_PAY,GstRtpG711Pay)) -#define GST_IS_RTP_G711_PAY(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_RTP_G711_PAY)) -#define GST_IS_RTP_G711_PAY_CLASS(obj) \ - (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_RTP_G711_PAY)) - -struct _GstRtpG711Pay -{ - GstBaseRTPPayload payload; - GstAdapter *adapter; - - GstClockTime first_ts; - GstClockTime duration; -}; - -struct _GstRtpG711PayClass -{ - GstBaseRTPPayloadClass parent_class; -}; - -gboolean gst_rtp_g711_pay_plugin_init (GstPlugin * plugin); - -G_END_DECLS - -#endif /* __GST_RTP_G711_PAY_H__ */ diff --git a/gst/rtp/gstrtppcmadepay.c b/gst/rtp/gstrtppcmadepay.c new file mode 100644 index 00000000..a381fe6b --- /dev/null +++ b/gst/rtp/gstrtppcmadepay.c @@ -0,0 +1,160 @@ +/* GStreamer + * Copyright (C) <1999> Erik Walthinsen + * Copyright (C) <2005> Edgard Lima + * Copyright (C) <2005> Zeeshan Ali + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include "gstrtppcmadepay.h" + +/* elementfactory information */ +static GstElementDetails gst_rtp_pcmadepay_details = { + "RTP packet parser", + "Codec/Depayr/Network", + "Extracts PCMA audio from RTP packets", + "Edgard Lima , Zeeshan Ali " +}; + +/* RtpPcmaDepay signals and args */ +enum +{ + /* FILL ME */ + LAST_SIGNAL +}; + +enum +{ + ARG_0 +}; + +static GstStaticPadTemplate gst_rtp_pcma_depay_sink_template = +GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("application/x-rtp, " + "media = (string) \"audio\", " + "clock-rate = (int) 8000, " "encoding-name = (string) \"PCMA\"") + ); + +static GstStaticPadTemplate gst_rtp_pcma_depay_src_template = +GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("audio/x-alaw, " "channels = (int) 1") + ); + +static GstBuffer *gst_rtp_pcma_depay_process (GstBaseRTPDepayload * depayload, + GstBuffer * buf); +static gboolean gst_rtp_pcma_depay_setcaps (GstBaseRTPDepayload * depayload, + GstCaps * caps); + +GST_BOILERPLATE (GstRtpPcmaDepay, gst_rtp_pcma_depay, GstBaseRTPDepayload, + GST_TYPE_BASE_RTP_DEPAYLOAD); + +static void +gst_rtp_pcma_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_pcma_depay_src_template)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&gst_rtp_pcma_depay_sink_template)); + gst_element_class_set_details (element_class, &gst_rtp_pcmadepay_details); +} + +static void +gst_rtp_pcma_depay_class_init (GstRtpPcmaDepayClass * klass) +{ + GObjectClass *gobject_class; + GstElementClass *gstelement_class; + GstBaseRTPDepayloadClass *gstbasertpdepayload_class; + + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; + gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass; + + parent_class = g_type_class_ref (GST_TYPE_BASE_RTP_DEPAYLOAD); + + gstbasertpdepayload_class->process = gst_rtp_pcma_depay_process; + gstbasertpdepayload_class->set_caps = gst_rtp_pcma_depay_setcaps; +} + +static void +gst_rtp_pcma_depay_init (GstRtpPcmaDepay * rtppcmadepay, + GstRtpPcmaDepayClass * klass) +{ + GstBaseRTPDepayload *depayload; + + depayload = GST_BASE_RTP_DEPAYLOAD (rtppcmadepay); + + depayload->clock_rate = 8000; + gst_pad_use_fixed_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload)); +} + +static gboolean +gst_rtp_pcma_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps) +{ + GstCaps *srccaps; + gboolean ret; + + srccaps = gst_caps_new_simple ("audio/x-alaw", + "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL); + + ret = gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload), srccaps); + gst_caps_unref (srccaps); + + return ret; +} + +static GstBuffer * +gst_rtp_pcma_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) +{ + GstCaps *srccaps; + GstBuffer *outbuf = NULL; + gint payload_len; + guint8 *payload; + + GST_DEBUG ("process : got %d bytes, mark %d ts %u seqn %d", + GST_BUFFER_SIZE (buf), + gst_rtp_buffer_get_marker (buf), + gst_rtp_buffer_get_timestamp (buf), gst_rtp_buffer_get_seq (buf)); + + srccaps = GST_PAD_CAPS (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload)); + if (!srccaps) { + /* Set the default caps */ + srccaps = gst_caps_new_simple ("audio/x-mulaw", + "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL); + gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload), srccaps); + gst_caps_unref (srccaps); + } + + payload_len = gst_rtp_buffer_get_payload_len (buf); + payload = gst_rtp_buffer_get_payload (buf); + + outbuf = gst_buffer_new_and_alloc (payload_len); + memcpy (GST_BUFFER_DATA (outbuf), payload, payload_len); + return outbuf; +} + +gboolean +gst_rtp_pcma_depay_plugin_init (GstPlugin * plugin) +{ + return gst_element_register (plugin, "rtppcmadepay", + GST_RANK_NONE, GST_TYPE_RTP_PCMA_DEPAY); +} diff --git a/gst/rtp/gstrtppcmadepay.h b/gst/rtp/gstrtppcmadepay.h new file mode 100644 index 00000000..ca9082ec --- /dev/null +++ b/gst/rtp/gstrtppcmadepay.h @@ -0,0 +1,51 @@ +/* GStreamer + * Copyright (C) <2005> Edgard Lima + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more + */ + +#ifndef __GST_RTP_PCMA_DEPAY_H__ +#define __GST_RTP_PCMA_DEPAY_H__ + +#include +#include + +G_BEGIN_DECLS + +typedef struct _GstRtpPcmaDepay GstRtpPcmaDepay; +typedef struct _GstRtpPcmaDepayClass GstRtpPcmaDepayClass; + +#define GST_TYPE_RTP_PCMA_DEPAY \ + (gst_rtp_pcma_depay_get_type()) +#define GST_RTP_PCMA_DEPAY(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_RTP_PCMA_DEPAY,GstRtpPcmaDepay)) +#define GST_RTP_PCMA_DEPAY_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_RTP_PCMA_DEPAY,GstRtpPcmaDepay)) +#define GST_IS_RTP_PCMA_DEPAY(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_RTP_PCMA_DEPAY)) +#define GST_IS_RTP_PCMA_DEPAY_CLASS(obj) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_RTP_PCMA_DEPAY)) + +struct _GstRtpPcmaDepay +{ + GstBaseRTPDepayload depayload; +}; + +struct _GstRtpPcmaDepayClass +{ + GstBaseRTPDepayloadClass parent_class; +}; + +gboolean gst_rtp_pcma_depay_plugin_init (GstPlugin * plugin); + +G_END_DECLS + +#endif /* __GST_RTP_PCMA_DEPAY_H__ */ diff --git a/gst/rtp/gstrtppcmapay.c b/gst/rtp/gstrtppcmapay.c new file mode 100644 index 00000000..bb99e700 --- /dev/null +++ b/gst/rtp/gstrtppcmapay.c @@ -0,0 +1,230 @@ +/* GStreamer + * Copyright (C) <1999> Erik Walthinsen + * Copyright (C) <2005> Edgard Lima + * Copyright (C) <2005> Nokia Corporation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include + +#include "gstrtppcmapay.h" + +/* elementfactory information */ +static GstElementDetails gst_rtp_pcma_pay_details = { + "RTP packet parser", + "Codec/Payloader/Network", + "Payload-encodes PCMA audio into a RTP packet", + "Edgard Lima " +}; + +static GstStaticPadTemplate gst_rtp_pcma_pay_sink_template = +GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("audio/x-alaw, channels=(int)1, rate=(int)8000") + ); + +static GstStaticPadTemplate gst_rtp_pcma_pay_src_template = +GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("application/x-rtp, " + "media = (string) \"audio\", " + "payload = (int) " GST_RTP_PAYLOAD_PCMA_STRING ", " + "clock-rate = (int) 8000, " "encoding-name = (string) \"PCMA\" ") + ); + +static gboolean gst_rtp_pcma_pay_setcaps (GstBaseRTPPayload * payload, + GstCaps * caps); +static GstFlowReturn gst_rtp_pcma_pay_handle_buffer (GstBaseRTPPayload * + payload, GstBuffer * buffer); +static void gst_rtp_pcma_pay_finalize (GObject * object); + +GST_BOILERPLATE (GstRtpPmcaPay, gst_rtp_pcma_pay, GstBaseRTPPayload, + GST_TYPE_BASE_RTP_PAYLOAD); + +/* The lower limit for number of octet to put in one packet + * (clock-rate=8000, octet-per-sample=1). The default 80 is equal + * to to 10msec (see RFC3551) */ +#define GST_RTP_PCMA_MIN_PTIME_OCTETS 80 + +static void +gst_rtp_pcma_pay_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_pcma_pay_sink_template)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&gst_rtp_pcma_pay_src_template)); + gst_element_class_set_details (element_class, &gst_rtp_pcma_pay_details); +} + +static void +gst_rtp_pcma_pay_class_init (GstRtpPmcaPayClass * klass) +{ + GObjectClass *gobject_class; + GstElementClass *gstelement_class; + GstBaseRTPPayloadClass *gstbasertppayload_class; + + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; + gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass; + + parent_class = g_type_class_ref (GST_TYPE_BASE_RTP_PAYLOAD); + gobject_class->finalize = gst_rtp_pcma_pay_finalize; + + gstbasertppayload_class->set_caps = gst_rtp_pcma_pay_setcaps; + gstbasertppayload_class->handle_buffer = gst_rtp_pcma_pay_handle_buffer; +} + +static void +gst_rtp_pcma_pay_init (GstRtpPmcaPay * rtppcmapay, GstRtpPmcaPayClass * klass) +{ + rtppcmapay->adapter = gst_adapter_new (); + GST_BASE_RTP_PAYLOAD (rtppcmapay)->clock_rate = 8000; +} + +static void +gst_rtp_pcma_pay_finalize (GObject * object) +{ + GstRtpPmcaPay *rtppcmapay; + + rtppcmapay = GST_RTP_PCMA_PAY (object); + + g_object_unref (rtppcmapay->adapter); + rtppcmapay->adapter = NULL; + + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +static gboolean +gst_rtp_pcma_pay_setcaps (GstBaseRTPPayload * payload, GstCaps * caps) +{ + payload->pt = GST_RTP_PAYLOAD_PCMA; + gst_basertppayload_set_options (payload, "audio", FALSE, "PCMA", 8000); + + gst_basertppayload_set_outcaps (payload, NULL); + + return TRUE; +} + +static GstFlowReturn +gst_rtp_pcma_pay_flush (GstRtpPmcaPay * rtppcmapay) +{ + guint avail; + GstBuffer *outbuf; + GstFlowReturn ret; + guint maxptime_octets = G_MAXUINT; + guint minptime_octets = GST_RTP_PCMA_MIN_PTIME_OCTETS; + + if (GST_BASE_RTP_PAYLOAD (rtppcmapay)->max_ptime > 0) { + /* calculate octet count with: + maxptime-nsec * samples-per-sec / nsecs-per-sec * octets-per-sample */ + maxptime_octets = + GST_BASE_RTP_PAYLOAD (rtppcmapay)->max_ptime * + GST_BASE_RTP_PAYLOAD (rtppcmapay)->clock_rate / GST_SECOND; + } + + /* the data available in the adapter is either smaller + * than the MTU or bigger. In the case it is smaller, the complete + * adapter contents can be put in one packet. */ + avail = gst_adapter_available (rtppcmapay->adapter); + + ret = GST_FLOW_OK; + + while (avail >= minptime_octets) { + guint8 *payload; + guint8 *data; + guint payload_len; + guint packet_len; + + /* fill one MTU or all available bytes */ + payload_len = + MIN (MIN (GST_BASE_RTP_PAYLOAD_MTU (rtppcmapay), maxptime_octets), + avail); + + /* this will be the total lenght of the packet */ + packet_len = gst_rtp_buffer_calc_packet_len (payload_len, 0, 0); + + /* create buffer to hold the payload */ + outbuf = gst_rtp_buffer_new_allocate (payload_len, 0, 0); + + /* copy payload */ + gst_rtp_buffer_set_payload_type (outbuf, + GST_BASE_RTP_PAYLOAD_PT (rtppcmapay)); + payload = gst_rtp_buffer_get_payload (outbuf); + data = (guint8 *) gst_adapter_peek (rtppcmapay->adapter, payload_len); + memcpy (payload, data, payload_len); + gst_adapter_flush (rtppcmapay->adapter, payload_len); + + avail -= payload_len; + + GST_BUFFER_TIMESTAMP (outbuf) = rtppcmapay->first_ts; + ret = gst_basertppayload_push (GST_BASE_RTP_PAYLOAD (rtppcmapay), outbuf); + } + + return ret; +} + +static GstFlowReturn +gst_rtp_pcma_pay_handle_buffer (GstBaseRTPPayload * basepayload, + GstBuffer * buffer) +{ + GstRtpPmcaPay *rtppcmapay; + guint size, packet_len, avail; + GstFlowReturn ret; + GstClockTime duration; + + rtppcmapay = GST_RTP_PCMA_PAY (basepayload); + + size = GST_BUFFER_SIZE (buffer); + duration = GST_BUFFER_TIMESTAMP (buffer); + + avail = gst_adapter_available (rtppcmapay->adapter); + if (avail == 0) { + rtppcmapay->first_ts = GST_BUFFER_TIMESTAMP (buffer); + rtppcmapay->duration = 0; + } + + /* get packet length of data and see if we exceeded MTU. */ + packet_len = gst_rtp_buffer_calc_packet_len (avail + size, 0, 0); + + /* if this buffer is going to overflow the packet, flush what we + * have. */ + if (gst_basertppayload_is_filled (basepayload, + packet_len, rtppcmapay->duration + duration)) { + ret = gst_rtp_pcma_pay_flush (rtppcmapay); + rtppcmapay->first_ts = GST_BUFFER_TIMESTAMP (buffer); + rtppcmapay->duration = 0; + } else { + ret = GST_FLOW_OK; + } + + gst_adapter_push (rtppcmapay->adapter, buffer); + rtppcmapay->duration += duration; + + return ret; +} + +gboolean +gst_rtp_pcma_pay_plugin_init (GstPlugin * plugin) +{ + return gst_element_register (plugin, "rtppcmapay", + GST_RANK_NONE, GST_TYPE_RTP_PCMA_PAY); +} diff --git a/gst/rtp/gstrtppcmapay.h b/gst/rtp/gstrtppcmapay.h new file mode 100644 index 00000000..0d498544 --- /dev/null +++ b/gst/rtp/gstrtppcmapay.h @@ -0,0 +1,57 @@ +/* GStreamer + * Copyright (C) <2005> Edgard Lima + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more + */ + + +#ifndef __GST_RTP_PCMA_PAY_H__ +#define __GST_RTP_PCMA_PAY_H__ + +#include +#include +#include + +G_BEGIN_DECLS + +typedef struct _GstRtpPmcaPay GstRtpPmcaPay; +typedef struct _GstRtpPmcaPayClass GstRtpPmcaPayClass; + +#define GST_TYPE_RTP_PCMA_PAY \ + (gst_rtp_pcma_pay_get_type()) +#define GST_RTP_PCMA_PAY(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_RTP_PCMA_PAY,GstRtpPmcaPay)) +#define GST_RTP_PCMA_PAY_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_RTP_PCMA_PAY,GstRtpPmcaPay)) +#define GST_IS_RTP_PCMA_PAY(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_RTP_PCMA_PAY)) +#define GST_IS_RTP_PCMA_PAY_CLASS(obj) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_RTP_PCMA_PAY)) + +struct _GstRtpPmcaPay +{ + GstBaseRTPPayload payload; + GstAdapter *adapter; + + GstClockTime first_ts; + GstClockTime duration; +}; + +struct _GstRtpPmcaPayClass +{ + GstBaseRTPPayloadClass parent_class; +}; + +gboolean gst_rtp_pcma_pay_plugin_init (GstPlugin * plugin); + +G_END_DECLS + +#endif /* __GST_RTP_PCMA_PAY_H__ */ diff --git a/gst/rtp/gstrtppcmudepay.c b/gst/rtp/gstrtppcmudepay.c new file mode 100644 index 00000000..0de704ce --- /dev/null +++ b/gst/rtp/gstrtppcmudepay.c @@ -0,0 +1,161 @@ +/* GStreamer + * Copyright (C) <1999> Erik Walthinsen + * Copyright (C) <2005> Edgard Lima + * Copyright (C) <2005> Zeeshan Ali + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include "gstrtppcmudepay.h" + +/* elementfactory information */ +static GstElementDetails gst_rtp_pcmudepay_details = { + "RTP packet parser", + "Codec/Depayr/Network", + "Extracts PCMU audio from RTP packets", + "Edgard Lima , Zeeshan Ali " +}; + +/* RtpPcmuDepay signals and args */ +enum +{ + /* FILL ME */ + LAST_SIGNAL +}; + +enum +{ + ARG_0 +}; + +static GstStaticPadTemplate gst_rtp_pcmu_depay_sink_template = +GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("application/x-rtp, " + "media = (string) \"audio\", " + "clock-rate = (int) 8000, " "encoding-name = (string) \"PCMU\"") + + ); + +static GstStaticPadTemplate gst_rtp_pcmu_depay_src_template = +GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("audio/x-mulaw, " "channels = (int) 1") + ); + +static GstBuffer *gst_rtp_pcmu_depay_process (GstBaseRTPDepayload * depayload, + GstBuffer * buf); +static gboolean gst_rtp_pcmu_depay_setcaps (GstBaseRTPDepayload * depayload, + GstCaps * caps); + +GST_BOILERPLATE (GstRtpPcmuDepay, gst_rtp_pcmu_depay, GstBaseRTPDepayload, + GST_TYPE_BASE_RTP_DEPAYLOAD); + +static void +gst_rtp_pcmu_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_pcmu_depay_src_template)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&gst_rtp_pcmu_depay_sink_template)); + gst_element_class_set_details (element_class, &gst_rtp_pcmudepay_details); +} + +static void +gst_rtp_pcmu_depay_class_init (GstRtpPcmuDepayClass * klass) +{ + GObjectClass *gobject_class; + GstElementClass *gstelement_class; + GstBaseRTPDepayloadClass *gstbasertpdepayload_class; + + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; + gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass; + + parent_class = g_type_class_ref (GST_TYPE_BASE_RTP_DEPAYLOAD); + + gstbasertpdepayload_class->process = gst_rtp_pcmu_depay_process; + gstbasertpdepayload_class->set_caps = gst_rtp_pcmu_depay_setcaps; +} + +static void +gst_rtp_pcmu_depay_init (GstRtpPcmuDepay * rtppcmudepay, + GstRtpPcmuDepayClass * klass) +{ + GstBaseRTPDepayload *depayload; + + depayload = GST_BASE_RTP_DEPAYLOAD (rtppcmudepay); + + depayload->clock_rate = 8000; + gst_pad_use_fixed_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload)); +} + +static gboolean +gst_rtp_pcmu_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps) +{ + GstCaps *srccaps; + gboolean ret; + + srccaps = gst_caps_new_simple ("audio/x-mulaw", + "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL); + + ret = gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload), srccaps); + gst_caps_unref (srccaps); + + return ret; +} + +static GstBuffer * +gst_rtp_pcmu_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) +{ + GstCaps *srccaps; + GstBuffer *outbuf = NULL; + gint payload_len; + guint8 *payload; + + GST_DEBUG ("process : got %d bytes, mark %d ts %u seqn %d", + GST_BUFFER_SIZE (buf), + gst_rtp_buffer_get_marker (buf), + gst_rtp_buffer_get_timestamp (buf), gst_rtp_buffer_get_seq (buf)); + + srccaps = GST_PAD_CAPS (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload)); + if (!srccaps) { + /* Set the default caps */ + srccaps = gst_caps_new_simple ("audio/x-mulaw", + "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL); + gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (depayload), srccaps); + gst_caps_unref (srccaps); + } + + payload_len = gst_rtp_buffer_get_payload_len (buf); + payload = gst_rtp_buffer_get_payload (buf); + + outbuf = gst_buffer_new_and_alloc (payload_len); + memcpy (GST_BUFFER_DATA (outbuf), payload, payload_len); + return outbuf; +} + +gboolean +gst_rtp_pcmu_depay_plugin_init (GstPlugin * plugin) +{ + return gst_element_register (plugin, "rtppcmudepay", + GST_RANK_NONE, GST_TYPE_RTP_PCMU_DEPAY); +} diff --git a/gst/rtp/gstrtppcmudepay.h b/gst/rtp/gstrtppcmudepay.h new file mode 100644 index 00000000..782c0bcc --- /dev/null +++ b/gst/rtp/gstrtppcmudepay.h @@ -0,0 +1,51 @@ +/* GStreamer + * Copyright (C) <2005> Edgard Lima + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more + */ + +#ifndef __GST_RTP_PCMU_DEPAY_H__ +#define __GST_RTP_PCMU_DEPAY_H__ + +#include +#include + +G_BEGIN_DECLS + +typedef struct _GstRtpPcmuDepay GstRtpPcmuDepay; +typedef struct _GstRtpPcmuDepayClass GstRtpPcmuDepayClass; + +#define GST_TYPE_RTP_PCMU_DEPAY \ + (gst_rtp_pcmu_depay_get_type()) +#define GST_RTP_PCMU_DEPAY(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_RTP_PCMU_DEPAY,GstRtpPcmuDepay)) +#define GST_RTP_PCMU_DEPAY_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_RTP_PCMU_DEPAY,GstRtpPcmuDepay)) +#define GST_IS_RTP_PCMU_DEPAY(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_RTP_PCMU_DEPAY)) +#define GST_IS_RTP_PCMU_DEPAY_CLASS(obj) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_RTP_PCMU_DEPAY)) + +struct _GstRtpPcmuDepay +{ + GstBaseRTPDepayload depayload; +}; + +struct _GstRtpPcmuDepayClass +{ + GstBaseRTPDepayloadClass parent_class; +}; + +gboolean gst_rtp_pcmu_depay_plugin_init (GstPlugin * plugin); + +G_END_DECLS + +#endif /* __GST_RTP_PCMU_DEPAY_H__ */ diff --git a/gst/rtp/gstrtppcmupay.c b/gst/rtp/gstrtppcmupay.c new file mode 100644 index 00000000..67c40201 --- /dev/null +++ b/gst/rtp/gstrtppcmupay.c @@ -0,0 +1,230 @@ +/* GStreamer + * Copyright (C) <1999> Erik Walthinsen + * Copyright (C) <2005> Edgard Lima + * Copyright (C) <2005> Nokia Corporation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include + +#include "gstrtppcmupay.h" + +/* elementfactory information */ +static GstElementDetails gst_rtp_pcmu_pay_details = { + "RTP packet parser", + "Codec/Payloader/Network", + "Payload-encodes PCMU audio into a RTP packet", + "Edgard Lima " +}; + +static GstStaticPadTemplate gst_rtp_pcmu_pay_sink_template = +GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("audio/x-mulaw, channels=(int)1, rate=(int)8000") + ); + +static GstStaticPadTemplate gst_rtp_pcmu_pay_src_template = +GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("application/x-rtp, " + "media = (string) \"audio\", " + "payload = (int) " GST_RTP_PAYLOAD_PCMU_STRING ", " + "clock-rate = (int) 8000, " "encoding-name = (string) \"PCMU\"") + ); + +static gboolean gst_rtp_pcmu_pay_setcaps (GstBaseRTPPayload * payload, + GstCaps * caps); +static GstFlowReturn gst_rtp_pcmu_pay_handle_buffer (GstBaseRTPPayload * + payload, GstBuffer * buffer); +static void gst_rtp_pcmu_pay_finalize (GObject * object); + +GST_BOILERPLATE (GstRtpPcmuPay, gst_rtp_pcmu_pay, GstBaseRTPPayload, + GST_TYPE_BASE_RTP_PAYLOAD); + +/* The lower limit for number of octet to put in one packet + * (clock-rate=8000, octet-per-sample=1). The default 80 is equal + * to to 10msec (see RFC3551) */ +#define GST_RTP_PCMU_MIN_PTIME_OCTETS 80 + +static void +gst_rtp_pcmu_pay_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_pcmu_pay_sink_template)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&gst_rtp_pcmu_pay_src_template)); + gst_element_class_set_details (element_class, &gst_rtp_pcmu_pay_details); +} + +static void +gst_rtp_pcmu_pay_class_init (GstRtpPcmuPayClass * klass) +{ + GObjectClass *gobject_class; + GstElementClass *gstelement_class; + GstBaseRTPPayloadClass *gstbasertppayload_class; + + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; + gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass; + + parent_class = g_type_class_ref (GST_TYPE_BASE_RTP_PAYLOAD); + gobject_class->finalize = gst_rtp_pcmu_pay_finalize; + + gstbasertppayload_class->set_caps = gst_rtp_pcmu_pay_setcaps; + gstbasertppayload_class->handle_buffer = gst_rtp_pcmu_pay_handle_buffer; +} + +static void +gst_rtp_pcmu_pay_init (GstRtpPcmuPay * rtppcmupay, GstRtpPcmuPayClass * klass) +{ + rtppcmupay->adapter = gst_adapter_new (); + GST_BASE_RTP_PAYLOAD (rtppcmupay)->clock_rate = 8000; +} + +static void +gst_rtp_pcmu_pay_finalize (GObject * object) +{ + GstRtpPcmuPay *rtppcmupay; + + rtppcmupay = GST_RTP_PCMU_PAY (object); + + g_object_unref (rtppcmupay->adapter); + rtppcmupay->adapter = NULL; + + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +static gboolean +gst_rtp_pcmu_pay_setcaps (GstBaseRTPPayload * payload, GstCaps * caps) +{ + payload->pt = GST_RTP_PAYLOAD_PCMU; + gst_basertppayload_set_options (payload, "audio", FALSE, "PCMU", 8000); + + gst_basertppayload_set_outcaps (payload, NULL); + + return TRUE; +} + +static GstFlowReturn +gst_rtp_pcmu_pay_flush (GstRtpPcmuPay * rtppcmupay) +{ + guint avail; + GstBuffer *outbuf; + GstFlowReturn ret; + guint maxptime_octets = G_MAXUINT; + guint minptime_octets = GST_RTP_PCMU_MIN_PTIME_OCTETS; + + if (GST_BASE_RTP_PAYLOAD (rtppcmupay)->max_ptime > 0) { + /* calculate octet count with: + maxptime-nsec * samples-per-sec / nsecs-per-sec * octets-per-sample */ + maxptime_octets = + GST_BASE_RTP_PAYLOAD (rtppcmupay)->max_ptime * + GST_BASE_RTP_PAYLOAD (rtppcmupay)->clock_rate / GST_SECOND; + } + + /* the data available in the adapter is either smaller + * than the MTU or bigger. In the case it is smaller, the complete + * adapter contents can be put in one packet. */ + avail = gst_adapter_available (rtppcmupay->adapter); + + ret = GST_FLOW_OK; + + while (avail >= minptime_octets) { + guint8 *payload; + guint8 *data; + guint payload_len; + guint packet_len; + + /* fill one MTU or all available bytes */ + payload_len = + MIN (MIN (GST_BASE_RTP_PAYLOAD_MTU (rtppcmupay), maxptime_octets), + avail); + + /* this will be the total lenght of the packet */ + packet_len = gst_rtp_buffer_calc_packet_len (payload_len, 0, 0); + + /* create buffer to hold the payload */ + outbuf = gst_rtp_buffer_new_allocate (payload_len, 0, 0); + + /* copy payload */ + gst_rtp_buffer_set_payload_type (outbuf, + GST_BASE_RTP_PAYLOAD_PT (rtppcmupay)); + payload = gst_rtp_buffer_get_payload (outbuf); + data = (guint8 *) gst_adapter_peek (rtppcmupay->adapter, payload_len); + memcpy (payload, data, payload_len); + gst_adapter_flush (rtppcmupay->adapter, payload_len); + + avail -= payload_len; + + GST_BUFFER_TIMESTAMP (outbuf) = rtppcmupay->first_ts; + ret = gst_basertppayload_push (GST_BASE_RTP_PAYLOAD (rtppcmupay), outbuf); + } + + return ret; +} + +static GstFlowReturn +gst_rtp_pcmu_pay_handle_buffer (GstBaseRTPPayload * basepayload, + GstBuffer * buffer) +{ + GstRtpPcmuPay *rtppcmupay; + guint size, packet_len, avail; + GstFlowReturn ret; + GstClockTime duration; + + rtppcmupay = GST_RTP_PCMU_PAY (basepayload); + + size = GST_BUFFER_SIZE (buffer); + duration = GST_BUFFER_TIMESTAMP (buffer); + + avail = gst_adapter_available (rtppcmupay->adapter); + if (avail == 0) { + rtppcmupay->first_ts = GST_BUFFER_TIMESTAMP (buffer); + rtppcmupay->duration = 0; + } + + /* get packet length of data and see if we exceeded MTU. */ + packet_len = gst_rtp_buffer_calc_packet_len (avail + size, 0, 0); + + /* if this buffer is going to overflow the packet, flush what we + * have. */ + if (gst_basertppayload_is_filled (basepayload, + packet_len, rtppcmupay->duration + duration)) { + ret = gst_rtp_pcmu_pay_flush (rtppcmupay); + rtppcmupay->first_ts = GST_BUFFER_TIMESTAMP (buffer); + rtppcmupay->duration = 0; + } else { + ret = GST_FLOW_OK; + } + + gst_adapter_push (rtppcmupay->adapter, buffer); + rtppcmupay->duration += duration; + + return ret; +} + +gboolean +gst_rtp_pcmu_pay_plugin_init (GstPlugin * plugin) +{ + return gst_element_register (plugin, "rtppcmupay", + GST_RANK_NONE, GST_TYPE_RTP_PCMU_PAY); +} diff --git a/gst/rtp/gstrtppcmupay.h b/gst/rtp/gstrtppcmupay.h new file mode 100644 index 00000000..046071bd --- /dev/null +++ b/gst/rtp/gstrtppcmupay.h @@ -0,0 +1,57 @@ +/* GStreamer + * Copyright (C) <2005> Edgard Lima + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more + */ + + +#ifndef __GST_RTP_PCMU_PAY_H__ +#define __GST_RTP_PCMU_PAY_H__ + +#include +#include +#include + +G_BEGIN_DECLS + +typedef struct _GstRtpPcmuPay GstRtpPcmuPay; +typedef struct _GstRtpPcmuPayClass GstRtpPcmuPayClass; + +#define GST_TYPE_RTP_PCMU_PAY \ + (gst_rtp_pcmu_pay_get_type()) +#define GST_RTP_PCMU_PAY(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_RTP_PCMU_PAY,GstRtpPcmuPay)) +#define GST_RTP_PCMU_PAY_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_RTP_PCMU_PAY,GstRtpPcmuPay)) +#define GST_IS_RTP_PCMU_PAY(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_RTP_PCMU_PAY)) +#define GST_IS_RTP_PCMU_PAY_CLASS(obj) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_RTP_PCMU_PAY)) + +struct _GstRtpPcmuPay +{ + GstBaseRTPPayload payload; + GstAdapter *adapter; + + GstClockTime first_ts; + GstClockTime duration; +}; + +struct _GstRtpPcmuPayClass +{ + GstBaseRTPPayloadClass parent_class; +}; + +gboolean gst_rtp_pcmu_pay_plugin_init (GstPlugin * plugin); + +G_END_DECLS + +#endif /* __GST_RTP_PCMU_PAY_H__ */ -- cgit