Skip to content
Extraits de code Groupes Projets

Video playback with mpv

2 files
+ 52
8
Comparer les modifications
  • Côte à côte
  • En ligne

Fichiers

+ 44
7
@@ -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;
}
}
Chargement en cours