From af483c11aebd8146a978dba3d604bda0951e24ac Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Sun, 17 Oct 2004 18:00:00 +0200 Subject: =?UTF-8?q?Version=201.3.13=20-=20Fixed=20checking=20for=20the=20p?= =?UTF-8?q?resence=20of=20NPTL=20(thanks=20to=20Jouni=20Karvo).=20-=20Maki?= =?UTF-8?q?ng=20sure=20section=20filters=20are=20only=20set=20if=20the=20d?= =?UTF-8?q?evice=20actually=20has=20a=20lock=20=20=20(thanks=20to=20Andrea?= =?UTF-8?q?s=20Share=20for=20pointing=20this=20out).=20-=20Fixed=20a=20pos?= =?UTF-8?q?sible=20NULL=20pointer=20assignment=20in=20cMenuText::SetText()?= =?UTF-8?q?=20(thanks=20to=20=20=20Marco=20Schl=C3=BCssler).=20-=20Fixed?= =?UTF-8?q?=20a=20crash=20in=20case=20the=20last=20line=20in=20channels.co?= =?UTF-8?q?nf=20is=20a=20group=20separator=20and=20=20=20that=20group=20is?= =?UTF-8?q?=20selected=20in=20the=20channel=20display=20(thanks=20to=20Dic?= =?UTF-8?q?k=20Streefland).=20-=20Added=20cRingBufferLinear::Read()=20to?= =?UTF-8?q?=20read=20directly=20from=20a=20file=20handle=20into=20the=20?= =?UTF-8?q?=20=20ring=20buffer.=20-=20Using=20timeouts=20in=20ring=20buffe?= =?UTF-8?q?rs=20to=20avoid=20'usleep()'.=20-=20Clearing=20the=20'Transfer?= =?UTF-8?q?=20Mode'=20ring=20buffer=20after=20clearing=20the=20device=20to?= =?UTF-8?q?=20avoid=20=20=20an=20"almost=20full"=20ring=20buffer.=20-=20Re?= =?UTF-8?q?moved=20locking=20from=20cRingBufferLinear=20for=20better=20per?= =?UTF-8?q?formance=20under=20high=20load.=20-=20Using=20a=20cRingBufferLi?= =?UTF-8?q?near=20in=20cRemux=20to=20avoid=20unnecessary=20copying=20of=20?= =?UTF-8?q?data.=20-=20Using=20a=20cRingBufferLinear=20in=20cTSBuffer=20an?= =?UTF-8?q?d=20filling=20it=20in=20a=20separate=20thread=20=20=20to=20avoi?= =?UTF-8?q?d=20buffer=20overflows.=20Plugins=20using=20cTSBuffer=20will=20?= =?UTF-8?q?need=20to=20remove=20the=20=20=20call=20to=20the=20now=20obsole?= =?UTF-8?q?te=20Read()=20function=20(see=20cDvbDevice::GetTSPacket()=20for?= =?UTF-8?q?=20=20=20the=20new=20usage=20of=20cTSBuffer).=20-=20cRemux::Pro?= =?UTF-8?q?cess()=20has=20been=20split=20into=20Put(),=20Get()=20and=20Del?= =?UTF-8?q?()=20to=20allow=20for=20a=20=20=20better=20decoupling=20of=20th?= =?UTF-8?q?e=20remuxing=20and=20disk=20writing=20process.=20Plugins=20usin?= =?UTF-8?q?g=20=20=20cRemux=20will=20need=20to=20be=20modified=20according?= =?UTF-8?q?ly.=20-=20The=20actual=20disk=20writing=20in=20recordings=20is?= =?UTF-8?q?=20now=20done=20in=20a=20separate=20thread=20to=20=20=20improve?= =?UTF-8?q?=20the=20overall=20throughput.=20-=20Changed=20cRemux=20so=20th?= =?UTF-8?q?at=20it=20returns=20the=20maximum=20available=20amount=20of=20d?= =?UTF-8?q?ata=20with=20=20=20each=20call,=20not=20just=202048=20byte.=20-?= =?UTF-8?q?=20Added=20a=20visual=20display=20of=20all=20cRingBufferLinear?= =?UTF-8?q?=20buffers=20for=20debugging.=20To=20=20=20activate=20it,=20def?= =?UTF-8?q?ine=20DEBUGRINGBUFFERS=20in=20ringbuffer.h.=20-=20Instead=20of?= =?UTF-8?q?=20cCondVar=20now=20using=20the=20new=20cCondWait=20(which=20al?= =?UTF-8?q?so=20avoids=20a=20possible=20=20=20"near=20miss"=20condition;?= =?UTF-8?q?=20thanks=20to=20Sascha=20Volkenandt=20for=20pointing=20out=20t?= =?UTF-8?q?his=20one).=20=20=20cCondVar=20is=20still=20present=20for=20plu?= =?UTF-8?q?gins=20that=20use=20it=20(and=20VDR=20itself=20also=20still=20?= =?UTF-8?q?=20=20uses=20it=20in=20cRemote).=20-=20The=20cRingBuffer=20now?= =?UTF-8?q?=20does=20EnableGet()/EnablePut()=20only=20if=20the=20buffer=20?= =?UTF-8?q?is=20more=20than=20=20=20one=20third=20full=20or=20empty,=20res?= =?UTF-8?q?pectively.=20This=20dramatically=20improves=20recording=20=20?= =?UTF-8?q?=20performance=20and=20reduces=20system=20load=20(thanks=20to?= =?UTF-8?q?=20Marco=20Schl=C3=BC=C3=9Fler=20for=20doing=20some=20=20=20tes?= =?UTF-8?q?ting=20regarding=20buffer=20performance=20and=20giving=20me=20s?= =?UTF-8?q?ome=20hints=20that=20finally=20led=20=20=20to=20finding=20out?= =?UTF-8?q?=20that=20this=20was=20the=20basic=20problem=20causing=20buffer?= =?UTF-8?q?=20overflows).=20-=20Improved=20Transfer=20Mode=20(thanks=20to?= =?UTF-8?q?=20Marco=20Schl=C3=BC=C3=9Fler=20for=20suggestions=20and=20test?= =?UTF-8?q?ing).=20-=20Fixed=20a=20possible=20crash=20with=20inconsistent?= =?UTF-8?q?=20SI=20data=20(thanks=20to=20Marcel=20Wiesweg).=20-=20Fixed=20?= =?UTF-8?q?showing=20the=20replay=20mode=20if=20the=20OSD=20is=20currently?= =?UTF-8?q?=20in=20use=20(thanks=20to=20Kimmo=20=20=20Tykkala=20for=20poin?= =?UTF-8?q?ting=20out=20this=20problem).=20-=20cOsdProvider::NewOsd()=20no?= =?UTF-8?q?w=20always=20returns=20a=20valid=20pointer,=20even=20if=20the?= =?UTF-8?q?=20OSD=20is=20=20=20currently=20in=20use=20(it=20will=20then=20?= =?UTF-8?q?return=20a=20dummy=20cOsd=20object=20and=20write=20a=20message?= =?UTF-8?q?=20to=20=20=20the=20log=20file).=20-=20Added=20Estonian=20langu?= =?UTF-8?q?age=20texts=20(thanks=20to=20Arthur=20Konovalov).=20-=20Fixed?= =?UTF-8?q?=20'newplugin'=20and=20libsi/Makefile=20to=20use=20the=20compil?= =?UTF-8?q?er=20defined=20in=20$(CXX)=20for=20=20=20generating=20file=20de?= =?UTF-8?q?pendencies=20(thanks=20to=20Andreas=20Brachold).=20-=20Moved=20?= =?UTF-8?q?the=20initialization=20of=20aPid1=20and=20aPid2=20to=20the=20be?= =?UTF-8?q?ginning=20of=20cDvbDevice::cDvbDevice()=20=20=20to=20have=20the?= =?UTF-8?q?m=20set=20in=20case=20a=20patch=20references=20them=20(thanks?= =?UTF-8?q?=20to=20Wayne=20Keer=20for=20pointing=20=20=20this=20out).=20-?= =?UTF-8?q?=20Completed=20the=20Russian=20OSD=20texts=20(thanks=20to=20Vya?= =?UTF-8?q?cheslav=20Dikonov).=20-=20Avoiding=20unnecessary=20section=20fi?= =?UTF-8?q?lter=20start/stops=20(thanks=20to=20Marco=20Schl=C3=BC=C3=9Fler?= =?UTF-8?q?).=20-=20Made=20the=20"Channel=20not=20available!"=20message=20?= =?UTF-8?q?and=20mtInfo=20instead=20of=20mtError=20(suggested=20=20=20by?= =?UTF-8?q?=20Wayne=20Keer).=20-=20Made=20volume=20control=20more=20linear?= =?UTF-8?q?=20(thanks=20to=20Emil=20Naepflein=20and=20Udo=20Richter).=20-?= =?UTF-8?q?=20Now=20skipping=20code=20table=20info=20in=20SI=20data=20(sug?= =?UTF-8?q?gested=20by=20Milos=20Kapoun).=20-=20Added=20missing=20Czech=20?= =?UTF-8?q?characters=20to=20fontosd-iso8859-2.c=20(thanks=20to=20Milos=20?= =?UTF-8?q?Kapoun).=20-=20Fixed=20a=20crash=20in=20the=20time=20search=20m?= =?UTF-8?q?echanism=20(reported=20by=20Reinhard=20Nissl).=20-=20If=20one?= =?UTF-8?q?=20PID=20can't=20be=20added,=20the=20whole=20cDevice::AttachRec?= =?UTF-8?q?eiver()=20will=20now=20fail=20=20=20and=20all=20PIDs=20added=20?= =?UTF-8?q?so=20far=20will=20be=20deleted=20(thanks=20to=20Marco=20Schl?= =?UTF-8?q?=C3=BC=C3=9Fler=20for=20=20=20pointing=20out=20this=20one).=20-?= =?UTF-8?q?=20Now=20only=20saving=20channels.conf=20after=20a=20modificati?= =?UTF-8?q?on=20made=20by=20the=20user=20(avoids=20=20=20lots=20of=20disk?= =?UTF-8?q?=20access=20due=20to=20automatic=20channel=20updates).=20Automa?= =?UTF-8?q?tic=20channel=20=20=20modifications=20will=20be=20saved=20every?= =?UTF-8?q?=2010=20minutes=20if=20no=20recording=20is=20currently=20=20=20?= =?UTF-8?q?active.=20-=20Removed=20the=20'Log'=20parameter=20from=20the=20?= =?UTF-8?q?cChannel::Set...=20functions.=20Instead=20=20=20checking=20if?= =?UTF-8?q?=20the=20channel=20has=20a=20non-zero=20number.=20-=20Updated?= =?UTF-8?q?=20'channels.conf.terr'=20for=20Hannover=20(thanks=20to=20Sven?= =?UTF-8?q?=20Kreiensen).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- device.c | 134 ++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 68 insertions(+), 66 deletions(-) (limited to 'device.c') diff --git a/device.c b/device.c index d62b456..b53c0ab 100644 --- a/device.c +++ b/device.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: device.c 1.56 2004/06/19 08:51:05 kls Exp $ + * $Id: device.c 1.60 2004/10/17 09:39:10 kls Exp $ */ #include "device.h" @@ -248,7 +248,11 @@ bool cDevice::AddPid(int Pid, ePidType PidType) if (++pidHandles[n].used == 2 && n <= ptTeletext) { // It's a special PID that may have to be switched into "tap" mode PRINTPIDS("A"); - return SetPid(&pidHandles[n], n, true); + if (!SetPid(&pidHandles[n], n, true)) { + esyslog("ERROR: can't set PID %d on device %d", Pid, CardIndex() + 1); + DelPid(Pid, PidType); + return false; + } } PRINTPIDS("a"); return true; @@ -261,13 +265,19 @@ bool cDevice::AddPid(int Pid, ePidType PidType) // The Pid is not yet in use and we have a free slot n = a; } - else - esyslog("ERROR: no free slot for PID %d", Pid); + else { + esyslog("ERROR: no free slot for PID %d on device %d", Pid, CardIndex() + 1); + return false; + } if (n >= 0) { pidHandles[n].pid = Pid; pidHandles[n].used = 1; PRINTPIDS("C"); - return SetPid(&pidHandles[n], n, true); + if (!SetPid(&pidHandles[n], n, true)) { + esyslog("ERROR: can't set PID %d on device %d", Pid, CardIndex() + 1); + DelPid(Pid, PidType); + return false; + } } } return true; @@ -314,7 +324,6 @@ void cDevice::StartSectionHandler(void) AttachFilter(patFilter = new cPatFilter); AttachFilter(sdtFilter = new cSdtFilter(patFilter)); AttachFilter(nitFilter = new cNitFilter); - sectionHandler->SetStatus(true); } } @@ -357,7 +366,7 @@ bool cDevice::SwitchChannel(const cChannel *Channel, bool LiveView) for (int i = 3; i--;) { switch (SetChannel(Channel, LiveView)) { case scrOk: return true; - case scrNotAvailable: Skins.Message(mtError, tr("Channel not available!")); + case scrNotAvailable: Skins.Message(mtInfo, tr("Channel not available!")); return false; case scrNoTransfer: Skins.Message(mtError, tr("Can't start Transfer Mode!")); return false; @@ -758,8 +767,13 @@ bool cDevice::AttachReceiver(cReceiver *Receiver) return true; for (int i = 0; i < MAXRECEIVERS; i++) { if (!receiver[i]) { - for (int n = 0; n < MAXRECEIVEPIDS; n++) - AddPid(Receiver->pids[n]);//XXX+ retval! + for (int n = 0; n < MAXRECEIVEPIDS; n++) { + if (!AddPid(Receiver->pids[n])) { + for ( ; n-- > 0; ) + DelPid(Receiver->pids[n]); + return false; + } + } Receiver->Activate(true); Lock(); Receiver->device = this; @@ -801,79 +815,67 @@ void cDevice::Detach(cReceiver *Receiver) cTSBuffer::cTSBuffer(int File, int Size, int CardIndex) { + SetDescription("TS buffer on device %d", CardIndex); f = File; - size = Size / TS_SIZE * TS_SIZE; cardIndex = CardIndex; - tsRead = tsWrite = 0; - buf = (f >= 0 && size >= TS_SIZE) ? MALLOC(uchar, size + TS_SIZE) : NULL; - // the '+ TS_SIZE' allocates some extra space for handling packets that got split by a buffer roll-over - firstRead = true; + active = false; + delivered = false; + ringBuffer = new cRingBufferLinear(Size, TS_SIZE, true, "TS"); + ringBuffer->SetTimeouts(100, 100); + Start(); } cTSBuffer::~cTSBuffer() { - free(buf); -} - -int cTSBuffer::Read(void) -{ - if (buf) { - cPoller Poller(f, false); - bool repeat; - int total = 0; - do { - repeat = false; - if (firstRead || Used() > TS_SIZE || Poller.Poll(100)) { // only wait if there's not enough data in the buffer - firstRead = false; - if (tsRead == tsWrite) - tsRead = tsWrite = 0; // keep the maximum buffer space available - if (tsWrite >= size && tsRead > 0) - tsWrite = 0; - int free = tsRead <= tsWrite ? size - tsWrite : tsRead - tsWrite - 1; - if (free > 0) { - int r = read(f, buf + tsWrite, free); - if (r > 0) { - total += r; - tsWrite += r; - if (tsWrite >= size && tsRead > 0) { - tsWrite = 0; - repeat = true; // read again after a boundary roll-over - } - } - } - } - } while (repeat); - return total; + active = false; + Cancel(3); + delete ringBuffer; +} + +void cTSBuffer::Action(void) +{ + if (ringBuffer) { + bool firstRead = true; + cPoller Poller(f); + active = true; + for (; active;) { + if (firstRead || Poller.Poll(100)) { + firstRead = false; + int r = ringBuffer->Read(f); + if (r < 0 && FATALERRNO) { + if (errno == EOVERFLOW) + esyslog("ERROR: driver buffer overflow on device %d", cardIndex); + else { + LOG_ERROR; + break; + } + } + } + } } - return -1; } uchar *cTSBuffer::Get(void) { - if (Used() >= TS_SIZE) { - uchar *p = buf + tsRead; + int Count = 0; + if (delivered) { + ringBuffer->Del(TS_SIZE); + delivered = false; + } + uchar *p = ringBuffer->Get(Count); + if (p && Count >= TS_SIZE) { if (*p != TS_SYNC_BYTE) { - esyslog("ERROR: not sync'ed to TS packet on device %d", cardIndex); - int tsMax = tsRead < tsWrite ? tsWrite : size; - for (int i = tsRead; i < tsMax; i++) { - if (buf[i] == TS_SYNC_BYTE) { - esyslog("ERROR: skipped %d bytes to sync on TS packet on device %d", i - tsRead, cardIndex); - tsRead = i; - return NULL; + for (int i = 1; i < Count; i++) { + if (p[i] == TS_SYNC_BYTE) { + Count = i; + break; } } - if ((tsRead = tsMax) >= size) - tsRead = 0; + ringBuffer->Del(Count); + esyslog("ERROR: skipped %d bytes to sync on TS packet on device %d", Count, cardIndex); return NULL; } - if (tsRead + TS_SIZE > size) { - // the packet rolled over the buffer boundary, so let's fetch the rest from the beginning (which MUST be there, since Used() >= TS_SIZE) - int rest = TS_SIZE - (size - tsRead); - memcpy(buf + size, buf, rest); - tsRead = rest; - } - else if ((tsRead += TS_SIZE) >= size) - tsRead = 0; + delivered = true; return p; } return NULL; -- cgit v1.2.3