Over-writing Wim's gsm plugins (currently not working) with that from the farsight repo. Also made sure that they wor...

Original commit message from CVS:
Over-writing Wim's gsm plugins (currently not working) with that from the farsight repo. Also made sure that they work with the RTP (de)payloader.
This commit is contained in:
Zeeshan Ali 2005-10-25 16:12:03 +00:00
parent 4d87f79f85
commit 6510eef093
6 changed files with 105 additions and 182 deletions

View file

@ -1,3 +1,15 @@
2005-10-25 Zeeshan Ali <zeenix@gmail.com>
* ext/gsm/gstgsm.c: (plugin_init):
* ext/gsm/gstgsmdec.c: (gst_gsmdec_class_init), (gst_gsmdec_init),
(gst_gsmdec_chain):
* ext/gsm/gstgsmdec.h:
* ext/gsm/gstgsmenc.c: (gst_gsmenc_class_init), (gst_gsmenc_init),
(gst_gsmenc_chain):
* ext/gsm/gstgsmenc.h:
Over-writing Wim's gsm plugins (currently not working) with that from the
farsight repo. Also made sure that they work with the RTP (de)payloader.
2005-10-25 Edgard Lima <edgard.lima@indt.org.br> 2005-10-25 Edgard Lima <edgard.lima@indt.org.br>
* ext/gsm/gstgsmenc.c: (gst_gsmenc_init), * ext/gsm/gstgsmenc.c: (gst_gsmenc_init),

View file

@ -1,5 +1,7 @@
/* GStreamer /*
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> * Farsight
* GStreamer GSM encoder/decoder (uses WAV49 compiled libgsm)
* Copyright (C) 2005 Philippe Khalaf <burger@speedy.org>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public * modify it under the terms of the GNU Library General Public
@ -29,14 +31,14 @@ plugin_init (GstPlugin * plugin)
{ {
if (!gst_element_register (plugin, "gsmenc", GST_RANK_NONE, GST_TYPE_GSMENC)) if (!gst_element_register (plugin, "gsmenc", GST_RANK_NONE, GST_TYPE_GSMENC))
return FALSE; return FALSE;
if (!gst_element_register (plugin, "gsmdec", GST_RANK_PRIMARY, if (!gst_element_register (plugin, "gsmdec", GST_RANK_NONE, GST_TYPE_GSMDEC))
GST_TYPE_GSMDEC))
return FALSE; return FALSE;
return TRUE; return TRUE;
} }
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR, GST_VERSION_MINOR,
"gsm", "gsm",
"GSM Elements Plugin", "GSM encoder/decoder",
plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN) plugin_init, VERSION, "LGPL", "Farsight", "http://farsight.sf.net")

View file

@ -1,5 +1,7 @@
/* GStreamer /*
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> * Farsight
* GStreamer GSM decoder
* Copyright (C) 2005 Philippe Khalaf <burger@speedy.org>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public * modify it under the terms of the GNU Library General Public
@ -25,12 +27,15 @@
#include "gstgsmdec.h" #include "gstgsmdec.h"
GST_DEBUG_CATEGORY (gsmdec_debug);
#define GST_CAT_DEFAULT (gsmdec_debug)
/* elementfactory information */ /* elementfactory information */
GstElementDetails gst_gsmdec_details = { GstElementDetails gst_gsmdec_details = {
"GSM audio decoder", "GSM audio decoder",
"Codec/Decoder/Audio", "Codec/Decoder/Audio",
"Decodes GSM encoded audio", "Decodes GSM encoded audio",
"Wim Taymans <wim.taymans@chello.be>", "Philippe Khalaf <burger@speedy.org>",
}; };
/* GSMDec signals and args */ /* GSMDec signals and args */
@ -42,15 +47,15 @@ enum
enum enum
{ {
ARG_0
/* FILL ME */ /* FILL ME */
ARG_0
}; };
static void gst_gsmdec_base_init (gpointer g_class); static void gst_gsmdec_base_init (gpointer g_class);
static void gst_gsmdec_class_init (GstGSMDec * klass); static void gst_gsmdec_class_init (GstGSMDec * klass);
static void gst_gsmdec_init (GstGSMDec * gsmdec); static void gst_gsmdec_init (GstGSMDec * gsmdec);
static GstFlowReturn gst_gsmdec_chain (GstPad * pad, GstBuffer * buffer); static GstFlowReturn gst_gsmdec_chain (GstPad * pad, GstBuffer * buf);
static GstElementClass *parent_class = NULL; static GstElementClass *parent_class = NULL;
@ -118,13 +123,13 @@ gst_gsmdec_class_init (GstGSMDec * klass)
gstelement_class = (GstElementClass *) klass; gstelement_class = (GstElementClass *) klass;
parent_class = g_type_class_ref (GST_TYPE_ELEMENT); parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
GST_DEBUG_CATEGORY_INIT (gsmdec_debug, "gsmdec", 0, "GSM Decoder");
} }
static void static void
gst_gsmdec_init (GstGSMDec * gsmdec) gst_gsmdec_init (GstGSMDec * gsmdec)
{ {
GST_DEBUG ("gst_gsmdec_init: initializing");
/* create the sink and src pads */ /* create the sink and src pads */
gsmdec->sinkpad = gsmdec->sinkpad =
gst_pad_new_from_template (gst_static_pad_template_get gst_pad_new_from_template (gst_static_pad_template_get
@ -138,72 +143,63 @@ gst_gsmdec_init (GstGSMDec * gsmdec)
gst_element_add_pad (GST_ELEMENT (gsmdec), gsmdec->srcpad); gst_element_add_pad (GST_ELEMENT (gsmdec), gsmdec->srcpad);
gsmdec->state = gsm_create (); gsmdec->state = gsm_create ();
gsmdec->bufsize = 0; // turn on WAN49 handling
gsmdec->next_ts = 0; gint use_wav49 = 0;
gsm_option (gsmdec->state, GSM_OPT_WAV49, &use_wav49);
gsmdec->next_of = 0; gsmdec->next_of = 0;
gsmdec->next_ts = 0;
} }
static GstFlowReturn static GstFlowReturn
gst_gsmdec_chain (GstPad * pad, GstBuffer * buf) gst_gsmdec_chain (GstPad * pad, GstBuffer * buf)
{ {
GstGSMDec *gsmdec; GstGSMDec *gsmdec;
gsm_byte *data;
g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
gsmdec = GST_GSMDEC (gst_pad_get_parent (pad)); gsmdec = GST_GSMDEC (gst_pad_get_parent (pad));
g_return_val_if_fail (GST_IS_GSMDEC (gsmdec), GST_FLOW_ERROR);
gsm_byte *data = (gsm_byte *) GST_BUFFER_DATA (buf); g_return_val_if_fail (GST_PAD_IS_LINKED (gsmdec->srcpad), GST_FLOW_ERROR);
guint size = GST_BUFFER_SIZE (buf);
if (gsmdec->bufsize && (gsmdec->bufsize + size >= 33)) { // do we have enough bytes to read a header
if (GST_BUFFER_SIZE (buf) >= 33) {
GstBuffer *outbuf; GstBuffer *outbuf;
memcpy (gsmdec->buffer + gsmdec->bufsize, data,
(33 - gsmdec->bufsize) * sizeof (gsm_byte));
outbuf = gst_buffer_new_and_alloc (160 * sizeof (gsm_signal)); outbuf = gst_buffer_new_and_alloc (160 * sizeof (gsm_signal));
// TODO take new segment in consideration, if not given restart
// timestamps at 0
if (GST_BUFFER_TIMESTAMP (buf) == GST_CLOCK_TIME_NONE) {
/* If we are not given any timestamp */
GST_BUFFER_TIMESTAMP (outbuf) = gsmdec->next_ts; GST_BUFFER_TIMESTAMP (outbuf) = gsmdec->next_ts;
GST_BUFFER_DURATION (outbuf) = 20 * GST_MSECOND;
GST_BUFFER_OFFSET (outbuf) = gsmdec->next_of;
GST_BUFFER_OFFSET_END (outbuf) = gsmdec->next_of + 160 - 1;
gst_buffer_set_caps (outbuf, gst_pad_get_caps (gsmdec->srcpad));
gsmdec->next_ts += 20 * GST_MSECOND; gsmdec->next_ts += 20 * GST_MSECOND;
gsmdec->next_of += 160;
gsm_decode (gsmdec->state, gsmdec->buffer,
(gsm_signal *) GST_BUFFER_DATA (outbuf));
gst_pad_push (gsmdec->srcpad, outbuf);
size -= (33 - gsmdec->bufsize);
data += (33 - gsmdec->bufsize);
gsmdec->bufsize = 0;
} }
while (size >= 33) { else {
GstBuffer *outbuf; /* But if you insist on giving us a timestamp, you are welcome. */
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf);
}
outbuf = gst_buffer_new_and_alloc (160 * sizeof (gsm_signal));
GST_BUFFER_TIMESTAMP (outbuf) = gsmdec->next_ts;
GST_BUFFER_DURATION (outbuf) = 20 * GST_MSECOND; GST_BUFFER_DURATION (outbuf) = 20 * GST_MSECOND;
GST_BUFFER_OFFSET (outbuf) = gsmdec->next_of; GST_BUFFER_OFFSET (outbuf) = gsmdec->next_of;
GST_BUFFER_OFFSET_END (outbuf) = gsmdec->next_of + 160 - 1; GST_BUFFER_OFFSET_END (outbuf) = gsmdec->next_of + 160 - 1;
gst_buffer_set_caps (outbuf, gst_pad_get_caps (gsmdec->srcpad)); gst_buffer_set_caps (outbuf, gst_pad_get_caps (gsmdec->srcpad));
gsmdec->next_ts += 20 * GST_MSECOND;
gsmdec->next_of += 160; gsmdec->next_of += 160;
data = (gsm_byte *) GST_BUFFER_DATA (buf);
gsm_decode (gsmdec->state, data, (gsm_signal *) GST_BUFFER_DATA (outbuf)); gsm_decode (gsmdec->state, data, (gsm_signal *) GST_BUFFER_DATA (outbuf));
GST_DEBUG ("Pushing buffer of size %d ts %" GST_TIME_FORMAT,
GST_BUFFER_SIZE (outbuf),
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)));
//gst_util_dump_mem (GST_BUFFER_DATA(outbuf), GST_BUFFER_SIZE (outbuf));
gst_pad_push (gsmdec->srcpad, outbuf); gst_pad_push (gsmdec->srcpad, outbuf);
size -= 33;
data += 33;
} }
if (size) { gst_buffer_unref (buf);
memcpy (gsmdec->buffer + gsmdec->bufsize, data, size * sizeof (gsm_byte));
gsmdec->bufsize += size;
}
return GST_FLOW_OK; return GST_FLOW_OK;
} }

View file

@ -1,5 +1,7 @@
/* GStreamer /*
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> * Farsight
* GStreamer GSM decoder (uses WAV49 compiled libgsm)
* Copyright (C) 2005 Philippe Khalaf <burger@speedy.org>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public * modify it under the terms of the GNU Library General Public
@ -52,10 +54,8 @@ struct _GstGSMDec
GstPad *sinkpad, *srcpad; GstPad *sinkpad, *srcpad;
gsm state; gsm state;
gsm_byte buffer[33];
gint bufsize;
GstClockTime next_ts;
gint64 next_of; gint64 next_of;
GstClockTime next_ts;
}; };
struct _GstGSMDecClass struct _GstGSMDecClass

View file

@ -1,5 +1,7 @@
/* GStreamer /*
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> * Farsight
* GStreamer GSM encoder
* Copyright (C) 2005 Philippe Khalaf <burger@speedy.org>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public * modify it under the terms of the GNU Library General Public
@ -25,26 +27,28 @@
#include "gstgsmenc.h" #include "gstgsmenc.h"
GST_DEBUG_CATEGORY (gsmenc_debug);
#define GST_CAT_DEFAULT (gsmenc_debug)
/* elementfactory information */ /* elementfactory information */
GstElementDetails gst_gsmenc_details = { GstElementDetails gst_gsmenc_details = {
"GSM audio encoder", "GSM audio encoder",
"Codec/Encoder/Audio", "Codec/Encoder/Audio",
"Encodes audio using GSM", "Encodes GSM audio",
"Wim Taymans <wim.taymans@chello.be>", "Philippe Khalaf <burger@speedy.org>",
}; };
/* GSMEnc signals and args */ /* GSMEnc signals and args */
enum enum
{ {
FRAME_ENCODED,
/* FILL ME */ /* FILL ME */
LAST_SIGNAL LAST_SIGNAL
}; };
enum enum
{ {
ARG_0
/* FILL ME */ /* FILL ME */
ARG_0
}; };
static void gst_gsmenc_base_init (gpointer g_class); static void gst_gsmenc_base_init (gpointer g_class);
@ -54,10 +58,6 @@ static void gst_gsmenc_init (GstGSMEnc * gsmenc);
static GstFlowReturn gst_gsmenc_chain (GstPad * pad, GstBuffer * buf); static GstFlowReturn gst_gsmenc_chain (GstPad * pad, GstBuffer * buf);
static GstElementClass *parent_class = NULL; static GstElementClass *parent_class = NULL;
static guint gst_gsmenc_signals[LAST_SIGNAL] = { 0 };
static gboolean gst_gsmenc_sink_event (GstPad * pad, GstEvent * event);
GType GType
gst_gsmenc_get_type (void) gst_gsmenc_get_type (void)
@ -124,13 +124,9 @@ gst_gsmenc_class_init (GstGSMEnc * klass)
parent_class = g_type_class_ref (GST_TYPE_ELEMENT); parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
gst_gsmenc_signals[FRAME_ENCODED] = GST_DEBUG_CATEGORY_INIT (gsmenc_debug, "gsmenc", 0, "GSM Encoder");
g_signal_new ("frame-encoded", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstGSMEncClass, frame_encoded), NULL,
NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
} }
static void static void
gst_gsmenc_init (GstGSMEnc * gsmenc) gst_gsmenc_init (GstGSMEnc * gsmenc)
{ {
@ -140,7 +136,6 @@ gst_gsmenc_init (GstGSMEnc * gsmenc)
(&gsmenc_sink_template), "sink"); (&gsmenc_sink_template), "sink");
gst_element_add_pad (GST_ELEMENT (gsmenc), gsmenc->sinkpad); gst_element_add_pad (GST_ELEMENT (gsmenc), gsmenc->sinkpad);
gst_pad_set_chain_function (gsmenc->sinkpad, gst_gsmenc_chain); gst_pad_set_chain_function (gsmenc->sinkpad, gst_gsmenc_chain);
gst_pad_set_event_function (gsmenc->sinkpad, gst_gsmenc_sink_event);
gsmenc->srcpad = gsmenc->srcpad =
gst_pad_new_from_template (gst_static_pad_template_get gst_pad_new_from_template (gst_static_pad_template_get
@ -148,42 +143,14 @@ gst_gsmenc_init (GstGSMEnc * gsmenc)
gst_element_add_pad (GST_ELEMENT (gsmenc), gsmenc->srcpad); gst_element_add_pad (GST_ELEMENT (gsmenc), gsmenc->srcpad);
gsmenc->state = gsm_create (); gsmenc->state = gsm_create ();
gsmenc->bufsize = 0; // turn on WAN49 handling
gint use_wav49 = 0;
gsm_option (gsmenc->state, GSM_OPT_WAV49, &use_wav49);
gsmenc->adapter = gst_adapter_new ();
gsmenc->next_ts = 0; gsmenc->next_ts = 0;
gsmenc->firstBuf = TRUE;
}
static gboolean
gst_gsmenc_sink_event (GstPad * pad, GstEvent * event)
{
GstGSMEnc *gsmenc;
gsmenc = GST_GSMENC (GST_OBJECT_PARENT (pad));
gboolean ret = TRUE;
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_EOS:
{
GST_STREAM_LOCK (pad);
ret = gst_pad_push_event (gsmenc->srcpad, event);
GST_STREAM_UNLOCK (pad);
break;
}
case GST_EVENT_NEWSEGMENT:
{
/* drop the discontinuity */
gst_event_unref (event);
break;
}
default:
{
gst_pad_event_default (pad, event);
break;
}
}
return ret;
} }
static GstFlowReturn static GstFlowReturn
@ -191,51 +158,18 @@ gst_gsmenc_chain (GstPad * pad, GstBuffer * buf)
{ {
GstGSMEnc *gsmenc; GstGSMEnc *gsmenc;
gsm_signal *data; gsm_signal *data;
guint size;
GstFlowReturn ret = GST_FLOW_OK; g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
gsmenc = GST_GSMENC (gst_pad_get_parent (pad)); gsmenc = GST_GSMENC (gst_pad_get_parent (pad));
g_return_val_if_fail (GST_IS_GSMENC (gsmenc), GST_FLOW_ERROR);
data = (gsm_signal *) GST_BUFFER_DATA (buf); g_return_val_if_fail (GST_PAD_IS_LINKED (gsmenc->srcpad), GST_FLOW_ERROR);
size = GST_BUFFER_SIZE (buf) / sizeof (gsm_signal);
if (gsmenc->bufsize && (gsmenc->bufsize + size >= 160)) { gst_adapter_push (gsmenc->adapter, buf);
GstBuffer *outbuf;
memcpy (gsmenc->buffer + gsmenc->bufsize, data, while (gst_adapter_available (gsmenc->adapter) >= 320) {
(160 - gsmenc->bufsize) * sizeof (gsm_signal));
outbuf = gst_buffer_new_and_alloc (33 * sizeof (gsm_byte));
GST_BUFFER_TIMESTAMP (outbuf) = gsmenc->next_ts;
GST_BUFFER_DURATION (outbuf) = 20 * GST_MSECOND;
gsmenc->next_ts += 20 * GST_MSECOND;
gsm_encode (gsmenc->state, gsmenc->buffer,
(gsm_byte *) GST_BUFFER_DATA (outbuf));
gst_buffer_set_caps (outbuf, GST_PAD_CAPS (gsmenc->srcpad));
if (gsmenc->firstBuf) {
gst_pad_push_event (gsmenc->srcpad,
gst_event_new_newsegment (FALSE, 1.0, GST_FORMAT_DEFAULT,
0, GST_CLOCK_TIME_NONE, 0));
gsmenc->firstBuf = FALSE;
}
ret = gst_pad_push (gsmenc->srcpad, outbuf);
if (ret != GST_FLOW_OK) {
gst_buffer_unref (outbuf);
goto error;
}
size -= (160 - gsmenc->bufsize);
data += (160 - gsmenc->bufsize);
gsmenc->bufsize = 0;
}
while (size >= 160) {
GstBuffer *outbuf; GstBuffer *outbuf;
outbuf = gst_buffer_new_and_alloc (33 * sizeof (gsm_byte)); outbuf = gst_buffer_new_and_alloc (33 * sizeof (gsm_byte));
@ -243,34 +177,16 @@ gst_gsmenc_chain (GstPad * pad, GstBuffer * buf)
GST_BUFFER_DURATION (outbuf) = 20 * GST_MSECOND; GST_BUFFER_DURATION (outbuf) = 20 * GST_MSECOND;
gsmenc->next_ts += 20 * GST_MSECOND; gsmenc->next_ts += 20 * GST_MSECOND;
// encode 160 16-bit samples into 33 bytes
data = (gsm_signal *) gst_adapter_peek (gsmenc->adapter, 320);
gsm_encode (gsmenc->state, data, (gsm_byte *) GST_BUFFER_DATA (outbuf)); gsm_encode (gsmenc->state, data, (gsm_byte *) GST_BUFFER_DATA (outbuf));
gst_adapter_flush (gsmenc->adapter, 320);
gst_buffer_set_caps (outbuf, GST_PAD_CAPS (gsmenc->srcpad)); gst_buffer_set_caps (outbuf, gst_pad_get_caps (gsmenc->srcpad));
if (gsmenc->firstBuf) { GST_DEBUG ("Pushing buffer of size %d", GST_BUFFER_SIZE (outbuf));
gst_pad_push_event (gsmenc->srcpad, //gst_util_dump_mem (GST_BUFFER_DATA(outbuf), GST_BUFFER_SIZE (outbuf));
gst_event_new_newsegment (FALSE, 1.0, GST_FORMAT_DEFAULT, gst_pad_push (gsmenc->srcpad, outbuf);
0, GST_CLOCK_TIME_NONE, 0));
gsmenc->firstBuf = FALSE;
}
ret = gst_pad_push (gsmenc->srcpad, outbuf);
if (ret != GST_FLOW_OK) {
gst_buffer_unref (outbuf);
goto error;
} }
size -= 160; return GST_FLOW_OK;
data += 160;
}
if (size) {
memcpy (gsmenc->buffer + gsmenc->bufsize, data, size * sizeof (gsm_signal));
gsmenc->bufsize += size;
}
error:
gst_object_unref (gsmenc);
return ret;
} }

View file

@ -21,6 +21,7 @@
#define __GST_GSMENC_H__ #define __GST_GSMENC_H__
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/base/gstadapter.h>
#ifdef GSM_HEADER_IN_SUBDIR #ifdef GSM_HEADER_IN_SUBDIR
#include <gsm/gsm.h> #include <gsm/gsm.h>
@ -50,10 +51,9 @@ struct _GstGSMEnc
/* pads */ /* pads */
GstPad *sinkpad, *srcpad; GstPad *sinkpad, *srcpad;
GstAdapter *adapter;
gsm state; gsm state;
gsm_signal buffer[160];
gint bufsize;
GstClockTime next_ts; GstClockTime next_ts;
gboolean firstBuf; gboolean firstBuf;
}; };
@ -61,9 +61,6 @@ struct _GstGSMEnc
struct _GstGSMEncClass struct _GstGSMEncClass
{ {
GstElementClass parent_class; GstElementClass parent_class;
/* signals */
void (*frame_encoded) (GstElement * element);
}; };
GType gst_gsmenc_get_type (void); GType gst_gsmenc_get_type (void);