Skip to content

Canvases - Part Deux (Loading/Saving + Frontend API) - #11832

Merged
RytoEX merged 3 commits into
obsproject:masterfrom
amazon-contributing:rodney/multi-canvas-frontend
May 2, 2025
Merged

RytoEX merged 3 commits into
obsproject:masterfrom
amazon-contributing:rodney/multi-canvas-frontend

Conversation

@dsaedtler

@dsaedtler dsaedtler commented Feb 5, 2025 •

Copy link
Copy Markdown

Description

Adds saving and loading for frontend-owned canvases as well as a frontend API to create/remove/enumerate them.

Motivation and Context

In order to persist additional canvases and their scenes/sources in a way that is reasonably straightforward for API users we want the frontend to own/manage additional canvases that it may interface with.

In the future I'd also like to make transitions and the main canvas part of this abstraction.

How Has This Been Tested?

This was tested with this fork of the vertical canvas plugin that makes use of the new APIs: https://github.com/dsaedtler/obs-vertical-canvas

Types of changes

  • New feature (non-breaking change which adds functionality)

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.

@dsaedtler dsaedtler mentioned this pull request Feb 5, 2025
6 tasks done
@WizardCM WizardCM added the kind/feature Functionality or other elements that the project doesn't currently have. label Feb 12, 2025
@dsaedtler
dsaedtler force-pushed the rodney/multi-canvas-frontend branch from 4804b5c to 8528fc9 Compare March 5, 2025 09:13
@dsaedtler
dsaedtler force-pushed the rodney/multi-canvas-frontend branch from 8528fc9 to 49ce592 Compare April 2, 2025 16:48
@dsaedtler
dsaedtler marked this pull request as ready for review April 2, 2025 16:49
@RytoEX
RytoEX requested a review from PatTheMav April 2, 2025 16:53
@RytoEX RytoEX self-assigned this Apr 2, 2025
Comment thread frontend/api/obs-frontend-api.h Resolved
Comment thread frontend/widgets/OBSBasic.hpp Resolved
@dsaedtler
dsaedtler force-pushed the rodney/multi-canvas-frontend branch 2 times, most recently from 5bafb33 to f3353c3 Compare April 3, 2025 07:36

@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.

I find the whole mix and match of C types by libobs, "native" C++ types used by the front-end, and "RAII"-wrapper types unfortunate, particularly the back and forth between OBSFrontendCanvas, OBSCanvas, and obs_canvas_t.

I would prefer if Canvas management had been properly encapsulated into its own class (which would also be the owner of the data and pointers) which could potentially make using the RAII wrappers as well as a wrapper around the wrapper for the vector superfluous.

Free standing functions could then serve as factory methods that yield either a vector of Canvas objects or an obs_data_array_t of canvas data. And OBSBasic would just call something like std::vector<OBS::Canvas> OBS::Canvas::LoadCanvases(obs_data_array_t *canvases) which would elide a copy thanks to RVO.

And instead of trying to get the pointer wrapped by the RAII wrapper and calling obs_canvas_remove on each of them, one would be call OBS::Canvas::Erase() or similar for each item in the vector.


Apart from my architectural concerns, the code as-is looks correct. But if we introduce a whole new thing like canvases into the program, I'd like us to do it right and use appropriate encapsulation and abstraction.

Comment thread frontend/widgets/OBSBasic_Canvases.cpp Resolved
Comment thread frontend/OBSStudioAPI.cpp Resolved
@dsaedtler

Copy link
Copy Markdown
Author

I find the whole mix and match of C types by libobs, "native" C++ types used by the front-end, and "RAII"-wrapper types unfortunate, particularly the back and forth between OBSFrontendCanvas, OBSCanvas, and obs_canvas_t.

I would prefer if Canvas management had been properly encapsulated into its own class (which would also be the owner of the data and pointers) which could potentially make using the RAII wrappers as well as a wrapper around the wrapper for the vector superfluous.

Free standing functions could then serve as factory methods that yield either a vector of Canvas objects or an obs_data_array_t of canvas data. And OBSBasic would just call something like std::vector<OBS::Canvas> OBS::Canvas::LoadCanvases(obs_data_array_t *canvases) which would elide a copy thanks to RVO.

That sounds fine, the OBSFrontendCanvas was originally intended to also carry transitions (to save/load them for non-primary canvases, and eventually the main one as well), but I didn't want to do that for this first iteration. But it could certainly be extended into a full-on wrapper that provides a more OOP API.

Where do you think such class should live in the current code structure? frontend/utility/OBSCanvas.{hpp,cpp}?

@PatTheMav

PatTheMav commented Apr 8, 2025 •

Copy link
Copy Markdown
Member

I find the whole mix and match of C types by libobs, "native" C++ types used by the front-end, and "RAII"-wrapper types unfortunate, particularly the back and forth between OBSFrontendCanvas, OBSCanvas, and obs_canvas_t.
I would prefer if Canvas management had been properly encapsulated into its own class (which would also be the owner of the data and pointers) which could potentially make using the RAII wrappers as well as a wrapper around the wrapper for the vector superfluous.
Free standing functions could then serve as factory methods that yield either a vector of Canvas objects or an obs_data_array_t of canvas data. And OBSBasic would just call something like std::vector<OBS::Canvas> OBS::Canvas::LoadCanvases(obs_data_array_t *canvases) which would elide a copy thanks to RVO.

That sounds fine, the OBSFrontendCanvas was originally intended to also carry transitions (to save/load them for non-primary canvases, and eventually the main one as well), but I didn't want to do that for this first iteration. But it could certainly be extended into a full-on wrapper that provides a more OOP API.

Where do you think such class should live in the current code structure? frontend/utility/OBSCanvas.{hpp,cpp}?

Yeah utility would be the "fallback" if we cannot come up with a better category for these things. In the future we'd need some directory for bespoke classes for transitions, scenes, scene collections, which aren't "utility" per-se, but core building blocks of the compositor.

(Particularly as the canvas class would "manage" the associated instances of transition-type classes, scene class instances, etc.)

@dsaedtler
dsaedtler force-pushed the rodney/multi-canvas-frontend branch 2 times, most recently from 8f15137 to f488cb0 Compare April 9, 2025 15:26
@dsaedtler

Copy link
Copy Markdown
Author

I've made some changes based on the above conversation (the diff may be a bit messy due to rebasing, sorry):

  • Added an OBS::Canvas class, that owns obs_canvas_t objects
    • Supports move semantics for std::vector, which automatically calls obs_canvas_remove() on the owned canvas when erased
  • Removed OBSFrontendCanvas
  • Created two free standing functions for loading/saving a vector of OBS::Canvas objects from obs_data_array_t

I'm not sure where the freestanding functions should be, so right now they're just part of the OBSCanvas.cpp file as OBS::LoadCanvases and OBS::SaveCanvases.

@dsaedtler
dsaedtler force-pushed the rodney/multi-canvas-frontend branch from f488cb0 to 579483e Compare April 9, 2025 16:05
@RytoEX
RytoEX requested a review from PatTheMav April 15, 2025 20:26

@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.

Apart from my comments and to ensure this doesn't get lost: #11824 needs to be merged first and this PR then based on top of it, as it introduces changes to the scene collections implementation on OBSBasic.

Comment thread frontend/OBSStudioAPI.cpp Resolved
Comment thread frontend/widgets/OBSBasic_Canvases.cpp Resolved
Comment thread frontend/utility/OBSCanvas.cpp Resolved
Comment thread frontend/utility/OBSCanvas.cpp Resolved
Comment thread frontend/utility/OBSCanvas.cpp Resolved
Comment thread frontend/utility/OBSCanvas.cpp Resolved
Comment thread frontend/utility/OBSCanvas.cpp Resolved
Comment thread frontend/widgets/OBSBasic_Canvases.cpp Resolved
Comment thread frontend/widgets/OBSBasic_Canvases.cpp Resolved
Comment thread frontend/widgets/OBSBasic_Canvases.cpp Resolved
@dsaedtler
dsaedtler force-pushed the rodney/multi-canvas-frontend branch 2 times, most recently from 148fcd5 to ee501de Compare April 29, 2025 14:37
@dsaedtler
dsaedtler force-pushed the rodney/multi-canvas-frontend branch from ee501de to 9b579dc Compare May 2, 2025 10:57
@dsaedtler
dsaedtler force-pushed the rodney/multi-canvas-frontend branch from 9b579dc to 9e6bed9 Compare May 2, 2025 11:01

@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.

Looks good to me - I cannot resolve the comment threads that are still open though.

@RytoEX
RytoEX merged commit 8441c04 into obsproject:master May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature Functionality or other elements that the project doesn't currently have.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants