Skip to content
Extraits de code Groupes Projets
Vérifiée Valider a6a50920 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

UI: Isolate the close MPV thing in a method + add callback for time change

parent 46ca3c84
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!15Video playback with mpv
......@@ -6,7 +6,7 @@ using namespace Vivy;
using namespace std::string_literals;
void
MpvContainer::mpvEventWakeUpCB(void *user)
MpvContainer::mpvEventWakeUpCB(void *user) noexcept
{
MpvContainer *container = reinterpret_cast<MpvContainer *>(user);
emit container->mpvEvent();
......@@ -35,16 +35,31 @@ MpvContainer::MpvContainer()
throw std::runtime_error("Failed to initialize the mpv context");
}
MpvContainer::~MpvContainer() noexcept
void
MpvContainer::registerMpvTimeCallback(void (*callback)(double)) noexcept
{
if (mpv_time_callback)
qWarning() << "Override a previous mpv callback, was" << mpv_time_callback
<< "and now will be" << callback;
mpv_time_callback = callback;
}
void
MpvContainer::closeMpv() noexcept
{
// TODO: Do that in a private method
if (mpv) {
registerMpvTimeCallback(nullptr);
mpv_handle *tmp_mpv = mpv;
mpv = nullptr; // Stop all other callbacks here
mpv_destroy(tmp_mpv);
}
}
MpvContainer::~MpvContainer() noexcept
{
closeMpv();
}
void
MpvContainer::handleMpvEvent(mpv_event *event) noexcept
{
......@@ -53,14 +68,11 @@ MpvContainer::handleMpvEvent(mpv_event *event) noexcept
union {
mpv_event_log_message *msg;
mpv_event_property *prop;
mpv_handle *tmp_mpv;
};
switch (event->event_id) {
case MPV_EVENT_SHUTDOWN:
tmp_mpv = mpv;
mpv = nullptr;
mpv_destroy(mpv);
closeMpv();
break;
case MPV_EVENT_VIDEO_RECONFIG:
......@@ -86,6 +98,31 @@ MpvContainer::handleMpvEvent(mpv_event *event) noexcept
}
}
break;
// Explicitly ignored
case MPV_EVENT_NONE:
case MPV_EVENT_GET_PROPERTY_REPLY:
case MPV_EVENT_SET_PROPERTY_REPLY:
case MPV_EVENT_COMMAND_REPLY:
case MPV_EVENT_START_FILE:
case MPV_EVENT_END_FILE:
case MPV_EVENT_FILE_LOADED:
case MPV_EVENT_TRACKS_CHANGED:
case MPV_EVENT_TRACK_SWITCHED:
case MPV_EVENT_IDLE:
case MPV_EVENT_PAUSE:
case MPV_EVENT_UNPAUSE:
case MPV_EVENT_TICK:
case MPV_EVENT_SCRIPT_INPUT_DISPATCH:
case MPV_EVENT_CLIENT_MESSAGE:
case MPV_EVENT_AUDIO_RECONFIG:
case MPV_EVENT_METADATA_UPDATE:
case MPV_EVENT_SEEK:
case MPV_EVENT_PLAYBACK_RESTART:
case MPV_EVENT_CHAPTER_CHANGE:
case MPV_EVENT_QUEUE_OVERFLOW:
case MPV_EVENT_HOOK:
break;
}
}
......
......@@ -19,14 +19,21 @@ class MpvContainer : public QWidget {
private:
mpv_handle *mpv{ nullptr };
void (*mpv_time_callback)(double){ nullptr };
public:
explicit MpvContainer();
~MpvContainer() noexcept override;
// Register a callback for time change, don't use Qt's signals for that.
void registerMpvTimeCallback(void (*)(double)) noexcept;
private:
void handleMpvEvent(mpv_event *) noexcept;
static void mpvEventWakeUpCB(void *); // Must be static for function ptr
void closeMpv() noexcept;
// Must be static to be passed as a function ptr
static void mpvEventWakeUpCB(void *) noexcept;
private slots:
void onMpvEvent() noexcept;
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter