forked from phoboslab/jsmpeg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·92 lines (82 loc) · 2.22 KB
/
build.sh
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
#!/bin/sh
# Build the .wasm Module first
# Since we're compiling a side module here, so that we can load it without the
# runtime cruft, we have to explicitly compile in support for malloc and
# friends.
# Note memcpy, memmove and memset are explicitly exported, otherwise they will
# be eliminated by the SIDE_MODULE=2 setting - not sure why that happens.
emcc \
src/wasm/mpeg1.c \
src/wasm/mp2.c \
src/wasm/buffer.c \
$EMSCRIPTEN/system/lib/emmalloc.cpp \
$EMSCRIPTEN/system/lib/libc/musl/src/string/memcpy.c \
$EMSCRIPTEN/system/lib/libc/musl/src/string/memmove.c \
$EMSCRIPTEN/system/lib/libc/musl/src/string/memset.c \
-s WASM=1 \
-s SIDE_MODULE=2 \
-s TOTAL_STACK=5242880\
-s USE_PTHREADS=0 \
-s LEGALIZE_JS_FFI=0\
-s NO_FILESYSTEM=1 \
-s DEFAULT_LIBRARY_FUNCS_TO_INCLUDE="[]" \
-s "EXPORTED_FUNCTIONS=[
'_memcpy',
'_memmove',
'_memset',
'_mpeg1_decoder_create',
'_mpeg1_decoder_destroy',
'_mpeg1_decoder_get_write_ptr',
'_mpeg1_decoder_get_index',
'_mpeg1_decoder_set_index',
'_mpeg1_decoder_did_write',
'_mpeg1_decoder_has_sequence_header',
'_mpeg1_decoder_get_frame_rate',
'_mpeg1_decoder_get_coded_size',
'_mpeg1_decoder_get_width',
'_mpeg1_decoder_get_height',
'_mpeg1_decoder_get_y_ptr',
'_mpeg1_decoder_get_cr_ptr',
'_mpeg1_decoder_get_cb_ptr',
'_mpeg1_decoder_decode',
'_mp2_decoder_create',
'_mp2_decoder_destroy',
'_mp2_decoder_get_write_ptr',
'_mp2_decoder_get_index',
'_mp2_decoder_set_index',
'_mp2_decoder_did_write',
'_mp2_decoder_get_left_channel_ptr',
'_mp2_decoder_get_right_channel_ptr',
'_mp2_decoder_get_sample_rate',
'_mp2_decoder_decode']" \
-O3 \
-o jsmpeg.wasm
# Concat all .js sources
cat \
src/jsmpeg.js \
src/video-element.js \
src/player.js \
src/buffer.js \
src/ajax.js \
src/fetch.js \
src/ajax-progressive.js \
src/websocket.js \
src/ts.js \
src/decoder.js \
src/mpeg1.js \
src/mpeg1-wasm.js \
src/mp2.js \
src/mp2-wasm.js \
src/webgl.js \
src/canvas2d.js \
src/webaudio.js \
src/wasm-module.js \
> jsmpeg.js
# Append the .wasm module to the .js source as base64 string
echo "JSMpeg.WASM_BINARY_INLINED='$(base64 -w 0 jsmpeg.wasm)';" \
>> jsmpeg.js
# Minify
uglifyjs jsmpeg.js -o jsmpeg.min.js
# Cleanup
rm jsmpeg.js
rm jsmpeg.wasm