Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS port #5

Closed
Ivshti opened this issue Dec 26, 2022 · 6 comments
Closed

macOS port #5

Ivshti opened this issue Dec 26, 2022 · 6 comments
Assignees

Comments

@Ivshti
Copy link
Member

Ivshti commented Dec 26, 2022

Summary

This draws inspiration from https://github.com/Ivshti/playback-native/blob/master/index.js, which is a VLC+WebView combo on macOS

Turns out that we can do the same with libMPV, since it can be given a pointer to NSView as the wid (like HWND on Windows): https://github.com/mpv-player/mpv-examples/blob/master/libmpv/cocoa/cocoabasic.m#L104

The only missing piece is how we initiate the window and webview.

WebView libraries

Most of them use WKWebView (“Starting in iOS 8.0 and OS X 10.10, use WKWebView to add web content to your app.Do not use UIWebView or WebView.”)

The best option is probably to use cocoa/objc directly, as the code will port almost 1:1

Here's an initial prototype: https://github.com/Ivshti/wry/blob/dev/examples/transparent.rs

@Ivshti
Copy link
Member Author

Ivshti commented Dec 26, 2022

Initial prototype here: https://github.com/Ivshti/wry/blob/dev/examples/transparent.rs

next steps:

  • figure out the resize crash - the prototype crashes when resizing on M1 mac
    • try the cocoa example of libmpv to see if it crashes - this one crashes, so it's a bug in MPV
    • cocoa-rendergl libmpv example is also worth reading and testing - this one doesn't crash and has the same performance (see below)

Two interesting things discovered in those tests

  • cocoa-rendergl does not init OpenGL with OpenGL 3 (NSOpenGLProfileVersion3_2Core), which threw "[libmpv_render/videotoolbox] error: need >= OpenGL 3.0 for core rectangle texture support" and degraded performance a bit; after fixing this, it's performance was equal to the cocoa example and the shell prototype
  • the shell prototype generated a bit more load for WindowService because MPV logging was enabled (msg-level all=v, terminal yes)

@Ivshti
Copy link
Member Author

Ivshti commented Dec 27, 2022

next steps:

  • compare cocoa-rendergl vs the cocoa vo
  • figure out scaling in cocoa-rendergl
  • figure out resizing in cocoa-rendergl (works but is slow)
  • research IINA and other cocoa+rendergl solutions
  • try a different version of libmpv - not doing this cause it's irrelevant; even if we get this to work, cocoa gpu context is obsolete, so it's best to use the mpv render API anyway
  • profile GPU usage as well between old stremio, iina, cocoa renderfb, transparency (new shell proto)

@Ivshti
Copy link
Member Author

Ivshti commented Dec 27, 2022

Another update

  • resizing is slow because everything runs in the main thread and goes through a objc queue waiting for it's turn
    • read IINA's video view to research how threading works there
  • dimensions are wrong in the example, and not wrong in other impls, because we use the "virtual" pixels we get from contentView bounds, and IINA/mpv (video/out/mac) get them from glViewport (real pixels).

@Ivshti
Copy link
Member Author

Ivshti commented Oct 4, 2024

It appears mpv has deprecated window embedding on macOS so this prototype should be re-made.

@Ivshti
Copy link
Member Author

Ivshti commented Oct 5, 2024

some performance tests done on an m3 max mbp, measuring CPU time and GPU time over 2 minutes of BBB (https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4)

all tests done with mpv 0.39.0, except stremio

  • cocoabasic 35.9 / 6.13
  • cocoa-rendergl 32.42 / 4.41
  • mpv: 41.52 / 6.16
  • stremio: 49 / 5.4 (INTEL)
  • opengl example from libmpv-rs 36.44 / 9.72
  • opengl example with sdl2 from libmpv2-rs 36.60 / 7.85

the good news is that the best performer is the cocoa-rendergl libmpv example, which is what we'd be basing our shell on

@Ivshti
Copy link
Member Author

Ivshti commented Oct 6, 2024

closing in favor of #9

@Ivshti Ivshti closed this as completed Oct 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants