comparison arib25/src/arib_std_b25.c @ 123:ec7c87854f2f b25

updated to arib25 0.2.5
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Wed, 15 Feb 2012 11:09:02 +0900
parents 521d796003b2
children
comparison
equal deleted inserted replaced
73:c44e16dbb0e2 123:ec7c87854f2f
1 #include <stdlib.h> 1 #include <stdlib.h>
2 #include <string.h> 2 #include <string.h>
3 #include <stdio.h>
3 4
4 #include "arib_std_b25.h" 5 #include "arib_std_b25.h"
5 #include "arib_std_b25_error_code.h" 6 #include "arib_std_b25_error_code.h"
6 #include "multi2.h" 7 #include "multi2.h"
7 #include "ts_common_types.h" 8 #include "ts_common_types.h"
1401 if(dec[0] == NULL){ 1402 if(dec[0] == NULL){
1402 r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY; 1403 r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY;
1403 goto LAST; 1404 goto LAST;
1404 } 1405 }
1405 dec[0]->ref += 1; 1406 dec[0]->ref += 1;
1407 } else {
1408 if (prv->decrypt.count == 1) {
1409 dec[0] = prv->decrypt.head;
1410 dec[0]->ref += 1;
1411 }
1406 } 1412 }
1407 head += length; 1413 head += length;
1414
1408 1415
1409 /* unref old stream entries */ 1416 /* unref old stream entries */
1410 while( (strm = get_stream_list_head(&(pgrm->old_strm))) != NULL ){ 1417 while( (strm = get_stream_list_head(&(pgrm->old_strm))) != NULL ){
1411 unref_stream(prv, strm->pid); 1418 unref_stream(prv, strm->pid);
1412 memset(strm, 0, sizeof(TS_STREAM_ELEM)); 1419 memset(strm, 0, sizeof(TS_STREAM_ELEM));
1483 if( (n < 0) && (r == 0) ){ 1490 if( (n < 0) && (r == 0) ){
1484 return ARIB_STD_B25_ERROR_PMT_PARSE_FAILURE; 1491 return ARIB_STD_B25_ERROR_PMT_PARSE_FAILURE;
1485 } 1492 }
1486 } 1493 }
1487 1494
1488 return 0; 1495 return r;
1489 } 1496 }
1490 1497
1491 static int32_t find_ca_descriptor_pid(uint8_t *head, uint8_t *tail, int32_t ca_system_id) 1498 static int32_t find_ca_descriptor_pid(uint8_t *head, uint8_t *tail, int32_t ca_system_id)
1492 { 1499 {
1493 uint32_t ca_pid; 1500 uint32_t ca_pid;
1753 dec->m2->set_round(dec->m2, multi2_round); 1760 dec->m2->set_round(dec->m2, multi2_round);
1754 } 1761 }
1755 1762
1756 dec->m2->set_scramble_key(dec->m2, res.scramble_key); 1763 dec->m2->set_scramble_key(dec->m2, res.scramble_key);
1757 1764
1765 if (0) {
1766 int i;
1767 fprintf(stdout, "----\n");
1768 fprintf(stdout, "odd: ");
1769 for(i=0;i<8;i++){
1770 fprintf(stdout, " %02x", res.scramble_key[i]);
1771 }
1772 fprintf(stdout, "\n");
1773 fprintf(stdout, "even:");
1774 for(i=8;i<16;i++){
1775 fprintf(stdout, " %02x", res.scramble_key[i]);
1776 }
1777 fprintf(stdout, "\n");
1778 fflush(stdout);
1779 }
1780
1758 LAST: 1781 LAST:
1759 if(sect.raw != NULL){ 1782 if(sect.raw != NULL){
1760 n = dec->ecm->ret(dec->ecm, &sect); 1783 n = dec->ecm->ret(dec->ecm, &sect);
1761 if( (n < 0) && (r == 0) ){ 1784 if( (n < 0) && (r == 0) ){
1762 r = ARIB_STD_B25_ERROR_ECM_PARSE_FAILURE; 1785 r = ARIB_STD_B25_ERROR_ECM_PARSE_FAILURE;
1763 } 1786 }
1764 } 1787 }
1765 1788
1766 return r; 1789 return r;
1790 }
1791
1792 static void dump_pts(uint8_t *src, int32_t crypt)
1793 {
1794 int32_t pts_dts_flag;
1795 int64_t pts,dts;
1796
1797 src += 4; // TS ヘッダ部
1798 src += 4; // start_code_prefix + stream_id 部
1799 src += 2; // packet_length 部
1800
1801 pts_dts_flag = (src[1] >> 6) & 3;
1802
1803 src += 3;
1804 if(pts_dts_flag & 2){
1805 // PTS
1806 pts = (src[0] >> 1) & 0x07;
1807 pts <<= 15;
1808 pts += ((src[1] << 8) + src[2]) >> 1;
1809 pts <<= 15;
1810 pts += ((src[3] << 8) + src[4]) >> 1;
1811 src += 5;
1812 }
1813 if(pts_dts_flag & 1){
1814 // DTS
1815 dts = (src[0] >> 1) & 0x07;
1816 dts <<= 15;
1817 dts += ((src[1] << 8) + src[2]) >> 1;
1818 dts <<= 15;
1819 dts += ((src[3] << 8) + src[4]) >> 1;
1820 }
1821
1822 if(pts_dts_flag == 2){
1823 fprintf(stdout, " key=%d, pts=%"PRId64"\n", crypt, pts/90);
1824 fflush(stdout);
1825 }
1767 } 1826 }
1768 1827
1769 static int proc_arib_std_b25(ARIB_STD_B25_PRIVATE_DATA *prv) 1828 static int proc_arib_std_b25(ARIB_STD_B25_PRIVATE_DATA *prv)
1770 { 1829 {
1771 int r; 1830 int r;
1858 prv->map[pid].undecrypted += 1; 1917 prv->map[pid].undecrypted += 1;
1859 } 1918 }
1860 }else{ 1919 }else{
1861 prv->map[pid].normal_packet += 1; 1920 prv->map[pid].normal_packet += 1;
1862 } 1921 }
1863 1922 #if 0
1923 if( (hdr.payload_unit_start_indicator != 0) && (pid == 0x111) ){
1924 dump_pts(curr, crypt);
1925 }
1926 #endif
1864 if(!append_work_buffer(&(prv->dbuf), curr, 188)){ 1927 if(!append_work_buffer(&(prv->dbuf), curr, 188)){
1865 r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY; 1928 r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY;
1866 goto LAST; 1929 goto LAST;
1867 } 1930 }
1868 1931
2067 } 2130 }
2068 2131
2069 static int proc_emm(ARIB_STD_B25_PRIVATE_DATA *prv) 2132 static int proc_emm(ARIB_STD_B25_PRIVATE_DATA *prv)
2070 { 2133 {
2071 int r; 2134 int r;
2072 int i,j,n; 2135 int j,n;
2073 2136
2074 int len; 2137 int len;
2075 2138
2076 uint8_t *head; 2139 uint8_t *head;
2077 uint8_t *tail; 2140 uint8_t *tail;
2104 } 2167 }
2105 2168
2106 head = sect.data; 2169 head = sect.data;
2107 tail = sect.tail - 4; 2170 tail = sect.tail - 4;
2108 2171
2109 i = 0;
2110 while( (head+13) <= tail ){ 2172 while( (head+13) <= tail ){
2111 2173
2112 extract_emm_fixed_part(&emm_hdr, head); 2174 extract_emm_fixed_part(&emm_hdr, head);
2113 len = emm_hdr.associated_information_length+7; 2175 len = emm_hdr.associated_information_length+7;
2114 if( (head+len) > tail ){ 2176 if( (head+len) > tail ){
2115 /* broken EMM element */ 2177 /* broken EMM element */
2116 goto NEXT; 2178 goto NEXT;
2117 } 2179 }
2118 2180
2119 for(j=0;j<prv->casid.count;j++){ 2181 for(j=0;j<prv->casid.count;j++){
2120 if(prv->casid.data[j] == emm_hdr.card_id){ 2182 if(prv->casid.data[j] == emm_hdr.card_id){
2121 n = prv->bcas->proc_emm(prv->bcas, head, len); 2183 n = prv->bcas->proc_emm(prv->bcas, head, len);
2122 if(n < 0){ 2184 if(n < 0){
2123 r = ARIB_STD_B25_ERROR_EMM_PROC_FAILURE; 2185 r = ARIB_STD_B25_ERROR_EMM_PROC_FAILURE;