Skip to content

Commit

Permalink
Merge branch 'koush:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
slyoldfox authored Nov 22, 2023
2 parents 125f539 + fa9a2eb commit 1161589
Show file tree
Hide file tree
Showing 82 changed files with 4,427 additions and 2,527 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ jobs:
# runs-on: ubuntu-latest
strategy:
matrix:
BASE: ["18-jammy-full", "18-jammy-lite", "18-jammy-thin", "20-jammy-full", "20-jammy-lite", "20-jammy-thin"]
BASE: [
"18-jammy-full",
"18-jammy-lite",
# "18-jammy-thin",
# "20-jammy-full",
# "20-jammy-lite",
# "20-jammy-thin",
]
SUPERVISOR: ["", ".s6"]
steps:
- name: Check out the repo
Expand Down
62 changes: 43 additions & 19 deletions common/src/async-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,36 +45,64 @@ export function createAsyncQueue<T>() {
return true;
}

if (signal)
dequeued ||= new Deferred();

const qi = {
item,
dequeued,
};
queued!.push(qi);

signal?.addEventListener('abort', () => {
if (!signal)
return true;

const h = () => {
const index = queued.indexOf(qi);
if (index === -1)
return;
queued.splice(index, 1);
dequeued?.reject(new Error('abort'));
});
};

dequeued.promise.catch(() => {}).finally(() => signal.removeEventListener('abort', h));
signal.addEventListener('abort', h);

return true;
}

function end(e?: Error) {
if (ended)
return false;
// catch to prevent unhandled rejection.
ended = e || new EndError()
while (waiting.length) {
waiting.shift().reject(ended);
}
return true;
}

function queue() {
return (async function* () {
while (true) {
try {
const item = await dequeue();
yield item;
}
catch (e) {
if (e instanceof EndError)
return;
throw e;
try {
while (true) {
try {
const item = await dequeue();
yield item;
}
catch (e) {
// the yield above may raise an error, and the queue should be ended.
end(e);
if (e instanceof EndError)
return;
throw e;
}
}
}
finally {
// the yield above may cause an iterator return, and the queue should be ended.
end();
}
})();
}

Expand All @@ -93,6 +121,9 @@ export function createAsyncQueue<T>() {
}

return {
get ended() {
return ended;
},
take,
clear() {
return clear();
Expand All @@ -106,14 +137,7 @@ export function createAsyncQueue<T>() {
submit(item: T, signal?: AbortSignal) {
return submit(item, undefined, signal);
},
end(e?: Error) {
if (ended)
return false;
// catch to prevent unhandled rejection.
ended = e || new EndError()
clear(e);
return true;
},
end,
async enqueue(item: T, signal?: AbortSignal) {
const dequeued = new Deferred<void>();
if (!submit(item, dequeued, signal))
Expand Down
77 changes: 77 additions & 0 deletions common/src/zygote.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import sdk, { PluginFork } from '@scrypted/sdk';
import worker_threads from 'worker_threads';
import { createAsyncQueue } from './async-queue';
import os from 'os';

export type Zygote<T> = () => PluginFork<T>;

export function createZygote<T>(): Zygote<T> {
if (!worker_threads.isMainThread)
return;

let zygote = sdk.fork<T>();
function* next() {
while (true) {
const cur = zygote;
zygote = sdk.fork<T>();
yield cur;
}
}

const gen = next();
return () => gen.next().value as PluginFork<T>;
}


export function createZygoteWorkQueue<T>(maxWorkers: number = os.cpus().length >> 1) {
const queue = createAsyncQueue<(doWork: (fork: PluginFork<T>) => Promise<any>) => Promise<any>>();
let forks = 0;

return async <R>(doWork: (fork: PluginFork<T>) => Promise<R>): Promise<R> => {
const check = queue.take();
if (check)
return check(doWork);

if (maxWorkers && forks < maxWorkers) {
let exited = false;
const controller = new AbortController();
// necessary to prevent unhandledrejection errors
controller.signal.addEventListener('abort', () => { });
const fork = sdk.fork<T>();
forks++;
fork.worker.on('exit', () => {
forks--;
exited = true;
controller.abort();
});

let timeout: NodeJS.Timeout;
const queueFork = () => {
clearTimeout(timeout);
timeout = setTimeout(() => {
// keep one alive.
if (forks === 1)
return;
fork.worker.terminate();
}, 30000);

queue.submit(async v2 => {
clearTimeout(timeout);
try {
return await v2(fork);
}
finally {
if (!exited) {
queueFork();
}
}
}, controller.signal);
}

queueFork();
}

const d = await queue.dequeue();
return d(doWork);
};
}
2 changes: 1 addition & 1 deletion external/werift
Submodule werift updated 50 files
+2 −0 .gitignore
+1 −1 .vscode/launch.json
+2 −0 .vscode/settings.json
+28 −0 NOTICE
+52 −35 e2e/package-lock.json
+1 −1 e2e/package.json
+40 −55 examples/package-lock.json
+1 −1 examples/package.json
+3 −3 examples/save_to_disk/answer.html
+139 −0 examples/save_to_disk/mp4/av.ts
+108 −0 examples/save_to_disk/mp4/h264.ts
+97 −0 examples/save_to_disk/mp4/opus.ts
+14 −13 examples/save_to_disk/react-client/main.tsx
+13 −1 package-lock.json
+6 −2 packages/ice/.eslintrc
+17 −6 packages/ice/src/ice.ts
+3 −1 packages/ice/src/stun/transaction.ts
+6 −3 packages/ice/src/turn/protocol.ts
+1 −1 packages/ice/src/types/model.ts
+1 −1 packages/ice/tests/ice/ice.test.ts
+1 −1 packages/ice/tests/stun/stun.test.ts
+1 −0 packages/rtp/package.json
+1 −1 packages/rtp/src/container/index.ts
+7 −0 packages/rtp/src/container/mp4/chunk.ts
+301 −0 packages/rtp/src/container/mp4/container.ts
+122 −0 packages/rtp/src/container/mp4/exp-golomb.ts
+226 −0 packages/rtp/src/container/mp4/h264.ts
+2 −0 packages/rtp/src/container/mp4/index.ts
+50 −0 packages/rtp/src/container/mp4/mp4box.ts
+325 −0 packages/rtp/src/container/mp4/sps-parser.ts
+3 −3 packages/rtp/src/container/webm/container.ts
+0 −0 packages/rtp/src/container/webm/ebml/ebml.ts
+0 −0 packages/rtp/src/container/webm/ebml/id.ts
+0 −0 packages/rtp/src/container/webm/ebml/index.ts
+0 −0 packages/rtp/src/container/webm/ebml/typedArrayUtils.ts
+2 −0 packages/rtp/src/container/webm/index.ts
+2 −0 packages/rtp/src/processor/index.ts
+165 −0 packages/rtp/src/processor/mp4.ts
+51 −0 packages/rtp/src/processor/mp4Callback.ts
+5 −5 packages/rtp/src/processor/webm.ts
+2 −1 packages/rtp/src/processor/webmCallback.ts
+1 −1 packages/rtp/src/processor/webmStream.ts
+4 −4 packages/rtp/src/processor_old/webm.ts
+2 −2 packages/rtp/src/rtcp/rtpfb/twcc.ts
+1 −1 packages/rtp/src/typings/jspack.d.ts
+1,893 −0 packages/rtp/src/typings/mp4box.d.ts
+8 −3 packages/rtp/tsconfig.json
+1 −1 packages/webrtc/package.json
+1 −1 packages/webrtc/src/nonstandard/recorder/writer/webm.ts
+3 −3 packages/webrtc/src/peerConnection.ts
2 changes: 1 addition & 1 deletion install/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Home Assistant Addon Configuration
name: Scrypted
version: "18-jammy-full.s6-v0.57.0"
version: "18-jammy-full.s6-v0.68.0"
slug: scrypted
description: Scrypted is a high performance home video integration and automation platform
url: "https://github.com/koush/scrypted"
Expand Down
4 changes: 1 addition & 3 deletions packages/cli/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
],
"preLaunchTask": "npm: build",
"args": [
"ffplay",
"Baby [email protected]",
"getVideoStream",
"shell",
],
"sourceMaps": true,
"resolveSourceMapLocations": [
Expand Down
Loading

0 comments on commit 1161589

Please sign in to comment.