mirror of
https://github.com/koush/scrypted.git
synced 2026-05-04 21:30:30 +01:00
plugins: cleanup package sizes
This commit is contained in:
@@ -5,16 +5,19 @@ import { listenZero } from "./listen-cluster";
|
||||
import { ffmpegLogInitialOutput } from "./media-helpers";
|
||||
|
||||
let wrtc: any;
|
||||
try {
|
||||
wrtc = require('wrtc');
|
||||
}
|
||||
catch (e) {
|
||||
console.warn('loading wrtc failed. trying @koush/wrtc fallback.');
|
||||
wrtc = require('@koush/wrtc');
|
||||
}
|
||||
function initalizeWebRtc() {
|
||||
if (wrtc)
|
||||
return;
|
||||
try {
|
||||
wrtc = require('wrtc');
|
||||
}
|
||||
catch (e) {
|
||||
console.warn('loading wrtc failed. trying @koush/wrtc fallback.');
|
||||
wrtc = require('@koush/wrtc');
|
||||
}
|
||||
|
||||
Object.assign(global, wrtc);
|
||||
const { RTCVideoSource, RTCAudioSource } = wrtc.nonstandard;
|
||||
Object.assign(global, wrtc);
|
||||
}
|
||||
|
||||
interface RTCSession {
|
||||
pc: RTCPeerConnection;
|
||||
@@ -90,6 +93,7 @@ export function addBuiltins(console: Console, mediaManager: MediaManager) {
|
||||
],
|
||||
};
|
||||
|
||||
initalizeWebRtc();
|
||||
const pc = new RTCPeerConnection(configuration);
|
||||
const id = Math.random().toString();
|
||||
const session: RTCSession = {
|
||||
@@ -106,6 +110,8 @@ export function addBuiltins(console: Console, mediaManager: MediaManager) {
|
||||
}
|
||||
}
|
||||
|
||||
const { RTCVideoSource, RTCAudioSource } = wrtc.nonstandard;
|
||||
|
||||
const videoSource = new RTCVideoSource();
|
||||
pc.addTrack(videoSource.createTrack());
|
||||
|
||||
|
||||
4
plugins/core/package-lock.json
generated
4
plugins/core/package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@scrypted/core",
|
||||
"version": "0.0.179",
|
||||
"version": "0.0.181",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@scrypted/core",
|
||||
"version": "0.0.179",
|
||||
"version": "0.0.181",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@koush/wrtc": "^0.5.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@scrypted/core",
|
||||
"version": "0.0.179",
|
||||
"version": "0.0.181",
|
||||
"description": "Scrypted Core plugin. Provides the UI, websocket, and engine.io APIs.",
|
||||
"author": "Scrypted",
|
||||
"license": "Apache-2.0",
|
||||
|
||||
4
plugins/homekit/package-lock.json
generated
4
plugins/homekit/package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@scrypted/homekit",
|
||||
"version": "0.0.171",
|
||||
"version": "0.0.172",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@scrypted/homekit",
|
||||
"version": "0.0.171",
|
||||
"version": "0.0.172",
|
||||
"dependencies": {
|
||||
"hap-nodejs": "file:../../external/HAP-NodeJS",
|
||||
"lodash": "^4.17.21",
|
||||
|
||||
@@ -40,5 +40,5 @@
|
||||
"@types/qrcode": "^1.4.1",
|
||||
"@types/url-parse": "^1.4.3"
|
||||
},
|
||||
"version": "0.0.171"
|
||||
"version": "0.0.172"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Battery, ScryptedDevice, ScryptedInterface } from "@scrypted/sdk";
|
||||
import { Accessory, Characteristic } from "./hap";
|
||||
import { Battery as HAPBattery, BatteryLevel, StatusLowBattery } from "hap-nodejs/src/lib/definitions";
|
||||
import { Battery as HAPBattery, StatusLowBattery, Accessory, Characteristic } from "./hap";
|
||||
import { bindCharacteristic } from "./common";
|
||||
|
||||
export function maybeAddBatteryService(device: ScryptedDevice & Battery, accessory: Accessory) {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
|
||||
import { EventDetails, EventListener, EventListenerRegister, Refresh, ScryptedDevice, ScryptedDeviceType, ScryptedInterface } from '@scrypted/sdk';
|
||||
import { CharacteristicEventTypes, WithUUID } from 'hap-nodejs';
|
||||
import { Characteristic } from 'hap-nodejs/src';
|
||||
import { Accessory, Service, SnapshotRequest } from './hap';
|
||||
import { Accessory, Service, SnapshotRequest, Characteristic, CharacteristicEventTypes, WithUUID } from './hap';
|
||||
|
||||
export interface DummyDevice {
|
||||
interfaces?: string[];
|
||||
|
||||
@@ -1 +1,7 @@
|
||||
export * from '../../../external/HAP-NodeJS/src/index';
|
||||
export * from 'hap-nodejs/src/index';
|
||||
export * from "hap-nodejs/src/lib/definitions";
|
||||
export * from 'hap-nodejs/src/lib/util/eventedhttp';
|
||||
export * from 'hap-nodejs/src/lib/definitions';
|
||||
export * from 'hap-nodejs/src';
|
||||
export * from 'hap-nodejs/src/lib/camera';
|
||||
export * from 'hap-nodejs/src/lib/camera/RecordingManagement';
|
||||
|
||||
@@ -9,7 +9,7 @@ import { randomBytes } from 'crypto';
|
||||
import qrcode from 'qrcode';
|
||||
import packageJson from "../package.json";
|
||||
import { randomPinCode } from './pincode';
|
||||
import { EventedHTTPServer } from 'hap-nodejs/dist/lib/util/eventedhttp';
|
||||
import { EventedHTTPServer } from './hap';
|
||||
import { getHAPUUID, initializeHapStorage } from './hap-utils';
|
||||
|
||||
const { systemManager, deviceManager } = sdk;
|
||||
|
||||
@@ -11,16 +11,13 @@ import { once } from 'events';
|
||||
import debounce from 'lodash/debounce';
|
||||
|
||||
import { CameraRecordingDelegate } from '../hap';
|
||||
import { AudioRecordingCodec, AudioRecordingCodecType, AudioRecordingSamplerate, CameraRecordingOptions } from 'hap-nodejs/src/lib/camera/RecordingManagement';
|
||||
import { ffmpegLogInitialOutput } from '@scrypted/common/src/media-helpers';
|
||||
import { RtpDemuxer } from '../rtp/rtp-demuxer';
|
||||
import { HomeKitRtpSink, startRtpSink } from '../rtp/rtp-ffmpeg-input';
|
||||
import { ContactSensor, OccupancySensor } from 'hap-nodejs/src/lib/definitions';
|
||||
import { handleFragmentsRequests, iframeIntervalSeconds } from './camera/camera-recording';
|
||||
import { createSnapshotHandler } from './camera/camera-snapshot';
|
||||
import { evalRequest } from './camera/camera-transcode';
|
||||
import { CharacteristicEventTypes, DataStreamConnection, Service, WithUUID } from 'hap-nodejs/src';
|
||||
import { RecordingManagement } from 'hap-nodejs/src/lib/camera';
|
||||
import { AudioRecordingCodec, AudioRecordingCodecType, AudioRecordingSamplerate, CameraRecordingOptions, RecordingManagement, OccupancySensor, CharacteristicEventTypes, DataStreamConnection, Service, WithUUID } from '../hap';
|
||||
import { defaultObjectDetectionContactSensorTimeout } from '../camera-mixin';
|
||||
import os from 'os';
|
||||
|
||||
@@ -204,7 +201,7 @@ addSupportedType({
|
||||
video: {
|
||||
},
|
||||
}, selectedStream || {});
|
||||
const bitrate = request.video.max_bit_rate * 1000;
|
||||
const bitrate = 10000000;//request.video.max_bit_rate * 1000;
|
||||
reconfigured.video.bitrate = bitrate;
|
||||
|
||||
device.setVideoStreamOptions(reconfigured);
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
|
||||
import { FFMpegInput, MotionSensor, ScryptedDevice, ScryptedMimeTypes, VideoCamera, AudioSensor, MediaStreamOptions } from '@scrypted/sdk'
|
||||
import { H264Level, H264Profile } from '../../hap';
|
||||
import net from 'net';
|
||||
|
||||
import sdk from '@scrypted/sdk';
|
||||
|
||||
import { AudioRecordingCodecType, AudioRecordingSamplerateValues, CameraRecordingConfiguration } from 'hap-nodejs/src/lib/camera/RecordingManagement';
|
||||
import { AudioRecordingCodecType, AudioRecordingSamplerateValues, CameraRecordingConfiguration } from '../../hap';
|
||||
import { FFMpegFragmentedMP4Session, startFFMPegFragmetedMP4Session } from '@scrypted/common/src/ffmpeg-mp4-parser-session';
|
||||
import { evalRequest } from './camera-transcode';
|
||||
import { parseFragmentedMP4 } from '@scrypted/common/src/stream-parser';
|
||||
import { levelToFfmpeg, profileToFfmpeg } from './camera-utils';
|
||||
|
||||
const { log, mediaManager, deviceManager } = sdk;
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
|
||||
import { BinarySensor, ScryptedDevice, ScryptedDeviceType, ScryptedInterface } from '@scrypted/sdk'
|
||||
import { ContactSensor, StatelessProgrammableSwitch } from 'hap-nodejs/src/lib/definitions';
|
||||
import { Characteristic, CharacteristicEventTypes, CharacteristicGetCallback, Service, ContactSensor, StatelessProgrammableSwitch } from '../hap';
|
||||
import { addSupportedType, bindCharacteristic, DummyDevice, HomeKitSession, supportedTypes } from '../common'
|
||||
import { Characteristic, CharacteristicEventTypes, CharacteristicGetCallback, Service } from '../hap';
|
||||
import { makeAccessory } from './common';
|
||||
|
||||
addSupportedType({
|
||||
|
||||
@@ -61,7 +61,7 @@ export class RtspCamera extends CameraBase<UrlMediaStreamOptions> {
|
||||
// Note the trailing colon.
|
||||
// issue: https://github.com/koush/scrypted/issues/134
|
||||
const parsedUrl = url.parse(vso.url);
|
||||
this.console.log('rtsp stream url', parsedUrl.toString());
|
||||
this.console.log('rtsp stream url', vso.url);
|
||||
const username = this.storage.getItem("username");
|
||||
const password = this.storage.getItem("password");
|
||||
if (username) {
|
||||
|
||||
@@ -14,7 +14,7 @@ import time
|
||||
import os
|
||||
import binascii
|
||||
from urllib.parse import urlparse
|
||||
import multiprocessing
|
||||
import threading
|
||||
from pipeline import run_pipeline
|
||||
|
||||
from gi.repository import Gst
|
||||
@@ -37,7 +37,7 @@ class PipelineValve:
|
||||
allowPacketCounter: int
|
||||
def __init__(self, gst, name) -> None:
|
||||
self.allowPacketCounter = 1
|
||||
self.mutex = multiprocessing.Lock()
|
||||
self.mutex = threading.Lock()
|
||||
valve = gst.get_by_name(name + "Valve")
|
||||
self.pad = valve.get_static_pad("src")
|
||||
self.name = name
|
||||
@@ -91,7 +91,7 @@ class DetectionSession:
|
||||
self.future = Future()
|
||||
self.running = False
|
||||
self.attached = False
|
||||
self.mutex = multiprocessing.Lock()
|
||||
self.mutex = threading.Lock()
|
||||
self.valve: PipelineValve = None
|
||||
self.last_sample = time.time()
|
||||
|
||||
@@ -120,7 +120,7 @@ class DetectPlugin(scrypted_sdk.ScryptedDeviceBase, ObjectDetection):
|
||||
def __init__(self, nativeId: str | None = None):
|
||||
super().__init__(nativeId=nativeId)
|
||||
self.detection_sessions: Mapping[str, DetectionSession] = {}
|
||||
self.session_mutex = multiprocessing.Lock()
|
||||
self.session_mutex = threading.Lock()
|
||||
|
||||
def detection_event(self, detection_session: DetectionSession, detection_result: ObjectsDetected, event_buffer: bytes = None):
|
||||
detection_result['detectionId'] = detection_session.id
|
||||
@@ -211,7 +211,7 @@ class DetectPlugin(scrypted_sdk.ScryptedDeviceBase, ObjectDetection):
|
||||
detection_session.future.add_done_callback(
|
||||
lambda _: self.end_session(detection_session))
|
||||
|
||||
if detection_session and time.time() - detection_session.last_sample > 30:
|
||||
if detection_session and time.time() - detection_session.last_sample > 30 and not mediaObject:
|
||||
print('detection session has not received a sample in 30 seconds, terminating', detection_session.id)
|
||||
ending = True
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from __future__ import annotations
|
||||
from scrypted_sdk.types import ObjectDetectionModel, ObjectDetectionResult, ObjectsDetected, Setting
|
||||
from .third_party.sort import Sort
|
||||
import multiprocessing
|
||||
import threading
|
||||
import io
|
||||
from .common import *
|
||||
from PIL import Image
|
||||
@@ -12,17 +11,15 @@ from pycoral.utils.edgetpu import list_edge_tpus
|
||||
from pycoral.utils.edgetpu import make_interpreter
|
||||
import tflite_runtime.interpreter as tflite
|
||||
import re
|
||||
import numpy as np
|
||||
import scrypted_sdk
|
||||
from typing import Any, List
|
||||
|
||||
from detect import DetectionSession, DetectPlugin
|
||||
|
||||
|
||||
class TrackerDetectionSession(DetectionSession):
|
||||
class TensorFlowLiteSession(DetectionSession):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self.tracker = Sort()
|
||||
|
||||
|
||||
def parse_label_contents(contents: str):
|
||||
@@ -57,7 +54,7 @@ class TensorFlowLitePlugin(DetectPlugin):
|
||||
'fs/mobilenet_ssd_v2_coco_quant_postprocess.tflite').read()
|
||||
self.interpreter = tflite.Interpreter(model_content=model)
|
||||
self.interpreter.allocate_tensors()
|
||||
self.mutex = multiprocessing.Lock()
|
||||
self.mutex = threading.Lock()
|
||||
|
||||
async def getDetectionModel(self) -> ObjectDetectionModel:
|
||||
_, height, width, channels = self.interpreter.get_input_details()[
|
||||
@@ -79,58 +76,19 @@ class TensorFlowLitePlugin(DetectPlugin):
|
||||
d['settings'] = [setting]
|
||||
return d
|
||||
|
||||
def create_detection_result(self, objs, size, tracker: Sort = None, convert_to_src_size=None):
|
||||
def create_detection_result(self, objs, size, convert_to_src_size=None):
|
||||
detections: List[ObjectDetectionResult] = []
|
||||
detection_result: ObjectsDetected = {}
|
||||
detection_result['detections'] = detections
|
||||
detection_result['inputDimensions'] = size
|
||||
|
||||
tracker_detections = []
|
||||
|
||||
for obj in objs:
|
||||
element = []
|
||||
element.append(obj.bbox.xmin)
|
||||
element.append(obj.bbox.ymin)
|
||||
element.append(obj.bbox.xmax)
|
||||
element.append(obj.bbox.ymax)
|
||||
element.append(obj.score)
|
||||
tracker_detections.append(element)
|
||||
|
||||
tracker_detections = np.array(tracker_detections)
|
||||
trdata = []
|
||||
trackerFlag = False
|
||||
if tracker and tracker_detections.any():
|
||||
trdata = tracker.update(tracker_detections)
|
||||
trackerFlag = True
|
||||
|
||||
if trackerFlag and (np.array(trdata)).size:
|
||||
for td in trdata:
|
||||
x0, y0, x1, y1, trackID = td[0].item(), td[1].item(
|
||||
), td[2].item(), td[3].item(), td[4].item()
|
||||
overlap = 0
|
||||
for ob in objs:
|
||||
dx0, dy0, dx1, dy1 = ob.bbox.xmin, ob.bbox.ymin, ob.bbox.xmax, ob.bbox.ymax
|
||||
area = (min(dx1, x1)-max(dx0, x0)) * \
|
||||
(min(dy1, y1)-max(dy0, y0))
|
||||
if (area > overlap):
|
||||
overlap = area
|
||||
obj = ob
|
||||
|
||||
detection: ObjectDetectionResult = {}
|
||||
detection['id'] = str(trackID)
|
||||
detection['boundingBox'] = (
|
||||
obj.bbox.xmin, obj.bbox.ymin, obj.bbox.xmax - obj.bbox.xmin, obj.bbox.ymax - obj.bbox.ymin)
|
||||
detection['className'] = self.labels.get(obj.id, obj.id)
|
||||
detection['score'] = obj.score
|
||||
detections.append(detection)
|
||||
else:
|
||||
for obj in objs:
|
||||
detection: ObjectDetectionResult = {}
|
||||
detection['boundingBox'] = (
|
||||
obj.bbox.xmin, obj.bbox.ymin, obj.bbox.xmax - obj.bbox.xmin, obj.bbox.ymax - obj.bbox.ymin)
|
||||
detection['className'] = self.labels.get(obj.id, obj.id)
|
||||
detection['score'] = obj.score
|
||||
detections.append(detection)
|
||||
detection: ObjectDetectionResult = {}
|
||||
detection['boundingBox'] = (
|
||||
obj.bbox.xmin, obj.bbox.ymin, obj.bbox.xmax - obj.bbox.xmin, obj.bbox.ymax - obj.bbox.ymin)
|
||||
detection['className'] = self.labels.get(obj.id, obj.id)
|
||||
detection['score'] = obj.score
|
||||
detections.append(detection)
|
||||
|
||||
if convert_to_src_size:
|
||||
detections = detection_result['detections']
|
||||
@@ -155,29 +113,25 @@ class TensorFlowLitePlugin(DetectPlugin):
|
||||
'score_threshold', score_threshold))
|
||||
return score_threshold
|
||||
|
||||
def run_detection_jpeg(self, detection_session: TrackerDetectionSession, image_bytes: bytes, settings: Any) -> ObjectsDetected:
|
||||
def run_detection_jpeg(self, detection_session: TensorFlowLiteSession, image_bytes: bytes, settings: Any) -> ObjectsDetected:
|
||||
stream = io.BytesIO(image_bytes)
|
||||
image = Image.open(stream)
|
||||
|
||||
_, scale = common.set_resized_input(
|
||||
self.interpreter, image.size, lambda size: image.resize(size, Image.ANTIALIAS))
|
||||
|
||||
tracker = None
|
||||
if detection_session:
|
||||
tracker = detection_session.tracker
|
||||
|
||||
score_threshold = self.parse_settings(settings)
|
||||
with self.mutex:
|
||||
self.interpreter.invoke()
|
||||
objs = detect.get_objects(
|
||||
self.interpreter, score_threshold=score_threshold, image_scale=scale)
|
||||
|
||||
return self.create_detection_result(objs, image.size, tracker=tracker)
|
||||
return self.create_detection_result(objs, image.size)
|
||||
|
||||
def get_detection_input_size(self, src_size):
|
||||
return input_size(self.interpreter)
|
||||
|
||||
def run_detection_gstsample(self, detection_session: TrackerDetectionSession, gstsample, settings: Any, src_size, convert_to_src_size) -> ObjectsDetected:
|
||||
def run_detection_gstsample(self, detection_session: TensorFlowLiteSession, gstsample, settings: Any, src_size, convert_to_src_size) -> ObjectsDetected:
|
||||
score_threshold = self.parse_settings(settings)
|
||||
|
||||
gst_buffer = gstsample.get_buffer()
|
||||
@@ -186,7 +140,7 @@ class TensorFlowLitePlugin(DetectPlugin):
|
||||
objs = detect.get_objects(
|
||||
self.interpreter, score_threshold=score_threshold)
|
||||
|
||||
return self.create_detection_result(objs, src_size, detection_session.tracker, convert_to_src_size)
|
||||
return self.create_detection_result(objs, src_size, convert_to_src_size)
|
||||
|
||||
def create_detection_session(self):
|
||||
return TrackerDetectionSession()
|
||||
return TensorFlowLiteSession()
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
../../../../../../external/sort/sort.py
|
||||
Reference in New Issue
Block a user