playsink: Remember automatically created sinks for future reconfigures

Also allow reuse of sink elements in error cases.
This commit is contained in:
Sebastian Dröge 2011-03-15 14:45:03 +01:00
parent 9c13edef4e
commit 2c057f745f

View file

@ -1215,6 +1215,8 @@ gen_video_chain (GstPlaySink * playsink, gboolean raw, gboolean async)
chain->sink = try_element (playsink, elem, TRUE); chain->sink = try_element (playsink, elem, TRUE);
} }
} }
if (chain->sink)
playsink->video_sink = gst_object_ref (chain->sink);
} }
if (chain->sink == NULL) if (chain->sink == NULL)
goto no_sinks; goto no_sinks;
@ -1360,6 +1362,8 @@ link_failed:
(NULL), ("Failed to configure the video sink.")); (NULL), ("Failed to configure the video sink."));
/* checking sink made it READY */ /* checking sink made it READY */
gst_element_set_state (chain->sink, GST_STATE_NULL); gst_element_set_state (chain->sink, GST_STATE_NULL);
/* Remove chain from the bin to allow reuse later */
gst_bin_remove (bin, chain->sink);
free_chain ((GstPlayChain *) chain); free_chain ((GstPlayChain *) chain);
return NULL; return NULL;
} }
@ -1486,6 +1490,9 @@ gen_text_chain (GstPlaySink * playsink)
gst_play_sink_find_property_sinks (playsink, chain->sink, gst_play_sink_find_property_sinks (playsink, chain->sink,
"sync", G_TYPE_BOOLEAN))) "sync", G_TYPE_BOOLEAN)))
g_object_set (elem, "sync", TRUE, NULL); g_object_set (elem, "sync", TRUE, NULL);
if (!textsinkpad)
gst_bin_remove (bin, chain->sink);
} else { } else {
GST_WARNING_OBJECT (playsink, GST_WARNING_OBJECT (playsink,
"can't find async property in custom text sink"); "can't find async property in custom text sink");
@ -1671,6 +1678,8 @@ gen_audio_chain (GstPlaySink * playsink, gboolean raw)
chain->sink = try_element (playsink, elem, TRUE); chain->sink = try_element (playsink, elem, TRUE);
} }
} }
if (chain->sink)
playsink->audio_sink = gst_object_ref (chain->sink);
} }
if (chain->sink == NULL) if (chain->sink == NULL)
goto no_sinks; goto no_sinks;
@ -1885,6 +1894,8 @@ link_failed:
(NULL), ("Failed to configure the audio sink.")); (NULL), ("Failed to configure the audio sink."));
/* checking sink made it READY */ /* checking sink made it READY */
gst_element_set_state (chain->sink, GST_STATE_NULL); gst_element_set_state (chain->sink, GST_STATE_NULL);
/* Remove chain from the bin to allow reuse later */
gst_bin_remove (bin, chain->sink);
free_chain ((GstPlayChain *) chain); free_chain ((GstPlayChain *) chain);
return NULL; return NULL;
} }
@ -2211,6 +2222,13 @@ gst_play_sink_reconfigure (GstPlaySink * playsink)
} }
add_chain (GST_PLAY_CHAIN (playsink->videochain), FALSE); add_chain (GST_PLAY_CHAIN (playsink->videochain), FALSE);
/* Remove the sink from the bin to keep its state
* and unparent it to allow reuse */
if (playsink->videochain->sink)
gst_bin_remove (GST_BIN_CAST (playsink->videochain->chain.bin),
playsink->videochain->sink);
activate_chain (GST_PLAY_CHAIN (playsink->videochain), FALSE); activate_chain (GST_PLAY_CHAIN (playsink->videochain), FALSE);
free_chain ((GstPlayChain *) playsink->videochain); free_chain ((GstPlayChain *) playsink->videochain);
playsink->videochain = NULL; playsink->videochain = NULL;
@ -2355,6 +2373,13 @@ gst_play_sink_reconfigure (GstPlaySink * playsink)
} }
add_chain (GST_PLAY_CHAIN (playsink->audiochain), FALSE); add_chain (GST_PLAY_CHAIN (playsink->audiochain), FALSE);
/* Remove the sink from the bin to keep its state
* and unparent it to allow reuse */
if (playsink->audiochain->sink)
gst_bin_remove (GST_BIN_CAST (playsink->audiochain->chain.bin),
playsink->audiochain->sink);
activate_chain (GST_PLAY_CHAIN (playsink->audiochain), FALSE); activate_chain (GST_PLAY_CHAIN (playsink->audiochain), FALSE);
disconnect_chain (playsink->audiochain, playsink); disconnect_chain (playsink->audiochain, playsink);
playsink->audiochain->volume = NULL; playsink->audiochain->volume = NULL;
@ -3275,6 +3300,27 @@ gst_play_sink_change_state (GstElement * element, GstStateChange transition)
* so they may be re-used faster next time/url around. * so they may be re-used faster next time/url around.
* when really going to NULL, clean up everything completely. */ * when really going to NULL, clean up everything completely. */
if (transition == GST_STATE_CHANGE_READY_TO_NULL) { if (transition == GST_STATE_CHANGE_READY_TO_NULL) {
/* Unparent the sinks to allow reuse */
if (playsink->videochain && playsink->videochain->sink)
gst_bin_remove (GST_BIN_CAST (playsink->videochain->chain.bin),
playsink->videochain->sink);
if (playsink->audiochain && playsink->audiochain->sink)
gst_bin_remove (GST_BIN_CAST (playsink->audiochain->chain.bin),
playsink->audiochain->sink);
if (playsink->textchain && playsink->textchain->sink)
gst_bin_remove (GST_BIN_CAST (playsink->textchain->chain.bin),
playsink->textchain->sink);
if (playsink->audio_sink != NULL)
gst_element_set_state (playsink->audio_sink, GST_STATE_NULL);
if (playsink->video_sink != NULL)
gst_element_set_state (playsink->video_sink, GST_STATE_NULL);
if (playsink->visualisation != NULL)
gst_element_set_state (playsink->visualisation, GST_STATE_NULL);
if (playsink->text_sink != NULL)
gst_element_set_state (playsink->text_sink, GST_STATE_NULL);
free_chain ((GstPlayChain *) playsink->videodeinterlacechain); free_chain ((GstPlayChain *) playsink->videodeinterlacechain);
playsink->videodeinterlacechain = NULL; playsink->videodeinterlacechain = NULL;
free_chain ((GstPlayChain *) playsink->videochain); free_chain ((GstPlayChain *) playsink->videochain);