Skip to content

Instantly share code, notes, and snippets.

@eagsalazar
Created July 18, 2010 00:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eagsalazar/479975 to your computer and use it in GitHub Desktop.
Save eagsalazar/479975 to your computer and use it in GitHub Desktop.
using Gtk;
using Gst;
public class VideoSample : Window {
private DrawingArea drawing_area;
private Pipeline pipeline;
private Element src;
private Element sink;
private Element decode;
private Element colorspace;
public VideoSample() {
create_widgets();
setup_gst_pipeline();
}
private void create_widgets() {
var vbox = new VBox(false, 0);
this.drawing_area = new DrawingArea();
this.drawing_area.set_size_request(300, 150);
vbox.pack_start(this.drawing_area, true, true, 0);
var play_button = new Button.from_stock(STOCK_MEDIA_PLAY);
play_button.clicked.connect(on_play);
var stop_button = new Button.from_stock(STOCK_MEDIA_STOP);
stop_button.clicked.connect(on_stop);
var quit_button = new Button.from_stock(STOCK_QUIT);
quit_button.clicked.connect(Gtk.main_quit);
var bb = new HButtonBox();
bb.add(play_button);
bb.add(stop_button);
bb.add(quit_button);
vbox.pack_start(bb, false, true, 0);
add(vbox);
}
private void on_play() {
stdout.printf("on_play()\n");
var xoverlay = this.sink as XOverlay;
xoverlay.set_xwindow_id (Gdk.x11_drawable_get_xid (this.drawing_area.window));
this.pipeline.set_state(State.PLAYING);
}
private void on_stop() {
this.pipeline.set_state(State.READY);
}
public static int main(string[] args) {
Gst.init (ref args);
Gtk.init(ref args);
var sample = new VideoSample();
sample.show_all();
Gtk.main();
return 0;
}
private void setup_gst_pipeline() {
this.pipeline = new Pipeline ("mypipeline");
this.src = ElementFactory.make("filesrc", "filesrc");
this.decode = ElementFactory.make("decodebin", "decode");
this.colorspace = ElementFactory.make("ffmpegcolorspace", "colorspace");
this.sink = ElementFactory.make ("xvimagesink", "sink");
src.set_property("location", "/home/esalazar/backlot/Rendezvous.avi");
decode.pad_added.connect(onDynamicLoad);
pipeline.add_many(src, decode, colorspace, sink);
pipeline.link_many(src, decode);
pipeline.link_many(colorspace, sink);
}
private void onDynamicLoad(Pad pad)
{
stdout.printf("!!Connecting pad!!\n");
pad.link(colorspace.get_pad("sink"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment