2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * gstreamerD helloworld.
34 import gstreamer
.gstreamer
;
36 import gobject
.ObjectG
;
37 import gstreamer
.Element
;
38 import gstreamer
.Pipeline
;
39 import gstreamer
.ElementFactory
;
41 import gstreamer
.Message
;
44 import gstreamerc
.gstreamertypes
;
45 import gstreamerc
.gstreamer
;
54 bool busCall( Message msg
)
56 debug(gstreamer
) writefln("GstHello.busCall(msg) START.");
57 debug(gstreamer
) scope(exit
) writefln("GstHello.busCall(msg) END.");
61 case GstMessageType
.UNKNOWN
:
62 writefln("Unknown message type.");
64 case GstMessageType
.EOS
:
65 writefln("End-of-stream.");
69 case GstMessageType
.ERROR
:
73 msg
.parseError(&err
, &dbug
);
75 writefln("Error: %s\n", err
.message
);
92 pipeline
= new Pipeline("audio-player");
94 source
= ElementFactory
.make("filesrc", "file-source");
95 parser
= ElementFactory
.make("oggdemux", "ogg-parser");
96 decoder
= ElementFactory
.make("vorbisdec", "vorbis-decoder");
97 conv
= ElementFactory
.make("audioconvert", "converter");
98 sink
= ElementFactory
.make("alsasink", "alsa-output");
100 if( pipeline
is null || source
is null || parser
is null || decoder
is null || conv
is null || sink
is null )
102 writefln("One or more element could not be created");
103 if( pipeline
is null ) writefln(" : no pipeline.");
104 if( source
is null ) writefln(" : no source.");
105 if( parser
is null ) writefln(" : no parser.");
106 if( decoder
is null ) writefln(" : no decoder.");
107 if( conv
is null ) writefln(" : no conv.");
108 if( sink
is null ) writefln(" : no sink.");
110 throw new Exception("One or more gstreamerD elements could not be created.");
113 // set filename property on the file source. Also add a message handler.
115 source
.location( file
); //You can also use this like a D property: source.location = file;
116 //Or you can also do: source.setProperty("location", file);
118 pipeline
.getBus().addWatch( &busCall
);
120 // put all elements in a bin
122 //shouldbe, but doesn't work yet:
123 //pipeline.addMany( source, parser, decoder, conv, sink );
124 //TODO, add variable number of arguments (...) support to GtkWrapper
125 pipeline
.add( source
);
126 pipeline
.add( parser
);
127 pipeline
.add( decoder
);
128 pipeline
.add( conv
);
129 pipeline
.add( sink
);
131 // link together - note that we cannot link the parser and
132 // decoder yet, because the parser uses dynamic pads. For that,
133 // we set a pad-added signal handler.
134 source
.link( parser
);
136 //shouldbe, but doesn't work yet:
137 //decoder.linkMany( conv, sink );
138 decoder
.link( conv
);
140 parser
.addOnPadAdded(&newPad
);
142 // Now set to playing and iterate.
143 writefln("Setting to PLAYING.");
144 pipeline
.setState( GstState
.PLAYING
);
145 writefln("Running.");
150 pipeline
.setState( GstState
.NULL
);
153 void newPad( Pad pad
, Element element
)
155 writefln("newPad callback called. START.");
158 // We can now link this pad with the audio decoder
159 writefln("Dynamic pad created, linking parser/decoder");
161 sinkpad
= decoder
.getPad("sink");
162 writefln("doing a gst_pad_link.");
164 writefln("Done. That was ok.");
171 Element source
, parser
, decoder
, conv
, sink
;
175 int main(char[][] args
)
177 writefln("gstreamerD Hello World!");
179 uint major
, minor
, micro
, nano
;
181 writefln("Trying to init...");
184 GStreamer
.init(args
);
186 // check input arguments
187 if (args
.length
!= 2)
189 writefln("Usage: %s <Ogg/Vorbis filename>\n", args
[0]);
193 writefln("Checking version of GStreamer...");
194 GStreamer
.versio(&major
, &minor
, µ
, &nano
);
195 writefln("This program is linked against GStreamer ", major
, ".", minor
, ".", micro
);
197 writefln( "The file is: ", args
[1] );
198 GstHello gstHello
= new GstHello( args
[1] );
200 //We must use the gtkD mainloop to run gstreamerD apps.