-
Notifications
You must be signed in to change notification settings - Fork 27
/
vlc.js
158 lines (131 loc) · 3.56 KB
/
vlc.js
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
var os = require('os');
var path = require('path');
var FFI = require('ffi');
var ref = require('ref');
var LIBRARY_PATHS = [];
switch (os.platform()) {
case 'darwin':
LIBRARY_PATHS.push('/Applications/VLC.app/Contents/MacOS/lib/libvlc.dylib');
LIBRARY_PATHS.push(path.join(process.env.HOME, 'Applications/VLC.app/Contents/MacOS/lib/libvlc.dylib'));
break;
case 'win32':
if (process.env['ProgramFiles(x86)']) {
LIBRARY_PATHS.push(path.join('',
process.env['ProgramFiles(x86)'],
'VideoLAN',
'VLC',
'libvlc.dll'
));
}
LIBRARY_PATHS.push(path.join(
process.env['ProgramFiles'],
'VideoLAN',
'VLC',
'libvlc.dll'
));
break;
default:
LIBRARY_PATHS.push('/usr/lib/libvlc.so');
LIBRARY_PATHS.push('/usr/lib/libvlc.so.5');
break;
}
exports.LIBRARY_PATHS = LIBRARY_PATHS;
var lib, MediaPlayer, Media, VLM;
var VLC = function (args) {
if (!(this instanceof VLC)) {
return new VLC(args);
}
if (!lib) {
lib = require('./lib/libvlc').initialize(LIBRARY_PATHS);
MediaPlayer = require('./lib/mediaplayer');
Media = require('./lib/media');
VLM = require('./lib/vlm');
}
var mediaplayer, vlm;
var released = false;
var cargs = new Buffer(ref.sizeof.pointer * args.length);
for (var i = 0; i < args.length; i++) {
cargs.writePointer(ref.allocCString(args[i]), i * ref.sizeof.pointer);
}
instance = lib.libvlc_new(args.length, cargs);
Object.defineProperty(this, 'mediaplayer', {
get: function () {
if (!mediaplayer) {
mediaplayer = new MediaPlayer(instance);
}
return mediaplayer;
},
});
Object.defineProperty(this, 'vlm', {
get: function () {
if (!vlm) {
vlm = new VLM(instance);
}
return vlm;
},
});
this.release = function () {
if (!released) {
if (mediaplayer) {
mediaplayer.release();
}
if (vlm) {
vlm.release();
}
lib.libvlc_release(instance);
released = true;
}
};
this.mediaFromFile = function (path) {
return new Media(instance, undefined, { path: path });
};
this.mediaFromUrl = function(url){
return new Media(instance, undefined, { url: url });
};
this.mediaFromFd = function(fd){
return new Media(instance, undefined, { fd: fd });
};
this.mediaFromNode = function(node){
return new Media(instance, undefined, node);
};
this.mediaFields = require('./lib/media_enum').metaEnum;
Object.defineProperty(this, 'audio_filters', {
get: function() {
var ret = [], tmp, start;
start = tmp = lib.libvlc_audio_filter_list_get(instance);
while (!tmp.isNull()) {
tmp = tmp.deref();
ret.push({
name: tmp.psz_name,
shortname: tmp.psz_shortname,
longname: tmp.psz_longname,
help: tmp.psz_help,
});
tmp = tmp.p_next;
}
if (!start.isNull())
lib.libvlc_module_description_list_release(start);
return ret;
},
});
Object.defineProperty(this, 'video_filters', {
get: function() {
var ret = [], tmp, start;
start = tmp = lib.libvlc_video_filter_list_get(instance);
while (!tmp.isNull()) {
tmp = tmp.deref();
ret.push({
name: tmp.psz_name,
shortname: tmp.psz_shortname,
longname: tmp.psz_longname,
help: tmp.psz_help,
});
tmp = tmp.p_next;
}
if (!start.isNull())
lib.libvlc_module_description_list_release(start);
return ret;
},
});
};
module.exports = VLC;