Skip to content

Commit

Permalink
Update for macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
yushulx committed Jan 14, 2025
1 parent 21d7cd6 commit 00468f9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
Binary file modified litecam/dist/lib/macos/liblitecam.dylib
Binary file not shown.
37 changes: 26 additions & 11 deletions litecam/src/CameraMacOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ - (void)captureOutput:(AVCaptureOutput *)output
}

AVCaptureSession *cs = [[AVCaptureSession alloc] init];
captureSession = (void *)cs;
captureSession = (__bridge void *)cs;
if (![cs canAddInput:input])
{
std::cerr << "Cannot add device input to session." << std::endl;
Expand All @@ -131,7 +131,7 @@ - (void)captureOutput:(AVCaptureOutput *)output
output.videoSettings = @{(NSString *)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32BGRA)};
output.alwaysDiscardsLateVideoFrames = YES;

videoOutput = (void *)output;
videoOutput = (__bridge void *)output;

if (![cs canAddOutput:output])
{
Expand Down Expand Up @@ -265,38 +265,53 @@ - (void)captureOutput:(AVCaptureOutput *)output

AVCaptureSession *session = (__bridge AVCaptureSession *)captureSession;

if (!session || session.inputs.count == 0) {
if (!session || session.inputs.count == 0)
{
std::cerr << "No inputs found in capture session." << std::endl;
return mediaTypes;
}

AVCaptureDeviceInput *input = (__bridge AVCaptureDeviceInput *)session.inputs.firstObject;
AVCaptureDevice *device = input.device;
AVCaptureDeviceInput *input = nil;
if ([session.inputs.firstObject isKindOfClass:[AVCaptureDeviceInput class]])
{
input = (AVCaptureDeviceInput *)session.inputs.firstObject;
}
else
{
std::cerr << "Error: First input is not an AVCaptureDeviceInput." << std::endl;
return mediaTypes;
}

if (!device) {
AVCaptureDevice *device = input.device;
if (!device)
{
std::cerr << "No device found." << std::endl;
return mediaTypes;
}

for (AVCaptureDeviceFormat *format in device.formats) {
// Iterate over all available formats for the device
for (AVCaptureDeviceFormat *format in device.formats)
{
MediaTypeInfo mediaType = {};
CMFormatDescriptionRef formatDescription = format.formatDescription;
FourCharCode mediaSubType = CMFormatDescriptionGetMediaSubType(formatDescription);

// Store width and height
// Get width and height from format description
CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription);
mediaType.width = dimensions.width;
mediaType.height = dimensions.height;

// Convert mediaSubType to a string
snprintf(mediaType.subtypeName, sizeof(mediaType.subtypeName), "Format %.4s", (char *)&mediaSubType);
// Convert FourCharCode (mediaSubType) to a readable string
snprintf(mediaType.subtypeName, sizeof(mediaType.subtypeName), "%.4s", (char *)&mediaSubType);

// Add the media type info to the list
mediaTypes.push_back(mediaType);
}

return mediaTypes;
}


void ReleaseFrame(FrameData &frame)
{
if (frame.rgbData)
Expand Down Expand Up @@ -324,4 +339,4 @@ void saveFrameAsJPEG(const unsigned char *data, int width, int height, const std
std::cerr << "Error saving frame as JPEG." << std::endl;
}
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

0 comments on commit 00468f9

Please sign in to comment.