diff options
author | Olivier CrĂȘte <olivier.crete@collabora.co.uk> | 2009-10-12 19:50:52 -0400 |
---|---|---|
committer | Olivier CrĂȘte <olivier.crete@collabora.co.uk> | 2010-06-02 21:03:53 -0400 |
commit | fe7fe29221abc1e1310c9f3f37cdf11c0bc7bad1 (patch) | |
tree | 95fc9598d44bba49f8c81313cf6e6caccd5ade8e /ext/mimic | |
parent | 2eee0091f322d4b691bbd8682a959fdc77415c12 (diff) | |
download | gstreamer-plugins-bad-fe7fe29221abc1e1310c9f3f37cdf11c0bc7bad1.tar.gz |
mimic: Initialize encoder/decoders in state change and setcaps where possible
Diffstat (limited to 'ext/mimic')
-rw-r--r-- | ext/mimic/gstmimdec.c | 50 | ||||
-rw-r--r-- | ext/mimic/gstmimenc.c | 94 |
2 files changed, 72 insertions, 72 deletions
diff --git a/ext/mimic/gstmimdec.c b/ext/mimic/gstmimdec.c index fbb865736..8ce81f4f0 100644 --- a/ext/mimic/gstmimdec.c +++ b/ext/mimic/gstmimdec.c @@ -216,7 +216,7 @@ gst_mim_dec_chain (GstPad * pad, GstBuffer * in) frame_body = (guchar *) gst_adapter_peek (mimdec->adapter, mimdec->payload_size); - if (mimdec->dec == NULL) { + if (mimdec->buffer_size < 0) { /* Check if its a keyframe, otherwise skip it */ if (GUINT32_FROM_LE (*((guint32 *) (frame_body + 12))) != 0) { gst_adapter_flush (mimdec->adapter, mimdec->payload_size); @@ -225,20 +225,7 @@ gst_mim_dec_chain (GstPad * pad, GstBuffer * in) goto out; } - mimdec->dec = mimic_open (); - if (mimdec->dec == NULL) { - - gst_adapter_flush (mimdec->adapter, mimdec->payload_size); - mimdec->have_header = FALSE; - GST_ELEMENT_ERROR (mimdec, LIBRARY, INIT, (NULL), ("mimic_open error")); - res = GST_FLOW_ERROR; - goto out; - } - if (!mimic_decoder_init (mimdec->dec, frame_body)) { - mimic_close (mimdec->dec); - mimdec->dec = NULL; - gst_adapter_flush (mimdec->adapter, mimdec->payload_size); mimdec->have_header = FALSE; GST_ELEMENT_ERROR (mimdec, LIBRARY, INIT, (NULL), @@ -249,9 +236,6 @@ gst_mim_dec_chain (GstPad * pad, GstBuffer * in) if (!mimic_get_property (mimdec->dec, "buffer_size", &mimdec->buffer_size)) { - mimic_close (mimdec->dec); - mimdec->dec = NULL; - gst_adapter_flush (mimdec->adapter, mimdec->payload_size); mimdec->have_header = FALSE; GST_ELEMENT_ERROR (mimdec, LIBRARY, INIT, (NULL), @@ -340,10 +324,35 @@ static GstStateChangeReturn gst_mim_dec_change_state (GstElement * element, GstStateChange transition) { GstMimDec *mimdec; + GstStateChangeReturn ret; mimdec = GST_MIM_DEC (element); switch (transition) { + case GST_STATE_CHANGE_NULL_TO_READY: + mimdec->dec = mimic_open (); + if (!mimdec) { + GST_ERROR_OBJECT (mimdec, "mimic_open failed"); + return GST_STATE_CHANGE_FAILURE; + } + break; + + case GST_STATE_CHANGE_READY_TO_PAUSED: + GST_OBJECT_LOCK (element); + mimdec->need_newsegment = TRUE; + GST_OBJECT_UNLOCK (element); + break; + default: + break; + } + + ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); + + if (ret == GST_STATE_CHANGE_FAILURE) + return ret; + + + switch (transition) { case GST_STATE_CHANGE_READY_TO_NULL: GST_OBJECT_LOCK (element); if (mimdec->dec != NULL) { @@ -356,16 +365,11 @@ gst_mim_dec_change_state (GstElement * element, GstStateChange transition) } GST_OBJECT_UNLOCK (element); break; - case GST_STATE_CHANGE_READY_TO_PAUSED: - GST_OBJECT_LOCK (element); - mimdec->need_newsegment = TRUE; - GST_OBJECT_UNLOCK (element); - break; default: break; } - return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); + return ret; } static gboolean diff --git a/ext/mimic/gstmimenc.c b/ext/mimic/gstmimenc.c index 5168afbf9..af63ae82a 100644 --- a/ext/mimic/gstmimenc.c +++ b/ext/mimic/gstmimenc.c @@ -209,48 +209,60 @@ gst_mim_enc_get_property (GObject * object, guint prop_id, static gboolean gst_mim_enc_setcaps (GstPad * pad, GstCaps * caps) { - GstMimEnc *filter; + GstMimEnc *mimenc; GstStructure *structure; int ret = TRUE, height, width; - filter = GST_MIM_ENC (gst_pad_get_parent (pad)); - g_return_val_if_fail (filter != NULL, FALSE); - g_return_val_if_fail (GST_IS_MIM_ENC (filter), FALSE); + mimenc = GST_MIM_ENC (gst_pad_get_parent (pad)); + g_return_val_if_fail (mimenc != NULL, FALSE); + g_return_val_if_fail (GST_IS_MIM_ENC (mimenc), FALSE); structure = gst_caps_get_structure (caps, 0); ret = gst_structure_get_int (structure, "width", &width); if (!ret) { - GST_DEBUG_OBJECT (filter, "No width set"); + GST_DEBUG_OBJECT (mimenc, "No width set"); goto out; } ret = gst_structure_get_int (structure, "height", &height); if (!ret) { - GST_DEBUG_OBJECT (filter, "No height set"); + GST_DEBUG_OBJECT (mimenc, "No height set"); goto out; } - GST_OBJECT_LOCK (filter); + GST_OBJECT_LOCK (mimenc); if (width == 320 && height == 240) - filter->res = MIMIC_RES_HIGH; + mimenc->res = MIMIC_RES_HIGH; else if (width == 160 && height == 120) - filter->res = MIMIC_RES_LOW; + mimenc->res = MIMIC_RES_LOW; else { - GST_WARNING_OBJECT (filter, "Invalid resolution %dx%d", width, height); + GST_WARNING_OBJECT (mimenc, "Invalid resolution %dx%d", width, height); ret = FALSE; - GST_OBJECT_UNLOCK (filter); + GST_OBJECT_UNLOCK (mimenc); goto out; } - filter->width = (guint16) width; - filter->height = (guint16) height; + mimenc->width = (guint16) width; + mimenc->height = (guint16) height; + + GST_DEBUG_OBJECT (mimenc, "Got info from caps w : %d, h : %d", + mimenc->width, mimenc->height); - GST_DEBUG_OBJECT (filter, "Got info from caps w : %d, h : %d", - filter->width, filter->height); + if (!mimic_encoder_init (mimenc->enc, mimenc->res)) { + GST_ERROR_OBJECT (mimenc, "mimic_encoder_init error"); + ret = FALSE; + GST_OBJECT_UNLOCK (mimenc); + goto out; + } - GST_OBJECT_UNLOCK (filter); + if (!mimic_get_property (mimenc->enc, "buffer_size", &mimenc->buffer_size)) { + GST_ERROR_OBJECT (mimenc, "mimic_get_property(buffer_size) error"); + ret = FALSE; + } + + GST_OBJECT_UNLOCK (mimenc); out: - gst_object_unref (filter); + gst_object_unref (mimenc); return ret; } @@ -281,30 +293,6 @@ gst_mim_enc_chain (GstPad * pad, GstBuffer * in) } if (mimenc->enc == NULL) { - mimenc->enc = mimic_open (); - if (mimenc->enc == NULL) { - GST_ELEMENT_ERROR (mimenc, LIBRARY, INIT, (NULL), ("mimic_open error")); - res = GST_FLOW_ERROR; - goto out_unlock; - } - - if (!mimic_encoder_init (mimenc->enc, mimenc->res)) { - mimic_close (mimenc->enc); - mimenc->enc = NULL; - GST_ELEMENT_ERROR (mimenc, LIBRARY, INIT, (NULL), - ("mimic_encoder_init error")); - res = GST_FLOW_ERROR; - goto out_unlock; - } - - if (!mimic_get_property (mimenc->enc, "buffer_size", &mimenc->buffer_size)) { - mimic_close (mimenc->enc); - mimenc->enc = NULL; - GST_ELEMENT_ERROR (mimenc, LIBRARY, INIT, (NULL), - ("mimic_get_property(buffer_size) error")); - res = GST_FLOW_ERROR; - goto out_unlock; - } } buf = in; @@ -546,15 +534,12 @@ gst_mim_enc_change_state (GstElement * element, GstStateChange transition) gboolean paused_mode; switch (transition) { - case GST_STATE_CHANGE_READY_TO_NULL: - GST_OBJECT_LOCK (element); - if (mimenc->enc != NULL) { - mimic_close (mimenc->enc); - mimenc->enc = NULL; - mimenc->buffer_size = -1; - mimenc->frames = 0; + case GST_STATE_CHANGE_NULL_TO_READY: + mimenc->enc = mimic_open (); + if (!mimenc) { + GST_ERROR_OBJECT (mimenc, "mimic_open failed"); + return GST_STATE_CHANGE_FAILURE; } - GST_OBJECT_UNLOCK (element); break; case GST_STATE_CHANGE_READY_TO_PAUSED: @@ -608,6 +593,17 @@ gst_mim_enc_change_state (GstElement * element, GstStateChange transition) } } break; + case GST_STATE_CHANGE_READY_TO_NULL: + GST_OBJECT_LOCK (element); + if (mimenc->enc != NULL) { + mimic_close (mimenc->enc); + mimenc->enc = NULL; + mimenc->buffer_size = -1; + mimenc->frames = 0; + } + GST_OBJECT_UNLOCK (element); + break; + default: break; } |