Beispiel #1
0
void do_common_options(const QOptions &options, const QString& appName)
{
    if (options.value(QString::fromLatin1("help")).toBool()) {
        options.print();
        exit(0);
    }
    // has no effect if qInstallMessageHandler() called
    //qSetMessagePattern("%{function} @%{line}: %{message}");
    QString app(appName);
    if (app.isEmpty() && qApp)
        app = qApp->applicationName();
    QString logfile(options.option(QString::fromLatin1("logfile")).value().toString().arg(app));
    if (!logfile.isEmpty()) {
        qDebug("set log file");
        fileLogger()->setFileName(logfile);
        if (fileLogger()->open(QIODevice::WriteOnly)) {
            qDebug() << "Logger";
            qInstallMessageHandler(Logger);
        } else {
            qWarning() << "Failed to open log file '" << fileLogger()->fileName() << "': " << fileLogger()->errorString();
        }
    }
    QByteArray level(options.value(QString::fromLatin1("log")).toByteArray());
    if (level.isEmpty())
        level = Config::instance().logLevel().toLatin1();
    if (!level.isEmpty())
        qputenv("QTAV_LOG", level);
}
Beispiel #2
0
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");
}
Beispiel #3
0
void do_common_options(const QOptions &options, const QString& appName)
{
    if (options.value(QString::fromLatin1("help")).toBool()) {
        options.print();
        exit(0);
    }
    // has no effect if qInstallMessageHandler() called
    //qSetMessagePattern("%{function} @%{line}: %{message}");
#if !defined(Q_OS_WINRT) && !defined(Q_OS_ANDROID)
    QString app(appName);
    if (app.isEmpty() && qApp)
        app = qApp->applicationName();
    QString logfile(options.option(QString::fromLatin1("logfile")).value().toString().arg(app));
    if (!logfile.isEmpty()) {
        if (QDir(logfile).isRelative()) {
            QString log_path(QString::fromLatin1("%1/%2").arg(qApp->applicationDirPath()).arg(logfile));
            QFile f(log_path);
            if (!f.open(QIODevice::WriteOnly)) {
                log_path = QString::fromLatin1("%1/%2").arg(appDataDir()).arg(logfile);
                qDebug() << "executable dir is not writable. log to " << log_path;
            }
            logfile = log_path;
        }
        qDebug() << "set log file: " << logfile;
        fileLogger()->setFileName(logfile);
        if (fileLogger()->open(QIODevice::WriteOnly)) {
            qDebug() << "Logger";
            qInstallMessageHandler(Logger);
        } else {
            qWarning() << "Failed to open log file '" << fileLogger()->fileName() << "': " << fileLogger()->errorString();
        }
    }
#endif
    QByteArray level(options.value(QString::fromLatin1("log")).toByteArray());
    if (level.isEmpty())
        level = Config::instance().logLevel().toLatin1();
    if (!level.isEmpty())
        qputenv("QTAV_LOG", level);
}
Beispiel #4
0
void do_common_options_before_qapp(const QOptions& options)
{
#ifdef Q_OS_LINUX
    QSettings cfg(Config::defaultConfigFile(), QSettings::IniFormat);
    const bool set_egl = cfg.value("opengl/egl").toBool();
    //https://bugreports.qt.io/browse/QTBUG-49529
    // it's too late if qApp is created. but why ANGLE is not?
    if (options.value(QString::fromLatin1("egl")).toBool() || set_egl) { //FIXME: Config is constructed too early because it requires qApp
        // 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");
#endif //Q_OS_LINUX
}
Beispiel #5
0
int main(int argc, char *argv[])
{
    qDebug() << aboutQtAV_PlainText();
    QApplication a(argc, argv);
    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'"))
            ("-vo",
#ifndef QT_NO_OPENGL
#ifdef Q_OS_ANDROID
             QString::fromLatin1("opengl")
#else
             QString::fromLatin1("gl")
#endif
#else
             QString::fromLatin1("qt")
#endif
             , QString::fromLatin1("video renderer engine. can be gl, qt, d2d, gdi, xv, x11."))
            ;
    options.parse(argc, argv);
    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());
    QtAV::setFFmpegLogLevel(options.value(QString::fromLatin1("ffmpeg-log")).toByteArray());

    QOption op = options.option(QString::fromLatin1("vo"));
    QString vo = op.value().toString();
    if (!op.isSet()) {
        QString exe(a.arguments().at(0));
        int i = exe.lastIndexOf(QLatin1Char('-'));
        if (i > 0) {
            vo = exe.mid(i+1, exe.indexOf(QLatin1Char('.')) - i - 1);
        }
    }
    qDebug("vo: %s", vo.toUtf8().constData());
    MainWindow window;
    window.setProperty("rendererId", rendererId_from_opt_name(vo.toLower()));
    window.show();
    window.setWindowTitle(QString::fromLatin1("QtAV %1 [email protected]").arg(QtAV_Version_String_Long()));
    AppEventFilter ae(&window);
    qApp->installEventFilter(&ae);

    int x = window.x();
    int y = window.y();
    op = options.option(QString::fromLatin1("width"));
    int w = op.value().toInt();
    op = options.option(QString::fromLatin1("height"));
    int h = op.value().toInt();
    op = options.option(QString::fromLatin1("x"));
    if (op.isSet())
        x = op.value().toInt();
    op = options.option(QString::fromLatin1("y"));
    if (op.isSet())
        y = op.value().toInt();
    window.resize(w, h);
    window.move(x, y);
    if (options.value(QString::fromLatin1("fullscreen")).toBool())
        window.showFullScreen();

    op = options.option(QString::fromLatin1("ao"));
    if (op.isSet()) {
        QString aos(op.value().toString());
        QStringList ao;
        if (aos.contains(QString::fromLatin1(";")))
            ao = aos.split(QString::fromLatin1(";"), QString::SkipEmptyParts);
        else
            ao = aos.split(QString::fromLatin1(","), QString::SkipEmptyParts);
        window.setAudioBackends(ao);
    }

    op = options.option(QString::fromLatin1("vd"));
    if (op.isSet()) {
        QStringList vd = op.value().toString().split(QString::fromLatin1(";"), QString::SkipEmptyParts);
        if (!vd.isEmpty())
            window.setVideoDecoderNames(vd);
    }
    op = options.option(QString::fromLatin1("file"));
    if (op.isSet()) {
        qDebug() << "-f set: " << op.value().toString();
        window.play(op.value().toString());
    } else {
        if (argc > 1 && !a.arguments().last().startsWith(QLatin1Char('-')) && !a.arguments().at(argc-2).startsWith(QLatin1Char('-')))
            window.play(a.arguments().last());
    }
    int ret = a.exec();
    return ret;
}