// SPDX-FileCopyrightText: 2026 Matvey Shcherbinin // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL #pragma once #include #include #include #include #include class QAudioOutput; class QMediaPlayer; class QVideoSink; // One frame out of a video, for the tile a chat draws before playback starts. // Qt Multimedia decodes through FFmpeg here, so the poster comes from the same // decoder the player page uses - no second decode stack. The frame is cached // by path, size and mtime, and made on the machine that has the file, so a // second ask reads the disk and no poster ever rides the wire. class VideoPoster : public QObject { Q_OBJECT public: explicit VideoPoster(QObject *parent = nullptr); // The poster's path when it is already on disk; otherwise empty, with a // posterReady() to follow once the frame is grabbed. Q_INVOKABLE QString posterFor(const QString &videoPath); Q_SIGNALS: // The frame is on disk. An empty posterPath means the video could not give // one up - a codec this platform cannot decode - and will not be asked again. void posterReady(const QString &videoPath, const QString &posterPath); private: void grabNext(); // The empty posterPath carries a reason in error: the tile hides the failure // from the reader, so the log is where it is said. void complete(const QString &posterPath, const QString &error = {}); QString cachePathFor(const QString &videoPath) const; struct Job { QString videoPath; // where the frame is written, and the queue's identity for the video // as well: the cache key covers the path, size and mtime together. QString cachePath; }; QMediaPlayer *m_player = nullptr; QAudioOutput *m_audio = nullptr; QVideoSink *m_sink = nullptr; QQueue m_queue; QSet m_failed; Job m_current; bool m_busy = false; bool m_grabbed = false; QElapsedTimer m_since; };