office-gobmx/avmedia/source/qt6/QtFrameGrabber.hxx
Michael Weghorn f04e711ea3 tdf#145735 qt avmedia: Implement frame grabber
Add a new `QtFrameGrabber` class that implements
the `css::media::XFrameGrabber` interface and
return an instance of it in
`QtPlayer::createFrameGrabber`.

As there seems to be no direct way to retrieve
the image/frame of a video at a certain point
in time, create a separate `QMediaPlayer` instance
for the `QtFrameGrabber`, set a video sink, connect
to its `&QVideoSink::videoFrameChanged` signal and
start playing the video (and stop it again once the
first frame has been received) in order to retrieve
a corresponding frame.

From that `QVideoFrame`, a `QImage` can be retrieved
that can then be converted to an `XGraphic`.

With this in place, a frame from the actual video
is now displaced in Impress in non-presentation
mode instead of just a generic "video icon" placeholder
when opening a presentation containing a video,
(e.g. attachment 145517 from tdf#120452) when the
qt6 VCL plugin is in use.

Change-Id: I3bba3c0fb62a219ac632ceed03ec17f9078f18d0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168255
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
2024-05-31 09:24:01 +02:00

50 lines
1.4 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <mutex>
#include <QtCore/QObject>
#include <QtMultimedia/QMediaPlayer>
#include <QtMultimedia/QVideoFrame>
#include <QtMultimedia/QVideoSink>
#include <com/sun/star/graphic/XGraphic.hpp>
#include <com/sun/star/media/XFrameGrabber.hpp>
#include <comphelper/compbase.hxx>
namespace avmedia::qt
{
class QtFrameGrabber : public QObject, public ::cppu::WeakImplHelper<css::media::XFrameGrabber>
{
Q_OBJECT
private:
std::unique_ptr<QVideoSink> m_xVideoSink;
std::unique_ptr<QMediaPlayer> m_xMediaPlayer;
std::recursive_mutex m_aMutex;
bool m_bWaitingForFrame;
css::uno::Reference<css::graphic::XGraphic> m_xGraphic;
public:
QtFrameGrabber(const QUrl& rSourceUrl);
virtual css::uno::Reference<css::graphic::XGraphic>
SAL_CALL grabFrame(double fMediaTime) override;
private slots:
void onErrorOccured(QMediaPlayer::Error eError, const QString& rErrorString);
void onVideoFrameChanged(const QVideoFrame& rFrame);
};
} // namespace avmedia::qt
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */