-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.html
186 lines (166 loc) · 5.13 KB
/
index.html
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<html>
<head>
<title>bsparser</title>
</head>
<style type='text/css'>
* {
font-family: monospace;
}
pre {
margin: 0 0;
}
</style>
<body>
<div style='height: 0px;width: 0px; overflow:hidden;'>
<input type='file' id='files'>
</div>
<div id='menu'></div>
<pre id='content'></pre>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js'></script>
<script src='./parser.js'></script>
<script>
var g_ctx = {
'fmt': null,
'parser': null,
'file': null,
'file_length': 0,
'file_pos': 0,
'max_num_headers': 300,
'num_headers': 0,
};
function padstr(x, length, padding, after) {
if (x.length > length)
return x.slice(0, length);
var pad = Array(length - x.length + 1).join(padding);
return after ? x + pad : pad + x;
}
function tostr(x, base, length, padding) {
var str = x.toString(base);
return padstr(str, length, padding, false);
}
function add(h) {
if (!($('#content').is(':parent'))) {
var e = '<span>'
+ padstr('Frame', 5, ' ', false)
+ padstr('Offset', 10, ' ', false)
+ padstr('Length', 10, ' ', false)
+ padstr('Type', 25, ' ', false);
if (g_ctx.fmt == 'ivf') {
e += padstr('Timestamp', 12, ' ', false);
}
e += '</span><br>';
$('#content').append(e);
}
var str;
if ('@type' in h) {
str = ('@frame_num' in h ? tostr(h['@frame_num'], 10, 5, ' ') : ' ')
+ padstr(tostr(h['@addr'], 16, 8, '0'), 10, ' ', false)
+ tostr(h['@length'], 10, 10, ' ')
+ padstr(h['@type'], 25, ' ', false);
if (g_ctx.fmt == 'ivf') {
str += ('@ts' in h) ?
tostr(h['@ts'], 10, 12, ' ') : padstr(' ', 12, ' ', false);
}
if ('@extra' in h) {
str += ' ' + h['@extra'];
}
} else if ('@error' in h) {
str = h['@error'];
} else {
alert('Unknown format of header.');
return;
}
var $elem = $('<span>', { id: 'h' + h['@id'], text: str });
if ((h['@keyframe'] || 0) || (h['@type'] || 0) == 'I') {
$elem.attr('style', 'color:red');
} else if ('@error' in h) {
$elem.attr('style', 'background-color:red');
}
$('#content').append($elem);
$('#content').append('<br>');
++g_ctx.num_headers;
}
function parse() {
while (g_ctx.file_pos < g_ctx.file_length) {
var buffer = new Uint8Array(g_ctx.file_data.slice(g_ctx.file_pos,
g_ctx.file_pos + Math.min(1024, g_ctx.file_length - g_ctx.file_pos)));
g_ctx.file_pos += buffer.length;
g_ctx.parser.parse(buffer);
if (g_ctx.file_pos >= g_ctx.file_length) {
g_ctx.parser.parse(null);
}
while (1) {
var h = g_ctx.parser.next();
if (h == null) break;
add(h);
}
if (g_ctx.num_headers >= g_ctx.max_num_headers)
break;
}
}
function open(file) {
var fr = new FileReader();
fr.onloadend = (function (file) {
return function (evt) {
if (evt.target.readyState == FileReader.DONE) {
g_ctx.fmt = file.name.toLowerCase().split('.').pop();
g_ctx.parser = create_parser(g_ctx.fmt);
if (g_ctx.parser == null)
return;
g_ctx.file_data = evt.target.result;
g_ctx.file_length = evt.target.result.byteLength;
parse();
}
}
})(file);
fr.readAsArrayBuffer(file);
}
$('#files').change(function (e) {
$('#open').remove();
open(e.target.files[0]);
});
$(document).scroll(function () {
if (document.body.scrollHeight * 0.95 <
document.body.scrollTop + window.innerHeight) {
if (g_ctx.file_pos < g_ctx.file_length) {
g_ctx.max_num_headers += 100;
parse();
}
}
});
$(document).ready(function () {
var $open = $('<button>', { text: 'Open' });
$open.click(function () {
$('#files').trigger('click');
});
$('#menu').append($open);
$('#content').click(function (evt) {
var id = evt.target.id;
if (id) {
if (id.substring(0, 1) == 'h') {
var next = $(evt.target).next('span');
if (next.length && next[0].id && next[0].id.substring(0, 1) == 'c') {
// Hide content on second click.
$(next[0]).remove();
} else {
id = parseInt(id.substring(1, id.length));
var h = g_ctx.parser.get(id);
var elem = '<span id=\'c' + id + '\' style=\'color:gray\'>';
for (var k in h) {
var startswith = k.substring(0, 1);
if (startswith != '@' && startswith != '#') {
console.log(k, h[k]);
elem += '<br><span> ' + padstr(k, 50, ' ', 1)
+ h[k] + '</span>';
}
}
elem += '</span>';
$(event.target).after(elem);
}
}
}
});
});
</script>
</body>
</html>