|
Packit |
8ff292 |
/* GStreamer
|
|
Packit |
8ff292 |
* Copyright (C) <2006> Philippe Khalaf <burger@speedy.org>
|
|
Packit |
8ff292 |
*
|
|
Packit |
8ff292 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
8ff292 |
* modify it under the terms of the GNU Library General Public
|
|
Packit |
8ff292 |
* License as published by the Free Software Foundation; either
|
|
Packit |
8ff292 |
* version 2 of the License, or (at your option) any later version.
|
|
Packit |
8ff292 |
*
|
|
Packit |
8ff292 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
8ff292 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
8ff292 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
8ff292 |
* Library General Public License for more details.
|
|
Packit |
8ff292 |
*
|
|
Packit |
8ff292 |
* You should have received a copy of the GNU Library General Public
|
|
Packit |
8ff292 |
* License along with this library; if not, write to the
|
|
Packit |
8ff292 |
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
Packit |
8ff292 |
* Boston, MA 02110-1301, USA.
|
|
Packit |
8ff292 |
*/
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
#ifdef HAVE_CONFIG_H
|
|
Packit |
8ff292 |
# include "config.h"
|
|
Packit |
8ff292 |
#endif
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
#include <string.h>
|
|
Packit |
8ff292 |
#include <stdlib.h>
|
|
Packit |
8ff292 |
#include <gst/rtp/gstrtpbuffer.h>
|
|
Packit |
8ff292 |
#include <gst/audio/audio.h>
|
|
Packit |
8ff292 |
#include "gstrtpilbcdepay.h"
|
|
Packit |
8ff292 |
#include "gstrtputils.h"
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
/* RtpiLBCDepay signals and args */
|
|
Packit |
8ff292 |
enum
|
|
Packit |
8ff292 |
{
|
|
Packit |
8ff292 |
/* FILL ME */
|
|
Packit |
8ff292 |
LAST_SIGNAL
|
|
Packit |
8ff292 |
};
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
#define DEFAULT_MODE GST_ILBC_MODE_30
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
enum
|
|
Packit |
8ff292 |
{
|
|
Packit |
8ff292 |
PROP_0,
|
|
Packit |
8ff292 |
PROP_MODE
|
|
Packit |
8ff292 |
};
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
/* FIXME, mode should be string because it is a parameter in SDP fmtp */
|
|
Packit |
8ff292 |
static GstStaticPadTemplate gst_rtp_ilbc_depay_sink_template =
|
|
Packit |
8ff292 |
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
Packit |
8ff292 |
GST_PAD_SINK,
|
|
Packit |
8ff292 |
GST_PAD_ALWAYS,
|
|
Packit |
8ff292 |
GST_STATIC_CAPS ("application/x-rtp, "
|
|
Packit |
8ff292 |
"media = (string) \"audio\", "
|
|
Packit |
8ff292 |
"clock-rate = (int) 8000, " "encoding-name = (string) \"ILBC\"")
|
|
Packit |
8ff292 |
/* "mode = (string) { \"20\", \"30\" }" */
|
|
Packit |
8ff292 |
);
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
static GstStaticPadTemplate gst_rtp_ilbc_depay_src_template =
|
|
Packit |
8ff292 |
GST_STATIC_PAD_TEMPLATE ("src",
|
|
Packit |
8ff292 |
GST_PAD_SRC,
|
|
Packit |
8ff292 |
GST_PAD_ALWAYS,
|
|
Packit |
8ff292 |
GST_STATIC_CAPS ("audio/x-iLBC, " "mode = (int) { 20, 30 }")
|
|
Packit |
8ff292 |
);
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
static void gst_ilbc_depay_set_property (GObject * object,
|
|
Packit |
8ff292 |
guint prop_id, const GValue * value, GParamSpec * pspec);
|
|
Packit |
8ff292 |
static void gst_ilbc_depay_get_property (GObject * object,
|
|
Packit |
8ff292 |
guint prop_id, GValue * value, GParamSpec * pspec);
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
static GstBuffer *gst_rtp_ilbc_depay_process (GstRTPBaseDepayload * depayload,
|
|
Packit |
8ff292 |
GstRTPBuffer * rtp);
|
|
Packit |
8ff292 |
static gboolean gst_rtp_ilbc_depay_setcaps (GstRTPBaseDepayload * depayload,
|
|
Packit |
8ff292 |
GstCaps * caps);
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
#define gst_rtp_ilbc_depay_parent_class parent_class
|
|
Packit |
8ff292 |
G_DEFINE_TYPE (GstRTPiLBCDepay, gst_rtp_ilbc_depay,
|
|
Packit |
8ff292 |
GST_TYPE_RTP_BASE_DEPAYLOAD);
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
#define GST_TYPE_ILBC_MODE (gst_ilbc_mode_get_type())
|
|
Packit |
8ff292 |
static GType
|
|
Packit |
8ff292 |
gst_ilbc_mode_get_type (void)
|
|
Packit |
8ff292 |
{
|
|
Packit |
8ff292 |
static GType ilbc_mode_type = 0;
|
|
Packit |
8ff292 |
static const GEnumValue ilbc_modes[] = {
|
|
Packit |
8ff292 |
{GST_ILBC_MODE_20, "20ms frames", "20ms"},
|
|
Packit |
8ff292 |
{GST_ILBC_MODE_30, "30ms frames", "30ms"},
|
|
Packit |
8ff292 |
{0, NULL, NULL},
|
|
Packit |
8ff292 |
};
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
if (!ilbc_mode_type) {
|
|
Packit |
8ff292 |
ilbc_mode_type = g_enum_register_static ("iLBCMode", ilbc_modes);
|
|
Packit |
8ff292 |
}
|
|
Packit |
8ff292 |
return ilbc_mode_type;
|
|
Packit |
8ff292 |
}
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
static void
|
|
Packit |
8ff292 |
gst_rtp_ilbc_depay_class_init (GstRTPiLBCDepayClass * klass)
|
|
Packit |
8ff292 |
{
|
|
Packit |
8ff292 |
GObjectClass *gobject_class;
|
|
Packit |
8ff292 |
GstElementClass *gstelement_class;
|
|
Packit |
8ff292 |
GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
gobject_class = (GObjectClass *) klass;
|
|
Packit |
8ff292 |
gstelement_class = (GstElementClass *) klass;
|
|
Packit |
8ff292 |
gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
gobject_class->set_property = gst_ilbc_depay_set_property;
|
|
Packit |
8ff292 |
gobject_class->get_property = gst_ilbc_depay_get_property;
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
/* FIXME, mode is in the caps */
|
|
Packit |
8ff292 |
g_object_class_install_property (gobject_class, PROP_MODE,
|
|
Packit |
8ff292 |
g_param_spec_enum ("mode", "Mode", "iLBC frame mode",
|
|
Packit |
8ff292 |
GST_TYPE_ILBC_MODE, DEFAULT_MODE,
|
|
Packit |
8ff292 |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
gst_element_class_add_static_pad_template (gstelement_class,
|
|
Packit |
8ff292 |
&gst_rtp_ilbc_depay_src_template);
|
|
Packit |
8ff292 |
gst_element_class_add_static_pad_template (gstelement_class,
|
|
Packit |
8ff292 |
&gst_rtp_ilbc_depay_sink_template);
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
gst_element_class_set_static_metadata (gstelement_class,
|
|
Packit |
8ff292 |
"RTP iLBC depayloader", "Codec/Depayloader/Network/RTP",
|
|
Packit |
8ff292 |
"Extracts iLBC audio from RTP packets (RFC 3952)",
|
|
Packit |
8ff292 |
"Philippe Kalaf <philippe.kalaf@collabora.co.uk>");
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
gstrtpbasedepayload_class->process_rtp_packet = gst_rtp_ilbc_depay_process;
|
|
Packit |
8ff292 |
gstrtpbasedepayload_class->set_caps = gst_rtp_ilbc_depay_setcaps;
|
|
Packit |
8ff292 |
}
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
static void
|
|
Packit |
8ff292 |
gst_rtp_ilbc_depay_init (GstRTPiLBCDepay * rtpilbcdepay)
|
|
Packit |
8ff292 |
{
|
|
Packit |
8ff292 |
/* Set default mode */
|
|
Packit |
8ff292 |
rtpilbcdepay->mode = DEFAULT_MODE;
|
|
Packit |
8ff292 |
}
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
static gboolean
|
|
Packit |
8ff292 |
gst_rtp_ilbc_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
|
|
Packit |
8ff292 |
{
|
|
Packit |
8ff292 |
GstRTPiLBCDepay *rtpilbcdepay = GST_RTP_ILBC_DEPAY (depayload);
|
|
Packit |
8ff292 |
GstCaps *srccaps;
|
|
Packit |
8ff292 |
GstStructure *structure;
|
|
Packit |
8ff292 |
const gchar *mode_str = NULL;
|
|
Packit |
8ff292 |
gint mode, clock_rate;
|
|
Packit |
8ff292 |
gboolean ret;
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
structure = gst_caps_get_structure (caps, 0);
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
mode = rtpilbcdepay->mode;
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
|
|
Packit |
8ff292 |
clock_rate = 8000;
|
|
Packit |
8ff292 |
depayload->clock_rate = clock_rate;
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
/* parse mode, if we can */
|
|
Packit |
8ff292 |
mode_str = gst_structure_get_string (structure, "mode");
|
|
Packit |
8ff292 |
if (mode_str) {
|
|
Packit |
8ff292 |
mode = strtol (mode_str, NULL, 10);
|
|
Packit |
8ff292 |
if (mode != 20 && mode != 30)
|
|
Packit |
8ff292 |
mode = rtpilbcdepay->mode;
|
|
Packit |
8ff292 |
}
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
rtpilbcdepay->mode = mode;
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
srccaps = gst_caps_new_simple ("audio/x-iLBC",
|
|
Packit |
8ff292 |
"mode", G_TYPE_INT, rtpilbcdepay->mode, NULL);
|
|
Packit |
8ff292 |
ret = gst_pad_set_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (depayload), srccaps);
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
GST_DEBUG ("set caps on source: %" GST_PTR_FORMAT " (ret=%d)", srccaps, ret);
|
|
Packit |
8ff292 |
gst_caps_unref (srccaps);
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
return ret;
|
|
Packit |
8ff292 |
}
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
static GstBuffer *
|
|
Packit |
8ff292 |
gst_rtp_ilbc_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp)
|
|
Packit |
8ff292 |
{
|
|
Packit |
8ff292 |
GstBuffer *outbuf;
|
|
Packit |
8ff292 |
gboolean marker;
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
marker = gst_rtp_buffer_get_marker (rtp);
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
GST_DEBUG ("process : got %" G_GSIZE_FORMAT " bytes, mark %d ts %u seqn %d",
|
|
Packit |
8ff292 |
gst_buffer_get_size (rtp->buffer), marker,
|
|
Packit |
8ff292 |
gst_rtp_buffer_get_timestamp (rtp), gst_rtp_buffer_get_seq (rtp));
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
outbuf = gst_rtp_buffer_get_payload_buffer (rtp);
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
if (marker && outbuf) {
|
|
Packit |
8ff292 |
/* mark start of talkspurt with RESYNC */
|
|
Packit |
8ff292 |
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_RESYNC);
|
|
Packit |
8ff292 |
}
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
if (outbuf) {
|
|
Packit |
8ff292 |
gst_rtp_drop_non_audio_meta (depayload, outbuf);
|
|
Packit |
8ff292 |
}
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
return outbuf;
|
|
Packit |
8ff292 |
}
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
static void
|
|
Packit |
8ff292 |
gst_ilbc_depay_set_property (GObject * object,
|
|
Packit |
8ff292 |
guint prop_id, const GValue * value, GParamSpec * pspec)
|
|
Packit |
8ff292 |
{
|
|
Packit |
8ff292 |
GstRTPiLBCDepay *rtpilbcdepay = GST_RTP_ILBC_DEPAY (object);
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
switch (prop_id) {
|
|
Packit |
8ff292 |
case PROP_MODE:
|
|
Packit |
8ff292 |
rtpilbcdepay->mode = g_value_get_enum (value);
|
|
Packit |
8ff292 |
break;
|
|
Packit |
8ff292 |
default:
|
|
Packit |
8ff292 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
Packit |
8ff292 |
break;
|
|
Packit |
8ff292 |
}
|
|
Packit |
8ff292 |
}
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
static void
|
|
Packit |
8ff292 |
gst_ilbc_depay_get_property (GObject * object,
|
|
Packit |
8ff292 |
guint prop_id, GValue * value, GParamSpec * pspec)
|
|
Packit |
8ff292 |
{
|
|
Packit |
8ff292 |
GstRTPiLBCDepay *rtpilbcdepay = GST_RTP_ILBC_DEPAY (object);
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
switch (prop_id) {
|
|
Packit |
8ff292 |
case PROP_MODE:
|
|
Packit |
8ff292 |
g_value_set_enum (value, rtpilbcdepay->mode);
|
|
Packit |
8ff292 |
break;
|
|
Packit |
8ff292 |
default:
|
|
Packit |
8ff292 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
Packit |
8ff292 |
break;
|
|
Packit |
8ff292 |
}
|
|
Packit |
8ff292 |
}
|
|
Packit |
8ff292 |
|
|
Packit |
8ff292 |
gboolean
|
|
Packit |
8ff292 |
gst_rtp_ilbc_depay_plugin_init (GstPlugin * plugin)
|
|
Packit |
8ff292 |
{
|
|
Packit |
8ff292 |
return gst_element_register (plugin, "rtpilbcdepay",
|
|
Packit |
8ff292 |
GST_RANK_SECONDARY, GST_TYPE_RTP_ILBC_DEPAY);
|
|
Packit |
8ff292 |
}
|