From a9657eba64b707d275efc19a697a5c05d58ff893 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 5 Oct 2020 23:10:22 +0900 Subject: [PATCH 1/4] =?UTF-8?q?=E8=BB=BD=E5=BE=AE=E3=81=AA=E6=9C=80?= =?UTF-8?q?=E9=81=A9=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://echo.5ch.net/test/read.cgi/avi/1428405907/602-603n --- src/arib_std_b25.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arib_std_b25.c b/src/arib_std_b25.c index 30827f6..4867fed 100644 --- a/src/arib_std_b25.c +++ b/src/arib_std_b25.c @@ -1414,10 +1414,10 @@ static int proc_pmt(ARIB_STD_B25_PRIVATE_DATA *prv, TS_PROGRAM *pgrm) head += length; /* save old streams */ - memcpy(&tmp_old_strm, &(pgrm->old_strm), sizeof(TS_STREAM_LIST)); + tmp_old_strm = pgrm->old_strm; /* save current streams */ - memcpy(&(pgrm->old_strm), &(pgrm->streams), sizeof(TS_STREAM_LIST)); + pgrm->old_strm = pgrm->streams; memset(&(pgrm->streams), 0, sizeof(TS_STREAM_LIST)); /* add current stream entries */ From 2470f5464df9e3c797d8dcff260819a637f4e896 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 5 Oct 2020 23:18:29 +0900 Subject: [PATCH 2/4] =?UTF-8?q?TS=E3=82=B9=E3=83=88=E3=83=AA=E3=83=BC?= =?UTF-8?q?=E3=83=A0=E3=81=AE=E5=A4=89=E6=9B=B4=E3=81=B8=E3=81=AE=E8=87=AA?= =?UTF-8?q?=E5=8B=95=E8=BF=BD=E5=BE=93=E3=81=AB=E5=A4=B1=E6=95=97=E3=81=99?= =?UTF-8?q?=E3=82=8B=E4=BA=8B=E3=81=8C=E3=81=82=E3=82=8B=E3=81=AE=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BonDriver共有ツール総合 http://peace.2ch.net/test/read.cgi/avi/1366339738/822 --- src/arib_std_b25.c | 236 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 199 insertions(+), 37 deletions(-) diff --git a/src/arib_std_b25.c b/src/arib_std_b25.c index 4867fed..d06e898 100644 --- a/src/arib_std_b25.c +++ b/src/arib_std_b25.c @@ -512,7 +512,7 @@ static int reset_arib_std_b25(void *std_b25) static int flush_arib_std_b25(void *std_b25) { - int r; + int r,l; int m,n; int32_t crypt; @@ -539,6 +539,9 @@ static int flush_arib_std_b25(void *std_b25) if(r < 0){ return r; } + if(prv->unit_size < 188){ + return ARIB_STD_B25_ERROR_NON_TS_INPUT_STREAM; + } } r = proc_arib_std_b25(prv); @@ -565,6 +568,12 @@ static int flush_arib_std_b25(void *std_b25) if(p == NULL){ goto LAST; } + if((p-curr) >= (unit-188)){ + if(!append_work_buffer(&(prv->dbuf), p-(unit-188), unit-188)){ + r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY; + goto LAST; + } + } curr = p; } @@ -574,7 +583,12 @@ static int flush_arib_std_b25(void *std_b25) if(hdr.transport_error_indicator != 0){ /* bit error - append output buffer without parsing */ - if(!append_work_buffer(&(prv->dbuf), curr, 188)){ + if((curr+unit) <= tail){ + l = unit; + }else{ + l = 188; + } + if(!append_work_buffer(&(prv->dbuf), curr, l)){ r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY; goto LAST; } @@ -588,12 +602,14 @@ static int flush_arib_std_b25(void *std_b25) p = curr+4; if(hdr.adaptation_field_control & 0x02){ p += (p[0]+1); - } - n = 188 - (p-curr); - if( (n < 1) && ((n < 0) || (hdr.adaptation_field_control & 0x01)) ){ - /* broken packet */ - curr += 1; - continue; + n = 188 - (p-curr); + if( (n < 1) && ((n < 0) || (hdr.adaptation_field_control & 0x01)) ){ + /* broken packet */ + curr += 1; + continue; + } + }else{ + n = 188 - 4; } if( (crypt != 0) && @@ -612,6 +628,7 @@ static int flush_arib_std_b25(void *std_b25) m = dec->m2->decrypt(dec->m2, crypt, p, n); if(m < 0){ r = ARIB_STD_B25_ERROR_DECRYPT_FAILURE; + curr += unit; goto LAST; } curr[3] &= 0x3f; @@ -623,7 +640,12 @@ static int flush_arib_std_b25(void *std_b25) prv->map[pid].normal_packet += 1; } - if(!append_work_buffer(&(prv->dbuf), curr, 188)){ + if((curr+unit) <= tail){ + l = unit; + }else{ + l = 188; + } + if(!append_work_buffer(&(prv->dbuf), curr, l)){ r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY; goto LAST; } @@ -633,16 +655,19 @@ static int flush_arib_std_b25(void *std_b25) if( (dec == NULL) || (dec->ecm == NULL) ){ /* this code will never execute */ r = ARIB_STD_B25_ERROR_ECM_PARSE_FAILURE; + curr += unit; goto LAST; } m = dec->ecm->put(dec->ecm, &hdr, p, n); if(m < 0){ r = ARIB_STD_B25_ERROR_ECM_PARSE_FAILURE; + curr += unit; goto LAST; } m = dec->ecm->get_count(dec->ecm); if(m < 0){ r = ARIB_STD_B25_ERROR_ECM_PARSE_FAILURE; + curr += unit; goto LAST; } if(m == 0){ @@ -650,6 +675,7 @@ static int flush_arib_std_b25(void *std_b25) } r = proc_ecm(dec, prv->bcas, prv->multi2_round); if(r < 0){ + curr += unit; goto LAST; } }else if(prv->map[pid].type == PID_MAP_TYPE_PMT){ @@ -657,16 +683,19 @@ static int flush_arib_std_b25(void *std_b25) if( (pgrm == NULL) || (pgrm->pmt == NULL) ){ /* this code will never execute */ r = ARIB_STD_B25_ERROR_PMT_PARSE_FAILURE; + curr += unit; goto LAST; } m = pgrm->pmt->put(pgrm->pmt, &hdr, p, n); if(m < 0){ r = ARIB_STD_B25_ERROR_PMT_PARSE_FAILURE; + curr += unit; goto LAST; } m = pgrm->pmt->get_count(pgrm->pmt); if(m < 0){ r = ARIB_STD_B25_ERROR_PMT_PARSE_FAILURE; + curr += unit; goto LAST; } if(m == 0){ @@ -674,6 +703,7 @@ static int flush_arib_std_b25(void *std_b25) } r = proc_pmt(prv, pgrm); if(r < 0){ + curr += unit; goto LAST; } }else if(prv->map[pid].type == PID_MAP_TYPE_EMM){ @@ -683,18 +713,20 @@ static int flush_arib_std_b25(void *std_b25) if( prv->emm == NULL ){ prv->emm = create_ts_section_parser(); if(prv->emm == NULL){ - r = ARIB_STD_B25_ERROR_EMM_PARSE_FAILURE; + r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY; goto LAST; } } m = prv->emm->put(prv->emm, &hdr, p, n); if(m < 0){ r = ARIB_STD_B25_ERROR_EMM_PARSE_FAILURE; + curr += unit; goto LAST; } m = prv->emm->get_count(prv->emm); if(m < 0){ r = ARIB_STD_B25_ERROR_EMM_PARSE_FAILURE; + curr += unit; goto LAST; } if(m == 0){ @@ -702,6 +734,7 @@ static int flush_arib_std_b25(void *std_b25) } r = proc_emm(prv); if(r < 0){ + curr += unit; goto LAST; } }else if(pid == 0x0001){ @@ -715,11 +748,13 @@ static int flush_arib_std_b25(void *std_b25) m = prv->cat->put(prv->cat, &hdr, p, n); if(m < 0){ r = ARIB_STD_B25_ERROR_CAT_PARSE_FAILURE; + curr += unit; goto LAST; } m = prv->cat->get_count(prv->cat); if(m < 0){ r = ARIB_STD_B25_ERROR_CAT_PARSE_FAILURE; + curr += unit; goto LAST; } if(m == 0){ @@ -727,6 +762,7 @@ static int flush_arib_std_b25(void *std_b25) } r = proc_cat(prv); if(r < 0){ + curr += unit; goto LAST; } }else if(pid == 0x0000){ @@ -740,11 +776,13 @@ static int flush_arib_std_b25(void *std_b25) m = prv->pat->put(prv->pat, &hdr, p, n); if(m < 0){ r = ARIB_STD_B25_ERROR_PAT_PARSE_FAILURE; + curr += unit; goto LAST; } m = prv->pat->get_count(prv->pat); if(m < 0){ r = ARIB_STD_B25_ERROR_PAT_PARSE_FAILURE; + curr += unit; goto LAST; } if(m == 0){ @@ -752,6 +790,7 @@ static int flush_arib_std_b25(void *std_b25) } r = proc_pat(prv); if(r < 0){ + curr += unit; goto LAST; } } @@ -762,11 +801,13 @@ static int flush_arib_std_b25(void *std_b25) LAST: - m = curr - prv->sbuf.head; + m = curr - prv->sbuf.pool; n = tail - curr; if( (n < 1024) || (m > (prv->sbuf.max/2) ) ){ p = prv->sbuf.pool; - memcpy(p, curr, n); + if(n > 0){ + memcpy(p, curr, n); + } prv->sbuf.head = p; prv->sbuf.tail = p+n; }else{ @@ -1011,7 +1052,15 @@ static int select_unit_size(ARIB_STD_B25_PRIVATE_DATA *prv) head = prv->sbuf.head; tail = prv->sbuf.tail; - + + if((tail-head) < (188*16)){ + // need more data + return 0; + } + if((tail-head) > (188*32)){ + tail = head + (188*32); + } + buf = head; memset(count, 0, sizeof(count)); @@ -1086,10 +1135,12 @@ static int find_pat(ARIB_STD_B25_PRIVATE_DATA *prv) p = curr+4; if(hdr.adaptation_field_control & 0x02){ p += (p[0]+1); - } - size = 188 - (p-curr); - if(size < 1){ - goto NEXT; + size = 188 - (p-curr); + if(size < 1){ + goto NEXT; + } + }else{ + size = 188 - 4; } if(prv->pat == NULL){ @@ -1278,6 +1329,45 @@ static int find_pmt(ARIB_STD_B25_PRIVATE_DATA *prv) extract_ts_header(&hdr, curr); + if(hdr.pid == 0x0000){ + p = curr+4; + if(hdr.adaptation_field_control & 0x02){ + p += (p[0]+1); + size = 188 - (p-curr); + if(size < 1){ + goto NEXT; + } + }else{ + size = 188 - 4; + } + if(prv->pat == NULL){ + prv->pat = create_ts_section_parser(); + if(prv->pat == NULL){ + r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY; + goto LAST; + } + } + n = prv->pat->put(prv->pat, &hdr, p, size); + if(n < 0){ + r = ARIB_STD_B25_ERROR_PAT_PARSE_FAILURE; + curr += unit; + goto LAST; + } + n = prv->pat->get_count(prv->pat); + if(n < 0){ + r = ARIB_STD_B25_ERROR_PAT_PARSE_FAILURE; + curr += unit; + goto LAST; + } + if(n == 0){ + goto NEXT; + } + r = proc_pat(prv); + prv->sbuf.head = curr; + curr += unit; + goto LAST; + } + if(prv->map[hdr.pid].type != PID_MAP_TYPE_PMT){ goto NEXT; } @@ -1291,10 +1381,12 @@ static int find_pmt(ARIB_STD_B25_PRIVATE_DATA *prv) p = curr + 4; if(hdr.adaptation_field_control & 0x02){ p += (p[0]+1); - } - size = 188 - (p-curr); - if(size < 1){ - goto NEXT; + size = 188 - (p-curr); + if(size < 1){ + goto NEXT; + } + }else{ + size = 188 - 4; } if(pgrm->pmt == NULL){ @@ -1610,6 +1702,46 @@ static int find_ecm(ARIB_STD_B25_PRIVATE_DATA *prv) curr = p; } extract_ts_header(&hdr, curr); + + if(hdr.pid == 0x0000){ + p = curr+4; + if(hdr.adaptation_field_control & 0x02){ + p += (p[0]+1); + size = 188 - (p-curr); + if(size < 1){ + goto NEXT; + } + }else{ + size = 188 - 4; + } + if(prv->pat == NULL){ + prv->pat = create_ts_section_parser(); + if(prv->pat == NULL){ + r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY; + goto LAST; + } + } + n = prv->pat->put(prv->pat, &hdr, p, size); + if(n < 0){ + r = ARIB_STD_B25_ERROR_PAT_PARSE_FAILURE; + curr += unit; + goto LAST; + } + n = prv->pat->get_count(prv->pat); + if(n < 0){ + r = ARIB_STD_B25_ERROR_PAT_PARSE_FAILURE; + curr += unit; + goto LAST; + } + if(n == 0){ + goto NEXT; + } + r = proc_pat(prv); + prv->sbuf.head = curr; + curr += unit; + goto LAST; + } + if(prv->map[hdr.pid].type != PID_MAP_TYPE_ECM){ goto NEXT; } @@ -1623,10 +1755,12 @@ static int find_ecm(ARIB_STD_B25_PRIVATE_DATA *prv) p = curr + 4; if(hdr.adaptation_field_control & 0x02){ p += (p[0]+1); - } - size = 188 - (p-curr); - if(size < 1){ - goto NEXT; + size = 188 - (p-curr); + if(size < 1){ + goto NEXT; + } + }else{ + size = 188 - 4; } if(dec->ecm == NULL){ @@ -1866,6 +2000,12 @@ static int proc_arib_std_b25(ARIB_STD_B25_PRIVATE_DATA *prv) if(p == NULL){ goto LAST; } + if((p-curr) >= (unit-188)){ + if(!append_work_buffer(&(prv->dbuf), p-(unit-188), unit-188)){ + r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY; + goto LAST; + } + } curr = p; } @@ -1875,7 +2015,7 @@ static int proc_arib_std_b25(ARIB_STD_B25_PRIVATE_DATA *prv) if(hdr.transport_error_indicator != 0){ /* bit error - append output buffer without parsing */ - if(!append_work_buffer(&(prv->dbuf), curr, 188)){ + if(!append_work_buffer(&(prv->dbuf), curr, unit)){ r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY; goto LAST; } @@ -1890,12 +2030,14 @@ static int proc_arib_std_b25(ARIB_STD_B25_PRIVATE_DATA *prv) p = curr+4; if(hdr.adaptation_field_control & 0x02){ p += (p[0]+1); - } - n = 188 - (p-curr); - if( (n < 1) && ((n < 0) || (hdr.adaptation_field_control & 0x01)) ){ - /* broken packet */ - curr += 1; - continue; + n = 188 - (p-curr); + if( (n < 1) && ((n < 0) || (hdr.adaptation_field_control & 0x01)) ){ + /* broken packet */ + curr += 1; + continue; + } + }else{ + n = 188 - 4; } if( (crypt != 0) && @@ -1914,6 +2056,7 @@ static int proc_arib_std_b25(ARIB_STD_B25_PRIVATE_DATA *prv) m = dec->m2->decrypt(dec->m2, crypt, p, n); if(m < 0){ r = ARIB_STD_B25_ERROR_DECRYPT_FAILURE; + curr += unit; goto LAST; } curr[3] &= 0x3f; @@ -1929,7 +2072,7 @@ static int proc_arib_std_b25(ARIB_STD_B25_PRIVATE_DATA *prv) dump_pts(curr, crypt); } #endif - if(!append_work_buffer(&(prv->dbuf), curr, 188)){ + if(!append_work_buffer(&(prv->dbuf), curr, unit)){ r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY; goto LAST; } @@ -1939,16 +2082,19 @@ static int proc_arib_std_b25(ARIB_STD_B25_PRIVATE_DATA *prv) if( (dec == NULL) || (dec->ecm == NULL) ){ /* this code will never execute */ r = ARIB_STD_B25_ERROR_ECM_PARSE_FAILURE; + curr += unit; goto LAST; } m = dec->ecm->put(dec->ecm, &hdr, p, n); if(m < 0){ r = ARIB_STD_B25_ERROR_ECM_PARSE_FAILURE; + curr += unit; goto LAST; } m = dec->ecm->get_count(dec->ecm); if(m < 0){ r = ARIB_STD_B25_ERROR_ECM_PARSE_FAILURE; + curr += unit; goto LAST; } if(m == 0){ @@ -1956,6 +2102,7 @@ static int proc_arib_std_b25(ARIB_STD_B25_PRIVATE_DATA *prv) } r = proc_ecm(dec, prv->bcas, prv->multi2_round); if(r < 0){ + curr += unit; goto LAST; } }else if(prv->map[pid].type == PID_MAP_TYPE_PMT){ @@ -1963,16 +2110,19 @@ static int proc_arib_std_b25(ARIB_STD_B25_PRIVATE_DATA *prv) if( (pgrm == NULL) || (pgrm->pmt == NULL) ){ /* this code will never execute */ r = ARIB_STD_B25_ERROR_PMT_PARSE_FAILURE; + curr += unit; goto LAST; } m = pgrm->pmt->put(pgrm->pmt, &hdr, p, n); if(m < 0){ r = ARIB_STD_B25_ERROR_PMT_PARSE_FAILURE; + curr += unit; goto LAST; } m = pgrm->pmt->get_count(pgrm->pmt); if(m < 0){ r = ARIB_STD_B25_ERROR_PMT_PARSE_FAILURE; + curr += unit; goto LAST; } if(m == 0){ @@ -1980,6 +2130,7 @@ static int proc_arib_std_b25(ARIB_STD_B25_PRIVATE_DATA *prv) } r = proc_pmt(prv, pgrm); if(r < 0){ + curr += unit; goto LAST; } }else if(prv->map[pid].type == PID_MAP_TYPE_EMM){ @@ -1989,18 +2140,20 @@ static int proc_arib_std_b25(ARIB_STD_B25_PRIVATE_DATA *prv) if( prv->emm == NULL ){ prv->emm = create_ts_section_parser(); if(prv->emm == NULL){ - r = ARIB_STD_B25_ERROR_EMM_PARSE_FAILURE; + r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY; goto LAST; } } m = prv->emm->put(prv->emm, &hdr, p, n); if(m < 0){ r = ARIB_STD_B25_ERROR_EMM_PARSE_FAILURE; + curr += unit; goto LAST; } m = prv->emm->get_count(prv->emm); if(m < 0){ r = ARIB_STD_B25_ERROR_EMM_PARSE_FAILURE; + curr += unit; goto LAST; } if(m == 0){ @@ -2008,6 +2161,7 @@ static int proc_arib_std_b25(ARIB_STD_B25_PRIVATE_DATA *prv) } r = proc_emm(prv); if(r < 0){ + curr += unit; goto LAST; } }else if(pid == 0x0001){ @@ -2021,11 +2175,13 @@ static int proc_arib_std_b25(ARIB_STD_B25_PRIVATE_DATA *prv) m = prv->cat->put(prv->cat, &hdr, p, n); if(m < 0){ r = ARIB_STD_B25_ERROR_CAT_PARSE_FAILURE; + curr += unit; goto LAST; } m = prv->cat->get_count(prv->cat); if(m < 0){ r = ARIB_STD_B25_ERROR_CAT_PARSE_FAILURE; + curr += unit; goto LAST; } if(m == 0){ @@ -2033,6 +2189,7 @@ static int proc_arib_std_b25(ARIB_STD_B25_PRIVATE_DATA *prv) } r = proc_cat(prv); if(r < 0){ + curr += unit; goto LAST; } }else if(pid == 0x0000){ @@ -2046,17 +2203,20 @@ static int proc_arib_std_b25(ARIB_STD_B25_PRIVATE_DATA *prv) m = prv->pat->put(prv->pat, &hdr, p, n); if(m < 0){ r = ARIB_STD_B25_ERROR_PAT_PARSE_FAILURE; + curr += unit; goto LAST; } m = prv->pat->get_count(prv->pat); if(m < 0){ r = ARIB_STD_B25_ERROR_PAT_PARSE_FAILURE; + curr += unit; goto LAST; } if(m == 0){ goto NEXT; } r = proc_pat(prv); + curr += unit; goto LAST; } @@ -2065,11 +2225,13 @@ static int proc_arib_std_b25(ARIB_STD_B25_PRIVATE_DATA *prv) } LAST: - m = curr - prv->sbuf.head; + m = curr - prv->sbuf.pool; n = tail - curr; if( (n < 1024) || (m > (prv->sbuf.max/2) ) ){ p = prv->sbuf.pool; - memcpy(p, curr, n); + if(n > 0){ + memcpy(p, curr, n); + } prv->sbuf.head = p; prv->sbuf.tail = p+n; }else{ @@ -2159,7 +2321,7 @@ static int proc_emm(ARIB_STD_B25_PRIVATE_DATA *prv) n = prv->emm->get(prv->emm, §); if(n < 0){ - r = ARIB_STD_B25_ERROR_CAT_PARSE_FAILURE; + r = ARIB_STD_B25_ERROR_EMM_PARSE_FAILURE; goto LAST; } From fcef9b7682c8682d512f56fdaa128c934c86864c Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 5 Oct 2020 23:42:17 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=E3=82=A2=E3=83=80=E3=83=97=E3=83=86?= =?UTF-8?q?=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E3=83=95=E3=82=A3=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E3=83=89=E3=81=AE=E3=81=BF=E3=81=AE=E3=83=91=E3=82=B1?= =?UTF-8?q?=E3=83=83=E3=83=88=E3=81=AE=E3=82=B9=E3=82=AF=E3=83=A9=E3=83=B3?= =?UTF-8?q?=E3=83=96=E3=83=AB=E3=83=95=E3=83=A9=E3=82=B0=E3=81=AE=E5=87=A6?= =?UTF-8?q?=E7=90=86=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BonDriver共有ツール総合 その2 http://peace.2ch.net/test/read.cgi/avi/1428405907/443-444n --- src/arib_std_b25.c | 84 +++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 38 deletions(-) diff --git a/src/arib_std_b25.c b/src/arib_std_b25.c index d06e898..0e969ff 100644 --- a/src/arib_std_b25.c +++ b/src/arib_std_b25.c @@ -612,29 +612,33 @@ static int flush_arib_std_b25(void *std_b25) n = 188 - 4; } - if( (crypt != 0) && - (hdr.adaptation_field_control & 0x01) ){ - - if(prv->map[pid].type == PID_MAP_TYPE_OTHER){ - dec = (DECRYPTOR_ELEM *)(prv->map[pid].target); - }else if( (prv->map[pid].type == 0) && - (prv->decrypt.count == 1) ){ - dec = prv->decrypt.head; - }else{ - dec = NULL; - } + if(crypt != 0){ + if(hdr.adaptation_field_control & 0x01){ - if( (dec != NULL) && (dec->m2 != NULL) ){ - m = dec->m2->decrypt(dec->m2, crypt, p, n); - if(m < 0){ - r = ARIB_STD_B25_ERROR_DECRYPT_FAILURE; - curr += unit; - goto LAST; + if(prv->map[pid].type == PID_MAP_TYPE_OTHER){ + dec = (DECRYPTOR_ELEM *)(prv->map[pid].target); + }else if( (prv->map[pid].type == 0) && + (prv->decrypt.count == 1) ){ + dec = prv->decrypt.head; + }else{ + dec = NULL; } + + if( (dec != NULL) && (dec->m2 != NULL) ){ + m = dec->m2->decrypt(dec->m2, crypt, p, n); + if(m < 0){ + r = ARIB_STD_B25_ERROR_DECRYPT_FAILURE; + curr += unit; + goto LAST; + } + curr[3] &= 0x3f; + prv->map[pid].normal_packet += 1; + }else{ + prv->map[pid].undecrypted += 1; + } + }else{ curr[3] &= 0x3f; prv->map[pid].normal_packet += 1; - }else{ - prv->map[pid].undecrypted += 1; } }else{ prv->map[pid].normal_packet += 1; @@ -2040,29 +2044,33 @@ static int proc_arib_std_b25(ARIB_STD_B25_PRIVATE_DATA *prv) n = 188 - 4; } - if( (crypt != 0) && - (hdr.adaptation_field_control & 0x01) ){ - - if(prv->map[pid].type == PID_MAP_TYPE_OTHER){ - dec = (DECRYPTOR_ELEM *)(prv->map[pid].target); - }else if( (prv->map[pid].type == 0) && - (prv->decrypt.count == 1) ){ - dec = prv->decrypt.head; - }else{ - dec = NULL; - } + if(crypt != 0){ + if(hdr.adaptation_field_control & 0x01){ - if( (dec != NULL) && (dec->m2 != NULL) ){ - m = dec->m2->decrypt(dec->m2, crypt, p, n); - if(m < 0){ - r = ARIB_STD_B25_ERROR_DECRYPT_FAILURE; - curr += unit; - goto LAST; + if(prv->map[pid].type == PID_MAP_TYPE_OTHER){ + dec = (DECRYPTOR_ELEM *)(prv->map[pid].target); + }else if( (prv->map[pid].type == 0) && + (prv->decrypt.count == 1) ){ + dec = prv->decrypt.head; + }else{ + dec = NULL; } + + if( (dec != NULL) && (dec->m2 != NULL) ){ + m = dec->m2->decrypt(dec->m2, crypt, p, n); + if(m < 0){ + r = ARIB_STD_B25_ERROR_DECRYPT_FAILURE; + curr += unit; + goto LAST; + } + curr[3] &= 0x3f; + prv->map[pid].normal_packet += 1; + }else{ + prv->map[pid].undecrypted += 1; + } + }else{ curr[3] &= 0x3f; prv->map[pid].normal_packet += 1; - }else{ - prv->map[pid].undecrypted += 1; } }else{ prv->map[pid].normal_packet += 1; From c7c4bc2c6b25cbbbf114928e8b84bf41082da220 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 6 Oct 2020 00:30:05 +0900 Subject: [PATCH 4/4] =?UTF-8?q?put()=E3=81=8C=E3=82=A8=E3=83=A9=E3=83=BC?= =?UTF-8?q?=E3=81=AB=E3=81=AA=E3=81=A3=E3=81=9F=E5=A0=B4=E5=90=88=E3=81=AE?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=81=AE=E5=A4=89=E6=9B=B4=E3=81=A8=E3=80=81?= =?UTF-8?q?=E6=9C=AA=E5=87=A6=E7=90=86=E3=83=90=E3=83=83=E3=83=95=E3=82=A1?= =?UTF-8?q?=E3=81=AE=E5=9B=9E=E5=8F=8EAPI=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BonDriver共有ツール総合 その2 http://peace.2ch.net/test/read.cgi/avi/1428405907/471 put()のエラー処理の方はsbufとdbufのtail位置を呼び出される前の状態に巻き戻し、未処理バッファの回収APIはsbufのheadからtailまでを返すものをwithdraw()として実装 --- src/arib_std_b25.c | 268 +++++++++++++++++++++++++++++---------------- src/arib_std_b25.h | 2 + 2 files changed, 178 insertions(+), 92 deletions(-) diff --git a/src/arib_std_b25.c b/src/arib_std_b25.c index 0e969ff..209eb6b 100644 --- a/src/arib_std_b25.c +++ b/src/arib_std_b25.c @@ -322,6 +322,7 @@ static int put_arib_std_b25(void *std_b25, ARIB_STD_B25_BUFFER *buf); static int get_arib_std_b25(void *std_b25, ARIB_STD_B25_BUFFER *buf); static int get_program_count_arib_std_b25(void *std_b25); static int get_program_info_arib_std_b25(void *std_b25, ARIB_STD_B25_PROGRAM_INFO *info, int idx); +static int withdraw_arib_std_b25(void *std_b25, ARIB_STD_B25_BUFFER *buf); /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ global function implementation @@ -357,6 +358,7 @@ ARIB25_API_EXPORT ARIB_STD_B25 *create_arib_std_b25() r->get = get_arib_std_b25; r->get_program_count = get_program_count_arib_std_b25; r->get_program_info = get_program_info_arib_std_b25; + r->withdraw = withdraw_arib_std_b25; return r; } @@ -628,7 +630,12 @@ static int flush_arib_std_b25(void *std_b25) m = dec->m2->decrypt(dec->m2, crypt, p, n); if(m < 0){ r = ARIB_STD_B25_ERROR_DECRYPT_FAILURE; - curr += unit; + if((curr+unit) <= tail){ + l = unit; + }else{ + l = 188; + } + curr += l; goto LAST; } curr[3] &= 0x3f; @@ -659,19 +666,34 @@ static int flush_arib_std_b25(void *std_b25) if( (dec == NULL) || (dec->ecm == NULL) ){ /* this code will never execute */ r = ARIB_STD_B25_ERROR_ECM_PARSE_FAILURE; - curr += unit; + if((curr+unit) <= tail){ + l = unit; + }else{ + l = 188; + } + curr += l; goto LAST; } m = dec->ecm->put(dec->ecm, &hdr, p, n); if(m < 0){ r = ARIB_STD_B25_ERROR_ECM_PARSE_FAILURE; - curr += unit; + if((curr+unit) <= tail){ + l = unit; + }else{ + l = 188; + } + curr += l; goto LAST; } m = dec->ecm->get_count(dec->ecm); if(m < 0){ r = ARIB_STD_B25_ERROR_ECM_PARSE_FAILURE; - curr += unit; + if((curr+unit) <= tail){ + l = unit; + }else{ + l = 188; + } + curr += l; goto LAST; } if(m == 0){ @@ -679,7 +701,12 @@ static int flush_arib_std_b25(void *std_b25) } r = proc_ecm(dec, prv->bcas, prv->multi2_round); if(r < 0){ - curr += unit; + if((curr+unit) <= tail){ + l = unit; + }else{ + l = 188; + } + curr += l; goto LAST; } }else if(prv->map[pid].type == PID_MAP_TYPE_PMT){ @@ -687,19 +714,34 @@ static int flush_arib_std_b25(void *std_b25) if( (pgrm == NULL) || (pgrm->pmt == NULL) ){ /* this code will never execute */ r = ARIB_STD_B25_ERROR_PMT_PARSE_FAILURE; - curr += unit; + if((curr+unit) <= tail){ + l = unit; + }else{ + l = 188; + } + curr += l; goto LAST; } m = pgrm->pmt->put(pgrm->pmt, &hdr, p, n); if(m < 0){ r = ARIB_STD_B25_ERROR_PMT_PARSE_FAILURE; - curr += unit; + if((curr+unit) <= tail){ + l = unit; + }else{ + l = 188; + } + curr += l; goto LAST; } m = pgrm->pmt->get_count(pgrm->pmt); if(m < 0){ r = ARIB_STD_B25_ERROR_PMT_PARSE_FAILURE; - curr += unit; + if((curr+unit) <= tail){ + l = unit; + }else{ + l = 188; + } + curr += l; goto LAST; } if(m == 0){ @@ -707,7 +749,12 @@ static int flush_arib_std_b25(void *std_b25) } r = proc_pmt(prv, pgrm); if(r < 0){ - curr += unit; + if((curr+unit) <= tail){ + l = unit; + }else{ + l = 188; + } + curr += l; goto LAST; } }else if(prv->map[pid].type == PID_MAP_TYPE_EMM){ @@ -724,13 +771,23 @@ static int flush_arib_std_b25(void *std_b25) m = prv->emm->put(prv->emm, &hdr, p, n); if(m < 0){ r = ARIB_STD_B25_ERROR_EMM_PARSE_FAILURE; - curr += unit; + if((curr+unit) <= tail){ + l = unit; + }else{ + l = 188; + } + curr += l; goto LAST; } m = prv->emm->get_count(prv->emm); if(m < 0){ r = ARIB_STD_B25_ERROR_EMM_PARSE_FAILURE; - curr += unit; + if((curr+unit) <= tail){ + l = unit; + }else{ + l = 188; + } + curr += l; goto LAST; } if(m == 0){ @@ -738,7 +795,12 @@ static int flush_arib_std_b25(void *std_b25) } r = proc_emm(prv); if(r < 0){ - curr += unit; + if((curr+unit) <= tail){ + l = unit; + }else{ + l = 188; + } + curr += l; goto LAST; } }else if(pid == 0x0001){ @@ -752,13 +814,23 @@ static int flush_arib_std_b25(void *std_b25) m = prv->cat->put(prv->cat, &hdr, p, n); if(m < 0){ r = ARIB_STD_B25_ERROR_CAT_PARSE_FAILURE; - curr += unit; + if((curr+unit) <= tail){ + l = unit; + }else{ + l = 188; + } + curr += l; goto LAST; } m = prv->cat->get_count(prv->cat); if(m < 0){ r = ARIB_STD_B25_ERROR_CAT_PARSE_FAILURE; - curr += unit; + if((curr+unit) <= tail){ + l = unit; + }else{ + l = 188; + } + curr += l; goto LAST; } if(m == 0){ @@ -766,7 +838,12 @@ static int flush_arib_std_b25(void *std_b25) } r = proc_cat(prv); if(r < 0){ - curr += unit; + if((curr+unit) <= tail){ + l = unit; + }else{ + l = 188; + } + curr += l; goto LAST; } }else if(pid == 0x0000){ @@ -780,13 +857,23 @@ static int flush_arib_std_b25(void *std_b25) m = prv->pat->put(prv->pat, &hdr, p, n); if(m < 0){ r = ARIB_STD_B25_ERROR_PAT_PARSE_FAILURE; - curr += unit; + if((curr+unit) <= tail){ + l = unit; + }else{ + l = 188; + } + curr += l; goto LAST; } m = prv->pat->get_count(prv->pat); if(m < 0){ r = ARIB_STD_B25_ERROR_PAT_PARSE_FAILURE; - curr += unit; + if((curr+unit) <= tail){ + l = unit; + }else{ + l = 188; + } + curr += l; goto LAST; } if(m == 0){ @@ -794,7 +881,12 @@ static int flush_arib_std_b25(void *std_b25) } r = proc_pat(prv); if(r < 0){ - curr += unit; + if((curr+unit) <= tail){ + l = unit; + }else{ + l = 188; + } + curr += l; goto LAST; } } @@ -823,8 +915,8 @@ LAST: static int put_arib_std_b25(void *std_b25, ARIB_STD_B25_BUFFER *buf) { - int32_t n; - + int r; + intptr_t slen,dlen; ARIB_STD_B25_PRIVATE_DATA *prv; prv = private_data(std_b25); @@ -832,14 +924,17 @@ static int put_arib_std_b25(void *std_b25, ARIB_STD_B25_BUFFER *buf) return ARIB_STD_B25_ERROR_INVALID_PARAM; } + slen = prv->sbuf.tail - prv->sbuf.head; + dlen = prv->dbuf.tail - prv->dbuf.head; + if(!append_work_buffer(&(prv->sbuf), buf->data, buf->size)){ return ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY; } if(prv->unit_size < 188){ - n = select_unit_size(prv); - if(n < 0){ - return n; + r = select_unit_size(prv); + if(r < 0){ + return r; } if(prv->unit_size < 188){ /* need more data */ @@ -848,9 +943,9 @@ static int put_arib_std_b25(void *std_b25, ARIB_STD_B25_BUFFER *buf) } if(prv->p_count < 1){ - n = find_pat(prv); - if(n < 0){ - return n; + r = find_pat(prv); + if(r < 0){ + return r; } if(prv->p_count < 1){ if(prv->sbuf_offset < (16*1024*1024)){ @@ -865,9 +960,9 @@ static int put_arib_std_b25(void *std_b25, ARIB_STD_B25_BUFFER *buf) } if(!check_pmt_complete(prv)){ - n = find_pmt(prv); - if(n < 0){ - return n; + r = find_pmt(prv); + if(r < 0){ + return r; } if(!check_pmt_complete(prv)){ if(prv->sbuf_offset < (32*1024*1024)){ @@ -882,9 +977,9 @@ static int put_arib_std_b25(void *std_b25, ARIB_STD_B25_BUFFER *buf) } if(!check_ecm_complete(prv)){ - n = find_ecm(prv); - if(n < 0){ - return n; + r = find_ecm(prv); + if(r < 0){ + return r; } if(!check_ecm_complete(prv)){ if(prv->sbuf_offset < (32*1024*1024)){ @@ -898,7 +993,13 @@ static int put_arib_std_b25(void *std_b25, ARIB_STD_B25_BUFFER *buf) prv->sbuf_offset = 0; } - return proc_arib_std_b25(prv); + r = proc_arib_std_b25(prv); + if(r < 0){ + /* rollback */ + prv->sbuf.tail = prv->sbuf.head + slen; + prv->dbuf.tail = prv->dbuf.head + dlen; + } + return r; } static int get_arib_std_b25(void *std_b25, ARIB_STD_B25_BUFFER *buf) @@ -980,6 +1081,22 @@ static int get_program_info_arib_std_b25(void *std_b25, ARIB_STD_B25_PROGRAM_INF return 0; } +static int withdraw_arib_std_b25(void *std_b25, ARIB_STD_B25_BUFFER *buf) +{ + ARIB_STD_B25_PRIVATE_DATA *prv; + prv = private_data(std_b25); + if((prv == NULL) || (buf == NULL)){ + return ARIB_STD_B25_ERROR_INVALID_PARAM; + } + + buf->data = prv->sbuf.head; + buf->size = prv->sbuf.tail - prv->sbuf.head; + + reset_work_buffer(&(prv->sbuf)); + + return 0; +} + /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ private method implementation ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ @@ -2006,8 +2123,7 @@ static int proc_arib_std_b25(ARIB_STD_B25_PRIVATE_DATA *prv) } if((p-curr) >= (unit-188)){ if(!append_work_buffer(&(prv->dbuf), p-(unit-188), unit-188)){ - r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY; - goto LAST; + return ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY; } } curr = p; @@ -2020,8 +2136,7 @@ static int proc_arib_std_b25(ARIB_STD_B25_PRIVATE_DATA *prv) if(hdr.transport_error_indicator != 0){ /* bit error - append output buffer without parsing */ if(!append_work_buffer(&(prv->dbuf), curr, unit)){ - r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY; - goto LAST; + return ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY; } goto NEXT; } @@ -2059,9 +2174,7 @@ static int proc_arib_std_b25(ARIB_STD_B25_PRIVATE_DATA *prv) if( (dec != NULL) && (dec->m2 != NULL) ){ m = dec->m2->decrypt(dec->m2, crypt, p, n); if(m < 0){ - r = ARIB_STD_B25_ERROR_DECRYPT_FAILURE; - curr += unit; - goto LAST; + return ARIB_STD_B25_ERROR_DECRYPT_FAILURE; } curr[3] &= 0x3f; prv->map[pid].normal_packet += 1; @@ -2081,65 +2194,50 @@ static int proc_arib_std_b25(ARIB_STD_B25_PRIVATE_DATA *prv) } #endif if(!append_work_buffer(&(prv->dbuf), curr, unit)){ - r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY; - goto LAST; + return ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY; } if(prv->map[pid].type == PID_MAP_TYPE_ECM){ dec = (DECRYPTOR_ELEM *)(prv->map[pid].target); if( (dec == NULL) || (dec->ecm == NULL) ){ /* this code will never execute */ - r = ARIB_STD_B25_ERROR_ECM_PARSE_FAILURE; - curr += unit; - goto LAST; + return ARIB_STD_B25_ERROR_ECM_PARSE_FAILURE; } m = dec->ecm->put(dec->ecm, &hdr, p, n); if(m < 0){ - r = ARIB_STD_B25_ERROR_ECM_PARSE_FAILURE; - curr += unit; - goto LAST; + return ARIB_STD_B25_ERROR_ECM_PARSE_FAILURE; } m = dec->ecm->get_count(dec->ecm); if(m < 0){ - r = ARIB_STD_B25_ERROR_ECM_PARSE_FAILURE; - curr += unit; - goto LAST; + return ARIB_STD_B25_ERROR_ECM_PARSE_FAILURE; } if(m == 0){ goto NEXT; } r = proc_ecm(dec, prv->bcas, prv->multi2_round); if(r < 0){ - curr += unit; - goto LAST; + return r; } }else if(prv->map[pid].type == PID_MAP_TYPE_PMT){ pgrm = (TS_PROGRAM *)(prv->map[pid].target); if( (pgrm == NULL) || (pgrm->pmt == NULL) ){ /* this code will never execute */ - r = ARIB_STD_B25_ERROR_PMT_PARSE_FAILURE; - curr += unit; - goto LAST; + return ARIB_STD_B25_ERROR_PMT_PARSE_FAILURE; } m = pgrm->pmt->put(pgrm->pmt, &hdr, p, n); if(m < 0){ - r = ARIB_STD_B25_ERROR_PMT_PARSE_FAILURE; - curr += unit; - goto LAST; + return ARIB_STD_B25_ERROR_PMT_PARSE_FAILURE; } m = pgrm->pmt->get_count(pgrm->pmt); if(m < 0){ - r = ARIB_STD_B25_ERROR_PMT_PARSE_FAILURE; - curr += unit; - goto LAST; + return ARIB_STD_B25_ERROR_PMT_PARSE_FAILURE; } if(m == 0){ goto NEXT; } r = proc_pmt(prv, pgrm); if(r < 0){ - curr += unit; - goto LAST; + return r; } }else if(prv->map[pid].type == PID_MAP_TYPE_EMM){ if( prv->emm_proc_on == 0){ @@ -2148,82 +2246,68 @@ static int proc_arib_std_b25(ARIB_STD_B25_PRIVATE_DATA *prv) if( prv->emm == NULL ){ prv->emm = create_ts_section_parser(); if(prv->emm == NULL){ - r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY; - goto LAST; + return ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY; } } m = prv->emm->put(prv->emm, &hdr, p, n); if(m < 0){ - r = ARIB_STD_B25_ERROR_EMM_PARSE_FAILURE; - curr += unit; - goto LAST; + return ARIB_STD_B25_ERROR_EMM_PARSE_FAILURE; } m = prv->emm->get_count(prv->emm); if(m < 0){ - r = ARIB_STD_B25_ERROR_EMM_PARSE_FAILURE; - curr += unit; - goto LAST; + return ARIB_STD_B25_ERROR_EMM_PARSE_FAILURE; } if(m == 0){ goto NEXT; } r = proc_emm(prv); if(r < 0){ - curr += unit; - goto LAST; + return r; } }else if(pid == 0x0001){ if( prv->cat == NULL ){ prv->cat = create_ts_section_parser(); if(prv->cat == NULL){ - r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY; - goto LAST; + return ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY; } } m = prv->cat->put(prv->cat, &hdr, p, n); if(m < 0){ - r = ARIB_STD_B25_ERROR_CAT_PARSE_FAILURE; - curr += unit; - goto LAST; + return ARIB_STD_B25_ERROR_CAT_PARSE_FAILURE; } m = prv->cat->get_count(prv->cat); if(m < 0){ - r = ARIB_STD_B25_ERROR_CAT_PARSE_FAILURE; - curr += unit; - goto LAST; + return ARIB_STD_B25_ERROR_CAT_PARSE_FAILURE; } if(m == 0){ goto NEXT; } r = proc_cat(prv); if(r < 0){ - curr += unit; - goto LAST; + return r; } }else if(pid == 0x0000){ if( prv->pat == NULL ){ prv->pat = create_ts_section_parser(); if(prv->pat == NULL){ - r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY; - goto LAST; + return ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY; } } m = prv->pat->put(prv->pat, &hdr, p, n); if(m < 0){ - r = ARIB_STD_B25_ERROR_PAT_PARSE_FAILURE; - curr += unit; - goto LAST; + return ARIB_STD_B25_ERROR_PAT_PARSE_FAILURE; } m = prv->pat->get_count(prv->pat); if(m < 0){ - r = ARIB_STD_B25_ERROR_PAT_PARSE_FAILURE; - curr += unit; - goto LAST; + return ARIB_STD_B25_ERROR_PAT_PARSE_FAILURE; } if(m == 0){ goto NEXT; } r = proc_pat(prv); + if(r < 0){ + return r; + } curr += unit; goto LAST; } diff --git a/src/arib_std_b25.h b/src/arib_std_b25.h index 922e8cc..7f8c338 100644 --- a/src/arib_std_b25.h +++ b/src/arib_std_b25.h @@ -45,6 +45,8 @@ typedef struct { int (* get_program_count)(void *std_b25); int (* get_program_info)(void *std_b25, ARIB_STD_B25_PROGRAM_INFO *info, int32_t idx); + int (*withdraw)(void *std_b25, ARIB_STD_B25_BUFFER *buf); + } ARIB_STD_B25; #ifdef __cplusplus