Skip to content

Commit 4398219

Browse files
committed
fix: remove pi model check for JPEG signature
1 parent 43c884d commit 4398219

File tree

4 files changed

+10
-47
lines changed

4 files changed

+10
-47
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
"test": "jest --runInBand",
2323
"prepublishOnly": "yarn clean && yarn build"
2424
},
25-
"dependencies": {
26-
"systeminformation": "4"
27-
},
25+
"dependencies": {},
2826
"devDependencies": {
2927
"@lcdev/eslint-config": "0.2",
3028
"@lcdev/jest": "0.2",

src/lib/still-camera.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as si from 'systeminformation';
21
import { AwbMode, ExposureMode, Flip, Rotation } from '..';
32
import { spawnPromise } from '../util';
43
import { getSharedArgs } from './shared-args';
@@ -25,6 +24,8 @@ export interface StillOptions {
2524
export default class StillCamera {
2625
private readonly options: StillOptions;
2726

27+
static readonly jpegSignature = Buffer.from([0xff, 0xd8, 0xff, 0xe1]);
28+
2829
constructor(options: StillOptions = {}) {
2930
this.options = {
3031
rotation: Rotation.Rotate0,
@@ -34,23 +35,6 @@ export default class StillCamera {
3435
};
3536
}
3637

37-
static async getJpegSignature() {
38-
const systemInfo = await si.system();
39-
switch (systemInfo.model) {
40-
case 'BCM2711':
41-
case 'BCM2835 - Pi 3 Model B':
42-
case 'BCM2835 - Pi 3 Model B+':
43-
case 'BCM2835 - Pi 4 Model B':
44-
case 'BCM2835 - Pi Zero':
45-
case 'BCM2835 - Pi Zero W':
46-
return Buffer.from([0xff, 0xd8, 0xff, 0xe1]);
47-
default:
48-
throw new Error(
49-
`Could not determine JPEG signature. Unknown system model '${systemInfo.model}'`,
50-
);
51-
}
52-
}
53-
5438
async takeImage() {
5539
try {
5640
return await spawnPromise('raspistill', [

src/lib/stream-camera.ts

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { ChildProcessWithoutNullStreams, spawn } from 'child_process';
22
import { EventEmitter } from 'events';
33
import * as stream from 'stream';
4-
import * as si from 'systeminformation';
54
import { AwbMode, ExposureMode, Flip, Rotation } from '..';
65
import { getSharedArgs } from './shared-args';
76

@@ -53,6 +52,8 @@ class StreamCamera extends EventEmitter {
5352
private childProcess?: ChildProcessWithoutNullStreams;
5453
private streams: Array<stream.Readable> = [];
5554

55+
static readonly jpegSignature = Buffer.from([0xff, 0xd8, 0xff, 0xdb, 0x00, 0x84, 0x00]);
56+
5657
constructor(options: StreamOptions = {}) {
5758
super();
5859

@@ -67,23 +68,6 @@ class StreamCamera extends EventEmitter {
6768
};
6869
}
6970

70-
static async getJpegSignature() {
71-
const systemInfo = await si.system();
72-
switch (systemInfo.model) {
73-
case 'BCM2711':
74-
case 'BCM2835 - Pi 3 Model B':
75-
case 'BCM2835 - Pi 3 Model B+':
76-
case 'BCM2835 - Pi 4 Model B':
77-
case 'BCM2835 - Pi Zero':
78-
case 'BCM2835 - Pi Zero W':
79-
return Buffer.from([0xff, 0xd8, 0xff, 0xdb, 0x00, 0x84, 0x00]);
80-
default:
81-
throw new Error(
82-
`Could not determine JPEG signature. Unknown system model '${systemInfo.model}'`,
83-
);
84-
}
85-
}
86-
8771
startCapture(): Promise<void> {
8872
// eslint-disable-next-line no-async-promise-executor
8973
return new Promise(async (resolve, reject) => {
@@ -183,7 +167,6 @@ class StreamCamera extends EventEmitter {
183167
// Wait for first data event to resolve promise
184168
this.childProcess.stdout.once('data', () => resolve());
185169

186-
const jpegSignature = await StreamCamera.getJpegSignature();
187170
let stdoutBuffer = Buffer.alloc(0);
188171

189172
// Listen for image data events and parse MJPEG frames if codec is MJPEG
@@ -196,14 +179,17 @@ class StreamCamera extends EventEmitter {
196179

197180
// Extract all image frames from the current buffer
198181
while (true) {
199-
const signatureIndex = stdoutBuffer.indexOf(jpegSignature, 0);
182+
const signatureIndex = stdoutBuffer.indexOf(StreamCamera.jpegSignature, 0);
200183

201184
if (signatureIndex === -1) break;
202185

203186
// Make sure the signature starts at the beginning of the buffer
204187
if (signatureIndex > 0) stdoutBuffer = stdoutBuffer.slice(signatureIndex);
205188

206-
const nextSignatureIndex = stdoutBuffer.indexOf(jpegSignature, jpegSignature.length);
189+
const nextSignatureIndex = stdoutBuffer.indexOf(
190+
StreamCamera.jpegSignature,
191+
StreamCamera.jpegSignature.length,
192+
);
207193

208194
if (nextSignatureIndex === -1) break;
209195

yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3969,11 +3969,6 @@ symbol-tree@^3.2.2:
39693969
version "3.2.2"
39703970
resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.2.tgz#ae27db38f660a7ae2e1c3b7d1bc290819b8519e6"
39713971

3972-
systeminformation@4:
3973-
version "4.23.0"
3974-
resolved "https://registry.yarnpkg.com/systeminformation/-/systeminformation-4.23.0.tgz#9a38262d3f6c2db4b7b5abd4808a2035c8a162c2"
3975-
integrity sha512-Gx24ttVOuqKpaGJ5bMYOt/Y7VTntc/Du6h0oh1evKPjxXdSeAcwk1+xsTxEizN3+ZuuVyoHl5hV0jtlHDOGeYA==
3976-
39773972
table@^5.2.3:
39783973
version "5.4.6"
39793974
resolved "https://registry.yarnpkg.com/table/-/table-5.4.6.tgz#1292d19500ce3f86053b05f0e8e7e4a3bb21079e"

0 commit comments

Comments
 (0)