Skip to content

Commit

Permalink
examples: add EGL and log options
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Nov 20, 2015
1 parent 230b7c6 commit 0266fe3
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 13 deletions.
8 changes: 5 additions & 3 deletions examples/QMLPlayer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ int main(int argc, char *argv[])
options.add(QLatin1String("QMLPlayer options"))
("scale", 1.0, QLatin1String("scale of graphics context. 0: auto"))
;
options.parse(argc, argv);
do_common_options_before_qapp(options);

QGuiApplication app(argc, argv);
app.setApplicationName(QStringLiteral("QMLPlayer"));
app.setApplicationDisplayName(QStringLiteral("QtAV QMLPlayer"));
options.parse(argc, argv);
do_common_options(options);

QDir::setCurrent(qApp->applicationDirPath());

do_common_options(options);
qDebug() << "arguments======= " << app.arguments();
set_opengl_backend(options.option(QStringLiteral("gl")).value().toString(), app.arguments().first());
load_qm(QStringList() << QStringLiteral("QMLPlayer"), options.value(QStringLiteral("language")).toString());
Expand Down
58 changes: 57 additions & 1 deletion examples/QMLPlayer/qml/QMLPlayer/MiscPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import "utils.js" as Utils

Page {
title: qsTr("Misc")
height: titleHeight + (1+glSet.visible*4)*Utils.kItemHeight + detail.contentHeight + 3*Utils.kSpacing
height: titleHeight + (4+glSet.visible*4)*Utils.kItemHeight + detail.contentHeight + 4*Utils.kSpacing

Column {
anchors.fill: content
Expand All @@ -29,6 +29,27 @@ Page {
text: qsTr("Press on the preview item to seek")
}
}
Row {
width: parent.width
height: Utils.kItemHeight
Button {
text: "EGL"
visible: Qt.platform.os === "linux"
checkable: true
checked: PlayerConfig.EGL
width: parent.width/3
height: Utils.kItemHeight
onCheckedChanged: PlayerConfig.EGL = checked
}
Text {
font.pixelSize: Utils.kFontSize
color: "white"
width: parent.width*2/3
height: parent.height
horizontalAlignment: Text.AlignHCenter
text: qsTr("Requirement") + ": Qt>=5.5+XCB"
}
}
Text {
width: parent.width
height: Utils.kItemHeight
Expand Down Expand Up @@ -104,7 +125,42 @@ Page {
}
}
}
Row {
width: parent.width
height: 2*Utils.kItemHeight
spacing: Utils.kSpacing
Text {
font.pixelSize: Utils.kFontSize
color: "white"
width: parent.width/3
height: parent.height
horizontalAlignment: Text.AlignHCenter
text: "Log"
}
Menu {
width: parent.width/2
height: parent.height
itemWidth: width
model: ListModel {
id: logModel
ListElement { name: "off" }
ListElement { name: "warning" }
ListElement { name: "debug" }
ListElement { name: "all" }
}
onClicked: PlayerConfig.logLevel = logModel.get(index).name
Component.onCompleted: {
for (var i = 0; i < logModel.count; ++i) {
if (PlayerConfig.logLevel === logModel.get(i).name) {
currentIndex = i
break
}
}
}
}
}
}

Component.onCompleted: {
if (PlayerConfig.openGLType === 2) {
angle.sourceComponent = angleMenu
Expand Down
36 changes: 36 additions & 0 deletions examples/common/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Config::Data
}

QSettings settings(file, QSettings::IniFormat);
log = settings.value(QString::fromLatin1("log"), QString()).toString();
last_file = settings.value(QString::fromLatin1("last_file"), QString()).toString();
timeout = settings.value(QString::fromLatin1("timeout"), 30.0).toReal();
abort_timeout = settings.value(QString::fromLatin1("abort_timeout"), true).toBool();
Expand Down Expand Up @@ -143,6 +144,7 @@ class Config::Data
avfilterAudio = settings.value(QString::fromLatin1("options"), QString()).toString();
settings.endGroup();
settings.beginGroup(QString::fromLatin1("opengl"));
egl = settings.value(QString::fromLatin1("egl"), false).toBool();
const QString glname = settings.value(QString::fromLatin1("type"), QString::fromLatin1("OpenGLES")).toString();
opengl = (Config::OpenGLType)Config::staticMetaObject.enumerator(Config::staticMetaObject.indexOfEnumerator("OpenGLType")).keysToValue(glname.toLatin1().constData());
// d3d11 bad performance (gltexsubimage2d)
Expand All @@ -158,6 +160,7 @@ class Config::Data
qDebug() << "sync config to " << file;
QSettings settings(file, QSettings::IniFormat);
// TODO: why crash on mac qt5.4 if call on aboutToQuit()
settings.setValue(QString::fromLatin1("log"), log);
settings.setValue(QString::fromLatin1("last_file"), last_file);
settings.setValue(QString::fromLatin1("timeout"), timeout);
settings.setValue(QString::fromLatin1("abort_timeout"), abort_timeout);
Expand Down Expand Up @@ -209,6 +212,7 @@ class Config::Data
settings.setValue(QString::fromLatin1("options"), avfilterAudio);
settings.endGroup();
settings.beginGroup(QString::fromLatin1("opengl"));
settings.setValue(QString::fromLatin1("egl"), egl);
const char* glname = Config::staticMetaObject.enumerator(Config::staticMetaObject.indexOfEnumerator("OpenGLType")).valueToKey(opengl);
settings.setValue(QString::fromLatin1("type"), QString::fromLatin1(glname));
settings.setValue(QString::fromLatin1("angle_platform"), angle_dx);
Expand Down Expand Up @@ -256,11 +260,13 @@ class Config::Data
bool preview_enabled;
int preview_w, preview_h;

bool egl;
Config::OpenGLType opengl;
QString angle_dx;
bool abort_timeout;
qreal timeout;
int buffer_value;
QString log;
};

Config& Config::instance()
Expand Down Expand Up @@ -753,6 +759,21 @@ Config& Config::avfilterAudioEnable(bool e)
return *this;
}

bool Config::isEGL() const
{
return mpData->egl;
}

Config& Config::setEGL(bool value)
{
if (mpData->egl == value)
return *this;
mpData->egl = value;
Q_EMIT EGLChanged();
Q_EMIT changed();
return *this;
}

Config::OpenGLType Config::openGLType() const
{
return mpData->opengl;
Expand Down Expand Up @@ -813,6 +834,21 @@ Config& Config::setTimeout(qreal value)
return *this;
}

QString Config::logLevel() const
{
return mpData->log;
}

Config& Config::setLogLevel(const QString& value)
{
if (mpData->log == value.toLower())
return *this;
mpData->log = value.toLower();
Q_EMIT logLevelChanged();
Q_EMIT changed();
return *this;
}

bool Config::abortOnTimeout() const
{
return mpData->abort_timeout;
Expand Down
11 changes: 11 additions & 0 deletions examples/common/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ class COMMON_EXPORT Config : public QObject
Q_PROPERTY(bool previewEnabled READ previewEnabled WRITE setPreviewEnabled NOTIFY previewEnabledChanged)
Q_PROPERTY(int previewWidth READ previewWidth WRITE setPreviewWidth NOTIFY previewWidthChanged)
Q_PROPERTY(int previewHeight READ previewHeight WRITE setPreviewHeight NOTIFY previewHeightChanged)
Q_PROPERTY(bool EGL READ isEGL WRITE setEGL NOTIFY EGLChanged)
Q_PROPERTY(OpenGLType openGLType READ openGLType WRITE setOpenGLType NOTIFY openGLTypeChanged)
Q_PROPERTY(QString ANGLEPlatform READ getANGLEPlatform WRITE setANGLEPlatform NOTIFY ANGLEPlatformChanged)
Q_PROPERTY(bool avformatOptionsEnabled READ avformatOptionsEnabled WRITE setAvformatOptionsEnabled NOTIFY avformatOptionsEnabledChanged)
Q_PROPERTY(qreal timeout READ timeout WRITE setTimeout NOTIFY timeoutChanged)
Q_PROPERTY(int bufferValue READ bufferValue WRITE setBufferValue NOTIFY bufferValueChanged)
Q_PROPERTY(QString logLevel READ logLevel WRITE setLogLevel NOTIFY logLevelChanged)
Q_ENUMS(OpenGLType)
public:
enum OpenGLType { // currently only for windows
Expand Down Expand Up @@ -169,6 +171,9 @@ class COMMON_EXPORT Config : public QObject
bool avfilterAudioEnable() const;
Config& avfilterAudioEnable(bool e);

// currently only for xcb
bool isEGL() const;
Config& setEGL(bool value);
// can be "Desktop", "OpenGLES", "Software"
OpenGLType openGLType() const;
Config& setOpenGLType(OpenGLType value);
Expand All @@ -187,6 +192,10 @@ class COMMON_EXPORT Config : public QObject
int bufferValue() const;
Config& setBufferValue(int value);

// can be: "", "off", "debug", "warning", "critical", "fatal", "all"
QString logLevel() const;
Config& setLogLevel(const QString& value);

Q_INVOKABLE QVariant operator ()(const QString& key) const;
Q_INVOKABLE Config& operator ()(const QString& key, const QVariant& value);
public:
Expand Down Expand Up @@ -217,12 +226,14 @@ class COMMON_EXPORT Config : public QObject
Q_SIGNAL void previewEnabledChanged();
Q_SIGNAL void previewWidthChanged();
Q_SIGNAL void previewHeightChanged();
Q_SIGNAL void EGLChanged();
Q_SIGNAL void openGLTypeChanged();
Q_SIGNAL void ANGLEPlatformChanged();
Q_SIGNAL void avformatOptionsEnabledChanged();
Q_SIGNAL void bufferValueChanged();
Q_SIGNAL void timeoutChanged();
Q_SIGNAL void abortOnTimeoutChanged();
Q_SIGNAL void logLevelChanged();
protected:
explicit Config(QObject *parent = 0);
~Config();
Expand Down
17 changes: 16 additions & 1 deletion examples/common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ QOptions get_common_options()
.add(QString::fromLatin1("common options"))
("help,h", QLatin1String("print this"))
("ao", QString(), QLatin1String("audio output. Can be ordered combination of available backends (-ao help). Leave empty to use the default setting. Set 'null' to disable audio."))
("-egl", QLatin1String("Use EGL. Only works for Qt>=5.5+XCB"))
("-gl", QLatin1String("OpenGL backend for Qt>=5.4(windows). can be 'desktop', 'opengles' and 'software'"))
("x", 0, QString())
("y", 0, QLatin1String("y"))
Expand All @@ -105,6 +106,18 @@ QOptions get_common_options()
return ops;
}

void do_common_options_before_qapp(const QOptions& options)
{
// it's too late if qApp is created. but why ANGLE is not?
if (options.value(QString::fromLatin1("egl")).toBool() || Config::instance().isEGL()) {
// only apply to current run. no config change
qputenv("QT_XCB_GL_INTEGRATION", "xcb_egl");
} else {
qputenv("QT_XCB_GL_INTEGRATION", "xcb_glx");
}
qDebug() << "QT_XCB_GL_INTEGRATION: " << qgetenv("QT_XCB_GL_INTEGRATION");
}

void do_common_options(const QOptions &options, const QString& appName)
{
if (options.value(QString::fromLatin1("help")).toBool()) {
Expand All @@ -127,7 +140,9 @@ void do_common_options(const QOptions &options, const QString& appName)
qWarning() << "Failed to open log file '" << fileLogger()->fileName() << "': " << fileLogger()->errorString();
}
}
const QByteArray level(options.value(QString::fromLatin1("log")).toByteArray());
QByteArray level(options.value(QString::fromLatin1("log")).toByteArray());
if (level.isEmpty())
level = Config::instance().logLevel().toLatin1();
if (!level.isEmpty())
qputenv("QTAV_LOG", level);
}
Expand Down
2 changes: 2 additions & 0 deletions examples/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
#include "ScreenSaver.h"

QOptions COMMON_EXPORT get_common_options();
void COMMON_EXPORT do_common_options_before_qapp(const QOptions& options);
/// help, log file, ffmpeg log level
void COMMON_EXPORT do_common_options(const QOptions& options, const QString& appName = QString());
void COMMON_EXPORT load_qm(const QStringList& names, const QString &lang = QLatin1String("system"));
// if appname ends with 'desktop', 'es', 'angle', software', 'sw', set by appname. otherwise set by command line option glopt, or Config file
// TODO: move to do_common_options_before_qapp
void COMMON_EXPORT set_opengl_backend(const QString& glopt = QString::fromLatin1("auto"), const QString& appname = QString());

QString COMMON_EXPORT appDataDir();
Expand Down
23 changes: 22 additions & 1 deletion examples/player/config/MiscPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,30 @@ MiscPage::MiscPage()
m_opengl->addItem(QString::fromLatin1("Desktop"), Config::Desktop);
m_opengl->addItem(QString::fromLatin1("OpenGLES"), Config::OpenGLES);
m_opengl->addItem(QString::fromLatin1("Software"), Config::Software);
m_opengl->setToolTip(tr("Windows only") + QString::fromLatin1("\n") + tr("OpenGLES is Used by DXVA Zero Copy"));
m_opengl->setToolTip(tr("Windows only") + " Qt>=5.4 + dynamicgl" + QString::fromLatin1("\n") + tr("OpenGLES is Used by DXVA Zero Copy"));
gl->addWidget(m_opengl, r, 1);
m_angle_platform = new QComboBox();
m_angle_platform->setToolTip(tr("D3D9 has performance if ZeroCopy is disabled or for software decoders") + QString::fromLatin1("\n") + tr("RESTART REQUIRED"));
m_angle_platform->addItems(QStringList() << QString::fromLatin1("D3D9") << QString::fromLatin1("D3D11") << QString::fromLatin1("AUTO") << QString::fromLatin1("WARP"));
#ifndef QT_OPENGL_DYNAMIC
m_opengl->setEnabled(false);
m_angle_platform->setEnabled(false);
#endif
gl->addWidget(m_angle_platform, r++, 2);

gl->addWidget(new QLabel("EGL"), r, 0);
m_egl = new QCheckBox();
m_egl->setToolTip(tr("Currently only works for Qt>=5.5 XCB build"));
#if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) || !defined(Q_OS_LINUX)
m_egl->setEnabled(false);
#endif
gl->addWidget(m_egl, r++, 1);

gl->addWidget(new QLabel("Log"), r, 0);
m_log = new QComboBox();
m_log->addItems(QStringList() << QString::fromLatin1("off") << QString::fromLatin1("warning") << QString::fromLatin1("debug") << QString::fromLatin1("all"));
gl->addWidget(m_log, r++, 1);

applyToUi();
}

Expand All @@ -98,12 +115,14 @@ void MiscPage::applyFromUi()
Config::instance().setPreviewEnabled(m_preview_on->isChecked())
.setPreviewWidth(m_preview_w->value())
.setPreviewHeight(m_preview_h->value())
.setEGL(m_egl->isChecked())
.setOpenGLType((Config::OpenGLType)m_opengl->itemData(m_opengl->currentIndex()).toInt())
.setANGLEPlatform(m_angle_platform->currentText().toLower())
.setForceFrameRate(m_fps->value())
.setBufferValue(m_buffer_value->value())
.setTimeout(m_timeout->value())
.setAbortOnTimeout(m_timeout_abort->isChecked())
.setLogLevel(m_log->currentText().toLower())
;
}

Expand All @@ -114,9 +133,11 @@ void MiscPage::applyToUi()
m_preview_h->setValue(Config::instance().previewHeight());
m_opengl->setCurrentIndex(m_opengl->findData(Config::instance().openGLType()));
m_angle_platform->setCurrentIndex(m_angle_platform->findText(Config::instance().getANGLEPlatform().toUpper()));
m_egl->setChecked(Config::instance().isEGL());
m_fps->setValue(Config::instance().forceFrameRate());
//m_notify_interval->setValue(Config::instance().avfilterOptions());
m_buffer_value->setValue(Config::instance().bufferValue());
m_timeout->setValue(Config::instance().timeout());
m_timeout_abort->setChecked(Config::instance().abortOnTimeout());
m_log->setCurrentIndex(m_log->findText(Config::instance().logLevel().toLower()));
}
2 changes: 2 additions & 0 deletions examples/player/config/MiscPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class MiscPage : public ConfigPageBase
QCheckBox *m_timeout_abort;
QComboBox *m_opengl;
QComboBox *m_angle_platform;
QCheckBox *m_egl;
QComboBox *m_log;
};

#endif // MISCPAGE_H
16 changes: 9 additions & 7 deletions examples/player/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,6 @@ VideoRendererId rendererId_from_opt_name(const QString& name) {
int main(int argc, char *argv[])
{
qDebug() << aboutQtAV_PlainText();
QApplication a(argc, argv);
a.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
qDebug() <<a.arguments();
a.setApplicationName(QString::fromLatin1("Player"));
// a.setApplicationDisplayName(QString::fromLatin1("QtAV Player"));

QDir::setCurrent(qApp->applicationDirPath());
QOptions options = get_common_options();
options.add(QString::fromLatin1("player options"))
("ffmpeg-log", QString(), QString::fromLatin1("ffmpeg log level. can be: quiet, panic, fatal, error, warn, info, verbose, debug. this can override env 'QTAV_FFMPEG_LOG'"))
Expand All @@ -84,6 +77,15 @@ int main(int argc, char *argv[])
, QString::fromLatin1("video renderer engine. can be gl, qt, d2d, gdi, xv, x11."))
;
options.parse(argc, argv);
do_common_options_before_qapp(options);

QApplication a(argc, argv);
a.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
qDebug() <<a.arguments();
a.setApplicationName(QString::fromLatin1("Player"));
// a.setApplicationDisplayName(QString::fromLatin1("QtAV Player"));
QDir::setCurrent(qApp->applicationDirPath());

do_common_options(options);
set_opengl_backend(options.option(QString::fromLatin1("gl")).value().toString(), a.arguments().first());
load_qm(QStringList() << QString::fromLatin1("player"), options.value(QString::fromLatin1("language")).toString());
Expand Down

0 comments on commit 0266fe3

Please sign in to comment.