From 33a1c0c796a66b0294cffe526cb70f4dcfd4b588 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sun, 12 Mar 2006 22:13:08 +0000 Subject: [PATCH] Connection failure detection --- player.cc | 26 ++++++++++++++------------ player.h | 1 + vepg.cc | 37 ++++++++++++++++++++++++------------- vlivebanner.cc | 2 -- voptions.cc | 2 ++ voptions.h | 1 + voptionsmenu.cc | 2 ++ vvideolive.cc | 2 ++ vvideorec.cc | 1 + 9 files changed, 47 insertions(+), 27 deletions(-) diff --git a/player.cc b/player.cc index a48f557..c0893af 100644 --- a/player.cc +++ b/player.cc @@ -281,6 +281,7 @@ void Player::skipForward(int seconds) ULONG wantedFrameNumber = video->timecodeToFrameNumber(getPositionTS() + (seconds * 90000)); ULLONG newPosition = VDR::getInstance()->positionFromFrameNumber(wantedFrameNumber); + if (!VDR::getInstance()->isConnected()) { doConnectionLost(); return; } logger->log("Player", Log::DEBUG, "wantedframe %i feedpos %llu goto %llu", wantedFrameNumber, feedPosition, newPosition); vfeed.stop(); @@ -316,6 +317,7 @@ void Player::skipBackward(int seconds) { ULONG wantedFrameNumber = video->timecodeToFrameNumber((ULLONG)newTimeCode); newPosition = VDR::getInstance()->positionFromFrameNumber(wantedFrameNumber); + if (!VDR::getInstance()->isConnected()) { doConnectionLost(); return; } logger->log("Player", Log::DEBUG, "wantedframe %i feedpos %llu goto %llu", wantedFrameNumber, feedPosition, newPosition); } @@ -505,6 +507,14 @@ void Player::call(void* caller) } } +void Player::doConnectionLost() +{ + Message* m = new Message(); + m->message = Message::CONNECTION_LOST; + m->to = this; + commandMessageQueue->postMessage(m); +} + // Feed thread void Player::threadMethod() @@ -528,14 +538,7 @@ void Player::threadMethod() if (isRecording && ((lastRescan + 60) < time(NULL))) { streamLength = vdr->rescanRecording(); - if (!vdr->isConnected()) - { - Message* m = new Message(); - m->message = Message::CONNECTION_LOST; - m->to = this; - commandMessageQueue->postMessage(m); - return; - } + if (!vdr->isConnected()) { doConnectionLost(); return; } logger->log("Player", Log::DEBUG, "Rescanned and reset length: %llu", streamLength); lastRescan = time(NULL); setEndTS(); @@ -571,10 +574,7 @@ void Player::threadMethod() threadBuffer = vdr->getBlock(feedPosition, askFor, &thisRead); if (!vdr->isConnected()) { - Message* m = new Message(); - m->message = Message::CONNECTION_LOST; - m->to = this; - commandMessageQueue->postMessage(m); + doConnectionLost(); return; } @@ -670,6 +670,7 @@ void Player::setStartTS(UINT dataInBuffer) UINT thisRead; UCHAR* tempBuffer = VDR::getInstance()->getBlock(0, 100000, &thisRead); + if (!tempBuffer && !VDR::getInstance()->isConnected()) { doConnectionLost(); return; } if (!tempBuffer) return; if (thisRead) demuxer.findVideoPTS(tempBuffer, thisRead, &startTS); free(tempBuffer); @@ -686,6 +687,7 @@ void Player::setEndTS() UINT thisRead; UCHAR* tempBuffer = VDR::getInstance()->getBlock((streamLength - 100000), 100000, &thisRead); + if (!tempBuffer && !VDR::getInstance()->isConnected()) { doConnectionLost(); return; } if (!tempBuffer) return; if (thisRead) demuxer.findVideoPTS(tempBuffer, thisRead, &endTS); free(tempBuffer); diff --git a/player.h b/player.h index c490c0c..24f5e18 100644 --- a/player.h +++ b/player.h @@ -75,6 +75,7 @@ class Player : public Thread, public Callback void resyncVideo(); void setStartTS(UINT dataInBuffer); void setEndTS(); + void doConnectionLost(); int initted; MessageQueue* commandMessageQueue; diff --git a/vepg.cc b/vepg.cc index 0f7ae5a..9aaca60 100644 --- a/vepg.cc +++ b/vepg.cc @@ -118,19 +118,23 @@ VEpg::VEpg(VVideoLive* v, UINT currentChannel) // populate channel list - Channel* chan; - int first = 1; - for (UINT i = 0; i < chanList->size(); i++) - { - chan = (*chanList)[i]; - if (i == currentChannel) - first = 1; - chan->index = chanListbox.addOption(chan->name, first); - first = 0; - } + if (chanList) + { + Channel* chan; + int first = 1; + for (UINT i = 0; i < chanList->size(); i++) + { + chan = (*chanList)[i]; + if (i == currentChannel) + first = 1; + chan->index = chanListbox.addOption(chan->name, first); + first = 0; + } + chanName.setText((*chanList)[chanListbox.getCurrentOption()]->name); + } + listTop = chanListbox.getTopOption(); chanListbox.draw(); // doing this to allow chanListbox.getBottomOption() in updateEventList() to work - chanName.setText((*chanList)[chanListbox.getCurrentOption()]->name); time(<ime); // set ltime to now ltime = prevHour(<ime); // set ltime to previous hour TODO make this half hour? time(&selTime); // set selTime to now @@ -340,6 +344,7 @@ int VEpg::handleCommand(int command) } case Remote::RECORD: { + if (!chanList) return 2; Log::getInstance()->log("VEPG", Log::DEBUG, "ID %lu TIME %lu DURATION %lu TITLE %s", thisEvent.id, thisEvent.time, thisEvent.duration, thisEvent.title); VEpgSetTimer* vs = new VEpgSetTimer(&thisEvent, (*chanList)[chanListbox.getCurrentOption()]); vs->draw(); @@ -350,7 +355,10 @@ int VEpg::handleCommand(int command) case Remote::PLAY: case Remote::GO: case Remote::OK: - { // select programme and display menu TODO currently just changes to selected channel + { + if (!chanList) return 2; + + // select programme and display menu TODO currently just changes to selected channel videoLive->channelChange(VVideoLive::NUMBER, (*chanList)[chanListbox.getCurrentOption()]->number); if(command == Remote::GO) @@ -529,6 +537,7 @@ void VEpg::drawgrid() // redraws grid and select programme void VEpg::updateEventList() { + if (!chanList) return; Channel* chan; for(UINT listIndex = 0; listIndex < gridRows; listIndex++) { @@ -540,7 +549,9 @@ void VEpg::updateEventList() if(listTop + listIndex >= UINT(chanListbox.getBottomOption())) continue; chan = (*chanList)[listTop + listIndex]; - eventLista[listIndex] = VDR::getInstance()->getChannelSchedule(chan->number, ltime - 1, WINDOW_WIDTH * 60 + 2); // ltime - 1 to get prog before window (allows cursor left past ltime). + 2 to get prog after window + + EventList* newEventList = VDR::getInstance()->getChannelSchedule(chan->number, ltime - 1, WINDOW_WIDTH * 60 + 2); // ltime - 1 to get prog before window (allows cursor left past ltime). + 2 to get prog after window + if (newEventList) eventLista[listIndex] = newEventList; } } diff --git a/vlivebanner.cc b/vlivebanner.cc index 6e53cf9..a973dca 100644 --- a/vlivebanner.cc +++ b/vlivebanner.cc @@ -96,9 +96,7 @@ void VLiveBanner::setChannel(Channel* tChannel) snprintf(ttitleText, 99, "%03lu - %s", currentChannel->number, currentChannel->name); setTitleText(ttitleText); - Log::getInstance()->log("Banner", Log::DEBUG, "Start get ch"); eventList = VDR::getInstance()->getChannelSchedule(currentChannel->number); - Log::getInstance()->log("Banner", Log::DEBUG, "End get ch"); if (!eventList) { diff --git a/voptions.cc b/voptions.cc index a2d2246..47c9fd7 100644 --- a/voptions.cc +++ b/voptions.cc @@ -119,6 +119,8 @@ VOptions::VOptions(View* tparent, const char* title, const OPTIONDATA* toptionDa { setScreenPos(94, 70 + voff); } + + if (!vdr->isConnected()) Command::getInstance()->connectionLost(); } VOptions::~VOptions() diff --git a/voptions.h b/voptions.h index 0d1481c..d30dbad 100644 --- a/voptions.h +++ b/voptions.h @@ -30,6 +30,7 @@ #include "woptionbox.h" #include "wsymbol.h" #include "i18n.h" +#include "command.h" typedef struct { diff --git a/voptionsmenu.cc b/voptionsmenu.cc index d3c0508..508187c 100644 --- a/voptionsmenu.cc +++ b/voptionsmenu.cc @@ -144,6 +144,8 @@ void VOptionsMenu::processMessage(Message* m) { doApplyChanges((map*)m->parameter); viewman->removeView(this); + + if (!VDR::getInstance()->isConnected()) Command::getInstance()->connectionLost(); } } diff --git a/vvideolive.cc b/vvideolive.cc index 0b23376..95b03a3 100644 --- a/vvideolive.cc +++ b/vvideolive.cc @@ -297,6 +297,7 @@ void VVideoLive::play(int noShowVLB) { if (!noShowVLB) doBanner(false); showUnavailable(1); + if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; } } else { @@ -313,6 +314,7 @@ void VVideoLive::stop(int noRemoveVLB) player->stop(); Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay starts here due to time taken by plugin to stop"); vdr->stopStreaming(); + if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; } Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay ends here due to time taken by plugin to stop"); } diff --git a/vvideorec.cc b/vvideorec.cc index 63cb0bc..d8d5b16 100644 --- a/vvideorec.cc +++ b/vvideorec.cc @@ -276,6 +276,7 @@ void VVideoRec::stopPlay() playing = false; + if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; } Log::getInstance()->log("VVideoRec", Log::DEBUG, "Post stopPlay"); } -- 2.39.5