LoginSignup
1

More than 5 years have passed since last update.

emscriptenでlibvpx.jsを作る

Last updated at Posted at 2017-03-05

emscriptenでlibvpx.jsを作る

ビルドの流れ

.o .a アセンブリを作る代わりに --emit-llvm で llvm bitcode を出力し、それを emcc で asm.js にビルドする

configure を書き換える

参考

https://chromium.googlesource.com/webm/libvpx/+/904b957ae965bd3d67f15a75cd9db7954f810d33 時点の場合だと

configure.patch
diff --git a/build/make/configure.sh b/build/make/configure.sh
index ac60f50..f95dbdc 100644
--- a/build/make/configure.sh
+++ b/build/make/configure.sh
@@ -456,7 +456,7 @@ NM=${NM}

 CFLAGS  = ${CFLAGS}
 CXXFLAGS  = ${CXXFLAGS}
-ARFLAGS = -crs\$(if \$(quiet),,v)
+ARFLAGS = crs\$(if \$(quiet),,v)
 LDFLAGS = ${LDFLAGS}
 ASFLAGS = ${ASFLAGS}
 extralibs = ${extralibs}
@@ -1337,6 +1337,22 @@ EOF
           ;;
       esac
       ;;
+    asmjs-unknown-emscripten)
+      # echo "@ " $toolchain " = asmjs-unknown-emscripten""
+      # echo "@ " $tgt_isa "-" $tgt_os "-" $tgt_cc
+      CC=emcc
+      LD=llvm-link
+      AR=llvm-ar
+      AS=llvm-as
+      NM=llvm-nm
+      tune_cflags=""
+      tune_asflags=""
+      add_cflags -emit-llvm
+      #add_ldflags
+      #add_asflags 
+      disabled multithread
+      HAVE_GNU_STRIP=no
+      ;;
     *-gcc|generic-gnu)
       link_with_cc=gcc
       enable_feature gcc
diff --git a/configure b/configure
index 379c2f4..deb0965 100755
--- a/configure
+++ b/configure
@@ -155,6 +155,7 @@ all_platforms="${all_platforms} x86_64-win64-vs11"
 all_platforms="${all_platforms} x86_64-win64-vs12"
 all_platforms="${all_platforms} x86_64-win64-vs14"
 all_platforms="${all_platforms} generic-gnu"
+all_platforms="${all_platforms} asmjs-unknown-emscripten"

 # all_targets is a list of all targets that can be configured
 # note that these should be in dependency order for now.

のようにすればよい

  • llvm-arar と違ってオプションに - がつかない

ビルドの手順

参考

build.sh
git clone https://chromium.googlesource.com/webm/libvpx
cd libvpx
patch -p1 -i ./configure.patch
source /path/to/emsdk_env.sh
emsdk activate latest
emconfigure ./configure \
  --disable-optimizations \
  --disable-runtime-cpu-detect \
  --disable-examples \
  --disable-docs \
  --disable-vp9 \
  --disable-vp8-encoder \
  --disable-unit_tests \
  --disable-install_bins \
  --disable-install_libs \
  --disable-encode_perf_tests \
  --disable-decode_perf_tests \
  --disable-vp8_encoder \
  --target=asmjs-unknown-emscripten \
  --extra-cflags="-O2"
emmake make
exported_functions="['_vpx_codec_version_str', '_vpx_codec_dec_init_ver', '_vpx_codec_enc_init_ver', '_vpx_codec_vp8_dx', '_vpx_codec_iface_name', '_vpx_codec_err_to_string', '_vpx_codec_error_detail', '_vpx_codec_error', '_vpx_codec_decode', '_vpx_codec_get_frame', '_vpx_codec_encode', '_vpx_codec_get_cx_data', '_vpx_img_alloc']"
emcc \
  -s ALLOW_MEMORY_GROWTH=1 \
  -s EXPORTED_FUNCTIONS="$exported_functions" \
  libvpx.a \
  -o libvpx.js
  • vp8 の decoder だけほしかったので --disable-vp9 --disable-vp8-encoder をした。
  • -s ALLOW_MEMORY_GROWTH=1 の代わりに -O2 ができたら asm.js の最適化が働いて嬉しい

JS との Interface

libvpx の使い方について

VP8 、 VP9 の 詳細について

VP8

VP9

emscripten の情報を得るには

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1