From 323ba80ff3295b0a46e136648ffaaac6131dea8c Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 27 Oct 2005 11:33:09 +0000 Subject: [PATCH] ext/: Take proper locks when handling events. Original commit message from CVS: * ext/theora/theoradec.c: (theora_dec_src_query), (theora_dec_sink_event): * ext/theora/theoraenc.c: (theora_enc_sink_event), (theora_enc_change_state): * ext/vorbis/vorbisenc.c: (gst_vorbisenc_init), (gst_vorbisenc_sink_event), (gst_vorbisenc_change_state): Take proper locks when handling events. --- ChangeLog | 10 ++++++++++ ext/theora/theoraenc.c | 11 ++++++++--- ext/vorbis/vorbisenc.c | 20 ++++++++++++++------ 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9b4413709e..558caee3c9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2005-10-27 Wim Taymans + + * ext/theora/theoradec.c: (theora_dec_src_query), + (theora_dec_sink_event): + * ext/theora/theoraenc.c: (theora_enc_sink_event), + (theora_enc_change_state): + * ext/vorbis/vorbisenc.c: (gst_vorbisenc_init), + (gst_vorbisenc_sink_event), (gst_vorbisenc_change_state): + Take proper locks when handling events. + 2005-10-27 Wim Taymans * gst/adder/gstadder.c: (gst_adder_query), (gst_adder_collected), diff --git a/ext/theora/theoraenc.c b/ext/theora/theoraenc.c index e511faecd2..cbf20d1174 100644 --- a/ext/theora/theoraenc.c +++ b/ext/theora/theoraenc.c @@ -419,20 +419,27 @@ theora_enc_sink_event (GstPad * pad, GstEvent * event) { GstTheoraEnc *enc; ogg_packet op; + gboolean res; enc = GST_THEORA_ENC (GST_PAD_PARENT (pad)); switch (GST_EVENT_TYPE (event)) { case GST_EVENT_EOS: + GST_STREAM_LOCK (pad); /* push last packet with eos flag */ while (theora_encode_packetout (&enc->state, 1, &op)) { GstClockTime out_time = theora_granule_time (&enc->state, op.granulepos) * GST_SECOND; + theora_push_packet (enc, &op, out_time, GST_SECOND / enc->fps); } + res = gst_pad_push_event (enc->srcpad, event); + GST_STREAM_UNLOCK (pad); + break; default: - return gst_pad_event_default (pad, event); + res = gst_pad_push_event (enc->srcpad, event); } + return res; } static GstFlowReturn @@ -721,11 +728,9 @@ theora_enc_change_state (GstElement * element, GstStateChange transition) case GST_STATE_CHANGE_PLAYING_TO_PAUSED: break; case GST_STATE_CHANGE_PAUSED_TO_READY: - GST_STREAM_LOCK (enc->sinkpad); theora_clear (&enc->state); theora_comment_clear (&enc->comment); theora_info_clear (&enc->info); - GST_STREAM_UNLOCK (enc->sinkpad); break; case GST_STATE_CHANGE_READY_TO_NULL: break; diff --git a/ext/vorbis/vorbisenc.c b/ext/vorbis/vorbisenc.c index 3e6b4b61d8..618c53f54c 100644 --- a/ext/vorbis/vorbisenc.c +++ b/ext/vorbis/vorbisenc.c @@ -550,8 +550,6 @@ gst_vorbisenc_init (GstVorbisEnc * vorbisenc) vorbisenc->quality_set = FALSE; vorbisenc->last_message = NULL; - vorbisenc->setup = FALSE; - vorbisenc->header_sent = FALSE; } @@ -883,14 +881,17 @@ gst_vorbisenc_sink_event (GstPad * pad, GstEvent * event) switch (GST_EVENT_TYPE (event)) { case GST_EVENT_EOS: + GST_STREAM_LOCK (pad); /* Tell the library we're at end of stream so that it can handle * the last frame and mark end of stream in the output properly */ GST_DEBUG_OBJECT (vorbisenc, "EOS, clearing state and sending event on"); gst_vorbisenc_clear (vorbisenc); - res = gst_pad_event_default (pad, event); + res = gst_pad_push_event (vorbisenc->srcpad, event); + GST_STREAM_UNLOCK (pad); break; case GST_EVENT_TAG: + GST_STREAM_LOCK (pad); if (vorbisenc->tags) { GstTagList *list; @@ -900,10 +901,11 @@ gst_vorbisenc_sink_event (GstPad * pad, GstEvent * event) } else { g_assert_not_reached (); } - res = gst_pad_event_default (pad, event); + res = gst_pad_push_event (vorbisenc->srcpad, event); + GST_STREAM_UNLOCK (pad); break; default: - res = gst_pad_event_default (pad, event); + res = gst_pad_push_event (vorbisenc->srcpad, event); break; } return res; @@ -1141,7 +1143,11 @@ gst_vorbisenc_change_state (GstElement * element, GstStateChange transition) vorbisenc->tags = gst_tag_list_new (); break; case GST_STATE_CHANGE_READY_TO_PAUSED: + vorbisenc->setup = FALSE; + vorbisenc->header_sent = FALSE; + break; case GST_STATE_CHANGE_PAUSED_TO_PLAYING: + break; default: break; } @@ -1152,7 +1158,9 @@ gst_vorbisenc_change_state (GstElement * element, GstStateChange transition) case GST_STATE_CHANGE_PLAYING_TO_PAUSED: break; case GST_STATE_CHANGE_PAUSED_TO_READY: - gst_vorbisenc_clear (vorbisenc); + vorbis_block_clear (&vorbisenc->vb); + vorbis_dsp_clear (&vorbisenc->vd); + vorbis_info_clear (&vorbisenc->vi); break; case GST_STATE_CHANGE_READY_TO_NULL: gst_tag_list_free (vorbisenc->tags);