]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
cwc: Use only one fastest ECM reader
authorJaroslav Kysela <perex@perex.cz>
Thu, 12 Apr 2012 12:35:06 +0000 (14:35 +0200)
committerJaroslav Kysela <perex@perex.cz>
Thu, 12 Apr 2012 12:47:57 +0000 (14:47 +0200)
Use only one - fastest - ECM reader when multiple CA readers/cards are
available for one program.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
src/cwc.c

index 7db2309998da0a374ef120b1d2035a37886c6e2f..9be063c64d2e5dc2a4e545d4b2455ac6133e5392 100644 (file)
--- a/src/cwc.c
+++ b/src/cwc.c
@@ -151,7 +151,8 @@ typedef struct cwc_service {
   enum {
     CS_UNKNOWN,
     CS_RESOLVED,
-    CS_FORBIDDEN
+    CS_FORBIDDEN,
+    CS_IDLE
   } cs_keystate;
 
   void *cs_keys;
@@ -742,6 +743,8 @@ handle_ecm_reply(cwc_service_t *ct, ecm_section_t *es, uint8_t *msg,
                 int len, int seq)
 {
   service_t *t = ct->cs_service;
+  cwc_service_t *ct2;
+  cwc_t *cwc2;
   ecm_pid_t *ep;
   char chaninfo[32];
   int i;
@@ -800,12 +803,25 @@ handle_ecm_reply(cwc_service_t *ct, ecm_section_t *es, uint8_t *msg,
           msg[3 + 5], msg[3 + 6], msg[3 + 7], msg[3 + 8], msg[3 + 9],
           msg[3 + 10],msg[3 + 11],msg[3 + 12],msg[3 + 13],msg[3 + 14],
           msg[3 + 15], seq, delay);
+
+    TAILQ_FOREACH(cwc2, &cwcs, cwc_link) {
+      LIST_FOREACH(ct2, &cwc2->cwc_services, cs_link) {
+        if (ct != ct2 && ct2->cs_service == t &&
+            ct2->cs_keystate == CS_RESOLVED) {
+          ct->cs_keystate = CS_IDLE;
+          tvhlog(LOG_DEBUG, "cwc",
+            "Already has a key for service \"%s\", from %s:%i",
+            t->s_svcname, ct2->cs_cwc->cwc_hostname, ct2->cs_cwc->cwc_port);
+          return;
+        }
+      }
+    }
     
     if(ct->cs_keystate != CS_RESOLVED)
       tvhlog(LOG_INFO, "cwc",
             "Obtained key for for service \"%s\" in %lld ms, from %s",
             t->s_svcname, delay, ct->cs_cwc->cwc_hostname);
-    
+
     ct->cs_keystate = CS_RESOLVED;
     memcpy(ct->cs_cw, msg + 3, 16);
     ct->cs_pending_cw_update = 1;
@@ -1519,6 +1535,9 @@ cwc_table_input(struct th_descrambler *td, struct service *t,
   char chaninfo[32];
   caid_t *c;
 
+  if (ct->cs_keystate == CS_IDLE)
+    return;
+
   if(len > 4096)
     return;