mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 08:46:40 +00:00
spanplc: Port to 1.0 API
This commit is contained in:
parent
77d4a59969
commit
f9320170cd
3 changed files with 68 additions and 112 deletions
|
@ -323,7 +323,7 @@ GST_PLUGINS_NONPORTED=" aiff \
|
||||||
decklink fbdev linsys vcd \
|
decklink fbdev linsys vcd \
|
||||||
apexsink cdaudio cog dc1394 dirac directfb \
|
apexsink cdaudio cog dc1394 dirac directfb \
|
||||||
gsettings jasper ladspa \
|
gsettings jasper ladspa \
|
||||||
musepack musicbrainz nas neon ofa openal rsvg sdl sndfile spandsp timidity \
|
musepack musicbrainz nas neon ofa openal rsvg sdl sndfile timidity \
|
||||||
directsound directdraw direct3d9 acm wininet \
|
directsound directdraw direct3d9 acm wininet \
|
||||||
wildmidi xvid lv2 teletextdec sndio uvch264"
|
wildmidi xvid lv2 teletextdec sndio uvch264"
|
||||||
AC_SUBST(GST_PLUGINS_NONPORTED)
|
AC_SUBST(GST_PLUGINS_NONPORTED)
|
||||||
|
|
|
@ -34,7 +34,9 @@
|
||||||
|
|
||||||
#include "gstspanplc.h"
|
#include "gstspanplc.h"
|
||||||
|
|
||||||
GST_BOILERPLATE (GstSpanPlc, gst_span_plc, GstElement, GST_TYPE_ELEMENT);
|
#include <gst/audio/audio.h>
|
||||||
|
|
||||||
|
G_DEFINE_TYPE (GstSpanPlc, gst_span_plc, GST_TYPE_ELEMENT);
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_STATIC (gst_span_plc_debug);
|
GST_DEBUG_CATEGORY_STATIC (gst_span_plc_debug);
|
||||||
#define GST_CAT_DEFAULT gst_span_plc_debug
|
#define GST_CAT_DEFAULT gst_span_plc_debug
|
||||||
|
@ -43,44 +45,26 @@ GST_DEBUG_CATEGORY_STATIC (gst_span_plc_debug);
|
||||||
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
||||||
GST_PAD_SRC,
|
GST_PAD_SRC,
|
||||||
GST_PAD_ALWAYS,
|
GST_PAD_ALWAYS,
|
||||||
GST_STATIC_CAPS ("audio/x-raw-int, "
|
GST_STATIC_CAPS ("audio/x-raw, format=\"" GST_AUDIO_NE (S16) "\", "
|
||||||
"endianness = (int) BYTE_ORDER, signed = (bool) TRUE, "
|
"rate = " GST_AUDIO_RATE_RANGE " , channels = (int) 1")
|
||||||
"width = (int) 16, depth = (int) 16, "
|
|
||||||
"rate = (int) [ 1, MAX ], channels = (int) 1")
|
|
||||||
);
|
);
|
||||||
|
|
||||||
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
|
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||||
GST_PAD_SINK,
|
GST_PAD_SINK,
|
||||||
GST_PAD_ALWAYS,
|
GST_PAD_ALWAYS,
|
||||||
GST_STATIC_CAPS ("audio/x-raw-int, "
|
GST_STATIC_CAPS ("audio/x-raw, format=\"" GST_AUDIO_NE (S16) "\", "
|
||||||
"endianness = (int) BYTE_ORDER, signed = (bool) TRUE, "
|
"rate = " GST_AUDIO_RATE_RANGE " , channels = (int) 1")
|
||||||
"width = (int) 16, depth = (int) 16, "
|
|
||||||
"rate = (int) [ 1, MAX ], channels = (int) 1")
|
|
||||||
);
|
);
|
||||||
|
|
||||||
static void gst_span_plc_dispose (GObject * object);
|
static void gst_span_plc_dispose (GObject * object);
|
||||||
|
|
||||||
static GstStateChangeReturn gst_span_plc_change_state (GstElement * element,
|
static GstStateChangeReturn gst_span_plc_change_state (GstElement * element,
|
||||||
GstStateChange transition);
|
GstStateChange transition);
|
||||||
static gboolean gst_span_plc_setcaps_sink (GstPad * pad, GstCaps * caps);
|
static void gst_span_plc_setcaps_sink (GstSpanPlc * plc, GstCaps * caps);
|
||||||
static GstFlowReturn gst_span_plc_chain (GstPad * pad, GstBuffer * buf);
|
static GstFlowReturn gst_span_plc_chain (GstPad * pad, GstObject * parent,
|
||||||
static gboolean gst_span_plc_event_sink (GstPad * pad, GstEvent * event);
|
GstBuffer * buf);
|
||||||
|
static gboolean gst_span_plc_event_sink (GstPad * pad, GstObject * parent,
|
||||||
static void
|
GstEvent * event);
|
||||||
gst_span_plc_base_init (gpointer gclass)
|
|
||||||
{
|
|
||||||
GstElementClass *element_class = (GstElementClass *) gclass;
|
|
||||||
|
|
||||||
gst_element_class_add_pad_template (element_class,
|
|
||||||
gst_static_pad_template_get (&src_factory));
|
|
||||||
gst_element_class_add_pad_template (element_class,
|
|
||||||
gst_static_pad_template_get (&sink_factory));
|
|
||||||
|
|
||||||
gst_element_class_set_details_simple (element_class, "SpanDSP PLC",
|
|
||||||
"Filter/Effect/Audio",
|
|
||||||
"Adds packet loss concealment to audio",
|
|
||||||
"Youness Alaoui <youness.alaoui@collabora.co.uk>");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* initialize the plugin's class */
|
/* initialize the plugin's class */
|
||||||
static void
|
static void
|
||||||
|
@ -89,6 +73,16 @@ gst_span_plc_class_init (GstSpanPlcClass * klass)
|
||||||
GObjectClass *gobject_class = (GObjectClass *) klass;
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
||||||
GstElementClass *gstelement_class = (GstElementClass *) klass;
|
GstElementClass *gstelement_class = (GstElementClass *) klass;
|
||||||
|
|
||||||
|
gst_element_class_add_pad_template (gstelement_class,
|
||||||
|
gst_static_pad_template_get (&src_factory));
|
||||||
|
gst_element_class_add_pad_template (gstelement_class,
|
||||||
|
gst_static_pad_template_get (&sink_factory));
|
||||||
|
|
||||||
|
gst_element_class_set_details_simple (gstelement_class, "SpanDSP PLC",
|
||||||
|
"Filter/Effect/Audio",
|
||||||
|
"Adds packet loss concealment to audio",
|
||||||
|
"Youness Alaoui <youness.alaoui@collabora.co.uk>");
|
||||||
|
|
||||||
gobject_class->dispose = gst_span_plc_dispose;
|
gobject_class->dispose = gst_span_plc_dispose;
|
||||||
|
|
||||||
gstelement_class->change_state =
|
gstelement_class->change_state =
|
||||||
|
@ -96,27 +90,19 @@ gst_span_plc_class_init (GstSpanPlcClass * klass)
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_INIT (gst_span_plc_debug, "spanplc",
|
GST_DEBUG_CATEGORY_INIT (gst_span_plc_debug, "spanplc",
|
||||||
0, "spanDSP's packet loss concealment");
|
0, "spanDSP's packet loss concealment");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_span_plc_init (GstSpanPlc * plc, GstSpanPlcClass * gclass)
|
gst_span_plc_init (GstSpanPlc * plc)
|
||||||
{
|
{
|
||||||
GST_DEBUG_OBJECT (plc, "init");
|
GST_DEBUG_OBJECT (plc, "init");
|
||||||
|
|
||||||
plc->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
|
plc->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
|
||||||
plc->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
|
plc->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
|
||||||
|
|
||||||
gst_pad_set_setcaps_function (plc->sinkpad,
|
|
||||||
GST_DEBUG_FUNCPTR (gst_span_plc_setcaps_sink));
|
|
||||||
|
|
||||||
gst_pad_set_getcaps_function (plc->srcpad,
|
|
||||||
GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps));
|
|
||||||
gst_pad_set_getcaps_function (plc->sinkpad,
|
|
||||||
GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps));
|
|
||||||
|
|
||||||
gst_pad_set_chain_function (plc->sinkpad,
|
gst_pad_set_chain_function (plc->sinkpad,
|
||||||
GST_DEBUG_FUNCPTR (gst_span_plc_chain));
|
GST_DEBUG_FUNCPTR (gst_span_plc_chain));
|
||||||
|
|
||||||
gst_pad_set_event_function (plc->sinkpad,
|
gst_pad_set_event_function (plc->sinkpad,
|
||||||
GST_DEBUG_FUNCPTR (gst_span_plc_event_sink));
|
GST_DEBUG_FUNCPTR (gst_span_plc_event_sink));
|
||||||
|
|
||||||
|
@ -124,7 +110,6 @@ gst_span_plc_init (GstSpanPlc * plc, GstSpanPlcClass * gclass)
|
||||||
gst_element_add_pad (GST_ELEMENT (plc), plc->sinkpad);
|
gst_element_add_pad (GST_ELEMENT (plc), plc->sinkpad);
|
||||||
|
|
||||||
plc->plc_state = NULL;
|
plc->plc_state = NULL;
|
||||||
plc->last_stop = GST_CLOCK_TIME_NONE;
|
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (plc, "init complete");
|
GST_DEBUG_OBJECT (plc, "init complete");
|
||||||
}
|
}
|
||||||
|
@ -138,7 +123,7 @@ gst_span_plc_dispose (GObject * object)
|
||||||
plc_free (plc->plc_state);
|
plc_free (plc->plc_state);
|
||||||
plc->plc_state = NULL;
|
plc->plc_state = NULL;
|
||||||
|
|
||||||
G_OBJECT_CLASS (parent_class)->dispose (object);
|
G_OBJECT_CLASS (gst_span_plc_parent_class)->dispose (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -150,7 +135,6 @@ gst_span_plc_flush (GstSpanPlc * plc, gboolean renew)
|
||||||
plc->plc_state = plc_init (NULL);
|
plc->plc_state = plc_init (NULL);
|
||||||
else
|
else
|
||||||
plc->plc_state = NULL;
|
plc->plc_state = NULL;
|
||||||
plc->last_stop = GST_CLOCK_TIME_NONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstStateChangeReturn
|
static GstStateChangeReturn
|
||||||
|
@ -167,7 +151,8 @@ gst_span_plc_change_state (GstElement * element, GstStateChange transition)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
ret = GST_ELEMENT_CLASS (gst_span_plc_parent_class)->change_state (element,
|
||||||
|
transition);
|
||||||
|
|
||||||
switch (transition) {
|
switch (transition) {
|
||||||
case GST_STATE_CHANGE_READY_TO_NULL:
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
||||||
|
@ -179,108 +164,86 @@ gst_span_plc_change_state (GstElement * element, GstStateChange transition)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static void
|
||||||
gst_span_plc_setcaps_sink (GstPad * pad, GstCaps * caps)
|
gst_span_plc_setcaps_sink (GstSpanPlc * plc, GstCaps * caps)
|
||||||
{
|
{
|
||||||
GstSpanPlc *plc = GST_SPAN_PLC (gst_pad_get_parent (pad));
|
|
||||||
GstStructure *s = NULL;
|
GstStructure *s = NULL;
|
||||||
gboolean ret = FALSE;
|
gint sample_rate;
|
||||||
|
|
||||||
ret = gst_pad_set_caps (plc->srcpad, caps);
|
|
||||||
s = gst_caps_get_structure (caps, 0);
|
s = gst_caps_get_structure (caps, 0);
|
||||||
if (s) {
|
if (!s)
|
||||||
gst_structure_get_int (s, "rate", &plc->sample_rate);
|
return;
|
||||||
GST_DEBUG_OBJECT (plc, "setcaps: got sample rate : %d", plc->sample_rate);
|
|
||||||
|
gst_structure_get_int (s, "rate", &sample_rate);
|
||||||
|
if (sample_rate != plc->sample_rate) {
|
||||||
|
GST_DEBUG_OBJECT (plc, "setcaps: got sample rate : %d", sample_rate);
|
||||||
|
plc->sample_rate = sample_rate;
|
||||||
|
gst_span_plc_flush (plc, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_span_plc_flush (plc, TRUE);
|
|
||||||
gst_object_unref (plc);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_span_plc_chain (GstPad * pad, GstBuffer * buffer)
|
gst_span_plc_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
|
||||||
{
|
{
|
||||||
GstSpanPlc *plc = GST_SPAN_PLC (GST_PAD_PARENT (pad));
|
GstSpanPlc *plc = GST_SPAN_PLC (parent);
|
||||||
GstClockTime buffer_duration;
|
GstMapInfo map;
|
||||||
|
|
||||||
if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer))
|
|
||||||
plc->last_stop = GST_BUFFER_TIMESTAMP (buffer);
|
|
||||||
else
|
|
||||||
GST_WARNING_OBJECT (plc, "Buffer has no timestamp!");
|
|
||||||
|
|
||||||
if (GST_BUFFER_DURATION_IS_VALID (buffer)) {
|
|
||||||
buffer_duration = GST_BUFFER_DURATION (buffer);
|
|
||||||
} else {
|
|
||||||
GST_WARNING_OBJECT (plc, "Buffer has no duration!");
|
|
||||||
buffer_duration = (GST_BUFFER_SIZE (buffer) /
|
|
||||||
(plc->sample_rate * sizeof (guint16))) * GST_SECOND;
|
|
||||||
GST_DEBUG_OBJECT (plc, "Buffer duration : %" GST_TIME_FORMAT,
|
|
||||||
GST_TIME_ARGS (buffer_duration));
|
|
||||||
}
|
|
||||||
|
|
||||||
plc->last_stop += buffer_duration;
|
|
||||||
|
|
||||||
if (plc->plc_state->missing_samples != 0)
|
if (plc->plc_state->missing_samples != 0)
|
||||||
buffer = gst_buffer_make_writable (buffer);
|
buffer = gst_buffer_make_writable (buffer);
|
||||||
plc_rx (plc->plc_state, (int16_t *) GST_BUFFER_DATA (buffer),
|
gst_buffer_map (buffer, &map, GST_MAP_READWRITE);
|
||||||
GST_BUFFER_SIZE (buffer) / 2);
|
plc_rx (plc->plc_state, (int16_t *) map.data, map.size / 2);
|
||||||
|
gst_buffer_unmap (buffer, &map);
|
||||||
|
|
||||||
return gst_pad_push (plc->srcpad, buffer);
|
return gst_pad_push (plc->srcpad, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_span_plc_send_fillin (GstSpanPlc * plc, GstClockTime duration)
|
gst_span_plc_send_fillin (GstSpanPlc * plc, GstClockTime timestamp,
|
||||||
|
GstClockTime duration)
|
||||||
{
|
{
|
||||||
guint buf_size;
|
guint buf_size;
|
||||||
GstBuffer *buffer = NULL;
|
GstBuffer *buffer = NULL;
|
||||||
|
GstMapInfo map;
|
||||||
|
|
||||||
buf_size = ((float) duration / GST_SECOND) * plc->sample_rate;
|
buf_size = ((float) duration / GST_SECOND) * plc->sample_rate;
|
||||||
buf_size *= sizeof (guint16);
|
buf_size *= sizeof (guint16);
|
||||||
buffer = gst_buffer_new_and_alloc (buf_size);
|
buffer = gst_buffer_new_and_alloc (buf_size);
|
||||||
GST_DEBUG_OBJECT (plc, "Missing packet of %" GST_TIME_FORMAT
|
GST_DEBUG_OBJECT (plc, "Missing packet of %" GST_TIME_FORMAT
|
||||||
" == %d bytes", GST_TIME_ARGS (duration), buf_size);
|
" == %d bytes", GST_TIME_ARGS (duration), buf_size);
|
||||||
plc_fillin (plc->plc_state, (int16_t *) GST_BUFFER_DATA (buffer),
|
gst_buffer_map (buffer, &map, GST_MAP_READWRITE);
|
||||||
GST_BUFFER_SIZE (buffer) / 2);
|
plc_fillin (plc->plc_state, (int16_t *) map.data, map.size / 2);
|
||||||
GST_BUFFER_TIMESTAMP (buffer) = plc->last_stop;
|
gst_buffer_unmap (buffer, &map);
|
||||||
|
GST_BUFFER_PTS (buffer) = timestamp;
|
||||||
GST_BUFFER_DURATION (buffer) = duration;
|
GST_BUFFER_DURATION (buffer) = duration;
|
||||||
gst_buffer_set_caps (buffer, GST_PAD_CAPS (plc->srcpad));
|
|
||||||
gst_pad_push (plc->srcpad, buffer);
|
gst_pad_push (plc->srcpad, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_span_plc_event_sink (GstPad * pad, GstEvent * event)
|
gst_span_plc_event_sink (GstPad * pad, GstObject * parent, GstEvent * event)
|
||||||
{
|
{
|
||||||
|
GstSpanPlc *plc = GST_SPAN_PLC (parent);
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
GstSpanPlc *plc = GST_SPAN_PLC (gst_pad_get_parent (pad));
|
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (plc, "received event %s", GST_EVENT_TYPE_NAME (event));
|
GST_DEBUG_OBJECT (plc, "received event %s", GST_EVENT_TYPE_NAME (event));
|
||||||
|
|
||||||
switch (GST_EVENT_TYPE (event)) {
|
switch (GST_EVENT_TYPE (event)) {
|
||||||
case GST_EVENT_NEWSEGMENT:
|
case GST_EVENT_CAPS:
|
||||||
{
|
{
|
||||||
GstFormat format;
|
GstCaps *caps;
|
||||||
gdouble rate;
|
gst_event_parse_caps (event, &caps);
|
||||||
gint64 start, stop, time;
|
gst_span_plc_setcaps_sink (plc, caps);
|
||||||
gboolean update;
|
|
||||||
|
|
||||||
gst_event_parse_new_segment (event, &update, &rate, &format, &start,
|
|
||||||
&stop, &time);
|
|
||||||
|
|
||||||
if (format != GST_FORMAT_TIME)
|
|
||||||
goto newseg_wrong_format;
|
|
||||||
|
|
||||||
if (update) {
|
|
||||||
/* time progressed without data, see if we can fill the gap with
|
|
||||||
* some concealment data */
|
|
||||||
if (plc->last_stop < start)
|
|
||||||
gst_span_plc_send_fillin (plc, start - plc->last_stop);
|
|
||||||
}
|
|
||||||
plc->last_stop = start;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GST_EVENT_FLUSH_START:
|
case GST_EVENT_GAP:
|
||||||
|
{
|
||||||
|
GstClockTime timestamp;
|
||||||
|
GstClockTime duration;
|
||||||
|
|
||||||
|
gst_event_parse_gap (event, ×tamp, &duration);
|
||||||
|
gst_span_plc_send_fillin (plc, timestamp, duration);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case GST_EVENT_FLUSH_STOP:
|
||||||
gst_span_plc_flush (plc, TRUE);
|
gst_span_plc_flush (plc, TRUE);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -291,10 +254,4 @@ gst_span_plc_event_sink (GstPad * pad, GstEvent * event)
|
||||||
gst_object_unref (plc);
|
gst_object_unref (plc);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
newseg_wrong_format:
|
|
||||||
{
|
|
||||||
GST_DEBUG_OBJECT (plc, "received non TIME newsegment");
|
|
||||||
gst_object_unref (plc);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,6 @@ struct _GstSpanPlc
|
||||||
|
|
||||||
/* <private> */
|
/* <private> */
|
||||||
plc_state_t *plc_state;
|
plc_state_t *plc_state;
|
||||||
GstClockTime last_stop;
|
|
||||||
gint sample_rate;
|
gint sample_rate;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue