Advertisement
lepe

vala-gst-demux

Jan 26th, 2012
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 2.49 KB | None | 0 0
  1. using Gtk;
  2. using Gst;
  3.  
  4. public class VideoSample : Window {
  5.  
  6.     private DrawingArea drawing_area;
  7.     private Pipeline pipeline;
  8.     private Element src;
  9.     private Element demux;
  10.     private Element decoder;
  11.     private Element sink;
  12.     private ulong xid;
  13.  
  14.     public VideoSample () {
  15.         create_widgets ();
  16.         setup_gst_pipeline ();
  17.     }
  18.  
  19.     private void create_widgets () {
  20.         var vbox = new Box (Orientation.VERTICAL, 0);
  21.         drawing_area = new DrawingArea ();
  22.         drawing_area.realize.connect(on_realize);
  23.         vbox.pack_start (drawing_area, true, true, 0);
  24.  
  25.         var play_button = new Button.from_stock (Stock.MEDIA_PLAY);
  26.         play_button.clicked.connect (on_play);
  27.         var stop_button = new Button.from_stock (Stock.MEDIA_STOP);
  28.         stop_button.clicked.connect (on_stop);
  29.         var quit_button = new Button.from_stock (Stock.QUIT);
  30.         quit_button.clicked.connect (Gtk.main_quit);
  31.  
  32.         var bb = new ButtonBox (Orientation.HORIZONTAL);
  33.         bb.add (play_button);
  34.         bb.add (stop_button);
  35.         bb.add (quit_button);
  36.         vbox.pack_start (bb, false, true, 0);
  37.  
  38.         add (vbox);
  39.         resize(640,480);
  40.     }
  41.  
  42.     private void setup_gst_pipeline () {
  43.         pipeline = new Pipeline ("mypipeline");
  44.         src = ElementFactory.make ("souphttpsrc", "video");
  45.         src.set("location","http://admin:12345@192.168.1.100/nphMotionJpeg?Resolution=320x240&Quality=Standard&Framerate=1");
  46.         src.set("do-timestamp",1);
  47.         demux = ElementFactory.make ("multipartdemux","demuxer");
  48.         decoder = ElementFactory.make ("jpegdec","jpg");
  49.         sink = ElementFactory.make ("xvimagesink", "sink");
  50.         pipeline.add_many (src, demux, decoder, sink);
  51.         demux.pad_added.connect((ev, pad) => {
  52.            pad.link(decoder.get_pad("sink"));
  53.         });
  54.         src.link (demux);
  55.         decoder.link (sink);
  56.     }
  57.  
  58.     private void on_realize() {
  59.         xid = (ulong)Gdk.X11Window.get_xid(drawing_area.get_window());
  60.     }
  61.  
  62.     private void on_play () {
  63.         var xoverlay = sink as XOverlay;
  64.         xoverlay.set_xwindow_id (xid);
  65.         pipeline.set_state (State.PLAYING);
  66.     }
  67.  
  68.     private void on_stop () {
  69.         pipeline.set_state (State.READY);
  70.     }
  71.  
  72.     public static int main (string[] args) {
  73.         Gst.init (ref args);
  74.         Gtk.init (ref args);
  75.  
  76.         var sample = new VideoSample ();
  77.         sample.show_all ();
  78.  
  79.         Gtk.main ();
  80.  
  81.         return 0;
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement