From 328cf1536ebb5ba2a0a065c381e65c47b2402407 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Sun, 12 Jun 2022 14:20:27 -0700 Subject: [PATCH] server: add hack (?) to fix gst plugin search path on darwin --- server/package-lock.json | 4 +-- server/package.json | 2 +- server/python/rpc.py | 4 +-- server/src/plugin/runtime/python-worker.ts | 32 ++++++++++++++++------ 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/server/package-lock.json b/server/package-lock.json index a61027a0e..149c14e04 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/server", - "version": "0.1.4", + "version": "0.1.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/server", - "version": "0.1.4", + "version": "0.1.5", "license": "ISC", "dependencies": { "@mapbox/node-pre-gyp": "^1.0.8", diff --git a/server/package.json b/server/package.json index fae64f6db..2ff94e26d 100644 --- a/server/package.json +++ b/server/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/server", - "version": "0.1.4", + "version": "0.1.5", "description": "", "dependencies": { "@mapbox/node-pre-gyp": "^1.0.8", diff --git a/server/python/rpc.py b/server/python/rpc.py index 64ea502b2..905c7eb4e 100644 --- a/server/python/rpc.py +++ b/server/python/rpc.py @@ -77,8 +77,8 @@ class RpcProxy(object): return super().__setattr__(name, value) def __call__(self, *args, **kwargs): - print('call') - pass + return self.__dict__['__proxy_peer'].__apply__(self.__dict__['__proxy_id'], self.__dict__['__proxy_oneway_methods'], None, args) + def __apply__(self, method: str, args: list): return self.__dict__['__proxy_peer'].__apply__(self.__dict__['__proxy_id'], self.__dict__['__proxy_oneway_methods'], method, args) diff --git a/server/src/plugin/runtime/python-worker.ts b/server/src/plugin/runtime/python-worker.ts index fc95b7848..8f145e444 100644 --- a/server/src/plugin/runtime/python-worker.ts +++ b/server/src/plugin/runtime/python-worker.ts @@ -1,13 +1,14 @@ -import { RuntimeWorker, RuntimeWorkerOptions as RuntimeWorkerOptions } from "./runtime-worker"; import child_process from 'child_process'; +import fs from "fs"; +import os from "os"; import path from 'path'; -import { EventEmitter } from "ws"; -import { Writable, Readable } from 'stream'; -import { RpcMessage, RpcPeer } from "../../rpc"; import readline from 'readline'; +import { Readable, Writable } from 'stream'; +import { RpcMessage, RpcPeer } from "../../rpc"; import { ChildProcessWorker } from "./child-process-worker"; +import { RuntimeWorkerOptions } from "./runtime-worker"; -export class PythonRuntimeWorker extends ChildProcessWorker { +export class PythonRuntimeWorker extends ChildProcessWorker { constructor(pluginId: string, options: RuntimeWorkerOptions) { super(pluginId, options); @@ -29,12 +30,27 @@ export class PythonRuntimeWorker extends ChildProcessWorker { path.join(__dirname, '../../../python', 'plugin-remote.py'), ) + const gstEnv: NodeJS.ProcessEnv = {}; + // hack to fix gst plugin search path on mac... + if (os.platform() === 'darwin') { + const gstPaths = [ + '/opt/homebrew/lib/gstreamer-1.0', + '/usr/local/lib/gstreamer-1.0', + ]; + for (const gstPath of gstPaths) { + if (fs.existsSync(path.join(gstPath, 'libgstx264.dylib'))) { + gstEnv['GST_PLUGIN_PATH'] = gstPath; + break; + } + } + } + this.worker = child_process.spawn('python3', args, { // stdin, stdout, stderr, peer in, peer out stdio: ['pipe', 'pipe', 'pipe', 'pipe', 'pipe'], env: Object.assign({ PYTHONPATH: path.join(process.cwd(), 'node_modules/@scrypted/types'), - }, process.env, env), + }, gstEnv, process.env, env), }); this.setupWorker(); @@ -58,8 +74,8 @@ export class PythonRuntimeWorker extends ChildProcessWorker { try { if (!this.worker) throw new Error('worked has been killed'); - (this.worker.stdio[3] as Writable).write(JSON.stringify(message) + '\n', e => e && reject?.(e)); - } + (this.worker.stdio[3] as Writable).write(JSON.stringify(message) + '\n', e => e && reject?.(e)); + } catch (e) { reject?.(e); }