Ignore:
Timestamp:
Jan 24, 2017, 12:41:54 PM (8 years ago)
Author:
Silvan Scherrer
Message:

SMPlayer: update trunk to version 17.1.0

Location:
smplayer/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • smplayer/trunk

  • smplayer/trunk/src/mpvoptions.cpp

    r181 r188  
    11/*  smplayer, GUI front-end for mplayer.
    2     Copyright (C) 2006-2016 Ricardo Villalba <rvm@users.sourceforge.net>
     2    Copyright (C) 2006-2017 Ricardo Villalba <rvm@users.sourceforge.net>
    33
    44    This program is free software; you can redistribute it and/or modify
     
    2020#include <QDebug>
    2121#include "inforeader.h"
     22#include "deviceinfo.h"
    2223
    2324void MPVProcess::addArgument(const QString & /*a*/) {
     
    3031                        "INFO_VIDEO_ASPECT=${=video-aspect}\n"
    3132//                      "INFO_VIDEO_DSIZE=${=dwidth}x${=dheight}\n"
    32                         "INFO_VIDEO_FPS=${=fps}\n"
     33                        "INFO_VIDEO_FPS=${=container-fps:${=fps}}\n"
    3334//                      "INFO_VIDEO_BITRATE=${=video-bitrate}\n"
    3435                        "INFO_VIDEO_FORMAT=${=video-format}\n"
     
    4748                        "INFO_LENGTH=${=duration:${=length}}\n"
    4849
    49                         "INFO_DEMUXER=${=demuxer}\n"
     50                        "INFO_DEMUXER=${=current-demuxer:${=demuxer}}\n"
    5051                        "INFO_SEEKABLE=${=seekable}\n"
    5152                        "INFO_TITLES=${=disc-titles}\n"
     
    6162                        "METADATA_COPYRIGHT=${metadata/by-key/copyright:}\n"
    6263
    63                         "INFO_MEDIA_TITLE=${=media-title:}\n";
     64                        "INFO_MEDIA_TITLE=${=media-title:}\n"
     65                        "INFO_STREAM_PATH=${stream-path}\n";
    6466
    6567#ifdef CUSTOM_STATUS
    66         arg << "--term-status-msg=STATUS: ${=time-pos} / ${=duration:${=length:0}} P: ${=pause} B: ${=paused-for-cache} I: ${=core-idle}";
     68        arg << "--term-status-msg=STATUS: ${=time-pos} / ${=duration:${=length:0}} P: ${=pause} B: ${=paused-for-cache} I: ${=core-idle} VB: ${=video-bitrate:0} AB: ${=audio-bitrate:0}";
    6769#endif
    6870
     
    7577#ifdef CAPTURE_STREAM
    7678        capturing = false;
     79#endif
     80
     81#ifdef OSD_WITH_TIMER
     82        if (!osd_timer) {
     83                osd_timer = new QTimer(this);
     84                osd_timer->setInterval(500);
     85                connect(osd_timer, SIGNAL(timeout()), this, SLOT(displayInfoOnOSD()));
     86        }
    7787#endif
    7888}
     
    90100void MPVProcess::disableInput() {
    91101        arg << "--no-input-default-bindings";
    92         arg << "--input-x11-keyboard=no";
     102        if (isOptionAvailable("--input-vo-keyboard")) {
     103                arg << "--input-vo-keyboard=no";
     104        } else {
     105                arg << "--input-x11-keyboard=no";
     106        }
    93107        arg << "--no-input-cursor";
    94108        arg << "--cursor-autohide=no";
     
    96110
    97111bool MPVProcess::isOptionAvailable(const QString & option) {
    98         InfoReader * ir = InfoReader::obj(executable());
    99         ir->getInfo();
    100         //qDebug() << "MPVProcess::isOptionAvailable: option_list:" << ir->optionList();
    101         return ir->optionList().contains(option);
     112        static QStringList option_list;
     113        static QString mpv_bin;
     114
     115        if (option_list.isEmpty() || mpv_bin != executable()) {
     116                InfoReader * ir = InfoReader::obj(executable());
     117                ir->getInfo();
     118                option_list = ir->optionList();
     119                mpv_bin = executable();
     120                //qDebug() << "MPVProcess::isOptionAvailable: option_list:" << option_list;
     121        }
     122
     123        return option_list.contains(option);
    102124}
    103125
     
    231253        if (option_name == "subfont-text-scale" || option_name == "ass-font-scale") {
    232254                arg << "--sub-scale=" + value.toString();
     255        }
     256        else
     257        if (option_name == "ass-line-spacing") {
     258                QString line_spacing = "--ass-line-spacing";
     259                if (isOptionAvailable("--sub-ass-line-spacing")) line_spacing = "--sub-ass-line-spacing";
     260                arg << line_spacing + "=" + value.toString();
     261        }
     262        else
     263        if (option_name == "ass-force-style") {
     264                QString ass_force_style = "--ass-force-style";
     265                if (isOptionAvailable("--sub-ass-force-style")) ass_force_style = "--sub-ass-force-style";
     266                arg << ass_force_style + "=" + value.toString();
    233267        }
    234268        else
     
    306340        }
    307341        else
     342        if (option_name == "vo") {
     343                QString vo = value.toString();
     344                if (vo.endsWith(",")) vo.chop(1);
     345                #ifndef Q_OS_WIN
     346                if (isOptionAvailable("--xv-adaptor")) {
     347                        QRegExp rx("xv:adaptor=(\\d+)");
     348                        if (rx.indexIn(vo) > -1) {
     349                                QString adaptor = rx.cap(1);
     350                                vo = "xv";
     351                                arg << "--xv-adaptor=" + adaptor;
     352                        }
     353                }
     354                #endif
     355                arg << "--vo=" + vo + ",";
     356        }
     357        else
    308358        if (option_name == "ao") {
    309                 QString o = value.toString();
    310                 if (o.startsWith("alsa:device=")) {
    311                         QString device = o.mid(12);
    312                         //qDebug() << "MPVProcess::setOption: alsa device:" << device;
    313                         device = device.replace("=", ":").replace(".", ",");
    314                         o = "alsa:device=[" + device + "]";
    315                 }
    316                 arg << "--ao=" + o;
     359                QString ao = value.toString();
     360
     361                QStringList l;
     362                if (ao.contains(":")) l = DeviceInfo::extractDevice(ao);
     363                if (l.count() > 0) ao = l[0];
     364
     365                if (isOptionAvailable("--audio-device")) {
     366                        if (l.count() == 3) {
     367                                #ifndef Q_OS_WIN
     368                                if (l[0] == "pulse") {
     369                                        arg << "--audio-device=pulse/" + l[2];
     370                                }
     371                                #if USE_MPV_ALSA_DEVICES
     372                                else
     373                                if (l[0] == "alsa") {
     374                                        arg << "--audio-device=alsa/" + l[1];
     375                                }
     376                                #endif
     377                                #else
     378                                if (l[0] == "dsound") {
     379                                        arg << "--audio-device=dsound/" + l[1];
     380                                }
     381                                else
     382                                if (l[0] == "wasapi") {
     383                                        arg << "--audio-device=wasapi/" + l[1];
     384                                }
     385                                #endif
     386                        }
     387                } else {
     388                        #ifndef Q_OS_WIN
     389                        if (l.count() > 1) {
     390                                if (l[0] == "alsa") {
     391                                        ao = "alsa:device=[hw:" + l[1] + "]";
     392                                }
     393                                else
     394                                if (l[0] == "pulse") {
     395                                        ao = "pulse::" + l[1];
     396                                }
     397                        }
     398                        #endif
     399                }
     400                arg << "--ao=" + ao + ",";
    317401        }
    318402        else
     
    368452        else
    369453        if (option_name == "wid" ||
    370             option_name == "vo" ||
    371454            option_name == "aid" || option_name == "vid" ||
    372455            option_name == "volume" ||
    373             option_name == "ass-styles" || option_name == "ass-force-style" ||
    374             option_name == "ass-line-spacing" ||
     456            option_name == "ass-styles" ||
    375457            option_name == "embeddedfonts" ||
    376458            option_name == "osd-scale" ||
     
    387469            option_name == "demuxer" ||
    388470            option_name == "frames" ||
     471            option_name == "user-agent" || option_name == "referrer" ||
    389472            option_name == "ab-loop-a" || option_name == "ab-loop-b")
    390473        {
     
    400483
    401484void MPVProcess::addUserOption(const QString & option) {
    402         arg << option;
     485        qDebug() << "MPVProcess::addUserOption:" << option;
     486
     487        // Remove quotes
     488        QString s = option;
     489        if (s.count("=\"") == 1 && s.endsWith("\"")) {
     490                s.replace("=\"", "=");
     491                s.chop(1);
     492        }
     493        else
     494        if (s.startsWith("\"") && s.endsWith("\"")) {
     495                s.remove(0, 1);
     496                s.chop(1);
     497        }
     498
     499        qDebug() << "MPVProcess::addUserOption: s:" << s;
     500
     501        arg << s;
    403502        if (option == "-v") {
    404503                verbose = true;
     
    621720
    622721void MPVProcess::showFilenameOnOSD() {
    623         writeToStdin("show_text \"${filename}\" 2000 0");
     722#ifdef OSD_WITH_TIMER
     723        toggleInfoOnOSD();
     724#else
     725        showOSDText("${filename}", 2000, 0);
     726#endif
    624727}
    625728
    626729void MPVProcess::showTimeOnOSD() {
    627         writeToStdin("show_text \"${time-pos} / ${length:0} (${percent-pos}%)\" 2000 0");
    628 }
     730#ifdef OSD_WITH_TIMER
     731        osd_timer->stop();
     732#endif
     733        writeToStdin("show_text \"${time-pos} ${?duration:/ ${duration} (${percent-pos}%)}\" 2000 0");
     734}
     735
     736#ifdef OSD_WITH_TIMER
     737void MPVProcess::toggleInfoOnOSD() {
     738        if (!osd_timer->isActive()) {
     739                osd_timer->start();
     740                displayInfoOnOSD();
     741        } else {
     742                osd_timer->stop();
     743                showOSDText("", 100, 0);
     744        }
     745}
     746
     747void MPVProcess::displayInfoOnOSD() {
     748        QString b1 = "{\\\\b1}";
     749        QString b0 = "{\\\\b0}";
     750        QString tab = "\\\\h\\\\h\\\\h\\\\h\\\\h";
     751        QString nl = "\\n";
     752
     753        QString s = "${osd-ass-cc/0}{\\\\fs14}" +
     754                b1 + tr("File:") + b0 +" ${filename}" + nl +
     755                "${time-pos} ${?duration:/ ${duration} (${percent-pos}%)}" + nl + nl +
     756                //b1 + tr("Title:") + b0 + " ${media-title}" + nl + nl +
     757                b1 + tr("Video:") + b0 + " ${video-codec}" + nl +
     758                tab + b1 + tr("Resolution:") + b0 +" ${=width}x${=height}" + nl +
     759                tab + b1 + tr("Frames per second:") + b0 + " ${container-fps:${fps}} " + b1 + tr("Estimated:") + b0 + " ${estimated-vf-fps}" + nl +
     760                //tab + b1 + tr("Display FPS:") + b0 + " ${display-fps}" + nl +
     761                tab + b1 + tr("Aspect Ratio:") + b0 + " ${video-params/aspect}" + nl +
     762                tab + b1 + tr("Bitrate:") + b0 + " ${video-bitrate}" + nl +
     763                tab + b1 + tr("Dropped frames:") + b0 + " ${drop-frame-count}" + nl +
     764                nl +
     765
     766                b1 + tr("Audio:") + b0 + " ${audio-codec}" + nl +
     767                tab + b1 + tr("Bitrate:") + b0 + " ${audio-bitrate}" + nl +
     768                tab + b1 + tr("Sample Rate:") + b0 + " ${audio-params/samplerate} Hz" + nl +
     769                tab + b1 + tr("Channels:") + b0 + " ${audio-params/channel-count}" + nl +
     770                nl +
     771
     772                b1 + tr("Audio/video synchronization:") + b0 + " ${avsync}" + nl +
     773                b1 + tr("Cache fill:") + b0 + " ${cache:0}%" + nl +
     774                b1 + tr("Used cache:") + b0 + " ${cache-used:0}" + nl;
     775
     776        if (!osd_media_info.isEmpty()) s = osd_media_info;
     777
     778        showOSDText(s, 2000, 0);
     779
     780        if (!isRunning()) osd_timer->stop();
     781}
     782#endif
    629783
    630784void MPVProcess::setContrast(int value) {
     
    9201074
    9211075void MPVProcess::setSubStyles(const AssStyles & styles, const QString &) {
     1076        QString sub_font = "--sub-text-font";
     1077        if (isOptionAvailable("--sub-font")) sub_font = "--sub-font";
     1078
     1079        QString sub_color = "--sub-text-color";
     1080        if (isOptionAvailable("--sub-color")) sub_color = "--sub-color";
     1081
     1082        QString sub_shadow_color = "--sub-text-shadow-color";
     1083        if (isOptionAvailable("--sub-shadow-color")) sub_shadow_color = "--sub-shadow-color";
     1084
     1085        QString sub_back_color = "--sub-text-back-color";
     1086        if (isOptionAvailable("--sub-back-color")) sub_back_color = "--sub-back-color";
     1087
     1088        QString sub_border_color = "--sub-text-border-color";
     1089        if (isOptionAvailable("--sub-border-color")) sub_border_color = "--sub-border-color";
     1090
     1091        QString sub_border_size = "--sub-text-border-size";
     1092        if (isOptionAvailable("--sub-border-size")) sub_border_size = "--sub-border-size";
     1093
     1094        QString sub_shadow_offset = "--sub-text-shadow-offset";
     1095        if (isOptionAvailable("--sub-shadow-offset")) sub_shadow_offset = "--sub-shadow-offset";
     1096
    9221097        QString font = styles.fontname;
    9231098        //arg << "--sub-text-font=" + font.replace(" ", "");
    924         arg << "--sub-text-font=" + font;
    925         arg << "--sub-text-color=#" + ColorUtils::colorToRRGGBB(styles.primarycolor);
     1099        arg << sub_font + "=" + font;
     1100        arg << sub_color + "=#" + ColorUtils::colorToAARRGGBB(styles.primarycolor);
    9261101
    9271102        if (styles.borderstyle == AssStyles::Outline) {
    928                 arg << "--sub-text-shadow-color=#" + ColorUtils::colorToRRGGBB(styles.backcolor);
     1103                arg << sub_shadow_color + "=#" + ColorUtils::colorToAARRGGBB(styles.backcolor);
    9291104        } else {
    930                 arg << "--sub-text-back-color=#" + ColorUtils::colorToRRGGBB(styles.outlinecolor);
    931         }
    932         arg << "--sub-text-border-color=#" + ColorUtils::colorToRRGGBB(styles.outlinecolor);
    933 
    934         arg << "--sub-text-border-size=" + QString::number(styles.outline * 2.5);
    935         arg << "--sub-text-shadow-offset=" + QString::number(styles.shadow * 2.5);
     1105                arg << sub_back_color + "=#" + ColorUtils::colorToAARRGGBB(styles.outlinecolor);
     1106        }
     1107        arg << sub_border_color + "=#" + ColorUtils::colorToAARRGGBB(styles.outlinecolor);
     1108
     1109        arg << sub_border_size + "=" + QString::number(styles.outline * 2.5);
     1110        arg << sub_shadow_offset + "=" + QString::number(styles.shadow * 2.5);
    9361111
    9371112        if (isOptionAvailable("--sub-text-font-size")) {
Note: See TracChangeset for help on using the changeset viewer.