-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtest.js
128 lines (113 loc) · 2.76 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
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
var tape = require('tape')
var mp4 = require('./')
tape('all boxes are decoded', function (t) {
var encode = mp4.encode()
var decode = mp4.decode()
var count = 0
decode.on('box', function () {
if (count === 0) {
decode.decode(function () { })
} else if (count === 1) {
decode.stream().on('data', function () { })
} else {
decode.ignore()
}
count++
})
decode.on('finish', function () {
t.same(count, 4)
t.end()
})
for (let i = 0; i < 4; i++) {
encode.box({
type: 'ftyp',
brand: 'mafi',
brandVersion: 1
})
}
encode.finalize()
encode.pipe(decode)
})
tape('generates and parses', function (t) {
var encode = mp4.encode()
var decode = mp4.decode()
decode.on('box', function (headers) {
if (headers.type === 'ftyp') {
decode.decode(function (box) {
t.same(box.type, 'ftyp')
t.same(box.brand, 'mafi')
t.same(box.brandVersion, 1)
})
} else if (headers.type === 'mdat') {
t.same(headers.type, 'mdat')
t.same(headers.length, 8 + 11)
var buffer = []
var stream = decode.stream()
stream.on('data', function (data) {
buffer.push(data)
})
stream.on('end', function () {
t.same(Buffer.concat(buffer).toString(), 'hello world')
t.end()
})
} else {
t.fail('unexpected box')
}
})
encode.box({
type: 'ftyp',
brand: 'mafi',
brandVersion: 1
})
var stream = encode.mediaData(11)
stream.end('hello world')
encode.finalize()
encode.pipe(decode)
})
tape('generates and parses with decoder/encoder in between', function (t) {
var encode = mp4.encode()
var decode = mp4.decode()
var encode2 = mp4.encode()
var decode2 = mp4.decode()
decode.on('box', function (headers) {
if (headers.type === 'ftyp') {
decode.decode(function (box) {
t.same(box.type, 'ftyp')
t.same(box.brand, 'mafi')
t.same(box.brandVersion, 1)
})
} else if (headers.type === 'mdat') {
t.same(headers.type, 'mdat')
t.same(headers.length, 8 + 11)
var buffer = []
var stream = decode.stream()
stream.on('data', function (data) {
buffer.push(data)
})
stream.on('end', function () {
t.same(Buffer.concat(buffer).toString(), 'hello world')
t.end()
})
} else {
t.fail('unexpected box')
}
})
encode.box({
type: 'ftyp',
brand: 'mafi',
brandVersion: 1
})
var stream = encode.mediaData(11)
stream.end('hello world')
encode.finalize()
encode.pipe(decode2)
decode2.on('box', function (headers) {
decode2.decode(function (box) {
encode2.box(box)
})
})
decode2.on('end', function () {
encode2.finalize()
})
encode2.pipe(decode)
})