From 9384e56566f56e77d577319a42929e708936e7c7 Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Sun, 14 Mar 2004 18:00:00 +0100 Subject: =?UTF-8?q?Version=201.3.6=20-=20Completed=20the=20Finnish=20OSD?= =?UTF-8?q?=20texts=20(thanks=20to=20Rolf=20Ahrenberg).=20-=20Fixed=20some?= =?UTF-8?q?=20descriptor=20handling=20in=20'libsi'=20(thanks=20to=20St?= =?UTF-8?q?=C3=A9phane=20Est=C3=A9-Gracias).=20-=20Fixed=20handling=20the?= =?UTF-8?q?=20current=20menu=20item=20(thanks=20to=20Marc=20Hoppe).=20-=20?= =?UTF-8?q?Fixed=20assigning=20events=20to=20timers=20(they=20no=20longer?= =?UTF-8?q?=20get=20"stuck").=20-=20Added=20log=20entries=20whenever=20the?= =?UTF-8?q?=20running=20status=20of=20an=20event=20changes=20(currently=20?= =?UTF-8?q?=20=20only=20logging=20the=20first=2030=20channels).=20-=20Fixe?= =?UTF-8?q?d=20handling=20timers=20in=20VPS=20margin=20if=20the=20EPG=20sc?= =?UTF-8?q?an=20is=20turned=20on=20(the=20EPG=20scan=20=20=20switched=20th?= =?UTF-8?q?e=20device=20away=20from=20the=20channel,=20so=20it=20wouldn't?= =?UTF-8?q?=20see=20the=20change=20of=20=20=20the=20running=20status).=20-?= =?UTF-8?q?=20Fixed=20handling=20"itemized"=20texts=20in=20EPG=20data=20(t?= =?UTF-8?q?hanks=20to=20St=C3=A9phane=20Est=C3=A9-Gracias=20=20=20for=20po?= =?UTF-8?q?inting=20out=20this=20problem,=20and=20Marcel=20Wiesweg=20for?= =?UTF-8?q?=20improving=20'libsi').=20-=20Fixed=20handling=20VPS=20times?= =?UTF-8?q?=20at=20year=20boundaries.=20-=20Avoiding=20too=20many=20consec?= =?UTF-8?q?utive=20"ring=20buffer=20overflow"=20messages=20(which=20only?= =?UTF-8?q?=20=20=20slowed=20down=20performance=20even=20more).=20-=20Taki?= =?UTF-8?q?ng=20the=20Sid=20into=20account=20when=20detecting=20version=20?= =?UTF-8?q?changes=20in=20processing=20the=20=20=20PMT=20(thanks=20to=20St?= =?UTF-8?q?=C3=A9phane=20Est=C3=A9-Gracias=20for=20pointing=20out=20this?= =?UTF-8?q?=20problem).=20-=20Completed=20the=20Russian=20OSD=20texts=20(t?= =?UTF-8?q?hanks=20to=20Vyacheslav=20Dikonov).=20-=20Any=20newline=20chara?= =?UTF-8?q?cters=20in=20the=20'description'=20of=20EPG=20events=20are=20no?= =?UTF-8?q?w=20preserved=20=20=20to=20allow=20texts=20to=20be=20displayed?= =?UTF-8?q?=20the=20way=20the=20tv=20stations=20have=20formatted=20them.?= =?UTF-8?q?=20=20=20This=20was=20also=20necessary=20to=20better=20display?= =?UTF-8?q?=20itemized=20texts.=20-=20Fixed=20detecting=20the=20running=20?= =?UTF-8?q?status=20in=20case=20an=20empty=20EPG=20event=20is=20broadcast?= =?UTF-8?q?=20(thanks=20=20=20to=20Michael=20Pennewi=C3=9F=20for=20pointin?= =?UTF-8?q?g=20this=20out).=20-=20Improved=20performance=20when=20paging?= =?UTF-8?q?=20through=20very=20long=20menu=20lists.=20-=20Removed=20cSched?= =?UTF-8?q?ule::GetEventNumber()=20and=20cSchedule::NumEvents().=20There?= =?UTF-8?q?=20is=20now=20=20=20cSchedule::Events()=20that=20returns=20the?= =?UTF-8?q?=20list=20of=20events=20directly.=20-=20Avoiding=20occasional?= =?UTF-8?q?=20bad=20responsiveness=20to=20user=20interaction=20caused=20by?= =?UTF-8?q?=20assigning=20=20=20events=20to=20timers.=20-=20Now=20explicit?= =?UTF-8?q?ly=20turning=20on=20the=20LNB=20power=20at=20startup,=20because?= =?UTF-8?q?=20newer=20drivers=20don't=20=20=20do=20this=20any=20more=20(th?= =?UTF-8?q?anks=20to=20Oliver=20Endriss=20for=20pointing=20this=20out).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libsi/descriptor.c | 156 +++++++++++++++++++++++++++++++++++++++++++++++------ libsi/descriptor.h | 27 +++++++--- libsi/si.c | 83 ++++++++++++++++++++++------ libsi/si.h | 63 ++++++++++++++++++---- 4 files changed, 283 insertions(+), 46 deletions(-) (limited to 'libsi') diff --git a/libsi/descriptor.c b/libsi/descriptor.c index 0b0019f..82e2a8f 100644 --- a/libsi/descriptor.c +++ b/libsi/descriptor.c @@ -6,7 +6,7 @@ * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * - * $Id: descriptor.c 1.6 2004/02/22 11:11:36 kls Exp $ + * $Id: descriptor.c 1.10 2004/03/13 15:08:12 kls Exp $ * * ***************************************************************************/ @@ -60,13 +60,13 @@ void ExtendedEventDescriptor::Item::Parse() { item.setData(data+offset, mid->item_length); } -int ExtendedEventDescriptors::getTextLength() { +/*int ExtendedEventDescriptors::getTextLength() { int ret=0; for (int i=0;itext.getLength()+1; //plus a blank + ret+=d->text.getLength(); ExtendedEventDescriptor::Item item; for (Loop::Iterator it; d->itemLoop.hasNext(it); ) { item=d->itemLoop.getNext(it); @@ -76,28 +76,84 @@ int ExtendedEventDescriptors::getTextLength() { } } return ret; -} +}*/ -//is there a case where this function does not return the same as getTextLength? int ExtendedEventDescriptors::getMaximumTextLength() { + return getMaximumTextPlainLength()+getMaximumTextItemizedLength(); +} + +char *ExtendedEventDescriptors::getText(const char *separation1, const char *separation2) { + char *text=new char[getMaximumTextLength()+strlen(separation1)+strlen(separation2)]; + return getText(text, separation1, separation2); +} + +char *ExtendedEventDescriptors::getText(char *buffer, const char *separation1, const char *separation2) { + int index=0, len; + char tempbuf[256]; + for (int i=0;itext.getText(tempbuf); + len=strlen(tempbuf); + if (len) { + memcpy(buffer+index, tempbuf, len); + index+=len; + } + } + + for (int i=0;iitemLoop.hasNext(it); ) { + item=d->itemLoop.getNext(it); + + item.itemDescription.getText(tempbuf); + len=strlen(tempbuf); + if (len) { + memcpy(buffer+index, tempbuf, len); + index+=len; + } + strcpy(buffer+index, separation1); + index += strlen(separation1); + + item.item.getText(tempbuf); + len=strlen(tempbuf); + if (len) { + memcpy(buffer+index, tempbuf, len); + index+=len; + } + strcpy(buffer+index, separation2); + index += strlen(separation2); + } + } + + buffer[index]='\0'; + return buffer; +} + +int ExtendedEventDescriptors::getMaximumTextPlainLength() { int ret=0; for (int i=0;itext.getLength()+1; //plus a blank - ret+=d->itemLoop.getLength(); + ret+=d->text.getLength(); } return ret; } -char *ExtendedEventDescriptors::getText() { - char *text=new char[getMaximumTextLength()]; - return getText(text); +char *ExtendedEventDescriptors::getTextPlain() { + char *text=new char[getMaximumTextPlainLength()]; + return getTextPlain(text); } -//appends the Strings of every Descriptor in the group -char *ExtendedEventDescriptors::getText(char *buffer) { +char *ExtendedEventDescriptors::getTextPlain(char *buffer) { int index=0, len; char tempbuf[256]; for (int i=0;iitemLoop.getLength(); + } + return ret; +} + +char *ExtendedEventDescriptors::getTextItemized(const char *separation1, const char *separation2) { + char *text=new char[getMaximumTextItemizedLength()+strlen(separation1)+strlen(separation2)]; + return getTextItemized(text, separation1, separation2); +} + +char *ExtendedEventDescriptors::getTextItemized(char *buffer, const char *separation1, const char *separation2) { + int index=0, len; + char tempbuf[256]; + for (int i=0;iitemLoop.hasNext(it); ) { item=d->itemLoop.getNext(it); - item.item.getText(tempbuf); + item.itemDescription.getText(tempbuf); len=strlen(tempbuf); if (len) { memcpy(buffer+index, tempbuf, len); index+=len; } + strcpy(buffer+index, separation1); + index += strlen(separation1); - item.itemDescription.getText(tempbuf); + item.item.getText(tempbuf); len=strlen(tempbuf); if (len) { memcpy(buffer+index, tempbuf, len); index+=len; } + strcpy(buffer+index, separation2); + index += strlen(separation2); } } buffer[index]='\0'; return buffer; } +//returns the itemized text pair by pair. Maximum length for buffers is 256. +//Return value is false if and only if the end of the list is reached. +bool ExtendedEventDescriptors::getTextItemized(Loop::Iterator &it, bool &valid, char *itemDescription, char *itemText) { + //The iterator has to store two values: The descriptor index (4bit) + //and the item loop index (max overall length 256, min item length 16 => max number 128 => 7bit) + valid=false; + + int index=(it.i & 0x780) >> 7; // 0x780 == 1111 000 0000 + it.i &= 0x7F; //0x7F == 111 1111 + + for (;indexitemLoop.hasNext(it)) { + item=d->itemLoop.getNext(it); + + item.item.getText(itemDescription); + item.itemDescription.getText(itemText); + valid=true; + break; + } else { + it.reset(); + continue; + } + } + + it.i &= 0x7F; + it.i |= (index & 0xF) << 7; //0xF == 1111 + + return indexreference_service_id); } @@ -148,7 +272,7 @@ void TimeShiftedEventDescriptor::Parse() { void ContentDescriptor::Parse() { //this descriptor is only a header and a loop - nibbleLoop.setData(data+sizeof(SectionHeader), getLength()-sizeof(SectionHeader)); + nibbleLoop.setData(data+sizeof(descr_content), getLength()-sizeof(descr_content)); } int ContentDescriptor::Nibble::getContentNibbleLevel1() const { @@ -173,7 +297,7 @@ void ContentDescriptor::Nibble::Parse() { void ParentalRatingDescriptor::Parse() { //this descriptor is only a header and a loop - ratingLoop.setData(data+sizeof(SectionHeader), getLength()-sizeof(SectionHeader)); + ratingLoop.setData(data+sizeof(descr_parental_rating), getLength()-sizeof(descr_parental_rating)); } int ParentalRatingDescriptor::Rating::getRating() const { diff --git a/libsi/descriptor.h b/libsi/descriptor.h index 17c81eb..3368b0a 100644 --- a/libsi/descriptor.h +++ b/libsi/descriptor.h @@ -6,7 +6,7 @@ * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * - * $Id: descriptor.h 1.6 2004/02/22 10:16:47 kls Exp $ + * $Id: descriptor.h 1.7 2004/03/07 11:13:54 kls Exp $ * * ***************************************************************************/ @@ -50,14 +50,29 @@ private: class ExtendedEventDescriptors : public DescriptorGroup { public: - //don't use - int getTextLength(); - //really fast int getMaximumTextLength(); + //Returns a concatenated version of first the non-itemized and then the itemized text //same semantics as with SI::String - char *getText(); + char *getText(const char *separation1="\t", const char *separation2="\n"); //buffer must at least be getTextLength(), getMaximumTextLength() is a good choice - char *getText(char *buffer); + char *getText(char *buffer, const char *separation1="\t", const char *separation2="\n"); + + //these only return the non-itemized text fields in concatenated form + int getMaximumTextPlainLength(); + char *getTextPlain(); + char *getTextPlain(char *buffer); + + //these only return the itemized text fields in concatenated form. + //Between the description and the text the separation1 character is used, + //separation2 used between two pairs. Example: + //Director\tSteven Spielberg\nActor\tMichael Mendl\n + int getMaximumTextItemizedLength(); + char *getTextItemized(const char *separation1="\t", const char *separation2="\n"); + char *getTextItemized(char *buffer, const char *separation1="\t", const char *separation2="\n"); + //returns the itemized text pair by pair. Maximum length for buffers is 256. + //Return value is false if and only if the end of the list is reached. + //The argument valid indicates whether the buffers contain valid content. + bool getTextItemized(Loop::Iterator &it, bool &valid, char *itemDescription, char *itemText); }; class TimeShiftedEventDescriptor : public Descriptor { diff --git a/libsi/si.c b/libsi/si.c index ee64802..9ce46f0 100644 --- a/libsi/si.c +++ b/libsi/si.c @@ -6,7 +6,7 @@ * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * - * $Id: si.c 1.8 2004/02/22 10:14:12 kls Exp $ + * $Id: si.c 1.9 2004/03/07 10:50:09 kls Exp $ * * ***************************************************************************/ @@ -103,7 +103,7 @@ DescriptorTag Descriptor::getDescriptorTag(const unsigned char *d) { Descriptor *DescriptorLoop::getNext(Iterator &it) { if (it.igetDescriptorTag()==UnimplementedDescriptorTag) - return returnUnimplemetedDescriptor ? d : 0; return d; } -Descriptor *DescriptorLoop::getNext(Iterator &it, DescriptorTag *tags, int arrayLength, bool returnUnimplemetedDescriptor) { +Descriptor *DescriptorLoop::getNext(Iterator &it, DescriptorTag *tags, int arrayLength, bool returnUnimplementedDescriptor) { Descriptor *d=0; if (it.igetDescriptorTag()==UnimplementedDescriptorTag) - return returnUnimplemetedDescriptor ? d : 0; return d; } -Descriptor *DescriptorLoop::createDescriptor(int &i) { - Descriptor *d=Descriptor::getDescriptor(data+i, domain); +Descriptor *DescriptorLoop::createDescriptor(int &i, bool returnUnimplemetedDescriptor) { + Descriptor *d=Descriptor::getDescriptor(data+i, domain, returnUnimplemetedDescriptor); + if (!d) + return 0; i+=d->getLength(); d->CheckParse(); return d; } +int DescriptorLoop::getNumberOfDescriptors() { + const unsigned char *p=data.getData(); + const unsigned char *end=p+getLength(); + int count=0; + while (p < end) { + count++; + p+=Descriptor::getLength(p); + } + return count; +} + DescriptorGroup::DescriptorGroup(bool del) { array=0; length=0; @@ -211,6 +221,16 @@ char *String::getText(char *buffer) { return buffer; } +//taken from VDR, Copyright Klaus Schmidinger +char *String::getText(char *buffer, char *shortVersion) { + if (getLength() < 0 || getLength() >4095) { + strncpy(buffer, "text error", getLength()+1); + return buffer; + } + decodeText(buffer, shortVersion); + return buffer; +} + //taken from libdtv, Copyright Rolf Hakenes void String::decodeText(char *buffer) { const unsigned char *from=data.getData(0); @@ -228,18 +248,47 @@ void String::decodeText(char *buffer) { if ( ((' ' <= *from) && (*from <= '~')) || (*from == '\n') || (0xA0 <= *from) + || (*from == 0x86 || *from == 0x87) ) *to++ = *from; else if (*from == 0x8A) *to++ = '\n'; - else if (*from == 0x86 || *from == 0x87) //&& !(GDT_NAME_DESCRIPTOR & type)) + from++; + } + *to = '\0'; +} + +void String::decodeText(char *buffer, char *shortVersion) { + const unsigned char *from=data.getData(0); + char *to=buffer; + char *toShort=shortVersion; + int IsShortName=0; + + for (int i = 0; i < getLength(); i++) { + if (*from == 0) + break; + if ( ((' ' <= *from) && (*from <= '~')) + || (*from == '\n') + || (0xA0 <= *from) + ) + { *to++ = *from; + if (IsShortName) + *toShort++ = *from; + } + else if (*from == 0x8A) + *to++ = '\n'; + else if (*from == 0x86) + IsShortName++; + else if (*from == 0x87) + IsShortName--; from++; } *to = '\0'; + *toShort = '\0'; } -Descriptor *Descriptor::getDescriptor(CharArray da, DescriptorTagDomain domain) { +Descriptor *Descriptor::getDescriptor(CharArray da, DescriptorTagDomain domain, bool returnUnimplemetedDescriptor) { Descriptor *d=0; switch (domain) { case SI: @@ -383,6 +432,8 @@ Descriptor *Descriptor::getDescriptor(CharArray da, DescriptorTagDomain domain) case AdaptationFieldDataDescriptorTag: case TransportStreamDescriptorTag: default: + if (!returnUnimplemetedDescriptor) + return 0; d=new UnimplementedDescriptor(); break; } @@ -417,6 +468,8 @@ Descriptor *Descriptor::getDescriptor(CharArray da, DescriptorTagDomain domain) case MHP_DelegatedApplicationDescriptorTag: case MHP_ApplicationStorageDescriptorTag: default: + if (!returnUnimplemetedDescriptor) + return 0; d=new UnimplementedDescriptor(); break; } diff --git a/libsi/si.h b/libsi/si.h index befff85..195830d 100644 --- a/libsi/si.h +++ b/libsi/si.h @@ -6,7 +6,7 @@ * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * - * $Id: si.h 1.8 2004/02/23 17:02:33 kls Exp $ + * $Id: si.h 1.9 2004/03/07 10:09:49 kls Exp $ * * ***************************************************************************/ @@ -252,8 +252,11 @@ protected: //returns a subclass of descriptor according to the data given. //The object is allocated with new and must be delete'd. //setData() will have been called, CheckParse() not. - //Never returns null - maybe the UnimplementedDescriptor. - static Descriptor *getDescriptor(CharArray d, DescriptorTagDomain domain); + //if returnUnimplemetedDescriptor==true: + // Never returns null - maybe the UnimplementedDescriptor. + //if returnUnimplemetedDescriptor==false: + // Never returns the UnimplementedDescriptor - maybe null + static Descriptor *getDescriptor(CharArray d, DescriptorTagDomain domain, bool returnUnimplemetedDescriptor); }; class Loop : public VariableLengthPart { @@ -266,6 +269,7 @@ public: template friend class StructureLoop; friend class DescriptorLoop; template friend class TypeLoop; + friend class ExtendedEventDescriptors; int i; }; protected: @@ -311,14 +315,46 @@ public: //returns null if no more descriptors available Descriptor *getNext(Iterator &it); //return the next descriptor with given tag, or 0 if not available. - //if the descriptor found is not implemented, - // an UnimplementedDescriptor will be returned if returnUnimplemetedDescriptor==true, - // 0 will be returned if returnUnimplemetedDescriptor==false + //if returnUnimplemetedDescriptor==true: + // an UnimplementedDescriptor may be returned if the next matching descriptor is unimplemented, + // 0 will be returned if and only if no matching descriptor is found. + //if returnUnimplemetedDescriptor==false: + // if 0 is returned, either no descriptor with the given tag was found, + // or descriptors were found, but the descriptor type is not implemented + //In either case, a return value of 0 indicates that no further calls to this method + //with the iterator shall be made. Descriptor *getNext(Iterator &it, DescriptorTag tag, bool returnUnimplemetedDescriptor=false); //return the next descriptor with one of the given tags, or 0 if not available. + //if returnUnimplemetedDescriptor==true: + // returns 0 if and only if no descriptor with one of the given tags was found. + // The UnimplementedDescriptor may be returned. + //if returnUnimplemetedDescriptor==false: + // if 0 is returned, either no descriptor with one of the given tags was found, + // or descriptors were found, but none of them are implemented. + // The UnimplementedDescriptor will never be returned. + //In either case, a return value of 0 indicates that no further calls to this method + //with the iterator shall be made. Descriptor *getNext(Iterator &it, DescriptorTag *tags, int arrayLength, bool returnUnimplemetedDescriptor=false); + //returns the number of descriptors in this loop + int getNumberOfDescriptors(); + //writes the tags of the descriptors in this loop in the array, + // which must at least have the size getNumberOfDescriptors(). + //The number of descriptors, i.e. getNumberOfDescriptors(), is returned. + // You can specify the array type (Descriptor tags are 8 Bit, + // you might e.g. choose a char, short, int or DescriptorTag array) + template int getDescriptorTags(T *tags) + { + const unsigned char *p=data.getData(); + const unsigned char *end=p+getLength(); + int count=0; + while (p < end) { + tags[count++]=(T)Descriptor::getDescriptorTag(p); + p+=Descriptor::getLength(p); + } + return count; + } protected: - Descriptor *createDescriptor(int &i); + Descriptor *createDescriptor(int &i, bool returnUnimplemetedDescriptor); DescriptorTagDomain domain; }; @@ -385,7 +421,7 @@ class String : public VariableLengthPart { public: //A note to the length: getLength() returns the length of the raw data. //The text may be shorter. Its length can be obtained with one of the - //above functions and strlen. + //getText functions and strlen. //returns text. Data is allocated with new and must be delete'd by the user. char *getText(); @@ -394,10 +430,19 @@ public: //In most descriptors the string length is an 8-bit field, //so the maximum there is 256. //returns the given buffer for convenience. - char * getText(char *buffer); + //The emphasis marks 0x86 and 0x87 are still available. + char *getText(char *buffer); + //The same semantics as for getText(char*) apply. + //The short version of the text according to ETSI TR 101 211 (chapter 4.6) + //will be written into the shortVersion buffer (which should, therefore, have the same + //length as buffer). If no shortVersion is available, shortVersion will contain + //an empty string. + //The emphasis marks 0x86 and 0x87 are still available in buffer, but not in shortVersion. + char *getText(char *buffer, char *shortVersion); protected: virtual void Parse() {} void decodeText(char *buffer); + void decodeText(char *buffer, char *shortVersion); }; } //end of namespace -- cgit v1.2.3