# HG changeset patch # User renatofilho # Date 1186063095 -3600 # Node ID a6ac25bf88a7a067b33f87dceb62a3400a716569 # Parent cdafc5e948b8c10f2cb155119b3f497637032734 [svn r798] fixed bug on video sink element diff -r cdafc5e948b8 -r a6ac25bf88a7 gst-gmyth/decodebin2/gstdecodebin2.c --- a/gst-gmyth/decodebin2/gstdecodebin2.c Thu Aug 02 14:49:26 2007 +0100 +++ b/gst-gmyth/decodebin2/gstdecodebin2.c Thu Aug 02 14:58:15 2007 +0100 @@ -450,9 +450,11 @@ } /* only select elements with autoplugging rank */ +#if 0 rank = gst_plugin_feature_get_rank (feature); if (rank < GST_RANK_MARGINAL) return FALSE; +#endif return TRUE; } diff -r cdafc5e948b8 -r a6ac25bf88a7 gst-gmyth/playbinmaemo/gstplaybinmaemo.c --- a/gst-gmyth/playbinmaemo/gstplaybinmaemo.c Thu Aug 02 14:49:26 2007 +0100 +++ b/gst-gmyth/playbinmaemo/gstplaybinmaemo.c Thu Aug 02 14:58:15 2007 +0100 @@ -95,10 +95,9 @@ gpointer user_data); static void queue_sink_overrun_cb (GstElement* queue, gpointer user_data); - - - - +static gboolean add_element (GstPlayBinMaemo *pbm, + GstElement *child); +static void clear_elements (GstPlayBinMaemo *pbm); GST_BOILERPLATE(GstPlayBinMaemo, gst_play_bin_maemo, GstPipeline, GST_TYPE_PIPELINE) @@ -191,6 +190,7 @@ static void gst_play_bin_maemo_finalize (GObject * object) { + clear_elements (GST_PLAY_BIN_MAEMO (object)); G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -248,8 +248,7 @@ if (IS_BLACKLISTED_URI (play_bin_maemo->uri)) goto uri_blacklisted; - source = gst_element_make_from_uri (GST_URI_SRC, play_bin_maemo->uri, - "source"); + source = gst_element_make_from_uri (GST_URI_SRC, play_bin_maemo->uri, "source"); if (!source) goto no_source; @@ -312,76 +311,32 @@ } static void -remove_source (GstPlayBinMaemo *pbm) -{ - GstElement *source = pbm->source; - - if (source) { - GST_DEBUG_OBJECT (pbm, "removing old src element"); - gst_element_set_state (source, GST_STATE_NULL); - gst_bin_remove (GST_BIN_CAST (pbm), source); - pbm->source = NULL; - } -} - -static void -remove_decoders (GstPlayBinMaemo *pbm) -{ - if (pbm->queue != NULL) { - gst_element_set_state (pbm->queue, GST_STATE_NULL); - gst_bin_remove (GST_BIN_CAST (pbm), pbm->queue); - pbm->queue = NULL; - } - - if (pbm->decoder != NULL) { - gst_element_set_state (pbm->decoder, GST_STATE_NULL); - gst_bin_remove (GST_BIN_CAST (pbm), pbm->decoder); - pbm->decoder = NULL; - } -} - -static void -remove_sinks (GstPlayBinMaemo *pbm) -{ - GSList *walk; - - for(walk=pbm->sinks; walk != NULL; walk = walk->next) { - GstElement *element = (GstElement *) walk->data; - - gst_element_set_state (element, GST_STATE_NULL); - gst_bin_remove (GST_BIN_CAST (pbm), element); - } - - g_slist_free (pbm->sinks); - pbm->sinks = NULL; -} - -static void prepare_elements (GstPlayBinMaemo *pbm) { - if (pbm->decoder == NULL) { - pbm->decoder = gst_element_factory_make ("decodebin2", "decode"); - gst_bin_add (GST_BIN (pbm), pbm->decoder); - g_signal_connect (G_OBJECT (pbm->decoder), - "autoplug-continue", - G_CALLBACK (autoplug_continue_cb), - pbm); - g_signal_connect (G_OBJECT (pbm->decoder), - "unknown-type", - G_CALLBACK (unknown_type_cb), - pbm); - g_signal_connect (G_OBJECT (pbm->decoder), - "new-decoded-pad", - G_CALLBACK (new_decoded_pad_cb), - pbm); - } + GstElement *decoder; + GstElement *queue; - if (pbm->queue == NULL) { - pbm->queue = gst_element_factory_make ("queue", NULL); - gst_bin_add (GST_BIN (pbm), pbm->queue); - } + decoder = gst_element_factory_make ("decodebin2", "decode"); + add_element (pbm, decoder); + g_signal_connect (G_OBJECT (decoder), + "autoplug-continue", + G_CALLBACK (autoplug_continue_cb), + pbm); - if (gst_element_link_many (pbm->source, pbm->queue, pbm->decoder, NULL) == FALSE) { + g_signal_connect (G_OBJECT (decoder), + "unknown-type", + G_CALLBACK (unknown_type_cb), + pbm); + + g_signal_connect (G_OBJECT (decoder), + "new-decoded-pad", + G_CALLBACK (new_decoded_pad_cb), + pbm); + + queue = gst_element_factory_make ("queue", NULL); + add_element (pbm, queue); + + if (gst_element_link_many (pbm->source, queue, decoder, NULL) == FALSE) { g_warning ("FAIL TO LINK SRC WITH DECODEBIN2"); } } @@ -389,26 +344,25 @@ static gboolean setup_source (GstPlayBinMaemo *pbm) { + GstIterator *childs; + GstState state; + if (!pbm->need_rebuild) return TRUE; + clear_elements (pbm); + GST_DEBUG_OBJECT (pbm, "setup source"); pbm->has_metadata = FALSE; - /* delete old src */ - remove_source (pbm); - /* create and configure an element that can handle the uri */ if (!(pbm->source = gen_source_element (pbm))) goto no_source; - gst_bin_add (GST_BIN_CAST (pbm), pbm->source); + add_element (pbm, pbm->source); - remove_decoders (pbm); - - remove_sinks (pbm); #if 0 if (verify_src_have_sink (pbm)) { @@ -460,7 +414,7 @@ } case ARG_VOLUME: { - guint volume; + guint volume = 0; volume = g_value_get_uint (value); if (volume != 0) { volume = (guint) (65535 * volume / 10); @@ -476,7 +430,8 @@ { long xid; xid = g_value_get_long (value); - if (play_bin_maemo->xid != xid) { + if (play_bin_maemo->xid != xid) + { play_bin_maemo->xid = xid; update_xid (play_bin_maemo); } @@ -509,8 +464,14 @@ g_value_set_object (value, play_bin_maemo->source); break; case ARG_VOLUME: - g_value_set_uint (value, play_bin_maemo->volume); + { + guint volume = 0; + if (play_bin_maemo->volume > 0) { + volume = 10 * play_bin_maemo->volume / 65535; + } + g_value_set_uint (value, volume); break; + } case ARG_XID: g_value_set_long (value, play_bin_maemo->xid); break; @@ -553,8 +514,7 @@ case GST_STATE_CHANGE_PAUSED_TO_READY: case GST_STATE_CHANGE_READY_TO_NULL: play_bin_maemo->need_rebuild = TRUE; - remove_decoders (play_bin_maemo); - remove_source (play_bin_maemo); + clear_elements (play_bin_maemo); break; default: break; @@ -719,47 +679,93 @@ static GstElement* create_element (GstPlayBinMaemo *pbm, GstElementFactory *factory) { - GstElement *ret = NULL; + GstElement *queue; + GstElement *bin = NULL; GstElement *element; + GstPad *pad; element = gst_element_factory_create (factory, NULL); if (element == NULL) return NULL; + + bin = gst_bin_new (NULL); + + queue = gst_element_factory_make ("queue", NULL); + gst_bin_add (GST_BIN (bin), queue); + if (strstr (gst_element_factory_get_klass (factory), "Sink/Video") != NULL) { + GstElement *colorspace; + + colorspace = gst_element_factory_make ("ffmpegcolorspace", NULL); + + gst_bin_add (GST_BIN (bin), colorspace); + if (gst_element_link (queue, colorspace) == FALSE) { + GST_WARNING_OBJECT (pbm, "Fail to link queue and colorspace"); + gst_element_set_state (colorspace, GST_STATE_NULL); + gst_object_unref (colorspace); + goto error; + } + + gst_bin_add (GST_BIN (bin), element); + if (gst_element_link (colorspace, element) == FALSE) { + GST_WARNING_OBJECT (pbm, "Fail to link colorspace and sink video: %s", GST_ELEMENT_NAME (element)); + gst_element_set_state (colorspace, GST_STATE_NULL); + gst_object_unref (colorspace); + goto error; + } + + pbm->sink_video = element; update_xid (pbm); - pbm->sink_video = element; - ret = element; + } else if (strstr (gst_element_factory_get_klass (factory), "Sink/Audio") != NULL) { GParamSpec *vol_spec; + GstElement *prev; + prev = queue; vol_spec = g_object_class_find_property (G_OBJECT_GET_CLASS (element), "volume"); if (vol_spec == NULL) { - GstElement *bin; GstElement *volume; bin = gst_bin_new (NULL); volume = gst_element_factory_make ("volume", "volume"); gst_bin_add (GST_BIN (bin), volume); - gst_bin_add (GST_BIN (bin), element); - if (gst_element_link (volume, element) == FALSE) { - GST_WARNING_OBJECT (pbm, "Fail to link volume and sink audio: %s", GST_ELEMENT_NAME (element)); - gst_element_set_state (bin, GST_STATE_NULL); - gst_object_unref (bin); - return NULL; + if (gst_element_link (queue, volume) == FALSE) { + GST_WARNING_OBJECT (pbm, "Fail to link queue and volume"); + gst_element_set_state (volume, GST_STATE_NULL); + gst_object_unref (volume); + goto error; } - pbm->volume_element = volume; - ret = bin; - } else { - ret = element; - pbm->volume_element = element; + + prev = volume; g_param_spec_unref (vol_spec); } + gst_bin_add (GST_BIN (bin), element); + if (gst_element_link (prev, element) == FALSE) { + GST_WARNING_OBJECT (pbm, "Fail to link volume and sink audio: %s", GST_ELEMENT_NAME (element)); + if (prev != queue) { + gst_element_set_state (prev, GST_STATE_NULL); + gst_object_unref (prev); + } + goto error; + } + + pbm->volume_element = (prev != queue) ? prev : element; update_volume (pbm); } - return ret; + pad = gst_element_get_pad (queue, "sink"); + gst_element_add_pad (bin, gst_ghost_pad_new ("sink", pad)); + gst_object_unref (pad); + + return bin; +error: + + gst_element_set_state (bin, GST_STATE_NULL); + gst_object_unref (bin); + + return NULL; } static void @@ -798,10 +804,13 @@ if ((element = create_element (pbm, factory)) == NULL) { GST_WARNING_OBJECT (pbm, "Could not create an element from %s", gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory))); + g_debug ("Could not create an element from %s", + gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory))); + continue; } - if (!(gst_bin_add (GST_BIN (user_data), element))) { + if (!(add_element (GST_PLAY_BIN_MAEMO (user_data), element))) { GST_WARNING_OBJECT (pbm, "Couldn't set %s to READY", GST_ELEMENT_NAME (element)); gst_object_unref (element); continue; @@ -817,6 +826,7 @@ if (!(sinkpad = find_sink_pad (element))) { GST_WARNING_OBJECT (pbm, "Element %s doesn't have a sink pad", GST_ELEMENT_NAME (element)); + g_debug ("Element %s doesn't have a sink pad", GST_ELEMENT_NAME (element)); gst_object_unref (element); continue; } @@ -838,8 +848,6 @@ continue; } - - pbm->sinks = g_slist_append (pbm->sinks, element); linked = TRUE; break; } @@ -874,14 +882,51 @@ (pbm->xid != -1) && (GST_IS_X_OVERLAY (pbm->sink_video))) { + Display *display; g_object_set (G_OBJECT (pbm->sink_video), "force-aspect-ratio", TRUE, NULL); + display = XOpenDisplay(NULL); + XMapRaised(display, pbm->xid); + XSync (display, FALSE); + gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (pbm->sink_video), pbm->xid); } } static gboolean +add_element (GstPlayBinMaemo *pbm, + GstElement *child) +{ + if (gst_bin_add (GST_BIN (pbm), child)) { + pbm->elements = g_list_append (pbm->elements, child); + return TRUE; + } + return FALSE; +} + +static void +clear_elements (GstPlayBinMaemo *pbm) +{ + GList *walk; + + walk = pbm->elements; + + for (; walk != NULL; walk = walk->next) { + GstElement *e = GST_ELEMENT (walk->data); + + gst_element_set_state (e, GST_STATE_NULL); + gst_bin_remove (GST_BIN (pbm), e); + } + + g_list_free (pbm->elements); + pbm->elements = NULL; + pbm->source = NULL; + pbm->volume_element = NULL; + pbm->sink_video = NULL; +} + +static gboolean plugin_init(GstPlugin * plugin) { #ifdef ENABLE_NLS diff -r cdafc5e948b8 -r a6ac25bf88a7 gst-gmyth/playbinmaemo/gstplaybinmaemo.h --- a/gst-gmyth/playbinmaemo/gstplaybinmaemo.h Thu Aug 02 14:49:26 2007 +0100 +++ b/gst-gmyth/playbinmaemo/gstplaybinmaemo.h Thu Aug 02 14:58:15 2007 +0100 @@ -54,12 +54,10 @@ gboolean need_rebuild; gboolean has_metadata; gchar *uri; + GstElement *volume_element; GstElement *source; - GstElement *decoder; - GstElement *queue; - GstElement *volume_element; GstElement *sink_video; - GSList *sinks; + GList *elements; GList *factories; };