mpv-player / mpv-examples

📚
235 stars 77 forks source link

Convert QML example from opengl-cb to render API #18

Closed mikhas closed 6 years ago

mikhas commented 6 years ago

Mimics the approach in SDL example.

Example application starts with no warnings on my box (only green terminal output), plays example (once I put something @ test.mkv) and exits cleanly.

The important change that makes it non-trivial (as compared to the changes in the SDL example) is that we have to reimplement "QQuickFramebufferObject::Renderer::createFramebufferObject(const QSize &size)" to make sure we initialize mpv_gl with a valid (and configured) OpenGL context at the right time.

There are some ugly casts in there, most notably the const cast in "MpvObject::createRenderer() const", but I would argue that the Qt API requiring a const is simply wrong/unjustified.

Also, the cleanup sequence: We initialize mpv_gl in the renderer but clean it up in the MpvObject d'tor. I tried to have that in the renderer d'tor but that would crash on exit. I assume it's because we don't actually know in which order both objects are destroyed. Having both the cleanup for mpv_gl and mpv resources in one d'tor makes sure we control the cleanup order.

One could push this further to no longer require

include <mpv/qthelper.hpp> but the node_builder class in there is nice to have

ghost commented 6 years ago

LGTM, just that there's nobody to merge it.

jeeb commented 6 years ago

Been a while since I've built qmake things, last time I did this was in 2016 (https://github.com/jeeb/mpv-examples/commit/d42e79fbe9f74a7d40334873300ea92db72ce068). Feel free to laugh :) , but I did this to make a brief test.

Anyways, qmake was surprisingly simple now that I got it installed. Seems to build, and if file is located in the correct spot it seems to work nicely enough.