Here is my attempt to translate the GStreamer Plugin Writer's Guide's
example.

It is almost a one-to-one translation.


Unfortunately you have to change the gstreamer vapi file in order to
compile this.

In particular you have to replace the line "public Gst.Caps proxy_getcaps 
(Gst.Pad pad);" with "public Gst.Caps proxy_getcaps ();".

Giulio.


Il 11/04/2011 17:09, Jordi Burguet Castell ha scritto:

> Excellent! I was missing the "class construct" syntax. Very nice
> examples, thanks to you both!
> Jordi
>
>
> On Mon, Apr 11, 2011 at 8:26 AM, Sandino Flores Moreno <[email protected]> 
> wrote:
>   
>> Here is another example:
>>
>> https://github.com/tigrux/gst-plugin-omap4videodecbin/blob/master/gst/gstomap4videodecbin.vala
>>
>> On Mon, Apr 11, 2011 at 3:28 AM, Thijs Vermeir <[email protected]> 
>> wrote:
>>     
>>> Hey,
>>>
>>> On Sun, Apr 10, 2011 at 10:27 PM, Jordi Burguet Castell
>>> <[email protected]> wrote:
>>>       
>>>> Hello,
>>>>
>>>> Has anyone tried to do a gstreamer *element* in vala? It sounds to me
>>>> like it would be worth because of the more succinct syntax, but I
>>>> could not figure out how to put the element and pads description in
>>>> the base_init() funtion (apart from putting the properties in the
>>>> class_init() and then doing the real initialization in the init()
>>>> functions).
>>>>
>>>> The only related documentation I've found is:
>>>> http://valadoc.org/references/gstreamer-0.10/0.11.5/index.htm
>>>> but nothing about how to put things in base_init()
>>>>
>>>> And also how to make a pipeline using gstreamer elements:
>>>> http://live.gnome.org/Vala/GStreamerSample
>>>> but not how to do the elements themselves.
>>>>         
>>> Yes, it's possible and not so difficult to write gstreamer elements in vala.
>>> Check this link for an example, it's an old link but I think the code
>>> is still valid:
>>> http://bazaar.launchpad.net/~asabil/vala/gst-vala-template/view/head:/src/vala-sink.vala
>>>
>>> Gr,
>>> Thijs
>>>
>>>       
>>>> Thanks,
>>>> Jordi
>>>> _______________________________________________
>>>> vala-list mailing list
>>>> [email protected]
>>>> http://mail.gnome.org/mailman/listinfo/vala-list
>>>>
>>>>         
>>> _______________________________________________
>>> vala-list mailing list
>>> [email protected]
>>> http://mail.gnome.org/mailman/listinfo/vala-list
>>>
>>>       
>>     
> _______________________________________________
> vala-list mailing list
> [email protected]
> http://mail.gnome.org/mailman/listinfo/vala-list
>
>
>   

using Gst;

//Compile with: valac gst_my_filter.vala --pkg gstreamer-0.10 -C -H gst_my_filter.h ; gcc gst_my_filter.c -shared -fPIC -o tmp.so $(pkg-config --cflags gstreamer-0.10) -DPACKAGE="\"plugin\"" -DVERSION="\"01\""

[CCode (lower_case_cprefix = "")]
namespace Macros
{
	extern const string VERSION;
	extern const string PACKAGE;
}

private static bool plugin_init(Gst.Plugin plugin)
{
 	return Gst.Element.register(plugin, "myfilter", Gst.Rank.SECONDARY, typeof(Gst.MyFilter));
}

public const Gst.PluginDesc gst_plugin_desc = {
    Gst.VERSION_MAJOR, Gst.VERSION_MINOR,
 	"myfilterplugin",
 	"My filter plugin",
 	plugin_init,
 	Macros.VERSION,
 	"LGPL",
    Macros.PACKAGE,
 	"GStreamer",
 	"http://gstreamer.net/";
};

public class Gst.MyFilter : Gst.Element {
	private static Gst.StaticPadTemplate sinktempl;
	private static Gst.StaticPadTemplate srctempl;
	class construct
	{
		sinktempl = Gst.StaticPadTemplate() { name_template = "sink", direction = Gst.PadDirection.SINK, presence = Gst.PadPresence.ALWAYS, static_caps = { "ANY" } };
		srctempl = Gst.StaticPadTemplate() { name_template = "src", direction = Gst.PadDirection.SRC, presence = Gst.PadPresence.ALWAYS, static_caps = { "ANY" } };
		// set the plugin information
		set_details_simple("My filter plugin in vala", "audio/filters", "A good filter plugin, described here", "Author <[email protected]>");

		// create and add the sink template
		add_pad_template(sinktempl.get());

		// create and add the src template
		add_pad_template(srctempl.get());
	}
	construct
	{
		this.sinkpad = new Gst.Pad.from_static_template (sinktempl, "sink");
		this.sinkpad.set_setcaps_function(Gst.MyFilter.set_caps);
		this.sinkpad.set_getcaps_function(Gst.Pad.proxy_getcaps);
		this.sinkpad.set_chain_function(Gst.MyFilter.chain);

		this.srcpad =  new Gst.Pad.from_static_template (srctempl, "src");
		this.srcpad.set_getcaps_function(Gst.Pad.proxy_getcaps);

		this.add_pad(this.srcpad);
		this.add_pad(this.sinkpad);
		this.silent = false;
	}

	[Description(nick = "verbose", blurb = "If the filter should be verbose.")]
    public bool silent { get; set; default = false; }

	public Gst.Pad sinkpad;
	public Gst.Pad srcpad;

	private static bool set_caps(Gst.Pad pad, Gst.Caps caps)
	{
		Gst.MyFilter filter = (Gst.MyFilter) pad.get_parent();
		/* When requested for some caps to an end (i.e., output/input), request the same caps as at the other end (i.e., input/output), so that we can just forward incoming buffers without touching them (look at chain function) */
		if(pad == filter.srcpad)
		{
			return filter.sinkpad.set_caps(caps);
		}
		else
		{
			return filter.srcpad.set_caps(caps);
		}
	}

	private static Gst.FlowReturn chain(Gst.Pad pad, owned Gst.Buffer buf)
	{
		Gst.MyFilter filter = (Gst.MyFilter) pad.get_parent();
		if(filter.silent == false)
		{
			stderr.printf("I'm plugged, therefore I'm in.\n");
		}
		/* just push out the incoming buffer without touching it */
		return filter.srcpad.push (buf);
	}
}
_______________________________________________
vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to