}
//
// Construct a pipeline: filesrc ! OutputStreamSink
//
Pipeline inputPipe = new Pipeline("input pipeline");
Element filesrc = ElementFactory.make("filesrc", "File source");
filesrc.set("location", args[0]);
Element outputstream = new WriteableByteChannelSink(pipeChannel.sink(), "output stream");
inputPipe.addMany(filesrc, outputstream);
Element.linkMany(filesrc, outputstream);
inputPipe.play();
//
// Now construct the output pipeline to process the data
//
Element src = null;
try {
src = new ReadableByteChannelSrc(pipeChannel.source(), "input file");
} catch (Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex);
}
DecodeBin2 decodeBin = (DecodeBin2) ElementFactory.make("decodebin2", "Decode Bin");
Pipeline pipe = new Pipeline("main pipeline");
pipe.addMany(src, decodeBin);
src.link(decodeBin);
/* create audio output */
final Bin audioBin = new Bin("Audio Bin");
Element conv = ElementFactory.make("audioconvert", "Audio Convert");
Element sink = ElementFactory.make("autoaudiosink", "sink");
audioBin.addMany(conv, sink);
Element.linkMany(conv, sink);
audioBin.addPad(new GhostPad("sink", conv.getStaticPad("sink")));
pipe.add(audioBin);
decodeBin.connect(new DecodeBin2.NEW_DECODED_PAD() {
public void newDecodedPad(DecodeBin2 elem, Pad pad, boolean last) {
System.out.println("newDecodedPad");
/* only link once */
Pad audioPad = audioBin.getStaticPad("sink");
if (pad.isLinked()) {
return;
}
/* check media type */
Caps caps = pad.getCaps();
Structure struct = caps.getStructure(0);
if (struct.getName().startsWith("audio/")) {
System.out.println("Got audio pad");
/* link'n'play */
pad.link(audioPad);
}
}
});
Bus bus = pipe.getBus();
bus.connect(new Bus.TAG() {
public void tagsFound(GstObject source, TagList tagList) {
System.out.println("Got TAG event");
for (String tag : tagList.getTagNames()) {
System.out.println("Tag " + tag + " = " + tagList.getValue(tag, 0));
}
}
});
bus.connect(new Bus.ERROR() {
public void errorMessage(GstObject source, int code, String message) {
System.out.println("Error: code=" + code + " message=" + message);
}
});
bus.connect(new Bus.EOS() {
public void endOfStream(GstObject source) {
System.out.println("Got EOS!");
}
});
pipe.play();
Gst.main();
}