Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions libs/openFrameworks/video/ofAVFoundationGrabber.mm
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,27 @@ - (BOOL)initCapture:(int)framerate capWidth:(int)w capHeight:(int)h{
devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
#pragma clang diagnostic pop
}

if([devices count] > 1) {
// Sort devices: "FaceTime" devices first, then alphabetically
devices = [devices sortedArrayUsingComparator:^NSComparisonResult(AVCaptureDevice *d1, AVCaptureDevice *d2) {
NSString *name1 = d1.localizedName;
NSString *name2 = d2.localizedName;

BOOL isFaceTime1 = [name1 hasPrefix:@"FaceTime"];
BOOL isFaceTime2 = [name2 hasPrefix:@"FaceTime"];

if (isFaceTime1 && !isFaceTime2) {
return NSOrderedAscending; // FaceTime first
} else if (!isFaceTime1 && isFaceTime2) {
return NSOrderedDescending; // FaceTime first
} else {
// Otherwise alphabetical
return [name1 compare:name2];
}
}];
}

if([devices count] > 0) {
if(deviceID>[devices count]-1)
deviceID = [devices count]-1;
Expand Down Expand Up @@ -284,6 +305,26 @@ -(CGImageRef)getCurrentFrame{
#pragma clang diagnostic pop
}

if([devices count] > 1) {
// Sort devices: "FaceTime" devices first, then alphabetically
devices = [devices sortedArrayUsingComparator:^NSComparisonResult(AVCaptureDevice *d1, AVCaptureDevice *d2) {
NSString *name1 = d1.localizedName;
NSString *name2 = d2.localizedName;

BOOL isFaceTime1 = [name1 hasPrefix:@"FaceTime"];
BOOL isFaceTime2 = [name2 hasPrefix:@"FaceTime"];

if (isFaceTime1 && !isFaceTime2) {
return NSOrderedAscending; // FaceTime first
} else if (!isFaceTime1 && isFaceTime2) {
return NSOrderedDescending; // FaceTime first
} else {
// Otherwise alphabetical
return [name1 compare:name2];
}
}];
}

int i=0;
for (AVCaptureDevice * captureDevice in devices){
deviceNames.push_back([captureDevice.localizedName UTF8String]);
Expand Down