1 /* 2 * gstreamer_helloworld is placed in the 3 * public domain. 4 */ 5 6 module gstreamer_helloworld; 7 8 import std.stdio; 9 10 //gtkD imports: 11 12 import glib.Str; 13 import gtk.Main; 14 15 //gstreamerD imports: 16 17 import gstreamer.GStreamer; 18 19 import gobject.ObjectG; 20 import glib.ErrorG; 21 import gstreamer.Element; 22 import gstreamer.ElementFactory; 23 import gstreamer.Message; 24 import gstreamer.Uri; 25 26 class GstHello 27 { 28 public: 29 30 bool busCall( Message msg ) 31 { 32 debug(gstreamer) 33 { 34 writefln("GstHello.busCall(msg) START."); 35 scope(exit) writefln("GstHello.busCall(msg) END."); 36 } 37 38 switch( msg.type ) 39 { 40 case GstMessageType.UNKNOWN: 41 writefln("Unknown message type."); 42 break; 43 case GstMessageType.EOS: 44 writefln("End-of-stream."); 45 Main.quit(); 46 break; 47 48 case GstMessageType.ERROR: 49 { 50 string dbug; 51 ErrorG err; 52 msg.parseError(err, dbug); 53 //g_free (dbug); 54 writefln("Error: %s dbug: %s", Str.toString(err.getErrorGStruct().message), dbug); 55 Main.quit(); 56 break; 57 } 58 default: 59 break; 60 } 61 62 return true; 63 } 64 65 this(string file) 66 { 67 // create the playbin. 68 playbin = ElementFactory.make("playbin"); 69 70 if( playbin is null ) 71 { 72 throw new Exception("'playbin' gstreamer plugin missing."); 73 } 74 75 // Make sure that file is an URI. 76 if ( !Uri.isValid(file) ) 77 file = Uri.filenameToUri(file); 78 79 playbin.setProperty("uri", file); 80 playbin.getBus().addWatch( &busCall ); 81 82 // Now set to playing and iterate. 83 writefln("Setting to PLAYING."); 84 playbin.setState( GstState.PLAYING ); 85 writefln("Running."); 86 } 87 88 ~this() 89 { 90 playbin.setState( GstState.NULL ); 91 } 92 93 protected: 94 Element playbin; 95 } 96 97 98 int main(string[] args) 99 { 100 writefln("gstreamerD Hello World!"); 101 102 uint major, minor, micro, nano; 103 104 writefln("Trying to init..."); 105 106 //Main.init(args); 107 GStreamer.init(args); 108 109 // check input arguments 110 if (args.length != 2) 111 { 112 writefln("Usage: %s <Ogg/Vorbis filename>", args[0]); 113 114 return -1; 115 } 116 117 writefln("Checking version of GStreamer..."); 118 119 GStreamer.version_(major, minor, micro, nano); 120 121 writefln("The installed version of GStreamer is %s.%s.%s", major, minor, micro ); 122 writefln( "The file is: %s", args[1] ); 123 124 GstHello gstHello = new GstHello( args[1] ); 125 126 //We must use the gtkD mainloop to run gstreamerD apps. 127 Main.run(); 128 129 return 0; 130 }