65
67
just_unloaded_external_subs = false;
66
68
change_volume_after_unpause = false;
71
dvdnav_title_is_menu = true; // Enabled by default for compatibility with previous versions of mplayer
68
74
#ifndef NO_USE_INI_FILES
69
75
// Create file_settings
70
#if NEW_SETTINGS_MANAGEMENT
72
77
changeFileSettingsMethod(pref->file_settings_method);
74
if (Paths::iniPath().isEmpty()) {
75
file_settings = new QSettings(QSettings::IniFormat, QSettings::UserScope,
76
QString(COMPANY), QString("smplayer_files") );
78
QString filename = Paths::iniPath() + "/smplayer_files.ini";
79
file_settings = new QSettings( filename, QSettings::IniFormat );
80
qDebug("Core::Core: file_settings: '%s'", filename.toUtf8().data());
80
tv_settings = new TVSettings(Paths::iniPath());
85
83
proc = new MplayerProcess(this);
91
89
connect( proc, SIGNAL(error(QProcess::ProcessError)),
92
90
mplayerwindow->videoLayer(), SLOT(playingStopped()) );
92
// Necessary to hide/unhide mouse cursor on black borders
93
connect( proc, SIGNAL(processExited()),
94
mplayerwindow, SLOT(playingStopped()) );
96
connect( proc, SIGNAL(error(QProcess::ProcessError)),
97
mplayerwindow, SLOT(playingStopped()) );
94
100
connect( proc, SIGNAL(receivedCurrentSec(double)),
95
101
this, SLOT(changeCurrentSec(double)) );
284
299
#ifndef NO_USE_INI_FILES
285
#if !NEW_SETTINGS_MANAGEMENT
287
bool Core::checkHaveSettingsSaved(QString group_name) {
288
qDebug("Core::checkHaveSettingsSaved: group_name: '%s'", group_name.toUtf8().data());
290
file_settings->beginGroup( group_name );
291
bool saved = file_settings->value( "saved", false ).toBool();
292
file_settings->endGroup();
297
void Core::loadMediaInfo(QString group_name) {
298
qDebug("Core::loadMediaInfo: '%s'", group_name.toUtf8().data() );
300
file_settings->beginGroup( group_name );
302
/*mdat.load(*settings);*/
303
mset.load(file_settings);
305
file_settings->endGroup();
308
#endif // NEW_SETTINGS_MANAGEMENT
310
300
void Core::saveMediaInfo() {
311
301
qDebug("Core::saveMediaInfo");
318
#if NEW_SETTINGS_MANAGEMENT
319
308
if ( (mdat.type == TYPE_FILE) && (!mdat.filename.isEmpty()) ) {
320
309
file_settings->saveSettingsFor(mdat.filename, mset);
326
if ( (mdat.type == TYPE_DVD) && (!mdat.dvd_id.isEmpty()) ) {
327
group_name = dvdForPref( mdat.dvd_id, mset.current_title_id );
331
if ( (mdat.type == TYPE_FILE) && (!mdat.filename.isEmpty()) ) {
332
group_name = FileSettings::filenameToGroupname( mdat.filename );
335
if (!group_name.isEmpty()) {
336
file_settings->beginGroup( group_name );
337
file_settings->setValue( "saved", true);
339
/*mdat.save(*settings);*/
340
mset.save(file_settings);
342
file_settings->endGroup();
344
#endif // NEW_SETTINGS_MANAGEMENT
312
if ( (mdat.type == TYPE_TV) && (!mdat.filename.isEmpty()) ) {
313
tv_settings->saveSettingsFor(mdat.filename, mset);
347
316
#endif // NO_USE_INI_FILES
349
318
void Core::initializeMenus() {
666
void Core::openTV(QString channel_id) {
667
qDebug("Core::openTV: '%s'", channel_id.toUtf8().constData());
669
if (proc->isRunning()) {
671
we_are_restarting = false;
674
// Save data of previous file:
675
#ifndef NO_USE_INI_FILES
679
// Use last channel if the name is just "dvb://" or "tv://"
680
if ((channel_id == "dvb://") && (!pref->last_dvb_channel.isEmpty())) {
681
channel_id = pref->last_dvb_channel;
684
if ((channel_id == "tv://") && (!pref->last_tv_channel.isEmpty())) {
685
channel_id = pref->last_tv_channel;
689
if (channel_id.startsWith("dvb://")) pref->last_dvb_channel = channel_id;
691
if (channel_id.startsWith("tv://")) pref->last_tv_channel = channel_id;
694
mdat.filename = channel_id;
699
// Set the default deinterlacer for TV
700
mset.current_deinterlacer = pref->initial_tv_deinterlace;
702
#ifndef NO_USE_INI_FILES
703
if (!pref->dont_remember_media_settings) {
704
// Check if we already have info about this file
705
if (tv_settings->existSettingsFor(channel_id)) {
706
qDebug("Core::openTV: we have settings for this file!!!");
708
// In this case we read info from config
709
tv_settings->loadSettingsFor(channel_id, mset);
710
qDebug("Core::openTV: media settings read");
715
/* initializeMenus(); */
692
720
void Core::openStream(QString name) {
693
721
qDebug("Core::openStream: '%s'", name.toUtf8().data());
737
765
#ifndef NO_USE_INI_FILES
738
766
// Check if we already have info about this file
739
#if NEW_SETTINGS_MANAGEMENT
740
767
if (file_settings->existSettingsFor(file)) {
742
if (checkHaveSettingsSaved( FileSettings::filenameToGroupname(file) )) {
744
768
qDebug("Core::playNewFile: We have settings for this file!!!");
746
770
// In this case we read info from config
747
771
if (!pref->dont_remember_media_settings) {
748
#if NEW_SETTINGS_MANAGEMENT
749
772
file_settings->loadSettingsFor(file, mset);
751
loadMediaInfo( FileSettings::filenameToGroupname(file) );
753
773
qDebug("Core::playNewFile: Media settings read");
755
775
// Resize the window and set the aspect as soon as possible
983
1003
we_are_restarting = false;
986
1005
changeAspectRatio(mset.aspect_ratio_id);
988
if (mset.aspect_ratio_id < MediaSettings::Aspect43Letterbox) {
989
changeAspectRatio(mset.aspect_ratio_id);
993
bool isMuted = mset.mute;
994
if (!pref->dont_change_volume) {
995
setVolume( mset.volume, TRUE );
1007
if (pref->global_volume) {
1008
bool was_muted = pref->mute;
1009
setVolume( pref->volume, true);
1010
if (was_muted) mute(true);
1012
bool was_muted = mset.mute;
1013
setVolume( mset.volume, true );
1014
if (was_muted) mute(true);
997
if (isMuted) mute(TRUE);
999
1017
if (pref->change_video_equalizer_on_startup && (mset.gamma != 0)) {
1000
1018
int gamma = mset.gamma;
1659
1748
// Set volume, requires mplayer svn r27872
1660
bool use_volume_option = (pref->use_volume_option == Preferences::Enabled);
1661
if (pref->use_volume_option == Preferences::Detect) {
1662
use_volume_option = (MplayerVersion::isMplayerAtLeast(27872));
1664
if ((use_volume_option) && (!pref->dont_change_volume)) {
1665
proc->addArgument("-volume");
1666
// Note: mset.volume may not be right, it can be the volume of the previous video if
1667
// playing a new one, but I think it's better to use anyway the current volume on
1668
// startup than set it to 0 or something.
1669
// The right volume will be set later, when the video starts to play.
1670
proc->addArgument( QString::number( mset.volume ) );
1749
bool use_volume_option = (MplayerVersion::isMplayerAtLeast(27872));
1751
if (pref->global_volume) {
1752
if (use_volume_option) {
1753
proc->addArgument("-volume");
1754
proc->addArgument( QString::number( pref->volume ) );
1757
if (use_volume_option) {
1758
proc->addArgument("-volume");
1759
// Note: mset.volume may not be right, it can be the volume of the previous video if
1760
// playing a new one, but I think it's better to use anyway the current volume on
1761
// startup than set it to 0 or something.
1762
// The right volume will be set later, when the video starts to play.
1763
proc->addArgument( QString::number( mset.volume ) );
1731
1826
proc->addArgument( QString::number( mset.speed ) );
1734
// If seek < 5 it's better to allow the video to start from the beginning
1735
if ((seek >= 5) && (!pref->loop)) {
1736
proc->addArgument("-ss");
1737
proc->addArgument( QString::number( seek ) );
1829
if (mdat.type != TYPE_TV) {
1830
// If seek < 5 it's better to allow the video to start from the beginning
1831
if ((seek >= 5) && (!pref->loop)) {
1832
proc->addArgument("-ss");
1833
proc->addArgument( QString::number( seek ) );
1837
// Enable the OSD later, to avoid a lot of messages to be
1838
// printed on startup
1740
1839
proc->addArgument("-osdlevel");
1741
proc->addArgument( QString::number( pref->osd ) );
1840
proc->addArgument( 0 );
1743
1842
if (pref->use_idx) {
1744
1843
proc->addArgument("-idx");
1790
#if !NEW_ASPECT_CODE
1792
if (!mset.panscan_filter.isEmpty()) {
1793
proc->addArgument( "-vf-add" );
1794
proc->addArgument( mset.panscan_filter );
1798
if (!mset.crop_43to169_filter.isEmpty()) {
1799
proc->addArgument( "-vf-add" );
1800
proc->addArgument( mset.crop_43to169_filter );
1805
1890
if (mset.current_denoiser != MediaSettings::NoDenoise) {
1806
1891
proc->addArgument("-vf-add");
1807
1892
if (mset.current_denoiser==MediaSettings::DenoiseSoft) {
1808
proc->addArgument( "hqdn3d=2:1:2" );
1893
proc->addArgument( pref->filters->item("denoise_soft").filter() );
1810
proc->addArgument( "hqdn3d" );
1895
proc->addArgument( pref->filters->item("denoise_normal").filter() );
1815
1900
if (mset.deblock_filter) {
1816
1901
proc->addArgument("-vf-add");
1817
proc->addArgument( "pp=vb/hb" );
1902
proc->addArgument( pref->filters->item("deblock").filter() );
2538
2623
void Core::setVolume(int volume, bool force) {
2539
2624
qDebug("Core::setVolume: %d", volume);
2541
if ((volume==mset.volume) && (!force)) return;
2543
mset.volume = volume;
2544
if (mset.volume > 100 ) mset.volume = 100;
2545
if (mset.volume < 0 ) mset.volume = 0;
2626
int current_volume = (pref->global_volume ? pref->volume : mset.volume);
2628
if ((volume == current_volume) && (!force)) return;
2630
current_volume = volume;
2631
if (current_volume > 100) current_volume = 100;
2632
if (current_volume < 0) current_volume = 0;
2547
2634
if (state() == Paused) {
2548
2635
// Change volume later, after quiting pause
2549
2636
change_volume_after_unpause = true;
2551
tellmp("volume " + QString::number(volume) + " 1");
2638
tellmp("volume " + QString::number(current_volume) + " 1");
2554
//if (mset.mute) mute(TRUE);
2641
if (pref->global_volume) {
2642
pref->volume = current_volume;
2645
mset.volume = current_volume;
2557
2649
updateWidgets();
2559
displayMessage( tr("Volume: %1").arg(mset.volume) );
2560
emit volumeChanged( mset.volume );
2651
displayMessage( tr("Volume: %1").arg(current_volume) );
2652
emit volumeChanged( current_volume );
2563
2655
void Core::switchMute() {
2570
2662
void Core::mute(bool b) {
2571
2663
qDebug("Core::mute");
2576
if (mset.mute) v = 1;
2665
int v = (b ? 1 : 0);
2577
2666
tellmp( pausing_prefix() + " mute " + QString::number(v) );
2668
if (pref->global_volume) {
2579
2674
updateWidgets();
2582
2677
void Core::incVolume() {
2583
2678
qDebug("Core::incVolume");
2584
setVolume(mset.volume + 4);
2679
int new_vol = (pref->global_volume ? pref->volume + 4 : mset.volume + 4);
2587
2683
void Core::decVolume() {
2588
2684
qDebug("Core::incVolume");
2589
setVolume(mset.volume-4);
2685
int new_vol = (pref->global_volume ? pref->volume - 4 : mset.volume - 4);
2592
2689
void Core::setSubDelay(int delay) {
2593
2690
qDebug("Core::setSubDelay: %d", delay);
2594
2691
mset.sub_delay = delay;
2595
tellmp("sub_delay " + QString::number( (double) mset.sub_delay/1000 ) +" 1");
2692
tellmp( pausing_prefix() + " sub_delay " + QString::number( (double) mset.sub_delay/1000 ) +" 1");
2693
displayMessage( tr("Subtitle delay: %1 ms").arg(delay) );
2598
2696
void Core::incSubDelay() {
2946
3056
tellmp("switch_audio " + QString::number(ID) );
2948
3057
// Workaround for a mplayer problem in windows,
2949
3058
// volume is too loud after changing audio.
2951
3060
// Workaround too for a mplayer problem in linux,
2952
3061
// the volume is reduced if using -softvol-max.
2953
if (!pref->dont_change_volume) {
3063
if (pref->global_volume) {
3064
setVolume( pref->volume, true);
3065
if (pref->mute) mute(true);
2954
3067
setVolume( mset.volume, true );
3068
if (mset.mute) mute(true); // if muted, mute again
2957
if (mset.mute) mute(true); // if muted, mute again
2958
3070
updateWidgets();
3134
void Core::changeProgram(int ID) {
3135
qDebug("Core::changeProgram: %d", ID);
3137
if (ID != mset.current_program_id) {
3138
mset.current_program_id = ID;
3139
tellmp("set_property switch_program " + QString::number(ID) );
3141
tellmp("get_property switch_audio");
3142
tellmp("get_property switch_video");
3145
mset.current_video_id = MediaSettings::NoneSelected;
3146
mset.current_audio_id = MediaSettings::NoneSelected;
3153
void Core::nextProgram() {
3154
qDebug("Core::nextProgram");
3155
// Not implemented yet
3017
3160
void Core::changeTitle(int ID) {
3018
3161
if (mdat.type == TYPE_VCD) {
3192
3335
void Core::nextAspectRatio() {
3193
int ID = mset.aspect_ratio_id + 1;
3194
if (ID > MediaSettings:: Aspect11) ID = MediaSettings::AspectNone;
3195
changeAspectRatio(ID);
3338
s << MediaSettings::AspectNone
3339
<< MediaSettings::AspectAuto
3340
<< MediaSettings::Aspect11 // 1
3341
<< MediaSettings::Aspect54 // 1.25
3342
<< MediaSettings::Aspect43 // 1.33
3343
<< MediaSettings::Aspect1410 // 1.4
3344
<< MediaSettings::Aspect32 // 1.5
3345
<< MediaSettings::Aspect149 // 1.55
3346
<< MediaSettings::Aspect1610 // 1.6
3347
<< MediaSettings::Aspect169 // 1.77
3348
<< MediaSettings::Aspect235; // 2.35
3350
int i = s.indexOf( mset.aspect_ratio_id ) + 1;
3351
if (i >= s.count()) i = 0;
3353
int new_aspect_id = s[i];
3355
changeAspectRatio( new_aspect_id );
3197
3356
updateWidgets();
3359
void Core::nextWheelFunction() {
3360
int a = pref->wheel_function;
3363
if(((int ) pref->wheel_function_cycle)==0)
3371
// See if we are done
3372
if(pref->wheel_function_cycle.testFlag(QFlag(a)))
3375
pref->wheel_function = a;
3378
case Preferences::Seeking:
3379
m = tr("Mouse wheel seeks now");
3381
case Preferences::Volume:
3382
m = tr("Mouse wheel changes volume now");
3384
case Preferences::Zoom:
3385
m = tr("Mouse wheel changes zoom level now");
3387
case Preferences::ChangeSpeed:
3388
m = tr("Mouse wheel changes speed now");
3200
3394
void Core::changeLetterbox(bool b) {
3201
3395
qDebug("Core::changeLetterbox: %d", b);
3210
void Core::changeAspectRatio( int ID ) {
3211
qDebug("Core::changeAspectRatio: %d", ID);
3213
int old_id = mset.aspect_ratio_id;
3214
mset.aspect_ratio_id = ID;
3215
bool need_restart = FALSE;
3217
double asp = mdat.video_aspect; // Set a default
3219
if (ID==MediaSettings::Aspect43Letterbox) {
3220
need_restart = (old_id != MediaSettings::Aspect43Letterbox);
3221
asp = (double) 4 / 3;
3222
mset.letterbox = MediaSettings::Letterbox_43;
3223
mset.panscan_filter = "";
3224
mset.crop_43to169_filter = "";
3227
if (ID==MediaSettings::Aspect169Letterbox) {
3228
need_restart = (old_id != MediaSettings::Aspect169Letterbox);
3229
asp = (double) 16 / 9;
3230
mset.letterbox = MediaSettings::Letterbox_169;
3231
mset.panscan_filter = "";
3232
mset.crop_43to169_filter = "";
3235
if (ID==MediaSettings::Aspect43Panscan) {
3236
need_restart = (old_id != MediaSettings::Aspect43Panscan);
3237
mset.crop_43to169_filter = "";
3238
mset.letterbox = MediaSettings::NoLetterbox;
3240
asp = (double) 4 / 3;
3241
int real_width = (int) round(mdat.video_height * mdat.video_aspect);
3242
mset.panscan_filter = QString("scale=%1:%2,").arg(real_width).arg(mdat.video_height);
3243
mset.panscan_filter += QString("crop=%1:%2").arg(round(mdat.video_height * 4 /3)).arg(mdat.video_height);
3244
//mset.crop = QSize( mdat.video_height * 4 /3, mdat.video_height );
3245
qDebug("Core::changeAspectRatio: panscan_filter = '%s'", mset.panscan_filter.toUtf8().data() );
3249
if (ID==MediaSettings::Aspect43To169) {
3250
need_restart = (old_id != MediaSettings::Aspect43To169);
3251
mset.panscan_filter = "";
3252
mset.crop_43to169_filter = "";
3253
mset.letterbox = MediaSettings::NoLetterbox;
3255
int real_width = (int) round(mdat.video_height * mdat.video_aspect);
3256
int height = (int) round(real_width * 9 / 16);
3258
qDebug("Core::changeAspectRatio: video_width: %d, video_height: %d", real_width, mdat.video_height);
3259
qDebug("Core::changeAspectRatio: crop: %d, %d", real_width, height );
3261
if (height > mdat.video_height) {
3262
// Invalid size, source video is not 4:3
3263
need_restart = FALSE;
3265
asp = (double) 16 / 9;
3266
mset.crop_43to169_filter = QString("scale=%1:%2,").arg(real_width).arg(mdat.video_height);
3267
mset.crop_43to169_filter += QString("crop=%1:%2").arg(real_width).arg(height);
3268
qDebug("Core::changeAspectRatio: crop_43to169_filter = '%s'", mset.crop_43to169_filter.toUtf8().data() );
3273
//need_restart = (mset.force_letterbox == TRUE);
3274
need_restart = ( (old_id == MediaSettings::Aspect43Letterbox) ||
3275
(old_id == MediaSettings::Aspect169Letterbox) ||
3276
(old_id == MediaSettings::Aspect43Panscan) ||
3277
(old_id == MediaSettings::Aspect43To169) );
3278
mset.letterbox = MediaSettings::NoLetterbox;
3279
mset.panscan_filter = "";
3280
mset.crop_43to169_filter = "";
3282
//case MediaSettings::AspectAuto: asp = mdat.video_aspect; break;
3283
case MediaSettings::AspectAuto: {
3284
qDebug("Core::changeAspectRatio: mset.win_width %d, mset.win_height: %d", mset.win_width, mset.win_height);
3285
asp = mset.win_aspect(); break;
3287
case MediaSettings::Aspect43: asp = (double) 4 / 3; break;
3288
case MediaSettings::Aspect169: asp = (double) 16 / 9; break;
3289
case MediaSettings::Aspect149: asp = (double) 14 / 9; break;
3290
case MediaSettings::Aspect1610: asp = (double) 16 / 10; break;
3291
case MediaSettings::Aspect54: asp = (double) 5 / 4; break;
3292
case MediaSettings::Aspect235: asp = 2.35; break;
3296
if (!pref->use_mplayer_window) {
3297
mplayerwindow->setAspect( asp );
3299
// Using mplayer own window
3300
tellmp("switch_ratio " + QString::number(asp));
3306
/*mdat.calculateWinResolution(mset.force_letterbox);*/
3312
3403
void Core::changeOSD(int v) {
3313
3404
qDebug("Core::changeOSD: %d", v);
3316
tellmp("osd " + QString::number( pref->osd ) );
3407
tellmp( pausing_prefix() + " osd " + QString::number( pref->osd ) );
3317
3408
updateWidgets();
3784
3876
// The loaded subtitle file is the last one, so
3785
3877
// try to select that one.
3786
3878
if (mdat.subs.numItems() > 0) {
3787
changeSubtitle( mdat.subs.numItems()-1 );
3879
int selected_subtitle = mdat.subs.numItems()-1; // If everything fails, use the last one
3881
// Try to find the subtitle file in the list
3882
for (int n = 0; n < mdat.subs.numItems(); n++) {
3883
SubData sub = mdat.subs.itemAt(n);
3884
if ((sub.type() == SubData::File) && (sub.filename() == mset.external_subtitles)) {
3885
selected_subtitle = n;
3886
qDebug("Core::initSubtitleTrack: external subtitle found: #%d", n);
3890
changeSubtitle( selected_subtitle );
3855
3958
void Core::dvdnavUpdateMousePos(QPoint pos) {
3856
if ((state() == Playing) && (mdat.filename.startsWith("dvdnav:"))) {
3959
if ((state() == Playing) && (mdat.filename.startsWith("dvdnav:")) && (dvdnav_title_is_menu)) {
3857
3960
if (mplayerwindow->videoLayer()->underMouse()) {
3858
3961
QPoint p = mplayerwindow->videoLayer()->mapFromParent(pos);
3859
3962
tellmp(QString("set_mouse_pos %1 %2").arg(p.x()).arg(p.y()));
3967
void Core::dvdTitleIsMenu() {
3968
qDebug("Core::dvdTitleIsMenu");
3969
dvdnav_title_is_menu = true;
3972
void Core::dvdTitleIsMovie() {
3973
qDebug("Core::dvdTitleIsMovie");
3974
dvdnav_title_is_menu = false;
3865
3979
QString Core::pausing_prefix() {