]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Fix bug #6293 – Missing EIT EPG Content Type
authorDeltaMikeCharlie <127641886+DeltaMikeCharlie@users.noreply.github.com>
Wed, 9 Aug 2023 06:19:47 +0000 (16:19 +1000)
committerFlole998 <Flole998@users.noreply.github.com>
Wed, 9 Aug 2023 15:01:01 +0000 (17:01 +0200)
src/epggrab.h
src/epggrab/module/eit.c
src/epggrab/otamux.c

index 90346fdca7db240c479acc116b5733c6c935fdaa..5b33696e7d0c44686488baa018dc0a1ab5233821 100644 (file)
@@ -212,7 +212,7 @@ struct epggrab_module_int
 struct epggrab_module_ext
 {
   epggrab_module_int_t         ;          ///< Parent object
-  
+
   int                          sock;      ///< Socket descriptor
 
   pthread_t                    tid;       ///< Thread ID
@@ -239,7 +239,7 @@ struct epggrab_ota_mux
 {
   tvh_uuid_t                         om_mux_uuid;     ///< Soft-link to mux
   LIST_HEAD(,epggrab_ota_map)        om_modules;      ///< List of linked mods
-  
+
   uint8_t                            om_done;         ///< The full completion mark for this round
   uint8_t                            om_complete;     ///< Has completed a scan
   uint8_t                            om_requeue;      ///< Requeue when stolen
@@ -403,7 +403,7 @@ const char *epggrab_ota_check_module_id( const char *id );
 /*
  * Global variable for genre translation
  */
-extern unsigned char                epggrab_ota_genre_translation[256];
+extern unsigned char                *epggrab_ota_genre_translation;
 
 #endif /* __EPGGRAB_H__ */
 
index 4ae2b126f72172f51414b703137cfae9d73c2f31..63df1b154585de12548796ef0e2bc96842693ddd 100644 (file)
@@ -113,7 +113,7 @@ typedef struct eit_event
 {
   char              uri[529];
   char              suri[529];
-  
+
   lang_str_t       *title;
   lang_str_t       *subtitle;
   lang_str_t       *summary;
@@ -155,7 +155,7 @@ static void _eit_done(void *mod);
 
 // Dump a descriptor tag for debug (looking for new tags etc...)
 static void
-_eit_dtag_dump 
+_eit_dtag_dump
   ( epggrab_module_t *mod, uint8_t dtag, uint8_t dlen, const uint8_t *buf )
 {
 #if APS_DEBUG
@@ -187,7 +187,7 @@ static dvb_string_conv_t _eit_freesat_conv[2] = {
  */
 static int _eit_get_string_with_len
   ( epggrab_module_t *mod,
-    char *dst, size_t dstlen, 
+    char *dst, size_t dstlen,
     const uint8_t *src, size_t srclen, const char *charset )
 {
   epggrab_module_ota_t *m = (epggrab_module_ota_t *)mod;
@@ -284,7 +284,7 @@ static int _eit_desc_ext_event
     if ( (r = _eit_get_string_with_len(mod, ikey, sizeof(ikey),
                                        iptr, ilen, ev->default_charset)) < 0 )
       break;
-    
+
     ilen -= r;
     iptr += r;
 
@@ -394,13 +394,17 @@ static int _eit_desc_content
   uint8_t tempPtr = 0;  //Temporary variable to hold a (potentially) changed *ptr value.
   tempPtr = *ptr;
   while (len > 1) {
-    //Get the potentially new genre value.
-    tempPtr = epggrab_ota_genre_translation[*ptr];
-    //If we did get a translation, write a trace for debugging.
-    if(tempPtr != *ptr)
-    {
-      tvhtrace(LS_TBL_EIT, "Translating '%d' to '%d'", *ptr, tempPtr);
-    }
+    //If the genre translation table has been loaded, it will not be a null pointer.
+    if (epggrab_ota_genre_translation){
+      //Get the potentially new genre value.
+      tempPtr = epggrab_ota_genre_translation[*ptr];
+      //If we did get a translation, write a trace for debugging.
+      if(tempPtr != *ptr)
+      {
+        tvhtrace(LS_TBL_EIT, "Translating '%d' (0x%02x) to '%d' (0x%02x)", *ptr, *ptr, tempPtr, tempPtr);
+      }
+    }//END genre translation table loaded.
+
     if (tempPtr == 0xb1)  //0xB1 is the genre code for 'Black and White'
       ev->bw = 1;
     else if (tempPtr < 0xb0) {  //0xB0 is the start of the 'Special Characteristics' block.
@@ -470,7 +474,7 @@ static int _eit_desc_crid
         crid = ev->suri;
         clen = sizeof(ev->suri);
       }
-    
+
       if (crid) {
         if (strstr(buf, "crid://") == buf) {
           strlcpy(crid, buf, clen);
@@ -1004,8 +1008,8 @@ _eit_callback
     mask <<= (24 - (sa % 32));
     st->sections[sa/32] &= ~mask;
   }
-  
-  /* UK Cable Virgin: EPG data for services in other transponders is transmitted 
+
+  /* UK Cable Virgin: EPG data for services in other transponders is transmitted
   // in the 'actual' transpoder table IDs */
   if ((hacks & EIT_HACK_EXTRAMUXLOOKUP) != 0 && (tableid == 0x50 || tableid == 0x4E)) {
     mm = mpegts_network_find_mux(mm->mm_network, onid, tsid, 1);
@@ -1106,7 +1110,7 @@ done:
 complete:
   if (ota && !r && (tableid >= 0x50 && tableid < 0x60))
     epggrab_ota_complete((epggrab_module_ota_t*)mod, ota);
-  
+
   return r;
 }
 
@@ -1249,7 +1253,7 @@ static int _eit_tune
     return 1;
 
   /* Check if any services are mapped */
-  // TODO: using indirect ref's like this is inefficient, should 
+  // TODO: using indirect ref's like this is inefficient, should
   //       consider changeing it?
   for (osl = RB_FIRST(&map->om_svcs); osl != NULL; osl = nxt) {
     nxt = RB_NEXT(osl, link);
index 953009479383c655bbd15f1521a4895d67320226..aa7d94c81bb794246ed0e3f39ae5d4c766c73cb1 100644 (file)
@@ -56,7 +56,8 @@ int                          epggrab_ota_pending_flag;
 
 tvh_mutex_t                  epggrab_ota_mutex;
 
-unsigned char                epggrab_ota_genre_translation[256];
+//If the pointer is not null, translation values have also been loaded.
+unsigned char                *epggrab_ota_genre_translation = NULL;
 
 SKEL_DECLARE(epggrab_ota_mux_skel, epggrab_ota_mux_t);
 SKEL_DECLARE(epggrab_svc_link_skel, epggrab_ota_svc_link_t);
@@ -423,7 +424,7 @@ epggrab_ota_register
       save = 1;
     }
   }
-  
+
   /* Find module map */
   map = epggrab_ota_find_map(ota, mod);
   if (!map) {
@@ -869,7 +870,7 @@ epggrab_ota_load_one
   epggrab_ota_mux_t *ota;
   epggrab_ota_map_t *map;
   const char *id;
-  
+
   mm = mpegts_mux_find(uuid);
   if (!mm) {
     hts_settings_remove("epggrab/otamux/%s", uuid);
@@ -885,14 +886,14 @@ epggrab_ota_load_one
     return;
   }
   ota->om_complete = htsmsg_get_u32_or_default(c, "complete", 0) != 0;
-  
+
   if (!(l = htsmsg_get_list(c, "modules"))) return;
   HTSMSG_FOREACH(f, l) {
     if (!(e   = htsmsg_field_get_map(f))) continue;
     if (!(id  = htsmsg_get_str(e, "id"))) continue;
     if (!(mod = (epggrab_module_ota_t*)epggrab_module_find_by_id(id)))
       continue;
-    
+
     map = calloc(1, sizeof(epggrab_ota_map_t));
     RB_INIT(&map->om_svcs);
     map->om_module   = mod;
@@ -941,12 +942,12 @@ epggrab_ota_init ( void )
       hts_settings_remove("epggrab/otamux");
 
   atomic_set(&epggrab_ota_running, 1);
-  
+
   /* Load config */
   if ((c = hts_settings_load_r(1, "epggrab/otamux"))) {
     HTSMSG_FOREACH(f, c) {
       if (!(m  = htsmsg_field_get_map(f))) continue;
-      epggrab_ota_load_one(htsmsg_field_name(f), m); 
+      epggrab_ota_load_one(htsmsg_field_name(f), m);
     }
     htsmsg_destroy(c);
   }
@@ -1052,8 +1053,24 @@ epggrab_ota_set_genre_translation ( void )
   lock_assert(&global_lock);
   tvh_mutex_lock(&epggrab_ota_mutex);
 
+  //Allocate storage for the translation table.
+  //The pointer is initialised as NULL.  If this function is not triggered
+  //(no setting in the file), the pointer will not be set and the EIT code
+  //where the actual translation ccurs can check for a null pointer before
+  //trying to translate.
+  epggrab_ota_genre_translation = calloc(sizeof(unsigned char) * 256, 1);
+
+  //Test to see if the translation table got space allocated, if not,
+  //complain and then exit the function.
+  if (!epggrab_ota_genre_translation){
+    tvherror(LS_EPGGRAB, "Unable to allocate memory, genre translations disabled.");
+    tvh_mutex_unlock(&epggrab_ota_mutex);
+    return;
+  }
+
   //Reset the translation table to 1:1 here before proceeding.
-  for(int i = 0; i < 256; i++)
+  int i = 0;  //Bugfix, some platforms don't like the variable declaration within the FOR.
+  for(i = 0; i < 256; i++)
   {
     epggrab_ota_genre_translation[i] = i;
   }
@@ -1098,7 +1115,7 @@ epggrab_ota_set_genre_translation ( void )
         //Test that the to/from values are sane before proceeding.
         if(tempFrom > -1 && tempFrom < 256 && tempTo > -1 && tempTo < 256)
         {
-          tvhtrace(LS_EPGGRAB, "Valid translation from '%d' to '%d'.", tempFrom, tempTo);
+          tvhtrace(LS_EPGGRAB, "Valid translation from '%d' (0x%02x) to '%d' (0x%02x).", tempFrom, tempFrom, tempTo, tempTo);
           epggrab_ota_genre_translation[tempFrom] = tempTo;
         }
         else
@@ -1111,7 +1128,8 @@ epggrab_ota_set_genre_translation ( void )
     }
   }
 
-  for(int x = 0; x < 256; x++)
+  int x = 0;
+  for(x = 0; x < 256; x++)
   {
     if(epggrab_ota_genre_translation[x] != x)
     {