1
1
import { ChildProcessWithoutNullStreams , spawn } from 'child_process' ;
2
2
import { EventEmitter } from 'events' ;
3
3
import * as stream from 'stream' ;
4
- import * as si from 'systeminformation' ;
5
4
import { AwbMode , ExposureMode , Flip , Rotation } from '..' ;
6
5
import { getSharedArgs } from './shared-args' ;
7
6
@@ -53,6 +52,8 @@ class StreamCamera extends EventEmitter {
53
52
private childProcess ?: ChildProcessWithoutNullStreams ;
54
53
private streams : Array < stream . Readable > = [ ] ;
55
54
55
+ static readonly jpegSignature = Buffer . from ( [ 0xff , 0xd8 , 0xff , 0xdb , 0x00 , 0x84 , 0x00 ] ) ;
56
+
56
57
constructor ( options : StreamOptions = { } ) {
57
58
super ( ) ;
58
59
@@ -67,23 +68,6 @@ class StreamCamera extends EventEmitter {
67
68
} ;
68
69
}
69
70
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
-
87
71
startCapture ( ) : Promise < void > {
88
72
// eslint-disable-next-line no-async-promise-executor
89
73
return new Promise ( async ( resolve , reject ) => {
@@ -183,7 +167,6 @@ class StreamCamera extends EventEmitter {
183
167
// Wait for first data event to resolve promise
184
168
this . childProcess . stdout . once ( 'data' , ( ) => resolve ( ) ) ;
185
169
186
- const jpegSignature = await StreamCamera . getJpegSignature ( ) ;
187
170
let stdoutBuffer = Buffer . alloc ( 0 ) ;
188
171
189
172
// Listen for image data events and parse MJPEG frames if codec is MJPEG
@@ -196,14 +179,17 @@ class StreamCamera extends EventEmitter {
196
179
197
180
// Extract all image frames from the current buffer
198
181
while ( true ) {
199
- const signatureIndex = stdoutBuffer . indexOf ( jpegSignature , 0 ) ;
182
+ const signatureIndex = stdoutBuffer . indexOf ( StreamCamera . jpegSignature , 0 ) ;
200
183
201
184
if ( signatureIndex === - 1 ) break ;
202
185
203
186
// Make sure the signature starts at the beginning of the buffer
204
187
if ( signatureIndex > 0 ) stdoutBuffer = stdoutBuffer . slice ( signatureIndex ) ;
205
188
206
- const nextSignatureIndex = stdoutBuffer . indexOf ( jpegSignature , jpegSignature . length ) ;
189
+ const nextSignatureIndex = stdoutBuffer . indexOf (
190
+ StreamCamera . jpegSignature ,
191
+ StreamCamera . jpegSignature . length ,
192
+ ) ;
207
193
208
194
if ( nextSignatureIndex === - 1 ) break ;
209
195
0 commit comments