Post

Replies

Boosts

Views

Activity

macOS console application with AVCaptureDevice
I am working on a console app (Actually a library, but designed to be used from console), where I want to be able to enumerate the AVCaptureDevices at runtime. Attempting to do this however, I am noticing that the AVCaptureDevice devices property is never updating. I have some minimal code to reproduce this. Run it with a USB camera plugged in, and as you unplug and replug the camera in the output never changes, and it says there are devices that don't actually exist. Note I am not running this in a UI application, so there is no standard loop. Its just meant to be running from a standard "c" main.#import <Foundation/Foundation.h> #import <AVFoundation/AVFoundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { while (true) { NSArray* captureDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]; for (id device in captureDevices) { NSString* uniqueIdentifier = [(AVCaptureDevice*)device uniqueID]; NSLog(uniqueIdentifier); } usleep(1000000); } } return 0; }Thanks for any help. I would be ok firing up a message loop in a background thread if I needed to, but I can't guarentee that the user application has a message loop (sorry if terminology is different, I come from windows).
4
0
1.1k
Dec ’21