]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
tvhcsa: optimize offset check for incomplete packet in CSA descramble
authorJaroslav Kysela <perex@perex.cz>
Thu, 13 Sep 2018 13:10:11 +0000 (15:10 +0200)
committerJaroslav Kysela <perex@perex.cz>
Thu, 13 Sep 2018 17:15:39 +0000 (19:15 +0200)
src/descrambler/tvhcsa.c

index 5519f4f7597ca8bc7a56e5eea357da01057e44ea..3345e4c68f6e841d3da773cf7edf92972a6265c8 100644 (file)
@@ -99,10 +99,9 @@ tvhcsa_des_descramble
 
 #if ENABLE_DVBCSA
   uint8_t *pkt;
-  int ev_od;
-  int len;
-  int offset;
-  int n;
+  int_fast8_t ev_od;
+  int_fast16_t len;
+  int_fast16_t offset;
 
   for ( ; tsb < tsb_end; tsb += 188) {
 
@@ -110,26 +109,19 @@ tvhcsa_des_descramble
    memcpy(pkt, tsb, 188);
    csa->csa_fill++;
 
-   do { // handle this packet
-     if((pkt[3] & 0x80) == 0) // clear or reserved (0x40)
+   do {                        // handle this packet
+     if((pkt[3] & 0x80) == 0)  // clear or reserved (0x40)
        break;
      ev_od = pkt[3] & 0x40;
-     pkt[3] &= 0x3f;  // consider it decrypted now
-     if(pkt[3] & 0x20) { // incomplete packet
+     pkt[3] &= 0x3f;           // consider it decrypted now
+     if(pkt[3] & 0x20) {       // incomplete packet
        offset = 4 + pkt[4] + 1;
-       if (offset > 187) // invalid offset
-         break;
+       if (offset > 188-8)     // invalid offset (residue handling?)
+         break;                        // no more processing
        len = 188 - offset;
-       n = len >> 3;
-       // FIXME: //residue = len - (n << 3);
-       if(n == 0) { // decrypted==encrypted!
-         break; // this doesn't need more processing
-       }
      } else {
        len = 184;
        offset = 4;
-       // FIXME: //n = 23;
-       // FIXME: //residue = 0;
      }
      if(ev_od == 0) {
        csa->csa_tsbbatch_even[csa->csa_fill_even].data = pkt + offset;