Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Don't create an additional thread for media playback.

After the threading changes prior to the 0.24 release, this extra thread
serves no purpose and is slowing down both startup and exiting of video
playback. It may also have an impact on sluggish keypress responses
reported by several people.

There are various cleanups that can now be made in the TV class.
  • Loading branch information...
commit 3429e9b27366503e731f138e2bac1fcfc0c58a72 1 parent 5b7b93d
authored December 08, 2010
78  mythtv/libs/libmythtv/tv_play.cpp
@@ -845,14 +845,6 @@ void TV::ResetKeys(void)
845 845
 }
846 846
 
847 847
 
848  
-class TVInitRunnable : public QRunnable
849  
-{
850  
-  public:
851  
-    TVInitRunnable(TV *ourTV) : tv(ourTV) {}
852  
-    virtual void run(void) { tv->InitFromDB(); }
853  
-    TV *tv;
854  
-};
855  
-
856 848
 /** \fn TV::TV(void)
857 849
  *  \sa Init(void)
858 850
  */
@@ -954,7 +946,7 @@ TV::TV(void)
954 946
     playerActive = 0;
955 947
     playerLock.unlock();
956 948
 
957  
-    QThreadPool::globalInstance()->start(new TVInitRunnable(this), 99);
  949
+    InitFromDB();
958 950
 
959 951
     VERBOSE(VB_PLAYBACK, LOC + "ctor -- end");
960 952
 }
@@ -1181,15 +1173,29 @@ bool TV::Init(bool createWindow)
1181 1173
         }
1182 1174
     }
1183 1175
 
1184  
-    mainLoopCondLock.lock();
1185  
-    start();
1186  
-    mainLoopCond.wait(&mainLoopCondLock);
  1176
+    PlayerContext *mctx = GetPlayerReadLock(0, __FILE__, __LINE__);
  1177
+    mctx->paused = false;
  1178
+    mctx->ff_rew_state = 0;
  1179
+    mctx->ff_rew_index = kInitFFRWSpeed;
  1180
+    mctx->ff_rew_speed = 0;
  1181
+    mctx->ts_normal    = 1.0f;
  1182
+    ReturnPlayerLock(mctx);
  1183
+
  1184
+    sleep_index = 0;
  1185
+
  1186
+    SetUpdateOSDPosition(false);
  1187
+
  1188
+    const PlayerContext *ctx = GetPlayerReadLock(0, __FILE__, __LINE__);
  1189
+    ClearInputQueues(ctx, false);
  1190
+    ReturnPlayerLock(ctx);
  1191
+
  1192
+    switchToRec = NULL;
  1193
+    SetExitPlayer(false, false);
  1194
+
1187 1195
     errorRecoveryTimerId = StartTimer(kErrorRecoveryCheckFrequency, __LINE__);
1188 1196
     lcdTimerId           = StartTimer(1, __LINE__);
1189 1197
     speedChangeTimerId   = StartTimer(kSpeedChangeCheckFrequency, __LINE__);
1190 1198
 
1191  
-    mainLoopCondLock.unlock();
1192  
-
1193 1199
     VERBOSE(VB_PLAYBACK, LOC + "Init -- end");
1194 1200
     return true;
1195 1201
 }
@@ -1218,9 +1224,6 @@ TV::~TV(void)
1218 1224
         myWindow = NULL;
1219 1225
     }
1220 1226
 
1221  
-    TV::exit(0);
1222  
-    TV::wait();
1223  
-
1224 1227
     VERBOSE(VB_PLAYBACK, "TV::~TV() -- lock");
1225 1228
 
1226 1229
     // restore window to gui size and position
@@ -2453,44 +2456,6 @@ void TV::TeardownPlayer(PlayerContext *mctx, PlayerContext *ctx)
2453 2456
     }
2454 2457
 }
2455 2458
 
2456  
-void TV::run(void)
2457  
-{
2458  
-    PlayerContext *mctx = GetPlayerReadLock(0, __FILE__, __LINE__);
2459  
-    mctx->paused = false;
2460  
-    mctx->ff_rew_state = 0;
2461  
-    mctx->ff_rew_index = kInitFFRWSpeed;
2462  
-    mctx->ff_rew_speed = 0;
2463  
-    mctx->ts_normal    = 1.0f;
2464  
-    ReturnPlayerLock(mctx);
2465  
-
2466  
-    sleep_index = 0;
2467  
-
2468  
-    SetUpdateOSDPosition(false);
2469  
-
2470  
-    const PlayerContext *ctx = GetPlayerReadLock(0, __FILE__, __LINE__);
2471  
-    ClearInputQueues(ctx, false);
2472  
-    ReturnPlayerLock(ctx);
2473  
-
2474  
-    switchToRec = NULL;
2475  
-    SetExitPlayer(false, false);
2476  
-
2477  
-    mainLoopCondLock.lock();
2478  
-    mainLoopCond.wakeAll();
2479  
-    mainLoopCondLock.unlock();
2480  
-
2481  
-    exec();
2482  
-
2483  
-    mctx = GetPlayerWriteLock(0, __FILE__, __LINE__);
2484  
-    if (!mctx->IsErrored() && (GetState(mctx) != kState_None))
2485  
-    {
2486  
-        mctx->ForceNextStateNone();
2487  
-        HandleStateChange(mctx, mctx);
2488  
-        if (jumpToProgram)
2489  
-            TeardownPlayer(mctx, mctx);
2490  
-    }
2491  
-    ReturnPlayerLock(mctx);
2492  
-}
2493  
-
2494 2459
 void TV::timerEvent(QTimerEvent *te)
2495 2460
 {
2496 2461
     const int timer_id = te->timerId();
@@ -2499,7 +2464,6 @@ void TV::timerEvent(QTimerEvent *te)
2499 2464
     if (mctx->IsErrored())
2500 2465
     {
2501 2466
         ReturnPlayerLock(mctx);
2502  
-        QThread::exit(1);
2503 2467
         return;
2504 2468
     }
2505 2469
     ReturnPlayerLock(mctx);
@@ -3465,7 +3429,7 @@ bool TV::event(QEvent *e)
3465 3429
             break;
3466 3430
     }
3467 3431
 
3468  
-    return QThread::event(e);
  3432
+    return QObject::event(e);
3469 3433
 }
3470 3434
 
3471 3435
 bool TV::HandleTrackAction(PlayerContext *ctx, const QString &action)
11  mythtv/libs/libmythtv/tv_play.h
@@ -164,9 +164,8 @@ class AskProgramInfo
164 164
     ProgramInfo *info;
165 165
 };
166 166
 
167  
-class MPUBLIC TV : public QThread
  167
+class MPUBLIC TV : public QObject
168 168
 {
169  
-    friend class QTVEventThread;
170 169
     friend class PlaybackBox;
171 170
     friend class GuideGrid;
172 171
     friend class TvPlayWindow;
@@ -233,9 +232,6 @@ class MPUBLIC TV : public QThread
233 232
     // Boolean queries
234 233
     /// Returns true if we are currently in the process of switching recorders.
235 234
     bool IsSwitchingCards(void)  const { return switchToRec; }
236  
-    /// Returns true if the TV event thread is running. Should always be true
237  
-    /// between the end of the constructor and the beginning of the destructor.
238  
-    bool IsRunning(void)         const { return isRunning(); }
239 235
     /// Returns true if the user told Mythtv to allow re-recording of the show
240 236
     bool getAllowRerecord(void) const { return allowRerecord;  }
241 237
     /// This is set to true if the player reaches the end of the
@@ -298,7 +294,6 @@ class MPUBLIC TV : public QThread
298 294
 
299 295
     void DoEditSchedule(int editType = kScheduleProgramGuide);
300 296
 
301  
-    virtual void run(void);
302 297
     void TVEventThreadChecks(void);
303 298
 
304 299
     void PauseAudioUntilBuffered(PlayerContext *ctx);
@@ -861,10 +856,6 @@ class MPUBLIC TV : public QThread
861 856
     TimerContextMap      signalMonitorTimerId;
862 857
     TimerContextMap      tvchainUpdateTimerId;
863 858
 
864  
-    /// Condition to signal that the Event thread is up and running
865  
-    QWaitCondition mainLoopCond;
866  
-    QMutex mainLoopCondLock;
867  
-
868 859
     /// Condition to signal State changes
869 860
     QWaitCondition stateChangeCond;
870 861
     QMutex stateChangeCondLock;
7  mythtv/programs/mythfrontend/guidegrid.cpp
@@ -264,9 +264,6 @@ GuideGrid::GuideGrid(MythScreenStack *parent,
264 264
     m_currentStartTime = m_originalStartTime.addSecs(secsoffset);
265 265
     m_startChanID  = chanid;
266 266
     m_startChanNum = channum;
267  
-
268  
-    if (m_player)
269  
-        m_embedVideo = m_player->IsRunning() && m_embedVideo;
270 267
 }
271 268
 
272 269
 bool GuideGrid::Create()
@@ -2200,7 +2197,7 @@ void GuideGrid::EmbedTVWindow(void)
2200 2197
 
2201 2198
 void GuideGrid::refreshVideo(void)
2202 2199
 {
2203  
-    if (m_player && m_player->IsRunning() && m_usingNullVideo)
  2200
+    if (m_player && m_usingNullVideo)
2204 2201
     {
2205 2202
         GetMythMainWindow()->GetPaintWindow()->update(m_videoRect);
2206 2203
     }
@@ -2216,7 +2213,7 @@ void GuideGrid::aboutToHide(void)
2216 2213
 
2217 2214
 void GuideGrid::aboutToShow(void)
2218 2215
 {
2219  
-    if (m_player && m_player->IsRunning())
  2216
+    if (m_player)
2220 2217
         EmbedTVWindow();
2221 2218
 
2222 2219
     MythScreenType::aboutToShow();

0 notes on commit 3429e9b

Please sign in to comment.
Something went wrong with that request. Please try again.