Skip to content

mac-avcapture: Use list-based format selector - #10895

Merged
RytoEX merged 1 commit into
obsproject:masterfrom
jcm93:avcapturelist
Apr 2, 2025
Merged

RytoEX merged 1 commit into
obsproject:masterfrom
jcm93:avcapturelist

Conversation

@jcm93

@jcm93 jcm93 commented Jun 19, 2024 •

Copy link
Copy Markdown
Contributor

Description

Updates the properties window for macOS mac-avcapture sources to use a unified list-based format selector when in the non-preset mode. Also adds a contextual warning in the properties window to show when a device has macOS system effects active.

Screenshot 2024-07-10 at 9 39 50 AMScreenshot 2025-03-17 at 1 58 31 PM
Bildschirmfoto_2025-03-17_um_19 35 50

Bildschirmfoto_2025-03-17_um_19 36 27

The frame rate selector is retained, so that we can continue to have explicit control over the device frame rate. The list selectors for resolution, color space, pixel format and video range, however, have all been consolidated inside the single format selector.

Motivation and Context

#9344 provided a much-needed update to the Video Capture Device source on macOS and added a lower-latency Capture Card Device source. A number of factors, however, have conspired to make the new version of the source harder to use, for both novice and adept users:

  • The new version does not reimplement the 'auto-populate parameters' feature of the source on other platforms. When a property is updated, the user must check all other properties to ensure that the combination of selected parameters is still a valid configuration, which is not always immediately apparent.
  • Because of "quirks" with OBS's frame rate selector and the default size for the source properties window, it is not apparent to many users that the list selectors for pixel format, video range and color space exist 'below the fold' in the source properties window.

This PR aims to simplify and improve the UI for the source while also reducing the complexity of the property selection code.

  • All parameters are now visible in the source properties window at its default size. The only parameter that can be invalid after changing the selected format is the frame rate, and its status should be more apparent within the context of the window.
  • It is easier to understand at a glance what combinations of parameters are valid for a given device. Making an appropriate selection should now be a quicker process.

Additionally, the new effects warning in the properties window should help to alleviate some user confusion. On macOS, enabling an effect such as Studio Light or Portrait mode for one video input will often enable them on all inputs (filed as FB13302833). Users are often confused to see webcam effects on e.g. capture card inputs. With this PR, the source properties window displays a warning for active system effects, which should make this issue more apparent.

How Has This Been Tested?

Tested locally on an M1 Max machine running the macOS Sequoia beta with all video capture devices on hand, including the built-in webcam, Continuity Camera from an iPhone, a virtual camera, and a single capture card from a popular brand, to ensure both OBS source types remained in good working order.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Tweak (non-breaking change to improve existing functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

Comment thread plugins/mac-avcapture/OBSAVCapture.m Resolved
@WizardCM WizardCM added kind/bug Categorizes issue or PR as related to a bug. kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. platform/macos Categorizes issue or PR as affecting macOS specifically labels Jun 20, 2024
@derrod
derrod self-requested a review June 22, 2024 17:53
Comment thread plugins/mac-avcapture/plugin-main.m Resolved
Comment thread plugins/mac-avcapture/OBSAVCapture.h Resolved

@PatTheMav PatTheMav left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some code-specific comments, overall I'd like to see more discussion about:

  1. Presentation of the formats in the dropdown (@Warchamp7 got some ideas there?)
  2. How to "upgrade" existing source configurations

@jcm93
jcm93 force-pushed the avcapturelist branch 5 times, most recently from af5e538 to 9ef9d69 Compare June 27, 2024 22:16
@jcm93

jcm93 commented Jun 28, 2024

Copy link
Copy Markdown
Contributor Author

Couple misc changes:

  • Fixed the reaction effects property issue
  • We were checking if the received buffers differed from the configured format by checking the video range; it seemed simpler to check the media subtype (fourCC) instead, since that will detect if (for whatever reason) the pixel format changes but not the range.

Secondly, added a migration routine in configureSession to attempt to configure with the legacy properties if there is no value for the new supported_format key. This seems to me like the only thing we need to do to cleanly migrate from the old properties. All new sources will contain just the supported_format key-value, and supported_format will start superseding the old properties for existing sources once the properties window for an existing source is opened. Tested with a couple sources to make sure migration worked.

Hopefully this should be in a pretty good state now.

Was intending to squash at the end, just let know if you want me to squash whenever.

@jcm93
jcm93 force-pushed the avcapturelist branch 2 times, most recently from 9719b24 to f5e0f4f Compare July 9, 2024 18:49
@jcm93

This comment was marked as resolved.

@jcm93
jcm93 force-pushed the avcapturelist branch 2 times, most recently from 829f71e to 57b315a Compare July 9, 2024 20:31
Comment thread plugins/mac-avcapture/OBSAVCapture.m Resolved
Comment thread plugins/mac-avcapture/OBSAVCapture.m Resolved
Comment thread plugins/mac-avcapture/OBSAVCapture.m Resolved
Comment thread plugins/mac-avcapture/plugin-main.m Resolved
Comment thread plugins/mac-avcapture/plugin-main.m Resolved
@jcm93

jcm93 commented Jan 22, 2025 •

Copy link
Copy Markdown
Contributor Author

Per discussions out of band, I am adding one last feature to this in a separate commit; if the user selects a format that does not support their previously configured frame rate, we will fall back to an appropriate FPS supported by the format based on OBS's configured output frame rate. This fallback frame rate is determined by the new function fallbackFrameRateForFormat:.

After sitting on it, I think that the benefits are large enough that the addition of this functionality is merited. Namely, it seems like selecting a navigating to a format in the properties window should try to offer immediate feedback to help the user select a format, rather than requiring fiddling with the frame rate selector on each selection just to get a visual preview. Hitting cancel in the window is always a reliable "bail out" to return to the previous committed configuration.

While it is a relatively small addition, it's nontrivial enough that I am adding it in a separate commit so it can be looked at, and I can squash the commits later.

I will request re-reviews for the two approvals here since it seems appropriate.

@jcm93
jcm93 requested review from RytoEX and Warchamp7 January 22, 2025 18:15

@PatTheMav PatTheMav left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as advertised apart from the code-style issues I commented on separately.

I'm not really a fan of the aspect ratio in the format drop-down and exposing all the frame rate ranges in it: With some devices I tested with this list becomes a big bunch of textual noise, so the usefulness of the information is drowned out by that.

Personally I'd rather have something that is simple and low-effort to parse for the user with a straight-forward and consistent behaviour. The existence of a bespoke frame rate selector makes exposing the ranges in the first dropdown redundant.

@Warchamp7 what do you think? I've posted some screenshots off-thread that display the "noise" I mention.

Comment thread plugins/mac-avcapture/OBSAVCapture.m Resolved
Comment thread plugins/mac-avcapture/OBSAVCapture.h Resolved
Comment thread plugins/mac-avcapture/OBSAVCapture.m Resolved
@jcm93
jcm93 force-pushed the avcapturelist branch 2 times, most recently from 77b75a7 to f196378 Compare March 14, 2025 20:25
@jcm93

jcm93 commented Mar 14, 2025

Copy link
Copy Markdown
Contributor Author

Added a second commit to address some visual noise when there are a great many FPS ranges present on a format.

The approach taken in the second commit simplifies the FPS ranges description if there are more than ten ranges, showing the minimum and maximum FPS in the array of ranges and the number of ranges. This can happen if a card advertises many discrete values in the form of ranges, i.e. 30-30, 45-45, 60-60.

This scenario is currently disambiguated from a "genuine range" with a parenthetical indicating the number of ranges. So for example a format advertising 60 ranges between 1 and 120 fps would show "1 - 120 FPS (60 values)". While a genuine FPS range between 1-120 (i.e. any frame rate between 1-120 is supported) would show just "1 - 120 FPS".

This is not perfect, but it seems necessary to handle this edge case if a format has, for example, 60 FPS ranges, each representing discrete integers between 1 and 60.

@jcm93
jcm93 force-pushed the avcapturelist branch 2 times, most recently from 645bd36 to d422d79 Compare March 17, 2025 14:53

@PatTheMav PatTheMav left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works fine with all devices available to me.

@RytoEX
RytoEX requested a review from Warchamp7 March 17, 2025 18:34
@Warchamp7

Copy link
Copy Markdown
Member

My final request for this is gonna be to change the discrete FPS listings to be from low to high, so that it's consistent with FPS ranges being low to high.

@derrod
derrod removed their request for review March 25, 2025 20:48
@jcm93

jcm93 commented Mar 26, 2025

Copy link
Copy Markdown
Contributor Author

Done. I went ahead and squashed all commits, so I reproduced the change below; it is just a one liner to enumerate the sorted ranges in reverse order when specifically generating the description. I also documented that it uses ascending order. Lastly I fixed a tiny issue where, for the "over 10 ranges" case, we were using the ranges from the API (presumably-sorted) rather than guaranteed-sorted, when getting the minimum and maximum rate.

---
 plugins/mac-avcapture/OBSAVCapture.h | 2 +-
 plugins/mac-avcapture/OBSAVCapture.m | 7 ++++---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/plugins/mac-avcapture/OBSAVCapture.h b/plugins/mac-avcapture/OBSAVCapture.h
index 3f1a4216e..b0468d4fd 100644
--- a/plugins/mac-avcapture/OBSAVCapture.h
+++ b/plugins/mac-avcapture/OBSAVCapture.h
@@ -264,7 +264,7 @@ static const UInt32 kMaxFrameRateRangesInDescription = 10;
 
 + (FourCharCode)fourCharCodeFromFormat:(OBSAVCaptureVideoFormat)format withRange:(enum video_range_type)videoRange;
 
-/// Generates a string describing an array of frame rate ranges.
+/// Generates a string describing an array of frame rate ranges. The frame rate ranges are described in ascending order.
 /// - Parameter ranges: [NSArray](https://developer.apple.com/documentation/foundation/nsarray?language=objc) of [AVFrameRateRange](https://developer.apple.com/documentation/avfoundation/avframeraterange?language=objc), such as might be provided by an `AVCaptureDeviceFormat` instance's [videoSupportedFrameRateRanges](https://developer.apple.com/documentation/avfoundation/avcapturedeviceformat/1387592-videosupportedframerateranges) property.
 /// - Returns: A new [NSString](https://developer.apple.com/documentation/foundation/nsstring?language=objc) instance that describes the frame rate ranges.
 + (NSString *)frameRateDescription:(NSArray<AVFrameRateRange *> *)ranges;
diff --git a/plugins/mac-avcapture/OBSAVCapture.m b/plugins/mac-avcapture/OBSAVCapture.m
index 64118173a..1dab839b4 100644
--- a/plugins/mac-avcapture/OBSAVCapture.m
+++ b/plugins/mac-avcapture/OBSAVCapture.m
@@ -1053,7 +1053,7 @@ + (NSString *)frameRateDescription:(NSArray<AVFrameRateRange *> *)ranges
         }];
     NSString *frameRateDescription;
     NSMutableArray *frameRateDescriptions = [[NSMutableArray alloc] initWithCapacity:ranges.count];
-    for (AVFrameRateRange *range in sortedRangesDescending) {
+    for (AVFrameRateRange *range in [sortedRangesDescending reverseObjectEnumerator]) {
         double minFrameRate = round(range.minFrameRate * 100) / 100;
         double maxFrameRate = round(range.maxFrameRate * 100) / 100;
         if (minFrameRate == maxFrameRate) {
@@ -1074,8 +1074,9 @@ + (NSString *)frameRateDescription:(NSArray<AVFrameRateRange *> *)ranges
         frameRateDescription = [frameRateDescriptions componentsJoinedByString:@", "];
         frameRateDescription = [frameRateDescription stringByAppendingString:@" FPS"];
     } else if (frameRateDescriptions.count > kMaxFrameRateRangesInDescription) {
-        frameRateDescription = [NSString stringWithFormat:@"%.0f-%.0f FPS (%lu values)", ranges.lastObject.minFrameRate,
-                                                          ranges.firstObject.maxFrameRate, ranges.count];
+        frameRateDescription =
+            [NSString stringWithFormat:@"%.0f-%.0f FPS (%lu values)", sortedRangesDescending.lastObject.minFrameRate,
+                                       sortedRangesDescending.firstObject.maxFrameRate, sortedRangesDescending.count];
     }
     return frameRateDescription;
 }
-- 

Comment thread plugins/mac-avcapture/OBSAVCapture.h Resolved
@RytoEX
RytoEX merged commit bf7e82d into obsproject:master Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug. kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. platform/macos Categorizes issue or PR as affecting macOS specifically Seeking Testers Build artifacts on CI

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

7 participants