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

Multithread AVIF & OxiPNG #829

Merged
merged 16 commits into from Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -16,3 +16,8 @@
# But it isn't a big deal if the user gets an old version.
/assets/*
Cache-Control: must-revalidate, max-age=3600

# COOP+COEP for WebAssembly threads.
/*
Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Opener-Policy: same-origin
@@ -1,138 +1,78 @@
CODEC_URL = https://github.com/AOMediaCodec/libavif/archive/v0.8.1.tar.gz
CODEC_PACKAGE = node_modules/libavif.tar.gz

CODEC_ENC_DIR = node_modules/libavif-enc
CODEC_ENC_BUILD_DIR := $(CODEC_ENC_DIR)/build
CODEC_ENC_OUT := $(CODEC_ENC_BUILD_DIR)/libavif.a

CODEC_DEC_DIR = node_modules/libavif-dec
CODEC_DEC_BUILD_DIR := $(CODEC_DEC_DIR)/build
CODEC_DEC_OUT := $(CODEC_DEC_BUILD_DIR)/libavif.a

LIBAOM_URL = https://aomedia.googlesource.com/aom/+archive/v2.0.0.tar.gz
LIBAOM_PACKAGE = node_modules/libaom.tar.gz

LIBAOM_ENC_DIR := $(CODEC_ENC_DIR)/ext/aom
LIBAOM_ENC_BUILD_DIR := $(LIBAOM_ENC_DIR)/build.libavif
LIBAOM_ENC_OUT := $(LIBAOM_ENC_BUILD_DIR)/libaom.a

LIBAOM_DEC_DIR := $(CODEC_DEC_DIR)/ext/aom
LIBAOM_DEC_BUILD_DIR := $(LIBAOM_DEC_DIR)/build.libavif
LIBAOM_DEC_OUT := $(LIBAOM_DEC_BUILD_DIR)/libaom.a
CODEC_ENC_DIR = node_modules/libavif-enc
CODEC_ENC_MT_DIR = node_modules/libavif-enc-mt
CODEC_DEC_DIR = node_modules/libavif-dec
LIBAOM_DIR = node_modules/libaom

OUT_ENC_JS = enc/avif_enc.js
OUT_ENC_CPP = $(OUT_ENC_JS:.js=.cpp)
OUT_ENC_WASM = $(OUT_ENC_JS:.js=.wasm)

OUT_ENC_MT_JS = enc/avif_enc_mt.js
OUT_DEC_JS = dec/avif_dec.js
OUT_DEC_CPP = $(OUT_DEC_JS:.js=.cpp)
OUT_DEC_WASM = $(OUT_DEC_JS:.js=.wasm)

# ERROR_ON_UNDEFINED_SYMBOLS=0 is needed to seperate the encoder and decoder
EMSCRIPTEN_FLAGS = ${CXXFLAGS} \
${LDFLAGS} \
--bind \
--closure 1 \
-s ALLOW_MEMORY_GROWTH=1 \
-s MODULARIZE=1 \
-s ERROR_ON_UNDEFINED_SYMBOLS=0

CODEC_EMCMAKE = emcmake cmake \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=0 \
-DAVIF_CODEC_AOM=1 \
-DAVIF_LOCAL_AOM=1 \
../
OUT_ENC_CPP = enc/avif_enc.cpp
OUT_DEC_CPP = dec/avif_dec.cpp

LIBAOM_FLAGS = -DCMAKE_BUILD_TYPE=Release \
-DENABLE_CCACHE=0 \
-DAOM_TARGET_CPU=generic \
-DENABLE_DOCS=0 \
-DENABLE_TESTS=0 \
-DENABLE_EXAMPLES=0 \
-DENABLE_TOOLS=0 \
-DCONFIG_ACCOUNTING=1 \
-DCONFIG_INSPECTION=0 \
-DCONFIG_MULTITHREAD=0 \
-DCONFIG_RUNTIME_CPU_DETECT=0 \
-DCONFIG_WEBM_IO=0
HELPER_MAKEFLAGS := -f helper.Makefile \
LIBAOM_DIR=$(LIBAOM_DIR) \
CODEC_PACKAGE=$(CODEC_PACKAGE) \
LIBAOM_PACKAGE=$(LIBAOM_PACKAGE)

.PHONY: all clean

all: $(OUT_ENC_JS) $(OUT_DEC_JS)

$(OUT_ENC_JS): $(OUT_ENC_CPP) $(LIBAOM_ENC_OUT) $(CODEC_ENC_OUT)
$(CXX) \
-I $(CODEC_ENC_DIR)/include \
${EMSCRIPTEN_FLAGS} \
-s 'EXPORT_NAME="$(basename $(@F))"' \
-o $@ \
$+

$(OUT_DEC_JS): $(OUT_DEC_CPP) $(LIBAOM_DEC_OUT) $(CODEC_DEC_OUT)
$(CXX) \
-I $(CODEC_DEC_DIR)/include \
${EMSCRIPTEN_FLAGS} \
-s 'EXPORT_NAME="$(basename $(@F))"' \
-o $@ \
$+

$(CODEC_ENC_OUT): $(CODEC_ENC_DIR)/CMakeLists.txt $(LIBAOM_ENC_OUT)
mkdir -p $(CODEC_ENC_BUILD_DIR)
cd $(CODEC_ENC_BUILD_DIR) && \
$(CODEC_EMCMAKE) && \
$(MAKE)

$(CODEC_DEC_OUT): $(CODEC_DEC_DIR)/CMakeLists.txt $(LIBAOM_DEC_OUT)
mkdir -p $(CODEC_DEC_BUILD_DIR)
cd $(CODEC_DEC_BUILD_DIR) && \
$(CODEC_EMCMAKE) && \
$(MAKE)

$(LIBAOM_ENC_OUT): $(LIBAOM_ENC_DIR)/CMakeLists.txt
mkdir -p $(LIBAOM_ENC_BUILD_DIR)
cd $(LIBAOM_ENC_BUILD_DIR) && \
emcmake cmake \
$(LIBAOM_FLAGS) \
-DCONFIG_AV1_DECODER=0 \
-DCONFIG_AV1_HIGHBITDEPTH=0 \
../ && \
$(MAKE)

$(LIBAOM_DEC_OUT): $(LIBAOM_DEC_DIR)/CMakeLists.txt
mkdir -p $(LIBAOM_DEC_BUILD_DIR)
cd $(LIBAOM_DEC_BUILD_DIR) && \
emcmake cmake \
$(LIBAOM_FLAGS) \
-DCONFIG_AV1_ENCODER=0 \
../ && \
$(MAKE)

$(CODEC_ENC_DIR)/CMakeLists.txt: $(CODEC_ENC_DIR)
$(CODEC_DEC_DIR)/CMakeLists.txt: $(CODEC_DEC_DIR)

$(LIBAOM_ENC_DIR)/CMakeLists.txt: $(LIBAOM_ENC_DIR)
$(LIBAOM_DEC_DIR)/CMakeLists.txt: $(LIBAOM_DEC_DIR)
all: $(OUT_ENC_JS) $(OUT_DEC_JS) $(OUT_ENC_MT_JS)

$(OUT_ENC_JS): $(OUT_ENC_CPP) $(CODEC_PACKAGE) $(LIBAOM_DIR)/CMakeLists.txt
$(MAKE) \
$(HELPER_MAKEFLAGS) \
CODEC_DIR=$(CODEC_ENC_DIR) \
OUT_JS=$@ \
OUT_CPP=$< \
LIBAOM_FLAGS="\
-DCONFIG_AV1_DECODER=0 \
-DCONFIG_MULTITHREAD=0 \
-DCONFIG_AV1_HIGHBITDEPTH=0 \
"

$(OUT_ENC_MT_JS): $(OUT_ENC_CPP) $(CODEC_PACKAGE) $(LIBAOM_DIR)/CMakeLists.txt
$(MAKE) \
$(HELPER_MAKEFLAGS) \
CODEC_DIR=$(CODEC_ENC_MT_DIR) \
OUT_JS=$@ \
OUT_CPP=$< \
LIBAOM_FLAGS="\
-DCONFIG_AV1_DECODER=0 \
-DCONFIG_AV1_HIGHBITDEPTH=0 \
" \
OUT_FLAGS="-pthread"

$(OUT_DEC_JS): $(OUT_DEC_CPP) $(CODEC_PACKAGE) $(LIBAOM_DIR)/CMakeLists.txt
$(MAKE) \
$(HELPER_MAKEFLAGS) \
CODEC_DIR=$(CODEC_DEC_DIR) \
OUT_JS=$@ \
OUT_CPP=$< \
LIBAOM_FLAGS="\
-DCONFIG_AV1_ENCODER=0 \
-DCONFIG_MULTITHREAD=0 \
"

$(CODEC_PACKAGE):
mkdir -p $(dir $@)
mkdir -p $(@D)
curl -sL $(CODEC_URL) -o $@

$(LIBAOM_PACKAGE):
mkdir -p $(dir $@)
mkdir -p $(@D)
curl -sL $(LIBAOM_URL) -o $@

$(CODEC_ENC_DIR) $(CODEC_DEC_DIR): $(CODEC_PACKAGE)
mkdir -p $@
tar xz --strip 1 -C $@ -f $(CODEC_PACKAGE)

$(LIBAOM_ENC_DIR) $(LIBAOM_DEC_DIR): $(LIBAOM_PACKAGE)
mkdir -p $@
tar xz -C $@ -f $(LIBAOM_PACKAGE)
$(LIBAOM_DIR)/CMakeLists.txt: $(LIBAOM_PACKAGE)
mkdir -p $(@D)
tar xzm -C $(@D) -f $(LIBAOM_PACKAGE)

clean:
$(RM) $(LIBAOM_PACKAGE) $(CODEC_PACKAGE) $(OUT_ENC_JS) $(OUT_ENC_WASM) $(OUT_DEC_JS) $(OUT_DEC_WASM)
$(MAKE) -C $(CODEC_ENC_BUILD_DIR) clean
$(MAKE) -C $(CODEC_DEC_BUILD_DIR) clean
$(MAKE) -C $(LIBAOM_ENC_BUILD_DIR) clean
$(MAKE) -C $(LIBAOM_DEC_BUILD_DIR) clean
$(MAKE) $(HELPER_MAKEFLAGS) CODEC_DIR=$(CODEC_ENC_DIR) OUT_JS=$(OUT_ENC_JS) clean
$(MAKE) $(HELPER_MAKEFLAGS) CODEC_DIR=$(CODEC_ENC_MT_DIR) OUT_JS=$(OUT_ENC_MT_JS) clean
$(MAKE) $(HELPER_MAKEFLAGS) CODEC_DIR=$(CODEC_DEC_DIR) OUT_JS=$(OUT_DEC_JS) clean