/trunk/src/core.cpp
C++ | 4281 lines | 3200 code | 745 blank | 336 comment | 786 complexity | 56b02342a29a9fd8e318170113e67e6c MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- /* smplayer, GUI front-end for mplayer.
- Copyright (C) 2006-2012 Ricardo Villalba <rvm@users.sourceforge.net>
- 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
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
- #include "core.h"
- #include <QDir>
- #include <QFileInfo>
- #include <QRegExp>
- #include <QTextStream>
- #include <QUrl>
- #ifdef Q_OS_OS2
- #include <QEventLoop>
- #endif
- #include <cmath>
- #include "mplayerwindow.h"
- #include "desktopinfo.h"
- #include "helper.h"
- #include "paths.h"
- #include "preferences.h"
- #include "global.h"
- #include "config.h"
- #include "mplayerversion.h"
- #include "constants.h"
- #include "colorutils.h"
- #include "discname.h"
- #include "filters.h"
- #if defined(Q_OS_WIN) || defined(Q_OS_OS2)
- #ifdef Q_OS_WIN
- #include <windows.h> // To change app priority
- #include <QSysInfo> // To get Windows version
- #endif
- #ifdef SCREENSAVER_OFF
- #include "screensaver.h"
- #endif
- #endif
- #ifndef NO_USE_INI_FILES
- #include "filesettings.h"
- #include "filesettingshash.h"
- #include "tvsettings.h"
- #endif
- #ifdef YOUTUBE_SUPPORT
- #include "retrieveyoutubeurl.h"
- #endif
- using namespace Global;
- Core::Core( MplayerWindow *mpw, QWidget* parent )
- : QObject( parent )
- {
- qRegisterMetaType<Core::State>("Core::State");
- mplayerwindow = mpw;
- _state = Stopped;
- we_are_restarting = false;
- just_loaded_external_subs = false;
- just_unloaded_external_subs = false;
- change_volume_after_unpause = false;
- #if DVDNAV_SUPPORT
- dvdnav_title_is_menu = true; // Enabled by default for compatibility with previous versions of mplayer
- #endif
- #ifndef NO_USE_INI_FILES
- // Create file_settings
- file_settings = 0;
- changeFileSettingsMethod(pref->file_settings_method);
- // TV settings
- tv_settings = new TVSettings(Paths::iniPath());
- #endif
- proc = new MplayerProcess(this);
- // Do this the first
- connect( proc, SIGNAL(processExited()),
- mplayerwindow->videoLayer(), SLOT(playingStopped()) );
- connect( proc, SIGNAL(error(QProcess::ProcessError)),
- mplayerwindow->videoLayer(), SLOT(playingStopped()) );
- // Necessary to hide/unhide mouse cursor on black borders
- connect( proc, SIGNAL(processExited()),
- mplayerwindow, SLOT(playingStopped()) );
- connect( proc, SIGNAL(error(QProcess::ProcessError)),
- mplayerwindow, SLOT(playingStopped()) );
- connect( proc, SIGNAL(receivedCurrentSec(double)),
- this, SLOT(changeCurrentSec(double)) );
- connect( proc, SIGNAL(receivedCurrentFrame(int)),
- this, SIGNAL(showFrame(int)) );
- connect( proc, SIGNAL(receivedPause()),
- this, SLOT(changePause()) );
- connect( proc, SIGNAL(processExited()),
- this, SLOT(processFinished()), Qt::QueuedConnection );
- connect( proc, SIGNAL(mplayerFullyLoaded()),
- this, SLOT(finishRestart()), Qt::QueuedConnection );
- connect( proc, SIGNAL(lineAvailable(QString)),
- this, SIGNAL(logLineAvailable(QString)) );
- connect( proc, SIGNAL(receivedCacheMessage(QString)),
- this, SLOT(displayMessage(QString)) );
- connect( proc, SIGNAL(receivedCreatingIndex(QString)),
- this, SLOT(displayMessage(QString)) );
- connect( proc, SIGNAL(receivedConnectingToMessage(QString)),
- this, SLOT(displayMessage(QString)) );
- connect( proc, SIGNAL(receivedResolvingMessage(QString)),
- this, SLOT(displayMessage(QString)) );
- connect( proc, SIGNAL(receivedScreenshot(QString)),
- this, SLOT(displayScreenshotName(QString)) );
- connect( proc, SIGNAL(receivedUpdatingFontCache()),
- this, SLOT(displayUpdatingFontCache()) );
-
- connect( proc, SIGNAL(receivedScanningFont(QString)),
- this, SLOT(displayMessage(QString)) );
-
- connect( proc, SIGNAL(receivedWindowResolution(int,int)),
- this, SLOT(gotWindowResolution(int,int)) );
- connect( proc, SIGNAL(receivedNoVideo()),
- this, SLOT(gotNoVideo()) );
- connect( proc, SIGNAL(receivedVO(QString)),
- this, SLOT(gotVO(QString)) );
- connect( proc, SIGNAL(receivedAO(QString)),
- this, SLOT(gotAO(QString)) );
- connect( proc, SIGNAL(receivedEndOfFile()),
- this, SLOT(fileReachedEnd()), Qt::QueuedConnection );
- connect( proc, SIGNAL(receivedStartingTime(double)),
- this, SLOT(gotStartingTime(double)) );
- connect( proc, SIGNAL(receivedStreamTitle(QString)),
- this, SLOT(streamTitleChanged(QString)) );
- connect( proc, SIGNAL(receivedStreamTitleAndUrl(QString,QString)),
- this, SLOT(streamTitleAndUrlChanged(QString,QString)) );
- connect( proc, SIGNAL(failedToParseMplayerVersion(QString)),
- this, SIGNAL(failedToParseMplayerVersion(QString)) );
- connect( this, SIGNAL(mediaLoaded()), this, SLOT(checkIfVideoIsHD()), Qt::QueuedConnection );
- #if DELAYED_AUDIO_SETUP_ON_STARTUP
- connect( this, SIGNAL(mediaLoaded()), this, SLOT(initAudioTrack()), Qt::QueuedConnection );
- #endif
- #if NOTIFY_SUB_CHANGES
- connect( proc, SIGNAL(subtitleInfoChanged(const SubTracks &)),
- this, SLOT(initSubtitleTrack(const SubTracks &)), Qt::QueuedConnection );
- connect( proc, SIGNAL(subtitleInfoReceivedAgain(const SubTracks &)),
- this, SLOT(setSubtitleTrackAgain(const SubTracks &)), Qt::QueuedConnection );
- #endif
- #if NOTIFY_AUDIO_CHANGES
- connect( proc, SIGNAL(audioInfoChanged(const Tracks &)),
- this, SLOT(initAudioTrack(const Tracks &)), Qt::QueuedConnection );
- #endif
- #if DVDNAV_SUPPORT
- connect( proc, SIGNAL(receivedDVDTitle(int)),
- this, SLOT(dvdTitleChanged(int)), Qt::QueuedConnection );
- connect( proc, SIGNAL(receivedDuration(double)),
- this, SLOT(durationChanged(double)), Qt::QueuedConnection );
- QTimer * ask_timer = new QTimer(this);
- connect( ask_timer, SIGNAL(timeout()), this, SLOT(askForInfo()) );
- ask_timer->start(5000);
- connect( proc, SIGNAL(receivedTitleIsMenu()),
- this, SLOT(dvdTitleIsMenu()) );
- connect( proc, SIGNAL(receivedTitleIsMovie()),
- this, SLOT(dvdTitleIsMovie()) );
- #endif
-
- connect( this, SIGNAL(stateChanged(Core::State)),
- this, SLOT(watchState(Core::State)) );
- connect( this, SIGNAL(mediaInfoChanged()), this, SLOT(sendMediaInfo()) );
- connect( proc, SIGNAL(error(QProcess::ProcessError)),
- this, SIGNAL(mplayerFailed(QProcess::ProcessError)) );
- //pref->load();
- mset.reset();
- // Mplayerwindow
- connect( this, SIGNAL(aboutToStartPlaying()),
- mplayerwindow->videoLayer(), SLOT(playingStarted()) );
- // Necessary to hide/unhide mouse cursor on black borders
- connect( this, SIGNAL(aboutToStartPlaying()),
- mplayerwindow, SLOT(playingStarted()) );
- #if DVDNAV_SUPPORT
- connect( mplayerwindow, SIGNAL(mouseMoved(QPoint)),
- this, SLOT(dvdnavUpdateMousePos(QPoint)) );
- #endif
- #if REPAINT_BACKGROUND_OPTION
- mplayerwindow->videoLayer()->setRepaintBackground(pref->repaint_video_background);
- #endif
- mplayerwindow->setMonitorAspect( pref->monitor_aspect_double() );
- #if defined(Q_OS_WIN) || defined(Q_OS_OS2)
- #ifdef SCREENSAVER_OFF
- // Windows or OS2 screensaver
- win_screensaver = new WinScreenSaver();
- #endif
- #endif
- #if DISCNAME_TEST
- DiscName::test();
- #endif
- #ifdef YOUTUBE_SUPPORT
- yt = new RetrieveYoutubeUrl(this);
- connect(yt, SIGNAL(gotPreferredUrl(const QString &)), this, SLOT(openYT(const QString &)));
- connect(yt, SIGNAL(connecting(QString)), this, SLOT(connectingToYT(QString)));
- connect(yt, SIGNAL(downloadFailed(QString)), this, SLOT(YTFailed(QString)));
- connect(yt, SIGNAL(gotEmptyList()), this, SLOT(YTNoVideoUrl()));
- #endif
- }
- Core::~Core() {
- #ifndef NO_USE_INI_FILES
- saveMediaInfo();
- #endif
- if (proc->isRunning()) stopMplayer();
- proc->terminate();
- delete proc;
- #ifndef NO_USE_INI_FILES
- delete file_settings;
- delete tv_settings;
- #endif
- #if defined(Q_OS_WIN) || defined(Q_OS_OS2)
- #ifdef SCREENSAVER_OFF
- delete win_screensaver;
- #endif
- #endif
- #ifdef YOUTUBE_SUPPORT
- delete yt;
- #endif
- }
- #ifndef NO_USE_INI_FILES
- void Core::changeFileSettingsMethod(QString method) {
- qDebug("Core::changeFileSettingsMethod: %s", method.toUtf8().constData());
- if (file_settings) delete file_settings;
- if (method.toLower() == "hash")
- file_settings = new FileSettingsHash(Paths::iniPath());
- else
- file_settings = new FileSettings(Paths::iniPath());
- }
- #endif
- void Core::setState(State s) {
- if (s != _state) {
- _state = s;
- emit stateChanged(_state);
- }
- }
- QString Core::stateToString() {
- if (state()==Playing) return "Playing";
- else
- if (state()==Stopped) return "Stopped";
- else
- if (state()==Paused) return "Paused";
- else
- return "Unknown";
- }
- // Public restart
- void Core::restart() {
- qDebug("Core::restart");
- if (proc->isRunning()) {
- restartPlay();
- } else {
- qDebug("Core::restart: mplayer is not running");
- }
- }
- void Core::reload() {
- qDebug("Core::reload");
- stopMplayer();
- we_are_restarting = false;
- initPlaying();
- }
- #ifndef NO_USE_INI_FILES
- void Core::saveMediaInfo() {
- qDebug("Core::saveMediaInfo");
- if (pref->dont_remember_media_settings) {
- qDebug("Core::saveMediaInfo: not saving settings, disabled by user");
- return;
- }
- if ( (mdat.type == TYPE_FILE) && (!mdat.filename.isEmpty()) ) {
- file_settings->saveSettingsFor(mdat.filename, mset);
- }
- else
- if ( (mdat.type == TYPE_TV) && (!mdat.filename.isEmpty()) ) {
- tv_settings->saveSettingsFor(mdat.filename, mset);
- }
- }
- #endif // NO_USE_INI_FILES
- void Core::initializeMenus() {
- qDebug("Core::initializeMenus");
- emit menusNeedInitialize();
- }
- void Core::updateWidgets() {
- qDebug("Core::updateWidgets");
- emit widgetsNeedUpdate();
- }
- void Core::tellmp(const QString & command) {
- qDebug("Core::tellmp: '%s'", command.toUtf8().data());
- //qDebug("Command: '%s'", command.toUtf8().data());
- if (proc->isRunning()) {
- proc->writeToStdin( command );
- } else {
- qWarning(" tellmp: no process running: %s", command.toUtf8().data());
- }
- }
- void Core::displayTextOnOSD(QString text, int duration, int level, QString prefix) {
- qDebug("Core::displayTextOnOSD: '%s'", text.toUtf8().constData());
- if (proc->isRunning()) {
- QString str = QString("osd_show_text \"%1\" %2 %3\n").arg(text.toUtf8().constData()).arg(duration).arg(level);
- if (!prefix.isEmpty()) str = prefix + " " + str;
- qDebug("Core::displayTextOnOSD: command: '%s'", str.toUtf8().constData());
- proc->write(str.toAscii());
- }
- }
- // Generic open, autodetect type
- void Core::open(QString file, int seek) {
- qDebug("Core::open: '%s'", file.toUtf8().data());
- if (file.startsWith("file:")) {
- file = QUrl(file).toLocalFile();
- qDebug("Core::open: converting url to local file: %s", file.toUtf8().constData());
- }
- QFileInfo fi(file);
- if ( (fi.exists()) && (fi.suffix().toLower()=="iso") ) {
- qDebug("Core::open: * identified as a dvd iso");
- #if DVDNAV_SUPPORT
- openDVD( DiscName::joinDVD(0, file, pref->use_dvdnav) );
- #else
- openDVD( DiscName::joinDVD(1, file, false) );
- #endif
- }
- else
- if ( (fi.exists()) && (!fi.isDir()) ) {
- qDebug("Core::open: * identified as local file");
- // Local file
- file = QFileInfo(file).absoluteFilePath();
- openFile(file, seek);
- }
- else
- if ( (fi.exists()) && (fi.isDir()) ) {
- // Directory
- qDebug("Core::open: * identified as a directory");
- qDebug("Core::open: checking if contains a dvd");
- file = QFileInfo(file).absoluteFilePath();
- if (Helper::directoryContainsDVD(file)) {
- qDebug("Core::open: * directory contains a dvd");
- #if DVDNAV_SUPPORT
- openDVD( DiscName::joinDVD(1, file, pref->use_dvdnav) );
- #else
- openDVD( DiscName::joinDVD(1, file, false) );
- #endif
- } else {
- qDebug("Core::open: * directory doesn't contain a dvd");
- qDebug("Core::open: opening nothing");
- }
- }
- else
- if ((file.toLower().startsWith("dvd:")) || (file.toLower().startsWith("dvdnav:"))) {
- qDebug("Core::open: * identified as dvd");
- openDVD(file);
- /*
- QString f = file.lower();
- QRegExp s("^dvd://(\\d+)");
- if (s.indexIn(f) != -1) {
- int title = s.cap(1).toInt();
- openDVD(title);
- } else {
- qWarning("Core::open: couldn't parse dvd title, playing first one");
- openDVD();
- }
- */
- }
- else
- if (file.toLower().startsWith("vcd:")) {
- qDebug("Core::open: * identified as vcd");
- QString f = file.toLower();
- QRegExp s("^vcd://(\\d+)");
- if (s.indexIn(f) != -1) {
- int title = s.cap(1).toInt();
- openVCD(title);
- } else {
- qWarning("Core::open: couldn't parse vcd title, playing first one");
- openVCD();
- }
- }
- else
- if (file.toLower().startsWith("cdda:")) {
- qDebug("Core::open: * identified as cdda");
- QString f = file.toLower();
- QRegExp s("^cdda://(\\d+)");
- if (s.indexIn(f) != -1) {
- int title = s.cap(1).toInt();
- openAudioCD(title);
- } else {
- qWarning("Core::open: couldn't parse cdda title, playing first one");
- openAudioCD();
- }
- }
- else
- if ((file.toLower().startsWith("dvb:")) || (file.toLower().startsWith("tv:"))) {
- qDebug("Core::open: * identified as TV");
- openTV(file);
- }
- else {
- qDebug("Core::open: * not identified, playing as stream");
- openStream(file);
- }
- }
- void Core::openFile(QString filename, int seek) {
- qDebug("Core::openFile: '%s'", filename.toUtf8().data());
- QFileInfo fi(filename);
- if (fi.exists()) {
- playNewFile(fi.absoluteFilePath(), seek);
- } else {
- //File doesn't exists
- //TODO: error message
- }
- }
- #ifdef YOUTUBE_SUPPORT
- void Core::openYT(const QString & url) {
- qDebug("Core::openYT: %s", url.toUtf8().constData());
- openStream(url);
- yt->close();
- }
- void Core::connectingToYT(QString host) {
- emit showMessage( tr("Connecting to %1").arg(host) );
- }
- void Core::YTFailed(QString /*error*/) {
- emit showMessage( tr("Unable to retrieve youtube page") );
- }
- void Core::YTNoVideoUrl() {
- emit showMessage( tr("Unable to locate the url of the video") );
- }
- #endif
- void Core::loadSub(const QString & sub ) {
- if ( (!sub.isEmpty()) && (QFile::exists(sub)) ) {
- #if NOTIFY_SUB_CHANGES
- mset.external_subtitles = sub;
- just_loaded_external_subs = true;
- QFileInfo fi(sub);
- if ((pref->fast_load_sub) && (fi.suffix().toLower() != "idx")) {
- QString sub_file = sub;
- #ifdef Q_OS_WIN
- if (pref->use_short_pathnames) {
- sub_file = Helper::shortPathName(sub);
- // For some reason it seems it's necessary to change the path separator to unix style
- // otherwise mplayer fails to load it
- sub_file = sub_file.replace("\\","/");
- }
- #endif
- tellmp( "sub_load \""+ sub_file +"\"" );
- } else {
- restartPlay();
- }
- #else
- mset.external_subtitles = sub;
- just_loaded_external_subs = true;
- restartPlay();
- #endif
- } else {
- qWarning("Core::loadSub: file '%s' is not valid", sub.toUtf8().constData());
- }
- }
- void Core::unloadSub() {
- if ( !mset.external_subtitles.isEmpty() ) {
- mset.external_subtitles = "";
- just_unloaded_external_subs = true;
- restartPlay();
- }
- }
- void Core::loadAudioFile(const QString & audiofile) {
- if (!audiofile.isEmpty()) {
- mset.external_audio = audiofile;
- restartPlay();
- }
- }
- void Core::unloadAudioFile() {
- if (!mset.external_audio.isEmpty()) {
- mset.external_audio = "";
- restartPlay();
- }
- }
- /*
- void Core::openDVD( bool from_folder, QString directory) {
- qDebug("Core::openDVD");
- if (from_folder) {
- if (!directory.isEmpty()) {
- QFileInfo fi(directory);
- if ( (fi.exists()) && (fi.isDir()) ) {
- pref->dvd_directory = directory;
- pref->play_dvd_from_hd = TRUE;
- openDVD();
- } else {
- qDebug("Core::openDVD: directory '%s' is not valid", directory.toUtf8().data());
- }
- } else {
- qDebug("Core::openDVD: directory is empty");
- }
- } else {
- pref->play_dvd_from_hd = FALSE;
- openDVD();
- }
- }
- void Core::openDVD() {
- openDVD(1);
- }
- void Core::openDVD(int title) {
- qDebug("Core::openDVD: %d", title);
- if (proc->isRunning()) {
- stopMplayer();
- }
- // Save data of previous file:
- saveMediaInfo();
- mdat.reset();
- mdat.filename = "dvd://" + QString::number(title);
- mdat.type = TYPE_DVD;
- mset.reset();
- mset.current_title_id = title;
- mset.current_chapter_id = 1;
- mset.current_angle_id = 1;
- initializeMenus();
- initPlaying();
- }
- */
- void Core::openVCD(int title) {
- qDebug("Core::openVCD: %d", title);
- if (title == -1) title = pref->vcd_initial_title;
- if (proc->isRunning()) {
- stopMplayer();
- }
- // Save data of previous file:
- #ifndef NO_USE_INI_FILES
- saveMediaInfo();
- #endif
- mdat.reset();
- mdat.filename = "vcd://" + QString::number(title);
- mdat.type = TYPE_VCD;
- mset.reset();
- mset.current_title_id = title;
- mset.current_chapter_id = -1;
- mset.current_angle_id = -1;
- /* initializeMenus(); */
- initPlaying();
- }
- void Core::openAudioCD(int title) {
- qDebug("Core::openAudioCD: %d", title);
- if (title == -1) title = 1;
- if (proc->isRunning()) {
- stopMplayer();
- }
- // Save data of previous file:
- #ifndef NO_USE_INI_FILES
- saveMediaInfo();
- #endif
- mdat.reset();
- mdat.filename = "cdda://" + QString::number(title);
- mdat.type = TYPE_AUDIO_CD;
- mset.reset();
- mset.current_title_id = title;
- mset.current_chapter_id = -1;
- mset.current_angle_id = -1;
- /* initializeMenus(); */
- initPlaying();
- }
- void Core::openDVD(QString dvd_url) {
- qDebug("Core::openDVD: '%s'", dvd_url.toUtf8().data());
- //Checks
- DiscData disc_data = DiscName::split(dvd_url);
- QString folder = disc_data.device;
- int title = disc_data.title;
- if (title == -1) {
- qWarning("Core::openDVD: title invalid, not playing dvd");
- return;
- }
- if (folder.isEmpty()) {
- qDebug("Core::openDVD: not folder");
- } else {
- QFileInfo fi(folder);
- if ( (!fi.exists()) /*|| (!fi.isDir())*/ ) {
- qWarning("Core::openDVD: folder invalid, not playing dvd");
- return;
- }
- }
- if (proc->isRunning()) {
- stopMplayer();
- we_are_restarting = false;
- }
- // Save data of previous file:
- #ifndef NO_USE_INI_FILES
- saveMediaInfo();
- #endif
- mdat.reset();
- mdat.filename = dvd_url;
- mdat.type = TYPE_DVD;
- mset.reset();
- mset.current_title_id = title;
- mset.current_chapter_id = firstChapter();
- mset.current_angle_id = 1;
- /* initializeMenus(); */
- initPlaying();
- }
- void Core::openTV(QString channel_id) {
- qDebug("Core::openTV: '%s'", channel_id.toUtf8().constData());
- if (proc->isRunning()) {
- stopMplayer();
- we_are_restarting = false;
- }
- // Save data of previous file:
- #ifndef NO_USE_INI_FILES
- saveMediaInfo();
- #endif
- // Use last channel if the name is just "dvb://" or "tv://"
- if ((channel_id == "dvb://") && (!pref->last_dvb_channel.isEmpty())) {
- channel_id = pref->last_dvb_channel;
- }
- else
- if ((channel_id == "tv://") && (!pref->last_tv_channel.isEmpty())) {
- channel_id = pref->last_tv_channel;
- }
- // Save last channel
- if (channel_id.startsWith("dvb://")) pref->last_dvb_channel = channel_id;
- else
- if (channel_id.startsWith("tv://")) pref->last_tv_channel = channel_id;
- mdat.reset();
- mdat.filename = channel_id;
- mdat.type = TYPE_TV;
- mset.reset();
- // Set the default deinterlacer for TV
- mset.current_deinterlacer = pref->initial_tv_deinterlace;
- #ifndef NO_USE_INI_FILES
- if (!pref->dont_remember_media_settings) {
- // Check if we already have info about this file
- if (tv_settings->existSettingsFor(channel_id)) {
- qDebug("Core::openTV: we have settings for this file!!!");
- // In this case we read info from config
- tv_settings->loadSettingsFor(channel_id, mset);
- qDebug("Core::openTV: media settings read");
- }
- }
- #endif
- /* initializeMenus(); */
- initPlaying();
- }
- void Core::openStream(QString name) {
- qDebug("Core::openStream: '%s'", name.toUtf8().data());
- #ifdef YOUTUBE_SUPPORT
- if (name.contains("youtube.com/watch", Qt::CaseInsensitive) ||
- name.contains("youtu.be/", Qt::CaseInsensitive) ||
- name.contains("y2u.be/", Qt::CaseInsensitive) )
- {
- qDebug("Core::openStream: youtube url detected");
- if (name.startsWith("www.youtube.com")) name = "http://" + name;
- if (name.startsWith("youtube.com")) name = "http://www." + name;
- if (name.startsWith("youtu.be")) name = "http://" + name;
- if (name.startsWith("y2u.be")) name = "http://" + name;
- yt->setPreferredQuality( (RetrieveYoutubeUrl::Quality) pref->yt_quality );
- yt->fetchPage(name);
- return;
- }
- #endif
- if (proc->isRunning()) {
- stopMplayer();
- we_are_restarting = false;
- }
- // Save data of previous file:
- #ifndef NO_USE_INI_FILES
- saveMediaInfo();
- #endif
- mdat.reset();
- mdat.filename = name;
- mdat.type = TYPE_STREAM;
- mset.reset();
- /* initializeMenus(); */
- initPlaying();
- }
- void Core::playNewFile(QString file, int seek) {
- qDebug("Core::playNewFile: '%s'", file.toUtf8().data());
- if (proc->isRunning()) {
- stopMplayer();
- we_are_restarting = false;
- }
- // Save data of previous file:
- #ifndef NO_USE_INI_FILES
- saveMediaInfo();
- #endif
- mdat.reset();
- mdat.filename = file;
- mdat.type = TYPE_FILE;
- int old_volume = mset.volume;
- mset.reset();
- #ifndef NO_USE_INI_FILES
- // Check if we already have info about this file
- if (file_settings->existSettingsFor(file)) {
- qDebug("Core::playNewFile: We have settings for this file!!!");
- // In this case we read info from config
- if (!pref->dont_remember_media_settings) {
- file_settings->loadSettingsFor(file, mset);
- qDebug("Core::playNewFile: Media settings read");
- // Resize the window and set the aspect as soon as possible
- int saved_width = mset.win_width;
- int saved_height = mset.win_height;
- // 400x300 is the default size for win_width and win_height
- // so we set them to 0 to avoid to resize the window on
- // audio files
- if ((saved_width == 400) && (saved_height == 300)) {
- saved_width = 0;
- saved_height = 0;
- }
- if ((saved_width > 0) && (saved_height > 0)) {
- emit needResize(mset.win_width, mset.win_height);
- changeAspectRatio(mset.aspect_ratio_id);
- }
- if (pref->dont_remember_time_pos) {
- mset.current_sec = 0;
- qDebug("Core::playNewFile: Time pos reset to 0");
- }
- } else {
- qDebug("Core::playNewFile: Media settings have not read because of preferences setting");
- }
- } else {
- // Recover volume
- mset.volume = old_volume;
- }
- #else
- // Recover volume
- mset.volume = old_volume;
- #endif // NO_USE_INI_FILES
- /* initializeMenus(); */
- qDebug("Core::playNewFile: volume: %d, old_volume: %d", mset.volume, old_volume);
- initPlaying(seek);
- }
- void Core::restartPlay() {
- we_are_restarting = true;
- initPlaying();
- }
- void Core::initPlaying(int seek) {
- qDebug("Core::initPlaying");
- /*
- mdat.list();
- mset.list();
- */
- /* updateWidgets(); */
- mplayerwindow->hideLogo();
- if (proc->isRunning()) {
- stopMplayer();
- }
- int start_sec = (int) mset.current_sec;
- if (seek > -1) start_sec = seek;
- #ifdef YOUTUBE_SUPPORT
- // Avoid to pass to mplayer the youtube page url
- if (mdat.type == TYPE_STREAM) {
- if (mdat.filename == yt->origUrl()) {
- mdat.filename = yt->latestPreferredUrl();
- }
- }
- #endif
- startMplayer( mdat.filename, start_sec );
- }
- // This is reached when a new video has just started playing
- // and maybe we need to give some defaults
- void Core::newMediaPlaying() {
- qDebug("Core::newMediaPlaying: --- start ---");
- QString file = mdat.filename;
- int type = mdat.type;
- mdat = proc->mediaData();
- mdat.filename = file;
- mdat.type = type;
- initializeMenus(); // Old
- // Video
- if ( (mset.current_video_id == MediaSettings::NoneSelected) &&
- (mdat.videos.numItems() > 0) )
- {
- changeVideo( mdat.videos.itemAt(0).ID(), false ); // Don't allow to restart
- }
- #if !DELAYED_AUDIO_SETUP_ON_STARTUP && !NOTIFY_AUDIO_CHANGES
- // First audio if none selected
- if ( (mset.current_audio_id == MediaSettings::NoneSelected) &&
- (mdat.audios.numItems() > 0) )
- {
- // Don't set mset.current_audio_id here! changeAudio will do.
- // Otherwise changeAudio will do nothing.
- int audio = mdat.audios.itemAt(0).ID(); // First one
- if (mdat.audios.existsItemAt(pref->initial_audio_track-1)) {
- audio = mdat.audios.itemAt(pref->initial_audio_track-1).ID();
- }
- // Check if one of the audio tracks is the user preferred.
- if (!pref->audio_lang.isEmpty()) {
- int res = mdat.audios.findLang( pref->audio_lang );
- if (res != -1) audio = res;
- }
- // Change the audio without restarting mplayer, it's not
- // safe to do it here.
- changeAudio( audio, false );
- }
- #endif
- #if !NOTIFY_SUB_CHANGES
- // Subtitles
- if (mset.external_subtitles.isEmpty()) {
- if (pref->autoload_sub) {
- //Select first subtitle if none selected
- if (mset.current_sub_id == MediaSettings::NoneSelected) {
- int sub = mdat.subs.selectOne( pref->subtitle_lang, pref->initial_subtitle_track-1 );
- changeSubtitle( sub );
- }
- } else {
- changeSubtitle( MediaSettings::SubNone );
- }
- }
- #endif
- if (mdat.n_chapters > 0) {
- // Just to show the first chapter checked in the menu
- mset.current_chapter_id = firstChapter();
- }
- mdat.initialized = TRUE;
- // MPlayer doesn't display the length in ID_LENGTH for audio CDs...
- if ((mdat.duration == 0) && (mdat.type == TYPE_AUDIO_CD)) {
- /*
- qDebug(" *** get duration here from title info *** ");
- qDebug(" *** current title: %d", mset.current_title_id );
- */
- if (mset.current_title_id > 0) {
- mdat.duration = mdat.titles.item(mset.current_title_id).duration();
- }
- }
- /* updateWidgets(); */
- mdat.list();
- mset.list();
- qDebug("Core::newMediaPlaying: --- end ---");
- }
- void Core::finishRestart() {
- qDebug("Core::finishRestart: --- start ---");
- if (!we_are_restarting) {
- newMediaPlaying();
- //QTimer::singleShot(1000, this, SIGNAL(mediaStartPlay()));
- emit mediaStartPlay();
- }
- if (we_are_restarting) {
- // Update info about codecs and demuxer
- mdat.video_codec = proc->mediaData().video_codec;
- mdat.audio_codec = proc->mediaData().audio_codec;
- mdat.demuxer = proc->mediaData().demuxer;
- }
- #ifdef YOUTUBE_SUPPORT
- // Change the real url with the youtube page url and set the title
- if (mdat.type == TYPE_STREAM) {
- if (mdat.filename == yt->latestPreferredUrl()) {
- mdat.filename = yt->origUrl();
- mdat.stream_title = yt->urlTitle();
- }
- }
- #endif
- #if !NOTIFY_SUB_CHANGES
- // Subtitles
- //if (we_are_restarting) {
- if ( (just_loaded_external_subs) || (just_unloaded_external_subs) ) {
- qDebug("Core::finishRestart: processing new subtitles");
- // Just to simplify things
- if (mset.current_sub_id == MediaSettings::NoneSelected) {
- mset.current_sub_id = MediaSettings::SubNone;
- }
- // Save current sub
- SubData::Type type;
- int ID;
- int old_item = -1;
- if ( mset.current_sub_id != MediaSettings::SubNone ) {
- old_item = mset.current_sub_id;
- type = mdat.subs.itemAt(old_item).type();
- ID = mdat.subs.itemAt(old_item).ID();
- }
- // Use the subtitle info from mplayerprocess
- qDebug( "Core::finishRestart: copying sub data from proc to mdat");
- mdat.subs = proc->mediaData().subs;
- initializeMenus();
- int item = MediaSettings::SubNone;
- // Try to recover old subtitle
- if (just_unloaded_external_subs) {
- if (old_item > -1) {
- int new_item = mdat.subs.find(type, ID);
- if (new_item > -1) item = new_item;
- }
- }
- // If we've just loaded a subtitle file
- // select one if the user wants to autoload
- // one subtitle
- if (just_loaded_external_subs) {
- if ( (pref->autoload_sub) && (item == MediaSettings::SubNone) ) {
- qDebug("Core::finishRestart: cannot find previous subtitle");
- qDebug("Core::finishRestart: selecting a new one");
- item = mdat.subs.selectOne( pref->subtitle_lang );
- }
- }
- changeSubtitle( item );
- just_loaded_external_subs = false;
- just_unloaded_external_subs = false;
- } else {
- // Normal restart, subtitles haven't changed
- // Recover current subtitle
- changeSubtitle( mset.current_sub_id );
- }
- #endif
- we_are_restarting = false;
- changeAspectRatio(mset.aspect_ratio_id);
- if (pref->global_volume) {
- bool was_muted = pref->mute;
- setVolume( pref->volume, true);
- if (was_muted) mute(true);
- } else {
- bool was_muted = mset.mute;
- setVolume( mset.volume, true );
- if (was_muted) mute(true);
- }
- if (pref->change_video_equalizer_on_startup && (mset.gamma != 0)) {
- int gamma = mset.gamma;
- mset.gamma = -1000; // if mset.gamma == new value, mset.gamma is not changed!
- setGamma( gamma );
- }
- // Hack to be sure that the equalizers are up to date
- emit videoEqualizerNeedsUpdate();
- emit audioEqualizerNeedsUpdate();
- changeZoom(mset.zoom_factor);
- // Toggle subtitle visibility
- changeSubVisibility(pref->sub_visibility);
- // A-B marker
- emit ABMarkersChanged(mset.A_marker, mset.B_marker);
- // Initialize the OSD level
- QTimer::singleShot(pref->osd_delay, this, SLOT(initializeOSD()));
- emit mediaLoaded();
- emit mediaInfoChanged();
- updateWidgets(); // New
- qDebug("Core::finishRestart: --- end ---");
- }
- void Core::initializeOSD() {
- changeOSD(pref->osd);
- }
- void Core::stop()
- {
- qDebug("Core::stop");
- qDebug("Core::stop: state: %s", stateToString().toUtf8().data());
-
- if (state()==Stopped) {
- // if pressed stop twice, reset video to the beginning
- qDebug("Core::stop: mset.current_sec: %f", mset.current_sec);
- mset.current_sec = 0;
- qDebug("Core::stop: mset.current_sec set to 0");
- emit showTime( mset.current_sec );
- #ifdef SEEKBAR_RESOLUTION
- emit positionChanged( 0 );
- #else
- emit posChanged( 0 );
- #endif
- //updateWidgets();
- }
- stopMplayer();
- emit mediaStoppedByUser();
- }
- void Core::play()
- {
- qDebug("Core::play");
-
- if ((proc->isRunning()) && (state()==Paused)) {
- tellmp("pause"); // Unpauses
- }
- else
- if ((proc->isRunning()) && (state()==Playing)) {
- // nothing to do, continue playing
- }
- else {
- // if we're stopped, play it again
- if ( !mdat.filename.isEmpty() ) {
- /*
- qDebug( "current_sec: %f, duration: %f", mset.current_sec, mdat.duration);
- if ( (floor(mset.current_sec)) >= (floor(mdat.duration)) ) {
- mset.current_sec = 0;
- }
- */
- restartPlay();
- }
- }
- }
- void Core::pause_and_frame_step() {
- qDebug("Core::pause_and_frame_step");
-
- if (proc->isRunning()) {
- if (state() == Paused) {
- tellmp("frame_step");
- }
- else {
- tellmp("pause");
- }
- }
- }
- void Core::pause() {
- qDebug("Core::pause");
- qDebug("Core::pause: current state: %s", stateToString().toUtf8().data());
- if (proc->isRunning()) {
- // Pauses and unpauses
- tellmp("pause");
- }
- }
- void Core::play_or_pause() {
- if (proc->isRunning()) {
- pause();
- } else {
- play();
- }
- }
- void Core::frameStep() {
- qDebug("Core::frameStep");
- if (proc->isRunning()) {
- tellmp("frame_step");
- }
- }
- void Core::screenshot() {
- qDebug("Core::screenshot");
- if ( (!pref->screenshot_directory.isEmpty()) &&
- (QFileInfo(pref->screenshot_directory).isDir()) )
- {
- tellmp( pausing_prefix() + " screenshot 0");
- qDebug("Core::screenshot: taken screenshot");
- } else {
- qDebug("Core::screenshot: error: directory for screenshots not valid");
- emit showMessage( tr("Screenshot NOT taken, folder not configured") );
- }
- }
- void Core::screenshots() {
- qDebug("Core::screenshots");
- if ( (!pref->screenshot_directory.isEmpty()) &&
- (QFileInfo(pref->screenshot_directory).isDir()) )
- {
- tellmp( "screenshot 1");
- } else {
- qDebug("Core::screenshots: error: directory for screenshots not valid");
- emit showMessage( tr("Screenshots NOT taken, folder not configured") );
- }
- }
- void Core::processFinished()
- {
- qDebug("Core::processFinished");
- #if defined(Q_OS_WIN) || defined(Q_OS_OS2)
- #ifdef SCREENSAVER_OFF
- // Restores the Windows or OS2 screensaver
- if (pref->turn_screensaver_off) {
- win_screensaver->enable();
- }
- #endif
- #endif
- qDebug("Core::processFinished: we_are_restarting: %d", we_are_restarting);
- //mset.current_sec = 0;
- if (!we_are_restarting) {
- qDebug("Core::processFinished: play has finished!");
- setState(Stopped);
- //emit stateChanged(state());
- }
- int exit_code = proc->exitCode();
- qDebug("Core::processFinished: exit_code: %d", exit_code);
- if (exit_code != 0) {
- emit mplayerFinishedWithError(exit_code);
- }
- }
- void Core::fileReachedEnd() {
- /*
- if (mdat.type == TYPE_VCD) {
- // If the first vcd title has nothing, it doesn't start to play
- // and menus are not initialized.
- initializeMenus();
- }
- */
- // If we're at the end of the movie, reset to 0
- mset.current_sec = 0;
- updateWidgets();
- emit mediaFinished();
- }
- #if SEEKBAR_RESOLUTION
- void Core::goToPosition(int value) {
- qDebug("Core::goToPosition: value: %d", value);
- if (pref->relative_seeking) {
- goToPos( (double) value / (SEEKBAR_RESOLUTION / 100) );
- }
- else {
- if (mdat.duration > 0) {
- int jump_time = (int) mdat.duration * value / SEEKBAR_RESOLUTION;
- goToSec(jump_time);
- }
- }
- }
- void Core::goToPos(double perc) {
- qDebug("Core::goToPos: per: %f", perc);
- tellmp( seek_cmd(perc, 1) );
- }
- #else
- void Core::goToPos(int perc) {
- qDebug("Core::goToPos: per: %d", perc);
- tellmp( seek_cmd(perc, 1) );
- }
- #endif
- void Core::startMplayer( QString file, double seek ) {
- qDebug("Core::startMplayer");
- if (file.isEmpty()) {
- qWarning("Core:startMplayer: file is empty!");
- return;
- }
- if (proc->isRunning()) {
- qWarning("Core::startMplayer: MPlayer still running!");
- return;
- }
- #ifdef YOUTUBE_SUPPORT
- // Stop any pending request
- qDebug("Core::startMplayer: yt state: %d", yt->state());
- if (yt->state() != QHttp::Unconnected) {
- //yt->abort(); /* Make the app to crash, don't know why */
- }
- #endif
- #if defined(Q_OS_WIN) || defined(Q_OS_OS2)
- #ifdef SCREENSAVER_OFF
- // Disable the Windows or OS2 screensaver
- if (pref->turn_screensaver_off) {
- win_screensaver->disable();
- }
- #endif
- #endif
- bool is_mkv = (QFileInfo(file).suffix().toLower() == "mkv");
- // DVD
- QString dvd_folder;
- int dvd_title = -1;
- if (mdat.type==TYPE_DVD) {
- DiscData disc_data = DiscName::split(file);
- dvd_folder = disc_data.device;
- if (dvd_folder.isEmpty()) dvd_folder = pref->dvd_device;
- dvd_title = disc_data.title;
- file = disc_data.protocol + "://";
- if (dvd_title > 0) file += QString::number(dvd_title);
- }
- // Check URL playlist
- bool url_is_playlist = false;
- if (file.endsWith("|playlist")) {
- url_is_playlist = true;
- file = file.remove("|playlist");
- } else {
- QUrl url(file);
- qDebug("Core::startMplayer: checking if stream is a playlist");
- qDebug("Core::startMplayer: url path: '%s'", url.path().toUtf8().constData());
- QRegExp rx("\\.ram$|\\.asx$|\\.m3u$|\\.pls$", Qt::CaseInsensitive);
- url_is_playlist = (rx.indexIn(url.path()) != -1);
- }
- qDebug("Core::startMplayer: url_is_playlist: %d", url_is_playlist);
- bool screenshot_enabled = ( (pref->use_screenshot) &&
- (!pref->screenshot_directory.isEmpty()) &&
- (QFileInfo(pref->screenshot_directory).isDir()) );
- proc->clearArguments();
- // Set working directory to screenshot directory
- if (screenshot_enabled) {
- qDebug("Core::startMplayer: setting working directory to '%s'", pref->screenshot_directory.toUtf8().data());
- proc->setWorkingDirectory( pref->screenshot_directory );
- }
- // Use absolute path, otherwise after changing to the screenshot directory
- // the mplayer path might not be found if it's a relative path
- // (seems to be necessary only for linux)
- QString mplayer_bin = pref->mplayer_bin;
- QFileInfo fi(mplayer_bin);
- if (fi.exists() && fi.isExecutable() && !fi.isDir()) {
- mplayer_bin = fi.absoluteFilePath();
- }
- proc->addArgument( mplayer_bin );
- proc->addArgument("-noquiet");
- #ifdef LOG_MPLAYER
- if (pref->verbose_log) {
- proc->addArgument("-v");
- }
- #endif
- if (pref->fullscreen && pref->use_mplayer_window) {
- proc->addArgument("-fs");
- } else {
- // No mplayer fullscreen mode
- #if !USE_MPLAYER_PANSCAN
- proc->addArgument("-nofs");
- #else
- // The command 'panscan' requires -fs
- proc->addArgument("-fs");
- #endif
- }
- proc->addArgument("-nomouseinput");
- // Demuxer and audio and video codecs:
- if (!mset.forced_demuxer.isEmpty()) {
- proc->addArgument("-demuxer");
- proc->addArgument(mset.forced_demuxer);
- }
- if (!mset.forced_audio_codec.isEmpty()) {
- proc->addArgument("-ac");
- proc->addArgument(mset.forced_audio_codec);
- }
- if (!mset.forced_video_codec.isEmpty()) {
- proc->addArgument("-vc");
- proc->addArgument(mset.forced_video_codec);
- }
- #ifndef Q_OS_WIN
- else {
- /* if (pref->vo.startsWith("x11")) { */ // My card doesn't support vdpau, I use x11 to test
- if (pref->vo.startsWith("vdpau")) {
- QString c;
- if (pref->vdpau.ffh264vdpau) c += "ffh264vdpau,";
- if (pref->vdpau.ffmpeg12vdpau) c += "ffmpeg12vdpau,";
- if (pref->vdpau.ffwmv3vdpau) c += "ffwmv3vdpau,";
- if (pref->vdpau.ffvc1vdpau) c += "ffvc1vdpau,";
- if (pref->vdpau.ffodivxvdpau) c += "ffodivxvdpau,";
- if (!c.isEmpty()) {
- proc->addArgument("-vc");
- proc->addArgument(c);
- }
- }
- #endif
- else {
- if (pref->coreavc) {
- proc->addArgument("-vc");
- proc->addArgument("coreserve,");
- }
- }
- #ifndef Q_OS_WIN
- }
- #endif
- if (pref->use_hwac3) {
- proc->addArgument("-afm");
- proc->addArgument("hwac3");
- }
- QString lavdopts;
- if ( (pref->h264_skip_loop_filter == Preferences::LoopDisabled) ||
- ((pref->h264_skip_loop_filter == Preferences::LoopDisabledOnHD) &&
- (mset.is264andHD)) )
- {
- if (!lavdopts.isEmpty()) lavdopts += ":";
- lavdopts += "skiploopfilter=all";
- }
- if (pref->threads > 1) {
- if (!lavdopts.isEmpty()) lavdopts += ":";
- lavdopts += "threads=" + QString::number(pref->threads);
- }
- if (!lavdopts.isEmpty()) {
- proc->addArgument("-lavdopts");
- proc->addArgument(lavdopts);
- }
- proc->addArgument("-sub-fuzziness");
- proc->addArgument( QString::number(pref->subfuzziness) );
- proc->addArgument("-identify");
- if (MplayerVersion::isMplayerAtLeast(27667)) {
- // From r27667 the number of chapters can be obtained from ID_CHAPTERS
- mset.current_chapter_id = 0; // Reset chapters
- } else {
- // We need this to get info about mkv chapters
- if (is_mkv) {
- proc->addArgument("-msglevel");
- proc->addArgument("demux=6");
- // **** Reset chapter ***
- // Select first chapter, otherwise we cannot
- // resume playback at the same point
- // (time would be relative to chapter)
- mset.current_chapter_id = 0;
- }
- }
- proc->addArgument("-slave");
- if (!pref->vo.isEmpty()) {
- proc->addArgument( "-vo");
- proc->addArgument( pref->vo );
- } else {
- proc->addArgument("-vo");
- #ifdef Q_OS_WIN
- if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA) {
- proc->addArgument("direct3d,");
- } else {
- proc->addArgument("directx,");
- }
- #else
- proc->addArgument("xv,");
- #endif
- }
- #if USE_ADAPTER
- if (pref->adapter > -1) {
- proc->addArgument("-adapter");
- proc->addArgument(QString::number(pref->adapter));
- }
- #endif
- if (!pref->ao.isEmpty()) {
- proc->addArgument( "-ao");
- proc->addArgument( pref->ao );
- }
- #if !defined(Q_OS_WIN) && !defined(Q_OS_OS2)
- if (pref->vo.startsWith("x11")) {
- proc->addArgument( "-zoom");
- }
- #endif
- proc->addArgument("-nokeepaspect");
- // Performance options
- #ifdef Q_OS_WIN
- QString p;
- int app_p = NORMAL_PRIORITY_CLASS;
- switch (pref->priority) {
- case Preferences::Realtime: p = "realtime";
- app_p = REALTIME_PRIORITY_CLASS;
- break;
- case Preferences::High: p = "high";
- app_p = REALTIME_PRIORITY_CLASS;
- break;
- case Preferences::AboveNormal: p = "abovenormal";
- app_p = HIGH_PRIORITY_CLASS;
- break;
- case Preferences::Normal: p = "normal";
- app_p = ABOVE_NORMAL_PRIORITY_CLASS;
- break;
- case Preferences::BelowNormal: p = "belownormal"; break;
- case Preferences::Idle: p = "idle"; break;
- default: p = "normal";
- }
- proc->addArgument("-priority");
- proc->addArgument( p );
- SetPriorityClass(GetCurrentProcess(), app_p);
- qDebug("Core::startMplayer: priority of smplayer process set to %d", app_p);
- #endif
- if (pref->frame_drop) {
- proc->addArgument("-framedrop");
- }
- if (pref->hard_frame_drop) {
- proc->addArgument("-hardframedrop");
- }
- if (pref->autosync) {
- proc->addArgument("-autosync");
- proc->addArgument( QString::number( pref->autosync_factor ) );
- }
- if (pref->use_mc) {
- proc->addArgument("-mc");
- proc->addArgument( QString::number( pref->mc_value ) );
- }
- if (pref->use_direct_rendering) {
- proc->addArgument("-dr");
- } else {
- proc->addArgument("-nodr");
- }
- if (pref->use_double_buffer) {
- proc->addArgument("-double");
- } else {
- proc->addArgument("-nodouble");
- }
- #if !defined(Q_OS_WIN) && !defined(Q_OS_OS2)
- if (!pref->use_mplayer_window) {
- proc->addArgument( "-input" );
- if (MplayerVersion::isMplayerAtLeast(29058)) {
- proc->addArgument( "nodefault-bindings:conf=/dev/null" );
- } else {
- proc->addArgument( "conf=" + Paths::dataPath() +"/input.conf" );
- }
- }
- #endif
- #ifdef Q_WS_X11
- if (pref->disable_screensaver) {
- proc->addArgument("-stop-xscreensaver");
- } else {
- proc->addArgument("-nostop-xscreensaver");
- }
- #endif
- if (!pref->use_mplayer_window) {
- proc->addArgument("-wid");
- #if defined(Q_OS_OS2)
- #define WINIDFROMHWND(hwnd) ( ( hwnd ) - 0x80000000UL )
- proc->addArgument( QString::number( WINIDFROMHWND( (int) mplayerwindow->videoLayer()->winId() ) ));
- #else
- proc->addArgument( QString::number( (qint64) mplayerwindow->videoLayer()->winId() ) );
- #endif
- #if USE_COLORKEY
- #if defined(Q_OS_WIN) || defined(Q_OS_OS2)
- if ((pref->vo.startsWith("directx")) || (pref->vo.startsWith("kva")) || (pref->vo.isEmpty())) {
- proc->addArgument("-colorkey");
- //proc->addArgument( "0x"+QString::number(pref->color_key, 16) );
- proc->addArgument( ColorUtils::colorToRGB(pref->color_key) );
- } else {
- #endif
- qDebug("Core::startMplayer: * not using -colorkey for %s", pref->vo.toUtf8().data());
- qDebug("Core::startMplayer: * report if you can't see the video");
- #if defined(Q_OS_WIN) || defined(Q_OS_OS2)
- }
- #endif
- #endif
- // Square pixels
- proc->addArgument("-monitorpixelaspect");
- proc->addArgument("1");
- } else {
- // no -wid
- if (!pref->monitor_aspect.isEmpty()) {
- proc->addArgument("-monitoraspect");
- proc->addArgument( pref->monitor_aspect );
- }
- }
- // Subtitles fonts
- if ((pref->use_ass_subtitles) && (pref->freetype_support)) {
- // ASS:
- proc->addArgument("-ass");
- proc->addArgument("-embeddedfonts");
- proc->addArgument("-ass-line-spacing");
- proc->addArgument(QString::number(pref->ass_line_spacing));
- proc->addArgument( "-ass-font-scale");
- proc->addArgument( QString::number(mset.sub_scale_ass) );
- if (!pref->force_ass_styles) {
- // Load the styles.ass file
- if (!QFile::exists(Paths::subtitleStyleFile())) {
- // If file doesn't exist, create it
- pref->ass_styles.exportStyles(Paths::subtitleStyleFile());
- }
- if (QFile::exists(Paths::subtitleStyleFile())) {
- proc->addArgument("-ass-styles");
- proc->addArgument( Paths::subtitleStyleFile() );
- } else {
- qWarning("Core::startMplayer: '%s' doesn't exist", Paths::subtitleStyleFile().toUtf8().constData());
- }
- } else {
- // Force styles for ass subtitles too
- proc->addArgument("-ass-force-style");
- if (!pref->user_forced_ass_style.isEmpty()) {
- proc->addArgument(pref->user_forced_ass_style);
- } else {
- proc->addArgument(pref->ass_styles.toString());
- }
- }
- // Use the same font for OSD
- #if !defined(Q_OS_OS2)
- if (!pref->ass_styles.fontname.isEmpty()) {
- proc->addArgument("-fontconfig");
- proc->addArgument("-font");
- proc->addArgument( pref->ass_styles.fontname );
- }
- #endif
- // Set the size of OSD
- if (pref->freetype_support) {
- proc->addArgument("-subfont-autoscale");
- proc->addArgument("0");
- proc->addArgument("-subfont-osd-scale");
- proc->addArgument(QString::number(pref->ass_styles.fontsize));
- proc->addArgument("-subfont-text-scale"); // Old versions (like 1.0rc2) need this
- proc->addArgument(QString::number(pref->ass_styles.fontsize));
- }
- } else {
- // NO ASS:
- if (pref->freetype_support) proc->addArgument("-noass");
- #if !defined(Q_OS_OS2)
- if ( (pref->use_fontconfig) && (!pref->font_name.isEmpty()) ) {
- proc->addArgument("-fontconfig");
- proc->addArgument("-font");
- proc->addArgument( pref->font_name );
- }
- #endif
- if ( (!pref->use_fontconfig) && (!pref->font_file.isEmpty()) ) {
- proc->addArgument("-font");
- proc->addArgument( pref->font_file );
- }
- if (pref->freetype_support) {
- proc->addArgument( "-subfont-autoscale");
- proc->addArgument( QString::number( pref->font_autoscale ) );
- proc->addArgument( "-subfont-text-scale");
- proc->addArgument( QString::number(mset.sub_scale) );
- }
- }
- // Subtitle encoding
- {
- QString encoding;
- if ( (pref->use_enca) && (!pref->enca_lang.isEmpty()) ) {
- encoding = "enca:"+ pref->enca_lang;
- if (!pref->subcp.isEmpty()) {
- encoding += ":"+ pref->subcp;
- }
- }
- else
- if (!pref->subcp.isEmpty()) {
- encoding = pref->subcp;
- }
- if (!encoding.isEmpty()) {
- proc->addArgument("-subcp");
- proc->addArgument( encoding );
- }
- }
- if (mset.closed_caption_channel > 0) {
- proc->addArgument("-subcc");
- if (MplayerVersion::isMplayerAtLeast(32607)) {
- proc->addArgument( QString::number( mset.closed_caption_channel ) );
- }
- }
- if (pref->use_forced_subs_only) {
- proc->addArgument("-forcedsubsonly");
- }
- #if PROGRAM_SWITCH
- if ( (mset.current_program_id != MediaSettings::NoneSelected) /*&&
- (mset.current_video_id == MediaSettings::NoneSelected) &&
- (mset.current_audio_id == MediaSettings::NoneSelected)*/ )
- {
- proc->addArgument("-tsprog");
- proc->addArgument( QString::number( mset.current_program_id ) );
- }
- // Don't set video and audio track if using -tsprog
- else {
- #endif
- if (mset.current_video_id != MediaSettings::NoneSelected) {
- proc->addArgument("-vid");
- proc->addArgument( QString::number( mset.current_video_id ) );
- }
- if (mset.current_audio_id != MediaSettings::NoneSelected) {
- // Workaround for MPlayer bug #1321 (http://bugzilla.mplayerhq.hu/show_bug.cgi?id=1321)
- if (mdat.audios.numItems() != 1) {
- proc->addArgument("-aid");
- proc->addArgument( QString::number( mset.current_audio_id ) );
- }
- }
- #if PROGRAM_SWITCH
- }
- #endif
- if (!initial_subtitle.isEmpty()) {
- mset.external_subtitles = initial_subtitle;
- initial_subtitle = "";
- just_loaded_external_subs = true; // Big ugly hack :(
- }
- if (!mset.external_subtitles.isEmpty()) {
- if (QFileInfo(mset.external_subtitles).suffix().toLower()=="idx") {
- // sub/idx subtitles
- QFileInfo fi;
- #ifdef Q_OS_WIN
- if (pref->use_short_pathnames)
- fi.setFile(Helper::shortPathName(mset.external_subtitles));
- else
- #endif
- fi.setFile(mset.external_subtitles);
- QString s = fi.path() +"/"+ fi.completeBaseName();
- qDebug("Core::startMplayer: subtitle file without extension: '%s'", s.toUtf8().data());
- proc->addArgument("-vobsub");
- proc->addArgument( s );
- } else {
- proc->addArgument("-sub");
- #ifdef Q_OS_WIN
- if (pref->use_short_pathnames)
- proc->addArgument(Helper::shortPathName(mset.external_subtitles));
- else
- #endif
- proc->addArgument( mset.external_subtitles );
- }
- }
- if (!mset.external_audio.isEmpty()) {
- proc->addArgument("-audiofile");
- #ifdef Q_OS_WIN
- if (pref->use_short_pathnames)
- proc->addArgument(Helper::shortPathName(mset.external_audio));
- else
- #endif
- proc->addArgument( mset.external_audio );
- }
- proc->addArgument("-subpos");
- proc->addArgument( QString::number(mset.sub_pos) );
- if (mset.audio_delay!=0) {
- proc->addArgument("-delay");
- proc->addArgument( QString::number( (double) mset.audio_delay/1000 ) );
- }
- if (mset.sub_delay!=0) {
- proc->addArgument("-subdelay");
- proc->addArgument( QString::number( (double) mset.sub_delay/1000 ) );
- }
- // Contrast, brightness...
- if (pref->change_video_equalizer_on_startup) {
- if (mset.contrast != 0) {
- proc->addArgument("-contrast");
- proc->addArgument( QString::number( mset.contrast ) );
- }
-
- if (mset.brightness != 0) {
- proc->addArgument("-brightness");
- proc->addArgument( QString::number( mset.brightness ) );
- }
- if (mset.hue != 0) {
- proc->addArgument("-hue");
- proc->addArgument( QString::number( mset.hue ) );
- }
- if (mset.saturation != 0) {
- proc->addArgument("-saturation");
- proc->addArgument( QString::number( mset.saturation ) );
- }
- }
- // Set volume, requires mplayer svn r27872
- bool use_volume_option = (MplayerVersion::isMplayerAtLeast(27872));
- if (pref->global_volume) {
- if (use_volume_option) {
- proc->addArgument("-volume");
- proc->addArgument( QString::number( pref->volume ) );
- }
- } else {
- if (use_volume_option) {
- proc->addArgument("-volume");
- // Note: mset.volume may not be right, it can be the volume of the previous video if
- // playing a new one, but I think it's better to use anyway the current volume on
- // startup than set it to 0 or something.
- // The right volume will be set later, when the video starts to play.
- proc->addArgument( QString::number( mset.volume ) );
- }
- }
- if (mdat.type==TYPE_DVD) {
- if (!dvd_folder.isEmpty()) {
- proc->addArgument("-dvd-device");
- proc->addArgument( dvd_folder );
- } else {
- qWarning("Core::startMplayer: dvd device is empty!");
- }
- }
- if ((mdat.type==TYPE_VCD) || (mdat.type==TYPE_AUDIO_CD)) {
- if (!pref->cdrom_device.isEmpty()) {
- proc->addArgument("-cdrom-device");
- proc->addArgument( pref->cdrom_device );
- }
- }
- if (mset.current_chapter_id > 0) {
- proc->addArgument("-chapter");
- int chapter = mset.current_chapter_id;
- // Fix for older versions of mplayer:
- if ((mdat.type == TYPE_DVD) && (firstChapter() == 0)) chapter++;
- proc->addArgument( QString::number( chapter ) );
- }
- if (mset.current_angle_id > 0) {
- proc->addArgument("-dvdangle");
- proc->addArgument( QString::number( mset.current_angle_id ) );
- }
- int cache = 0;
- switch (mdat.type) {
- case TYPE_FILE : cache = pref->cache_for_files; break;
- case TYPE_DVD : cache = pref->cache_for_dvds;
- #if DVDNAV_SUPPORT
- if (file.startsWith("dvdnav:")) cache = 0;…
Large files files are truncated, but you can click here to view the full file