From f044202c9edb65e3c65fe99a1fa66ede719b4442 Mon Sep 17 00:00:00 2001 From: APTX Date: Sun, 9 Oct 2022 12:17:07 +0900 Subject: [PATCH] Fix startup and play state handling Sometimes property events can arrive without data (maybe because the property is "unset"?). Due to this an assert to check if data is null can be used. The property to check if playback is paused is "pause" not "paused". There is no "pause" property. Its uses have been removed and replced with the "paused" property. --- backendplugins/backend_mpv/backendmpv.cpp | 2 +- backendplugins/backend_mpv/mpvhelper.h | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/backendplugins/backend_mpv/backendmpv.cpp b/backendplugins/backend_mpv/backendmpv.cpp index 4422560..5d03292 100644 --- a/backendplugins/backend_mpv/backendmpv.cpp +++ b/backendplugins/backend_mpv/backendmpv.cpp @@ -192,7 +192,7 @@ void MpvInstance::onLogMessage(mpv_event_log_message *log) { } void MpvInstance::onFileLoaded() { - const auto maybePaused = mpv::GetProperty(m_handle, mpv::property::Paused); + const auto maybePaused = mpv::GetProperty(m_handle, mpv::property::Pause); if (!maybePaused) { return; } diff --git a/backendplugins/backend_mpv/mpvhelper.h b/backendplugins/backend_mpv/mpvhelper.h index 5322560..82838e6 100644 --- a/backendplugins/backend_mpv/mpvhelper.h +++ b/backendplugins/backend_mpv/mpvhelper.h @@ -115,7 +115,6 @@ constexpr auto MakeProperty(Format, const char *name) { namespace property { constexpr Property Pause = MakeProperty(format::Flag, "pause"); -constexpr Property Paused = MakeProperty(format::Flag, "paused"); constexpr Property Duration = MakeProperty(format::Double, "duration"); constexpr Property PlaybackTime = MakeProperty(format::Double, "playback-time"); constexpr Property Volume = MakeProperty(format::Double, "volume"); @@ -295,7 +294,6 @@ class EventHandler { if constexpr (IsVoid) { (obj->*m_callback)(); } else { - assert(event->data != nullptr); if (event->format != m_property.format.format) { qCWarning(mpvHelper()).nospace() << "Observed property: " << event->name @@ -303,6 +301,13 @@ class EventHandler { << ", got format: " << event->format; return; } + if (event->data == nullptr) { + qCWarning(mpvHelper()).nospace() + << "Observed property: " << event->name + << " was registered with format: " << m_property.format.format + << ", but was delivered without data, skipping call"; + return; + } const auto &mpvData = *static_cast< typename decltype(Property::format)::MpvInternalType *>( event->data); @@ -376,6 +381,7 @@ public: property, handler))); const bool inserted = pair.second; if (!inserted) { + qCWarning(mpvHelper) << "Already observing property:" << property.name; return false; } @@ -414,8 +420,11 @@ public: break; } default: { + qCDebug(mpvHelper) << "Received event:" << event->event_id; const auto it = m_eventHandlers.find(event->event_id); if (it == std::end(m_eventHandlers)) { + qCDebug(mpvHelper) << "Received event without handler:" + << event->event_id; return; } it->second->run(m_obj, event); -- 2.52.0