[cscore] Fix USB video mode handling on macOS (#7904)

* fix: UsbCameraImpl on macOS

* fix: add back logs
This commit is contained in:
Yuhao
2025-04-22 00:27:42 +08:00
committed by GitHub
parent 07192285f6
commit 26e299115f
2 changed files with 16 additions and 12 deletions

View File

@@ -91,6 +91,5 @@ class UsbCameraImpl : public SourceImpl {
private:
UsbCameraImplObjc* m_objc;
std::vector<CameraModeStore> m_platformModes;
VideoMode m_mode;
};
} // namespace cs

View File

@@ -380,22 +380,27 @@ static cs::VideoMode::PixelFormat FourCCToPixelFormat(FourCharCode fourcc) {
toCheck->height, toCheck->fps);
std::vector<CameraModeStore>& platformModes =
sharedThis->objcGetPlatformVideoModes();
// Find the matching mode
auto match = std::find_if(platformModes.begin(), platformModes.end(),
[&](CameraModeStore& input) {
return input.mode.CompareWithoutFps(*toCheck);
});
// Find all matching modes
std::vector<CameraModeStore*> matchingModes;
for (auto& mode : platformModes) {
if (mode.mode.CompareWithoutFps(*toCheck)) {
matchingModes.push_back(&mode);
}
}
if (match == platformModes.end()) {
if (matchingModes.empty()) {
return nil;
}
// Check FPS
for (CameraFPSRange& range : match->fpsRanges) {
OBJCDEBUG3("Checking Range {} {}", range.min, range.max);
if (range.IsWithinRange(toCheck->fps)) {
*fps = toCheck->fps;
return match->format;
for (auto mode : matchingModes) {
for (CameraFPSRange& range : mode->fpsRanges) {
OBJCDEBUG3("Checking Range {} {}", range.min, range.max);
if (range.IsWithinRange(toCheck->fps)) {
*fps = toCheck->fps;
return mode->format;
}
}
}