From f06369efd6c356f2f681f1d293658719350644f5 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sun, 2 Dec 2007 18:01:22 +0000 Subject: [PATCH] Live TV updates --- afeed.cc | 4 +- demuxer.cc | 3 + playerlivetv.cc | 166 +++++++++++++++++++++++++----------------------- playerlivetv.h | 11 ++-- vfeed.cc | 2 + 5 files changed, 96 insertions(+), 90 deletions(-) diff --git a/afeed.cc b/afeed.cc index 5b8dce9..7efcffd 100644 --- a/afeed.cc +++ b/afeed.cc @@ -76,14 +76,12 @@ void AFeed::threadMethod() if (alen) { -// Log::getInstance()->log("AFeed", Log::DEBUG, "Written %i", alen); cb.call(this); } else { -// Log::getInstance()->log("AFeed", Log::DEBUG, "No data delay"); //MILLISLEEP(100); - MILLISLEEP(20); //Performance Issue Marten + MILLISLEEP(20); //Performance Issue Marten } } else diff --git a/demuxer.cc b/demuxer.cc index b9ec4ab..1443b7b 100644 --- a/demuxer.cc +++ b/demuxer.cc @@ -179,6 +179,7 @@ int Demuxer::init(Callback* tcallback, DrainTarget* audio, DrainTarget* video, U void Demuxer::reset() { + Log::getInstance()->log("Demuxer", Log::DEBUG, "Reset called"); flush(); video_current = audio_current = -1; horizontal_size = vertical_size = 0; @@ -206,6 +207,8 @@ int Demuxer::shutdown() void Demuxer::flush() { + Log::getInstance()->log("Demuxer", Log::DEBUG, "Flush called"); + videostream.flush(); audiostream.flush(); } diff --git a/playerlivetv.cc b/playerlivetv.cc index c88d056..22a10fb 100644 --- a/playerlivetv.cc +++ b/playerlivetv.cc @@ -45,8 +45,7 @@ PlayerLiveTV::PlayerLiveTV(MessageQueue* tmessageQueue, void* tmessageReceiver, vdr = VDR::getInstance(); initted = false; -// videoStartup = false; -// preBuffering = false; + videoStartup = false; stopNow = false; state = 1; @@ -127,42 +126,27 @@ void PlayerLiveTV::go(ULONG index) i.instruction = 1; i.channelIndex = index; instructions.push(i); - threadStart(); } void PlayerLiveTV::setChannel(ULONG index) { -// demuxer->setVID(Vpid); -// demuxer->setAID(Apid); -// play(); logger->log("PlayerLiveTV", Log::DEBUG, "setChannel"); - struct PLTVInstruction i; i.instruction = 1; i.channelIndex = index; instructions.push(i); - threadSignalNoLock(); } void PlayerLiveTV::stop() { logger->log("PlayerLiveTV", Log::DEBUG, "stop"); - struct PLTVInstruction i; i.instruction = 2; instructions.push(i); - - logger->log("PlayerLiveTV", Log::DEBUG, "Pushed instruction"); - threadSignal(); - - logger->log("PlayerLiveTV", Log::DEBUG, "Signal sent"); - threadStop(); - - logger->log("PlayerLiveTV", Log::DEBUG, "Stop returning"); } // ----------------------------------- Callback @@ -208,22 +192,37 @@ void PlayerLiveTV::call(void* caller) { logger->log("PlayerLiveTV", Log::DEBUG, "Demuxer said video is something else... ignoring"); } - } - else + else if (caller == &afeed) { - if (videoStartup) + if (state == S_VIDEOSTARTUP) { - logger->log("PlayerLiveTV", Log::DEBUG, "Video startup"); - videoStartup = false; - video->reset(); - video->play(); - video->sync(); - vfeed.release(); + logger->log("PlayerLiveTV", Log::DEBUG, "afeed video startup"); + videoStartup = true; + threadSignalNoLock(); + } + } + /* + else if (caller == &vfeed) + { + if (videoStartup2) + { + logger->log("PlayerLiveTV", Log::DEBUG, "Video startup %i", videoStartup2count); + + if (++videoStartup2count == 2) + { + videoStartup2 = false; + + video->unPause(); + audio->unPause(); + + audio->systemMuteOff(); + } } threadSignalNoLock(); } +*/ } // ----------------------------------- @@ -266,7 +265,8 @@ void PlayerLiveTV::chunkToDemuxer() StreamChunk s = streamChunks.front(); streamChunks.pop(); logger->log("PlayerLiveTV", Log::DEBUG, "About to call demuxer with %p %lu", s.data, s.len); - demuxer->put((UCHAR*)s.data, s.len); + int a = demuxer->put((UCHAR*)s.data, s.len); + logger->log("PlayerLiveTV", Log::DEBUG, "put %i to demuxer", a); free(s.data); } @@ -280,20 +280,22 @@ void PlayerLiveTV::switchState(UCHAR newState) { switch(newState) { - case S_STOP: - { - abort(); - } case S_PREBUFFERING: { - break; - } - case S_PLAY: - { - abort(); + video->blank(); + audio->stop(); + audio->unPause(); + audio->reset(); + + audio->setStreamType(Audio::MPEG2_PES); + audio->systemMuteOff(); + video->reset(); + demuxer->reset(); + demuxer->seek(); + state = newState; + return; } } - break; } case S_PREBUFFERING: // FROM S_PREBUFFERING @@ -304,35 +306,48 @@ void PlayerLiveTV::switchState(UCHAR newState) { vdr->stopStreaming(); clearStreamChunks(); - break; + state = newState; + return; } case S_PREBUFFERING: { vdr->stopStreaming(); clearStreamChunks(); - break; + state = newState; + return; } - case S_PLAY: + case S_VIDEOSTARTUP: { - videoStartup = true; + logger->log("PlayerLiveTV", Log::DEBUG, "doing ss to videostartup"); - audio->reset(); - audio->setStreamType(Audio::MPEG2_PES); - audio->systemMuteOff(); - video->reset(); - demuxer->reset(); - demuxer->seek(); - audio->sync(); audio->play(); + //audio->systemMuteOn(); video->sync(); video->pause(); afeed.start(); vfeed.start(); - break; + state = newState; + return; + } + } + } + + case S_VIDEOSTARTUP: // FROM S_VIDEOSTARTUP + { + switch(newState) + { + case S_PLAY: + { + logger->log("PlayerLiveTV", Log::DEBUG, "doing ss to play"); + video->reset(); + video->play(); + video->sync(); + vfeed.release(); + state = newState; + return; } } - break; } case S_PLAY: // FROM S_PLAY @@ -349,8 +364,10 @@ void PlayerLiveTV::switchState(UCHAR newState) video->blank(); audio->stop(); audio->unPause(); + audio->reset(); video->reset(); - break; + state = newState; + return; } case S_PREBUFFERING: { @@ -362,20 +379,22 @@ void PlayerLiveTV::switchState(UCHAR newState) video->blank(); audio->stop(); audio->unPause(); + audio->reset(); + + audio->setStreamType(Audio::MPEG2_PES); + // audio->systemMuteOn(); video->reset(); demuxer->reset(); - break; - } - case S_PLAY: - { - abort(); + demuxer->seek(); + state = newState; + return; } } - break; } } - state = newState; + logger->log("PlayerLiveTV", Log::EMERG, "Thread called state %u to state %u which is not supported", state, newState); + abort(); } void PlayerLiveTV::threadMethod() @@ -384,6 +403,12 @@ void PlayerLiveTV::threadMethod() while(1) { + if (videoStartup) // we are in S_VIDEOSTARTUP, afeed has signalled that it has written some data + { + switchState(S_PLAY); + videoStartup = false; + } + while(!instructions.empty()) { struct PLTVInstruction i = instructions.front(); @@ -422,13 +447,13 @@ void PlayerLiveTV::threadMethod() { if (state == S_PREBUFFERING) { - if (streamChunks.size() > 4) + if (streamChunks.size() > 9) { while(streamChunks.size()) chunkToDemuxer(); - switchState(S_PLAY); + switchState(S_VIDEOSTARTUP); } } - else if (state == S_PLAY) + else if (state == S_PLAY || state == S_VIDEOSTARTUP) { while(streamChunks.size()) chunkToDemuxer(); } @@ -444,22 +469,3 @@ void PlayerLiveTV::threadMethod() logger->log("PlayerLiveTV", Log::DEBUG, "End of thread"); } -void PlayerLiveTV::threadPostStopCleanup() -{ - logger->log("PlayerLiveTV", Log::DEBUG, "Post stop cleanup"); -} - -// ----------------------------------- Dev - -#ifdef DEV -void PlayerLiveTV::test1() -{ - logger->log("PlayerLiveTV", Log::DEBUG, "PLAYER TEST 1"); -} - -void PlayerLiveTV::test2() -{ - logger->log("PlayerLiveTV", Log::DEBUG, "PLAYER TEST 2"); -} -#endif - diff --git a/playerlivetv.h b/playerlivetv.h index 21a214e..ef28aa5 100644 --- a/playerlivetv.h +++ b/playerlivetv.h @@ -92,14 +92,9 @@ class PlayerLiveTV : public Thread_TYPE, public Callback, public StreamReceiver const static UCHAR ASPECT43 = 4; const static UCHAR ASPECT169 = 5; -#ifdef DEV - void test1(); - void test2(); -#endif - protected: void threadMethod(); - void threadPostStopCleanup(); + void threadPostStopCleanup() {}; private: @@ -122,11 +117,13 @@ class PlayerLiveTV : public Thread_TYPE, public Callback, public StreamReceiver UCHAR state; const static UCHAR S_STOP = 1; const static UCHAR S_PREBUFFERING = 2; - const static UCHAR S_PLAY = 3; + const static UCHAR S_VIDEOSTARTUP = 3; + const static UCHAR S_PLAY = 4; void switchState(UCHAR newState); bool videoStartup; bool stopNow; + void clearStreamChunks(); void chunkToDemuxer(); diff --git a/vfeed.cc b/vfeed.cc index c4409be..f08cc4b 100644 --- a/vfeed.cc +++ b/vfeed.cc @@ -59,7 +59,9 @@ void VFeed::threadMethod() { bool vlen; + Log::getInstance()->log("VFeed", Log::DEBUG, "Started"); threadWaitForSignal(); // Don't feed video until audio has started + Log::getInstance()->log("VFeed", Log::DEBUG, "Released"); while(1) { -- 2.39.2