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