This repository has been archived by the owner on Oct 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
89 lines (73 loc) · 2.4 KB
/
test.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
var should = require('should');
var fs = require('fs');
var path = require('path');
const { URL } = require('url');
var Mp4BufferProxy = require('./src/mp4-buffer-proxy');
var TEST_SEGMENTS = [
'test-data/hybrid-segments/init.video.mp4',
'test-data/hybrid-segments/media-0.mp4'
];
function toArrayBuffer(buf) {
var ab = new ArrayBuffer(buf.length);
var view = new Uint8Array(ab);
for (var i = 0; i < buf.length; ++i) {
view[i] = buf[i];
}
return ab;
}
function readArrayBufferFromFile(relativePath, arrayBufferCallback) {
var absPath = path.join(__dirname, relativePath);
console.log('reading file:', absPath);
fs.readFile(absPath, (err, data) => {
if (err) throw err;
arrayBufferCallback(toArrayBuffer(data));
});
}
function writeArrayBufferToFile(relativePath, arrayBuffer, successCallback) {
var absPath = path.join(__dirname, relativePath);
console.log('writing file:', absPath);
fs.writeFile(absPath, Buffer.from(arrayBuffer), {
flag: 'w'
}, (err) => {
if (err) throw err;
successCallback();
});
}
function ab2str(buf) {
return String.fromCharCode.apply(null, new Uint8Array(buf));
}
describe('Mp4BufferProxy', function() {
it('should process a segment', function(done) {
var path = TEST_SEGMENTS[0];
readArrayBufferFromFile(path, (arrayBuffer) => {
Mp4BufferProxy.digest(arrayBuffer, function(arrayBufferOutput) {
// TODO: do some validation of output here
writeArrayBufferToFile(path + '.out', arrayBufferOutput, () => {
done();
});
});
});
});
it('should process an init segment (moov)', function(done) {
var path = TEST_SEGMENTS[0];
readArrayBufferFromFile(path, (arrayBuffer) => {
Mp4BufferProxy.digest(arrayBuffer, function(arrayBufferOutput) {
// TODO: do some validation of output here
writeArrayBufferToFile(path + '.out', arrayBufferOutput, () => {
done();
});
});
});
});
it('should process an media fragment segment (moof)', function(done) {
var path = TEST_SEGMENTS[1];
readArrayBufferFromFile(path, (arrayBuffer) => {
Mp4BufferProxy.digest(arrayBuffer, function(arrayBufferOutput) {
// TODO: do some validation of output here
writeArrayBufferToFile(path + '.out', arrayBufferOutput, () => {
done();
});
});
});
});
});