]> Some of my projects - aniplayer.git/commitdiff
Fix startup and play state handling
authorAPTX <marek321@gmail.com>
Sun, 9 Oct 2022 03:17:07 +0000 (12:17 +0900)
committerAPTX <marek321@gmail.com>
Sun, 9 Oct 2022 03:17:07 +0000 (12:17 +0900)
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
backendplugins/backend_mpv/mpvhelper.h

index 4422560d8592a4a7734f7dbce9936132182e4846..5d0329227f3c351aea61576b776e28960ca80deb 100644 (file)
@@ -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;
   }
index 5322560dfeb4fe38ca23221b108556ce0027e59b..82838e688103f19c7bbe1b54893ea218af093821 100644 (file)
@@ -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);