From f6761bed4ce4a25cc958fddaf7966de83376b8ad Mon Sep 17 00:00:00 2001 From: VaL Doroshchuk Date: Sat, 26 Oct 2024 12:28:56 +0200 Subject: [PATCH] Support 6.8.0 --- src/QtAVPlayer/qavvideoframe.cpp | 61 +++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/src/QtAVPlayer/qavvideoframe.cpp b/src/QtAVPlayer/qavvideoframe.cpp index 1d32a3e..1d528de 100644 --- a/src/QtAVPlayer/qavvideoframe.cpp +++ b/src/QtAVPlayer/qavvideoframe.cpp @@ -12,13 +12,17 @@ #include "qavhwdevice_p.h" #include #ifdef QT_AVPLAYER_MULTIMEDIA -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) -#include -#else -#include -#include -#endif -#endif + #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + #include + #else + #if QT_VERSION < QT_VERSION_CHECK(6, 8, 0) + #include + #else + #include + #endif // #if QT_VERSION < QT_VERSION_CHECK(6, 8, 0) + #include + #endif // #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +#endif // #ifdef QT_AVPLAYER_MULTIMEDIA #include extern "C" { @@ -217,15 +221,23 @@ class PlanarVideoBuffer : public QAbstractPlanarVideoBuffer QAVVideoFrame m_frame; MapMode m_mode = NotMapped; }; +#else // #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + +#if QT_VERSION < QT_VERSION_CHECK(6, 8, 0) +using AbstractVideoBuffer = QAbstractVideoBuffer; #else -class PlanarVideoBuffer : public QAbstractVideoBuffer +using AbstractVideoBuffer = QHwVideoBuffer; +#endif + +class PlanarVideoBuffer : public AbstractVideoBuffer { public: PlanarVideoBuffer(const QAVVideoFrame &frame, QVideoFrameFormat::PixelFormat format - , QVideoFrame::HandleType type = QVideoFrame::NoHandle) - : QAbstractVideoBuffer(type) + , QVideoFrame::HandleType type = QVideoFrame::NoHandle, QVideoFrameFormat videoFormat = {}) + : AbstractVideoBuffer(type) , m_frame(frame) , m_pixelFormat(format) + , m_videoFormat(videoFormat) { } @@ -234,10 +246,11 @@ class PlanarVideoBuffer : public QAbstractVideoBuffer quint64 textureHandle(int plane) const override #else - QVideoFrame::MapMode mapMode() const { return m_mode; } - - quint64 textureHandle(QRhi*, int plane) const override +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) + QVideoFrameFormat format() const override { return m_videoFormat; } #endif + quint64 textureHandle(QRhi*, int plane) const override +#endif // #if QT_VERSION < QT_VERSION_CHECK(6, 7, 2) { if (m_textures.isNull()) const_cast(this)->m_textures = m_frame.handle(m_rhi); @@ -258,15 +271,24 @@ class PlanarVideoBuffer : public QAbstractVideoBuffer m_mode = mode; auto mapData = m_frame.map(); auto *desc = QVideoTextureHelper::textureDescription(m_pixelFormat); +#if QT_VERSION < QT_VERSION_CHECK(6, 8, 0) res.nPlanes = desc->nplanes; - for (int i = 0; i < res.nPlanes; ++i) { +#else + res.planeCount = desc->nplanes; +#endif + for (int i = 0; i < desc->nplanes; ++i) { if (!mapData.bytesPerLine[i]) break; res.data[i] = mapData.data[i]; res.bytesPerLine[i] = mapData.bytesPerLine[i]; // TODO: Reimplement heightForPlane - res.size[i] = mapData.bytesPerLine[i] * desc->heightForPlane(m_frame.size().height(), i); + auto size = mapData.bytesPerLine[i] * desc->heightForPlane(m_frame.size().height(), i); +#if QT_VERSION < QT_VERSION_CHECK(6, 8, 0) + res.size[i] = size; +#else + res.dataSize[i] = size; +#endif } return res; } @@ -367,11 +389,12 @@ class PlanarVideoBuffer : public QAbstractVideoBuffer } return maxNits; } -#endif +#endif // #if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) private: QAVVideoFrame m_frame; QVideoFrameFormat::PixelFormat m_pixelFormat = QVideoFrameFormat::Format_Invalid; + QVideoFrameFormat m_videoFormat; QVideoFrame::MapMode m_mode = QVideoFrame::NotMapped; QVariant m_textures; #if QT_VERSION < QT_VERSION_CHECK(6, 4, 0) @@ -473,8 +496,12 @@ QAVVideoFrame::operator QVideoFrame() const videoFormat.setColorTransfer(PlanarVideoBuffer::colorTransfer(frame())); videoFormat.setColorRange(PlanarVideoBuffer::colorRange(frame())); videoFormat.setMaxLuminance(PlanarVideoBuffer::maxNits(frame())); -#endif +#endif // #if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) +#if QT_VERSION < QT_VERSION_CHECK(6, 8, 0) return QVideoFrame(new PlanarVideoBuffer(result, format, type), videoFormat); +#else + return QVideoFrame(std::make_unique(result, format, type, videoFormat)); +#endif #endif } #endif // #ifdef QT_AVPLAYER_MULTIMEDIA