]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
cclient: try to fix duplicate ECM requests for multiple sections, issue #4876
authorJaroslav Kysela <perex@perex.cz>
Sun, 21 Jan 2018 17:51:29 +0000 (18:51 +0100)
committerJaroslav Kysela <perex@perex.cz>
Sun, 21 Jan 2018 17:51:29 +0000 (18:51 +0100)
src/descrambler/cclient.c
src/descrambler/cclient.h

index cd31f87275c9174531126d080a3f5a0435e0699a..577f7f38cb080166c56b4a9bf62eae7ce45371c0 100644 (file)
@@ -45,6 +45,7 @@ static void
 cc_free_ecm_section(cc_ecm_section_t *es)
 {
   LIST_REMOVE(es, es_link);
+  free(es->es_data);
   free(es);
 }
 
@@ -280,8 +281,12 @@ cc_ecm_reset(th_descrambler_t *th)
   pthread_mutex_lock(&cc->cc_mutex);
   descrambler_change_keystate(th, DS_READY, 1);
   LIST_FOREACH(ep, &ct->cs_ecm_pids, ep_link)
-    LIST_FOREACH(es, &ep->ep_sections, es_link)
+    LIST_FOREACH(es, &ep->ep_sections, es_link) {
       es->es_keystate = ES_UNKNOWN;
+      free(es->es_data);
+      es->es_data = NULL;
+      es->es_data_len = 0;
+    }
   ct->ecm_state = ECM_RESET;
   pthread_mutex_unlock(&cc->cc_mutex);
   return 0;
@@ -300,8 +305,12 @@ cc_ecm_idle(th_descrambler_t *th)
 
   pthread_mutex_lock(&cc->cc_mutex);
   LIST_FOREACH(ep, &ct->cs_ecm_pids, ep_link)
-    LIST_FOREACH(es, &ep->ep_sections, es_link)
+    LIST_FOREACH(es, &ep->ep_sections, es_link) {
       es->es_keystate = ES_IDLE;
+      free(es->es_data);
+      es->es_data = NULL;
+      es->es_data_len = 0;
+    }
   ct->ecm_state = ECM_RESET;
   pthread_mutex_unlock(&cc->cc_mutex);
 }
@@ -927,6 +936,14 @@ found:
       es->es_section = section;
       LIST_INSERT_HEAD(&ep->ep_sections, es, es_link);
     }
+    if (es->es_data_len == len && memcmp(es->es_data, data, len) == 0)
+      goto end;
+    if (es->es_data_len < len) {
+      free(es->es_data);
+      es->es_data = malloc(len);
+    }
+    memcpy(es->es_data, data, len);
+    es->es_data_len = len;
 
     if(cc->cc_fd == -1) {
       // New key, but we are not connected (anymore), can not descramble
index 5674339b9face153ce6a55fef5cd14103b817d5c..9f68815812286520ce898cf6ad3edb33f8b13101 100644 (file)
@@ -43,6 +43,8 @@ typedef struct cc_ecm_section {
   } es_keystate;
 
   int      es_section;
+  uint8_t *es_data;
+  uint32_t es_data_len;
 
   uint32_t es_card_id;
   uint16_t es_capid;