snapshot: snapshot the prebuffer to cache at least one image.

This commit is contained in:
Koushik Dutta
2022-03-30 12:50:01 -07:00
parent e9dbb85642
commit 75946345ac
3 changed files with 20 additions and 15 deletions

View File

@@ -1,12 +1,12 @@
{
"name": "@scrypted/snapshot",
"version": "0.0.21",
"version": "0.0.22",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@scrypted/snapshot",
"version": "0.0.21",
"version": "0.0.22",
"dependencies": {
"@koush/axios-digest-auth": "^0.8.5",
"@types/node": "^16.6.1",

View File

@@ -1,6 +1,6 @@
{
"name": "@scrypted/snapshot",
"version": "0.0.21",
"version": "0.0.22",
"description": "Snapshot Plugin for Scrypted",
"scripts": {
"prepublishOnly": "NODE_ENV=production scrypted-webpack",

View File

@@ -119,17 +119,19 @@ class SnapshotMixin extends SettingsMixinDeviceBase<Camera> implements Camera {
try {
const realDevice = systemManager.getDeviceById<VideoCamera>(this.id);
const msos = await realDevice.getVideoStreamOptions();
for (const mso of msos) {
if (mso.prebuffer) {
const request = mso as RequestMediaStreamOptions;
request.refresh = false;
takePicture = async () => mediaManager.convertMediaObjectToBuffer(await realDevice.getVideoStream(request), 'image/jpeg');
// a prebuffer snapshot should wipe out any pending pictures
// that may not have come from the prebuffer to allow a safe-ish/fast refresh.
this.pendingPicture = undefined;
this.console.log('snapshotting active prebuffer');
break;
}
let prebufferChannel = msos?.find(mso => mso.prebuffer);
if (prebufferChannel || !this.lastAvailablePicture) {
prebufferChannel = prebufferChannel || {
id: undefined,
};
const request = prebufferChannel as RequestMediaStreamOptions;
request.refresh = false;
takePicture = async () => mediaManager.convertMediaObjectToBuffer(await realDevice.getVideoStream(request), 'image/jpeg');
// a prebuffer snapshot should wipe out any pending pictures
// that may not have come from the prebuffer to allow a safe-ish/fast refresh.
this.pendingPicture = undefined;
this.console.log('snapshotting active prebuffer');
}
}
catch (e) {
@@ -292,8 +294,9 @@ class SnapshotMixin extends SettingsMixinDeviceBase<Camera> implements Camera {
}
async createErrorImage(e: any) {
this.console.log('creating error snapshot', e);
if (e instanceof TimeoutError) {
if (!this.timeoutPicture)
this.console.log('creating timeout snapshot');
this.timeoutPicture = singletonPromise(this.timeoutPicture,
() => this.createTextErrorImage('Snapshot Timed Out'),
FOREVER);
@@ -306,6 +309,8 @@ class SnapshotMixin extends SettingsMixinDeviceBase<Camera> implements Camera {
return this.progressPicture.promise;
}
else {
if (!this.errorPicture)
this.console.log('creating error snapshot', e);
this.errorPicture = singletonPromise(this.errorPicture,
() => this.createTextErrorImage('Snapshot Failed'),
FOREVER);