~ubuntu-branches/debian/squeeze/smplayer/squeeze

« back to all changes in this revision

Viewing changes to src/core.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Breuil Cyril
  • Date: 2007-06-24 16:35:29 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070624163529-hhckbmd24uicada7
Tags: 0.5.20-0ubuntu1
* New upstream release
* Change Maintainer Email

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include "config.h"
34
34
 
35
35
 
 
36
#ifdef Q_OS_WIN
 
37
/* To change app priority */
 
38
#include <windows.h>
 
39
#endif
 
40
 
 
41
 
36
42
Core::Core( MplayerWindow *mpw, QWidget* parent, const char* name ) 
37
43
        : QObject( parent, name ) 
38
44
{
96
102
        connect( proc, SIGNAL(receivedStartingTime(double)),
97
103
             this, SLOT(gotStartingTime(double)) );
98
104
 
 
105
        connect( proc, SIGNAL(receivedStreamTitleAndUrl(QString,QString)),
 
106
             this, SLOT(streamTitleAndUrlChanged(QString,QString)) );
 
107
 
99
108
        // Mplayerwindow
100
109
        connect( this, SIGNAL(stateChanged(int)),
101
110
             this, SLOT(prepareMplayerWindow(int)) );
273
282
                        openVCD();
274
283
                }
275
284
        }
 
285
        else
 
286
        if (file.lower().startsWith("cdda:")) {
 
287
                qDebug(" * identified as cdda");
 
288
 
 
289
                QString f = file.lower();
 
290
                QRegExp s("^cdda://(\\d+)");
 
291
                if (s.search(f) != -1) {
 
292
                        int title = s.cap(1).toInt();
 
293
                        openAudioCD(title);
 
294
                } else {
 
295
                        qWarning("Core::open: couldn't parse cdda title, playing first one");
 
296
                        openAudioCD();
 
297
                }
 
298
        }
276
299
        else {
277
300
                qDebug(" * not identified, playing as stream");
278
301
                openStream(file);
313
336
#endif
314
337
}
315
338
 
 
339
void Core::loadAudioFile(const QString & audiofile) {
 
340
        if (!audiofile.isEmpty()) {
 
341
                mset.external_audio = audiofile;
 
342
                restartPlay();
 
343
        }
 
344
}
 
345
 
 
346
void Core::unloadAudioFile() {
 
347
        if (!mset.external_audio.isEmpty()) {
 
348
                mset.external_audio = "";
 
349
                restartPlay();
 
350
        }
 
351
}
 
352
 
316
353
/*
317
354
void Core::openDVD( bool from_folder, QString directory) {
318
355
        qDebug("Core::openDVD");
393
430
        initPlaying();
394
431
}
395
432
 
 
433
void Core::openAudioCD(int title) {
 
434
        qDebug("Core::openAudioCD: %d", title);
 
435
 
 
436
        if (title == -1) title = 1;
 
437
 
 
438
        if (proc->isRunning()) {
 
439
                stopMplayer();
 
440
        }
 
441
 
 
442
        // Save data of previous file:
 
443
        saveMediaInfo();
 
444
 
 
445
        mdat.reset();
 
446
        mdat.filename = "cdda://" + QString::number(title);
 
447
        mdat.type = TYPE_AUDIO_CD;
 
448
 
 
449
        mset.reset();
 
450
 
 
451
        mset.current_title_id = title;
 
452
        mset.current_chapter_id = -1;
 
453
        mset.current_angle_id = -1;
 
454
 
 
455
        /* initializeMenus(); */
 
456
 
 
457
        initPlaying();
 
458
}
 
459
 
396
460
void Core::openDVD(QString dvd_url) {
397
461
        qDebug("Core::openDVD: '%s'", dvd_url.utf8().data());
398
462
 
602
666
 
603
667
        mdat.initialized = TRUE;
604
668
 
 
669
        // MPlayer doesn't display the length in ID_LENGTH for audio CDs...
 
670
        if ((mdat.duration == 0) && (mdat.type == TYPE_AUDIO_CD)) {
 
671
                /*
 
672
                qDebug(" *** get duration here from title info *** ");
 
673
                qDebug(" *** current title: %d", mset.current_title_id );
 
674
                */
 
675
                if (mset.current_title_id > 0) {
 
676
                        mdat.duration = mdat.titles.item(mset.current_title_id).duration();
 
677
                }
 
678
        }
 
679
 
605
680
        /* updateWidgets(); */
606
681
 
607
682
        mdat.list();
690
765
        updateWidgets(); // New
691
766
 
692
767
        emit mediaLoaded();
 
768
        emit mediaInfoChanged();
693
769
}
694
770
 
695
771
 
907
983
                proc->addArgument(mset.forced_video_codec);
908
984
        }
909
985
 
 
986
        if (pref->use_hwac3) {
 
987
                proc->addArgument("-afm");
 
988
                proc->addArgument("hwac3");
 
989
        }
 
990
 
910
991
        proc->addArgument("-sub-fuzziness");
911
992
#if SUBTITLES_BY_INDEX
912
993
        proc->addArgument( QString::number(pref->subfuzziness) );
956
1037
 
957
1038
        // Performance options
958
1039
        #ifdef Q_OS_WIN
959
 
        proc->addArgument("-priority");
960
1040
        QString p;
 
1041
        int app_p = NORMAL_PRIORITY_CLASS;
961
1042
        switch (pref->priority) {
962
 
                case Preferences::Realtime: p = "realtime"; break;
963
 
                case Preferences::High: p = "high"; break;
964
 
                case Preferences::AboveNormal: p = "abovenormal"; break;
965
 
                case Preferences::BelowNormal: p = "belownormal"; break;
966
 
                case Preferences::Idle: p = "idle"; break;
967
 
                default: p = "normal";
 
1043
                case Preferences::Realtime:     p = "realtime"; 
 
1044
                                                                                app_p = REALTIME_PRIORITY_CLASS;
 
1045
                                                                                break;
 
1046
                case Preferences::High:                 p = "high"; 
 
1047
                                                                                app_p = REALTIME_PRIORITY_CLASS;
 
1048
                                                                                break;
 
1049
                case Preferences::AboveNormal:  p = "abovenormal"; 
 
1050
                                                                                app_p = HIGH_PRIORITY_CLASS;
 
1051
                                                                                break;
 
1052
                case Preferences::Normal:               p = "normal"; 
 
1053
                                                                                app_p = ABOVE_NORMAL_PRIORITY_CLASS; 
 
1054
                                                                                break;
 
1055
                case Preferences::BelowNormal:  p = "belownormal"; break;
 
1056
                case Preferences::Idle:                 p = "idle"; break;
 
1057
                default:                                                p = "normal";
968
1058
        }
 
1059
        proc->addArgument("-priority");
969
1060
        proc->addArgument( p );
 
1061
        SetPriorityClass(GetCurrentProcess(), app_p);
 
1062
        qDebug("Priority of smplayer process set to %d", app_p);
970
1063
        #endif
971
1064
 
972
1065
        if (pref->frame_drop) {
1001
1094
                proc->addArgument( QString::number( (int) mplayerwindow->mplayerLayer()->winId() ) );
1002
1095
        
1003
1096
                proc->addArgument("-colorkey");
1004
 
                proc->addArgument( QString::number(COLORKEY) );
 
1097
                //proc->addArgument( QString::number(COLORKEY) );
 
1098
                proc->addArgument( QString::number(pref->color_key) );
1005
1099
 
1006
1100
                // Set monitoraspect to desktop aspect
1007
1101
                proc->addArgument("-monitoraspect");
1008
 
                proc->addArgument( QString::number( desktop_aspectRatio() ) );
 
1102
                proc->addArgument( QString::number( DesktopInfo::desktop_aspectRatio(mplayerwindow) ) );
1009
1103
        } else {
1010
1104
                // no -wid
1011
1105
                if (!pref->monitor_aspect.isEmpty()) {
1021
1115
                proc->addArgument( Helper::colorToRGBA( pref->ass_color ) );
1022
1116
                proc->addArgument("-ass-border-color");
1023
1117
                proc->addArgument( Helper::colorToRGBA( pref->ass_border_color ) );
 
1118
                if (!pref->ass_styles.isEmpty()) {
 
1119
                        proc->addArgument("-ass-force-style");
 
1120
                        proc->addArgument( pref->ass_styles );
 
1121
                }
1024
1122
        }
1025
1123
 
1026
1124
        // Subtitles font
1033
1131
        if ( (!pref->use_fontconfig) && (!pref->font_file.isEmpty()) ) {
1034
1132
                proc->addArgument("-font");
1035
1133
                proc->addArgument( pref->font_file );
 
1134
 
 
1135
                if (pref->use_subfont) {
 
1136
                        proc->addArgument("-subfont");
 
1137
                        proc->addArgument( pref->font_file );
 
1138
                }
1036
1139
        }
1037
1140
 
1038
1141
        proc->addArgument( "-subfont-autoscale");
1064
1167
                }
1065
1168
        }
1066
1169
 
 
1170
        if (!mset.external_audio.isEmpty()) {
 
1171
                proc->addArgument("-audiofile");
 
1172
                proc->addArgument( mset.external_audio );
 
1173
        }
 
1174
 
1067
1175
        proc->addArgument("-subpos");
1068
1176
        proc->addArgument( QString::number(mset.sub_pos) );
1069
1177
 
1079
1187
 
1080
1188
        // Contrast, brightness...
1081
1189
        //if (mset.contrast !=0) {
 
1190
        if (!pref->dont_use_eq_options) {
1082
1191
                proc->addArgument("-contrast");
1083
1192
                proc->addArgument( QString::number( mset.contrast ) );
1084
 
        //}
 
1193
        }
1085
1194
        
1086
1195
        #ifdef Q_OS_WIN
1087
 
        if (mset.brightness !=0) {
 
1196
        if (mset.brightness != 0) {
1088
1197
        #endif
1089
 
                proc->addArgument("-brightness");
1090
 
                proc->addArgument( QString::number( mset.brightness ) );
 
1198
                if (!pref->dont_use_eq_options) {
 
1199
                        proc->addArgument("-brightness");
 
1200
                        proc->addArgument( QString::number( mset.brightness ) );
 
1201
                }
1091
1202
        #ifdef Q_OS_WIN
1092
1203
        }
1093
1204
        #endif
1094
1205
 
1095
1206
        //if (mset.hue !=0) {
 
1207
        if (!pref->dont_use_eq_options) {
1096
1208
                proc->addArgument("-hue");
1097
1209
                proc->addArgument( QString::number( mset.hue ) );
1098
 
        //}
 
1210
        }
1099
1211
 
1100
1212
        //if (mset.saturation !=0) {
 
1213
        if (!pref->dont_use_eq_options) {
1101
1214
                proc->addArgument("-saturation");
1102
1215
                proc->addArgument( QString::number( mset.saturation ) );
1103
 
        //}
 
1216
        }
1104
1217
 
1105
1218
 
1106
1219
        /*
1126
1239
                }
1127
1240
        }
1128
1241
 
1129
 
        if (mdat.type==TYPE_VCD) {
 
1242
        if ((mdat.type==TYPE_VCD) || (mdat.type==TYPE_AUDIO_CD)) {
1130
1243
                if (!pref->cdrom_device.isEmpty()) {
1131
1244
                        proc->addArgument("-cdrom-device");
1132
1245
                        proc->addArgument( pref->cdrom_device );
1144
1257
        }
1145
1258
 
1146
1259
 
1147
 
        if ( (pref->cache > 0) && ((mdat.type!=TYPE_DVD) || (!pref->fast_chapter_change)) ) {
 
1260
        bool cache_activated = ( (pref->use_cache) && (pref->cache > 0) );
 
1261
        if ( (mdat.type==TYPE_DVD) && (pref->fast_chapter_change) ) 
 
1262
                cache_activated = false;
 
1263
 
 
1264
        //if ( (pref->cache > 0) && ((mdat.type!=TYPE_DVD) || (!pref->fast_chapter_change)) ) {
 
1265
        if (cache_activated) {
1148
1266
                proc->addArgument("-cache");
1149
1267
                proc->addArgument( QString::number( pref->cache ) );
1150
1268
        }
1154
1272
                proc->addArgument( QString::number( mset.speed ) );
1155
1273
        }
1156
1274
 
1157
 
        // If seek < 5 it's best to allow the video to start from the beginning
1158
 
        if (seek >= 5) {
 
1275
        // If seek < 5 it's better to allow the video to start from the beginning
 
1276
        if ((seek >= 5) && (!pref->loop)) {
1159
1277
                proc->addArgument("-ss");
1160
1278
                proc->addArgument( QString::number( seek ) );
1161
1279
        }
1177
1295
                        case MediaSettings::L5:                 proc->addArgument("pp=l5"); break;
1178
1296
                        case MediaSettings::Yadif:              proc->addArgument("yadif"); break;
1179
1297
                        case MediaSettings::LB:                 proc->addArgument("pp=lb"); break;
 
1298
                        case MediaSettings::Yadif_1:    proc->addArgument("yadif=1"); break;
 
1299
                        case MediaSettings::Kerndeint:  proc->addArgument("kerndeint=5"); break;
1180
1300
                }
1181
1301
        }
1182
1302
 
1221
1341
        }
1222
1342
 
1223
1343
        // Postprocessing
1224
 
        if (mset.postprocessing_filter) {
 
1344
        if ( (mset.postprocessing_filter) || (pref->use_postprocessing) ) {
1225
1345
                proc->addArgument("-vf-add");
1226
1346
                proc->addArgument("pp");
1227
1347
                proc->addArgument("-autoq");
1297
1417
                af += "extrastereo";
1298
1418
        }
1299
1419
 
 
1420
        if ( (pref->use_volnorm) || (mset.volnorm_filter) ) {
 
1421
                if (!af.isEmpty()) af += ",";
 
1422
                af += "volnorm=2";
 
1423
        }
 
1424
 
1300
1425
        // Additional audio filters, supplied by user
1301
1426
        // File
1302
1427
        if ( !pref->mplayer_additional_audio_filters.isEmpty() ) {
1316
1441
 
1317
1442
        if (pref->use_soft_vol) {
1318
1443
                proc->addArgument("-softvol");
 
1444
                proc->addArgument("-softvol-max");
 
1445
                proc->addArgument( QString::number(pref->softvol_max) );
1319
1446
        }
1320
1447
 
1321
1448
        if (pref->loop) {
1451
1578
 
1452
1579
void Core::wheelUp() {
1453
1580
        qDebug("wheelUp");
1454
 
        if (pref->wheel_changes_volume) 
1455
 
                incVolume();
1456
 
        else
1457
 
                forward( pref->seeking4 );
 
1581
        switch (pref->wheel_function) {
 
1582
                case Preferences::Volume : incVolume(); break;
 
1583
                case Preferences::Zoom : incPanscan(); break;
 
1584
                default : forward( pref->seeking4 );
 
1585
        }
1458
1586
}
1459
1587
 
1460
1588
void Core::wheelDown() {
1461
1589
        qDebug("wheelDown");
1462
 
        if (pref->wheel_changes_volume) 
1463
 
                decVolume();
1464
 
        else
1465
 
                rewind( pref->seeking4 );
 
1590
        switch (pref->wheel_function) {
 
1591
                case Preferences::Volume : decVolume(); break;
 
1592
                case Preferences::Zoom : decPanscan(); break;
 
1593
                default : rewind( pref->seeking4 );
 
1594
        }
1466
1595
}
1467
1596
 
1468
1597
 
1505
1634
        }
1506
1635
}
1507
1636
 
 
1637
void Core::toggleVolnorm() {
 
1638
        toggleVolnorm( !mset.volnorm_filter );
 
1639
}
 
1640
 
 
1641
void Core::toggleVolnorm(bool b) {
 
1642
        qDebug("Core::toggleVolnorm: %d", b);
 
1643
        if (b != mset.volnorm_filter) {
 
1644
                mset.volnorm_filter = b;
 
1645
                restartPlay();
 
1646
        }
 
1647
}
 
1648
 
1508
1649
void Core::setAudioChannels(int channels) {
1509
1650
        qDebug("Core::setAudioChannels:%d", channels);
1510
1651
        if (channels != mset.audio_use_channels ) {
1819
1960
        tellmp("sub_pos " + QString::number( mset.sub_pos ) + " 1");
1820
1961
}
1821
1962
 
 
1963
 
 
1964
void Core::incSubStep() {
 
1965
        qDebug("Core::incSubStep");
 
1966
        tellmp("sub_step +1");
 
1967
}
 
1968
 
 
1969
void Core::decSubStep() {
 
1970
        qDebug("Core::decSubStep");
 
1971
        tellmp("sub_step -1");
 
1972
}
 
1973
 
 
1974
 
1822
1975
void Core::changeCurrentSec(double sec) {
1823
1976
    mset.current_sec = sec;
1824
1977
 
1964
2117
        if (mdat.type == TYPE_VCD) {
1965
2118
                // VCD
1966
2119
                openVCD( ID );
1967
 
        } 
 
2120
        }
 
2121
        else 
 
2122
        if (mdat.type == TYPE_AUDIO_CD) {
 
2123
                // AUDIO CD
 
2124
                openAudioCD( ID );
 
2125
        }
1968
2126
        else
1969
2127
        if (mdat.type == TYPE_DVD) {
1970
2128
                QString dvd_url = "dvd://" + QString::number(ID);
2166
2324
        changeOSD( osd );
2167
2325
}
2168
2326
 
2169
 
void Core::changeZoom(int n) {
2170
 
        if ( (n != pref->zoom) && (!pref->use_mplayer_window) ) {
2171
 
                pref->zoom = n;
 
2327
void Core::changeSize(int n) {
 
2328
        if ( /*(n != pref->size_factor) &&*/ (!pref->use_mplayer_window) ) {
 
2329
                pref->size_factor = n;
2172
2330
 
2173
2331
                emit needResize(mset.win_width, mset.win_height);
2174
2332
                updateWidgets();
2175
2333
        }
2176
2334
}
2177
2335
 
 
2336
void Core::toggleDoubleSize() {
 
2337
        if (pref->size_factor != 100) 
 
2338
                changeSize(100);
 
2339
        else
 
2340
                changeSize(200);
 
2341
}
 
2342
 
2178
2343
void Core::changePanscan(double p) {
2179
2344
        qDebug("Core::changePanscan: %f", p);
2180
2345
        if (p < 1.0) p = 1.0;
2286
2451
                        mplayerwindow->allowClearingBackground(true);
2287
2452
        }
2288
2453
}
 
2454
 
 
2455
void Core::streamTitleAndUrlChanged(QString title, QString url) {
 
2456
        mdat.stream_title = title;
 
2457
        mdat.stream_url = url;
 
2458
        emit mediaInfoChanged();
 
2459
}