Ticket #8641: 8641-v3.patch

File 8641-v3.patch, 18.0 KB (added by danielk, 9 years ago)
  • libs/libmythtv/tv_play.h

     
    182182    TV(void);
    183183   ~TV();
    184184
     185    void InitFromDB(void);
    185186    bool Init(bool createWindow = true);
    186187
    187188    // User input processing commands
     
    689690
    690691    QTime ctorTime;
    691692    uint switchToInputId;
     693
     694    QMutex         initFromDBLock;
     695    bool           initFromDBDone;
     696    QWaitCondition initFromDBWait;
     697
    692698    /// True if the user told MythTV to stop plaback. If this is false
    693699    /// when we exit the player, we display an error screen.
    694700    mutable bool wantsToQuit;
     
    807813
    808814    // Window info (GUI is optional, transcoding, preview img, etc)
    809815    TvPlayWindow *myWindow;   ///< Our screen, if it exists
    810     ///< player bounds, for after DoEditSchedule() returns to normal playing.
     816    /// player bounds, for after DoEditSchedule() returns to normal playing.
    811817    QRect player_bounds;
    812     ///< Prior GUI window bounds, for DoEditSchedule() and player exit().
     818    /// Prior GUI window bounds, for DoEditSchedule() and player exit().
    813819    QRect saved_gui_bounds;
     820    /// true if this instance disabled MythUI drawing.
     821    bool  weDisabledGUI;
    814822
    815823    // embedded status
    816824    bool         isEmbedded;       ///< are we currently embedded
  • libs/libmythtv/tv_play.cpp

     
    834834    InitKeys();
    835835}
    836836
     837
     838class TVInitRunnable : public QRunnable
     839{
     840  public:
     841    TVInitRunnable(TV *ourTV) : tv(ourTV) {}
     842    virtual void run(void) { tv->InitFromDB(); }
     843    TV *tv;
     844};
     845
    837846/** \fn TV::TV(void)
    838  *  \brief Performs instance initialiation not requiring access to database.
    839847 *  \sa Init(void)
    840848 */
    841849TV::TV(void)
     
    907915      // LCD Info
    908916      lcdTitle(""), lcdSubtitle(""), lcdCallsign(""),
    909917      // Window info (GUI is optional, transcoding, preview img, etc)
    910       myWindow(NULL),               isEmbedded(false),
    911       ignoreKeyPresses(false),
     918      myWindow(NULL),               weDisabledGUI(false),
     919      isEmbedded(false),            ignoreKeyPresses(false),
    912920      // Timers
    913921      lcdTimerId(0),                keyListTimerId(0),
    914922      networkControlTimerId(0),     jumpMenuTimerId(0),
     
    927935    setObjectName("TV");
    928936    keyRepeatTimer.start();
    929937
     938    sleep_times.push_back(SleepTimerInfo(QObject::tr("Off"),       0));
     939    sleep_times.push_back(SleepTimerInfo(QObject::tr("30m"),   30*60));
     940    sleep_times.push_back(SleepTimerInfo(QObject::tr("1h"),    60*60));
     941    sleep_times.push_back(SleepTimerInfo(QObject::tr("1h30m"), 90*60));
     942    sleep_times.push_back(SleepTimerInfo(QObject::tr("2h"),   120*60));
     943
     944    playerLock.lockForWrite();
     945    player.push_back(new PlayerContext(kPlayerInUseID));
     946    playerActive = 0;
     947    playerLock.unlock();
     948
     949    QThreadPool::globalInstance()->start(new TVInitRunnable(this), 99);
     950
     951    VERBOSE(VB_PLAYBACK, LOC + "ctor -- end");
     952}
     953
     954void TV::InitFromDB(void)
     955{
    930956    QMap<QString,QString> kv;
    931957    kv["LiveTVIdleTimeout"]        = "0";
    932958    kv["UDPNotifyPort"]            = "0";
     
    10231049
    10241050    vbimode = VBIMode::Parse(!feVBI.isEmpty() ? feVBI : beVBI);
    10251051
    1026     sleep_times.push_back(SleepTimerInfo(QObject::tr("Off"),       0));
    1027     sleep_times.push_back(SleepTimerInfo(QObject::tr("30m"),   30*60));
    1028     sleep_times.push_back(SleepTimerInfo(QObject::tr("1h"),    60*60));
    1029     sleep_times.push_back(SleepTimerInfo(QObject::tr("1h30m"), 90*60));
    1030     sleep_times.push_back(SleepTimerInfo(QObject::tr("2h"),   120*60));
    1031 
    10321052    osdMenuEntries = new TVOSDMenuEntryList();
    10331053
     1054    if (browse_changrp && (channel_group_id > -1))
     1055    {
     1056        m_channellist = ChannelUtil::GetChannels(
     1057            0, true, "channum, callsign", channel_group_id);
     1058        ChannelUtil::SortChannels(m_channellist, "channum", true);
     1059    }
     1060
     1061    m_changrplist  = ChannelGroup::GetChannelGroups();
     1062
    10341063    gCoreContext->addListener(this);
    10351064
    1036     playerLock.lockForWrite();
    1037     player.push_back(new PlayerContext(kPlayerInUseID));
    1038     playerActive = 0;
    1039     playerLock.unlock();
    1040     VERBOSE(VB_PLAYBACK, LOC + "ctor -- end");
     1065    QMutexLocker lock(&initFromDBLock);
     1066    initFromDBDone = true;
     1067    initFromDBWait.wakeAll();
    10411068}
    10421069
    10431070/** \fn TV::Init(bool)
     
    10501077{
    10511078    VERBOSE(VB_PLAYBACK, LOC + "Init -- begin");
    10521079
    1053     if (browse_changrp && (channel_group_id > -1))
    1054     {
    1055       m_channellist = ChannelUtil::GetChannels(0, true, "channum, callsign", channel_group_id);
    1056       ChannelUtil::SortChannels(m_channellist, "channum", true);
    1057     }
    1058 
    1059     m_changrplist  = ChannelGroup::GetChannelGroups();
    1060 
    1061     VERBOSE(VB_PLAYBACK, LOC + "Init -- end channel groups");
    1062 
    10631080    if (createWindow)
    10641081    {
    10651082        bool fullscreen = !gCoreContext->GetNumSetting("GuiSizeForTV", 0);
     
    11371154        }
    11381155
    11391156        MythMainWindow *mainWindow = GetMythMainWindow();
    1140         //QPalette p = mainWindow->palette();
    1141         //p.setColor(mainWindow->backgroundRole(), Qt::black);
    1142         //mainWindow->setPalette(p);
    11431157        mainWindow->installEventFilter(this);
     1158        // get this screen to show on screen immediately..
    11441159        qApp->processEvents();
    11451160    }
    11461161
     1162    {
     1163        VERBOSE(VB_PLAYBACK, LOC + "Init -- waiting on InitFromDB");
     1164        QMutexLocker locker(&initFromDBLock);
     1165        while (!initFromDBDone)
     1166        {
     1167            qApp->processEvents();
     1168            initFromDBWait.wait(&initFromDBLock, 50);
     1169        }
     1170    }
     1171
     1172    VERBOSE(VB_PLAYBACK, LOC + "Init -- starting main loop");
     1173
    11471174    mainLoopCondLock.lock();
    11481175    start();
    11491176    mainLoopCond.wait(&mainLoopCondLock);
     
    11691196
    11701197    gCoreContext->removeListener(this);
    11711198
    1172     GetMythMainWindow()->SetDrawEnabled(true);
     1199    if (GetMythMainWindow() && weDisabledGUI)
     1200        GetMythMainWindow()->PopDrawDisabled(__FILE__, __LINE__);
    11731201
    11741202    if (myWindow)
    11751203    {
     
    19561984
    19571985        VERBOSE(VB_IMPORTANT, "We have a RingBuffer");
    19581986
    1959         GetMythUI()->DisableScreensaver();
    1960         GetMythMainWindow()->SetDrawEnabled(false);
     1987        if (GetMythMainWindow() && !weDisabledGUI)
     1988        {
     1989            weDisabledGUI = true;
     1990            GetMythMainWindow()->PushDrawDisabled(__FILE__, __LINE__);
     1991            DrawUnusedRects();
     1992        }
    19611993
    19621994        if (ctx->playingInfo && StartRecorder(ctx,-1))
    19631995        {
     
    20232055
    20242056        if (ctx->buffer && ctx->buffer->IsOpen())
    20252057        {
    2026             GetMythMainWindow()->SetDrawEnabled(false);
    20272058            GetMythUI()->DisableScreensaver();
    20282059
     2060            if (GetMythMainWindow() && !weDisabledGUI)
     2061            {
     2062                weDisabledGUI = true;
     2063                GetMythMainWindow()->PushDrawDisabled(__FILE__, __LINE__);
     2064                DrawUnusedRects();
     2065            }
     2066
    20292067            if (desiredNextState == kState_WatchingRecording)
    20302068            {
    20312069                ctx->LockPlayingInfo(__FILE__, __LINE__);
     
    76047642
    76057643void TV::DrawUnusedRects(void)
    76067644{
     7645    if (!weDisabledGUI)
     7646        return;
     7647
    76077648    VERBOSE(VB_PLAYBACK, LOC + "DrawUnusedRects() -- begin");
    76087649
    76097650    PlayerContext *mctx = GetPlayerReadLock(0, __FILE__, __LINE__);
     
    77577798        }
    77587799    }
    77597800
    7760     //we are embedding in a mythui window so show the gui paint window again
    7761     GetMythMainWindow()->SetDrawEnabled(true);
     7801    // We are embedding in a mythui window so assuming no one
     7802    // else has disabled painting show the MythUI window again.
     7803    if (GetMythMainWindow() && weDisabledGUI)
     7804    {
     7805        GetMythMainWindow()->PopDrawDisabled(__FILE__, __LINE__);
     7806        weDisabledGUI = false;
     7807    }
    77627808    GetMythMainWindow()->GetPaintWindow()->show();
    77637809}
    77647810
     
    84378483    if (message.left(11) == "EPG_EXITING" ||
    84388484        message.left(18) == "PROGFINDER_EXITING" ||
    84398485        message.left(21) == "VIEWSCHEDULED_EXITING" ||
    8440         message.left(19)   == "PLAYBACKBOX_EXITING" ||
     8486        message.left(19) == "PLAYBACKBOX_EXITING" ||
    84418487        message.left(22) == "SCHEDULEEDITOR_EXITING")
    84428488    {
    8443         GetMythMainWindow()->SetDrawEnabled(false);
    84448489        // Resize the window back to the MythTV Player size
    84458490        PlayerContext *actx = GetPlayerReadLock(-1, __FILE__, __LINE__);
    84468491        PlayerContext *mctx;
     
    84698514        GetMythMainWindow()->GetPaintWindow()->clearMask();
    84708515
    84718516        qApp->processEvents();
    8472         DrawUnusedRects();
    84738517
     8518        if (!weDisabledGUI)
     8519        {
     8520            weDisabledGUI = true;
     8521            GetMythMainWindow()->PushDrawDisabled(__FILE__, __LINE__);
     8522            DrawUnusedRects();
     8523        }
     8524
    84748525        isEmbedded = false;
    84758526        ignoreKeyPresses = false;
    84768527
  • libs/libmythtv/videooutbase.cpp

     
    15461546
    15471547void VideoOutput::ExposeEvent(void)
    15481548{
     1549    VERBOSE(VB_IMPORTANT, "VideoOutput::ExposeEvent()");
    15491550    windows[0].SetNeedRepaint(true);
    15501551}
    15511552
  • libs/libmythui/mythmainwindow.cpp

     
    1515#include <QGLWidget>
    1616#endif
    1717
     18#include <QWaitCondition>
    1819#include <QApplication>
    1920#include <QTimer>
    2021#include <QDesktopWidget>
     
    7576
    7677#define GESTURE_TIMEOUT 1000
    7778
     79#define LOC      QString("MythMainWindow: ")
     80#define LOC_WARN QString("MythMainWindow, Warning: ")
     81#define LOC_ERR  QString("MythMainWindow, Error: ")
     82
    7883class KeyContext
    7984{
    8085  public:
     
    113118class MythMainWindowPrivate
    114119{
    115120  public:
     121    MythMainWindowPrivate() :
     122        wmult(1.0f), hmult(1.0f),
     123        screenwidth(0), screenheight(0),
     124        xbase(0), ybase(0),
     125        does_fill_screen(false),
     126        ignore_lirc_keys(false),
     127        ignore_joystick_keys(false),
     128        lircThread(NULL),
     129#ifdef USE_JOYSTICK_MENU
     130        joystickThread(NULL),
     131#endif
     132
     133#ifdef USING_APPLEREMOTE
     134        appleRemoteListener(NULL),
     135        appleRemote(NULL),
     136#endif
     137        exitingtomain(false),
     138        popwindows(false),
     139
     140        m_useDB(true),
     141
     142        exitmenucallback(NULL),
     143
     144        exitmenumediadevicecallback(NULL),
     145        mediadeviceforcallback(NULL),
     146
     147        escapekey(0),
     148
     149        sysEventHandler(NULL),
     150
     151        drawTimer(NULL),
     152        mainStack(NULL),
     153
     154        painter(NULL),
     155
     156#ifdef USE_OPENGL_PAINTER
     157        render(NULL),
     158#endif
     159
     160        AllowInput(true),
     161
     162        gestureTimer(NULL),
     163
     164        paintwin(NULL),
     165
     166        oldpaintwin(NULL),
     167        oldpainter(NULL),
     168
     169        m_drawDisabledDepth(0),
     170        m_drawEnabled(true)
     171    {
     172    }
     173
    116174    int TranslateKeyNum(QKeyEvent *e);
    117175
    118176    float wmult, hmult;
     
    182240    QWidget *oldpaintwin;
    183241    MythPainter *oldpainter;
    184242
    185     volatile bool m_drawEnabled;
     243    QMutex m_drawDisableLock;
     244    QMutex m_setDrawEnabledLock;
     245    QWaitCondition m_setDrawEnabledWait;
     246    uint m_drawDisabledDepth;
     247    bool m_drawEnabled;
    186248};
    187249
    188250// Make keynum in QKeyEvent be equivalent to what's in QKeySequence
     
    11141176}
    11151177/* FIXME: end compatibility */
    11161178
     1179uint MythMainWindow::PushDrawDisabled(const char *file, int line)
     1180{
     1181    QMutexLocker locker(&d->m_drawDisableLock);
     1182    VERBOSE(VB_IMPORTANT, QString("PushDrawDisabled(%1@%2) -- begin")
     1183            .arg(file).arg(line));
     1184    d->m_drawDisabledDepth++;
     1185    if (d->m_drawDisabledDepth && d->m_drawEnabled)
     1186        SetDrawEnabled(false);
     1187    VERBOSE(VB_IMPORTANT, QString("PushDrawDisabled(%1@%2) -- end")
     1188            .arg(file).arg(line));
     1189    return d->m_drawDisabledDepth;
     1190}
     1191
     1192uint MythMainWindow::PopDrawDisabled(const char *file, int line)
     1193{
     1194    QMutexLocker locker(&d->m_drawDisableLock);
     1195    VERBOSE(VB_IMPORTANT, QString("PopDrawDisabled(%1@%2) -- begin")
     1196            .arg(file).arg(line));
     1197    if (d->m_drawDisabledDepth)
     1198    {
     1199        d->m_drawDisabledDepth--;
     1200        if (!d->m_drawDisabledDepth && !d->m_drawEnabled)
     1201            SetDrawEnabled(true);
     1202    }
     1203    VERBOSE(VB_IMPORTANT, QString("PopDrawDisabled(%1@%2) -- end")
     1204            .arg(file).arg(line));
     1205    return d->m_drawDisabledDepth;
     1206}
     1207
    11171208void MythMainWindow::SetDrawEnabled(bool enable)
    11181209{
     1210    QMutexLocker locker(&d->m_setDrawEnabledLock);
     1211
     1212    if (!gCoreContext->IsUIThread())
     1213    {
     1214        VERBOSE(VB_IMPORTANT, LOC + QString("SetDrawEnabled(%1) -- outside UI")
     1215                .arg(enable));
     1216
     1217        QCoreApplication::postEvent(
     1218            this, new MythEvent(
     1219                (enable) ?
     1220                MythEvent::kSetDrawEnabledEventType :
     1221                MythEvent::kSetDrawDisabledEventType));
     1222
     1223        VERBOSE(VB_IMPORTANT, LOC + QString("SetDrawEnabled(%1) -- waiting")
     1224                .arg(enable));
     1225
     1226        while (QCoreApplication::hasPendingEvents())
     1227            d->m_setDrawEnabledWait.wait(&d->m_setDrawEnabledLock);
     1228
     1229        VERBOSE(VB_IMPORTANT, LOC + QString("SetDrawEnabled(%1) -- done")
     1230                .arg(enable));
     1231
     1232        return;
     1233    }
     1234
     1235    static uint ecnt = 0, dcnt = 0;
     1236    ecnt += enable ? 1 : 0;
     1237    dcnt += enable ? 0 : 1;
     1238
     1239    VERBOSE(VB_IMPORTANT, LOC + QString("SetDrawEnabled(%1) cnt %2")
     1240            .arg(enable).arg(enable?ecnt:dcnt));
     1241
    11191242    setUpdatesEnabled(enable);
    11201243    d->m_drawEnabled = enable;
    11211244
     
    11231246        d->drawTimer->start(1000 / 70);
    11241247    else
    11251248        d->drawTimer->stop();
     1249
     1250    d->m_setDrawEnabledWait.wakeAll();
    11261251}
    11271252
    11281253void MythMainWindow::SetEffectsEnabled(bool enable)
     
    19262051            }
    19272052        }
    19282053    }
    1929     else if (ce->type() == MythEvent::kDisableDrawingEventType)
     2054    else if (ce->type() == MythEvent::kPushDisableDrawingEventType)
    19302055    {
    1931         SetDrawEnabled(false);
     2056        PushDrawDisabled(__FILE__, __LINE__);
    19322057    }
    1933     else if (ce->type() == MythEvent::kEnableDrawingEventType)
     2058    else if (ce->type() == MythEvent::kPopDisableDrawingEventType)
    19342059    {
     2060        PopDrawDisabled(__FILE__, __LINE__);
     2061    }
     2062    else if (ce->type() == MythEvent::kSetDrawEnabledEventType)
     2063    {
     2064        VERBOSE(VB_IMPORTANT, LOC + "kSetDrawEnabledEvent");
    19352065        SetDrawEnabled(true);
    19362066    }
     2067    else if (ce->type() == MythEvent::kSetDrawDisabledEventType)
     2068    {
     2069        VERBOSE(VB_IMPORTANT, LOC + "kSetDrawDisabledEvent");
     2070        SetDrawEnabled(false);
     2071    }
    19372072    else if ((MythEvent::Type)(ce->type()) == MythEvent::MythEventMessage)
    19382073    {
    19392074        MythEvent *me = (MythEvent *)ce;
  • libs/libmythui/mythmainwindow.h

     
    113113
    114114    QWidget *currentWidget(void);
    115115
    116     void SetDrawEnabled(bool enable);
     116    uint PushDrawDisabled(const char *file, int line);
     117    uint PopDrawDisabled(const char *file, int line);
    117118    void SetEffectsEnabled(bool enable);
    118119
    119120  public slots:
     
    140141
    141142    QObject *getTarget(QKeyEvent &key);
    142143
     144    void SetDrawEnabled(bool enable);
     145
    143146    MythMainWindowPrivate *d;
    144147};
    145148
  • libs/libmyth/util.cpp

     
    12771277#endif
    12781278    bool res = myth_system(command,
    12791279                           MYTH_SYSTEM_DONT_BLOCK_LIRC |
    1280                            MYTH_SYSTEM_DONT_BLOCK_JOYSTICK_MENU |
    1281                            MYTH_SYSTEM_DONT_BLOCK_PARENT);
     1280                           MYTH_SYSTEM_DONT_BLOCK_JOYSTICK_MENU);
    12821281    return !res;
    12831282}
    12841283
  • libs/libmythdb/mythsystem.cpp

     
    8080    // since this function could be called inside one of those events.
    8181    if (ready_to_lock && !(flags & MYTH_SYSTEM_DONT_BLOCK_PARENT))
    8282    {
    83         QEvent event(MythEvent::kDisableDrawingEventType);
     83        QEvent event(MythEvent::kPushDisableDrawingEventType);
    8484        QCoreApplication::sendEvent(gCoreContext->GetGUIObject(), &event);
    8585    }
    8686
     
    216216    // since this function could be called inside one of those events.
    217217    if (ready_to_lock && !(flags & MYTH_SYSTEM_DONT_BLOCK_PARENT))
    218218    {
    219         QEvent event(MythEvent::kEnableDrawingEventType);
     219        QEvent event(MythEvent::kPopDisableDrawingEventType);
    220220        QCoreApplication::sendEvent(gCoreContext->GetGUIObject(), &event);
    221221    }
    222222
  • libs/libmythdb/mythevent.h

     
    5252    static Type MythEventMessage;
    5353    static Type kExitToMainMenuEventType;
    5454    static Type kMythPostShowEventType;
    55     static Type kDisableDrawingEventType;
    56     static Type kEnableDrawingEventType;
     55    static Type kPushDisableDrawingEventType;
     56    static Type kPopDisableDrawingEventType;
     57    static Type kSetDrawEnabledEventType;
     58    static Type kSetDrawDisabledEventType;
    5759
    5860  private:
    5961    QString message;
  • libs/libmythdb/mythevent.cpp

     
    66    (QEvent::Type) QEvent::registerEventType();
    77QEvent::Type MythEvent::kMythPostShowEventType =
    88    (QEvent::Type) QEvent::registerEventType();
    9 QEvent::Type MythEvent::kDisableDrawingEventType =
     9QEvent::Type MythEvent::kPushDisableDrawingEventType =
    1010    (QEvent::Type) QEvent::registerEventType();
    11 QEvent::Type MythEvent::kEnableDrawingEventType =
     11QEvent::Type MythEvent::kPopDisableDrawingEventType =
    1212    (QEvent::Type) QEvent::registerEventType();
     13QEvent::Type MythEvent::kSetDrawEnabledEventType =
     14    (QEvent::Type) QEvent::registerEventType();
     15QEvent::Type MythEvent::kSetDrawDisabledEventType =
     16    (QEvent::Type) QEvent::registerEventType();
    1317QEvent::Type ExternalKeycodeEvent::kEventType =
    1418    (QEvent::Type) QEvent::registerEventType();