summaryrefslogtreecommitdiff
path: root/gst/siren
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian.droege@collabora.co.uk>2012-03-29 17:41:53 +0200
committerSebastian Dröge <sebastian.droege@collabora.co.uk>2012-03-29 17:41:53 +0200
commit860ccd414dbb313fabf065b92838f0f39037584b (patch)
tree0d5c0d3510db3ca3d7e6487420e8d09f74ae1961 /gst/siren
parenta9ec4d62a89dd53aa295af02c7d5f57ef936359b (diff)
parentd84d98943af42ce645ee022207bcf04e747d2d4a (diff)
downloadgstreamer-plugins-bad-860ccd414dbb313fabf065b92838f0f39037584b.tar.gz
Merge remote-tracking branch 'origin/0.10'
Conflicts: NEWS RELEASE common configure.ac docs/libs/gst-plugins-bad-libs-sections.txt docs/plugins/gst-plugins-bad-plugins.args docs/plugins/gst-plugins-bad-plugins.hierarchy docs/plugins/gst-plugins-bad-plugins.interfaces docs/plugins/inspect/plugin-adpcmdec.xml docs/plugins/inspect/plugin-adpcmenc.xml docs/plugins/inspect/plugin-assrender.xml docs/plugins/inspect/plugin-audiovisualizers.xml docs/plugins/inspect/plugin-autoconvert.xml docs/plugins/inspect/plugin-bayer.xml docs/plugins/inspect/plugin-bz2.xml docs/plugins/inspect/plugin-camerabin2.xml docs/plugins/inspect/plugin-celt.xml docs/plugins/inspect/plugin-dataurisrc.xml docs/plugins/inspect/plugin-debugutilsbad.xml docs/plugins/inspect/plugin-dtmf.xml docs/plugins/inspect/plugin-dtsdec.xml docs/plugins/inspect/plugin-dvbsuboverlay.xml docs/plugins/inspect/plugin-dvdspu.xml docs/plugins/inspect/plugin-faac.xml docs/plugins/inspect/plugin-faad.xml docs/plugins/inspect/plugin-gsm.xml docs/plugins/inspect/plugin-h264parse.xml docs/plugins/inspect/plugin-mms.xml docs/plugins/inspect/plugin-modplug.xml docs/plugins/inspect/plugin-mpeg2enc.xml docs/plugins/inspect/plugin-mpegdemux2.xml docs/plugins/inspect/plugin-mpegtsdemux.xml docs/plugins/inspect/plugin-mpegvideoparse.xml docs/plugins/inspect/plugin-mplex.xml docs/plugins/inspect/plugin-pcapparse.xml docs/plugins/inspect/plugin-rawparse.xml docs/plugins/inspect/plugin-rtpmux.xml docs/plugins/inspect/plugin-rtpvp8.xml docs/plugins/inspect/plugin-scaletempo.xml docs/plugins/inspect/plugin-schro.xml docs/plugins/inspect/plugin-sdp.xml docs/plugins/inspect/plugin-segmentclip.xml docs/plugins/inspect/plugin-shm.xml docs/plugins/inspect/plugin-videomaxrate.xml docs/plugins/inspect/plugin-videoparsersbad.xml docs/plugins/inspect/plugin-vp8.xml docs/plugins/inspect/plugin-y4mdec.xml ext/celt/gstceltdec.c ext/dts/gstdtsdec.c ext/modplug/gstmodplug.cc ext/opus/gstopusenc.c gst-libs/gst/video/gstbasevideocodec.c gst-libs/gst/video/gstbasevideocodec.h gst-libs/gst/video/gstbasevideodecoder.c gst-libs/gst/video/gstbasevideodecoder.h gst-libs/gst/video/gstbasevideoencoder.c gst-libs/gst/video/gstbasevideoencoder.h gst/adpcmdec/Makefile.am gst/audiovisualizers/gstbaseaudiovisualizer.c gst/h264parse/gsth264parse.c gst/mpegdemux/mpegtsparse.c gst/mpegtsdemux/mpegtsbase.c gst/mpegtsdemux/mpegtspacketizer.c gst/mpegtsdemux/mpegtsparse.c gst/mpegtsdemux/tsdemux.c gst/mpegtsdemux/tsdemux.h gst/mxf/mxfdemux.c gst/rawparse/gstaudioparse.c gst/videoparsers/gsth263parse.c gst/videoparsers/gsth264parse.c sys/d3dvideosink/d3dvideosink.c sys/decklink/gstdecklinksink.cpp sys/dvb/gstdvbsrc.c sys/shm/gstshmsrc.c sys/vdpau/h264/gstvdph264dec.c sys/vdpau/mpeg/gstvdpmpegdec.c tests/examples/opencv/gst_element_print_properties.c win32/common/config.h
Diffstat (limited to 'gst/siren')
-rw-r--r--gst/siren/Makefile.am2
-rw-r--r--gst/siren/gstsirendec.c223
-rw-r--r--gst/siren/gstsirendec.h12
-rw-r--r--gst/siren/gstsirenenc.c198
-rw-r--r--gst/siren/gstsirenenc.h12
5 files changed, 133 insertions, 314 deletions
diff --git a/gst/siren/Makefile.am b/gst/siren/Makefile.am
index 2be9ede49..c6d1d8cba 100644
--- a/gst/siren/Makefile.am
+++ b/gst/siren/Makefile.am
@@ -10,7 +10,7 @@ libgstsiren_la_SOURCES = gstsiren.c \
libgstsiren_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) \
$(GST_CFLAGS)
-libgstsiren_la_LIBADD = $(GST_PLUGINS_BASE_LIBS) -lgstrtp-@GST_MAJORMINOR@ \
+libgstsiren_la_LIBADD = $(GST_PLUGINS_BASE_LIBS) -lgstaudio-@GST_MAJORMINOR@ \
$(GST_BASE_LIBS) $(GST_LIBS) $(LIBM)
libgstsiren_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstsiren_la_LIBTOOLFLAGS = --tag=disable-static
diff --git a/gst/siren/gstsirendec.c b/gst/siren/gstsirendec.c
index 2e517199f..9dd12c359 100644
--- a/gst/siren/gstsirendec.c
+++ b/gst/siren/gstsirendec.c
@@ -69,14 +69,14 @@ enum
ARG_0,
};
-static void gst_siren_dec_finalize (GObject * object);
-
-static GstStateChangeReturn
-gst_siren_change_state (GstElement * element, GstStateChange transition);
-
-static gboolean gst_siren_dec_sink_setcaps (GstPad * pad, GstCaps * caps);
-static gboolean gst_siren_dec_sink_event (GstPad * pad, GstEvent * event);
-static GstFlowReturn gst_siren_dec_chain (GstPad * pad, GstBuffer * buf);
+static gboolean gst_siren_dec_start (GstAudioDecoder * dec);
+static gboolean gst_siren_dec_stop (GstAudioDecoder * dec);
+static gboolean gst_siren_dec_set_format (GstAudioDecoder * dec,
+ GstCaps * caps);
+static gboolean gst_siren_dec_parse (GstAudioDecoder * dec,
+ GstAdapter * adapter, gint * offset, gint * length);
+static GstFlowReturn gst_siren_dec_handle_frame (GstAudioDecoder * dec,
+ GstBuffer * buffer);
static void
_do_init (GType type)
@@ -84,8 +84,8 @@ _do_init (GType type)
GST_DEBUG_CATEGORY_INIT (sirendec_debug, "sirendec", 0, "sirendec");
}
-GST_BOILERPLATE_FULL (GstSirenDec, gst_siren_dec, GstElement,
- GST_TYPE_ELEMENT, _do_init);
+GST_BOILERPLATE_FULL (GstSirenDec, gst_siren_dec, GstAudioDecoder,
+ GST_TYPE_AUDIO_DECODER, _do_init);
static void
gst_siren_dec_base_init (gpointer klass)
@@ -106,17 +106,15 @@ gst_siren_dec_base_init (gpointer klass)
static void
gst_siren_dec_class_init (GstSirenDecClass * klass)
{
- GObjectClass *gobject_class;
- GstElementClass *gstelement_class;
-
- gobject_class = (GObjectClass *) klass;
- gstelement_class = (GstElementClass *) klass;
+ GstAudioDecoderClass *base_class = GST_AUDIO_DECODER_CLASS (klass);
GST_DEBUG ("Initializing Class");
- gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_siren_dec_finalize);
-
- gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_siren_change_state);
+ base_class->start = GST_DEBUG_FUNCPTR (gst_siren_dec_start);
+ base_class->stop = GST_DEBUG_FUNCPTR (gst_siren_dec_stop);
+ base_class->set_format = GST_DEBUG_FUNCPTR (gst_siren_dec_set_format);
+ base_class->parse = GST_DEBUG_FUNCPTR (gst_siren_dec_parse);
+ base_class->handle_frame = GST_DEBUG_FUNCPTR (gst_siren_dec_handle_frame);
GST_DEBUG ("Class Init done");
}
@@ -124,119 +122,103 @@ gst_siren_dec_class_init (GstSirenDecClass * klass)
static void
gst_siren_dec_init (GstSirenDec * dec, GstSirenDecClass * klass)
{
+}
- GST_DEBUG_OBJECT (dec, "Initializing");
- dec->decoder = Siren7_NewDecoder (16000);;
-
- dec->sinkpad = gst_pad_new_from_static_template (&sinktemplate, "sink");
- dec->srcpad = gst_pad_new_from_static_template (&srctemplate, "src");
+static gboolean
+gst_siren_dec_start (GstAudioDecoder * dec)
+{
+ GstSirenDec *sdec = GST_SIREN_DEC (dec);
- gst_pad_set_setcaps_function (dec->sinkpad,
- GST_DEBUG_FUNCPTR (gst_siren_dec_sink_setcaps));
- gst_pad_set_event_function (dec->sinkpad,
- GST_DEBUG_FUNCPTR (gst_siren_dec_sink_event));
- gst_pad_set_chain_function (dec->sinkpad,
- GST_DEBUG_FUNCPTR (gst_siren_dec_chain));
+ GST_DEBUG_OBJECT (dec, "start");
- gst_element_add_pad (GST_ELEMENT (dec), dec->sinkpad);
- gst_element_add_pad (GST_ELEMENT (dec), dec->srcpad);
+ sdec->decoder = Siren7_NewDecoder (16000);;
- dec->adapter = gst_adapter_new ();
+ /* no flushing please */
+ gst_audio_decoder_set_drainable (dec, FALSE);
- GST_DEBUG_OBJECT (dec, "Init done");
+ return TRUE;
}
-static void
-gst_siren_dec_finalize (GObject * object)
+static gboolean
+gst_siren_dec_stop (GstAudioDecoder * dec)
{
- GstSirenDec *dec = GST_SIREN_DEC (object);
+ GstSirenDec *sdec = GST_SIREN_DEC (dec);
- GST_DEBUG_OBJECT (dec, "Finalize");
+ GST_DEBUG_OBJECT (dec, "stop");
- Siren7_CloseDecoder (dec->decoder);
- g_object_unref (dec->adapter);
+ Siren7_CloseDecoder (sdec->decoder);
- G_OBJECT_CLASS (parent_class)->finalize (object);
+ return TRUE;
}
static gboolean
-gst_siren_dec_sink_setcaps (GstPad * pad, GstCaps * caps)
+gst_siren_dec_negotiate (GstSirenDec * dec)
{
- GstSirenDec *dec;
gboolean res;
GstCaps *outcaps;
- dec = GST_SIREN_DEC (GST_PAD_PARENT (pad));
-
outcaps = gst_static_pad_template_get_caps (&srctemplate);
- res = gst_pad_set_caps (dec->srcpad, outcaps);
+ res = gst_pad_set_caps (GST_AUDIO_DECODER_SRC_PAD (dec), outcaps);
gst_caps_unref (outcaps);
return res;
}
static gboolean
-gst_siren_dec_sink_event (GstPad * pad, GstEvent * event)
+gst_siren_dec_set_format (GstAudioDecoder * bdec, GstCaps * caps)
{
GstSirenDec *dec;
- gboolean res;
- dec = GST_SIREN_DEC (GST_PAD_PARENT (pad));
-
- switch (GST_EVENT_TYPE (event)) {
- case GST_EVENT_EOS:
- gst_adapter_clear (dec->adapter);
- res = gst_pad_push_event (dec->srcpad, event);
- break;
- case GST_EVENT_FLUSH_STOP:
- gst_adapter_clear (dec->adapter);
- res = gst_pad_push_event (dec->srcpad, event);
- break;
- default:
- res = gst_pad_push_event (dec->srcpad, event);
- break;
+ dec = GST_SIREN_DEC (bdec);
+
+ return gst_siren_dec_negotiate (dec);
+}
+
+static GstFlowReturn
+gst_siren_dec_parse (GstAudioDecoder * dec, GstAdapter * adapter,
+ gint * offset, gint * length)
+{
+ gint size;
+ GstFlowReturn ret;
+
+ size = gst_adapter_available (adapter);
+ g_return_val_if_fail (size > 0, GST_FLOW_ERROR);
+
+ /* accept any multiple of frames */
+ if (size > 40) {
+ ret = GST_FLOW_OK;
+ *offset = 0;
+ *length = size - (size % 40);
+ } else {
+ ret = GST_FLOW_UNEXPECTED;
}
- return res;
+
+ return ret;
}
static GstFlowReturn
-gst_siren_dec_chain (GstPad * pad, GstBuffer * buf)
+gst_siren_dec_handle_frame (GstAudioDecoder * bdec, GstBuffer * buf)
{
GstSirenDec *dec;
GstFlowReturn ret = GST_FLOW_OK;
GstBuffer *out_buf;
guint8 *in_data, *out_data;
- guint8 *to_free = NULL;
guint i, size, num_frames;
gint out_size, in_size;
gint decode_ret;
- gboolean discont;
- GstClockTime timestamp;
- guint64 distance;
- GstCaps *outcaps;
-
- dec = GST_SIREN_DEC (GST_PAD_PARENT (pad));
- discont = GST_BUFFER_IS_DISCONT (buf);
- if (discont) {
- GST_DEBUG_OBJECT (dec, "received DISCONT, flush adapter");
- gst_adapter_clear (dec->adapter);
- dec->discont = TRUE;
- }
+ dec = GST_SIREN_DEC (bdec);
- gst_adapter_push (dec->adapter, buf);
+ size = GST_BUFFER_SIZE (buf);
- size = gst_adapter_available (dec->adapter);
+ GST_LOG_OBJECT (dec, "Received buffer of size %u", size);
- GST_LOG_OBJECT (dec, "Received buffer of size %u with adapter of size : %u",
- GST_BUFFER_SIZE (buf), size);
+ g_return_val_if_fail (size % 40 == 0, GST_FLOW_ERROR);
+ g_return_val_if_fail (size > 0, GST_FLOW_ERROR);
/* process 40 input bytes into 640 output bytes */
num_frames = size / 40;
- if (num_frames == 0)
- goto done;
-
/* this is the input/output size */
in_size = num_frames * 40;
out_size = num_frames * 640;
@@ -244,32 +226,19 @@ gst_siren_dec_chain (GstPad * pad, GstBuffer * buf)
GST_LOG_OBJECT (dec, "we have %u frames, %u in, %u out", num_frames, in_size,
out_size);
- /* set output caps when needed */
- if ((outcaps = GST_PAD_CAPS (dec->srcpad)) == NULL) {
- outcaps = gst_static_pad_template_get_caps (&srctemplate);
- gst_pad_set_caps (dec->srcpad, outcaps);
- gst_caps_unref (outcaps);
+ /* allow and handle un-negotiated input */
+ if (G_UNLIKELY (GST_PAD_CAPS (GST_AUDIO_DECODER_SRC_PAD (dec)) == NULL)) {
+ gst_siren_dec_negotiate (dec);
}
/* get a buffer */
- ret = gst_pad_alloc_buffer_and_set_caps (dec->srcpad, -1,
- out_size, outcaps, &out_buf);
+ ret = gst_pad_alloc_buffer_and_set_caps (GST_AUDIO_DECODER_SRC_PAD (dec), -1,
+ out_size, GST_PAD_CAPS (GST_AUDIO_DECODER_SRC_PAD (dec)), &out_buf);
if (ret != GST_FLOW_OK)
goto alloc_failed;
- /* get the timestamp for the output buffer */
- timestamp = gst_adapter_prev_timestamp (dec->adapter, &distance);
-
- /* add the amount of time taken by the distance, each frame is 20ms */
- if (timestamp != -1)
- timestamp += (distance / 40) * FRAME_DURATION;
-
- GST_LOG_OBJECT (dec,
- "timestamp %" GST_TIME_FORMAT ", distance %" G_GUINT64_FORMAT,
- GST_TIME_ARGS (timestamp), distance);
-
/* get the input data for all the frames */
- to_free = in_data = gst_adapter_take (dec->adapter, in_size);
+ in_data = GST_BUFFER_DATA (buf);
out_data = GST_BUFFER_DATA (out_buf);
for (i = 0; i < num_frames; i++) {
@@ -287,21 +256,11 @@ gst_siren_dec_chain (GstPad * pad, GstBuffer * buf)
GST_LOG_OBJECT (dec, "Finished decoding");
- /* mark discont */
- if (dec->discont) {
- GST_BUFFER_FLAG_SET (out_buf, GST_BUFFER_FLAG_DISCONT);
- dec->discont = FALSE;
- }
-
- GST_BUFFER_TIMESTAMP (out_buf) = timestamp;
- GST_BUFFER_DURATION (out_buf) = num_frames * FRAME_DURATION;
-
- ret = gst_pad_push (dec->srcpad, out_buf);
+ /* might really be multiple frames,
+ * but was treated as one for all purposes here */
+ ret = gst_audio_decoder_finish_frame (bdec, out_buf, 1);
done:
- if (to_free)
- g_free (to_free);
-
return ret;
/* ERRORS */
@@ -313,41 +272,15 @@ alloc_failed:
}
decode_error:
{
- GST_ELEMENT_ERROR (dec, STREAM, DECODE, (NULL),
- ("Error decoding frame: %d", decode_ret));
- ret = GST_FLOW_ERROR;
+ GST_AUDIO_DECODER_ERROR (bdec, 1, STREAM, DECODE, (NULL),
+ ("Error decoding frame: %d", decode_ret), ret);
+ if (ret == GST_FLOW_OK)
+ gst_audio_decoder_finish_frame (bdec, NULL, 1);
gst_buffer_unref (out_buf);
goto done;
}
}
-static GstStateChangeReturn
-gst_siren_change_state (GstElement * element, GstStateChange transition)
-{
- GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
- GstSirenDec *dec = GST_SIREN_DEC (element);
-
- switch (transition) {
- case GST_STATE_CHANGE_READY_TO_PAUSED:
- dec->discont = FALSE;
- break;
- default:
- break;
- }
-
- ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
-
- switch (transition) {
- case GST_STATE_CHANGE_PAUSED_TO_READY:
- gst_adapter_clear (dec->adapter);
- break;
- default:
- break;
- }
-
- return ret;
-}
-
gboolean
gst_siren_dec_plugin_init (GstPlugin * plugin)
{
diff --git a/gst/siren/gstsirendec.h b/gst/siren/gstsirendec.h
index 7c020896f..4c42c4de7 100644
--- a/gst/siren/gstsirendec.h
+++ b/gst/siren/gstsirendec.h
@@ -24,7 +24,7 @@
#define __GST_SIREN_DEC_H__
#include <gst/gst.h>
-#include <gst/base/gstadapter.h>
+#include <gst/audio/gstaudiodecoder.h>
#include "siren7.h"
@@ -48,21 +48,15 @@ typedef struct _GstSirenDecPrivate GstSirenDecPrivate;
struct _GstSirenDec
{
- GstElement parent;
+ GstAudioDecoder parent;
/* Protected by stream lock */
SirenDecoder decoder;
-
- GstAdapter *adapter;
- gboolean discont;
-
- GstPad *sinkpad;
- GstPad *srcpad;
};
struct _GstSirenDecClass
{
- GstElementClass parent_class;
+ GstAudioDecoderClass parent_class;
};
GType gst_siren_dec_get_type (void);
diff --git a/gst/siren/gstsirenenc.c b/gst/siren/gstsirenenc.c
index a78cdb8bc..6bcf20568 100644
--- a/gst/siren/gstsirenenc.c
+++ b/gst/siren/gstsirenenc.c
@@ -69,17 +69,12 @@ enum
ARG_0,
};
-
-
-static void gst_siren_enc_finalize (GObject * object);
-
-static gboolean gst_siren_enc_sink_setcaps (GstPad * pad, GstCaps * caps);
-static gboolean gst_siren_enc_sink_event (GstPad * pad, GstEvent * event);
-
-static GstFlowReturn gst_siren_enc_chain (GstPad * pad, GstBuffer * buf);
-static GstStateChangeReturn
-gst_siren_change_state (GstElement * element, GstStateChange transition);
-
+static gboolean gst_siren_enc_start (GstAudioEncoder * enc);
+static gboolean gst_siren_enc_stop (GstAudioEncoder * enc);
+static gboolean gst_siren_enc_set_format (GstAudioEncoder * enc,
+ GstAudioInfo * info);
+static GstFlowReturn gst_siren_enc_handle_frame (GstAudioEncoder * enc,
+ GstBuffer * in_buf);
static void
_do_init (GType type)
@@ -87,8 +82,8 @@ _do_init (GType type)
GST_DEBUG_CATEGORY_INIT (sirenenc_debug, "sirenenc", 0, "sirenenc");
}
-GST_BOILERPLATE_FULL (GstSirenEnc, gst_siren_enc, GstElement,
- GST_TYPE_ELEMENT, _do_init);
+GST_BOILERPLATE_FULL (GstSirenEnc, gst_siren_enc, GstAudioEncoder,
+ GST_TYPE_AUDIO_ENCODER, _do_init);
static void
gst_siren_enc_base_init (gpointer klass)
@@ -109,17 +104,14 @@ gst_siren_enc_base_init (gpointer klass)
static void
gst_siren_enc_class_init (GstSirenEncClass * klass)
{
- GObjectClass *gobject_class;
- GstElementClass *gstelement_class;
-
- gobject_class = (GObjectClass *) klass;
- gstelement_class = (GstElementClass *) klass;
+ GstAudioEncoderClass *base_class = GST_AUDIO_ENCODER_CLASS (klass);
GST_DEBUG ("Initializing Class");
- gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_siren_enc_finalize);
-
- gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_siren_change_state);
+ base_class->start = GST_DEBUG_FUNCPTR (gst_siren_enc_start);
+ base_class->stop = GST_DEBUG_FUNCPTR (gst_siren_enc_stop);
+ base_class->set_format = GST_DEBUG_FUNCPTR (gst_siren_enc_set_format);
+ base_class->handle_frame = GST_DEBUG_FUNCPTR (gst_siren_enc_handle_frame);
GST_DEBUG ("Class Init done");
}
@@ -127,120 +119,81 @@ gst_siren_enc_class_init (GstSirenEncClass * klass)
static void
gst_siren_enc_init (GstSirenEnc * enc, GstSirenEncClass * klass)
{
+}
- GST_DEBUG_OBJECT (enc, "Initializing");
- enc->encoder = Siren7_NewEncoder (16000);
- enc->adapter = gst_adapter_new ();
-
- enc->sinkpad = gst_pad_new_from_static_template (&sinktemplate, "sink");
- enc->srcpad = gst_pad_new_from_static_template (&srctemplate, "src");
+static gboolean
+gst_siren_enc_start (GstAudioEncoder * enc)
+{
+ GstSirenEnc *senc = GST_SIREN_ENC (enc);
- gst_pad_set_setcaps_function (enc->sinkpad,
- GST_DEBUG_FUNCPTR (gst_siren_enc_sink_setcaps));
- gst_pad_set_event_function (enc->sinkpad,
- GST_DEBUG_FUNCPTR (gst_siren_enc_sink_event));
- gst_pad_set_chain_function (enc->sinkpad,
- GST_DEBUG_FUNCPTR (gst_siren_enc_chain));
+ GST_DEBUG_OBJECT (enc, "start");
- gst_element_add_pad (GST_ELEMENT (enc), enc->sinkpad);
- gst_element_add_pad (GST_ELEMENT (enc), enc->srcpad);
+ senc->encoder = Siren7_NewEncoder (16000);
- GST_DEBUG_OBJECT (enc, "Init done");
+ return TRUE;
}
-static void
-gst_siren_enc_finalize (GObject * object)
+static gboolean
+gst_siren_enc_stop (GstAudioEncoder * enc)
{
- GstSirenEnc *enc = GST_SIREN_ENC (object);
+ GstSirenEnc *senc = GST_SIREN_ENC (enc);
- GST_DEBUG_OBJECT (object, "Disposing");
+ GST_DEBUG_OBJECT (senc, "stop");
- Siren7_CloseEncoder (enc->encoder);
- g_object_unref (enc->adapter);
+ Siren7_CloseEncoder (senc->encoder);
- G_OBJECT_CLASS (parent_class)->finalize (object);
+ return TRUE;
}
static gboolean
-gst_siren_enc_sink_setcaps (GstPad * pad, GstCaps * caps)
+gst_siren_enc_set_format (GstAudioEncoder * benc, GstAudioInfo * info)
{
GstSirenEnc *enc;
gboolean res;
GstCaps *outcaps;
- enc = GST_SIREN_ENC (GST_PAD_PARENT (pad));
+ enc = GST_SIREN_ENC (benc);
outcaps = gst_static_pad_template_get_caps (&srctemplate);
- res = gst_pad_set_caps (enc->srcpad, outcaps);
+ res = gst_pad_set_caps (GST_AUDIO_ENCODER_SRC_PAD (enc), outcaps);
gst_caps_unref (outcaps);
- return res;
-}
-
-static gboolean
-gst_siren_enc_sink_event (GstPad * pad, GstEvent * event)
-{
- GstSirenEnc *enc;
- gboolean res;
+ /* report needs to base class */
+ gst_audio_encoder_set_frame_samples_min (benc, 320);
+ gst_audio_encoder_set_frame_samples_max (benc, 320);
+ /* no remainder or flushing please */
+ gst_audio_encoder_set_hard_min (benc, TRUE);
+ gst_audio_encoder_set_drainable (benc, FALSE);
- enc = GST_SIREN_ENC (GST_PAD_PARENT (pad));
-
- switch (GST_EVENT_TYPE (event)) {
- case GST_EVENT_EOS:
- gst_adapter_clear (enc->adapter);
- res = gst_pad_push_event (enc->srcpad, event);
- break;
- case GST_EVENT_FLUSH_STOP:
- gst_adapter_clear (enc->adapter);
- res = gst_pad_push_event (enc->srcpad, event);
- break;
- default:
- res = gst_pad_push_event (enc->srcpad, event);
- break;
- }
return res;
}
static GstFlowReturn
-gst_siren_enc_chain (GstPad * pad, GstBuffer * buf)
+gst_siren_enc_handle_frame (GstAudioEncoder * benc, GstBuffer * buf)
{
GstSirenEnc *enc;
GstFlowReturn ret = GST_FLOW_OK;
GstBuffer *out_buf;
guint8 *in_data, *out_data;
- guint8 *to_free = NULL;
guint i, size, num_frames;
gint out_size, in_size;
gint encode_ret;
- gboolean discont;
- GstClockTime timestamp;
- guint64 distance;
- GstCaps *outcaps;
- enc = GST_SIREN_ENC (GST_PAD_PARENT (pad));
+ g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
- discont = GST_BUFFER_IS_DISCONT (buf);
- if (discont) {
- GST_DEBUG_OBJECT (enc, "received DISCONT, flush adapter");
- gst_adapter_clear (enc->adapter);
- enc->discont = TRUE;
- }
+ enc = GST_SIREN_ENC (benc);
- gst_adapter_push (enc->adapter, buf);
+ size = GST_BUFFER_SIZE (buf);
- size = gst_adapter_available (enc->adapter);
+ GST_LOG_OBJECT (enc, "Received buffer of size %d", GST_BUFFER_SIZE (buf));
- GST_LOG_OBJECT (enc, "Received buffer of size %d with adapter of size : %d",
- GST_BUFFER_SIZE (buf), size);
+ g_return_val_if_fail (size > 0, GST_FLOW_ERROR);
+ g_return_val_if_fail (size % 640 == 0, GST_FLOW_ERROR);
/* we need to process 640 input bytes to produce 40 output bytes */
/* calculate the amount of frames we will handle */
num_frames = size / 640;
- /* no frames, wait some more */
- if (num_frames == 0)
- goto done;
-
/* this is the input/output size */
in_size = num_frames * 640;
out_size = num_frames * 40;
@@ -248,32 +201,14 @@ gst_siren_enc_chain (GstPad * pad, GstBuffer * buf)
GST_LOG_OBJECT (enc, "we have %u frames, %u in, %u out", num_frames, in_size,
out_size);
- /* set output caps when needed */
- if ((outcaps = GST_PAD_CAPS (enc->srcpad)) == NULL) {
- outcaps = gst_static_pad_template_get_caps (&srctemplate);
- gst_pad_set_caps (enc->srcpad, outcaps);
- gst_caps_unref (outcaps);
- }
-
/* get a buffer */
- ret = gst_pad_alloc_buffer_and_set_caps (enc->srcpad, -1,
- out_size, outcaps, &out_buf);
+ ret = gst_pad_alloc_buffer_and_set_caps (GST_AUDIO_ENCODER_SRC_PAD (benc),
+ -1, out_size, GST_PAD_CAPS (GST_AUDIO_ENCODER_SRC_PAD (benc)), &out_buf);
if (ret != GST_FLOW_OK)
goto alloc_failed;
- /* get the timestamp for the output buffer */
- timestamp = gst_adapter_prev_timestamp (enc->adapter, &distance);
-
- /* add the amount of time taken by the distance */
- if (timestamp != -1)
- timestamp += gst_util_uint64_scale_int (distance / 2, GST_SECOND, 16000);
-
- GST_LOG_OBJECT (enc,
- "timestamp %" GST_TIME_FORMAT ", distance %" G_GUINT64_FORMAT,
- GST_TIME_ARGS (timestamp), distance);
-
/* get the input data for all the frames */
- to_free = in_data = gst_adapter_take (enc->adapter, in_size);
+ in_data = GST_BUFFER_DATA (buf);
out_data = GST_BUFFER_DATA (out_buf);
for (i = 0; i < num_frames; i++) {
@@ -291,20 +226,10 @@ gst_siren_enc_chain (GstPad * pad, GstBuffer * buf)
GST_LOG_OBJECT (enc, "Finished encoding");
- /* mark discont */
- if (enc->discont) {
- GST_BUFFER_FLAG_SET (out_buf, GST_BUFFER_FLAG_DISCONT);
- enc->discont = FALSE;
- }
- GST_BUFFER_TIMESTAMP (out_buf) = timestamp;
- GST_BUFFER_DURATION (out_buf) = num_frames * FRAME_DURATION;
-
- ret = gst_pad_push (enc->srcpad, out_buf);
+ /* we encode all we get, pass it along */
+ ret = gst_audio_encoder_finish_frame (benc, out_buf, -1);
done:
- if (to_free)
- g_free (to_free);
-
return ret;
/* ERRORS */
@@ -324,33 +249,6 @@ encode_error:
}
}
-static GstStateChangeReturn
-gst_siren_change_state (GstElement * element, GstStateChange transition)
-{
- GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
- GstSirenEnc *enc = GST_SIREN_ENC (element);
-
- switch (transition) {
- case GST_STATE_CHANGE_READY_TO_PAUSED:
- enc->discont = FALSE;
- break;
- default:
- break;
- }
-
- ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
-
- switch (transition) {
- case GST_STATE_CHANGE_PAUSED_TO_READY:
- gst_adapter_clear (enc->adapter);
- break;
- default:
- break;
- }
-
- return ret;
-}
-
gboolean
gst_siren_enc_plugin_init (GstPlugin * plugin)
{
diff --git a/gst/siren/gstsirenenc.h b/gst/siren/gstsirenenc.h
index 1d63628dc..3477db1a7 100644
--- a/gst/siren/gstsirenenc.h
+++ b/gst/siren/gstsirenenc.h
@@ -24,7 +24,7 @@
#define __GST_SIREN_ENC_H__
#include <gst/gst.h>
-#include <gst/base/gstadapter.h>
+#include <gst/audio/gstaudioencoder.h>
#include "siren7.h"
@@ -48,21 +48,15 @@ typedef struct _GstSirenEncPrivate GstSirenEncPrivate;
struct _GstSirenEnc
{
- GstElement parent;
+ GstAudioEncoder parent;
/* protected by the stream lock */
SirenEncoder encoder;
- GstAdapter *adapter;
-
- gboolean discont;
-
- GstPad *srcpad;
- GstPad *sinkpad;
};
struct _GstSirenEncClass
{
- GstElementClass parent_class;
+ GstAudioEncoderClass parent_class;
};
GType gst_siren_enc_get_type (void);