From 56ff7ee1ae31ca1647ce44c6c3364e257b747e6f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim-Philipp=20M=C3=BCller?= Date: Wed, 26 Sep 2007 13:19:17 +0000 Subject: [PATCH] ext/flac/gstflacenc.*: Save the flow return from the last gst_pad_push() and make sure we pass the right flow return ... Original commit message from CVS: * ext/flac/gstflacenc.c: * ext/flac/gstflacenc.h: Save the flow return from the last gst_pad_push() and make sure we pass the right flow return value upstream in the case of failure; minor clean-ups. --- ChangeLog | 8 ++++++++ ext/flac/gstflacenc.c | 40 ++++++++++++++++++++++++---------------- ext/flac/gstflacenc.h | 4 ++++ 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index e4d7210bd6..647b853dce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2007-09-26 Tim-Philipp Müller + + * ext/flac/gstflacenc.c: + * ext/flac/gstflacenc.h: + Save the flow return from the last gst_pad_push() and + make sure we pass the right flow return value upstream + in the case of failure; minor clean-ups. + 2007-09-25 Tim-Philipp Müller * ext/taglib/gstapev2mux.cc: diff --git a/ext/flac/gstflacenc.c b/ext/flac/gstflacenc.c index 7a8f0cffe8..f778fac159 100644 --- a/ext/flac/gstflacenc.c +++ b/ext/flac/gstflacenc.c @@ -307,19 +307,16 @@ gst_flac_enc_class_init (GstFlacEncClass * klass) static void gst_flac_enc_init (GstFlacEnc * flacenc, GstFlacEncClass * klass) { - GstElementClass *eclass = GST_ELEMENT_CLASS (klass); - - flacenc->sinkpad = - gst_pad_new_from_template (gst_element_class_get_pad_template (eclass, - "sink"), "sink"); + flacenc->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink"); + gst_pad_set_chain_function (flacenc->sinkpad, + GST_DEBUG_FUNCPTR (gst_flac_enc_chain)); + gst_pad_set_event_function (flacenc->sinkpad, + GST_DEBUG_FUNCPTR (gst_flac_enc_sink_event)); + gst_pad_set_setcaps_function (flacenc->sinkpad, + GST_DEBUG_FUNCPTR (gst_flac_enc_sink_setcaps)); gst_element_add_pad (GST_ELEMENT (flacenc), flacenc->sinkpad); - gst_pad_set_chain_function (flacenc->sinkpad, gst_flac_enc_chain); - gst_pad_set_event_function (flacenc->sinkpad, gst_flac_enc_sink_event); - gst_pad_set_setcaps_function (flacenc->sinkpad, gst_flac_enc_sink_setcaps); - flacenc->srcpad = - gst_pad_new_from_template (gst_element_class_get_pad_template (eclass, - "src"), "src"); + flacenc->srcpad = gst_pad_new_from_static_template (&src_factory, "src"); gst_pad_use_fixed_caps (flacenc->srcpad); gst_element_add_pad (GST_ELEMENT (flacenc), flacenc->srcpad); @@ -335,6 +332,7 @@ gst_flac_enc_init (GstFlacEnc * flacenc, GstFlacEncClass * klass) flacenc->tags = gst_tag_list_new (); flacenc->got_headers = FALSE; flacenc->headers = NULL; + flacenc->last_flow = GST_FLOW_OK; } static void @@ -809,12 +807,17 @@ gst_flac_enc_write_callback (const FLAC__StreamEncoder * encoder, gst_buffer_set_caps (outbuf, GST_PAD_CAPS (flacenc->srcpad)); ret = gst_pad_push (flacenc->srcpad, outbuf); + if (ret != GST_FLOW_OK) + GST_DEBUG_OBJECT (flacenc, "flow: %s", gst_flow_get_name (ret)); + + flacenc->last_flow = ret; + out: flacenc->offset += bytes; flacenc->samples_written += samples; - if (GST_FLOW_IS_FATAL (ret)) + if (GST_FLOW_IS_FATAL (ret) || ret == GST_FLOW_NOT_LINKED) return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; return FLAC__STREAM_ENCODER_WRITE_STATUS_OK; @@ -957,10 +960,14 @@ gst_flac_enc_chain (GstPad * pad, GstBuffer * buffer) g_free (data); - if (res) - return GST_FLOW_OK; - else - return GST_FLOW_ERROR; + if (!res) { + if (flacenc->last_flow == GST_FLOW_OK) + return GST_FLOW_ERROR; + else + return flacenc->last_flow; + } + + return GST_FLOW_OK; } static void @@ -1277,6 +1284,7 @@ gst_flac_enc_change_state (GstElement * element, GstStateChange transition) g_list_free (flacenc->headers); flacenc->headers = NULL; flacenc->got_headers = FALSE; + flacenc->last_flow = GST_FLOW_OK; break; case GST_STATE_CHANGE_READY_TO_NULL: default: diff --git a/ext/flac/gstflacenc.h b/ext/flac/gstflacenc.h index ca1933a2a0..a7bbd46abf 100644 --- a/ext/flac/gstflacenc.h +++ b/ext/flac/gstflacenc.h @@ -48,6 +48,10 @@ struct _GstFlacEnc { GstPad *sinkpad; GstPad *srcpad; + GstFlowReturn last_flow; /* save flow from last push so we can pass the + * correct flow return upstream in case the push + * fails for some reason */ + gboolean first; GstBuffer *first_buf; guint64 offset; -- 2.34.1