Render libmpv video through Avalonia's OpenGL control - #8
Conversation
Replace native child-window embedding with libmpv's OpenGL render API so video frames participate in Avalonia layout, clipping, overlays, and fullscreen transitions on macOS. Serialize media commands away from the UI and render threads, preserve playback state across view changes, and hide image-only histogram content for videos.
7612ea2 to
0f9363a
Compare
|
Thanks for this, and thanks for the detailed write-up. Moving from Before I can merge this, a few things need to change. 1. Lock contention in the render path (blocking)
2. The comment says this matches the image behavior, but it does not. 3. Dispose can never complete (blocking) While a render context is attached, actual teardown is deferred to 4. Comment language This repository keeps identifiers in English and comments in German. The PR rewrites 5. Please split out the histogram change The histogram visibility work ( Smaller items, worth folding in
Validation Since this replaces the render path on all three platforms, macOS alone is not enough. The Happy to discuss any of the above if you see it differently. |
|
I’m closing this PR for now. After testing the implementation, I realized that the remaining questions—particularly end-of-file frame behavior and HDR/color-management policy—are not isolated rendering fixes. They affect FerrumPix’s broader platform and architecture direction and need project-level decisions first. Continuing to add changes without that direction could increase the maintenance burden and make future review harder. I would rather pause this work, follow the project’s current development direction, and revisit a similar contribution when the relevant architecture and platform policies are clearer. Thank you for the careful review and for the useful feedback. |
|
Thanks for pointing out the histogram change in your review. I checked the current main branch and confirmed that the histogram visibility and loading behavior has already been fixed there: videos no longer show or trigger histogram loading, while images and the editor retain their normal histogram behavior. Since this is already covered by your mainline changes, I will not pursue a separate histogram PR. Thanks for taking care of it. |
Summary
Motivation
The previous native child-window approach used platform window handles and did not compose reliably with Avalonia layout and overlays on macOS. In failure cases, the embedded surface could remain black while mpv opened a separate window.
This change uses the libmpv Render API with an Avalonia OpenGL control. Avalonia owns the framebuffer, clipping, controls, and fullscreen layout, while libmpv commands are kept away from the UI thread and OpenGL render callbacks. The same rendering and composition path is now used on Windows, Linux, and macOS.
macOS also has a separate library-discovery issue. A Homebrew-installed libmpv normally lives under
/opt/homebrew, which is not necessarily searched by the .NET native-library resolver when FerrumPix is launched as an application bundle. The resolver now checks the default library names first, then conventional Homebrew, Intel Homebrew, and MacPorts library directories before retaining the existing application-local fallback.Dependency policy
This PR does not bundle libmpv or codecs and does not add package references or packaging changes. It preserves the existing system-first policy. On macOS, libmpv must still be installed separately, for example with:
Validation