Browse Source

Don't disable screensaver during music playback

Rename the playbackActive signal to videoPlaybackActive, and trigger it
only if the video output is in use.
Vincent Lang 8 năm trước cách đây
mục cha
commit
98d5fb618c

+ 11 - 3
src/player/PlayerComponent.cpp

@@ -37,7 +37,8 @@ static void wakeup_cb(void *context)
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 PlayerComponent::PlayerComponent(QObject* parent)
   : ComponentBase(parent), m_state(State::stopped), m_paused(false), m_playbackActive(false),
-  m_inPlayback(false), m_bufferingPercentage(100), m_lastBufferingPercentage(-1),
+  m_windowVisible(false), m_videoPlaybackActive(false), m_inPlayback(false),
+  m_bufferingPercentage(100), m_lastBufferingPercentage(-1),
   m_lastPositionUpdate(0.0), m_playbackAudioDelay(0),
   m_playbackStartSent(false), m_window(nullptr), m_mediaFrameRate(0),
   m_restoreDisplayTimer(this), m_reloadAudioTimer(this),
@@ -416,6 +417,13 @@ void PlayerComponent::updatePlaybackState()
   if (m_state == State::buffering && m_lastBufferingPercentage != m_bufferingPercentage)
     emit buffering(m_bufferingPercentage);
   m_lastBufferingPercentage = m_bufferingPercentage;
+
+  bool is_videoPlaybackActive = m_state == State::playing && m_windowVisible;
+  if (m_videoPlaybackActive != is_videoPlaybackActive)
+  {
+    m_videoPlaybackActive = is_videoPlaybackActive;
+    emit videoPlaybackActive(m_videoPlaybackActive);
+  }
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -471,7 +479,6 @@ void PlayerComponent::handleMpvEvent(mpv_event *event)
       else if (strcmp(prop->name, "core-idle") == 0 && prop->format == MPV_FORMAT_FLAG)
       {
         m_playbackActive = !*(int *)prop->data;
-        emit playbackActive(m_playbackActive);
       }
       else if (strcmp(prop->name, "cache-buffering-state") == 0)
       {
@@ -490,7 +497,8 @@ void PlayerComponent::handleMpvEvent(mpv_event *event)
       else if (strcmp(prop->name, "vo-configured") == 0)
       {
         int state = prop->format == MPV_FORMAT_FLAG ? *(int *)prop->data : 0;
-        emit windowVisible(state);
+        m_windowVisible = state;
+        emit windowVisible(m_windowVisible);
       }
       else if (strcmp(prop->name, "duration") == 0)
       {

+ 3 - 1
src/player/PlayerComponent.h

@@ -150,7 +150,7 @@ Q_SIGNALS:
 
   // true if the video (or music) is actually playing
   // false if nothing is loaded, playback is paused, during seeking, or media is being loaded
-  void playbackActive(bool active);
+  void videoPlaybackActive(bool active);
   void windowVisible(bool visible);
   // emitted as soon as the duration of the current file is known
   void updateDuration(qint64 milliseconds);
@@ -194,6 +194,8 @@ private:
   State m_state;
   bool m_paused;
   bool m_playbackActive;
+  bool m_windowVisible;
+  bool m_videoPlaybackActive;
   bool m_inPlayback;
   int m_bufferingPercentage;
   int m_lastBufferingPercentage;

+ 2 - 2
src/player/PlayerQuickItem.cpp

@@ -226,7 +226,7 @@ void PlayerRenderer::swap()
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-void PlayerRenderer::onPlaybackActive(bool active)
+void PlayerRenderer::onVideoPlaybackActive(bool active)
 {
 #ifdef Q_OS_WIN32
   if (active && !m_hAvrtHandle)
@@ -303,7 +303,7 @@ void PlayerQuickItem::onSynchronize()
     }
     connect(window(), &QQuickWindow::beforeRendering, m_renderer, &PlayerRenderer::render, Qt::DirectConnection);
     connect(window(), &QQuickWindow::frameSwapped, m_renderer, &PlayerRenderer::swap, Qt::DirectConnection);
-    connect(&PlayerComponent::Get(), &PlayerComponent::playbackActive, m_renderer, &PlayerRenderer::onPlaybackActive, Qt::QueuedConnection);
+    connect(&PlayerComponent::Get(), &PlayerComponent::videoPlaybackActive, m_renderer, &PlayerRenderer::onVideoPlaybackActive, Qt::QueuedConnection);
     window()->setPersistentOpenGLContext(true);
     window()->setPersistentSceneGraph(true);
     window()->setClearBeforeRendering(false);

+ 1 - 1
src/player/PlayerQuickItem.h

@@ -28,7 +28,7 @@ class PlayerRenderer : public QObject
   void swap();
 
 public slots:
-  void onPlaybackActive(bool active);
+  void onVideoPlaybackActive(bool active);
 
 private:
   static void on_update(void *ctx);

+ 2 - 2
src/power/PowerComponent.cpp

@@ -45,7 +45,7 @@ bool PowerComponent::componentInitialize()
 {
   PlayerComponent* player = &PlayerComponent::Get();
 
-  connect(player, &PlayerComponent::playbackActive, this, &PowerComponent::playbackActive);
+  connect(player, &PlayerComponent::videoPlaybackActive, this, &PowerComponent::videoPlaybackActive);
 
   return true;
 }
@@ -91,7 +91,7 @@ void PowerComponent::redecideScreeensaverState()
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////
-void PowerComponent::playbackActive(bool active)
+void PowerComponent::videoPlaybackActive(bool active)
 {
   m_videoPlaying = active;
   redecideScreeensaverState();

+ 1 - 1
src/power/PowerComponent.h

@@ -48,7 +48,7 @@ public Q_SLOTS:
   virtual bool Suspend() { return false; }
 
 private Q_SLOTS:
-  void playbackActive(bool active);
+  void videoPlaybackActive(bool active);
 
 Q_SIGNALS:
   void screenSaverEnabled();