VV: some cleanup, add ffmpeg filter to ksvideosrc

Thu, 06 Jun 2013 13:39:17 +0200

author
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
date
Thu, 06 Jun 2013 13:39:17 +0200
changeset 33957
0a4c13fa94ba
parent 33956
84f5fef32685
child 33958
d76b1d242829

VV: some cleanup, add ffmpeg filter to ksvideosrc

pidgin/gtkmedia.c file | annotate | diff | comparison | revisions
pidgin/gtkprefs.c file | annotate | diff | comparison | revisions
--- a/pidgin/gtkmedia.c	Mon Jun 03 00:10:15 2013 -0700
+++ b/pidgin/gtkmedia.c	Thu Jun 06 13:39:17 2013 +0200
@@ -1057,46 +1057,83 @@
 }
 
 static GstElement *
+create_vv_element(const gchar *plugin, const gchar *device)
+{
+	GstElement *element;
+
+	g_return_val_if_fail(plugin != NULL, NULL);
+	g_return_val_if_fail(plugin[0] != '\0', NULL);
+
+	if (device != NULL && device[0] == '\0')
+		device = NULL;
+
+	if (g_strcmp0(plugin, "videodisabledsrc") == 0) {
+		element = gst_element_factory_make("videotestsrc", NULL);
+		g_object_set(G_OBJECT(element), "is-live", TRUE, NULL);
+		if (g_strcmp0(device, "snow") == 0) {
+			/* GST_VIDEO_TEST_SRC_SNOW */
+			g_object_set(G_OBJECT(element), "pattern", 1, NULL);
+		} else {
+			/* GST_VIDEO_TEST_SRC_BLACK */
+			g_object_set(G_OBJECT(element), "pattern", 2, NULL);
+		}
+		return element;
+	}
+
+	if (g_strcmp0(plugin, "ksvideosrc") == 0) {
+		GstElement *ksv_bin, *ksv_src, *ksv_filter;
+		GstPad *ksv_pad, *ksv_ghost;
+
+		ksv_bin = gst_bin_new("ksvideofilteredsrc");
+		ksv_src = gst_element_factory_make("ksvideosrc", NULL);
+		ksv_filter = gst_element_factory_make("ffmpegcolorspace", NULL);
+
+		gst_bin_add_many(GST_BIN(ksv_bin), ksv_src, ksv_filter, NULL);
+
+		gst_element_link(ksv_src, ksv_filter);
+
+		ksv_pad = gst_element_get_static_pad(ksv_filter, "src");
+		ksv_ghost = gst_ghost_pad_new("src", ksv_pad);
+		gst_object_unref(ksv_pad);
+		gst_element_add_pad(ksv_bin, ksv_ghost);
+
+		element = ksv_bin;
+	}
+	else
+		element = gst_element_factory_make(plugin, NULL);
+
+	if (element == NULL)
+		return NULL;
+
+	if (device != NULL)
+		g_object_set(G_OBJECT(element), "device", device, NULL);
+
+	if (g_strcmp0(plugin, "videotestsrc") == 0)
+		g_object_set(G_OBJECT(element), "is-live", TRUE, NULL);
+
+	return element;
+}
+
+static GstElement *
 create_configured_vv_element(const gchar *type, const gchar *dir)
 {
 	gchar *tmp;
 	const gchar *plugin, *device;
-	GstElement *ret;
 
-	tmp = g_strdup_printf(PIDGIN_PREFS_ROOT "/vvconfig/%s/%s/plugin", type, dir);
+	tmp = g_strdup_printf(PIDGIN_PREFS_ROOT "/vvconfig/%s/%s/plugin",
+		type, dir);
 	plugin = purple_prefs_get_string(tmp);
 	g_free(tmp);
 
-	tmp = g_strdup_printf(PIDGIN_PREFS_ROOT "/vvconfig/%s/%s/device", type, dir);
+	tmp = g_strdup_printf(PIDGIN_PREFS_ROOT "/vvconfig/%s/%s/device",
+		type, dir);
 	device = purple_prefs_get_string(tmp);
 	g_free(tmp);
 
 	if (plugin == NULL || plugin[0] == '\0')
 		return NULL;
 
-	if (g_strcmp0(type, "video") == 0 && g_strcmp0(dir, "src") == 0 &&
-		g_strcmp0(plugin, "disabled") == 0)
-	{
-		ret = gst_element_factory_make("videotestsrc", NULL);
-		g_object_set(G_OBJECT(ret), "is-live", 1, NULL);
-		if (g_strcmp0(device, "snow") == 0) {
-			/* GST_VIDEO_TEST_SRC_SNOW */
-			g_object_set(G_OBJECT(ret), "pattern", 1, NULL);
-		} else {
-			/* GST_VIDEO_TEST_SRC_BLACK */
-			g_object_set(G_OBJECT(ret), "pattern", 2, NULL);
-		}
-		return ret;
-	}
-
-	ret = gst_element_factory_make(plugin, NULL);
-	if (device != NULL && device[0] != '\0')
-		g_object_set(G_OBJECT(ret), "device", device, NULL);
-
-	if (g_strcmp0(plugin, "videotestsrc") == 0)
-		g_object_set(G_OBJECT(ret), "is-live", 1, NULL);
-
-	return ret;
+	return create_vv_element(plugin, device);
 }
 
 static GstElement *
@@ -1110,33 +1147,29 @@
 	src = create_configured_vv_element("video", "src");
 
 #ifdef _WIN32
-	/* autovideosrc doesn't pick ksvideosrc for some reason */
 	if (src == NULL)
-		src = gst_element_factory_make("ksvideosrc", NULL);
+		src = create_vv_element("ksvideosrc", NULL);
 	if (src == NULL)
-		src = gst_element_factory_make("dshowvideosrc", NULL);
+		src = create_vv_element("dshowvideosrc", NULL);
 	if (src == NULL)
-		src = gst_element_factory_make("autovideosrc", NULL);
+		src = create_vv_element("autovideosrc", NULL);
 #elif defined(__APPLE__)
 	if (src == NULL)
-		src = gst_element_factory_make("osxvideosrc", NULL);
+		src = create_vv_element("osxvideosrc", NULL);
 	if (src == NULL)
-		src = gst_element_factory_make("autovideosrc", NULL);
+		src = create_vv_element("autovideosrc", NULL);
 #else
 	if (src == NULL)
-		src = gst_element_factory_make("gconfvideosrc", NULL);
+		src = create_vv_element("gconfvideosrc", NULL);
 	if (src == NULL)
-		src = gst_element_factory_make("autovideosrc", NULL);
-	if (src == NULL)
-		src = gst_element_factory_make("v4l2src", NULL);
+		src = create_vv_element("autovideosrc", NULL);
 	if (src == NULL)
-		src = gst_element_factory_make("v4lsrc", NULL);
+		src = create_vv_element("v4l2src", NULL);
+	if (src == NULL)
+		src = create_vv_element("v4lsrc", NULL);
 #endif
-	if (src == NULL) {
-		src = gst_element_factory_make("videotestsrc", NULL);
-		if (src != NULL)
-			g_object_set(G_OBJECT(src), "is-live", TRUE, NULL);
-	}
+	if (src == NULL)
+		src = create_vv_element("videotestsrc", NULL);
 	if (src == NULL) {
 		purple_debug_error("gtkmedia", "Unable to find a suitable "
 				"element for the default video source.\n");
@@ -1164,11 +1197,11 @@
 	sink = create_configured_vv_element("video", "sink");
 
 	if (sink == NULL)
-		sink = gst_element_factory_make("directdrawsink", NULL);
+		sink = create_vv_element("directdrawsink", NULL);
 	if (sink == NULL)
-		sink = gst_element_factory_make("gconfvideosink", NULL);
+		sink = create_vv_element("gconfvideosink", NULL);
 	if (sink == NULL)
-		sink = gst_element_factory_make("autovideosink", NULL);
+		sink = create_vv_element("autovideosink", NULL);
 	if (sink == NULL)
 		purple_debug_error("gtkmedia", "Unable to find a suitable "
 				"element for the default video sink.\n");
@@ -1184,19 +1217,19 @@
 	src = create_configured_vv_element("audio", "src");
 
 	if (src == NULL)
-		src = gst_element_factory_make("directsoundsrc", NULL);
+		src = create_vv_element("directsoundsrc", NULL);
 	if (src == NULL)
-		src = gst_element_factory_make("gconfaudiosrc", NULL);
+		src = create_vv_element("gconfaudiosrc", NULL);
 	if (src == NULL)
-		src = gst_element_factory_make("autoaudiosrc", NULL);
+		src = create_vv_element("autoaudiosrc", NULL);
 	if (src == NULL)
-		src = gst_element_factory_make("alsasrc", NULL);
+		src = create_vv_element("alsasrc", NULL);
 	if (src == NULL)
-		src = gst_element_factory_make("osssrc", NULL);
+		src = create_vv_element("osssrc", NULL);
 	if (src == NULL)
-		src = gst_element_factory_make("dshowaudiosrc", NULL);
+		src = create_vv_element("dshowaudiosrc", NULL);
 	if (src == NULL)
-		src = gst_element_factory_make("osxaudiosrc", NULL);
+		src = create_vv_element("osxaudiosrc", NULL);
 	if (src == NULL) {
 		purple_debug_error("gtkmedia", "Unable to find a suitable "
 				"element for the default audio source.\n");
@@ -1215,11 +1248,11 @@
 	sink = create_configured_vv_element("audio", "sink");
 
 	if (sink == NULL)
-		sink = gst_element_factory_make("directsoundsink", NULL);
+		sink = create_vv_element("directsoundsink", NULL);
 	if (sink == NULL)
-		sink = gst_element_factory_make("gconfaudiosink", NULL);
+		sink = create_vv_element("gconfaudiosink", NULL);
 	if (sink == NULL)
-		sink = gst_element_factory_make("autoaudiosink",NULL);
+		sink = create_vv_element("autoaudiosink",NULL);
 	if (sink == NULL) {
 		purple_debug_error("gtkmedia", "Unable to find a suitable "
 				"element for the default audio sink.\n");
--- a/pidgin/gtkprefs.c	Mon Jun 03 00:10:15 2013 -0700
+++ b/pidgin/gtkprefs.c	Thu Jun 06 13:39:17 2013 +0200
@@ -150,7 +150,7 @@
 };
 
 static const gchar *VIDEO_SRC_PLUGINS[] = {
-	"disabled",	N_("Disabled"),
+	"videodisabledsrc",	N_("Disabled"),
 	"videotestsrc",	"Test Input",
 	"dshowvideosrc","DirectDraw",
 	"ksvideosrc",	"KS Video",
@@ -3114,7 +3114,7 @@
 		return g_list_reverse(ret);
 	}
 
-	if (g_strcmp0(element_name, "disabled") == 0) {
+	if (g_strcmp0(element_name, "videodisabledsrc") == 0) {
 		ret = g_list_prepend(ret, (gpointer)_("Random noise"));
 		ret = g_list_prepend(ret, "snow");
 
@@ -3205,7 +3205,7 @@
 #else
 		if (gst_default_registry_check_feature_version(plugins[0], 0, 0, 0)
 #endif
-			|| g_strcmp0(plugins[0], "disabled") == 0)
+			|| g_strcmp0(plugins[0], "videodisabledsrc") == 0)
 		{
 			ret = g_list_prepend(ret, (gpointer)plugins[1]);
 			ret = g_list_prepend(ret, (gpointer)plugins[0]);

mercurial