Skip to content

Commit

Permalink
Merge branch 'master' into svtav1
Browse files Browse the repository at this point in the history
  • Loading branch information
Yahweasel committed Sep 28, 2024
2 parents 117be4f + 9508ac6 commit ea08db4
Show file tree
Hide file tree
Showing 8 changed files with 675 additions and 95 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ tests/out.webm
tests/out.mp4

node_modules/
package-lock.json
548 changes: 492 additions & 56 deletions Makefile

Large diffs are not rendered by default.

34 changes: 25 additions & 9 deletions Makefile.m4
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ LIBAVJS_VERSION_BASE=5.4
LIBAVJS_VERSION=$(LIBAVJS_VERSION_BASE).$(FFMPEG_VERSION)$(LIBAVJS_VERSION_SUFFIX)
LIBAVJS_VERSION_SHORT=$(LIBAVJS_VERSION_BASE).$(FFMPEG_VERSION_MAJOR)
EMCC=emcc
MINIFIER=node_modules/.bin/uglifyjs -m
MINIFIER=node_modules/.bin/terser
OPTFLAGS=-Oz
NOTHRFLAGS=build/inst/base/lib/libemfiberthreads.a
NOTHRFLAGS=-Lbuild/inst/base/lib -lemfiberthreads
THRFLAGS=-pthread
ES6FLAGS=-sEXPORT_ES6=1 -sUSE_ES6_IMPORT_META=1
EFLAGS=\
Expand Down Expand Up @@ -72,7 +72,7 @@ build-%: \
define([[[febuildrule]]], [[[
dist/libav-$(LIBAVJS_VERSION)-%$1.$2: build/libav-$(LIBAVJS_VERSION).$2 \
dist/libav-$(LIBAVJS_VERSION)-%$1.wasm.$2 \
node_modules/.bin/uglifyjs
node_modules/.bin/terser
mkdir -p dist
sed "s/@CONFIG/$(*)/g ; s/@DBG/$1/g" < $< | $3 > $(@)
Expand All @@ -89,22 +89,38 @@ dist/libav.types.d.ts: build/libav.types.d.ts
mkdir -p dist
cp $< $@

# Link rule that checks for a library's existence before linking it
# Use: linkfflib(library name, target inst name)
define([[[linkfflib]]], [[[ \
`test ! -e build/ffmpeg-$(FFMPEG_VERSION)/build-$2-$(*)/lib$1/lib$1.a || echo ' \
-Lbuild/ffmpeg-$(FFMPEG_VERSION)/build-$2-$(*)/lib$1 -l$1 \
'` \
]]])

# General build rule for any target
# Use: buildrule(target file name, debug infix, target inst name, CFLAGS, target file suffix)
# Use: buildrule(target file name, debug infix, target inst name, extra link flags, target file suffix)
define([[[buildrule]]], [[[
dist/libav-$(LIBAVJS_VERSION)-%.$2$1.$5: build/ffmpeg-$(FFMPEG_VERSION)/build-$3-%/libavformat/libavformat.a \
build/exports.json pre.js build/post.js extern-post.js bindings.c
mkdir -p $(@).d
$(EMCC) $(OPTFLAGS) $(EFLAGS) $4 \
$(EMCC) $(OPTFLAGS) $(EFLAGS) \
-Ibuild/ffmpeg-$(FFMPEG_VERSION) -Ibuild/ffmpeg-$(FFMPEG_VERSION)/build-$3-$(*) \
`test ! -e configs/configs/$(*)/link-flags.txt || cat configs/configs/$(*)/link-flags.txt` \
bindings.c \
`grep LIBAVJS_WITH_CLI configs/configs/$(*)/link-flags.txt > /dev/null 2>&1 && echo ' \
build/ffmpeg-$(FFMPEG_VERSION)/build-$3-$(*)/fftools/*.o \
build/ffmpeg-$(FFMPEG_VERSION)/build-$3-$(*)/libavdevice/libavdevice.a \
-Lbuild/ffmpeg-$(FFMPEG_VERSION)/build-$3-$(*)/libavdevice -lavdevice \
'` \
build/ffmpeg-$(FFMPEG_VERSION)/build-$3-$(*)/*/lib*.a \
`test ! -e configs/configs/$(*)/libs.txt || sed 's/@TARGET/$3/' configs/configs/$(*)/libs.txt` -o $(@).d/libav-$(LIBAVJS_VERSION)-$(*).$2$1.$5
linkfflib(avutil, $3) \
linkfflib(avformat, $3) \
linkfflib(avcodec, $3) \
linkfflib(avfilter, $3) \
linkfflib(swresample, $3) \
linkfflib(swscale, $3) \
linkfflib(foob, $3) \
`test ! -e configs/configs/$(*)/libs.txt || sed 's/@TARGET/$3/' configs/configs/$(*)/libs.txt` \
$4 \
-o $(@).d/libav-$(LIBAVJS_VERSION)-$(*).$2$1.$5
if [ -e $(@).d/libav-$(LIBAVJS_VERSION)-$(*).$2$1.wasm.map ] ; then \
./tools/adjust-sourcemap.js $(@).d/libav-$(LIBAVJS_VERSION)-$(*).$2$1.wasm.map \
ffmpeg $(FFMPEG_VERSION) \
Expand Down Expand Up @@ -149,7 +165,7 @@ build/libav-$(LIBAVJS_VERSION).js: libav.in.js post.in.js funcs.json tools/apply
build/libav.types.d.ts build/libav-$(LIBAVJS_VERSION).mjs build/exports.json build/post.js: build/libav-$(LIBAVJS_VERSION).js
touch $@

node_modules/.bin/uglifyjs:
node_modules/.bin/terser:
npm install

# Targets
Expand Down
43 changes: 22 additions & 21 deletions extern-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,41 +48,42 @@ if (/* We're in a worker */
var fun = e.data[1];
var args = e.data.slice(2);
var ret = void 0;
var transfer = [];
var succ = true;

function reply() {
var transfer = [];
if (ret && ret.libavjsTransfer)
transfer = ret.libavjsTransfer
try {
postMessage([id, fun, succ, ret], transfer);
} catch (ex) {
try {
ret = JSON.parse(JSON.stringify(
ret, function(k, v) { return v; }
));
postMessage([id, fun, succ, ret], transfer);
} catch (ex) {
postMessage([id, fun, succ, "" + ret]);
}
}
}

try {
ret = libav[fun].apply(libav, args);
} catch (ex) {
succ = false;
ret = ex;
}
if (succ && typeof ret === "object" && ret !== null && ret.then) {
if (succ && ret && ret.then) {
// Let the promise resolve
ret.then(function(res) {
ret = res;
}).catch(function(ex) {
succ = false;
ret = ex;
}).then(function() {
if (typeof ret === "object" && ret && ret.libavjsTransfer)
transfer = ret.libavjsTransfer;
try {
postMessage([id, fun, succ, ret], transfer);
} catch (ex) {
postMessage([id, fun, succ, "" + ret]);
}
});
}).then(reply);

} else {
if (typeof ret === "object" && ret && ret.libavjsTransfer)
transfer = ret.libavjsTransfer;
try {
postMessage([id, fun, succ, ret], transfer);
} catch (ex) {
postMessage([id, fun, succ, "" + ret]);
}

}
} else reply();
};

libav.onwrite = function(name, pos, buf) {
Expand Down
135 changes: 135 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@
},
"homepage": "https://github.com/Yahweasel/libav.js#readme",
"devDependencies": {
"fast-xml-parser": "^4.2.2",
"uglify-js": "^3.14.3"
"terser": "^5.34.1"
}
}
3 changes: 0 additions & 3 deletions tests/tests/602-demuxing-block-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@

// Example of directly using a block device

if (h.libAVOpts && h.libAVOpts.yesthreads)
throw new Error("Known bug: test 602 does not work with threads.");

const libav = await h.LibAV();
const buf = await h.readCachedFile("bbb.webm");

Expand Down
3 changes: 0 additions & 3 deletions tests/tests/616-reentrancy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@

// Check for reentrancy issues by trying to do two files at once

if (h.libAVOpts && h.libAVOpts.yesthreads)
throw new Error("Known bug: test 616 does not work with threads.");

const libav = await h.LibAV();
const buf = await h.readCachedFile("bbb.webm");

Expand Down

0 comments on commit ea08db4

Please sign in to comment.