avmedia/source/qt6/QtFrameGrabber.cxx |   14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

New commits:
commit a99575f04fa9c858bfcd996f037444135810d43f
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Sat Jun 1 07:32:22 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sun Jun 2 06:19:25 2024 +0200

    tdf#194504 qt avmedia: Don't wait for video frame if there's none
    
    If the media doesn't have video, then don't try to
    grab a frame, but stop waiting for the
    `QVideoSink::videoFrameChanged` signal to be emitted
    in `QtFrameGrabber::grabFrame`.
    
    Don't call `QMediaPlayer::hasVideo` while the media
    is still being loaded, as the result is only valid once loading
    the media has been finished (`false` is returned otherwise
    even if the media file contains video), s. the platform
    implementation in qtmultimedia's `QFFmpegMediaPlayer::setMedia`,
    which loads the media in a separate thread: Once the media
    has been loaded, `QFFmpegMediaPlayer::setMediaAsync`
    calls `QPlatformMediaPlayer::videoAvailableChanged`
    to specify whether video is available.
    
    With this commit in place, opening an Impress presentation
    that contains an audio file (like attachment 194504
    from tdf#145735) now shows an "audio icon" as placeholder
    as expected and the application exits properly on close,
    rather than blocking as it's still waiting for a video frame.
    
    Change-Id: I5448a9f7396d4c419d76a2400e3f2a1ef52a7e85
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168305
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/avmedia/source/qt6/QtFrameGrabber.cxx 
b/avmedia/source/qt6/QtFrameGrabber.cxx
index 9adfdc6d3978..d58c274520ef 100644
--- a/avmedia/source/qt6/QtFrameGrabber.cxx
+++ b/avmedia/source/qt6/QtFrameGrabber.cxx
@@ -93,7 +93,19 @@ css::uno::Reference<css::graphic::XGraphic> SAL_CALL 
QtFrameGrabber::grabFrame(d
             &QtFrameGrabber::onVideoFrameChanged, 
Qt::BlockingQueuedConnection);
     m_xMediaPlayer->play();
     while (m_bWaitingForFrame)
-        Scheduler::ProcessEventsToIdle();
+    {
+        // QMediaPlayer::hasVideo() result isn't valid while media is loading
+        if (m_xMediaPlayer->mediaStatus() != QMediaPlayer::LoadingMedia
+            && !m_xMediaPlayer->hasVideo())
+        {
+            // There's no video, don't wait for frame
+            m_bWaitingForFrame = false;
+        }
+        else
+        {
+            Scheduler::ProcessEventsToIdle();
+        }
+    }
     m_xMediaPlayer->stop();
 
     uno::Reference<css::graphic::XGraphic> xGraphic = m_xGraphic;

Reply via email to