Skip to content

Commit

Permalink
Merge pull request #492 from valbok/6.8.0
Browse files Browse the repository at this point in the history
Support 6.8.0
  • Loading branch information
valbok authored Oct 26, 2024
2 parents 7b24bd1 + f6761be commit 4d67bbc
Showing 1 changed file with 44 additions and 17 deletions.
61 changes: 44 additions & 17 deletions src/QtAVPlayer/qavvideoframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
#include "qavhwdevice_p.h"
#include <QSize>
#ifdef QT_AVPLAYER_MULTIMEDIA
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QAbstractVideoSurface>
#else
#include <QtMultimedia/private/qabstractvideobuffer_p.h>
#include <QtMultimedia/private/qvideotexturehelper_p.h>
#endif
#endif
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QAbstractVideoSurface>
#else
#if QT_VERSION < QT_VERSION_CHECK(6, 8, 0)
#include <QtMultimedia/private/qabstractvideobuffer_p.h>
#else
#include <QtMultimedia/private/qhwvideobuffer_p.h>
#endif // #if QT_VERSION < QT_VERSION_CHECK(6, 8, 0)
#include <QtMultimedia/private/qvideotexturehelper_p.h>
#endif // #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#endif // #ifdef QT_AVPLAYER_MULTIMEDIA
#include <QDebug>

extern "C" {
Expand Down Expand Up @@ -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)
{
}

Expand All @@ -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<PlanarVideoBuffer *>(this)->m_textures = m_frame.handle(m_rhi);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<PlanarVideoBuffer>(result, format, type, videoFormat));
#endif
#endif
}
#endif // #ifdef QT_AVPLAYER_MULTIMEDIA
Expand Down

0 comments on commit 4d67bbc

Please sign in to comment.