how to use filter in C source?

dhkdlasdnr alsdnr4874 at gmail.com
Fri Apr 27 07:14:40 UTC 2018


Hi.

I try to make some simple gstreamer application.

My pipeline is v4l2src ! video/x-raw, format=YUY2, width=640, height=480,
framerate=30/1 ! videoconvert ! video/x-raw, format=GRAY8 ! videoconvert !
ximagesink

That pipeline is well running on gst-launch-1.0.

I tested no filter version pipeline. this v4l2src ! videoconvert !
ximagesink pipeline.

and That test application working well.

Point is, I don't know how to use filter in C source code. so I try some
searching to use filter.

and I make this code

#include <string.h>
#include <gst/gst.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>

GMainLoop *loop;
GstElement *pipeline, *src, *conv, *sink;

static gboolean link_element_with_filter (GstElement *e1, GstElement *e2)
{
	gboolean link_ok;
	GstCaps *caps;

	caps = gst_caps_new_simple("video/x-raw", 
			"format", G_TYPE_STRING, "YUY2", 
			"width", G_TYPE_INT, 640, 
			"height", G_TYPE_INT, 480, 
			"framerate", GST_TYPE_FRACTION, 30, 1,
		       	NULL);

	link_ok = gst_element_link_filtered (e1, e2, caps);
	gst_caps_unref(caps);

	if(!link_ok){
		g_warning("Failed to link e1 and e2.\n");
	}
	return link_ok;
}

static void on_pad_added(GstElement *element, GstPad *pad, gpointer data)
{
	GstPad *sinkpad;
	GstElement *decoder = (GstElement *) data;

	g_print("Dynamic pad created, linking demuxer/decoder\n");

	sinkpad = gst_element_get_static_pad(decoder, "sink");
	gst_pad_link(pad, sinkpad);

	gst_object_unref(sinkpad);
}

int main (int argc, char *argv[])
{
	GstBus *bus;
	gboolean res;

	signal(SIGINT, sigintHandler);
	gst_init(&argc, &argv);

	loop = g_main_loop_new(NULL, FALSE);

	pipeline = gst_pipeline_new("v4l2_test");
	src	 = gst_element_factory_make("v4l2src", "v4l2src");
	conv	 = gst_element_factory_make("videoconvert", "converter");
	sink	 = gst_element_factory_make("ximagesink", "videosink");
	if(!pipeline || !src || !conv || !sink){
		g_error("Failed to create elements.\n");
		return -1;
	}
	
	gst_element_link(src, conv);
	gst_element_link(conv, sink);

	g_signal_connect(conv, "pad-added", G_CALLBACK(on_pad_added), sink);

	res = link_element_with_filter(src, conv);
	
	gst_bin_add_many(GST_BIN(pipeline), src, conv, sink, NULL);

	if(!gst_element_link_many(src, conv, sink, NULL)){
		g_error("Failed to link elements.\n");
		return -2;
	}

	bus = gst_pipeline_get_bus(GST_PIPELINE (pipeline));

	gst_bus_add_signal_watch(bus);

	g_signal_connect(G_OBJECT(bus), "message", G_CALLBACK(message_cb), NULL);

	gst_object_unref(GST_OBJECT(bus));

	gst_element_set_state(pipeline, GST_STATE_PLAYING);

	g_print("Starting loop.\n");

	g_main_loop_run(loop);

	return 0;
}

but this code not work. when execute this code, can't working filter and
some warning messages.

and then play no filter v4l2src media.

warning message is 
"Gstreamer-CRITICAL **: gst_element_link_pads_filtered: assertion
'GST_IS_BIN' (parent) failed'
"WARNING **: Failed to link e1 and e2."

I know second message's reason, but I don't understand first message.

Please help me.




--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/


More information about the gstreamer-devel mailing list