]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
tsdebug: fix compilation
authorJaroslav Kysela <perex@perex.cz>
Tue, 30 May 2017 11:53:02 +0000 (13:53 +0200)
committerJaroslav Kysela <perex@perex.cz>
Tue, 30 May 2017 11:53:02 +0000 (13:53 +0200)
src/descrambler/caclient.h
src/descrambler/descrambler.c
src/descrambler/tsdebugcw.c
src/input/mpegts/mpegts_input.c

index d7db76512646daa7b33e551b800d9c40e7f0440f..b02c6349d4893a6a4cef357e08dba9373cf6dd17 100644 (file)
@@ -78,7 +78,7 @@ void caclient_init(void);
 void caclient_done(void);
 
 void tsdebugcw_service_start(struct service *t);
-void tsdebugcw_new_keys(struct service *t, int type, uint8_t *odd, uint8_t *even);
+void tsdebugcw_new_keys(struct service *t, int type, uint16_t pid, uint8_t *odd, uint8_t *even);
 void tsdebugcw_go(void);
 void tsdebugcw_init(void);
 
index 24dcec58672b7becbd8ea68587c8b79fcffb2a6a..5c35aeb415437762b397afee8f39a23a50775cd9 100644 (file)
@@ -619,19 +619,22 @@ descrambler_keys ( th_descrambler_t *td, int type, uint16_t pid,
   }
 
 fin:
-  pthread_mutex_unlock(&t->s_stream_mutex);
 #if ENABLE_TSDEBUG
   if (j) {
     tsdebug_packet_t *tp = malloc(sizeof(*tp));
     uint16_t keylen = tk->key_csa.csa_keylen;
-    uint16_t sid = ((mpegts_service_t *)td->td_service)->s_dvb_service_id;
+    mpegts_service_t *ms = (mpegts_service_t *)t;
+    uint16_t sid = ms->s_dvb_service_id;
     uint32_t pos = 0, crc;
-    mpegts_mux_t *mm = ((mpegts_service_t *)td->td_service)->s_dvb_mux;
-    if (!mm->mm_active) {
+    mpegts_mux_t *mm = ms->s_dvb_mux;
+    mpegts_mux_instance_t *mmi = mm ? mm->mm_active : NULL;
+    mpegts_input_t *mi = mmi ? mmi->mmi_input : NULL;
+    if (mi == NULL) {
       free(tp);
       return;
-       }
-    pthread_mutex_lock(&mm->mm_active->mmi_input->mi_output_lock);
+    }
+    pthread_mutex_unlock(&t->s_stream_mutex);
+    pthread_mutex_lock(&mi->mi_output_lock);
     tp->pos = mm->mm_tsdebug_pos;
     memset(tp->pkt, 0xff, sizeof(tp->pkt));
     tp->pkt[pos++] = 0x47; /* sync byte */
@@ -655,9 +658,11 @@ fin:
     tp->pkt[pos++] = (crc >> 8) & 0xff;
     tp->pkt[pos++] = crc & 0xff;
     TAILQ_INSERT_HEAD(&mm->mm_tsdebug_packets, tp, link);
-    pthread_mutex_unlock(&mm->mm_active->mmi_input->mi_output_lock);
+    pthread_mutex_unlock(&mi->mi_output_lock);
+    return;
   }
 #endif
+  pthread_mutex_unlock(&t->s_stream_mutex);
 }
 
 void
index c50230f5b872eb6250cafbe1d625b650ec4d26fb..b42449ac12a1ff76c96338423f8ff24400edc820 100644 (file)
@@ -29,6 +29,7 @@ typedef struct tsdebugcw_service {
   th_descrambler_t;
 
   int        tdcw_type;
+  uint16_t   tdcw_pid;
   uint8_t    tdcw_key_even[16];   /* DES or AES key */
   uint8_t    tdcw_key_odd [16];   /* DES or AES key */
 
@@ -109,13 +110,13 @@ tsdebugcw_service_start(service_t *t)
  *
  */
 void
-tsdebugcw_new_keys(service_t *t, int type, uint8_t *odd, uint8_t *even)
+tsdebugcw_new_keys(service_t *t, int type, uint16_t pid, uint8_t *odd, uint8_t *even)
 {
   static char empty[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
   th_descrambler_t *td;
   tsdebugcw_service_t *ct;
   tsdebugcw_request_t *ctr;
-  int keylen = type == DESCRAMBLER_AES ? 16 : 8;
+  int keylen = type == DESCRAMBLER_AES_ECB ? 16 : 8;
 
   LIST_FOREACH(td, &t->s_descramblers, td_service_link)
     if (td->td_stop == tsdebugcw_service_destroy)
@@ -124,9 +125,10 @@ tsdebugcw_new_keys(service_t *t, int type, uint8_t *odd, uint8_t *even)
     return;
   ct = (tsdebugcw_service_t *)td;
   ct->tdcw_type = type;
-  if (memcmp(empty, odd, keylen))
+  ct->tdcw_pid = pid;
+  if (odd && memcmp(empty, odd, keylen))
     memcpy(ct->tdcw_key_odd, odd, keylen);
-  if (memcmp(empty, even, keylen))
+  if (even && memcmp(empty, even, keylen))
     memcpy(ct->tdcw_key_even, even, keylen);
   ctr = malloc(sizeof(*ctr));
   ctr->ct = ct;
@@ -152,7 +154,8 @@ tsdebugcw_go(void)
     pthread_mutex_unlock(&tsdebugcw_mutex);
     if (!ctr) break;
     ct = ctr->ct;
-    descrambler_keys((th_descrambler_t *)ct, ct->tdcw_type,
+    descrambler_keys((th_descrambler_t *)ct,
+                     ct->tdcw_type, ct->tdcw_pid,
                      ct->tdcw_key_odd, ct->tdcw_key_even);
     free(ctr);
   }
index e432f36b0681e7e50131bfec455297e2dd328d54..fff35f4f2d9b1f338eaf2e688c6ef7d53ece9b7d 100644 (file)
@@ -1278,8 +1278,9 @@ mpegts_input_table_waiting ( mpegts_input_t *mi, mpegts_mux_t *mm )
 static void
 tsdebug_check_tspkt( mpegts_mux_t *mm, uint8_t *pkt, int len )
 {
-  void tsdebugcw_new_keys(service_t *t, int type, uint8_t *odd, uint8_t *even);
+  void tsdebugcw_new_keys(service_t *t, int type, uint16_t pid, uint8_t *odd, uint8_t *even);
   uint32_t pos, type, keylen, sid, crc;
+  uint16_t pid;
   mpegts_service_t *t;
 
   for ( ; len > 0; pkt += 188, len -= 188) {
@@ -1301,9 +1302,9 @@ tsdebug_check_tspkt( mpegts_mux_t *mm, uint8_t *pkt, int len )
       if (t->s_dvb_service_id == sid) break;
     if (!t)
       return;
-    pos =  4 + 24 + 4;
+    pos = 4 + 24 + 4;
     tvhdebug(LS_DESCRAMBLER, "Keys from MPEG-TS source (PID 0x1FFF)!");
-    tsdebugcw_new_keys((service_t *)t, type, pkt + pos, pkt + pos + keylen);
+    tsdebugcw_new_keys((service_t *)t, type, pid, pkt + pos, pkt + pos + keylen);
   }
 }
 #endif