hello,

the attached .vala file causes valac to segfault during compilation (it
used to compile fine with 0.5.4). 

Make check passes all 27 tests, and valac can compile itself, so it
shouldn't be a problem with my installation, but if someone could check
to make sure...

Thanks
alberto

PS: requires gstreamer-devel installed

        valac --pkg gstreamer-0.10 gst-app.vala
using Gst, GLib;

// compile with:
// valac --pkg gstreamer-0.10 gst-app.vala

class Gstapp : GLib.Object
{
    MainLoop loop = new MainLoop(null, false);
    Bin pipeline;
    Bin decoder;
    Element sink;
    Element filter;

    private bool bus_watch(Bus bus, Message message)
    {
        //stdout.printf("Got %s message", Message.type_get_name(message.type));
        switch (message.type)
        {
            case MessageType.ERROR:
            {
                Error err;
                string debug;
                message.parse_error(out err, out debug);
                stdout.printf("Error: %s\n", err.message);
                loop.quit();
                break;
            }
            case MessageType.EOS:
            {
                loop.quit();
                break;
            }
            default: break;
        }
        //stdout.putc('\n');
        return true;
    }

    private void on_new_pad(Pad pad)
    {
        Pad sinkpad = sink.get_pad("sink");
        if (pad.can_link(sinkpad)) pad.link(sinkpad);
    }

	public int run(string[] args)
	{
	    Gst.init(ref args);
	    if (args.length != 2)
	    {
	        stdout.printf("usage: %s FILE\n", args[0]);
	        return 1;
        }
        string location = args[1];
        pipeline = new Pipeline("pipeline");
        decoder = (Bin)ElementFactory.make("decodebin", "decoder");
        Signal.connect_swapped(decoder, "new-decoded-pad", (Callback)on_new_pad, this);
        dynamic Element source = ElementFactory.make("filesrc", "source");
        source.location = location;
        sink = ElementFactory.make("autovideosink", "sink");
        filter = new MyTransform(); 
        filter.name = "filter";
        var colorspace = ElementFactory.make("ffmpegcolorspace", "colorspace");
        pipeline.add_many(source, decoder, colorspace, filter, sink);
        source.link(decoder);
        colorspace.link(sink);
        sink = colorspace;
        pipeline.get_bus().add_watch(bus_watch);
		pipeline.set_state(State.PLAYING);
		loop.run();
		pipeline.set_state(State.NULL);
		return 0;
	}
	
	public static int main(string[] args)
	{
	    var app = new Gstapp();
	    return app.run(args);
	}
}

class MyTransform: Element
{
    static const ElementDetails details = {
        "My Transform",
        "Example/FirstExample",
        "Try to make a plugin using Vala",
        "alberto <[email protected]>"
    };
	
    static const StaticPadTemplate sink_factory =  {
        "sink", PadDirection.SINK, PadPresence.ALWAYS, {"ANY"}
    };
    
    static const StaticPadTemplate src_factory =  {
        "src", PadDirection.SRC, PadPresence.ALWAYS, {"ANY"}
    };
    
    class construct
    {
        set_details(details);
        add_pad_template(src_factory.get());
        add_pad_template(sink_factory.get());        
    }
    
}

/*
    // from bus callback
            case MessageType.TAG:
            {
		        TagList taglist;
		        message.parse_tag(out taglist);
		        // generates a warning in the C sources		        
		        taglist.foreach( (list, tag) => {
	                string val, niceval;
	                if (list.get_string(tag, out val))
	                    niceval = " = \""+val+"\"";
                    else
                        niceval = "";
		            stdout.printf(": %s%s", tag, niceval);
	            });      
	            break;      
            }
            case MessageType.ELEMENT:
            {
                Structure s = message.get_structure();
                // generates a warning in the C sources
                s.foreach( (field_id, val) => {
                    stdout.printf("\tfield %s\n", field_id.to_string());
                    return true;
                });                
                break;
            }
            case MessageType.STATE_CHANGED:
            {
                State oldstate, newstate, pending;
		        message.parse_state_changed(out oldstate, out newstate, out pending);
                stdout.printf(": %d -> %d (%d)", (int)oldstate, (int)newstate, (int)pending);
                break;
            }
    


    // MUST be static, otherwise valac will silently omit them in the C sources... 
    static string? vfs_location;
    static string? rtsp_location;
    static string? file_location;
    const OptionEntry[] entries = {
            {"vfs", 'v', 0, OptionArg.STRING, out vfs_location, 
            "play video from URI", "URI"},
            {"rtsp", 'r', 0, OptionArg.STRING, out rtsp_location,
            "play RTSP stream", "RTSP"},
            {"file", 'f', 0, OptionArg.FILENAME, out file_location,
            "play video from FILE", "FILE"},
            {null}
        };


        OptionContext ctx = new OptionContext(" -- play video from file or RTSP");
        OptionGroup gstgroup = Gst.init_get_option_group();
        ctx.add_main_entries(entries, null);
        ctx.add_group(#gstgroup);
        Element source;
        try
        {
            GLib.Object src;
            ctx.parse(ref args);
            if (rtsp_location != null)
            {
                src = ElementFactory.make("rtspsrc", "source");
                src.set("location", rtsp_location);
            }
            else if (vfs_location != null)
            {
                src = ElementFactory.make("gnomevfssrc", "source");
                src.set("location", vfs_location);
            }
            else if (file_location != null)
            {
                src = ElementFactory.make("filesrc", "source");
                src.set("location", file_location);
            }
            else
            {
                stdout.printf("%s", ctx.get_help(true, null));
                throw new OptionError.FAILED("please specify a file/uri to play");
            }
            assert(src != null);
            source = (Element)src;
        }
        catch (OptionError e)
        {
            stdout.printf("Error: %s\n\n", e.message);
            return 1;
        }
*/
_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to