Advertisement
Guest User

Untitled

a guest
Sep 9th, 2014
928
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 23.00 KB | None | 0 0
  1. --- a/arib_std_b25.c    Sun Oct 21 19:38:02 2012 +0900
  2. +++ b/arib_std_b25.c    Wed Sep 10 06:15:32 2014 +0900
  3. @@ -25,12 +25,12 @@
  4.  } TS_STREAM_LIST;
  5.  
  6.  typedef struct {
  7. -  
  8. +
  9.     uint8_t          *pool;
  10.     uint8_t          *head;
  11.     uint8_t          *tail;
  12.     int32_t           max;
  13. -  
  14. +
  15.  } TS_WORK_BUFFER;
  16.  
  17.  typedef struct {
  18. @@ -88,7 +88,7 @@
  19.     int32_t            multi2_round;
  20.     int32_t            strip;
  21.     int32_t            emm_proc_on;
  22. -  
  23. +
  24.     int32_t            unit_size;
  25.  
  26.     int32_t            sbuf_offset;
  27. @@ -97,7 +97,7 @@
  28.     TS_SECTION_PARSER *cat;
  29.  
  30.     TS_STREAM_LIST     strm_pool;
  31. -  
  32. +
  33.     int32_t            p_count;
  34.     TS_PROGRAM        *program;
  35.  
  36. @@ -114,7 +114,7 @@
  37.  
  38.     TS_WORK_BUFFER     sbuf;
  39.     TS_WORK_BUFFER     dbuf;
  40. -  
  41. +
  42.  } ARIB_STD_B25_PRIVATE_DATA;
  43.  
  44.  typedef struct {
  45. @@ -329,13 +329,13 @@
  46.  ARIB_STD_B25 *create_arib_std_b25()
  47.  {
  48.     int n;
  49. -  
  50. +
  51.     ARIB_STD_B25 *r;
  52.     ARIB_STD_B25_PRIVATE_DATA *prv;
  53.  
  54.     n  = sizeof(ARIB_STD_B25_PRIVATE_DATA);
  55.     n += sizeof(ARIB_STD_B25);
  56. -  
  57. +
  58.     prv = (ARIB_STD_B25_PRIVATE_DATA *)calloc(1, n);
  59.     if(prv == NULL){
  60.         return NULL;
  61. @@ -558,51 +558,55 @@
  62.  
  63.     r = 0;
  64.  
  65. -   while( (curr+188) <= tail ){
  66. -      
  67. +   while( (curr+unit) <= tail ){
  68. +
  69.         if(curr[0] != 0x47){
  70.             p = resync_force(curr, tail, unit);
  71.             if(p == NULL){
  72. +               curr = tail;
  73.                 goto LAST;
  74.             }
  75.             curr = p;
  76.         }
  77. -      
  78. +
  79.         extract_ts_header(&hdr, curr);
  80.         crypt = hdr.transport_scrambling_control;
  81.         pid = hdr.pid;
  82.  
  83.         if(hdr.transport_error_indicator != 0){
  84.             /* bit error - append output buffer without parsing */
  85. -           if(!append_work_buffer(&(prv->dbuf), curr, 188)){
  86. +           if(!append_work_buffer(&(prv->dbuf), curr, unit)){
  87.                 r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY;
  88.                 goto LAST;
  89.             }
  90.             goto NEXT;
  91.         }
  92. -      
  93. +
  94.         if( (pid == 0x1fff) && (prv->strip) ){
  95. +           /* strip null(padding) stream */
  96.             goto NEXT;
  97.         }
  98. -      
  99. +
  100.         p = curr+4;
  101.         if(hdr.adaptation_field_control & 0x02){
  102.             p += (p[0]+1);
  103. -       }
  104. -       n = 188 - (p-curr);
  105. -       if( (n < 1) && ((n < 0) || (hdr.adaptation_field_control & 0x01)) ){
  106. -           /* broken packet */
  107. -           curr += 1;
  108. -           continue;
  109. +           n = unit - (p-curr);
  110. +           if( (n < 1) && ((n < 0) || (hdr.adaptation_field_control & 0x01)) ){
  111. +               /* broken packet */
  112. +               curr += 1;
  113. +               continue;
  114. +           }
  115. +       }else{
  116. +           n = unit - 4;
  117.         }
  118.  
  119.         if( (crypt != 0) &&
  120.             (hdr.adaptation_field_control & 0x01) ){
  121. -          
  122. +
  123.             if(prv->map[pid].type == PID_MAP_TYPE_OTHER){
  124.                 dec = (DECRYPTOR_ELEM *)(prv->map[pid].target);
  125.             }else if( (prv->map[pid].type == 0) &&
  126. -                 (prv->decrypt.count == 1) ){
  127. +                     (prv->decrypt.count == 1) ){
  128.                 dec = prv->decrypt.head;
  129.             }else{
  130.                 dec = NULL;
  131. @@ -612,6 +616,7 @@
  132.                 m = dec->m2->decrypt(dec->m2, crypt, p, n);
  133.                 if(m < 0){
  134.                     r = ARIB_STD_B25_ERROR_DECRYPT_FAILURE;
  135. +                   curr += unit;
  136.                     goto LAST;
  137.                 }
  138.                 curr[3] &= 0x3f;
  139. @@ -623,7 +628,7 @@
  140.             prv->map[pid].normal_packet += 1;
  141.         }
  142.  
  143. -       if(!append_work_buffer(&(prv->dbuf), curr, 188)){
  144. +       if(!append_work_buffer(&(prv->dbuf), curr, unit)){
  145.             r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY;
  146.             goto LAST;
  147.         }
  148. @@ -633,16 +638,19 @@
  149.             if( (dec == NULL) || (dec->ecm == NULL) ){
  150.                 /* this code will never execute */
  151.                 r = ARIB_STD_B25_ERROR_ECM_PARSE_FAILURE;
  152. +               curr += unit;
  153.                 goto LAST;
  154.             }
  155.             m = dec->ecm->put(dec->ecm, &hdr, p, n);
  156.             if(m < 0){
  157.                 r = ARIB_STD_B25_ERROR_ECM_PARSE_FAILURE;
  158. +               curr += unit;
  159.                 goto LAST;
  160.             }
  161.             m = dec->ecm->get_count(dec->ecm);
  162.             if(m < 0){
  163.                 r = ARIB_STD_B25_ERROR_ECM_PARSE_FAILURE;
  164. +               curr += unit;
  165.                 goto LAST;
  166.             }
  167.             if(m == 0){
  168. @@ -650,6 +658,7 @@
  169.             }
  170.             r = proc_ecm(dec, prv->bcas, prv->multi2_round);
  171.             if(r < 0){
  172. +               curr += unit;
  173.                 goto LAST;
  174.             }
  175.         }else if(prv->map[pid].type == PID_MAP_TYPE_PMT){
  176. @@ -657,16 +666,19 @@
  177.             if( (pgrm == NULL) || (pgrm->pmt == NULL) ){
  178.                 /* this code will never execute */
  179.                 r = ARIB_STD_B25_ERROR_PMT_PARSE_FAILURE;
  180. +               curr += unit;
  181.                 goto LAST;
  182.             }
  183.             m = pgrm->pmt->put(pgrm->pmt, &hdr, p, n);
  184.             if(m < 0){
  185.                 r = ARIB_STD_B25_ERROR_PMT_PARSE_FAILURE;
  186. +               curr += unit;
  187.                 goto LAST;
  188.             }
  189.             m = pgrm->pmt->get_count(pgrm->pmt);
  190.             if(m < 0){
  191.                 r = ARIB_STD_B25_ERROR_PMT_PARSE_FAILURE;
  192. +               curr += unit;
  193.                 goto LAST;
  194.             }
  195.             if(m == 0){
  196. @@ -674,6 +686,7 @@
  197.             }
  198.             r = proc_pmt(prv, pgrm);
  199.             if(r < 0){
  200. +               curr += unit;
  201.                 goto LAST;
  202.             }
  203.         }else if(prv->map[pid].type == PID_MAP_TYPE_EMM){
  204. @@ -683,18 +696,20 @@
  205.             if( prv->emm == NULL ){
  206.                 prv->emm = create_ts_section_parser();
  207.                 if(prv->emm == NULL){
  208. -                   r = ARIB_STD_B25_ERROR_EMM_PARSE_FAILURE;
  209. +                   r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY;
  210.                     goto LAST;
  211.                 }
  212.             }
  213.             m = prv->emm->put(prv->emm, &hdr, p, n);
  214.             if(m < 0){
  215.                 r = ARIB_STD_B25_ERROR_EMM_PARSE_FAILURE;
  216. +               curr += unit;
  217.                 goto LAST;
  218.             }
  219.             m = prv->emm->get_count(prv->emm);
  220.             if(m < 0){
  221.                 r = ARIB_STD_B25_ERROR_EMM_PARSE_FAILURE;
  222. +               curr += unit;
  223.                 goto LAST;
  224.             }
  225.             if(m == 0){
  226. @@ -702,6 +717,7 @@
  227.             }
  228.             r = proc_emm(prv);
  229.             if(r < 0){
  230. +               curr += unit;
  231.                 goto LAST;
  232.             }
  233.         }else if(pid == 0x0001){
  234. @@ -715,11 +731,13 @@
  235.             m = prv->cat->put(prv->cat, &hdr, p, n);
  236.             if(m < 0){
  237.                 r = ARIB_STD_B25_ERROR_CAT_PARSE_FAILURE;
  238. +               curr += unit;
  239.                 goto LAST;
  240.             }
  241.             m = prv->cat->get_count(prv->cat);
  242.             if(m < 0){
  243.                 r = ARIB_STD_B25_ERROR_CAT_PARSE_FAILURE;
  244. +               curr += unit;
  245.                 goto LAST;
  246.             }
  247.             if(m == 0){
  248. @@ -727,6 +745,7 @@
  249.             }
  250.             r = proc_cat(prv);
  251.             if(r < 0){
  252. +               curr += unit;
  253.                 goto LAST;
  254.             }
  255.         }else if(pid == 0x0000){
  256. @@ -740,11 +759,13 @@
  257.             m = prv->pat->put(prv->pat, &hdr, p, n);
  258.             if(m < 0){
  259.                 r = ARIB_STD_B25_ERROR_PAT_PARSE_FAILURE;
  260. +               curr += unit;
  261.                 goto LAST;
  262.             }
  263.             m = prv->pat->get_count(prv->pat);
  264.             if(m < 0){
  265.                 r = ARIB_STD_B25_ERROR_PAT_PARSE_FAILURE;
  266. +               curr += unit;
  267.                 goto LAST;
  268.             }
  269.             if(m == 0){
  270. @@ -752,21 +773,22 @@
  271.             }
  272.             r = proc_pat(prv);
  273.             if(r < 0){
  274. +               curr += unit;
  275.                 goto LAST;
  276.             }
  277.         }
  278. -          
  279. +
  280.     NEXT:
  281.         curr += unit;
  282.     }
  283.  
  284.  LAST:
  285. -  
  286. -   m = curr - prv->sbuf.head;
  287. +   m = curr - prv->sbuf.pool;
  288.     n = tail - curr;
  289.     if( (n < 1024) || (m > (prv->sbuf.max/2) ) ){
  290.         p = prv->sbuf.pool;
  291. -       memcpy(p, curr, n);
  292. +       if(n > 0)
  293. +           memcpy(p, curr, n);
  294.         prv->sbuf.head = p;
  295.         prv->sbuf.tail = p+n;
  296.     }else{
  297. @@ -779,7 +801,7 @@
  298.  static int put_arib_std_b25(void *std_b25, ARIB_STD_B25_BUFFER *buf)
  299.  {
  300.     int32_t n;
  301. -  
  302. +
  303.     ARIB_STD_B25_PRIVATE_DATA *prv;
  304.  
  305.     prv = private_data(std_b25);
  306. @@ -875,7 +897,7 @@
  307.  static int get_program_count_arib_std_b25(void *std_b25)
  308.  {
  309.     ARIB_STD_B25_PRIVATE_DATA *prv;
  310. -  
  311. +
  312.     prv = private_data(std_b25);
  313.     if(prv == NULL){
  314.         return ARIB_STD_B25_ERROR_INVALID_PARAM;
  315. @@ -889,12 +911,12 @@
  316.     ARIB_STD_B25_PRIVATE_DATA *prv;
  317.  
  318.     TS_PROGRAM *pgrm;
  319. -  
  320. +
  321.     TS_STREAM_ELEM *strm;
  322.     DECRYPTOR_ELEM *dec;
  323.  
  324.     int32_t pid;
  325. -  
  326. +
  327.     prv = private_data(std_b25);
  328.     if( (prv == NULL) || (info == NULL) || (idx < 0) || (idx >= prv->p_count) ){
  329.         return ARIB_STD_B25_ERROR_INVALID_PARAM;
  330. @@ -905,7 +927,7 @@
  331.     memset(info, 0, sizeof(ARIB_STD_B25_PROGRAM_INFO));
  332.  
  333.     info->program_number = pgrm->program_number;
  334. -  
  335. +
  336.     pid = pgrm->pmt_pid;
  337.     info->total_packet_count += prv->map[pid].normal_packet;
  338.     info->total_packet_count += prv->map[pid].undecrypted;
  339. @@ -953,13 +975,13 @@
  340.         return NULL;
  341.     }
  342.  
  343. -   return r;
  344. +   return r;
  345.  }
  346.  
  347.  static void teardown(ARIB_STD_B25_PRIVATE_DATA *prv)
  348.  {
  349.     int i;
  350. -  
  351. +
  352.     prv->unit_size = 0;
  353.     prv->sbuf_offset = 0;
  354.  
  355. @@ -1011,7 +1033,7 @@
  356.  
  357.     head = prv->sbuf.head;
  358.     tail = prv->sbuf.tail;
  359. -  
  360. +
  361.     buf = head;
  362.     memset(count, 0, sizeof(count));
  363.  
  364. @@ -1058,7 +1080,7 @@
  365.  {
  366.     int r;
  367.     int n,size;
  368. -  
  369. +
  370.     int32_t unit;
  371.  
  372.     uint8_t *p;
  373. @@ -1073,32 +1095,36 @@
  374.     tail = prv->sbuf.tail;
  375.  
  376.     while( (curr+unit) < tail ){
  377. +
  378.         if( (curr[0] != 0x47) || (curr[unit] != 0x47) ){
  379.             p = resync(curr, tail, unit);
  380.             if(p == NULL){
  381. +               curr = tail;
  382.                 goto LAST;
  383.             }
  384.             curr = p;
  385.         }
  386. +
  387.         extract_ts_header(&hdr, curr);
  388. +
  389.         if(hdr.pid == 0x0000){
  390. -          
  391.             p = curr+4;
  392.             if(hdr.adaptation_field_control & 0x02){
  393.                 p += (p[0]+1);
  394. +               size = unit - (p-curr);
  395. +               if(size < 1){
  396. +                   goto NEXT;
  397. +               }
  398. +           }else{
  399. +               size = unit - 4;
  400.             }
  401. -           size = 188 - (p-curr);
  402. -           if(size < 1){
  403. -               goto NEXT;
  404. -           }
  405. -          
  406.             if(prv->pat == NULL){
  407.                 prv->pat = create_ts_section_parser();
  408.                 if(prv->pat == NULL){
  409.                     return ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY;
  410.                 }
  411.             }
  412. -          
  413. +
  414.             n = prv->pat->put(prv->pat, &hdr, p, size);
  415.             if(n < 0){
  416.                 r = ARIB_STD_B25_ERROR_PAT_PARSE_FAILURE;
  417. @@ -1136,13 +1162,13 @@
  418.     int i,n;
  419.     int len;
  420.     int count;
  421. -  
  422. +
  423.     int32_t program_number;
  424.     int32_t pid;
  425.  
  426.     uint8_t *head;
  427.     uint8_t *tail;
  428. -  
  429. +
  430.     TS_PROGRAM *work;
  431.     TS_SECTION  sect;
  432.  
  433. @@ -1168,7 +1194,7 @@
  434.         r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY;
  435.         goto LAST;
  436.     }
  437. -  
  438. +
  439.     if(prv->program != NULL){
  440.         for(i=0;i<prv->p_count;i++){
  441.             release_program(prv, prv->program+i);
  442. @@ -1203,7 +1229,7 @@
  443.  
  444.     prv->program = work;
  445.     prv->p_count = i;
  446. -  
  447. +
  448.     prv->map[0x0000].ref = 1;
  449.     prv->map[0x0000].type = PID_MAP_TYPE_PAT;
  450.     prv->map[0x0000].target = NULL;
  451. @@ -1251,7 +1277,7 @@
  452.  {
  453.     int r;
  454.     int n,size;
  455. -  
  456. +
  457.     int32_t unit;
  458.  
  459.     uint8_t *p;
  460. @@ -1267,17 +1293,57 @@
  461.     tail = prv->sbuf.tail;
  462.  
  463.     while( (curr+unit) < tail ){
  464. -      
  465. +
  466.         if( (curr[0] != 0x47) || (curr[unit] != 0x47) ){
  467.             p = resync(curr, tail, unit);
  468.             if(p == NULL){
  469. +               curr = tail;
  470.                 goto LAST;
  471.             }
  472.             curr = p;
  473.         }
  474. -      
  475. +
  476.         extract_ts_header(&hdr, curr);
  477. -      
  478. +
  479. +       if(hdr.pid == 0x0000){
  480. +           p = curr+4;
  481. +           if(hdr.adaptation_field_control & 0x02){
  482. +               p += (p[0]+1);
  483. +               size = unit - (p-curr);
  484. +               if(size < 1){
  485. +                   goto NEXT;
  486. +               }
  487. +           }else{
  488. +               size = unit - 4;
  489. +           }
  490. +           if(prv->pat == NULL){
  491. +               prv->pat = create_ts_section_parser();
  492. +               if(prv->pat == NULL){
  493. +                   r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY;
  494. +                   goto LAST;
  495. +               }
  496. +           }
  497. +           n = prv->pat->put(prv->pat, &hdr, p, size);
  498. +           if(n < 0){
  499. +               r = ARIB_STD_B25_ERROR_PAT_PARSE_FAILURE;
  500. +               curr += unit;
  501. +               goto LAST;
  502. +           }
  503. +           n = prv->pat->get_count(prv->pat);
  504. +           if(n < 0){
  505. +               r = ARIB_STD_B25_ERROR_PAT_PARSE_FAILURE;
  506. +               curr += unit;
  507. +               goto LAST;
  508. +           }
  509. +           if(n == 0){
  510. +               goto NEXT;
  511. +           }
  512. +           r = proc_pat(prv);
  513. +           prv->sbuf.head = curr;
  514. +           curr += unit;
  515. +           goto LAST;
  516. +       }
  517. +
  518.         if(prv->map[hdr.pid].type != PID_MAP_TYPE_PMT){
  519.             goto NEXT;
  520.         }
  521. @@ -1285,25 +1351,27 @@
  522.         if(pgrm == NULL){
  523.             goto NEXT;
  524.         }
  525. -      
  526. +
  527.         if(pgrm->phase == 0){
  528. -          
  529. +
  530.             p = curr + 4;
  531.             if(hdr.adaptation_field_control & 0x02){
  532.                 p += (p[0]+1);
  533. +               size = unit - (p-curr);
  534. +               if(size < 1){
  535. +                   goto NEXT;
  536. +               }
  537. +           }else{
  538. +               size = unit - 4;
  539.             }
  540. -           size = 188 - (p-curr);
  541. -           if(size < 1){
  542. -               goto NEXT;
  543. -           }
  544. -          
  545. +
  546.             if(pgrm->pmt == NULL){
  547.                 /* this code will never execute */
  548.                 r = ARIB_STD_B25_ERROR_PMT_PARSE_FAILURE;
  549.                 curr += unit;
  550.                 goto LAST;
  551.             }
  552. -          
  553. +
  554.             n = pgrm->pmt->put(pgrm->pmt, &hdr, p, size);
  555.             if(n < 0){
  556.                 r = ARIB_STD_B25_ERROR_PMT_PARSE_FAILURE;
  557. @@ -1338,7 +1406,7 @@
  558.             curr += unit;
  559.             goto LAST;
  560.         }
  561. -      
  562. +
  563.     NEXT:
  564.         curr += unit;
  565.     }
  566. @@ -1364,10 +1432,10 @@
  567.     int32_t type;
  568.  
  569.     TS_SECTION sect;
  570. -  
  571. +
  572.     DECRYPTOR_ELEM *dec[2];
  573.     DECRYPTOR_ELEM *dw;
  574. -  
  575. +
  576.     TS_STREAM_ELEM *strm;
  577.  
  578.     r = 0;
  579. @@ -1383,7 +1451,7 @@
  580.         r = ARIB_STD_B25_WARN_TS_SECTION_ID_MISSMATCH;
  581.         goto LAST;
  582.     }
  583. -  
  584. +
  585.     head = sect.data;
  586.     tail = sect.tail-4;
  587.  
  588. @@ -1412,7 +1480,6 @@
  589.     }
  590.     head += length;
  591.  
  592. -  
  593.     /* unref old stream entries */
  594.     while( (strm = get_stream_list_head(&(pgrm->old_strm))) != NULL ){
  595.         unref_stream(prv, strm->pid);
  596. @@ -1440,7 +1507,7 @@
  597.         head += 5;
  598.         ecm_pid = find_ca_descriptor_pid(head, head+length, prv->ca_system_id);
  599.         head += length;
  600. -      
  601. +
  602.         if( (ecm_pid != 0) && (ecm_pid != 0x1fff) ){
  603.             dec[1] = set_decryptor(prv, ecm_pid);
  604.             if(dec[1] == NULL){
  605. @@ -1466,16 +1533,16 @@
  606.             strm->pid = pid;
  607.             strm->type = type;
  608.         }
  609. -      
  610. +
  611.         prv->map[pid].type = PID_MAP_TYPE_OTHER;
  612.         prv->map[pid].ref += 1;
  613.  
  614.         dw = select_active_decryptor(dec[0], dec[1], ecm_pid);
  615.         bind_stream_decryptor(prv, pid, dw);
  616. -      
  617. +
  618.         put_stream_list_tail(&(pgrm->streams), strm);
  619.     }
  620. -  
  621. +
  622.  LAST:
  623.     if( dec[0] != NULL ){
  624.         dec[0]->ref -= 1;
  625. @@ -1494,12 +1561,12 @@
  626.  
  627.     return r;
  628.  }
  629. -      
  630. +
  631.  static int32_t find_ca_descriptor_pid(uint8_t *head, uint8_t *tail, int32_t ca_system_id)
  632.  {
  633.     uint32_t ca_pid;
  634.     uint32_t ca_sys_id;
  635. -  
  636. +
  637.     uint32_t tag;
  638.     uint32_t len;
  639.  
  640. @@ -1602,11 +1669,52 @@
  641.         if( (curr[0] != 0x47) || (curr[unit] != 0x47) ){
  642.             p = resync(curr, tail, unit);
  643.             if(p == NULL){
  644. +               curr = tail;
  645.                 goto LAST;
  646.             }
  647.             curr = p;
  648.         }
  649.         extract_ts_header(&hdr, curr);
  650. +
  651. +       if(hdr.pid == 0x0000){
  652. +           p = curr+4;
  653. +           if(hdr.adaptation_field_control & 0x02){
  654. +               p += (p[0]+1);
  655. +               size = unit - (p-curr);
  656. +               if(size < 1){
  657. +                   goto NEXT;
  658. +               }
  659. +           }else{
  660. +               size = unit - 4;
  661. +           }
  662. +           if(prv->pat == NULL){
  663. +               prv->pat = create_ts_section_parser();
  664. +               if(prv->pat == NULL){
  665. +                   r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY;
  666. +                   goto LAST;
  667. +               }
  668. +           }
  669. +           n = prv->pat->put(prv->pat, &hdr, p, size);
  670. +           if(n < 0){
  671. +               r = ARIB_STD_B25_ERROR_PAT_PARSE_FAILURE;
  672. +               curr += unit;
  673. +               goto LAST;
  674. +           }
  675. +           n = prv->pat->get_count(prv->pat);
  676. +           if(n < 0){
  677. +               r = ARIB_STD_B25_ERROR_PAT_PARSE_FAILURE;
  678. +               curr += unit;
  679. +               goto LAST;
  680. +           }
  681. +           if(n == 0){
  682. +               goto NEXT;
  683. +           }
  684. +           r = proc_pat(prv);
  685. +           prv->sbuf.head = curr;
  686. +           curr += unit;
  687. +           goto LAST;
  688. +       }
  689. +
  690.         if(prv->map[hdr.pid].type != PID_MAP_TYPE_ECM){
  691.             goto NEXT;
  692.         }
  693. @@ -1616,23 +1724,25 @@
  694.         }
  695.  
  696.         if(dec->phase == 0){
  697. -          
  698. +
  699.             p = curr + 4;
  700.             if(hdr.adaptation_field_control & 0x02){
  701.                 p += (p[0]+1);
  702. +               size = unit - (p-curr);
  703. +               if(size < 1){
  704. +                   goto NEXT;
  705. +               }
  706. +           }else{
  707. +               size = unit - 4;
  708.             }
  709. -           size = 188 - (p-curr);
  710. -           if(size < 1){
  711. -               goto NEXT;
  712. -           }
  713. -          
  714. +
  715.             if(dec->ecm == NULL){
  716.                 /*  this code will never execute */
  717.                 r = ARIB_STD_B25_ERROR_ECM_PARSE_FAILURE;
  718.                 curr += unit;
  719.                 goto LAST;
  720.             }
  721. -              
  722. +
  723.             n = dec->ecm->put(dec->ecm, &hdr, p, size);
  724.             if(n < 0){
  725.                 r = ARIB_STD_B25_ERROR_ECM_PARSE_FAILURE;
  726. @@ -1658,7 +1768,7 @@
  727.                 /* broken or unexpected section data */
  728.                 goto NEXT;
  729.             }
  730. -          
  731. +
  732.             dec->phase = 1;
  733.             if(check_ecm_complete(prv)){
  734.                 curr += unit;
  735. @@ -1670,7 +1780,7 @@
  736.             curr += unit;
  737.             goto LAST;
  738.         }
  739. -      
  740. +
  741.     NEXT:
  742.         curr += unit;
  743.     }
  744. @@ -1687,7 +1797,7 @@
  745.     int length;
  746.  
  747.     uint8_t *p;
  748. -  
  749. +
  750.     B_CAS_INIT_STATUS is;
  751.     B_CAS_ECM_RESULT res;
  752.  
  753. @@ -1710,7 +1820,7 @@
  754.         r = ARIB_STD_B25_WARN_TS_SECTION_ID_MISSMATCH;
  755.         goto LAST;
  756.     }
  757. -  
  758. +
  759.     if(dec->locked){
  760.         /* previous ECM has returned unpurchased
  761.            skip this pid for B-CAS card load reduction */
  762. @@ -1730,7 +1840,7 @@
  763.         r = ARIB_STD_B25_ERROR_ECM_PROC_FAILURE;
  764.         goto LAST;
  765.     }
  766. -  
  767. +
  768.     if( (res.return_code != 0x0800) &&
  769.         (res.return_code != 0x0400) &&
  770.         (res.return_code != 0x0200) ){
  771. @@ -1777,7 +1887,7 @@
  772.         fprintf(stdout, "\n");
  773.         fflush(stdout);
  774.     }
  775. -  
  776. +
  777.  LAST:
  778.     if(sect.raw != NULL){
  779.         n = dec->ecm->ret(dec->ecm, &sect);
  780. @@ -1785,7 +1895,7 @@
  781.             r = ARIB_STD_B25_ERROR_ECM_PARSE_FAILURE;
  782.         }
  783.     }
  784. -  
  785. +
  786.     return r;
  787.  }
  788.  
  789. @@ -1793,10 +1903,10 @@
  790.  {
  791.     int32_t pts_dts_flag;
  792.     int64_t pts,dts;
  793. -  
  794. -   src += 4; // TS ヘッダ部
  795. -   src += 4; // start_code_prefix + stream_id 部
  796. -   src += 2; // packet_length 部
  797. +
  798. +   src += 4; // TS header
  799. +   src += 4; // start_code_prefix + stream_id
  800. +   src += 2; // packet_length
  801.  
  802.     pts_dts_flag = (src[1] >> 6) & 3;
  803.  
  804. @@ -1820,7 +1930,7 @@
  805.     }
  806.  
  807.     if(pts_dts_flag == 2){
  808. -       fprintf(stdout, "  key=%d, pts=%"PRId64"\n", crypt, pts/90);
  809. +       fprintf(stdout, "  key=%d, pts=%d\n", crypt, (int32_t)(pts/90));
  810.         fflush(stdout);
  811.     }
  812.  }
  813. @@ -1855,28 +1965,29 @@
  814.     r = 0;
  815.  
  816.     while( (curr+unit) < tail ){
  817. -      
  818. +
  819.         if( (curr[0] != 0x47) || (curr[unit] != 0x47) ){
  820.             p = resync(curr, tail, unit);
  821.             if(p == NULL){
  822. +               curr = tail;
  823.                 goto LAST;
  824.             }
  825.             curr = p;
  826.         }
  827. -      
  828. +
  829.         extract_ts_header(&hdr, curr);
  830.         crypt = hdr.transport_scrambling_control;
  831.         pid = hdr.pid;
  832.  
  833.         if(hdr.transport_error_indicator != 0){
  834.             /* bit error - append output buffer without parsing */
  835. -           if(!append_work_buffer(&(prv->dbuf), curr, 188)){
  836. +           if(!append_work_buffer(&(prv->dbuf), curr, unit)){
  837.                 r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY;
  838.                 goto LAST;
  839.             }
  840.             goto NEXT;
  841.         }
  842. -      
  843. +
  844.         if( (pid == 0x1fff) && (prv->strip) ){
  845.             /* strip null(padding) stream */
  846.             goto NEXT;
  847. @@ -1885,17 +1996,19 @@
  848.         p = curr+4;
  849.         if(hdr.adaptation_field_control & 0x02){
  850.             p += (p[0]+1);
  851. -       }
  852. -       n = 188 - (p-curr);
  853. -       if( (n < 1) && ((n < 0) || (hdr.adaptation_field_control & 0x01)) ){
  854. -           /* broken packet */
  855. -           curr += 1;
  856. -           continue;
  857. +           n = unit - (p-curr);
  858. +           if( (n < 1) && ((n < 0) || (hdr.adaptation_field_control & 0x01)) ){
  859. +               /* broken packet */
  860. +               curr += 1;
  861. +               continue;
  862. +           }
  863. +       }else{
  864. +           n = unit - 4;
  865.         }
  866.  
  867.         if( (crypt != 0) &&
  868.             (hdr.adaptation_field_control & 0x01) ){
  869. -          
  870. +
  871.             if(prv->map[pid].type == PID_MAP_TYPE_OTHER){
  872.                 dec = (DECRYPTOR_ELEM *)(prv->map[pid].target);
  873.             }else if( (prv->map[pid].type == 0) &&
  874. @@ -1909,6 +2022,7 @@
  875.                 m = dec->m2->decrypt(dec->m2, crypt, p, n);
  876.                 if(m < 0){
  877.                     r = ARIB_STD_B25_ERROR_DECRYPT_FAILURE;
  878. +                   curr += unit;
  879.                     goto LAST;
  880.                 }
  881.                 curr[3] &= 0x3f;
  882. @@ -1924,7 +2038,7 @@
  883.             dump_pts(curr, crypt);
  884.         }
  885.  #endif
  886. -       if(!append_work_buffer(&(prv->dbuf), curr, 188)){
  887. +       if(!append_work_buffer(&(prv->dbuf), curr, unit)){
  888.             r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY;
  889.             goto LAST;
  890.         }
  891. @@ -1934,16 +2048,19 @@
  892.             if( (dec == NULL) || (dec->ecm == NULL) ){
  893.                 /* this code will never execute */
  894.                 r = ARIB_STD_B25_ERROR_ECM_PARSE_FAILURE;
  895. +               curr += unit;
  896.                 goto LAST;
  897.             }
  898.             m = dec->ecm->put(dec->ecm, &hdr, p, n);
  899.             if(m < 0){
  900.                 r = ARIB_STD_B25_ERROR_ECM_PARSE_FAILURE;
  901. +               curr += unit;
  902.                 goto LAST;
  903.             }
  904.             m = dec->ecm->get_count(dec->ecm);
  905.             if(m < 0){
  906.                 r = ARIB_STD_B25_ERROR_ECM_PARSE_FAILURE;
  907. +               curr += unit;
  908.                 goto LAST;
  909.             }
  910.             if(m == 0){
  911. @@ -1951,6 +2068,7 @@
  912.             }
  913.             r = proc_ecm(dec, prv->bcas, prv->multi2_round);
  914.             if(r < 0){
  915. +               curr += unit;
  916.                 goto LAST;
  917.             }
  918.         }else if(prv->map[pid].type == PID_MAP_TYPE_PMT){
  919. @@ -1958,16 +2076,19 @@
  920.             if( (pgrm == NULL) || (pgrm->pmt == NULL) ){
  921.                 /* this code will never execute */
  922.                 r = ARIB_STD_B25_ERROR_PMT_PARSE_FAILURE;
  923. +               curr += unit;
  924.                 goto LAST;
  925.             }
  926.             m = pgrm->pmt->put(pgrm->pmt, &hdr, p, n);
  927.             if(m < 0){
  928.                 r = ARIB_STD_B25_ERROR_PMT_PARSE_FAILURE;
  929. +               curr += unit;
  930.                 goto LAST;
  931.             }
  932.             m = pgrm->pmt->get_count(pgrm->pmt);
  933.             if(m < 0){
  934.                 r = ARIB_STD_B25_ERROR_PMT_PARSE_FAILURE;
  935. +               curr += unit;
  936.                 goto LAST;
  937.             }
  938.             if(m == 0){
  939. @@ -1975,6 +2096,7 @@
  940.             }
  941.             r = proc_pmt(prv, pgrm);
  942.             if(r < 0){
  943. +               curr += unit;
  944.                 goto LAST;
  945.             }
  946.         }else if(prv->map[pid].type == PID_MAP_TYPE_EMM){
  947. @@ -1984,18 +2106,20 @@
  948.             if( prv->emm == NULL ){
  949.                 prv->emm = create_ts_section_parser();
  950.                 if(prv->emm == NULL){
  951. -                   r = ARIB_STD_B25_ERROR_EMM_PARSE_FAILURE;
  952. +                   r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY;
  953.                     goto LAST;
  954.                 }
  955.             }
  956.             m = prv->emm->put(prv->emm, &hdr, p, n);
  957.             if(m < 0){
  958.                 r = ARIB_STD_B25_ERROR_EMM_PARSE_FAILURE;
  959. +               curr += unit;
  960.                 goto LAST;
  961.             }
  962.             m = prv->emm->get_count(prv->emm);
  963.             if(m < 0){
  964.                 r = ARIB_STD_B25_ERROR_EMM_PARSE_FAILURE;
  965. +               curr += unit;
  966.                 goto LAST;
  967.             }
  968.             if(m == 0){
  969. @@ -2003,6 +2127,7 @@
  970.             }
  971.             r = proc_emm(prv);
  972.             if(r < 0){
  973. +               curr += unit;
  974.                 goto LAST;
  975.             }
  976.         }else if(pid == 0x0001){
  977. @@ -2016,11 +2141,13 @@
  978.             m = prv->cat->put(prv->cat, &hdr, p, n);
  979.             if(m < 0){
  980.                 r = ARIB_STD_B25_ERROR_CAT_PARSE_FAILURE;
  981. +               curr += unit;
  982.                 goto LAST;
  983.             }
  984.             m = prv->cat->get_count(prv->cat);
  985.             if(m < 0){
  986.                 r = ARIB_STD_B25_ERROR_CAT_PARSE_FAILURE;
  987. +               curr += unit;
  988.                 goto LAST;
  989.             }
  990.             if(m == 0){
  991. @@ -2028,6 +2155,7 @@
  992.             }
  993.             r = proc_cat(prv);
  994.             if(r < 0){
  995. +               curr += unit;
  996.                 goto LAST;
  997.             }
  998.         }else if(pid == 0x0000){
  999. @@ -2041,26 +2169,29 @@
  1000.             m = prv->pat->put(prv->pat, &hdr, p, n);
  1001.             if(m < 0){
  1002.                 r = ARIB_STD_B25_ERROR_PAT_PARSE_FAILURE;
  1003. +               curr += unit;
  1004.                 goto LAST;
  1005.             }
  1006.             m = prv->pat->get_count(prv->pat);
  1007.             if(m < 0){
  1008.                 r = ARIB_STD_B25_ERROR_PAT_PARSE_FAILURE;
  1009. +               curr += unit;
  1010.                 goto LAST;
  1011.             }
  1012.             if(m == 0){
  1013.                 goto NEXT;
  1014.             }
  1015.             r = proc_pat(prv);
  1016. +           curr += unit;
  1017.             goto LAST;
  1018.         }
  1019. -          
  1020. +
  1021.     NEXT:
  1022.         curr += unit;
  1023.     }
  1024.  
  1025.  LAST:
  1026. -   m = curr - prv->sbuf.head;
  1027. +   m = curr - prv->sbuf.pool;
  1028.     n = tail - curr;
  1029.     if( (n < 1024) || (m > (prv->sbuf.max/2) ) ){
  1030.         p = prv->sbuf.pool;
  1031. @@ -2112,7 +2243,7 @@
  1032.         prv->map[emm_pid].type = PID_MAP_TYPE_EMM;
  1033.         prv->map[emm_pid].target = NULL;
  1034.     }
  1035. -  
  1036. +
  1037.     prv->map[0x0001].ref = 1;
  1038.     prv->map[0x0001].type = PID_MAP_TYPE_CAT;
  1039.     prv->map[0x0001].target = NULL;
  1040. @@ -2154,7 +2285,7 @@
  1041.  
  1042.         n = prv->emm->get(prv->emm, &sect);
  1043.         if(n < 0){
  1044. -           r = ARIB_STD_B25_ERROR_CAT_PARSE_FAILURE;
  1045. +           r = ARIB_STD_B25_ERROR_EMM_PARSE_FAILURE;
  1046.             goto LAST;
  1047.         }
  1048.  
  1049. @@ -2170,14 +2301,14 @@
  1050.         tail = sect.tail - 4;
  1051.  
  1052.         while( (head+13) <= tail ){
  1053. -          
  1054. +
  1055.             extract_emm_fixed_part(&emm_hdr, head);
  1056.             len = emm_hdr.associated_information_length+7;
  1057.             if( (head+len) > tail ){
  1058.                 /* broken EMM element */
  1059.                 goto NEXT;
  1060.             }
  1061. -          
  1062. +
  1063.             for(j=0;j<prv->casid.count;j++){
  1064.                 if(prv->casid.data[j] == emm_hdr.card_id){
  1065.                     n = prv->bcas->proc_emm(prv->bcas, head, len);
  1066. @@ -2220,7 +2351,7 @@
  1067.     TS_STREAM_ELEM *strm;
  1068.  
  1069.     pid = pgrm->pmt_pid;
  1070. -  
  1071. +
  1072.     if(pgrm->pmt != NULL){
  1073.         pgrm->pmt->release(pgrm->pmt);
  1074.         pgrm->pmt = NULL;
  1075. @@ -2376,7 +2507,7 @@
  1076.         /* already binded - do nothing */
  1077.         return;
  1078.     }
  1079. -        
  1080. +
  1081.     if(old != NULL){
  1082.         old->ref -= 1;
  1083.         if(old->ref == 0){
  1084. @@ -2493,7 +2624,7 @@
  1085.  {
  1086.     int m,n;
  1087.     uint8_t *p;
  1088. -  
  1089. +
  1090.     if(buf->max >= size){
  1091.         return 1;
  1092.     }
  1093. @@ -2503,7 +2634,7 @@
  1094.     }else{
  1095.         n = buf->max * 2;
  1096.     }
  1097. -  
  1098. +
  1099.     while(n < size){
  1100.         n += n;
  1101.     }
  1102. @@ -2591,7 +2722,7 @@
  1103.     for(i=0;i<6;i++){
  1104.         dst->card_id = (dst->card_id << 8) | src[i];
  1105.     }
  1106. -  
  1107. +
  1108.     dst->associated_information_length = src[ 6];
  1109.     dst->protocol_number               = src[ 7];
  1110.     dst->broadcaster_group_id          = src[ 8];
  1111. @@ -2629,7 +2760,7 @@
  1112.     unsigned char *buf;
  1113.  
  1114.     buf = head;
  1115. -   while( buf <= (tail-188) ){
  1116. +   while( buf <= (tail-unit_size) ){
  1117.         if(buf[0] == 0x47){
  1118.             n = (tail - buf) / unit_size;
  1119.             if(n == 0){
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement