Run a virtual iPhone on an Apple Silicon Mac.
Swift
Record movies from the virtual camera in Camera.app
Jacky3a0d01c0bf45
diff --git a/Research/0_binary_patch_comparison.md b/Research/0_binary_patch_comparison.mdindex 0ebf09af..22044caf 100644--- a/Research/0_binary_patch_comparison.md+++ b/Research/0_binary_patch_comparison.md@@ -411,9 +411,20 @@> full callback sequence it waits for before saving, and starts the preview> scan for a client that skips `-startRunning`. Camera.app's shutter saves> photos again on 27 (issue #707) and on 26.6.2, which shoots the same way.-> Video recording still does not work. Details and validation:+> Camera.app video recording followed (see the next note). Details and validation:> [`Guest/virtual_camera_transport.md`](Guest/virtual_camera_transport.md#ios-27-the-camera-through-the-backings-provider-2026-10-22).+> **Camera hook: Camera.app video recording (2026-10-22):** no new patch and+> no new library; `libcamfix.dylib` changes behaviour only. For a vcam-bound+> `AVCaptureMovieFileOutput` it writes the shm frames (and, when the session+> has a microphone input, an AVAudioEngine microphone track) to the+> requested movie with AVAssetWriter and sends the recording delegate its+> start and finish callbacks, so Camera.app's VIDEO mode saves movies on 27.0+> and 26.6.2. On 26.x it also sets `CAMCaptureCapabilities._videoSupported`,+> which comes from `AVGQVideoCameraCapability` and is NO on a guest, so the+> VIDEO tab appears. Details and validation:+> [`Guest/virtual_camera_transport.md`](Guest/virtual_camera_transport.md#cameraapp-video-recording-2026-10-22).+> **3D gyroscope core (2026-10-08; guest acceptance pending):**> `system-backboardd-cfw-gyroscope`, declared in the Guest System set and> selected by both presets on iOS 18+, installs `/usr/lib/libvphonegyro.dylib`.diff --git a/Research/Guest/virtual_camera_transport.md b/Research/Guest/virtual_camera_transport.mdindex da645ef9..e6ef6643 100644--- a/Research/Guest/virtual_camera_transport.md+++ b/Research/Guest/virtual_camera_transport.md@@ -273,11 +273,59 @@ there also shoots with `-capturePhotoWithSettings:delegate:`: with theprevious `libcamfix` the shutter saved nothing, with this one it saved thestreamed frame, through the same callback sequence.-Limit, on both: Camera.app video recording does not work. `libcamfix` has no-movie path and the daemon never runs the graph, so the timer stays at-00:00:00 and stopping saves no file. Until Camera.app is relaunched its-engine then refuses photos too.+Camera.app video recording did not work on either at this point; see+[the next section](#cameraapp-video-recording-2026-10-22).Restarting vphoned (or replacing the shared frame file) leaves the hoststreaming into the old mapping: the host notices a dead connection only whena send fails. Restart the VM, then start streaming again.++## Camera.app video recording (2026-10-22)++Camera.app's VIDEO mode records with `-[AVCaptureMovieFileOutput+startRecordingToOutputFileURL:recordingDelegate:]` into+`DCIM/.MISC/Incoming/<id>.MOV` and stops with `-stopRecording`; its+`CAMCaptureEngine` saves the file once the delegate gets+`-captureOutput:didFinishRecordingToOutputFileAtURL:fromConnections:error:`.+A vcam session's graph never runs, so the output never started: the timer+stayed at 00:00:00, no file was written, and with the request still open the+engine refused photos until Camera.app was relaunched.++`CamFix/Movie/CamFixMovieRecording.m` takes both calls for a vcam-bound+movie output and never calls the original:++- A recorder on its own queue writes the shm frame at 30 Hz with+ AVAssetWriter: H.264, 1280x720 (the frame as photos get it), in a+ QuickTime movie at the requested URL, timed from the first frame.+- After the first frame the delegate gets+ `-captureOutput:didStartRecordingToOutputFileAtURL:fromConnections:`; after+ `-stopRecording`, once the writer has finished, the didFinish callback+ with no error (or with one if the writer failed or no frame arrived).+- `-isRecording`, `-recordedDuration` and `-outputFileURL` answer for the+ recorder while it runs.+- When the session has an audio input the daemon records no sound either,+ so an AVAudioEngine input tap records the microphone into an AAC track,+ timed on the same uptime clock as the frames. The tap's buffer is copied+ into a CMSampleBuffer on the tap's thread, since the engine reuses it.++iOS 26.6.2's Camera.app lists VIDEO only when `-[CAMCaptureCapabilities+isVideoSupported]` is set. `-initWithHostProcess:` fills the `_videoSupported`+ivar behind it from `AVGestaltGetBoolAnswer(AVGQVideoCameraCapability)`,+which is NO on a guest, and other CameraUI code reads the ivar directly. The+hook sets the ivar after the initializer when the vcam device exists. iOS 27+dropped the ivar: `-[CAMUserPreferences supportedCaptureModesForCapabilities:+emulatingImagePicker:]` always adds photo and video, and+`-isSupportedMode:withDevice:` answers both with the camera. The hook does not+install there.++Validation, with the host streaming its test pattern:++| Guest | Result |+| --- | --- |+| `photo707`, iPhone17,3 27.0 | Timer counts; IMG_0013.MOV: H.264 1280x720 126 frames 4.13 s, AAC 44.1 kHz mono 4.12 s (mean -42 dB, the Mac's microphone); first and last frames differ; a photo right after the recording saves |+| `cam26`, iPhone17,3 26.6.2 | VIDEO tab appears; timer counts; IMG_0003.MOV: H.264 1280x720 130 frames 4.29 s, no audio track (the iPhone 26.x guest's Camera session has no microphone input); a photo right after saves |++No Camera, cameracaptured or assetsd crash reports on either. Not done: the+movie is landscape with no rotation metadata, like the photos; pause/resume,+slo-mo, time-lapse and cinematic modes; `-startRecordingMovieWithSettings:`+(the moment-capture movie path), which Camera.app did not call here.diff --git a/VPhoneGuestComponents/CamFix/CamFixPrivate.h b/VPhoneGuestComponents/CamFix/CamFixPrivate.hindex 0a25a816..0625a672 100644--- a/VPhoneGuestComponents/CamFix/CamFixPrivate.h+++ b/VPhoneGuestComponents/CamFix/CamFixPrivate.h@@ -67,6 +67,11 @@ CFX_HIDDEN BOOL cfx_delegate_registers_still_requests(id delegate);// full will/did/finish callback sequence for the settings' uniqueID.CFX_HIDDEN void cfx_drive_capture(id output, id delegate, id settings);+// MARK: - movies (Movie/)++CFX_HIDDEN void cfx_install_movie_recording_hooks(void);+CFX_HIDDEN void cfx_install_video_mode_capability(void);+// MARK: - preview (Preview/)CFX_HIDDEN BOOL cfx_preview_has_layers(void);diff --git a/VPhoneGuestComponents/CamFix/Movie/CamFixMovieRecording.m b/VPhoneGuestComponents/CamFix/Movie/CamFixMovieRecording.mnew file mode 100644index 00000000..cf2b9440--- /dev/null+++ b/VPhoneGuestComponents/CamFix/Movie/CamFixMovieRecording.m@@ -0,0 +1,443 @@+// AVCaptureMovieFileOutput recording for vcam sessions.+//+// Camera.app's VIDEO mode records with+// -[AVCaptureMovieFileOutput startRecordingToOutputFileURL:recordingDelegate:]+// and -stopRecording. A vcam session's capture graph never runs, so the+// output never starts: the recording timer stays at 00:00:00, no file is+// written, and CAMCaptureEngine, still waiting for its request to finish,+// refuses photos until the app is relaunched.+//+// For an output bound to the virtual camera the original is never called.+// A recorder writes the shm frame at 30 Hz into the requested file with+// AVAssetWriter (H.264 in a QuickTime movie, the frame as photos get it),+// and sends the delegate the two callbacks a real recording sends:+// -captureOutput:didStartRecordingToOutputFileAtURL:fromConnections: once+// the first frame is written, and+// -captureOutput:didFinishRecordingToOutputFileAtURL:fromConnections:error:+// once the file is finished. The output's recording getters answer for the+// recorder meanwhile.+//+// When the session has an audio input (Camera.app's VIDEO mode adds the+// microphone), the daemon records no audio either, so an AVAudioEngine input+// tap in the client records the microphone into an AAC track, timed on the+// same uptime clock as the frames. Without a usable input format the movie+// is video only.++#import "CamFixPrivate.h"++// MARK: - recorder++@interface CfxMovieRecorder : NSObject+@property(nonatomic, weak) id output;+@property(nonatomic, strong) id delegate;+@property(nonatomic, copy) NSURL *url;+@property(nonatomic, copy) NSArray *connections;+@property(nonatomic, strong) AVAssetWriter *writer;+@property(nonatomic, strong) AVAssetWriterInput *input;+@property(nonatomic, strong) AVAssetWriterInputPixelBufferAdaptor *adaptor;+@property(nonatomic, strong) AVAudioEngine *engine;+@property(nonatomic, strong) AVAudioFormat *audioFormat;+@property(nonatomic, strong) AVAssetWriterInput *audioInput;+@property(nonatomic) NSUInteger audioBuffers;+@property(nonatomic, strong) dispatch_queue_t queue;+@property(nonatomic, strong) dispatch_source_t timer;+@property(nonatomic) uint64_t startNs;+@property(nonatomic) CMTime lastTime;+@property(nonatomic) NSUInteger frames;+@property(nonatomic) BOOL started;+@property(nonatomic) BOOL stopping;+@end++@implementation CfxMovieRecorder+@end++static const void *CFX_ASSOC_RECORDER_KEY = &CFX_ASSOC_RECORDER_KEY;++static CfxMovieRecorder *cfx_recorder_for(id output) {+ return objc_getAssociatedObject(output, CFX_ASSOC_RECORDER_KEY);+}++static void cfx_recorder_set(id output, CfxMovieRecorder *recorder) {+ objc_setAssociatedObject(output, CFX_ASSOC_RECORDER_KEY, recorder,+ OBJC_ASSOCIATION_RETAIN_NONATOMIC);+}++static uint64_t cfx_now_ns(void) {+ return clock_gettime_nsec_np(CLOCK_UPTIME_RAW);+}++// The recorded length so far, zero before the first frame.+static CMTime cfx_recorder_duration(CfxMovieRecorder *r) {+ if (!r.started) return kCMTimeZero;+ return CMTimeMake((int64_t)((cfx_now_ns() - r.startNs) / 1000000ull), 1000);+}++static void cfx_send_did_start(CfxMovieRecorder *r) {+ SEL sel = @selector(captureOutput:didStartRecordingToOutputFileAtURL:fromConnections:);+ id output = r.output;+ if (!output || ![r.delegate respondsToSelector:sel]) return;+ cfxlog(@"[movie] -> didStartRecordingToOutputFileAtURL: %@", r.url.lastPathComponent);+ ((void (*)(id, SEL, id, id, id))objc_msgSend)(r.delegate, sel, output, r.url, r.connections);+}++static void cfx_send_did_finish(CfxMovieRecorder *r, NSError *error) {+ SEL sel = @selector(captureOutput:didFinishRecordingToOutputFileAtURL:fromConnections:error:);+ id output = r.output;+ if (output) cfx_recorder_set(output, nil);+ if (!output || ![r.delegate respondsToSelector:sel]) return;+ cfxlog(@"[movie] -> didFinishRecordingToOutputFileAtURL: %@ frames=%lu audio=%lu error=%@",+ r.url.lastPathComponent, (unsigned long)r.frames, (unsigned long)r.audioBuffers, error);+ ((void (*)(id, SEL, id, id, id, id))objc_msgSend)(r.delegate, sel, output, r.url,+ r.connections, error);+}++static NSError *cfx_movie_error(NSString *reason) {+ return [NSError errorWithDomain:AVFoundationErrorDomain+ code:AVErrorUnknown+ userInfo:@{NSLocalizedDescriptionKey: reason}];+}++static void cfx_recorder_stop_audio(CfxMovieRecorder *r);++// Runs on the recorder's queue. Creates the writer on the first frame, when+// the frame size is known.+static void cfx_recorder_tick(CfxMovieRecorder *r) {+ if (r.stopping) return;+ uint32_t w = 0, h = 0;+ CMSampleBufferRef sb =+ cfx_build_oriented_cmsb(VCC_FMT_420V, 0, 0, 0, 1.0, 0, NO, &w, &h);+ if (!sb) return;+ CVPixelBufferRef pb = CMSampleBufferGetImageBuffer(sb);+ if (!pb) {+ CFRelease(sb);+ return;+ }+ if (!r.writer) {+ NSError *err = nil;+ [NSFileManager.defaultManager removeItemAtURL:r.url error:NULL];+ AVAssetWriter *writer = [AVAssetWriter assetWriterWithURL:r.url+ fileType:AVFileTypeQuickTimeMovie+ error:&err];+ AVAssetWriterInput *input = [AVAssetWriterInput+ assetWriterInputWithMediaType:AVMediaTypeVideo+ outputSettings:@{+ AVVideoCodecKey: AVVideoCodecTypeH264,+ AVVideoWidthKey: @(w),+ AVVideoHeightKey: @(h),+ AVVideoCompressionPropertiesKey: @{+ AVVideoAverageBitRateKey: @(6000000),+ AVVideoExpectedSourceFrameRateKey: @(30),+ AVVideoMaxKeyFrameIntervalKey: @(30),+ },+ }];+ input.expectsMediaDataInRealTime = YES;+ if (!writer || ![writer canAddInput:input]) {+ CFRelease(sb);+ cfxlog(@"[movie] cannot create writer for %@: %@", r.url.path, err);+ r.stopping = YES;+ dispatch_source_cancel(r.timer);+ cfx_recorder_stop_audio(r);+ cfx_send_did_finish(r, cfx_movie_error(@"The recording could not be started."));+ return;+ }+ [writer addInput:input];+ if (r.audioFormat) {+ AVAssetWriterInput *audio = [AVAssetWriterInput+ assetWriterInputWithMediaType:AVMediaTypeAudio+ outputSettings:@{+ AVFormatIDKey: @(kAudioFormatMPEG4AAC),+ AVSampleRateKey: @(r.audioFormat.sampleRate),+ AVNumberOfChannelsKey: @(MIN(r.audioFormat.channelCount, 2u)),+ AVEncoderBitRateKey: @(128000),+ }+ sourceFormatHint:r.audioFormat.formatDescription];+ audio.expectsMediaDataInRealTime = YES;+ if ([writer canAddInput:audio]) {+ [writer addInput:audio];+ r.audioInput = audio;+ } else {+ cfxlog(@"[movie] audio input refused for %@; recording video only", r.audioFormat);+ }+ }+ r.adaptor = [AVAssetWriterInputPixelBufferAdaptor+ assetWriterInputPixelBufferAdaptorWithAssetWriterInput:input+ sourcePixelBufferAttributes:nil];+ if (![writer startWriting]) {+ CFRelease(sb);+ cfxlog(@"[movie] startWriting failed: %@", writer.error);+ r.stopping = YES;+ dispatch_source_cancel(r.timer);+ cfx_recorder_stop_audio(r);+ cfx_send_did_finish(r, writer.error ?: cfx_movie_error(@"The recording could not be started."));+ return;+ }+ [writer startSessionAtSourceTime:kCMTimeZero];+ r.writer = writer;+ r.input = input;+ r.startNs = cfx_now_ns();+ cfxlog(@"[movie] writing %ux%u H.264%@ to %@", w, h, r.audioInput ? @" + AAC" : @"",+ r.url.path);+ }+ CMTime t = CMTimeMake((int64_t)((cfx_now_ns() - r.startNs) / 1000000ull), 1000);+ if (r.frames == 0 || CMTimeCompare(t, r.lastTime) > 0) {+ if (r.input.readyForMoreMediaData && [r.adaptor appendPixelBuffer:pb withPresentationTime:t]) {+ r.lastTime = t;+ r.frames++;+ if (!r.started) {+ r.started = YES;+ cfx_send_did_start(r);+ }+ }+ }+ CFRelease(sb);+}++// MARK: - microphone++// YES when the output's session records sound: it has a device input whose+// device delivers audio.+static BOOL cfx_session_has_audio_input(id output) {+ @try {+ AVCaptureSession *session = [output valueForKey:@"session"];+ for (AVCaptureInput *input in session.inputs) {+ if ([input isKindOfClass:[AVCaptureDeviceInput class]] &&+ [((AVCaptureDeviceInput *)input).device hasMediaType:AVMediaTypeAudio]) {+ return YES;+ }+ }+ } @catch (NSException *e) {}+ return NO;+}++// A copy of the tap's buffer, timed from startNs, or NULL. The engine reuses+// its buffer once the tap returns, so the samples are copied here, on the+// tap's thread.+static CMSampleBufferRef cfx_audio_sample_buffer(AVAudioPCMBuffer *buffer, AVAudioTime *when,+ uint64_t startNs) CF_RETURNS_RETAINED {+ if (!buffer.frameLength) return NULL;+ uint64_t hostNs = when.hostTimeValid+ ? (uint64_t)([AVAudioTime secondsForHostTime:when.hostTime] * 1e9)+ : cfx_now_ns();+ if (hostNs < startNs) return NULL;+ CMSampleTimingInfo timing = {+ .duration = CMTimeMake(1, (int32_t)buffer.format.sampleRate),+ .presentationTimeStamp = CMTimeMake((int64_t)((hostNs - startNs) / 1000ull), 1000000),+ .decodeTimeStamp = kCMTimeInvalid,+ };+ CMSampleBufferRef sb = NULL;+ OSStatus err = CMSampleBufferCreate(kCFAllocatorDefault, NULL, false, NULL, NULL,+ buffer.format.formatDescription, buffer.frameLength, 1,+ &timing, 0, NULL, &sb);+ if (err == noErr) {+ err = CMSampleBufferSetDataBufferFromAudioBufferList(sb, kCFAllocatorDefault,+ kCFAllocatorDefault, 0,+ buffer.audioBufferList);+ }+ if (err != noErr) {+ static int logged = 0;+ if (logged++ == 0) cfxlog(@"[movie] audio sample buffer failed: %d", (int)err);+ if (sb) CFRelease(sb);+ return NULL;+ }+ return sb;+}++// Runs on the recorder's queue. Consumes sb.+static void cfx_recorder_append_audio(CfxMovieRecorder *r, CMSampleBufferRef sb) {+ if (!r.stopping && r.audioInput.readyForMoreMediaData && [r.audioInput appendSampleBuffer:sb]) {+ r.audioBuffers++;+ }+ CFRelease(sb);+}++// Starts the microphone tap. Leaves audioFormat nil, so the movie is video+// only, when the input has no usable format or the engine will not start.+static void cfx_recorder_start_audio(CfxMovieRecorder *r) {+ AVAudioEngine *engine = [AVAudioEngine new];+ AVAudioInputNode *mic = engine.inputNode;+ AVAudioFormat *format = [mic outputFormatForBus:0];+ if (format.sampleRate <= 0 || format.channelCount == 0) {+ cfxlog(@"[movie] microphone has no input format (%@); recording video only", format);+ return;+ }+ __weak CfxMovieRecorder *weak = r;+ [mic installTapOnBus:0+ bufferSize:1024+ format:format+ block:^(AVAudioPCMBuffer *buffer, AVAudioTime *when) {+ CfxMovieRecorder *strong = weak;+ // Nothing before the first frame starts the writer's+ // session at time zero.+ if (!strong.started) return;+ CMSampleBufferRef sb = cfx_audio_sample_buffer(buffer, when, strong.startNs);+ if (!sb) return;+ dispatch_async(strong.queue, ^{ cfx_recorder_append_audio(strong, sb); });+ }];+ NSError *error = nil;+ if (![engine startAndReturnError:&error]) {+ [mic removeTapOnBus:0];+ cfxlog(@"[movie] microphone did not start (%@); recording video only", error);+ return;+ }+ r.engine = engine;+ r.audioFormat = format;+ cfxlog(@"[movie] microphone %@", format);+}++static void cfx_recorder_stop_audio(CfxMovieRecorder *r) {+ if (!r.engine) return;+ [r.engine.inputNode removeTapOnBus:0];+ [r.engine stop];+ r.engine = nil;+}++// Runs on the recorder's queue.+static void cfx_recorder_finish(CfxMovieRecorder *r) {+ if (r.stopping) return;+ r.stopping = YES;+ dispatch_source_cancel(r.timer);+ cfx_recorder_stop_audio(r);+ if (!r.writer || r.frames == 0) {+ cfxlog(@"[movie] stopped before any frame was written");+ [r.writer cancelWriting];+ cfx_send_did_finish(r, cfx_movie_error(@"No camera frames were recorded."));+ return;+ }+ [r.input markAsFinished];+ [r.audioInput markAsFinished];+ [r.writer endSessionAtSourceTime:r.lastTime];+ [r.writer finishWritingWithCompletionHandler:^{+ dispatch_async(r.queue, ^{+ NSError *error = r.writer.status == AVAssetWriterStatusCompleted ? nil : r.writer.error;+ cfx_send_did_finish(r, error);+ });+ }];+}++// MARK: - AVCaptureMovieFileOutput hooks++static IMP cfx_orig_movie_start = NULL;+static IMP cfx_orig_movie_stop = NULL;+static IMP cfx_orig_movie_isRecording = NULL;+static IMP cfx_orig_movie_recordedDuration = NULL;+static IMP cfx_orig_movie_outputFileURL = NULL;++static void cfx_movie_start_hook(id self, SEL _cmd, NSURL *url, id delegate) {+ if (!cfx_output_is_for_vcam(self)) {+ ((void (*)(id, SEL, NSURL *, id))cfx_orig_movie_start)(self, _cmd, url, delegate);+ return;+ }+ cfxlog(@"[movie] startRecordingToOutputFileURL: %@ delegate=%@", url.path, delegate);+ CfxMovieRecorder *previous = cfx_recorder_for(self);+ if (previous) {+ dispatch_async(previous.queue, ^{ cfx_recorder_finish(previous); });+ }+ CfxMovieRecorder *r = [CfxMovieRecorder new];+ r.output = self;+ r.delegate = delegate;+ r.url = url;+ @try { r.connections = [self valueForKey:@"connections"]; } @catch (NSException *e) {}+ r.queue = dispatch_queue_create("com.vphone.camfix.movie", DISPATCH_QUEUE_SERIAL);+ r.timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, r.queue);+ dispatch_source_set_timer(r.timer, dispatch_time(DISPATCH_TIME_NOW, 0),+ NSEC_PER_SEC / 30, NSEC_PER_MSEC);+ __weak CfxMovieRecorder *weak = r;+ dispatch_source_set_event_handler(r.timer, ^{+ @autoreleasepool {+ CfxMovieRecorder *strong = weak;+ if (strong) cfx_recorder_tick(strong);+ }+ });+ if (cfx_session_has_audio_input(self)) cfx_recorder_start_audio(r);+ cfx_recorder_set(self, r);+ dispatch_resume(r.timer);+}++static void cfx_movie_stop_hook(id self, SEL _cmd) {+ CfxMovieRecorder *r = cfx_recorder_for(self);+ if (!r) {+ ((void (*)(id, SEL))cfx_orig_movie_stop)(self, _cmd);+ return;+ }+ cfxlog(@"[movie] stopRecording after %lu frame(s)", (unsigned long)r.frames);+ dispatch_async(r.queue, ^{ cfx_recorder_finish(r); });+}++static BOOL cfx_movie_isRecording_hook(id self, SEL _cmd) {+ CfxMovieRecorder *r = cfx_recorder_for(self);+ if (r) return r.started && !r.stopping;+ return ((BOOL (*)(id, SEL))cfx_orig_movie_isRecording)(self, _cmd);+}++static CMTime cfx_movie_recordedDuration_hook(id self, SEL _cmd) {+ CfxMovieRecorder *r = cfx_recorder_for(self);+ if (r) return cfx_recorder_duration(r);+ return ((CMTime (*)(id, SEL))cfx_orig_movie_recordedDuration)(self, _cmd);+}++static NSURL *cfx_movie_outputFileURL_hook(id self, SEL _cmd) {+ CfxMovieRecorder *r = cfx_recorder_for(self);+ if (r) return r.url;+ return ((NSURL * (*)(id, SEL)) cfx_orig_movie_outputFileURL)(self, _cmd);+}++static void cfx_swizzle(Class cls, SEL sel, IMP imp, IMP *orig) {+ Method m = class_getInstanceMethod(cls, sel);+ if (!m) {+ cfxlog(@"[movie] -[%s %@] missing", class_getName(cls), NSStringFromSelector(sel));+ return;+ }+ *orig = method_setImplementation(m, imp);+}++void cfx_install_movie_recording_hooks(void) {+ Class cls = NSClassFromString(@"AVCaptureMovieFileOutput");+ if (!cls) {+ cfxlog(@"AVCaptureMovieFileOutput missing");+ return;+ }+ cfx_swizzle(cls, @selector(startRecordingToOutputFileURL:recordingDelegate:),+ (IMP)cfx_movie_start_hook, &cfx_orig_movie_start);+ cfx_swizzle(cls, @selector(stopRecording), (IMP)cfx_movie_stop_hook, &cfx_orig_movie_stop);+ cfx_swizzle(cls, @selector(isRecording), (IMP)cfx_movie_isRecording_hook,+ &cfx_orig_movie_isRecording);+ cfx_swizzle(cls, @selector(recordedDuration), (IMP)cfx_movie_recordedDuration_hook,+ &cfx_orig_movie_recordedDuration);+ cfx_swizzle(cls, @selector(outputFileURL), (IMP)cfx_movie_outputFileURL_hook,+ &cfx_orig_movie_outputFileURL);+ cfxlog(@"installed movie recording hooks");+}++// MARK: - Camera.app's VIDEO mode (iOS 26)+//+// Camera.app on 26.x lists VIDEO only when -[CAMCaptureCapabilities+// isVideoSupported] is set, and -initWithHostProcess: sets the+// _videoSupported ivar it reads from AVGestaltGetBoolAnswer(+// AVGQVideoCameraCapability), which is NO on a guest. Other CameraUI code+// reads the ivar directly, so it is the ivar that is set, once the+// initializer returns and only when the vcam device is there. iOS 27 dropped+// the ivar and lists VIDEO with the camera; this does nothing there.++static IMP cfx_orig_capabilities_init = NULL;++__attribute__((ns_returns_retained))+static id cfx_capabilities_init_hook(id self, SEL _cmd, id hostProcess) {+ typedef id (*Fn)(id, SEL, id);+ id caps = ((Fn)cfx_orig_capabilities_init)(self, _cmd, hostProcess);+ Ivar iv = caps ? class_getInstanceVariable(object_getClass(caps), "_videoSupported") : NULL;+ if (!iv) return caps;+ BOOL *flag = (BOOL *)((char *)(__bridge void *)caps + ivar_getOffset(iv));+ if (!*flag && [AVCaptureDevice deviceWithUniqueID:VCAM_UID]) {+ *flag = YES;+ cfxlog(@"[movie] CAMCaptureCapabilities: video supported (vcam device present)");+ }+ return caps;+}++void cfx_install_video_mode_capability(void) {+ Class cls = NSClassFromString(@"CAMCaptureCapabilities");+ if (!cls || !class_getInstanceVariable(cls, "_videoSupported")) return;+ cfx_swizzle(cls, NSSelectorFromString(@"initWithHostProcess:"),+ (IMP)cfx_capabilities_init_hook, &cfx_orig_capabilities_init);+ cfxlog(@"installed CAMCaptureCapabilities video mode hook");+}diff --git a/VPhoneGuestComponents/CamFix/libcamfix.m b/VPhoneGuestComponents/CamFix/libcamfix.mindex 51b6ba8e..8a6732ee 100644--- a/VPhoneGuestComponents/CamFix/libcamfix.m+++ b/VPhoneGuestComponents/CamFix/libcamfix.m@@ -63,6 +63,11 @@* H.264 at the delivered size instead of 0x0.* (Session/CamFixAssetWriterSettings.m)*+ * 12. AVCaptureMovieFileOutput recording: the shm frames are written to the+ * requested movie file and the recording delegate gets its start and+ * finish callbacks, so Camera.app's VIDEO mode saves a movie.+ * (Movie/CamFixMovieRecording.m)+ ** Frames come from the vphoned shared frame file through the shared data* plane (Frame/CamFixFrameSource.m). Diagnostics go to the shared camera* media directory, written by cfxlog.@@ -98,6 +103,8 @@ static void cfx_install_all_hooks(void) {cfx_install_preview_layer_hooks();cfx_install_photo_representation_hooks();cfx_install_capturerequest_stubs();+ cfx_install_movie_recording_hooks();+ cfx_install_video_mode_capability();cfx_install_remote_queue_tap();// The 1 Hz preview layer scan starts with the first running vcam session// (Session/CamFixSessionGuards.m), not here: this hook also loads into