Exemplo n.º 1
0
Arquivo: si.c Projeto: suborb/reelvdr
void String::decodeText(char *buffer, int size, const char* charset) {
#else
void String::decodeText(char *buffer, int size) {
#endif
   const unsigned char *from=data.getData(0);
   char *to=buffer;
   int len=getLength();
   if (len <= 0) {
      *to = '\0';
      return;
      }
   bool singleByte;

   if ( from[0] == 0x1f ) {
       char *temp = freesat_huffman_decode(from, len);
       if (temp ) {
           len = strlen(temp);
           len = len < size - 1 ? len : size - 1;
           strncpy(buffer, temp, len);
           buffer[len] = 0;
           free(temp);
          return;
       }
   }
#ifdef USE_PROVIDERCHARSET
const char* cs;
if (charset)
	cs = charset;
else
	cs = getCharacterTable(from, len, &singleByte);
#else
   const char *cs = getCharacterTable(from, len, &singleByte);
#endif
   // FIXME Need to make this UTF-8 aware (different control codes).
   // However, there's yet to be found a broadcaster that actually
   // uses UTF-8 for the SI data... (kls 2007-06-10)
   for (int i = 0; i < len; i++) {
      if (*from == 0)
         break;
      if (    ((' ' <= *from) && (*from <= '~'))
           || (*from == '\n')
           || (0xA0 <= *from)
         )
         *to++ = *from;
      else if (*from == 0x8A)
         *to++ = '\n';
      from++;
      if (to - buffer >= size - 1)
         break;
   }
   *to = '\0';
   if (!singleByte || !SystemCharacterTableIsSingleByte) {
      char convBuffer[size];
      if (convertCharacterTable(buffer, strlen(buffer), convBuffer, sizeof(convBuffer), cs))
         strncpy(buffer, convBuffer, strlen(convBuffer) + 1);
   }
}

#ifdef USE_PROVIDERCHARSET
void String::decodeText(char *buffer, char *shortVersion, int sizeBuffer, int sizeShortVersion, const char* charset) {
#else
void String::decodeText(char *buffer, char *shortVersion, int sizeBuffer, int sizeShortVersion) {
#endif
   const unsigned char *from=data.getData(0);
   unsigned char *temp = NULL;
   char *to=buffer;
   char *toShort=shortVersion;
   int IsShortName=0;
   int len=getLength();
   if (len <= 0) {
      *to = '\0';
      *toShort = '\0';
      return;
      }


   if ( from[0] == 0x1f ) {
       temp = ( unsigned char *)freesat_huffman_decode(from, len);
       from = temp;
   }


   bool singleByte;
#ifdef USE_PROVIDERCHARSET
const char* cs;
if (charset)
	cs = charset;
else
	cs = getCharacterTable(from, len, &singleByte);
#else
   const char *cs = getCharacterTable(from, len, &singleByte);
#endif
   // FIXME Need to make this UTF-8 aware (different control codes).
   // However, there's yet to be found a broadcaster that actually
   // uses UTF-8 for the SI data... (kls 2007-06-10)
   for (int i = 0; i < len; i++) {
      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--;
      else if (*from == 0)
         break;
      from++;
      if (to - buffer >= sizeBuffer - 1 || toShort - shortVersion >= sizeShortVersion - 1)
         break;
   }
   *to = '\0';
   *toShort = '\0';
   if (!singleByte || !SystemCharacterTableIsSingleByte) {
      char convBuffer[sizeBuffer];
      if (convertCharacterTable(buffer, strlen(buffer), convBuffer, sizeof(convBuffer), cs))
         strncpy(buffer, convBuffer, strlen(convBuffer) + 1);
      char convShortVersion[sizeShortVersion];
      if (convertCharacterTable(shortVersion, strlen(shortVersion), convShortVersion, sizeof(convShortVersion), cs))
         strncpy(shortVersion, convShortVersion, strlen(convShortVersion) + 1);
   }
   if (temp) free(temp);
}

Descriptor *Descriptor::getDescriptor(CharArray da, DescriptorTagDomain domain, bool returnUnimplemetedDescriptor) {
   Descriptor *d=0;
   switch (domain) {
   case SI:
      switch ((DescriptorTag)da.getData<DescriptorHeader>()->descriptor_tag) {
         case CaDescriptorTag:
            d=new CaDescriptor();
            break;
         case CarouselIdentifierDescriptorTag:
            d=new CarouselIdentifierDescriptor();
            break;
         case NetworkNameDescriptorTag:
            d=new NetworkNameDescriptor();
            break;
         case ServiceListDescriptorTag:
            d=new ServiceListDescriptor();
            break;
         case SatelliteDeliverySystemDescriptorTag:
            d=new SatelliteDeliverySystemDescriptor();
            break;
         case CableDeliverySystemDescriptorTag:
            d=new CableDeliverySystemDescriptor();
            break;
         case TerrestrialDeliverySystemDescriptorTag:
            d=new TerrestrialDeliverySystemDescriptor();
            break;
         case BouquetNameDescriptorTag:
            d=new BouquetNameDescriptor();
            break;
         case ServiceDescriptorTag:
            d=new ServiceDescriptor();
            break;
         case NVODReferenceDescriptorTag:
            d=new NVODReferenceDescriptor();
            break;
         case TimeShiftedServiceDescriptorTag:
            d=new TimeShiftedServiceDescriptor();
            break;
         case ComponentDescriptorTag:
            d=new ComponentDescriptor();
            break;
         case StreamIdentifierDescriptorTag:
            d=new StreamIdentifierDescriptor();
            break;
         case SubtitlingDescriptorTag:
            d=new SubtitlingDescriptor();
            break;
         case MultilingualNetworkNameDescriptorTag:
            d=new MultilingualNetworkNameDescriptor();
            break;
         case MultilingualBouquetNameDescriptorTag:
            d=new MultilingualBouquetNameDescriptor();
            break;
         case MultilingualServiceNameDescriptorTag:
            d=new MultilingualServiceNameDescriptor();
            break;
         case MultilingualComponentDescriptorTag:
            d=new MultilingualComponentDescriptor();
            break;
         case PrivateDataSpecifierDescriptorTag:
            d=new PrivateDataSpecifierDescriptor();
            break;
         case ServiceMoveDescriptorTag:
            d=new ServiceMoveDescriptor();
            break;
         case FrequencyListDescriptorTag:
            d=new FrequencyListDescriptor();
            break;
         case ServiceIdentifierDescriptorTag:
            d=new ServiceIdentifierDescriptor();
            break;
         case CaIdentifierDescriptorTag:
            d=new CaIdentifierDescriptor();
            break;
         case ShortEventDescriptorTag:
            d=new ShortEventDescriptor();
            break;
         case ExtendedEventDescriptorTag:
            d=new ExtendedEventDescriptor();
            break;
         case TimeShiftedEventDescriptorTag:
            d=new TimeShiftedEventDescriptor();
            break;
         case ContentDescriptorTag:
            d=new ContentDescriptor();
            break;
         case ParentalRatingDescriptorTag:
            d=new ParentalRatingDescriptor();
            break;
         case TeletextDescriptorTag:
         case VBITeletextDescriptorTag:
            d=new TeletextDescriptor();
            break;
         case ApplicationSignallingDescriptorTag:
            d=new ApplicationSignallingDescriptor();
            break;
         case LocalTimeOffsetDescriptorTag:
            d=new LocalTimeOffsetDescriptor();
            break;
         case LinkageDescriptorTag:
            d=new LinkageDescriptor();
            break;
         case ISO639LanguageDescriptorTag:
            d=new ISO639LanguageDescriptor();
            break;
         case PDCDescriptorTag:
            d=new PDCDescriptor();
            break;
         case AncillaryDataDescriptorTag:
            d=new AncillaryDataDescriptor();
            break;
         case S2SatelliteDeliverySystemDescriptorTag:
            d=new S2SatelliteDeliverySystemDescriptor();
            break;
         case ExtensionDescriptorTag:
            d=new ExtensionDescriptor();
            break;
         case RegistrationDescriptorTag:
            d=new RegistrationDescriptor();
            break;
         case ContentIdentifierDescriptorTag:
            d=new ContentIdentifierDescriptor();
            break;
         case DefaultAuthorityDescriptorTag:
            d=new DefaultAuthorityDescriptor();
            break;

         //note that it is no problem to implement one
         //of the unimplemented descriptors.

         //defined in ISO-13818-1
         case VideoStreamDescriptorTag:
         case AudioStreamDescriptorTag:
         case HierarchyDescriptorTag:
         case DataStreamAlignmentDescriptorTag:
         case TargetBackgroundGridDescriptorTag:
         case VideoWindowDescriptorTag:
         case SystemClockDescriptorTag:
         case MultiplexBufferUtilizationDescriptorTag:
         case CopyrightDescriptorTag:
         case MaximumBitrateDescriptorTag:
         case PrivateDataIndicatorDescriptorTag:
         case SmoothingBufferDescriptorTag:
         case STDDescriptorTag:
         case IBPDescriptorTag:

         //defined in ETSI EN 300 468
         case StuffingDescriptorTag:
         case VBIDataDescriptorTag:
         case CountryAvailabilityDescriptorTag:
         case MocaicDescriptorTag:
         case TelephoneDescriptorTag:
         case CellListDescriptorTag:
         case CellFrequencyLinkDescriptorTag:
         case ServiceAvailabilityDescriptorTag:
         case ShortSmoothingBufferDescriptorTag:
         case PartialTransportStreamDescriptorTag:
         case DataBroadcastDescriptorTag:
         case DataBroadcastIdDescriptorTag:
         case ScramblingDescriptorTag:
         case AC3DescriptorTag:
         case DSNGDescriptorTag:
         case AnnouncementSupportDescriptorTag:
         case AdaptationFieldDataDescriptorTag:
         case TransportStreamDescriptorTag:

         //defined in ETSI EN 300 468 v 1.7.1
         case RelatedContentDescriptorTag:
         case TVAIdDescriptorTag:
         case TimeSliceFecIdentifierDescriptorTag:
         case ECMRepetitionRateDescriptorTag:
         case EnhancedAC3DescriptorTag:
         case DTSDescriptorTag:
         case AACDescriptorTag:
         default:
            if (!returnUnimplemetedDescriptor)
               return 0;
            d=new UnimplementedDescriptor();
            break;
      }
      break;
   case MHP:
      switch ((DescriptorTag)da.getData<DescriptorHeader>()->descriptor_tag) {
      // They once again start with 0x00 (see page 234, MHP specification)
         case MHP_ApplicationDescriptorTag:
            d=new MHP_ApplicationDescriptor();
            break;
         case MHP_ApplicationNameDescriptorTag:
            d=new MHP_ApplicationNameDescriptor();
            break;
         case MHP_TransportProtocolDescriptorTag:
            d=new MHP_TransportProtocolDescriptor();
            break;
         case MHP_DVBJApplicationDescriptorTag:
            d=new MHP_DVBJApplicationDescriptor();
            break;
         case MHP_DVBJApplicationLocationDescriptorTag:
            d=new MHP_DVBJApplicationLocationDescriptor();
            break;
         case MHP_SimpleApplicationLocationDescriptorTag:
            d=new MHP_SimpleApplicationLocationDescriptor();
            break;
      // 0x05 - 0x0A is unimplemented this library
         case MHP_ExternalApplicationAuthorisationDescriptorTag:
         case MHP_IPv4RoutingDescriptorTag:
         case MHP_IPv6RoutingDescriptorTag:
         case MHP_DVBHTMLApplicationDescriptorTag:
         case MHP_DVBHTMLApplicationLocationDescriptorTag:
         case MHP_DVBHTMLApplicationBoundaryDescriptorTag:
         case MHP_ApplicationIconsDescriptorTag:
         case MHP_PrefetchDescriptorTag:
         case MHP_DelegatedApplicationDescriptorTag:
         case MHP_ApplicationStorageDescriptorTag:
         default:
            if (!returnUnimplemetedDescriptor)
               return 0;
            d=new UnimplementedDescriptor();
            break;
      }
      break;
   case PCIT:
      switch ((DescriptorTag)da.getData<DescriptorHeader>()->descriptor_tag) {
         case ContentDescriptorTag:
            d=new ContentDescriptor();
            break;
         case ShortEventDescriptorTag:
            d=new ShortEventDescriptor();
            break;
         case ExtendedEventDescriptorTag:
            d=new ExtendedEventDescriptor();
            break;
         case PremiereContentTransmissionDescriptorTag:
            d=new PremiereContentTransmissionDescriptor();
            break;
         default:
            if (!returnUnimplemetedDescriptor)
               return 0;
            d=new UnimplementedDescriptor();
            break;
      }
      break;
   default: ; // unknown domain, nothing to do
   }
   d->setData(da);
   return d;
}
Exemplo n.º 2
0
   if ( from[0] == 0x1f ) {
       char *temp = freesat_huffman_decode(from, len);
       if (temp ) {
           len = strlen(temp);
           len = len < size - 1 ? len : size - 1;
           strncpy(buffer, temp, len);
           buffer[len] = 0;
           free(temp);
           return;
       }
   }

   if ( from[0] == 0x1f ) {
       temp = ( unsigned char *)freesat_huffman_decode(from, len);
       from = temp;
   }

   if (temp) free(temp);