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)
|
||||
list(APPEND AUDIO_SRC
|
||||
AudioProcessorQt.cpp
|
||||
AudioDevice.cpp)
|
||||
if(QT_V LESS 6)
|
||||
list(APPEND SOURCE_FILES
|
||||
VideoDumper.cpp)
|
||||
endif()
|
||||
AudioDevice.cpp
|
||||
VideoDumper.cpp)
|
||||
if (WIN32 AND QT_STATIC)
|
||||
list(APPEND QT_LIBRARIES ${QT}::QWindowsAudioPlugin ${QT}::DSServicePlugin ${QT}::QWindowsVistaStylePlugin ${QT}::QJpegPlugin
|
||||
strmiids mfuuid mfplat mf ksguid dxva2 evr d3d9)
|
||||
|
|
|
@ -5,59 +5,69 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
#include "VideoDumper.h"
|
||||
|
||||
#include "VideoProcessor.h"
|
||||
|
||||
#include <QImage>
|
||||
#include <QVideoSurfaceFormat>
|
||||
|
||||
using namespace QGBA;
|
||||
|
||||
VideoDumper::VideoDumper(QObject* parent)
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
: QAbstractVideoSurface(parent)
|
||||
#else
|
||||
: QObject(parent)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
bool VideoDumper::present(const QVideoFrame& frame) {
|
||||
QVideoFrame mappedFrame(frame);
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
if (!mappedFrame.map(QAbstractVideoBuffer::ReadOnly)) {
|
||||
return false;
|
||||
}
|
||||
QVideoFrame::PixelFormat vFormat = mappedFrame.pixelFormat();
|
||||
QImage::Format format = QVideoFrame::imageFormatFromPixelFormat(vFormat);
|
||||
#else
|
||||
if (!mappedFrame.map(QVideoFrame::ReadOnly)) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
PixelFormat vFormat = mappedFrame.pixelFormat();
|
||||
QImage::Format format = imageFormatFromPixelFormat(vFormat);
|
||||
bool swap = false;
|
||||
#ifdef USE_FFMPEG
|
||||
bool useScaler = false;
|
||||
#endif
|
||||
if (format == QImage::Format_Invalid) {
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
if (vFormat < QVideoFrame::Format_BGRA5658_Premultiplied) {
|
||||
vFormat = static_cast<QVideoFrame::PixelFormat>(vFormat - QVideoFrame::Format_BGRA32 + QVideoFrame::Format_ARGB32);
|
||||
format = QVideoFrame::imageFormatFromPixelFormat(vFormat);
|
||||
if (format == QImage::Format_ARGB32) {
|
||||
format = QImage::Format_RGBA8888;
|
||||
} else if (format == QImage::Format_ARGB32_Premultiplied) {
|
||||
format = QImage::Format_RGBA8888_Premultiplied;
|
||||
}
|
||||
#else
|
||||
if (vFormat < PixelFormat::Format_AYUV) {
|
||||
#endif
|
||||
format = imageFormatFromPixelFormat(vFormat);
|
||||
swap = true;
|
||||
} else {
|
||||
#ifdef USE_FFMPEG
|
||||
enum AVPixelFormat pixelFormat;
|
||||
switch (vFormat) {
|
||||
case QVideoFrame::Format_YUV420P:
|
||||
case VideoDumper::PixelFormat::Format_YUV420P:
|
||||
pixelFormat = AV_PIX_FMT_YUV420P;
|
||||
break;
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
case QVideoFrame::Format_YUV422P:
|
||||
case VideoDumper::PixelFormat::Format_YUV422P:
|
||||
pixelFormat = AV_PIX_FMT_YUV422P;
|
||||
break;
|
||||
#endif
|
||||
case QVideoFrame::Format_YUYV:
|
||||
case VideoDumper::PixelFormat::Format_YUYV:
|
||||
pixelFormat = AV_PIX_FMT_YUYV422;
|
||||
break;
|
||||
case QVideoFrame::Format_UYVY:
|
||||
case VideoDumper::PixelFormat::Format_UYVY:
|
||||
pixelFormat = AV_PIX_FMT_UYVY422;
|
||||
break;
|
||||
case QVideoFrame::Format_NV12:
|
||||
case VideoDumper::PixelFormat::Format_NV12:
|
||||
pixelFormat = AV_PIX_FMT_NV12;
|
||||
break;
|
||||
case QVideoFrame::Format_NV21:
|
||||
case VideoDumper::PixelFormat::Format_NV21:
|
||||
pixelFormat = AV_PIX_FMT_NV12;
|
||||
break;
|
||||
default:
|
||||
|
@ -80,11 +90,15 @@ bool VideoDumper::present(const QVideoFrame& frame) {
|
|||
#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
|
||||
QImage image;
|
||||
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) {
|
||||
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);
|
||||
} 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
|
||||
if (swap) {
|
||||
image = image.rgbSwapped();
|
||||
} else if (surfaceFormat().scanLineDirection() != QVideoSurfaceFormat::BottomToTop) {
|
||||
} else if (direction != Direction::BottomToTop) {
|
||||
image = image.copy(); // Create a deep copy of the bits
|
||||
}
|
||||
if (surfaceFormat().scanLineDirection() == QVideoSurfaceFormat::BottomToTop) {
|
||||
if (direction == Direction::BottomToTop) {
|
||||
image = image.mirrored();
|
||||
}
|
||||
mappedFrame.unmap();
|
||||
|
@ -114,29 +128,63 @@ bool VideoDumper::present(const QVideoFrame& frame) {
|
|||
return true;
|
||||
}
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
QList<QVideoFrame::PixelFormat> VideoDumper::supportedPixelFormats(QAbstractVideoBuffer::HandleType) const {
|
||||
QList<QVideoFrame::PixelFormat> list;
|
||||
list.append(QVideoFrame::Format_RGB32);
|
||||
list.append(QVideoFrame::Format_ARGB32);
|
||||
list.append(QVideoFrame::Format_RGB24);
|
||||
list.append(QVideoFrame::Format_ARGB32_Premultiplied);
|
||||
list.append(QVideoFrame::Format_RGB565);
|
||||
list.append(QVideoFrame::Format_RGB555);
|
||||
list.append(QVideoFrame::Format_BGR32);
|
||||
list.append(QVideoFrame::Format_BGRA32);
|
||||
list.append(QVideoFrame::Format_BGR24);
|
||||
list.append(QVideoFrame::Format_BGRA32_Premultiplied);
|
||||
list.append(QVideoFrame::Format_BGR565);
|
||||
list.append(QVideoFrame::Format_BGR555);
|
||||
return VideoDumper::supportedPixelFormats();
|
||||
}
|
||||
#endif
|
||||
|
||||
QList<VideoDumper::PixelFormat> VideoDumper::supportedPixelFormats() {
|
||||
QList<VideoDumper::PixelFormat> list{{
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
VideoDumper::PixelFormat::Format_RGB32,
|
||||
VideoDumper::PixelFormat::Format_ARGB32,
|
||||
VideoDumper::PixelFormat::Format_RGB24,
|
||||
VideoDumper::PixelFormat::Format_ARGB32_Premultiplied,
|
||||
VideoDumper::PixelFormat::Format_RGB565,
|
||||
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
|
||||
list.append(QVideoFrame::Format_YUYV);
|
||||
list.append(QVideoFrame::Format_UYVY);
|
||||
VideoDumper::PixelFormat::Format_YUYV,
|
||||
VideoDumper::PixelFormat::Format_UYVY,
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
list.append(QVideoFrame::Format_YUV422P);
|
||||
VideoDumper::PixelFormat::Format_YUV422P,
|
||||
#endif
|
||||
list.append(QVideoFrame::Format_YUV420P);
|
||||
list.append(QVideoFrame::Format_NV12);
|
||||
list.append(QVideoFrame::Format_NV21);
|
||||
VideoDumper::PixelFormat::Format_YUV420P,
|
||||
VideoDumper::PixelFormat::Format_NV12,
|
||||
VideoDumper::PixelFormat::Format_NV21,
|
||||
#endif
|
||||
}};
|
||||
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/. */
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
#include <QAbstractVideoSurface>
|
||||
#include <QVideoSurfaceFormat>
|
||||
#else
|
||||
#include <QVideoFrameFormat>
|
||||
#endif
|
||||
|
||||
#ifdef USE_FFMPEG
|
||||
extern "C" {
|
||||
|
@ -15,14 +21,38 @@ extern "C" {
|
|||
|
||||
namespace QGBA {
|
||||
|
||||
class VideoDumper : public QAbstractVideoSurface {
|
||||
class VideoDumper : public
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
QAbstractVideoSurface
|
||||
#else
|
||||
QObject
|
||||
#endif
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
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);
|
||||
|
||||
#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;
|
||||
QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType type = QAbstractVideoBuffer::NoHandle) const override;
|
||||
#else
|
||||
public slots:
|
||||
bool present(const QVideoFrame& frame);
|
||||
#endif
|
||||
|
||||
signals:
|
||||
void imageAvailable(const QImage& image);
|
||||
|
|
Loading…
Reference in New Issue