rem: if (type == BVW_USE_TYPE_VIDEO && GST_IS_BIN (bvw->priv->play)) { GstElement *element = NULL; GstIterator *iter;   if (GST_IS_BIN (video_sink)) { element = gst_bin_get_by_interface (GST_BIN (video_sink), GST_TYPE_X_OVERLAY); } else { element = video_sink; } if (GST_IS_X_OVERLAY (element)) bvw->priv->xoverlay = GST_X_OVERLAY (element);    iter = gst_bin_iterate_all_by_interface (GST_BIN (bvw->priv->play), GST_TYPE_COLOR_BALANCE);  element = NULL; gst_iterator_fold (iter, (GstIteratorFoldFunction) find_colorbalance_element, NULL, &element); gst_iterator_free (iter);  if (element) bvw->priv->balance = GST_COLOR_BALANCE (element); }   for (i = 0; i < 4; i++) { confvalue = gconf_client_get_without_default (bvw->priv->gc, video_props_str[i], NULL); if (confvalue != NULL) { bacon_video_widget_set_video_property (bvw, i, gconf_value_get_int (confvalue)); gconf_value_free (confvalue); } }
add: if (type == BVW_USE_TYPE_VIDEO) {  (void) gst_element_get_state (video_sink, NULL, NULL, GST_CLOCK_TIME_NONE); bvw_update_interface_implementations (bvw); }  if (GST_IS_BIN (video_sink)) {  g_signal_connect (video_sink, "element-added", G_CALLBACK (got_new_video_sink_bin_element), bvw);  gst_bus_set_sync_handler (bus, gst_bus_sync_signal_handler, bvw); g_signal_connect (bus, "sync-message::state-changed", G_CALLBACK (bvw_changed_state_msg_sync), bvw); }  gst_object_unref (bus);
context: bacon_video_widget_new (int width, int height,			BvwUseType type, GError ** err){  GConfValue *confvalue;  BaconVideoWidget *bvw;  GstElement *audio_sink = NULL, *video_sink = NULL;  gint i;  GstBus *bus;  bvw = BACON_VIDEO_WIDGET (g_object_new                            (bacon_video_widget_get_type (), NULL));    bvw->priv->play = gst_element_factory_make ("playbin", "play");  if (!bvw->priv->play) {    g_set_error (err, BVW_ERROR, BVW_ERROR_PLUGIN_LOAD,		 _("Failed to create a GStreamer play object. "		   "Please check your GStreamer installation."));    g_object_unref (bvw);    return NULL;  }  bus = gst_pipeline_get_bus (GST_PIPELINE (bvw->priv->play));  gst_bus_add_signal_watch (bus);  g_signal_connect (bus, "message",                     G_CALLBACK (bvw_bus_message_cb),                    bvw);  bvw->priv->vis_capsfilter = gst_element_factory_make ("capsfilter",							"vis-capsfilter");  bvw->priv->speakersetup = BVW_AUDIO_SOUND_STEREO;  bvw->priv->media_device = g_strdup ("/dev/dvd");  bvw->priv->init_width = 240;  bvw->priv->init_height = 180;  bvw->priv->visq = VISUAL_SMALL;  bvw->priv->show_vfx = FALSE;  bvw->priv->vis_element = NULL;  bvw->priv->tv_out_type = TV_OUT_NONE;  bvw->priv->connection_speed = 0;  bvw->priv->ratio_type = BVW_RATIO_AUTO;  bvw->priv->cursor_shown = TRUE;  bvw->priv->logo_mode = TRUE;  bvw->priv->auto_resize = TRUE;  bvw->priv->cache_errors = TRUE;  /* gconf setting in backend */  bvw->priv->gc = gconf_client_get_default ();  gconf_client_notify_add (bvw->priv->gc, "/apps/totem",      cb_gconf, bvw, NULL, NULL);  if (type == BVW_USE_TYPE_VIDEO || type == BVW_USE_TYPE_AUDIO) {    audio_sink = gst_element_factory_make ("gconfaudiosink", "audio-sink");    if (audio_sink) {      gst_element_set_bus (audio_sink, bus); /* FIXME: WHY THIS? */    } else {      g_warning ("Could not create element 'gconfaudiosink'");    }  } else {    audio_sink = gst_element_factory_make ("fakesink", "audio-fake-sink");  }  if (type == BVW_USE_TYPE_VIDEO) {    video_sink = gst_element_factory_make ("gconfvideosink", "video-sink");    if (video_sink) {      gst_element_set_bus (video_sink, bus); /* FIXME: WHY THIS? */    } else {      g_warning ("Could not create element 'gconfvideosink'");    }/* FIXME: April fool's day puzzle */#if 0    if (video_sink) {      GDate d;      g_date_clear (&d, 1);      g_date_set_time (&d, time (NULL));      if (g_date_day (&d) == 1 && g_date_month (&d) == G_DATE_APRIL) {        confvalue = gconf_client_get_without_default (bvw->priv->gc,            GCONF_PREFIX"/puzzle_year", NULL);        if (!confvalue ||            gconf_value_get_int (confvalue) != g_date_year (&d)) {          GstElement *puzzle;          gconf_client_set_int (bvw->priv->gc, GCONF_PREFIX"/puzzle_year",              g_date_year (&d), NULL);          puzzle = gst_element_factory_make ("puzzle", NULL);          if (puzzle) {            GstElement *bin = gst_bin_new ("videosinkbin");            GstPad *pad;            gst_bin_add_many (GST_BIN (bin), puzzle, video_sink, NULL);            gst_element_link_pads (puzzle, "src", video_sink, "sink");            pad = gst_element_get_pad (puzzle, "sink");            gst_element_add_pad (bin, gst_ghost_pad_new ("sink", pad));            gst_object_unref (pad);            video_sink = bin;          }        }        if (confvalue)          gconf_value_free (confvalue);      }    }#endif  } else {    video_sink = gst_element_factory_make ("fakesink", "video-fake-sink");  }  /* check video */  if (!video_sink ||      gst_element_set_state (video_sink,			     GST_STATE_READY) == GST_STATE_CHANGE_FAILURE) {    /* Videosink not available; give user feedback on what to do now */    if (err) {      bacon_video_widget_process_pending_bus_messages (bvw);      if (bvw->priv->last_error &&	  bvw->priv->last_error->domain == GST_RESOURCE_ERROR) {	switch (bvw->priv->last_error->code) {	  case GST_RESOURCE_ERROR_NOT_FOUND:	  case GST_RESOURCE_ERROR_OPEN_WRITE:	    /* can use the default below... */	    break;	  case GST_RESOURCE_ERROR_BUSY:	    g_set_error (err, BVW_ERROR, BVW_ERROR_VIDEO_PLUGIN,		_("The video output is in use by another application. "		  "Please close other video applications, or select another video output in the Multimedia Systems Selector."));	    break;	  default:	    break;	}      }      if (!*err) {	/* "default" */	if (video_sink) {	  g_set_error (err, BVW_ERROR, BVW_ERROR_VIDEO_PLUGIN,	      _("Failed to open video output. It may not be available. "	        "Please select another video output in the Multimedia Systems Selector."));	} else {	  g_set_error (err, BVW_ERROR, BVW_ERROR_VIDEO_PLUGIN,	      _("Could not find the video output. "		"You may need to install additional GStreamer plugins, or select another video output in the Multimedia Systems Selector."));	}      }      if (bvw->priv->last_error)	g_error_free (bvw->priv->last_error);    }    if (video_sink)      gst_object_unref (video_sink);    if (audio_sink)      gst_object_unref (audio_sink);    g_free (bvw);    return NULL;  }  if (!audio_sink ||      gst_element_set_state (audio_sink,			     GST_STATE_READY) == GST_STATE_CHANGE_FAILURE) {    if (err) {      bacon_video_widget_process_pending_bus_messages (bvw);      if (bvw->priv->last_error &&	  bvw->priv->last_error->domain == GST_RESOURCE_ERROR) {	switch (bvw->priv->last_error->code) {	  case GST_RESOURCE_ERROR_OPEN_WRITE:	  case GST_RESOURCE_ERROR_OPEN_READ_WRITE:	    /* use default below */	    break;	  case GST_RESOURCE_ERROR_BUSY:	    g_set_error (err, BVW_ERROR, BVW_ERROR_AUDIO_BUSY,		_("The audio output is in use by another application. "		  "Please select another audio output in the Multimedia Systems Selector. "		  "You may want to consider using a sound server."));	    break;	  case GST_RESOURCE_ERROR_NOT_FOUND:	    g_set_error (err, BVW_ERROR, BVW_ERROR_AUDIO_PLUGIN,		_("The requested audio output was not found. "		  "Please select another audio output in the Multimedia Systems Selector"));	    break;	  default:	    break;	}      }      if (!*err) {	if (audio_sink) {	  /* "default" */          g_set_error (err, BVW_ERROR, BVW_ERROR_AUDIO_PLUGIN,	      _("Failed to open audio output. You may not have permission to open the sound device, or the sound server may not be running. "	        "Please select another audio output in the Multimedia Systems Selector."));	} else {	  g_set_error (err, BVW_ERROR, BVW_ERROR_AUDIO_PLUGIN,	      _("Could not find the audio output. "		"You may need to install additional GStreamer plugins, or select another audio output in the Multimedia Systems Selector"));	}      }      if (bvw->priv->last_error)	g_error_free (bvw->priv->last_error);    }    if (video_sink)      gst_object_unref (video_sink);    if (audio_sink)      gst_object_unref (audio_sink);    g_free (bvw);    return NULL;  }  do {    GstElement *bin;    GstPad *pad;    bvw->priv->audio_capsfilter =        gst_element_factory_make ("capsfilter", "audiofilter");    bin = gst_bin_new ("audiosinkbin");    gst_bin_add_many (GST_BIN (bin),	bvw->priv->audio_capsfilter, audio_sink, NULL);    gst_element_link_pads (bvw->priv->audio_capsfilter, "src",	audio_sink, "sink");    pad = gst_element_get_pad (bvw->priv->audio_capsfilter, "sink");    gst_element_add_pad (bin, gst_ghost_pad_new ("sink", pad));    gst_object_unref (pad);    audio_sink = bin;  } while (0);  /* now tell playbin */  g_object_set (bvw->priv->play, "video-sink", video_sink, NULL);  g_object_set (bvw->priv->play, "audio-sink", audio_sink, NULL);  bvw->priv->vis_plugins_list = NULL;  bvw->priv->cache_errors = FALSE;  gst_object_unref (bus);  g_signal_connect (bvw->priv->play, "notify::source",		    G_CALLBACK (got_source), bvw);  g_signal_connect (bvw->priv->play, "notify::stream-info",		    G_CALLBACK (stream_info_set), bvw);  /* We try to get an element supporting XOverlay interface */  if (type == BVW_USE_TYPE_VIDEO && GST_IS_BIN (bvw->priv->play)) {    GstElement *element = NULL;    GstIterator *iter;    /* Find videosink */    if (GST_IS_BIN (video_sink)) {      element = gst_bin_get_by_interface (GST_BIN (video_sink),					  GST_TYPE_X_OVERLAY);    } else {      element = video_sink;    }    if (GST_IS_X_OVERLAY (element))      bvw->priv->xoverlay = GST_X_OVERLAY (element);    /* Find best color balance element (using custom iterator so     * we can prefer hardware implementations to software ones) */    iter = gst_bin_iterate_all_by_interface (GST_BIN (bvw->priv->play),					     GST_TYPE_COLOR_BALANCE);    /* naively assume no resync */    element = NULL;    gst_iterator_fold (iter,        (GstIteratorFoldFunction) find_colorbalance_element, NULL, &element);    gst_iterator_free (iter);    if (element)      bvw->priv->balance = GST_COLOR_BALANCE (element);  }  /* Setup brightness and contrast */  for (i = 0; i < 4; i++) {    confvalue = gconf_client_get_without_default (bvw->priv->gc,        video_props_str[i], NULL);    if (confvalue != NULL) {      bacon_video_widget_set_video_property (bvw, i,        gconf_value_get_int (confvalue));      gconf_value_free (confvalue);    }  }  /* audio out, if any */  confvalue = gconf_client_get_without_default (bvw->priv->gc,      GCONF_PREFIX"/audio_output_type", NULL);  if (confvalue != NULL &&      (type != BVW_USE_TYPE_METADATA && type != BVW_USE_TYPE_CAPTURE)) {    bvw->priv->speakersetup = gconf_value_get_int (confvalue);    bvw->priv->speakersetup = gconf_value_get_int (confvalue) - 1;    bacon_video_widget_set_audio_out_type (bvw, bvw->priv->speakersetup + 1);    gconf_value_free (confvalue);  } else {    bvw->priv->speakersetup = -1;    bacon_video_widget_set_audio_out_type (bvw, BVW_AUDIO_SOUND_STEREO);  }  /* visualization */  confvalue = gconf_client_get_without_default (bvw->priv->gc,      GCONF_PREFIX "/show_vfx", NULL);  if (confvalue != NULL) {    bvw->priv->show_vfx = gconf_value_get_bool (confvalue);    gconf_value_free (confvalue);  }  confvalue = gconf_client_get_without_default (bvw->priv->gc,      GCONF_PREFIX "/visual_quality", NULL);  if (confvalue != NULL) {    bvw->priv->visq = gconf_value_get_int (confvalue);    gconf_value_free (confvalue);  }#if 0  confvalue = gconf_client_get_without_default (bvw->priv->gc,      GCONF_PREFIX "/visual", NULL);  if (confvalue != NULL) {    bvw->priv->vis_element =         gst_element_factory_make (gconf_value_get_string (confvalue), NULL);    gconf_value_free (confvalue);  }  setup_vis ();#endif  /* tv/conn (not used yet) */  confvalue = gconf_client_get_without_default (bvw->priv->gc,      GCONF_PREFIX "/tv_out_type", NULL);  if (confvalue != NULL) {    bvw->priv->tv_out_type = gconf_value_get_int (confvalue);    gconf_value_free (confvalue);  }  confvalue = gconf_client_get_without_default (bvw->priv->gc,      GCONF_PREFIX "/connection_speed", NULL);  if (confvalue != NULL) {    bvw->priv->connection_speed = gconf_value_get_int (confvalue);    gconf_value_free (confvalue);  }  /* those are private to us, i.e. not Xine-compatible */  confvalue = gconf_client_get_without_default (bvw->priv->gc,      GCONF_PREFIX "/buffer-size", NULL);  if (confvalue != NULL) {    g_object_set (bvw->priv->play, "queue-size",        (guint64) GST_SECOND * gconf_value_get_float (confvalue), NULL);    gconf_value_free (confvalue);  }  confvalue = gconf_client_get_without_default (bvw->priv->gc,      GCONF_PREFIX "/network-buffer-threshold", NULL);  if (confvalue != NULL) {    g_object_set (bvw->priv->play, "queue-threshold",        (guint64) GST_SECOND * gconf_value_get_float (confvalue), NULL);    gconf_value_free (confvalue);  }  return GTK_WIDGET (bvw);}