summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@collabora.co.uk>2009-09-03 19:04:33 +0200
committerWim Taymans <wim.taymans@collabora.co.uk>2009-09-03 19:04:33 +0200
commit00f395e82f2732ba33f7e396da7b8f77ec4c7dca (patch)
treea4532aa00392e73cbfc44deb6bc9887e015b3c5b
parent823f06f039a11920a9c0337821b7528eaab4b33b (diff)
sirenenc: fix events and caps
Add an event function that clears the adapter. Add a setcaps function to configure caps on the srcpad. Remove the instance variable for the caps.
-rw-r--r--gst/siren/gstsirenenc.c73
-rw-r--r--gst/siren/gstsirenenc.h2
2 files changed, 53 insertions, 22 deletions
diff --git a/gst/siren/gstsirenenc.c b/gst/siren/gstsirenenc.c
index e21da4fc4..b0dfbc64d 100644
--- a/gst/siren/gstsirenenc.c
+++ b/gst/siren/gstsirenenc.c
@@ -79,7 +79,10 @@ enum
-static void gst_siren_enc_dispose (GObject * object);
+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
@@ -119,7 +122,7 @@ gst_siren_enc_class_init (GstSirenEncClass * klass)
GST_DEBUG ("Initializing Class");
- gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_siren_enc_dispose);
+ gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_siren_enc_finalize);
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_siren_change_state);
@@ -137,40 +140,70 @@ gst_siren_enc_init (GstSirenEnc * enc, GstSirenEncClass * klass)
enc->sinkpad = gst_pad_new_from_static_template (&sinktemplate, "sink");
enc->srcpad = gst_pad_new_from_static_template (&srctemplate, "src");
+ 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_element_add_pad (GST_ELEMENT (enc), enc->sinkpad);
gst_element_add_pad (GST_ELEMENT (enc), enc->srcpad);
- enc->srccaps = gst_static_pad_template_get_caps (&srctemplate);
-
GST_DEBUG_OBJECT (enc, "Init done");
}
static void
-gst_siren_enc_dispose (GObject * object)
+gst_siren_enc_finalize (GObject * object)
{
GstSirenEnc *enc = GST_SIREN_ENC (object);
GST_DEBUG_OBJECT (object, "Disposing");
- if (enc->encoder) {
- Siren7_CloseEncoder (enc->encoder);
- enc->encoder = NULL;
- }
+ Siren7_CloseEncoder (enc->encoder);
+ g_object_unref (enc->adapter);
- if (enc->adapter) {
- g_object_unref (enc->adapter);
- enc->adapter = NULL;
- }
+ G_OBJECT_CLASS (parent_class)->dispose (object);
+}
- if (enc->srccaps) {
- gst_caps_unref (enc->srccaps);
- enc->srccaps = NULL;
- }
+static gboolean
+gst_siren_enc_sink_setcaps (GstPad * pad, GstCaps * caps)
+{
+ GstSirenEnc *enc;
+ gboolean res;
+ GstCaps *outcaps;
- G_OBJECT_CLASS (parent_class)->dispose (object);
+ enc = GST_SIREN_ENC (GST_PAD_PARENT (pad));
+
+ outcaps = gst_static_pad_template_get_caps (&srctemplate);
+ res = gst_pad_set_caps (enc->srcpad, outcaps);
+ gst_caps_unref (outcaps);
+
+ return res;
+}
+
+static gboolean
+gst_siren_enc_sink_event (GstPad * pad, GstEvent * event)
+{
+ GstSirenEnc *enc;
+ gboolean res;
+
+ 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
@@ -210,7 +243,7 @@ gst_siren_enc_chain (GstPad * pad, GstBuffer * buf)
if (num_frames == 0)
goto done;
- /* this is the output size */
+ /* this is the input/output size */
in_size = num_frames * 640;
out_size = num_frames * 40;
@@ -219,7 +252,7 @@ gst_siren_enc_chain (GstPad * pad, GstBuffer * buf)
/* get a buffer */
ret = gst_pad_alloc_buffer_and_set_caps (enc->srcpad, -1,
- out_size, enc->srccaps, &out_buf);
+ out_size, GST_PAD_CAPS (enc->srcpad), &out_buf);
if (ret != GST_FLOW_OK)
goto alloc_failed;
diff --git a/gst/siren/gstsirenenc.h b/gst/siren/gstsirenenc.h
index 66709be89..1d63628dc 100644
--- a/gst/siren/gstsirenenc.h
+++ b/gst/siren/gstsirenenc.h
@@ -58,8 +58,6 @@ struct _GstSirenEnc
GstPad *srcpad;
GstPad *sinkpad;
-
- GstCaps *srccaps;
};
struct _GstSirenEncClass