Merge pull request #198 from hrstv/plugins/synology-ss

synology-ss: support for sub streams
This commit is contained in:
Koushik Dutta
2022-03-22 20:47:32 -07:00
committed by GitHub
2 changed files with 52 additions and 6 deletions

View File

@@ -82,6 +82,21 @@ export class SynologyApiClient {
return response.cameras;
}
public async getCameraInfo(cameraId: number | string): Promise<SynologyCameraInfo> {
const params = {
api: 'SYNO.SurveillanceStation.Camera',
version: 8,
method: 'GetInfo',
privCamType: 1,
streamInfo: true,
cameraIds: cameraId
};
const response = await this.sendRequest<SynologyCameraInfoResponse>(params);
return response.cameras[0];
}
public async login(account: string, password: string, otpCode?: number, enableDeviceToken: boolean = false, deviceName?: string,
deviceId?: string): Promise<string | undefined> {
const params = {
@@ -225,3 +240,21 @@ export interface SynologyCameraStream {
quality?: string;
constantBitrate?: string;
}
export interface SynologyCameraInfoResponse {
cameras: SynologyCameraInfo[];
}
export interface SynologyCameraInfo {
id: string;
stm_info: SynologyCameraInfoStream[];
}
export interface SynologyCameraInfoStream {
camPath?: string;
fps?: number;
quality?: string;
resolution?: string;
stmNo?: number;
type?: number;
}

View File

@@ -1,6 +1,6 @@
import sdk, { ScryptedDeviceBase, DeviceProvider, HttpRequest, HttpRequestHandler, HttpResponse, Settings, Setting, ScryptedDeviceType, VideoCamera, MediaObject, Device, MotionSensor, ScryptedInterface, Camera, MediaStreamOptions, PictureOptions } from "@scrypted/sdk";
import { createInstanceableProviderPlugin, enableInstanceableProviderMode, isInstanceableProviderModeEnabled } from '../../../common/src/provider-plugin';
import {SynologyApiClient, SynologyCameraStream, SynologyCamera} from "./api/synology-api-client";
import { SynologyApiClient, SynologyCameraStream, SynologyCamera } from "./api/synology-api-client";
const { deviceManager, mediaManager } = sdk;
@@ -96,15 +96,28 @@ class SynologyCameraDevice extends ScryptedDeviceBase implements Camera, HttpReq
const rtspChannel = this.streams.find(check => check.id === vso.id);
const liveViewPaths = await this.provider.api.getCameraLiveViewPath([this.nativeId]);
if (!liveViewPaths?.length)
throw new Error(`Unable to locate RTSP stream for camera ${this.nativeId}`);
let rtspPath = null;
if (vso.id !== '1') {
const cameraInfo = await this.provider.api.getCameraInfo(this.nativeId);
const camStream = cameraInfo?.stm_info?.find(el => el.stmNo.toString() == vso.id);
if (camStream)
rtspPath = Buffer.from(camStream.camPath, 'base64').toString('binary')
}
if (!rtspPath) {
const liveViewPaths = await this.provider.api.getCameraLiveViewPath([this.nativeId]);
if (!liveViewPaths?.length)
throw new Error(`Unable to locate RTSP stream for camera ${this.nativeId}`);
rtspPath = liveViewPaths[0].rtspPath;
}
return mediaManager.createFFmpegMediaObject({
url: liveViewPaths[0].rtspPath,
url: rtspPath,
inputArguments: [
"-rtsp_transport", "tcp",
"-i", liveViewPaths[0].rtspPath,
"-i", rtspPath,
],
mediaStreamOptions: this.createMediaStreamOptions(rtspChannel),
});