[mythtv] "The fallacy that is: spawning a decoder thread
willalways result in playing" or "Hurry up and wait"
Anduin Withers
awithers at anduin.com
Thu Aug 7 21:24:08 EDT 2003
> or introduce an error condition variable to dump it out of that loop
I tried a variant of that my first attempt. I'm attaching a patch that works
for me (no new breakage that I can detect).
Note: I only patched the one case I care about, the hopeful spinning idle
loop idiom seems pretty entrenched in other places as well (though mostly
with less dire results).
--
Anduin Withers
-------------- next part --------------
Index: NuppelVideoPlayer.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/NuppelVideoPlayer.cpp,v
retrieving revision 1.245
diff -u -r1.245 NuppelVideoPlayer.cpp
--- NuppelVideoPlayer.cpp 7 Aug 2003 17:37:41 -0000 1.245
+++ NuppelVideoPlayer.cpp 8 Aug 2003 02:56:09 -0000
@@ -55,6 +55,7 @@
m_playbackinfo = new ProgramInfo(*info);
playing = false;
+ decoder_thread_alive = false;
filename = "output.nuv";
prebuffering = false;
Index: NuppelVideoPlayer.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/NuppelVideoPlayer.h,v
retrieving revision 1.104
diff -u -r1.104 NuppelVideoPlayer.h
--- NuppelVideoPlayer.h 6 Aug 2003 17:35:48 -0000 1.104
+++ NuppelVideoPlayer.h 8 Aug 2003 02:56:09 -0000
@@ -66,6 +66,14 @@
bool IsPlaying(void) { return playing; }
+ // Calling this function _before_ spawning a decoder thread
+ // will allow you to check if that thread is still running.
+ void StartingDecoderThread() { decoder_thread_alive = true; }
+ // Only useful if you call StartingDecoderThread
+ bool IsDecoderThreadAlive() { return decoder_thread_alive; }
+ // Must be called from the thread context when it is exiting.
+ void DecoderThreadExit() { decoder_thread_alive = false; }
+
void SetRingBuffer(RingBuffer *rbuf) { ringBuffer = rbuf; }
void SetAudioSampleRate(int rate) { audio_samplerate = rate; }
@@ -296,6 +304,8 @@
bool cc;
bool playing;
+
+ bool decoder_thread_alive;
RingBuffer *ringBuffer;
bool weMadeBuffer;
Index: tv_play.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/tv_play.cpp,v
retrieving revision 1.89
diff -u -r1.89 tv_play.cpp
--- tv_play.cpp 5 Aug 2003 21:10:58 -0000 1.89
+++ tv_play.cpp 8 Aug 2003 02:56:11 -0000
@@ -65,6 +65,8 @@
{
NuppelVideoPlayer *nvp = (NuppelVideoPlayer *)param;
nvp->StartPlaying();
+ nvp->StopPlaying();
+ nvp->DecoderThreadExit();
return NULL;
}
@@ -496,9 +498,10 @@
if (startPlayer)
{
SetupPlayer();
+ nvp->StartingDecoderThread();
pthread_create(&decode, NULL, SpawnDecode, nvp);
- while (!nvp->IsPlaying())
+ while (!nvp->IsPlaying() && nvp->IsDecoderThreadAlive())
usleep(50);
activenvp = nvp;
More information about the mythtv-dev
mailing list