Commit 8449839a authored by Philippe Kalaf's avatar Philippe Kalaf

rtp/gst/: Separated the G711 payloaders/depayloaders into separate elements...

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  <philippe.kalaf at collabora.co.uk>

* 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.
parent ec24b0df
2006-02-23 Philippe Kalaf <philippe.kalaf at collabora.co.uk>
* 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.
2006-02-22 Wim Taymans <wim@fluendo.com>
* ext/dv/gstdvdec.c: (gst_dvdec_base_init), (gst_dvdec_init),
......
......@@ -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 \
......
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
-------------------------------
......
......@@ -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))
......
......@@ -20,17 +20,17 @@
#include <string.h>
#include <gst/rtp/gstrtpbuffer.h>
#include "gstrtpg711depay.h"
#include "gstrtppcmadepay.h"
/* elementfactory information */
static GstElementDetails gst_rtp_g711depay_details = {
static GstElementDetails gst_rtp_pcmadepay_details = {
"RTP packet parser",
"Codec/Depayr/Network",
"Extracts PCMU/PCMA audio from RTP packets",
"Extracts PCMA audio from RTP packets",
"Edgard Lima <edgard.lima@indt.org.br>, Zeeshan Ali <zeenix@gmail.com>"
};
/* RtpG711Depay signals and args */
/* RtpPcmaDepay signals and args */
enum
{
/* FILL ME */
......@@ -42,50 +42,44 @@ enum
ARG_0
};
static GstStaticPadTemplate gst_rtp_g711_depay_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink",
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) \"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",
static GstStaticPadTemplate gst_rtp_pcma_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")
GST_STATIC_CAPS ("audio/x-alaw, " "channels = (int) 1")
);
static GstBuffer *gst_rtp_g711_depay_process (GstBaseRTPDepayload * depayload,
static GstBuffer *gst_rtp_pcma_depay_process (GstBaseRTPDepayload * depayload,
GstBuffer * buf);
static gboolean gst_rtp_g711_depay_setcaps (GstBaseRTPDepayload * depayload,
static gboolean gst_rtp_pcma_depay_setcaps (GstBaseRTPDepayload * depayload,
GstCaps * caps);
GST_BOILERPLATE (GstRtpG711Depay, gst_rtp_g711_depay, GstBaseRTPDepayload,
GST_BOILERPLATE (GstRtpPcmaDepay, gst_rtp_pcma_depay, GstBaseRTPDepayload,
GST_TYPE_BASE_RTP_DEPAYLOAD);
static void
gst_rtp_g711_depay_base_init (gpointer klass)
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_g711_depay_src_template));
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_g711_depay_sink_template));
gst_element_class_set_details (element_class, &gst_rtp_g711depay_details);
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_g711_depay_class_init (GstRtpG711DepayClass * klass)
gst_rtp_pcma_depay_class_init (GstRtpPcmaDepayClass * klass)
{
GObjectClass *gobject_class;
GstElementClass *gstelement_class;
......@@ -97,46 +91,30 @@ gst_rtp_g711_depay_class_init (GstRtpG711DepayClass * 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;
gstbasertpdepayload_class->process = gst_rtp_pcma_depay_process;
gstbasertpdepayload_class->set_caps = gst_rtp_pcma_depay_setcaps;
}
static void
gst_rtp_g711_depay_init (GstRtpG711Depay * rtpg711depay,
GstRtpG711DepayClass * klass)
gst_rtp_pcma_depay_init (GstRtpPcmaDepay * rtppcmadepay,
GstRtpPcmaDepayClass * klass)
{
GstBaseRTPDepayload *depayload;
depayload = GST_BASE_RTP_DEPAYLOAD (rtpg711depay);
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_g711_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
gst_rtp_pcma_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;
}
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);
......@@ -145,7 +123,7 @@ gst_rtp_g711_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
}
static GstBuffer *
gst_rtp_g711_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
gst_rtp_pcma_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
{
GstCaps *srccaps;
GstBuffer *outbuf = NULL;
......@@ -175,8 +153,8 @@ gst_rtp_g711_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
}
gboolean
gst_rtp_g711_depay_plugin_init (GstPlugin * plugin)
gst_rtp_pcma_depay_plugin_init (GstPlugin * plugin)
{
return gst_element_register (plugin, "rtpg711depay",
GST_RANK_NONE, GST_TYPE_RTP_G711_DEPAY);
return gst_element_register (plugin, "rtppcmadepay",
GST_RANK_NONE, GST_TYPE_RTP_PCMA_DEPAY);
}
......@@ -12,40 +12,40 @@
* Library General Public License for more
*/
#ifndef __GST_RTP_G711_DEPAY_H__
#define __GST_RTP_G711_DEPAY_H__
#ifndef __GST_RTP_PCMA_DEPAY_H__
#define __GST_RTP_PCMA_DEPAY_H__
#include <gst/gst.h>
#include <gst/rtp/gstbasertpdepayload.h>
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
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 _GstRtpG711DepayClass
struct _GstRtpPcmaDepayClass
{
GstBaseRTPDepayloadClass parent_class;
};
gboolean gst_rtp_g711_depay_plugin_init (GstPlugin * plugin);
gboolean gst_rtp_pcma_depay_plugin_init (GstPlugin * plugin);
G_END_DECLS
#endif /* __GST_RTP_G711_DEPAY_H__ */
#endif /* __GST_RTP_PCMA_DEPAY_H__ */
......@@ -13,8 +13,8 @@
*/
#ifndef __GST_RTP_G711_PAY_H__
#define __GST_RTP_G711_PAY_H__
#ifndef __GST_RTP_PCMA_PAY_H__
#define __GST_RTP_PCMA_PAY_H__
#include <gst/gst.h>
#include <gst/rtp/gstbasertppayload.h>
......@@ -22,21 +22,21 @@
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
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;
......@@ -45,13 +45,13 @@ struct _GstRtpG711Pay
GstClockTime duration;
};
struct _GstRtpG711PayClass
struct _GstRtpPmcaPayClass
{
GstBaseRTPPayloadClass parent_class;
};
gboolean gst_rtp_g711_pay_plugin_init (GstPlugin * plugin);
gboolean gst_rtp_pcma_pay_plugin_init (GstPlugin * plugin);
G_END_DECLS
#endif /* __GST_RTP_G711_PAY_H__ */
#endif /* __GST_RTP_PCMA_PAY_H__ */
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* Copyright (C) <2005> Edgard Lima <edgard.lima@indt.org.br>
* Copyright (C) <2005> Zeeshan Ali <zeenix@gmail.com>
*
* 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 <string.h>
#include <gst/rtp/gstrtpbuffer.h>
#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 <edgard.lima@indt.org.br>, Zeeshan Ali <zeenix@gmail.com>"
};
/* 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);
}
/* GStreamer
* Copyright (C) <2005> Edgard Lima <edgard.lima@indt.org.br>
*
* 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 <gst/gst.h>
#include <gst/rtp/gstbasertpdepayload.h>
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__ */
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* Copyright (C) <2005> Edgard Lima <edgard.lima@indt.org.br>
* Copyright (C) <2005> Nokia Corporation <kai.vehmanen@nokia.com>
*
* 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 <stdlib.h>
#include <string.h>
#include <gst/rtp/gstrtpbuffer.h>
#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 <edgard.lima@indt.org.br>"
};
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);