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
|
imports.gi.versions.GLib = '2.0';
imports.gi.versions.GObject = '2.0';
imports.gi.versions.Gio = '2.0';
imports.gi.versions.Gdk = '3.0';
imports.gi.versions.Gtk = '3.0';
imports.gi.versions.Clutter = '1.0';
imports.gi.versions.Gst = '0.10';
imports.gi.versions.GstBase = '0.10';
imports.gi.versions.GstVideo = '0.10';
const Mainloop = imports.mainloop;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gio = imports.gi.Gio;
const Gdk = imports.gi.Gdk;
const Gtk = imports.gi.Gtk;
const Clutter = imports.gi.Clutter;
const Gst = imports.gi.Gst;
const GstBase = imports.gi.GstBase;
const GstApp = imports.gi.GstApp;
const GstVideo = imports.gi.GstVideo;
function _init() {
Gst.init(null, null);
Gst.debug_set_active(true);
Gst.debug_set_default_threshold(Gst.DebugLevel.WARNING);
Gst.debug_set_colored(false);
let pipeline = Gst.Pipeline.new('my-pipeline');
if (!pipeline) {
throw new Error('could not create pipeline');
}
let bus = pipeline.get_bus();
bus.connect('sync-message',
function(bus, message) {
print (message);
});
bus.connect('message::eos',
function() {
print('end of stream');
Mainloop.quit();
throw new Error('eos');
});
bus.connect('message::error',
function(bus, message) {
let [ error, debug ] = message.parse_error();
printerr('error: ' + error.message);
printerr('debug: ' + debug);
throw new Error('error');
});
let source = Gst.ElementFactory.make('filesrc', 'file-source');
if (!source) {
throw new Error('could not create element of type filesrc');
}
source.location = ARGV[0];
pipeline.add(source);
let demuxer = Gst.ElementFactory.make('oggdemux', 'ogg-demuxer');
if (!demuxer) {
throw new Error('could not create element of type oggdemux');
}
pipeline.add(demuxer);
let decoder = Gst.ElementFactory.make('vorbisdec', 'vorbis-decoder');
if (!decoder) {
throw new Error('could not create element of type vorbisdec');
}
pipeline.add(decoder);
let converter = Gst.ElementFactory.make('audioconvert', 'converter');
if (!converter) {
throw new Error('could not create element of type audioconvert');
}
pipeline.add(converter);
let sink = Gst.ElementFactory.make('autoaudiosink', 'audio-output');
if (!sink) {
throw new Error('could not create element of type autoaudiosink');
}
pipeline.add(sink);
source.link(demuxer);
demuxer.connect('pad-added',
function(element, pad) {
print('a new pad ' + pad.get_name() + ' was created');
let sinkPad = decoder.get_static_pad('sink');
pad.link(sinkPad);
});
decoder.link(converter);
converter.link(sink);
pipeline.set_state(Gst.State.PLAYING);
Mainloop.run('stream');
pipline.set_state(Gst.State.NULL);
}
_init();
|