Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the build.sh file with a makefile #291

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
### Project ###
build/

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*
77 changes: 73 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ var player = new JSMpeg.Player('video.ts' {loop: true, autoplay: true});

or HTML
```html
<div class="jsmpeg" data-url="video.ts"
<div class="jsmpeg" data-url="video.ts"
data-loop="true" data-autoplay="true"></div>
```

Expand Down Expand Up @@ -185,7 +185,7 @@ ffmpeg \
http://localhost:8081/supersecret
```

You should now see a live webcam image in your browser.
You should now see a live webcam image in your browser.

If ffmpeg failed to open the input video, it's likely that your webcam does not support the given resolution, format or framerate. To get a list of compatible modes run:

Expand Down Expand Up @@ -245,9 +245,78 @@ Have a look a the [jsmpeg.js source](https://github.com/phoboslab/jsmpeg/blob/ma

Using parts of the library without creating a full player should also be fairly straightforward. E.g. you can create a stand-alone instance of the `JSMpeg.Decoder.MPEG1Video` class, `.connect()` a renderer, `.write()` some data to it and `.decode()` a frame, without touching JSMpeg's other parts.

## Building yourself
In case of you needs build youself or debug your application.

### Prerequisites
- GNU make (search for your platform);
- Emscripten EMCC (See the installation instructions in [download and install page](https://emscripten.org/docs/getting_started/downloads.html#download-and-install));
- GNU base64 (search for your platform);
- NODE uglifyjs (search for your platform)

### Building
```bash
# Change to jsmpeg directory
$ cd to/jsmpeg/dir
# Run the make
$ make
```
> The output files will be generated in `build/` directory.

## Previous Version
### Make options
Build the `jsmpeg.min.js` file:
```bash
$ make jsmpeg.min.js
```

The JSMpeg version currently living in this repo is a complete rewrite of the original jsmpeg library that was just able to decode raw mpeg1video. If you're looking for the old version, see the [v0.2 tag](https://github.com/phoboslab/jsmpeg/releases/tag/v0.2).
Build the `jsmpeg.js` file:
```bash
$ make jsmpeg.js
```
Build the `jsmpeg.wasm.js` file:
```bash
$ make jsmpeg.wasm.js
```

Build the `jsmpeg.wasm` file:
```bash
$ make jsmpeg.wasm
```

To clean the `build/` directory:
```bash
$ make clean
```

### Loading the JS files individually
To load the JS files individually, put the `<script>` tags in oder inside the `<body>` tag, like:
```html
<body>
<!-- ... -->
<script type="text/javascript" src="src/jsmpeg.js"></script>
<script type="text/javascript" src="src/video-element.js"></script>
<script type="text/javascript" src="src/player.js"></script>
<script type="text/javascript" src="src/buffer.js"></script>
<script type="text/javascript" src="src/ajax.js"></script>
<script type="text/javascript" src="src/ajax-progressive.js"></script>
<script type="text/javascript" src="src/websocket.js"></script>
<script type="text/javascript" src="src/ts.js"></script>
<script type="text/javascript" src="src/decoder.js"></script>
<script type="text/javascript" src="src/mpeg1.js"></script>
<script type="text/javascript" src="src/mpeg1-wasm.js"></script>
<script type="text/javascript" src="src/mp2.js"></script>
<script type="text/javascript" src="src/mp2-wasm.js"></script>
<script type="text/javascript" src="src/webgl.js"></script>
<script type="text/javascript" src="src/canvas2d.js"></script>
<script type="text/javascript" src="src/webaudio.js"></script>
<script type="text/javascript" src="src/wasm-module.js"></script>
<script type="text/javascript" src="build/jsmpeg.wasm.js"></script>
<!-- ... -->
<body>
```
> Don't forguet to build the `jsmpeg.wasm.js` file.


## Previous Version

The JSMpeg version currently living in this repo is a complete rewrite of the original jsmpeg library that was just able to decode raw mpeg1video. If you're looking for the old version, see the [v0.2 tag](https://github.com/phoboslab/jsmpeg/releases/tag/v0.2).
91 changes: 0 additions & 91 deletions build.sh

This file was deleted.

96 changes: 96 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# General settings
PROJECT_NAME = jsmpeg
SRC_DIR = src
WASM_SRC_DIR = $(SRC_DIR)/wasm
BUILD_DIR = build

# Javascript source files setup
JS_SRC_FILES = src/jsmpeg.js src/video-element.js src/player.js src/buffer.js \
src/ajax.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

# WASM source files setup
WASM_SRC_FILES = $(shell find $(WASM_SRC_DIR) -type f \( -name "*.c" \) )

# Tools setup
MINJS = uglifyjs
B64 = base64
B64FLAGS = -w 0

# Emscripten Compiler setup
WASMCC = emcc
EMCCROOT = ${EMSCRIPTEN}
WASMCCFLAGS = -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="[]"
WASMCCEXTRAFLAGS = -O3

#EMCC core library files will be used
WASM_EMCC_FILES = system/lib/emmalloc.cpp \
system/lib/libc/musl/src/string/memcpy.c \
system/lib/libc/musl/src/string/memmove.c \
system/lib/libc/musl/src/string/memset.c
WASM_EMCC_FILES := $(addprefix $(EMCCROOT)/, $(WASM_EMCC_FILES))

# Functions that will be used
WASM_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

WASM_FUNCTIONS := "EXPORTED_FUNCTIONS=[$(foreach i,$(WASM_FUNCTIONS),'_$(i)',)]"
STR_NEEDLE := ,]
WASMCCFLAGS += -s $(subst $(STR_NEEDLE),],$(WASM_FUNCTIONS))

VPATH = src: $(SRC_DIR)
vpath %.js $(SRC_DIR)
vpath %.c $(WASM_SRC_DIR)

.PHONY: all clean $(PROJECT_NAME).js $(PROJECT_NAME).min.js $(PROJECT_NAME).wasm.js $(PROJECT_NAME).wasm

# *********************************** RULES ************************************

all: $(PROJECT_NAME).min.js
clean:
rm -rf $(BUILD_DIR)

# Build minified JS file
$(PROJECT_NAME).min.js: $(BUILD_DIR)/$(PROJECT_NAME).min.js
$(BUILD_DIR)/$(PROJECT_NAME).min.js: $(BUILD_DIR)/$(PROJECT_NAME).js
@mkdir -p $(@D)
$(MINJS) $? -o $@

# Build concatenated JS file
$(PROJECT_NAME).js: $(BUILD_DIR)/$(PROJECT_NAME).js
$(BUILD_DIR)/$(PROJECT_NAME).js: $(JS_SRC_FILES) $(BUILD_DIR)/$(PROJECT_NAME).wasm.js
@mkdir -p $(@D)
cat $? >> $@

# Build the WASM code embedded in JS file
$(PROJECT_NAME).wasm.js: $(BUILD_DIR)/$(PROJECT_NAME).wasm.js
$(BUILD_DIR)/$(PROJECT_NAME).wasm.js: $(BUILD_DIR)/$(PROJECT_NAME).wasm.b64
@mkdir -p $(@D)
echo -n "JSMpeg.WASM_BINARY_INLINED='" >> $@
cat $? >> $@
echo "';" >> $@

# Genereate base64 file with WASM code
$(BUILD_DIR)/$(PROJECT_NAME).wasm.b64: $(BUILD_DIR)/$(PROJECT_NAME).wasm
@mkdir -p $(@D)
$(B64) $(B64FLAGS) $? >> $@

# Build the WASM code
$(PROJECT_NAME).wasm: $(BUILD_DIR)/$(PROJECT_NAME).wasm
$(BUILD_DIR)/$(PROJECT_NAME).wasm: $(WASM_SRC_FILES)
@mkdir -p $(@D)
$(WASMCC) $(WASM_SRC_FILES) $(WASM_EMCC_FILES) $(WASMCCFLAGS) $(WASMCCEXTRAFLAGS) -o $@