From 3fa60712f2f86591d7ab7b0c454e1676ad72b751 Mon Sep 17 00:00:00 2001 From: Carl-Anton Ingmarsson Date: Sun, 7 Jun 2009 00:55:55 +0200 Subject: vdpaumpegdec: use gst_pad_get_parent for threadsafety --- sys/vdpau/gstvdpmpegdec.c | 64 ++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 23 deletions(-) (limited to 'sys/vdpau/gstvdpmpegdec.c') diff --git a/sys/vdpau/gstvdpmpegdec.c b/sys/vdpau/gstvdpmpegdec.c index c5d6fde5..bcff055f 100644 --- a/sys/vdpau/gstvdpmpegdec.c +++ b/sys/vdpau/gstvdpmpegdec.c @@ -161,7 +161,7 @@ gst_vdp_mpeg_packetizer_init (GstVdpMpegPacketizer * packetizer, static gboolean gst_vdp_mpeg_dec_set_caps (GstPad * pad, GstCaps * caps) { - GstVdpMpegDec *mpeg_dec = GST_VDP_MPEG_DEC (GST_OBJECT_PARENT (pad)); + GstVdpMpegDec *mpeg_dec = GST_VDP_MPEG_DEC (gst_pad_get_parent (pad)); GstStructure *structure; gint width, height; @@ -198,7 +198,7 @@ gst_vdp_mpeg_dec_set_caps (GstPad * pad, GstCaps * caps) res = gst_pad_set_caps (mpeg_dec->src, src_caps); gst_caps_unref (src_caps); if (!res) - return FALSE; + goto done; mpeg_dec->width = width; mpeg_dec->height = height; @@ -274,9 +274,15 @@ gst_vdp_mpeg_dec_set_caps (GstPad * pad, GstCaps * caps) ("Could not create vdpau decoder"), ("Error returned from vdpau was: %s", device->vdp_get_error_string (status))); - return FALSE; + res = FALSE; + goto done; } - return TRUE; + res = TRUE; + +done: + gst_object_unref (mpeg_dec); + + return res; } GstFlowReturn @@ -605,13 +611,11 @@ gst_vdp_mpeg_dec_reset (GstVdpMpegDec * mpeg_dec) static GstFlowReturn gst_vdp_mpeg_dec_chain (GstPad * pad, GstBuffer * buffer) { - GstVdpMpegDec *mpeg_dec; + GstVdpMpegDec *mpeg_dec = GST_VDP_MPEG_DEC (gst_pad_get_parent (pad)); GstVdpMpegPacketizer packetizer; GstBuffer *buf; GstFlowReturn ret = GST_FLOW_OK; - mpeg_dec = GST_VDP_MPEG_DEC (GST_OBJECT_PARENT (pad)); - if (G_UNLIKELY (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT))) { GST_DEBUG_OBJECT (mpeg_dec, "Received discont buffer"); gst_vdp_mpeg_dec_flush (mpeg_dec); @@ -643,9 +647,9 @@ gst_vdp_mpeg_dec_chain (GstPad * pad, GstBuffer * buffer) case MPEG_PACKET_PICTURE: GST_DEBUG_OBJECT (mpeg_dec, "MPEG_PACKET_PICTURE"); - if (!gst_vdp_mpeg_dec_parse_picture (mpeg_dec, buf)) { - return GST_FLOW_OK; - } + if (!gst_vdp_mpeg_dec_parse_picture (mpeg_dec, buf)) + goto done; + break; case MPEG_PACKET_SEQUENCE: GST_DEBUG_OBJECT (mpeg_dec, "MPEG_PACKET_SEQUENCE"); @@ -688,6 +692,9 @@ gst_vdp_mpeg_dec_chain (GstPad * pad, GstBuffer * buffer) ret = gst_vdp_mpeg_dec_decode (mpeg_dec, GST_BUFFER_TIMESTAMP (buffer), GST_BUFFER_SIZE (buffer)); +done: + gst_object_unref (mpeg_dec); + return ret; } @@ -735,16 +742,16 @@ gst_mpeg_dec_get_querytypes (GstPad * pad) static gboolean gst_vdp_mpeg_dec_src_query (GstPad * pad, GstQuery * query) { - GstVdpMpegDec *mpeg_dec = GST_VDP_MPEG_DEC (GST_OBJECT_PARENT (pad)); - gboolean res = FALSE; + GstVdpMpegDec *mpeg_dec = GST_VDP_MPEG_DEC (gst_pad_get_parent (pad)); + gboolean res; switch (GST_QUERY_TYPE (query)) { case GST_QUERY_POSITION: { GstFormat format; - if (gst_pad_query_default (pad, query)) - return TRUE; + if ((res = gst_pad_query_default (pad, query))) + goto done; gst_query_parse_position (query, &format, NULL); if (format == GST_FORMAT_TIME && @@ -760,8 +767,8 @@ gst_vdp_mpeg_dec_src_query (GstPad * pad, GstQuery * query) { GstFormat format; - if (gst_pad_query_default (pad, query)) - return TRUE; + if ((res = gst_pad_query_default (pad, query))) + goto done; gst_query_parse_duration (query, &format, NULL); if (format == GST_FORMAT_TIME) { @@ -787,13 +794,15 @@ gst_vdp_mpeg_dec_src_query (GstPad * pad, GstQuery * query) res = gst_pad_query_default (pad, query); } +done: + gst_object_unref (mpeg_dec); + return res; } static gboolean -normal_seek (GstPad * pad, GstEvent * event) +normal_seek (GstVdpMpegDec * mpeg_dec, GstEvent * event) { - GstVdpMpegDec *mpeg_dec = GST_VDP_MPEG_DEC (GST_OBJECT_PARENT (pad)); gdouble rate; GstFormat format, conv; GstSeekFlags flags; @@ -853,28 +862,33 @@ convert_failed: static gboolean gst_vdp_mpeg_dec_src_event (GstPad * pad, GstEvent * event) { + GstVdpMpegDec *mpeg_dec = GST_VDP_MPEG_DEC (gst_pad_get_parent (pad)); gboolean res; switch (GST_EVENT_TYPE (event)) { case GST_EVENT_SEEK: { - if (gst_pad_event_default (pad, event)) - return TRUE; + if ((res = gst_pad_event_default (pad, event))) + goto done; + + res = normal_seek (mpeg_dec, event); - res = normal_seek (pad, event); break; } default: res = gst_pad_event_default (pad, event); } +done: + gst_object_unref (mpeg_dec); + return res; } static gboolean gst_vdp_mpeg_dec_sink_event (GstPad * pad, GstEvent * event) { - GstVdpMpegDec *mpeg_dec = GST_VDP_MPEG_DEC (GST_OBJECT_PARENT (pad)); + GstVdpMpegDec *mpeg_dec = GST_VDP_MPEG_DEC (gst_pad_get_parent (pad)); gboolean res; switch (GST_EVENT_TYPE (event)) { @@ -919,7 +933,8 @@ gst_vdp_mpeg_dec_sink_event (GstPad * pad, GstEvent * event) * use the calculated timestamp of the first frame for this */ if (mpeg_dec->seeking) { gst_event_unref (event); - return TRUE; + res = TRUE; + goto done; } convert_error: @@ -931,6 +946,9 @@ gst_vdp_mpeg_dec_sink_event (GstPad * pad, GstEvent * event) res = gst_pad_event_default (pad, event); } +done: + gst_object_unref (mpeg_dec); + return res; } -- cgit v1.2.1