serve-sim 0.1.38 → 0.1.40-beta.66.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Sources/SimCameraInjector/SimCamFakes.h +2 -0
- package/Sources/SimCameraInjector/SimCamFakes.m +71 -2
- package/Sources/SimCameraInjector/SimCamSwizzles.m +42 -2
- package/bin/serve-sim-bin +0 -0
- package/dist/serve-sim.js +61 -61
- package/dist/simcam/libSimCameraInjector.dylib +0 -0
- package/package.json +1 -1
|
@@ -72,6 +72,8 @@ AVCaptureDevice *SimCamFakeDeviceForPosition(AVCaptureDevicePosition p);
|
|
|
72
72
|
AVCaptureDeviceInput *SimCamFakeInputForPosition(AVCaptureDevicePosition p);
|
|
73
73
|
|
|
74
74
|
AVCaptureConnection *SimCamFakeConnectionForOutput(AVCaptureOutput *out);
|
|
75
|
+
void SimCamSetOutputInput(AVCaptureOutput *out, AVCaptureInput *input);
|
|
76
|
+
AVCaptureInput *SimCamOutputInput(AVCaptureOutput *out);
|
|
75
77
|
|
|
76
78
|
CMAttitude *SimCamSharedAttitude(void);
|
|
77
79
|
CMAccelerometerData *SimCamSharedAccelerometerData(void);
|
|
@@ -149,6 +149,8 @@ void SimCamLogSwallowedRuntimeError(NSString *via, id object, NSDictionary *user
|
|
|
149
149
|
- (NSArray *)supportedColorSpaces { return @[]; }
|
|
150
150
|
- (NSArray *)supportedDepthDataFormats { return @[]; }
|
|
151
151
|
- (BOOL)isPortraitEffectSupported { return NO; }
|
|
152
|
+
- (NSArray<Class> *)unsupportedCaptureOutputClasses { return @[]; }
|
|
153
|
+
- (BOOL)isStreamingDisparitySupported { return NO; }
|
|
152
154
|
- (float)minISO { return 25.0f; }
|
|
153
155
|
- (float)maxISO { return 6400.0f; }
|
|
154
156
|
- (CMTime)minExposureDuration { return CMTimeMake(1, 8000); }
|
|
@@ -286,6 +288,8 @@ AVCaptureDevice *SimCamFakeDeviceForPosition(AVCaptureDevicePosition p) {
|
|
|
286
288
|
- (AVCaptureVideoOrientation)_videoOrientation;
|
|
287
289
|
@end
|
|
288
290
|
|
|
291
|
+
static AVCaptureInputPort *SimCamFakeInputPortForInput(AVCaptureInput *input, AVCaptureDevicePosition position);
|
|
292
|
+
|
|
289
293
|
@implementation SimCamFakeConnection {
|
|
290
294
|
__weak AVCaptureOutput *_outputRef;
|
|
291
295
|
AVCaptureDevicePosition _position;
|
|
@@ -311,8 +315,12 @@ AVCaptureDevice *SimCamFakeDeviceForPosition(AVCaptureDevicePosition p) {
|
|
|
311
315
|
return c;
|
|
312
316
|
}
|
|
313
317
|
- (AVCaptureOutput *)output { return _outputRef; }
|
|
314
|
-
- (NSArray *)inputPorts {
|
|
315
|
-
|
|
318
|
+
- (NSArray *)inputPorts {
|
|
319
|
+
AVCaptureInput *input = SimCamOutputInput(_outputRef) ?: SimCamFakeInputForPosition(_position);
|
|
320
|
+
AVCaptureInputPort *port = SimCamFakeInputPortForInput(input, _position);
|
|
321
|
+
return port ? @[port] : @[];
|
|
322
|
+
}
|
|
323
|
+
- (AVCaptureInput *)input { return SimCamOutputInput(_outputRef) ?: SimCamFakeInputForPosition(_position); }
|
|
316
324
|
- (AVCaptureVideoPreviewLayer *)videoPreviewLayer { return nil; }
|
|
317
325
|
- (BOOL)isEnabled { return _enabled; }
|
|
318
326
|
- (void)setEnabled:(BOOL)e { _enabled = e; }
|
|
@@ -411,6 +419,67 @@ AVCaptureConnection *SimCamFakeConnectionForOutput(AVCaptureOutput *out) {
|
|
|
411
419
|
return conn;
|
|
412
420
|
}
|
|
413
421
|
|
|
422
|
+
#pragma mark - SimCamFakeInputPort
|
|
423
|
+
|
|
424
|
+
@interface SimCamFakeInputPort : AVCaptureInputPort
|
|
425
|
+
@end
|
|
426
|
+
|
|
427
|
+
@implementation SimCamFakeInputPort {
|
|
428
|
+
__weak AVCaptureInput *_inputRef;
|
|
429
|
+
AVCaptureDevicePosition _position;
|
|
430
|
+
}
|
|
431
|
+
+ (instancetype)allocWithZone:(NSZone *)zone {
|
|
432
|
+
return class_createInstance([SimCamFakeInputPort class], 0);
|
|
433
|
+
}
|
|
434
|
+
+ (instancetype)portForInput:(AVCaptureInput *)input position:(AVCaptureDevicePosition)position {
|
|
435
|
+
SimCamFakeInputPort *p = [self alloc];
|
|
436
|
+
if (p) {
|
|
437
|
+
p->_inputRef = input;
|
|
438
|
+
p->_position = position;
|
|
439
|
+
}
|
|
440
|
+
return p;
|
|
441
|
+
}
|
|
442
|
+
- (AVCaptureInput *)input { return _inputRef; }
|
|
443
|
+
- (AVMediaType)mediaType { return AVMediaTypeVideo; }
|
|
444
|
+
- (AVCaptureDeviceType)sourceDeviceType { return AVCaptureDeviceTypeBuiltInWideAngleCamera; }
|
|
445
|
+
- (AVCaptureDevicePosition)sourceDevicePosition { return _position; }
|
|
446
|
+
- (CMFormatDescriptionRef)formatDescription { return SimCamSharedFakeFormat().formatDescription; }
|
|
447
|
+
- (BOOL)isEnabled { return YES; }
|
|
448
|
+
- (void)setEnabled:(BOOL)enabled { (void)enabled; }
|
|
449
|
+
@end
|
|
450
|
+
|
|
451
|
+
static char kSimCamOutputInputRefKey;
|
|
452
|
+
static char kSimCamFakeInputPortKey;
|
|
453
|
+
|
|
454
|
+
void SimCamSetOutputInput(AVCaptureOutput *out, AVCaptureInput *input) {
|
|
455
|
+
if (!out) return;
|
|
456
|
+
if (!input) {
|
|
457
|
+
objc_setAssociatedObject(out, &kSimCamOutputInputRefKey, nil, OBJC_ASSOCIATION_RETAIN);
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
SimCamWeakRef *ref = [SimCamWeakRef new];
|
|
461
|
+
ref.target = input;
|
|
462
|
+
objc_setAssociatedObject(out, &kSimCamOutputInputRefKey, ref, OBJC_ASSOCIATION_RETAIN);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
AVCaptureInput *SimCamOutputInput(AVCaptureOutput *out) {
|
|
466
|
+
if (!out) return nil;
|
|
467
|
+
SimCamWeakRef *ref = objc_getAssociatedObject(out, &kSimCamOutputInputRefKey);
|
|
468
|
+
return ref.target;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
static AVCaptureInputPort *SimCamFakeInputPortForInput(AVCaptureInput *input, AVCaptureDevicePosition position) {
|
|
472
|
+
if (!input) return nil;
|
|
473
|
+
AVCaptureInputPort *port = objc_getAssociatedObject(input, &kSimCamFakeInputPortKey);
|
|
474
|
+
if (!port) {
|
|
475
|
+
port = (AVCaptureInputPort *)[SimCamFakeInputPort portForInput:input position:position];
|
|
476
|
+
if (port) {
|
|
477
|
+
objc_setAssociatedObject(input, &kSimCamFakeInputPortKey, port, OBJC_ASSOCIATION_RETAIN);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
return port;
|
|
481
|
+
}
|
|
482
|
+
|
|
414
483
|
#pragma mark - SimCamFakeInput marking
|
|
415
484
|
|
|
416
485
|
static char kSimCamFakeInputKey;
|
|
@@ -200,6 +200,7 @@ static BOOL SwizzleInstanceMethod(Class cls, SEL orig, SEL swiz) {
|
|
|
200
200
|
static char kSimCamSessionRunningKey;
|
|
201
201
|
static char kSimCamSessionInputsKey;
|
|
202
202
|
static char kSimCamSessionOutputsKey;
|
|
203
|
+
static char kSimCamOutputAttachedToFakeSessionKey;
|
|
203
204
|
|
|
204
205
|
static NSMutableArray *SimCamSessionTrackedInputs(AVCaptureSession *s) {
|
|
205
206
|
NSMutableArray *arr = objc_getAssociatedObject(s, &kSimCamSessionInputsKey);
|
|
@@ -218,6 +219,39 @@ static NSMutableArray *SimCamSessionTrackedOutputs(AVCaptureSession *s) {
|
|
|
218
219
|
return arr;
|
|
219
220
|
}
|
|
220
221
|
|
|
222
|
+
static AVCaptureInput *SimCamFirstFakeInputForSession(AVCaptureSession *s) {
|
|
223
|
+
for (AVCaptureInput *candidate in SimCamSessionTrackedInputs(s)) {
|
|
224
|
+
if (SimCamIsFakeInput(candidate)) return candidate;
|
|
225
|
+
}
|
|
226
|
+
return nil;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Real AVFoundation only exposes output connections after an output has been
|
|
230
|
+
// attached to a session. Keep this per-output so newly created outputs still
|
|
231
|
+
// look disconnected during client-side session configuration checks.
|
|
232
|
+
static void SimCamMarkOutputAttachedToFakeSession(AVCaptureSession *s, AVCaptureOutput *output) {
|
|
233
|
+
if (!output) return;
|
|
234
|
+
objc_setAssociatedObject(output, &kSimCamOutputAttachedToFakeSessionKey, @YES, OBJC_ASSOCIATION_RETAIN);
|
|
235
|
+
SimCamSetOutputInput(output, SimCamFirstFakeInputForSession(s));
|
|
236
|
+
}
|
|
237
|
+
static void SimCamUnmarkOutputAttachedToFakeSession(AVCaptureOutput *output) {
|
|
238
|
+
if (!output) return;
|
|
239
|
+
objc_setAssociatedObject(output, &kSimCamOutputAttachedToFakeSessionKey, nil, OBJC_ASSOCIATION_RETAIN);
|
|
240
|
+
SimCamSetOutputInput(output, nil);
|
|
241
|
+
}
|
|
242
|
+
static BOOL SimCamOutputAttachedToFakeSession(AVCaptureOutput *output) {
|
|
243
|
+
if (!output) return NO;
|
|
244
|
+
return [objc_getAssociatedObject(output, &kSimCamOutputAttachedToFakeSessionKey) boolValue];
|
|
245
|
+
}
|
|
246
|
+
static void SimCamRefreshAttachedOutputInputsForSession(AVCaptureSession *s) {
|
|
247
|
+
AVCaptureInput *input = SimCamFirstFakeInputForSession(s);
|
|
248
|
+
for (AVCaptureOutput *output in SimCamSessionTrackedOutputs(s)) {
|
|
249
|
+
if (SimCamOutputAttachedToFakeSession(output)) {
|
|
250
|
+
SimCamSetOutputInput(output, input);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
221
255
|
@interface AVCaptureSession (SimCam)
|
|
222
256
|
@end
|
|
223
257
|
@implementation AVCaptureSession (SimCam)
|
|
@@ -229,6 +263,7 @@ static NSMutableArray *SimCamSessionTrackedOutputs(AVCaptureSession *s) {
|
|
|
229
263
|
SimCamMarkSessionUsingFakeCamera(self, YES);
|
|
230
264
|
NSMutableArray *tracked = SimCamSessionTrackedInputs(self);
|
|
231
265
|
if (![tracked containsObject:input]) [tracked addObject:input];
|
|
266
|
+
SimCamRefreshAttachedOutputInputsForSession(self);
|
|
232
267
|
simcam_log(@"addInput: fake input (%@) — tracked (count=%lu), skipping native add",
|
|
233
268
|
p == AVCaptureDevicePositionBack ? @"back" : @"front",
|
|
234
269
|
(unsigned long)tracked.count);
|
|
@@ -248,6 +283,7 @@ static NSMutableArray *SimCamSessionTrackedOutputs(AVCaptureSession *s) {
|
|
|
248
283
|
SimCamMarkSessionUsingFakeCamera(self, YES);
|
|
249
284
|
NSMutableArray *tracked = SimCamSessionTrackedInputs(self);
|
|
250
285
|
if (![tracked containsObject:input]) [tracked addObject:input];
|
|
286
|
+
SimCamRefreshAttachedOutputInputsForSession(self);
|
|
251
287
|
simcam_log(@"addInputWithNoConnections: fake input (%@) — tracked (count=%lu), skipping native add",
|
|
252
288
|
p == AVCaptureDevicePositionBack ? @"back" : @"front",
|
|
253
289
|
(unsigned long)tracked.count);
|
|
@@ -259,6 +295,7 @@ static NSMutableArray *SimCamSessionTrackedOutputs(AVCaptureSession *s) {
|
|
|
259
295
|
if (SimCamIsFakeInput(input)) {
|
|
260
296
|
NSMutableArray *tracked = SimCamSessionTrackedInputs(self);
|
|
261
297
|
[tracked removeObject:input];
|
|
298
|
+
SimCamRefreshAttachedOutputInputsForSession(self);
|
|
262
299
|
if (tracked.count == 0) SimCamMarkSessionUsingFakeCamera(self, NO);
|
|
263
300
|
simcam_log(@"removeInput: fake input — untracked (count=%lu)",
|
|
264
301
|
(unsigned long)tracked.count);
|
|
@@ -268,6 +305,7 @@ static NSMutableArray *SimCamSessionTrackedOutputs(AVCaptureSession *s) {
|
|
|
268
305
|
}
|
|
269
306
|
- (void)simcam_addOutput:(AVCaptureOutput *)output {
|
|
270
307
|
SimCamSetPosition(output, SimCamPositionOf(self));
|
|
308
|
+
SimCamMarkOutputAttachedToFakeSession(self, output);
|
|
271
309
|
SimCamMarkCameraInUse();
|
|
272
310
|
NSMutableArray *tracked = SimCamSessionTrackedOutputs(self);
|
|
273
311
|
if (![tracked containsObject:output]) [tracked addObject:output];
|
|
@@ -279,6 +317,7 @@ static NSMutableArray *SimCamSessionTrackedOutputs(AVCaptureSession *s) {
|
|
|
279
317
|
- (BOOL)simcam_canAddOutput:(AVCaptureOutput *)output { return YES; }
|
|
280
318
|
- (void)simcam_addOutputWithNoConnections:(AVCaptureOutput *)output {
|
|
281
319
|
SimCamSetPosition(output, SimCamPositionOf(self));
|
|
320
|
+
SimCamMarkOutputAttachedToFakeSession(self, output);
|
|
282
321
|
SimCamMarkCameraInUse();
|
|
283
322
|
NSMutableArray *tracked = SimCamSessionTrackedOutputs(self);
|
|
284
323
|
if (![tracked containsObject:output]) [tracked addObject:output];
|
|
@@ -288,6 +327,7 @@ static NSMutableArray *SimCamSessionTrackedOutputs(AVCaptureSession *s) {
|
|
|
288
327
|
(int)SimCamPositionOf(self));
|
|
289
328
|
}
|
|
290
329
|
- (void)simcam_removeOutput:(AVCaptureOutput *)output {
|
|
330
|
+
SimCamUnmarkOutputAttachedToFakeSession(output);
|
|
291
331
|
NSMutableArray *tracked = SimCamSessionTrackedOutputs(self);
|
|
292
332
|
[tracked removeObject:output];
|
|
293
333
|
simcam_log(@"removeOutput: %@ — untracked (count=%lu)",
|
|
@@ -436,7 +476,7 @@ static NSMutableArray *SimCamSessionTrackedOutputs(AVCaptureSession *s) {
|
|
|
436
476
|
- (AVCaptureConnection *)simcam_connectionWithMediaType:(AVMediaType)mediaType {
|
|
437
477
|
AVCaptureConnection *real = [self simcam_connectionWithMediaType:mediaType];
|
|
438
478
|
if (real) return real;
|
|
439
|
-
if (!
|
|
479
|
+
if (!SimCamOutputAttachedToFakeSession(self)) return nil;
|
|
440
480
|
if (![mediaType isEqualToString:AVMediaTypeVideo]) return nil;
|
|
441
481
|
AVCaptureConnection *fake = SimCamFakeConnectionForOutput(self);
|
|
442
482
|
simcam_log(@"connectionWithMediaType:%@ → fake %p for %@ %p",
|
|
@@ -446,7 +486,7 @@ static NSMutableArray *SimCamSessionTrackedOutputs(AVCaptureSession *s) {
|
|
|
446
486
|
- (NSArray<AVCaptureConnection *> *)simcam_connections {
|
|
447
487
|
NSArray *real = [self simcam_connections];
|
|
448
488
|
if (real.count > 0) return real;
|
|
449
|
-
if (!
|
|
489
|
+
if (!SimCamOutputAttachedToFakeSession(self)) return real ?: @[];
|
|
450
490
|
AVCaptureConnection *fake = SimCamFakeConnectionForOutput(self);
|
|
451
491
|
return fake ? @[fake] : @[];
|
|
452
492
|
}
|
package/bin/serve-sim-bin
CHANGED
|
Binary file
|