mac-avcapture: Use fallback frame rate by default for new devices

When a new device is selected, a best-possible frame rate is chosen
for the initial configuration of the device. This has to be set in the
source settings, as those are the "source of truth" for the properties
and the device configuration.

The object has to be created explicitly first before setting the
frame rate value. The source then has to be updated explicitly as well
to ensure that the change will be picked up by the next iteration
of the render thread to "tick" the source and thus make it configure
a capture session with the fallback framerate set.
This commit is contained in:
PatTheMav
2025-10-21 16:44:07 +02:00
committed by Ryan Foster
parent 12361ff135
commit 2954532019

View File

@@ -417,6 +417,23 @@ static const UInt32 kMaxFrameRateRangesInDescription = 10;
OBSAVCaptureMediaFPS fps;
if (!obs_data_get_frames_per_second(self.captureInfo->settings, "frame_rate", &fps, NULL)) {
[self AVCaptureLog:LOG_DEBUG withFormat:@"No valid framerate found in settings"];
AVCaptureDeviceFormat *lastFormat = [self.deviceInput.device.formats lastObject];
fps = [OBSAVCapture fallbackFrameRateForFormat:lastFormat];
if (lastFormat.videoSupportedFrameRateRanges.count == 0) {
return NO;
}
obs_data_set_obj(self.captureInfo->settings, "frame_rate", NULL);
obs_data_item_t *frameRateSetting = obs_data_item_byname(self.captureInfo->settings, "frame_rate");
obs_data_item_set_frames_per_second(&frameRateSetting, fps, NULL);
obs_source_update(self.captureInfo->source, self.captureInfo->settings);
return NO;
}