mirror of https://github.com/mgba-emu/mgba.git
Qt: Get VideoDumper compiling with Qt6
Cameras still don't work though
This commit is contained in:
parent
3f21de2b7c
commit
06448e8445
|
@ -225,11 +225,8 @@ endif()
|
||||||
if(${QT}Multimedia_FOUND)
|
if(${QT}Multimedia_FOUND)
|
||||||
list(APPEND AUDIO_SRC
|
list(APPEND AUDIO_SRC
|
||||||
AudioProcessorQt.cpp
|
AudioProcessorQt.cpp
|
||||||
AudioDevice.cpp)
|
AudioDevice.cpp
|
||||||
if(QT_V LESS 6)
|
|
||||||
list(APPEND SOURCE_FILES
|
|
||||||
VideoDumper.cpp)
|
VideoDumper.cpp)
|
||||||
endif()
|
|
||||||
if (WIN32 AND QT_STATIC)
|
if (WIN32 AND QT_STATIC)
|
||||||
list(APPEND QT_LIBRARIES ${QT}::QWindowsAudioPlugin ${QT}::DSServicePlugin ${QT}::QWindowsVistaStylePlugin ${QT}::QJpegPlugin
|
list(APPEND QT_LIBRARIES ${QT}::QWindowsAudioPlugin ${QT}::DSServicePlugin ${QT}::QWindowsVistaStylePlugin ${QT}::QJpegPlugin
|
||||||
strmiids mfuuid mfplat mf ksguid dxva2 evr d3d9)
|
strmiids mfuuid mfplat mf ksguid dxva2 evr d3d9)
|
||||||
|
|
|
@ -5,59 +5,69 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
#include "VideoDumper.h"
|
#include "VideoDumper.h"
|
||||||
|
|
||||||
|
#include "VideoProcessor.h"
|
||||||
|
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QVideoSurfaceFormat>
|
|
||||||
|
|
||||||
using namespace QGBA;
|
using namespace QGBA;
|
||||||
|
|
||||||
VideoDumper::VideoDumper(QObject* parent)
|
VideoDumper::VideoDumper(QObject* parent)
|
||||||
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||||
: QAbstractVideoSurface(parent)
|
: QAbstractVideoSurface(parent)
|
||||||
|
#else
|
||||||
|
: QObject(parent)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VideoDumper::present(const QVideoFrame& frame) {
|
bool VideoDumper::present(const QVideoFrame& frame) {
|
||||||
QVideoFrame mappedFrame(frame);
|
QVideoFrame mappedFrame(frame);
|
||||||
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||||
if (!mappedFrame.map(QAbstractVideoBuffer::ReadOnly)) {
|
if (!mappedFrame.map(QAbstractVideoBuffer::ReadOnly)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
QVideoFrame::PixelFormat vFormat = mappedFrame.pixelFormat();
|
#else
|
||||||
QImage::Format format = QVideoFrame::imageFormatFromPixelFormat(vFormat);
|
if (!mappedFrame.map(QVideoFrame::ReadOnly)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
PixelFormat vFormat = mappedFrame.pixelFormat();
|
||||||
|
QImage::Format format = imageFormatFromPixelFormat(vFormat);
|
||||||
bool swap = false;
|
bool swap = false;
|
||||||
#ifdef USE_FFMPEG
|
#ifdef USE_FFMPEG
|
||||||
bool useScaler = false;
|
bool useScaler = false;
|
||||||
#endif
|
#endif
|
||||||
if (format == QImage::Format_Invalid) {
|
if (format == QImage::Format_Invalid) {
|
||||||
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||||
if (vFormat < QVideoFrame::Format_BGRA5658_Premultiplied) {
|
if (vFormat < QVideoFrame::Format_BGRA5658_Premultiplied) {
|
||||||
vFormat = static_cast<QVideoFrame::PixelFormat>(vFormat - QVideoFrame::Format_BGRA32 + QVideoFrame::Format_ARGB32);
|
vFormat = static_cast<QVideoFrame::PixelFormat>(vFormat - QVideoFrame::Format_BGRA32 + QVideoFrame::Format_ARGB32);
|
||||||
format = QVideoFrame::imageFormatFromPixelFormat(vFormat);
|
#else
|
||||||
if (format == QImage::Format_ARGB32) {
|
if (vFormat < PixelFormat::Format_AYUV) {
|
||||||
format = QImage::Format_RGBA8888;
|
#endif
|
||||||
} else if (format == QImage::Format_ARGB32_Premultiplied) {
|
format = imageFormatFromPixelFormat(vFormat);
|
||||||
format = QImage::Format_RGBA8888_Premultiplied;
|
|
||||||
}
|
|
||||||
swap = true;
|
swap = true;
|
||||||
} else {
|
} else {
|
||||||
#ifdef USE_FFMPEG
|
#ifdef USE_FFMPEG
|
||||||
enum AVPixelFormat pixelFormat;
|
enum AVPixelFormat pixelFormat;
|
||||||
switch (vFormat) {
|
switch (vFormat) {
|
||||||
case QVideoFrame::Format_YUV420P:
|
case VideoDumper::PixelFormat::Format_YUV420P:
|
||||||
pixelFormat = AV_PIX_FMT_YUV420P;
|
pixelFormat = AV_PIX_FMT_YUV420P;
|
||||||
break;
|
break;
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||||
case QVideoFrame::Format_YUV422P:
|
case VideoDumper::PixelFormat::Format_YUV422P:
|
||||||
pixelFormat = AV_PIX_FMT_YUV422P;
|
pixelFormat = AV_PIX_FMT_YUV422P;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case QVideoFrame::Format_YUYV:
|
case VideoDumper::PixelFormat::Format_YUYV:
|
||||||
pixelFormat = AV_PIX_FMT_YUYV422;
|
pixelFormat = AV_PIX_FMT_YUYV422;
|
||||||
break;
|
break;
|
||||||
case QVideoFrame::Format_UYVY:
|
case VideoDumper::PixelFormat::Format_UYVY:
|
||||||
pixelFormat = AV_PIX_FMT_UYVY422;
|
pixelFormat = AV_PIX_FMT_UYVY422;
|
||||||
break;
|
break;
|
||||||
case QVideoFrame::Format_NV12:
|
case VideoDumper::PixelFormat::Format_NV12:
|
||||||
pixelFormat = AV_PIX_FMT_NV12;
|
pixelFormat = AV_PIX_FMT_NV12;
|
||||||
break;
|
break;
|
||||||
case QVideoFrame::Format_NV21:
|
case VideoDumper::PixelFormat::Format_NV21:
|
||||||
pixelFormat = AV_PIX_FMT_NV12;
|
pixelFormat = AV_PIX_FMT_NV12;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -80,11 +90,15 @@ bool VideoDumper::present(const QVideoFrame& frame) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
uchar* bits = mappedFrame.bits();
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||||
|
Direction direction = surfaceFormat().scanLineDirection();
|
||||||
|
#else
|
||||||
|
Direction direction = mappedFrame.surfaceFormat().scanLineDirection();
|
||||||
|
#endif
|
||||||
#ifdef USE_FFMPEG
|
#ifdef USE_FFMPEG
|
||||||
QImage image;
|
QImage image;
|
||||||
if (!useScaler) {
|
if (!useScaler) {
|
||||||
image = QImage(bits, mappedFrame.width(), mappedFrame.height(), mappedFrame.bytesPerLine(), format);
|
image = QImage(mappedFrame.bits(0), mappedFrame.width(), mappedFrame.height(), mappedFrame.bytesPerLine(0), format);
|
||||||
}
|
}
|
||||||
if (useScaler) {
|
if (useScaler) {
|
||||||
image = QImage(mappedFrame.width(), mappedFrame.height(), format);
|
image = QImage(mappedFrame.width(), mappedFrame.height(), format);
|
||||||
|
@ -99,14 +113,14 @@ bool VideoDumper::present(const QVideoFrame& frame) {
|
||||||
sws_scale(m_scaler, planes, strides, 0, mappedFrame.height(), &outBits, &outStride);
|
sws_scale(m_scaler, planes, strides, 0, mappedFrame.height(), &outBits, &outStride);
|
||||||
} else
|
} else
|
||||||
#else
|
#else
|
||||||
QImage image(bits, mappedFrame.width(), mappedFrame.height(), mappedFrame.bytesPerLine(), format);
|
QImage image(mappedFrame.bits(0), mappedFrame.width(), mappedFrame.height(), mappedFrame.bytesPerLine(0), format);
|
||||||
#endif
|
#endif
|
||||||
if (swap) {
|
if (swap) {
|
||||||
image = image.rgbSwapped();
|
image = image.rgbSwapped();
|
||||||
} else if (surfaceFormat().scanLineDirection() != QVideoSurfaceFormat::BottomToTop) {
|
} else if (direction != Direction::BottomToTop) {
|
||||||
image = image.copy(); // Create a deep copy of the bits
|
image = image.copy(); // Create a deep copy of the bits
|
||||||
}
|
}
|
||||||
if (surfaceFormat().scanLineDirection() == QVideoSurfaceFormat::BottomToTop) {
|
if (direction == Direction::BottomToTop) {
|
||||||
image = image.mirrored();
|
image = image.mirrored();
|
||||||
}
|
}
|
||||||
mappedFrame.unmap();
|
mappedFrame.unmap();
|
||||||
|
@ -114,29 +128,63 @@ bool VideoDumper::present(const QVideoFrame& frame) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||||
QList<QVideoFrame::PixelFormat> VideoDumper::supportedPixelFormats(QAbstractVideoBuffer::HandleType) const {
|
QList<QVideoFrame::PixelFormat> VideoDumper::supportedPixelFormats(QAbstractVideoBuffer::HandleType) const {
|
||||||
QList<QVideoFrame::PixelFormat> list;
|
return VideoDumper::supportedPixelFormats();
|
||||||
list.append(QVideoFrame::Format_RGB32);
|
}
|
||||||
list.append(QVideoFrame::Format_ARGB32);
|
#endif
|
||||||
list.append(QVideoFrame::Format_RGB24);
|
|
||||||
list.append(QVideoFrame::Format_ARGB32_Premultiplied);
|
QList<VideoDumper::PixelFormat> VideoDumper::supportedPixelFormats() {
|
||||||
list.append(QVideoFrame::Format_RGB565);
|
QList<VideoDumper::PixelFormat> list{{
|
||||||
list.append(QVideoFrame::Format_RGB555);
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||||
list.append(QVideoFrame::Format_BGR32);
|
VideoDumper::PixelFormat::Format_RGB32,
|
||||||
list.append(QVideoFrame::Format_BGRA32);
|
VideoDumper::PixelFormat::Format_ARGB32,
|
||||||
list.append(QVideoFrame::Format_BGR24);
|
VideoDumper::PixelFormat::Format_RGB24,
|
||||||
list.append(QVideoFrame::Format_BGRA32_Premultiplied);
|
VideoDumper::PixelFormat::Format_ARGB32_Premultiplied,
|
||||||
list.append(QVideoFrame::Format_BGR565);
|
VideoDumper::PixelFormat::Format_RGB565,
|
||||||
list.append(QVideoFrame::Format_BGR555);
|
VideoDumper::PixelFormat::Format_RGB555,
|
||||||
|
VideoDumper::PixelFormat::Format_BGR32,
|
||||||
|
VideoDumper::PixelFormat::Format_BGRA32,
|
||||||
|
VideoDumper::PixelFormat::Format_BGR24,
|
||||||
|
VideoDumper::PixelFormat::Format_BGRA32_Premultiplied,
|
||||||
|
VideoDumper::PixelFormat::Format_BGR565,
|
||||||
|
VideoDumper::PixelFormat::Format_BGR555,
|
||||||
|
#else
|
||||||
|
VideoDumper::PixelFormat::Format_XRGB8888,
|
||||||
|
VideoDumper::PixelFormat::Format_ARGB8888,
|
||||||
|
VideoDumper::PixelFormat::Format_ARGB8888_Premultiplied,
|
||||||
|
VideoDumper::PixelFormat::Format_RGBX8888,
|
||||||
|
VideoDumper::PixelFormat::Format_RGBA8888,
|
||||||
|
VideoDumper::PixelFormat::Format_XBGR8888,
|
||||||
|
VideoDumper::PixelFormat::Format_ABGR8888,
|
||||||
|
VideoDumper::PixelFormat::Format_BGRX8888,
|
||||||
|
VideoDumper::PixelFormat::Format_BGRA8888,
|
||||||
|
VideoDumper::PixelFormat::Format_BGRA8888_Premultiplied,
|
||||||
|
#endif
|
||||||
#ifdef USE_FFMPEG
|
#ifdef USE_FFMPEG
|
||||||
list.append(QVideoFrame::Format_YUYV);
|
VideoDumper::PixelFormat::Format_YUYV,
|
||||||
list.append(QVideoFrame::Format_UYVY);
|
VideoDumper::PixelFormat::Format_UYVY,
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||||
list.append(QVideoFrame::Format_YUV422P);
|
VideoDumper::PixelFormat::Format_YUV422P,
|
||||||
#endif
|
#endif
|
||||||
list.append(QVideoFrame::Format_YUV420P);
|
VideoDumper::PixelFormat::Format_YUV420P,
|
||||||
list.append(QVideoFrame::Format_NV12);
|
VideoDumper::PixelFormat::Format_NV12,
|
||||||
list.append(QVideoFrame::Format_NV21);
|
VideoDumper::PixelFormat::Format_NV21,
|
||||||
#endif
|
#endif
|
||||||
|
}};
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QImage::Format VideoDumper::imageFormatFromPixelFormat(VideoDumper::PixelFormat vFormat) {
|
||||||
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||||
|
QImage::Format format = QVideoFrame::imageFormatFromPixelFormat(vFormat);
|
||||||
|
#else
|
||||||
|
QImage::Format format = QVideoFrameFormat::imageFormatFromPixelFormat(vFormat);
|
||||||
|
#endif
|
||||||
|
if (format == QImage::Format_ARGB32) {
|
||||||
|
format = QImage::Format_RGBA8888;
|
||||||
|
} else if (format == QImage::Format_ARGB32_Premultiplied) {
|
||||||
|
format = QImage::Format_RGBA8888_Premultiplied;
|
||||||
|
}
|
||||||
|
return format;
|
||||||
|
}
|
||||||
|
|
|
@ -5,7 +5,13 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||||
#include <QAbstractVideoSurface>
|
#include <QAbstractVideoSurface>
|
||||||
|
#include <QVideoSurfaceFormat>
|
||||||
|
#else
|
||||||
|
#include <QVideoFrameFormat>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef USE_FFMPEG
|
#ifdef USE_FFMPEG
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -15,14 +21,38 @@ extern "C" {
|
||||||
|
|
||||||
namespace QGBA {
|
namespace QGBA {
|
||||||
|
|
||||||
class VideoDumper : public QAbstractVideoSurface {
|
class VideoDumper : public
|
||||||
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||||
|
QAbstractVideoSurface
|
||||||
|
#else
|
||||||
|
QObject
|
||||||
|
#endif
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||||
|
using PixelFormat = QVideoFrame::PixelFormat;
|
||||||
|
using Direction = QVideoSurfaceFormat::Direction;
|
||||||
|
#else
|
||||||
|
using PixelFormat = QVideoFrameFormat::PixelFormat;
|
||||||
|
using Direction = QVideoFrameFormat::Direction;
|
||||||
|
#endif
|
||||||
|
|
||||||
VideoDumper(QObject* parent = nullptr);
|
VideoDumper(QObject* parent = nullptr);
|
||||||
|
|
||||||
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||||
|
QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType type) const override;
|
||||||
|
#endif
|
||||||
|
static QList<PixelFormat> supportedPixelFormats();
|
||||||
|
static QImage::Format imageFormatFromPixelFormat(PixelFormat);
|
||||||
|
|
||||||
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||||
bool present(const QVideoFrame& frame) override;
|
bool present(const QVideoFrame& frame) override;
|
||||||
QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType type = QAbstractVideoBuffer::NoHandle) const override;
|
#else
|
||||||
|
public slots:
|
||||||
|
bool present(const QVideoFrame& frame);
|
||||||
|
#endif
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void imageAvailable(const QImage& image);
|
void imageAvailable(const QImage& image);
|
||||||
|
|
Loading…
Reference in New Issue