Skip to content

Commit 5b5ec47

Browse files
committed
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.
1 parent 5ec3af3 commit 5b5ec47

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

plugins/mac-avcapture/OBSAVCapture.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,23 @@ - (BOOL)configureSession:(NSError *__autoreleasing *)error
417417
OBSAVCaptureMediaFPS fps;
418418
if (!obs_data_get_frames_per_second(self.captureInfo->settings, "frame_rate", &fps, NULL)) {
419419
[self AVCaptureLog:LOG_DEBUG withFormat:@"No valid framerate found in settings"];
420+
421+
AVCaptureDeviceFormat *lastFormat = [self.deviceInput.device.formats lastObject];
422+
423+
fps = [OBSAVCapture fallbackFrameRateForFormat:lastFormat];
424+
425+
if (lastFormat.videoSupportedFrameRateRanges.count == 0) {
426+
return NO;
427+
}
428+
429+
obs_data_set_obj(self.captureInfo->settings, "frame_rate", NULL);
430+
431+
obs_data_item_t *frameRateSetting = obs_data_item_byname(self.captureInfo->settings, "frame_rate");
432+
433+
obs_data_item_set_frames_per_second(&frameRateSetting, fps, NULL);
434+
435+
obs_source_update(self.captureInfo->source, self.captureInfo->settings);
436+
420437
return NO;
421438
}
422439

0 commit comments

Comments
 (0)