From a8653aabb69a8292d3395e2bc345e2a7fd35701d Mon Sep 17 00:00:00 2001 From: Tobias Grimm Date: Sun, 11 Jan 2009 10:20:00 +0100 Subject: =?UTF-8?q?More=20refactoring=20of=20the=20TxtStatus=20class=20(Th?= =?UTF-8?q?x=20to=20S=C3=B6ren=20Moch!)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HISTORY | 3 ++ txtrecv.c | 103 ++++++++++++++++---------------------------------------------- txtrecv.h | 15 +-------- 3 files changed, 31 insertions(+), 90 deletions(-) diff --git a/HISTORY b/HISTORY index 8af056f..c798f44 100644 --- a/HISTORY +++ b/HISTORY @@ -1,6 +1,9 @@ VDR Plugin 'osdteletext' Revision History ----------------------------------------- +2009-xx-xx: version 0.x.x +- More refactoring of the TxtStatus class (Thx to Sören Moch!) + 2009-01-10: version 0.8.1 - Small bugfix in channel switching code diff --git a/txtrecv.c b/txtrecv.c index c8113aa..7a401d6 100644 --- a/txtrecv.c +++ b/txtrecv.c @@ -92,7 +92,7 @@ int Storage::cleanSubDir(const char *dir) { reportedError=true; } } - + if (hadError && !reportedError) { esyslog("OSD-Teletext: Error removing teletext storage subdirectory \"%s\": %s", dir, strerror(hadError)); reportedError=true; @@ -146,7 +146,7 @@ void Storage::freeSpace() { //occupies the whole space. We cannot delete anything. Don't waste time scanning. if (failedFreeSpace) return; - + //printf("freeSpace()\n"); time_t min=time(0); char minDir[PATH_MAX]; @@ -171,7 +171,7 @@ void Storage::freeSpace() { } } closedir(top); - + //if haveDir, only current directory present, which must not be deleted if (haveDir>=2) byteCount-=cleanSubDir(minDir); @@ -233,16 +233,15 @@ int LegacyStorage::actualFileSize(int netFileSize) { //max==0 means unlimited, max==-1 means a reasonable default value shall be calculated void LegacyStorage::initMaxStorage(int maxMB) { - struct statfs fs; if (statfs(getRootDir(), &fs)!=0) { esyslog("OSD-Teletext: Error statfs'ing root directory \"%s\": %s, cache size uncontrolled", getRootDir(), strerror(errno)); return; } fsBlockSize=fs.f_bsize; - + pageBytes=actualFileSize(TELETEXT_PAGESIZE); - + if (maxMB>=0) { if (maxMB<3) { esyslog("OSD-Teletext: Request to use at most %d MB for caching. This is not enough, using 3 MB", maxMB); @@ -346,7 +345,7 @@ PackedStorage::PackedStorage() { bool PackedStorage::seekTo(PageID page, int desc, bool create) { lseek(desc, 0, SEEK_SET); PageAddress addr[TOC_SIZE]; - + while (::read(desc, addr, sizeof(addr)) == sizeof(addr)) { lseek(desc, 0, SEEK_CUR); for (int index=0; indexmaxBytes ) freeSpace(); return (StorageHandle)desc; @@ -495,25 +494,12 @@ void cTelePage::save() cTxtStatus::cTxtStatus(void) { receiver = NULL; - - //running=false; - TPid=0; - /*doNotSuspend=false; - doNotReceive=false;*/ - //suspended=false; - currentLiveChannel = tChannelID::InvalidID; } cTxtStatus::~cTxtStatus() { - /*if (running) - Cancel(3);*/ - if (receiver) - { - receiver->Stop(); - delete receiver; - } + delete receiver; } void cTxtStatus::ChannelSwitch(const cDevice *Device, int ChannelNumber) @@ -539,55 +525,20 @@ void cTxtStatus::ChannelSwitch(const cDevice *Device, int ChannelNumber) currentLiveChannel = newLiveChannel->GetChannelID(); - CheckDeleteReceiver(); - - if (newLiveChannel->Tpid()) { - TPid=newLiveChannel->Tpid(); - chan=newLiveChannel->GetChannelID(); - CheckCreateReceiver(); - } + delete receiver; + receiver = NULL; - TeletextBrowser::ChannelSwitched(ChannelNumber); -} + int TPid = newLiveChannel->Tpid(); -void cTxtStatus::CheckCreateReceiver() { - if (!receiver && TPid ) { - cChannel *channel = Channels.GetByChannelID(chan); - if (!channel) - return; - //primary device a full-featured card - if (cDevice::ActualDevice()->ProvidesChannel(channel, Setup.PrimaryLimit)) { - receiver = new cTxtReceiver(TPid, chan); - cDevice::ActualDevice()->AttachReceiver(receiver); - //dsyslog("OSD-Teletext: Created teletext receiver for channel %d, PID %d on primary device", ChNum, TPid); - //primary device a DXR3 or similar - } else { - int devNum = cDevice::NumDevices(); - bool bFound = false; - cDevice* pDevice = 0; - for (int i = 0; i < devNum && !bFound; ++i) { - pDevice = cDevice::GetDevice(i); - if (pDevice && pDevice->ProvidesChannel(channel, Setup.PrimaryLimit) && pDevice->Receiving(true)) { - bFound = true; - receiver = new cTxtReceiver(TPid, chan); - pDevice->AttachReceiver(receiver); - //dsyslog("OSD-Teletext: Created teletext receiver for channel %d, PID %d on device %d", ChNum, TPid, i); - } - } - if (!bFound) //can this happen? - esyslog("OSDTeletext: Did not find appropriate device for teletext receiver for channel %s, PID %d", channel->Name(), TPid); - } + if (TPid) { + receiver = new cTxtReceiver(TPid, currentLiveChannel); + cDevice::ActualDevice()->AttachReceiver(receiver); } -} -void cTxtStatus::CheckDeleteReceiver() { - if (receiver) { - //dsyslog("OSD-Teletext: Deleted teletext receiver"); - delete receiver; - receiver = NULL; - } + TeletextBrowser::ChannelSwitched(ChannelNumber); } + cTxtReceiver::cTxtReceiver(int TPid, tChannelID chan) : cReceiver(chan, -1, TPid), cThread("osdteletext-receiver"), chan(chan), TxtPage(0), buffer((188+60)*75), running(false) @@ -653,7 +604,7 @@ void cTxtReceiver::Action() { cFrame *frame=buffer.Get(); if (frame) { uchar *Datai=frame->Data(); - + for (int i=0; i < 4; i++) { if (Datai[4+i*46]==2 || Datai[4+i*46]==3) { for (int j=(8+i*46);j<(50+i*46);j++) @@ -661,12 +612,12 @@ void cTxtReceiver::Action() { DecodeTXT(&Datai[i*46]); } } - + buffer.Drop(frame); } else buffer.Wait(); } - + buffer.Clear(); running=false; } @@ -709,17 +660,17 @@ void cTxtReceiver::DecodeTXT(uchar* TXT_buf) // C11 - Magazine Serial mode // C12-C14 - Language selection, lower 3 bits - + int hdr,mag,mag8,line; uchar *ptr; uchar flags,lang; - + hdr = unham16 (&TXT_buf[0x8]); mag = hdr & 0x07; mag8 = mag ?: 8; line = (hdr>>3) & 0x1f; ptr = &TXT_buf[10]; - + switch (line) { case 0: { @@ -727,7 +678,7 @@ void cTxtReceiver::DecodeTXT(uchar* TXT_buf) int pgno, subno; b1 = unham16 (ptr); // Page no, 10- and 1-digit - + if (b1 == 0xff) break; if (TxtPage) { TxtPage->save(); @@ -755,7 +706,7 @@ void cTxtReceiver::DecodeTXT(uchar* TXT_buf) pgno = mag8 * 256 + b1; subno = (b2 + b3 * 256) & 0x3f7f; // Sub Page Number - + TxtPage = new cTelePage(PageID(chan, pgno, subno), flags, lang, mag); TxtPage->SetLine((int)line,(uchar *)ptr); break; diff --git a/txtrecv.h b/txtrecv.h index bb9edc4..ec274ea 100644 --- a/txtrecv.h +++ b/txtrecv.h @@ -178,28 +178,15 @@ public: virtual void Stop(); }; -class cTxtStatus : public cStatus/*, public cThread*/ { +class cTxtStatus : public cStatus { private: cTxtReceiver *receiver; - //bool running; - //cCondVar condVar; - //cMutex mutex; - //int count; tChannelID currentLiveChannel; protected: - int TPid; - tChannelID chan; - //bool doNotSuspend; - //bool doNotReceive; virtual void ChannelSwitch(const cDevice *Device, int ChannelNumber); - //virtual void Action(); - void CheckCreateReceiver(); - void CheckDeleteReceiver(); public: cTxtStatus(void); ~cTxtStatus(); - //void ForceReceiving(bool onOrOff); - //void ForceSuspending(bool onOrOff); }; -- cgit v1.2.3