Skip to content

Commit

Permalink
qt6 support
Browse files Browse the repository at this point in the history
no qml. examples are wip.
fix wang-bin#1381, wang-bin#1294, wang-bin#1389
  • Loading branch information
wang-bin committed Jan 8, 2022
1 parent b156991 commit ce21c55
Show file tree
Hide file tree
Showing 46 changed files with 215 additions and 115 deletions.
2 changes: 1 addition & 1 deletion QtAV.pro
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 10,7 @@ libqtav.file = src/libQtAV.pro
libqtavwidgets.depends = libqtav
examples.depends = libqtavwidgets #TODO: enable widgets based examples
}
greaterThan(QT_MAJOR_VERSION, 4) {
isEqual(QT_MAJOR_VERSION, 5) {
# qtHaveModule does not exist in Qt5.0
isEqual(QT_MINOR_VERSION, 0)|qtHaveModule(quick) {
SUBDIRS = libqmlav
Expand Down
6 changes: 5 additions & 1 deletion examples/common/Config.cpp
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
/******************************************************************************
QtAV Player Demo: this file is part of QtAV examples
Copyright (C) 2012-2017 Wang Bin <[email protected]>
Copyright (C) 2012-2022 Wang Bin <[email protected]>
* This file is part of QtAV (from 2014)
Expand Down Expand Up @@ -305,7 305,11 @@ void Config::reload()
settings.beginGroup(QString::fromLatin1("decoder"));
settings.beginGroup(QString::fromLatin1("video"));
QString decs_default(QString::fromLatin1("HW FFmpeg")); // HW is ignored
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
setDecoderPriorityNames(settings.value(QString::fromLatin1("priority"), decs_default).toString().split(QString::fromLatin1(" "), Qt::SkipEmptyParts));
#else
setDecoderPriorityNames(settings.value(QString::fromLatin1("priority"), decs_default).toString().split(QString::fromLatin1(" "), QString::SkipEmptyParts));
#endif
setZeroCopy(settings.value(QString::fromLatin1("zeroCopy"), true).toBool());
settings.endGroup(); //video
settings.endGroup(); //decoder
Expand Down
4 changes: 2 additions & 2 deletions examples/common/qoptions.cpp
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
/******************************************************************************
QOptions: make command line options easy. https://github.com/wang-bin/qoptions
Copyright (C) 2011-2015 Wang Bin <[email protected]>
Copyright (C) 2011-2022 Wang Bin <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -241,7 241,7 @@ bool QOptions::parse(int argc, const char *const*argv)
QString sname = it_list->shortName();
int sname_len = sname.length(); //usally is 1
//TODO: startsWith(-height,-h) Not endsWith, -oabco
if (it->midRef(1).compare(sname) == 0) {
if (it->mid(1).compare(sname) == 0) {
if (it_list->type() == QOption::NoToken) {
it_list->setValue(true);
it = args.erase(it);
Expand Down
10 changes: 5 additions & 5 deletions examples/filters/SimpleFilter.cpp
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <[email protected]>
Copyright (C) 2012-2022 Wang Bin <[email protected]>
* This file is part of QtAV (from 2013)
Expand All @@ -22,7 22,7 @@
#include "SimpleFilter.h"
#include <QWidget>
#include <math.h>

#include <QTime>
namespace QtAV {

SimpleFilter::SimpleFilter(QObject *parent):
Expand Down Expand Up @@ -124,10 124,10 @@ void SimpleFilter::process(Statistics *statistics, VideoFrame *frame)
int i16 = (t i) & 15;
ctx->pen.setColor(QColor::fromHsv((15-i16)*16, 255, 255));
if (mCanRot)
ctx->drawPlainText(QPointF(x-fm.width(mText)/2-ctx->rect.x(), y-sin_tbl[i16]*h/400), mText.mid(i, 1));
ctx->drawPlainText(QPointF(x-fm.boundingRect(mText).width()/2-ctx->rect.x(), y-sin_tbl[i16]*h/400), mText.mid(i, 1));
else
ctx->drawPlainText(QPointF(x, y-sin_tbl[i16]*h/400), mText.mid(i, 1));
x = fm.width(mText[i]);
x = fm.boundingRect(mText[i]).width();
}
} else {
qreal c = fabs(sin((float)t));
Expand All @@ -142,7 142,7 @@ void SimpleFilter::process(Statistics *statistics, VideoFrame *frame)
return;
if (mCanRot) {
QFontMetrics fm(ctx->font);
ctx->drawPlainText(QRectF(-fm.width(mText)/2, ctx->rect.y(), ctx->rect.width(), ctx->rect.height()), Qt::TextWordWrap, mText);
ctx->drawPlainText(QRectF(-fm.boundingRect(mText).width()/2, ctx->rect.y(), ctx->rect.width(), ctx->rect.height()), Qt::TextWordWrap, mText);
} else {
ctx->drawPlainText(ctx->rect, Qt::TextWordWrap, mText);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/filters/SimpleFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 23,7 @@
#define QTAV_EXAMPLE_SIMPLEFILTER_H

#include <QtAV/Filter.h>
#include <QtCore/QTime>
#include <QtCore/QElapsedTimer>
#include <QtGui/QMatrix4x4>

namespace QtAV {
Expand Down Expand Up @@ -52,7 52,7 @@ class SimpleFilter : public VideoFilter
private:
bool mCanRot;
bool mWave;
QTime mTime;
QElapsedTimer mTime;
qreal mStartValue;
QString mText;
QMatrix4x4 mMat;
Expand Down
4 changes: 3 additions & 1 deletion examples/player/TVView.cpp
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
/******************************************************************************
QtAV Player Demo: this file is part of QtAV examples
Copyright (C) 2012-2014 Wang Bin <[email protected]>
Copyright (C) 2012-2022 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -60,7 60,9 @@ void TVView::load()
if (!tv_file.open(QIODevice::ReadOnly))
return;
QTextStream ts(&tv_file);
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
ts.setCodec("UTF-8");
#endif
QTreeWidgetItem *nodeItem = new QTreeWidgetItem(mpView);
nodeItem->setData(0, Qt::DisplayRole, QString());
mpView->addTopLevelItem(nodeItem);
Expand Down
26 changes: 22 additions & 4 deletions examples/player/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
/******************************************************************************
QtAV Player Demo: this file is part of QtAV examples
Copyright (C) 2012-2015 Wang Bin <[email protected]>
Copyright (C) 2012-2022 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -144,15 144,33 @@ int main(int argc, char *argv[])
QString aos(op.value().toString());
QStringList ao;
if (aos.contains(QString::fromLatin1(";")))
ao = aos.split(QString::fromLatin1(";"), QString::SkipEmptyParts);
ao = aos.split(QString::fromLatin1(";"),
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
Qt::SkipEmptyParts
#else
QString::SkipEmptyParts
#endif
);
else
ao = aos.split(QString::fromLatin1(","), QString::SkipEmptyParts);
ao = aos.split(QString::fromLatin1(","),
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
Qt::SkipEmptyParts
#else
QString::SkipEmptyParts
#endif
);
window.setAudioBackends(ao);
}

op = options.option(QString::fromLatin1("vd"));
if (op.isSet()) {
QStringList vd = op.value().toString().split(QString::fromLatin1(";"), QString::SkipEmptyParts);
QStringList vd = op.value().toString().split(QString::fromLatin1(";"),
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
Qt::SkipEmptyParts
#else
QString::SkipEmptyParts
#endif
);
if (!vd.isEmpty())
window.setVideoDecoderNames(vd);
}
Expand Down
1 change: 1 addition & 0 deletions examples/player/player.pro
Original file line number Diff line number Diff line change
@@ -1,6 1,7 @@
TARGET = Player
TEMPLATE = app
contains(QT_CONFIG, opengl): QT = opengl
greaterThan(QT_MAJOR_VERSION, 5): QT = opengl
QT = sql svg
greaterThan(QT_MAJOR_VERSION, 4): QT = widgets
TRANSLATIONS = res/player_zh_CN.ts res/player.ts
Expand Down
4 changes: 2 additions & 2 deletions examples/videographicsitem/videoplayer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
/******************************************************************************
this file is part of QtAV examples
Copyright (C) 2012-2015 Wang Bin <[email protected]>
Copyright (C) 2012-2022 Wang Bin <[email protected]>
* This file is part of QtAV
Expand All @@ -21,7 21,7 @@
#include "videoplayer.h"
#include <QGraphicsView>

#ifndef QT_NO_OPENGL
#if !defined(QT_NO_OPENGL) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
#include <QtOpenGL/QGLWidget>
#endif

Expand Down
21 changes: 12 additions & 9 deletions examples/videogroup/videogroup.cpp
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
/******************************************************************************
VideoGroup: this file is part of QtAV examples
Copyright (C) 2012-2015 Wang Bin <[email protected]>
Copyright (C) 2012-2022 Wang Bin <[email protected]>
* This file is part of QtAV
Expand All @@ -20,14 20,17 @@

#include "videogroup.h"
#include <QApplication>
#include <QDesktopWidget>
#include <QEvent>
#include <QFileDialog>
#include <QGridLayout>
#include <QtCore/QUrl>
#include <QtAV/AudioOutput.h>
#include <QtAVWidgets>

#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
#define DESKTOP_RECT() qApp->desktop()->rect()
#else
#define DESKTOP_RECT() qApp->primaryScreen()->availableGeometry()
#endif
using namespace QtAV;

VideoGroup::VideoGroup(QObject *parent) :
Expand Down Expand Up @@ -114,7 117,7 @@ void VideoGroup::setSingleWindow(bool s)
if (view)
return;
view = new QWidget;
view->resize(qApp->desktop()->size());
view->resize(DESKTOP_RECT().size());
QGridLayout *layout = new QGridLayout;
layout->setSizeConstraint(QLayout::SetMaximumSize);
layout->setSpacing(1);
Expand Down Expand Up @@ -227,14 230,14 @@ void VideoGroup::addRenderer()
wf |= Qt::FramelessWindowHint;
}
renderer->widget()->setWindowFlags(wf);
int w = view ? view->frameGeometry().width()/c : qApp->desktop()->width()/c;
int h = view ? view->frameGeometry().height()/r : qApp->desktop()->height()/r;
int w = view ? view->frameGeometry().width()/c : DESKTOP_RECT().width()/c;
int h = view ? view->frameGeometry().height()/r : DESKTOP_RECT().height()/r;
renderer->widget()->resize(w, h);
mpPlayer->addVideoRenderer(renderer);
int i = (mRenderers.size()-1)/cols();
int j = (mRenderers.size()-1)%cols();
if (view) {
view->resize(qApp->desktop()->size());
view->resize(DESKTOP_RECT().size());
((QGridLayout*)view->layout())->addWidget(renderer->widget(), i, j);
view->show();
} else {
Expand Down Expand Up @@ -268,8 271,8 @@ void VideoGroup::updateROI()
}
return;
}
int W = view ? view->frameGeometry().width() : qApp->desktop()->width();
int H = view ? view->frameGeometry().height() : qApp->desktop()->height();
int W = view ? view->frameGeometry().width() : DESKTOP_RECT().width();
int H = view ? view->frameGeometry().height() : DESKTOP_RECT().height();
int w = W / c;
int h = H / r;
for (int i = 0; i < mRenderers.size(); i) {
Expand Down
1 change: 1 addition & 0 deletions examples/window/window.pro
Original file line number Diff line number Diff line change
@@ -1,6 1,7 @@
TEMPLATE = app
CONFIG -= app_bundle
QT = core gui
greaterThan(QT_MAJOR_VERSION, 5): QT = opengl
PROJECTROOT = $$PWD/../..
include($$PROJECTROOT/src/libQtAV.pri)
preparePaths($$OUT_PWD/../../out)
Expand Down
6 changes: 3 additions & 3 deletions qml/MediaMetaData.cpp
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <[email protected]>
Copyright (C) 2012-2022 Wang Bin <[email protected]>
* This file is part of QtAV (from 2014)
Expand Down Expand Up @@ -76,8 76,8 @@ void MediaMetaData::setValuesFromStatistics(const QtAV::Statistics &st)
setValue(TrackNumber, it.value().toInt());
continue;
}
setValue(TrackNumber, it.value().leftRef(slash).string()->toInt()); //QStringRef.toInt(): Qt5.2
setValue(TrackCount, it.value().midRef(slash 1).string()->toInt());
setValue(TrackNumber, it.value().left(slash).string()->toInt()); //QStringRef.toInt(): Qt5.2
setValue(TrackCount, it.value().mid(slash 1).string()->toInt());
continue;
}
if (keyName == QLatin1String("date")
Expand Down
12 changes: 10 additions & 2 deletions qml/QQuickItemRenderer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2017 Wang Bin <[email protected]>
Copyright (C) 2012-2022 Wang Bin <[email protected]>
theoribeiro <[email protected]>
* This file is part of QtAV (from 2013)
Expand Down Expand Up @@ -112,9 112,17 @@ bool QQuickItemRenderer::event(QEvent *e)
return true;
}

#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
void QQuickItemRenderer::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
#else
void QQuickItemRenderer::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
#endif
{
QQuickItem::geometryChanged(newGeometry, oldGeometry); //geometry will be updated
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
QQuickItem::geometryChange(newGeometry, oldGeometry);
#else
QQuickItem::geometryChanged(newGeometry, oldGeometry);
#endif
DPTR_D(QQuickItemRenderer);
resizeRenderer(newGeometry.size().toSize());
if (d.fill_mode == PreserveAspectCrop) {
Expand Down
8 changes: 4 additions & 4 deletions qml/QuickFBORenderer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2017 Wang Bin <[email protected]>
Copyright (C) 2012-2022 Wang Bin <[email protected]>
* This file is part of QtAV (from 2015)
Expand All @@ -27,13 27,13 @@
#include "QtAV/private/mkid.h"
#include "QtAV/private/factory.h"
#include <QtCore/QCoreApplication>
#include <QtGui/QOpenGLFunctions>
#include <QtGui/QOpenGLFramebufferObject>
#include <QOpenGLFunctions>
#include <QOpenGLFramebufferObject>
#include <QtQuick/QQuickWindow>
// for dynamicgl. qglfunctions before qt5.3 does not have portable gl functions
// use qt gl func if possible to avoid linking to opengl directly
#if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)
#include <QtGui/QOpenGLFunctions>
#include <QOpenGLFunctions>
#define DYGL(glFunc) QOpenGLContext::currentContext()->functions()->glFunc
#else
#define DYGL(glFunc) glFunc
Expand Down
4 changes: 2 additions & 2 deletions qml/SGVideoNode.cpp
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <[email protected]>
Copyright (C) 2012-2022 Wang Bin <[email protected]>
* This file is part of QtAV (from 2014)
Expand All @@ -24,7 24,7 @@
#include "QtAV/VideoShader.h"
#include "QtAV/VideoFrame.h"
#include <QtCore/QScopedPointer>
#include <QtGui/QOpenGLFunctions>
#include <QOpenGLFunctions>
#include <QtQuick/QSGMaterial>
#include <QtQuick/QSGMaterialShader>

Expand Down
11 changes: 10 additions & 1 deletion src/AVDemuxer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2018 Wang Bin <[email protected]>
Copyright (C) 2012-2022 Wang Bin <[email protected]>
* This file is part of QtAV
Expand All @@ -23,6 23,7 @@
#include "QtAV/private/AVCompat.h"
#include <QtCore/QMutex>
#include <QtCore/QStringList>
#include <QtCore/QIODevice>
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
#include <QtCore/QElapsedTimer>
#else
Expand Down Expand Up @@ -366,10 367,18 @@ static void getFFmpegInputFormats(QStringList* formats, QStringList* extensions)
av_register_all(); // MUST register all input/output formats
while ((i = av_iformat_next(i))) {
#endif

#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
if (i->extensions)
e << QString::fromLatin1(i->extensions).split(QLatin1Char(','), Qt::SkipEmptyParts);
if (i->name)
f << QString::fromLatin1(i->name).split(QLatin1Char(','), Qt::SkipEmptyParts);
#else
if (i->extensions)
e << QString::fromLatin1(i->extensions).split(QLatin1Char(','), QString::SkipEmptyParts);
if (i->name)
f << QString::fromLatin1(i->name).split(QLatin1Char(','), QString::SkipEmptyParts);
#endif
}
foreach (const QString& v, e) {
exts.append(v.trimmed());
Expand Down
Loading

0 comments on commit ce21c55

Please sign in to comment.