~ubuntu-branches/ubuntu/wily/smplayer/wily

« back to all changes in this revision

Viewing changes to src/core.cpp

  • Committer: Package Import Robot
  • Author(s): Maia Kozheva, Maia Kozheva, Alessio Treglia
  • Date: 2012-04-14 12:01:57 UTC
  • mfrom: (1.1.13)
  • mto: (20.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 23.
  • Revision ID: package-import@ubuntu.com-20120414120157-mndwobcslgisomso
[ Maia Kozheva ]
* New upstream release:
  - Changes since 0.7.1:
    + A toolbar editor has been added. Now it's possible to select the
      buttons and controls that want to appear in the toolbars.
    + New video filters: gradfun, blur and sharpen.
    + Now it's possible to change the GUI (default, mini, mpc) at runtime,
      no restart required.
    + sub files from opensubtitles should work again.
    + (Youtube) Recognize short urls (like this one:
      http://y2u.be/F5OcZBVPwOA)
    + Better support for chapters in video files.
    + Bug fix: remote m3u files work from the favorites menu or command line.
    + Internal changes in the single instance option (switch to 
      QtSingleApplication).
  - Fixes since 0.7.0:
    + SMPlayer took more than 10 seconds to show when running for the very
      first time.
    + The links to download subtitles from Opensubtitles were wrong.
    + SMPlayer crashed in the favorite editor when trying to select a file
      if the KDE open dialog was used.
  - Changes since 0.7.0:
    + By default the screenshots are saved in the user's pictures folder
      instead of the SMPlayer's config folder.
    + Now it's possible to change the opensubtitles server.
    + Youtube: seeking is slow with flv videos, so now flv videos have the
      lowest priority.
    + Youtube: now it's possible to search and download videos from youtube.
      This is provided by an external application (in linux you have to
      install an independent package: smtube).
* debian/copyright:
  - Rewrite according to DEP-5 specification.
* debian/control:
  - Depend on mplayer2 | mplayer. (Closes: #638279)
  - Update Standards-Version to 3.9.3.
* Remove debian/patches/handle_local_urls.diff, merged upstream.

[ Alessio Treglia ]
* Mention smplayer is also a front-end for MPlayer2.
* Fix small typo in the description.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <QTextStream>
24
24
#include <QUrl>
25
25
 
 
26
#ifdef Q_OS_OS2
 
27
#include <QEventLoop>
 
28
#endif
 
29
 
26
30
#include <cmath>
27
31
 
28
32
#include "mplayerwindow.h"
54
58
#include "tvsettings.h"
55
59
#endif
56
60
 
57
 
#if YOUTUBE_SUPPORT
 
61
#ifdef YOUTUBE_SUPPORT
58
62
#include "retrieveyoutubeurl.h"
59
63
#endif
60
64
 
240
244
        DiscName::test();
241
245
#endif
242
246
 
243
 
#if YOUTUBE_SUPPORT
 
247
#ifdef YOUTUBE_SUPPORT
244
248
        yt = new RetrieveYoutubeUrl(this);
245
249
        connect(yt, SIGNAL(gotPreferredUrl(const QString &)), this, SLOT(openYT(const QString &)));
246
250
        connect(yt, SIGNAL(connecting(QString)), this, SLOT(connectingToYT(QString)));
270
274
#endif
271
275
#endif
272
276
 
273
 
#if YOUTUBE_SUPPORT
 
277
#ifdef YOUTUBE_SUPPORT
274
278
        delete yt;
275
279
#endif
276
280
}
489
493
        }
490
494
}
491
495
 
492
 
#if YOUTUBE_SUPPORT
 
496
#ifdef YOUTUBE_SUPPORT
493
497
void Core::openYT(const QString & url) {
494
498
        qDebug("Core::openYT: %s", url.toUtf8().constData());
495
499
        openStream(url);
713
717
        mset.reset();
714
718
 
715
719
        mset.current_title_id = title;
716
 
#if GENERIC_CHAPTER_SUPPORT
717
720
        mset.current_chapter_id = firstChapter();
718
 
#else
719
 
        mset.current_chapter_id = dvdFirstChapter();
720
 
#endif
721
721
        mset.current_angle_id = 1;
722
722
 
723
723
        /* initializeMenus(); */
782
782
void Core::openStream(QString name) {
783
783
        qDebug("Core::openStream: '%s'", name.toUtf8().data());
784
784
 
785
 
#if YOUTUBE_SUPPORT
786
 
        if (name.startsWith("http://www.youtube.com/watch?v=")) {
 
785
#ifdef YOUTUBE_SUPPORT
 
786
        if (name.contains("youtube.com/watch", Qt::CaseInsensitive) || 
 
787
        name.contains("youtu.be/", Qt::CaseInsensitive) ||
 
788
        name.contains("y2u.be/", Qt::CaseInsensitive) )
 
789
        {
787
790
                qDebug("Core::openStream: youtube url detected");
 
791
                if (name.startsWith("www.youtube.com")) name = "http://" + name;
 
792
                if (name.startsWith("youtube.com")) name = "http://www." + name;
 
793
                if (name.startsWith("youtu.be")) name = "http://" + name;
 
794
                if (name.startsWith("y2u.be")) name = "http://" + name;
788
795
                yt->setPreferredQuality( (RetrieveYoutubeUrl::Quality) pref->yt_quality );
789
796
                yt->fetchPage(name);
790
797
                return;
905
912
        int start_sec = (int) mset.current_sec;
906
913
        if (seek > -1) start_sec = seek;
907
914
 
908
 
#if YOUTUBE_SUPPORT
 
915
#ifdef YOUTUBE_SUPPORT
909
916
        // Avoid to pass to mplayer the youtube page url
910
917
        if (mdat.type == TYPE_STREAM) {
911
918
                if (mdat.filename == yt->origUrl()) {
978
985
        }
979
986
#endif
980
987
 
981
 
#if GENERIC_CHAPTER_SUPPORT
982
 
        if (mdat.chapters > 0) {
983
 
#else
984
 
        // mkv chapters
985
 
        if (mdat.mkv_chapters > 0) {
986
 
#endif
 
988
        if (mdat.n_chapters > 0) {
987
989
                // Just to show the first chapter checked in the menu
988
990
                mset.current_chapter_id = firstChapter();
989
991
        }
1025
1027
                mdat.demuxer = proc->mediaData().demuxer;
1026
1028
        }
1027
1029
 
1028
 
#if YOUTUBE_SUPPORT
 
1030
#ifdef YOUTUBE_SUPPORT
1029
1031
        // Change the real url with the youtube page url and set the title
1030
1032
        if (mdat.type == TYPE_STREAM) {
1031
1033
                if (mdat.filename == yt->latestPreferredUrl()) {
1337
1339
                return;
1338
1340
    }
1339
1341
 
1340
 
#if YOUTUBE_SUPPORT
 
1342
#ifdef YOUTUBE_SUPPORT
1341
1343
        // Stop any pending request
1342
1344
        qDebug("Core::startMplayer: yt state: %d", yt->state());        
1343
1345
        if (yt->state() != QHttp::Unconnected) {
1409
1411
 
1410
1412
        proc->addArgument("-noquiet");
1411
1413
 
 
1414
#ifdef LOG_MPLAYER
1412
1415
        if (pref->verbose_log) {
1413
1416
                proc->addArgument("-v");
1414
1417
        }
 
1418
#endif
1415
1419
 
1416
1420
        if (pref->fullscreen && pref->use_mplayer_window) {
1417
1421
                proc->addArgument("-fs");
1497
1501
 
1498
1502
        proc->addArgument("-identify");
1499
1503
 
1500
 
#if GENERIC_CHAPTER_SUPPORT
1501
1504
        if (MplayerVersion::isMplayerAtLeast(27667)) {
1502
1505
                // From r27667 the number of chapters can be obtained from ID_CHAPTERS
1503
1506
                mset.current_chapter_id = 0; // Reset chapters
1504
1507
        } else {
1505
 
#endif
1506
1508
                // We need this to get info about mkv chapters
1507
1509
                if (is_mkv) {
1508
1510
                        proc->addArgument("-msglevel");
1514
1516
                        // (time would be relative to chapter)
1515
1517
                        mset.current_chapter_id = 0;
1516
1518
                }
1517
 
#if GENERIC_CHAPTER_SUPPORT
1518
1519
        }
1519
 
#endif
1520
 
        
 
1520
 
1521
1521
        proc->addArgument("-slave");
1522
1522
 
1523
1523
        if (!pref->vo.isEmpty()) {
1637
1637
                #define WINIDFROMHWND(hwnd) ( ( hwnd ) - 0x80000000UL )
1638
1638
                proc->addArgument( QString::number( WINIDFROMHWND( (int) mplayerwindow->videoLayer()->winId() ) ));
1639
1639
#else
1640
 
                proc->addArgument( QString::number( (int) mplayerwindow->videoLayer()->winId() ) );
 
1640
                proc->addArgument( QString::number( (qint64) mplayerwindow->videoLayer()->winId() ) );
1641
1641
#endif
1642
1642
 
1643
1643
#if USE_COLORKEY
1918
1918
                proc->addArgument("-chapter");
1919
1919
                int chapter = mset.current_chapter_id;
1920
1920
                // Fix for older versions of mplayer:
1921
 
#if GENERIC_CHAPTER_SUPPORT
1922
1921
                if ((mdat.type == TYPE_DVD) && (firstChapter() == 0)) chapter++;
1923
 
#else
1924
 
                if ((mdat.type == TYPE_DVD) && (dvdFirstChapter() == 0)) chapter++;
1925
 
#endif
1926
1922
                proc->addArgument( QString::number( chapter ) );
1927
1923
        }
1928
1924
 
2046
2042
                }
2047
2043
        }
2048
2044
 
 
2045
        // Unsharp
 
2046
        if (mset.current_unsharp != 0) {
 
2047
                proc->addArgument("-vf-add");
 
2048
                if (mset.current_unsharp == 1) {
 
2049
                        proc->addArgument( pref->filters->item("blur").filter() );
 
2050
                } else {
 
2051
                        proc->addArgument( pref->filters->item("sharpen").filter() );
 
2052
                }
 
2053
        }
 
2054
 
2049
2055
        // Deblock
2050
2056
        if (mset.deblock_filter) {
2051
2057
                proc->addArgument("-vf-add");
2058
2064
                proc->addArgument( "pp=dr" );
2059
2065
        }
2060
2066
 
 
2067
        // Gradfun
 
2068
        if (mset.gradfun_filter) {
 
2069
                proc->addArgument("-vf-add");
 
2070
                proc->addArgument( pref->filters->item("gradfun").filter() );
 
2071
        }
 
2072
 
2061
2073
        // Upscale
2062
2074
        if (mset.upscaling_filter) {
2063
2075
                int width = DesktopInfo::desktop_size(mplayerwindow).width();
2324
2336
                return;
2325
2337
        }
2326
2338
 
 
2339
#ifdef Q_OS_OS2
 
2340
        QEventLoop eventLoop;
 
2341
 
 
2342
        connect(proc, SIGNAL(processExited()), &eventLoop, SLOT(quit()));
 
2343
 
 
2344
        tellmp("quit");
 
2345
 
 
2346
        QTimer::singleShot(5000, &eventLoop, SLOT(quit()));
 
2347
        eventLoop.exec(QEventLoop::ExcludeUserInputEvents);
 
2348
 
 
2349
        if (proc->isRunning()) {
 
2350
                qWarning("Core::stopMplayer: process didn't finish. Killing it...");
 
2351
                proc->kill();
 
2352
        }
 
2353
#else
2327
2354
    tellmp("quit");
2328
2355
    
2329
2356
        qDebug("Core::stopMplayer: Waiting mplayer to finish...");
2331
2358
                qWarning("Core::stopMplayer: process didn't finish. Killing it...");
2332
2359
                proc->kill();
2333
2360
        }
 
2361
#endif
2334
2362
 
2335
2363
        qDebug("Core::stopMplayer: Finished. (I hope)");
2336
2364
}
2631
2659
        }
2632
2660
}
2633
2661
 
 
2662
void Core::toggleGradfun() {
 
2663
        toggleGradfun( !mset.gradfun_filter );
 
2664
}
 
2665
 
 
2666
void Core::toggleGradfun(bool b) {
 
2667
        qDebug("Core::toggleGradfun: %d", b);
 
2668
        if ( b != mset.gradfun_filter) {
 
2669
                mset.gradfun_filter = b;
 
2670
                restartPlay();
 
2671
        }
 
2672
}
 
2673
 
2634
2674
void Core::toggleNoise() {
2635
2675
        toggleNoise( !mset.noise_filter );
2636
2676
}
2663
2703
        }
2664
2704
}
2665
2705
 
 
2706
void Core::changeUnsharp(int id) {
 
2707
        qDebug( "Core::changeUnsharp: %d", id );
 
2708
        if (id != mset.current_unsharp) {
 
2709
                mset.current_unsharp = id;
 
2710
                restartPlay();
 
2711
        }
 
2712
}
 
2713
 
2666
2714
void Core::changeUpscale(bool b) {
2667
2715
        qDebug( "Core::changeUpscale: %d", b );
2668
2716
        if (mset.upscaling_filter != b) {
3409
3457
void Core::changeChapter(int ID) {
3410
3458
        qDebug("Core::changeChapter: ID: %d", ID);
3411
3459
 
3412
 
        if (ID != mset.current_chapter_id) {
3413
 
                //if (QFileInfo(mdat.filename).extension().lower()=="mkv") {
3414
 
#if GENERIC_CHAPTER_SUPPORT
3415
 
                if (mdat.type != TYPE_DVD) {
3416
 
#else
3417
 
                if (mdat.mkv_chapters > 0) {
3418
 
                        // mkv doesn't require to restart
3419
 
#endif
 
3460
        if (mdat.type != TYPE_DVD) {
 
3461
                /*
 
3462
                if (mdat.chapters.find(ID) > -1) {
 
3463
                        double start = mdat.chapters.item(ID).start();
 
3464
                        qDebug("Core::changeChapter: start: %f", start);
 
3465
                        goToSec(start);
 
3466
                        mset.current_chapter_id = ID;
 
3467
                } else {
 
3468
                */
3420
3469
                        tellmp("seek_chapter " + QString::number(ID) +" 1");
3421
3470
                        mset.current_chapter_id = ID;
3422
 
                        updateWidgets();
3423
 
                } else {
 
3471
                        //updateWidgets();
 
3472
                /*
 
3473
                }
 
3474
                */
 
3475
        } else {
3424
3476
#if SMART_DVD_CHAPTERS
3425
 
                        if (pref->cache_for_dvds == 0) {
 
3477
                if (pref->cache_for_dvds == 0) {
3426
3478
#else
3427
 
                        if (pref->fast_chapter_change) {
 
3479
                if (pref->fast_chapter_change) {
3428
3480
#endif
3429
 
                                tellmp("seek_chapter " + QString::number(ID) +" 1");
3430
 
                                mset.current_chapter_id = ID;
3431
 
                                updateWidgets();
3432
 
                        } else {
3433
 
                                stopMplayer();
3434
 
                                mset.current_chapter_id = ID;
3435
 
                                //goToPos(0);
3436
 
                                mset.current_sec = 0;
3437
 
                                restartPlay();
3438
 
                        }
 
3481
                        tellmp("seek_chapter " + QString::number(ID) +" 1");
 
3482
                        mset.current_chapter_id = ID;
 
3483
                        updateWidgets();
 
3484
                } else {
 
3485
                        stopMplayer();
 
3486
                        mset.current_chapter_id = ID;
 
3487
                        //goToPos(0);
 
3488
                        mset.current_sec = 0;
 
3489
                        restartPlay();
3439
3490
                }
3440
3491
        }
3441
3492
}
3448
3499
                return 0;
3449
3500
}
3450
3501
 
3451
 
#if !GENERIC_CHAPTER_SUPPORT
3452
 
int Core::dvdFirstChapter() {
3453
 
        // TODO: check if the change really happens in the same version as mkv
3454
 
        return firstChapter();
3455
 
}
3456
 
#endif
3457
 
 
3458
3502
void Core::prevChapter() {
3459
3503
        qDebug("Core::prevChapter");
3460
3504
 
3461
 
#if GENERIC_CHAPTER_SUPPORT
3462
3505
        int last_chapter = 0;
3463
3506
        int first_chapter = firstChapter();
3464
3507
 
3465
 
        last_chapter = mdat.chapters + firstChapter() - 1;
3466
 
 
3467
 
        int ID = mset.current_chapter_id - 1;
3468
 
        if (ID < first_chapter) {
3469
 
                ID = last_chapter;
3470
 
        }
3471
 
        changeChapter(ID);
3472
 
#else
3473
 
        int last_chapter = 0;
3474
 
        bool matroshka = (mdat.mkv_chapters > 0);
3475
 
 
3476
 
        int first_chapter = dvdFirstChapter();
3477
 
        if (matroshka) first_chapter = firstChapter();
3478
 
 
3479
 
        // Matroshka chapters
3480
 
        if (matroshka) last_chapter = mdat.mkv_chapters + firstChapter() - 1;
3481
 
        else
3482
 
        // DVD chapters
3483
 
        if (mset.current_title_id > 0) {
3484
 
                last_chapter = mdat.titles.item(mset.current_title_id).chapters() + dvdFirstChapter() -1;
3485
 
        }
3486
 
 
3487
 
        int ID = mset.current_chapter_id - 1;
3488
 
        if (ID < first_chapter) {
3489
 
                ID = last_chapter;
3490
 
        }
3491
 
        changeChapter(ID);
3492
 
#endif
 
3508
        int ID = mdat.chapters.itemBeforeTime(mset.current_sec).ID();
 
3509
 
 
3510
        if (ID == -1) {
 
3511
                last_chapter = mdat.n_chapters + firstChapter() - 1;
 
3512
 
 
3513
                ID = mset.current_chapter_id - 1;
 
3514
                if (ID < first_chapter) {
 
3515
                        ID = last_chapter;
 
3516
                }
 
3517
        }
 
3518
 
 
3519
        changeChapter(ID);
3493
3520
}
3494
3521
 
3495
3522
void Core::nextChapter() {
3496
3523
        qDebug("Core::nextChapter");
3497
3524
 
3498
 
#if GENERIC_CHAPTER_SUPPORT
3499
 
        int last_chapter = 0;
3500
 
        last_chapter = mdat.chapters + firstChapter() - 1;
3501
 
 
3502
 
        int ID = mset.current_chapter_id + 1;
3503
 
        if (ID > last_chapter) {
3504
 
                ID = firstChapter();
3505
 
        }
3506
 
        changeChapter(ID);
3507
 
#else
3508
 
        int last_chapter = 0;
3509
 
        bool matroshka = (mdat.mkv_chapters > 0);
3510
 
 
3511
 
        // Matroshka chapters
3512
 
        if (matroshka) last_chapter = mdat.mkv_chapters + firstChapter() - 1;
3513
 
        else
3514
 
        // DVD chapters
3515
 
        if (mset.current_title_id > 0) {
3516
 
                last_chapter = mdat.titles.item(mset.current_title_id).chapters() + dvdFirstChapter() - 1;
3517
 
        }
3518
 
 
3519
 
        int ID = mset.current_chapter_id + 1;
3520
 
        if (ID > last_chapter) {
3521
 
                if (matroshka) ID = firstChapter(); else ID = dvdFirstChapter();
3522
 
        }
3523
 
        changeChapter(ID);
3524
 
#endif
 
3525
        int last_chapter = mdat.n_chapters + firstChapter() - 1;
 
3526
 
 
3527
        int ID = mdat.chapters.itemAfterTime(mset.current_sec).ID();
 
3528
 
 
3529
        if (ID == -1) {
 
3530
                ID = mset.current_chapter_id + 1;
 
3531
                if (ID > last_chapter) {
 
3532
                        ID = firstChapter();
 
3533
                }
 
3534
        }
 
3535
 
 
3536
        changeChapter(ID);
3525
3537
}
3526
3538
 
3527
3539
void Core::changeAngle(int ID) {