changeset 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 c44e16dbb0e2
children
files arib25/readme.txt arib25/src/Makefile arib25/src/arib_std_b25.c arib25/src/b_cas_card.c arib25/src/td.c
diffstat 5 files changed, 146 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/arib25/readme.txt	Wed Nov 18 13:12:44 2009 +0900
+++ b/arib25/readme.txt	Wed Feb 15 11:09:02 2012 +0900
@@ -4,7 +4,7 @@
 
 【バージョン】
 
- 0.2.3
+ 0.2.5
 
 【作者】
 
@@ -13,11 +13,11 @@
 
 【一次配布元】
 
- http://www.marumo.ne.jp/db2008_c.htm#30
+ http://www.marumo.ne.jp/db2012_2.htm#13 又は
 
  あるいは
 
- http://www.marumo.ne.jp/junk/arib_std_b25-0.2.3.lzh
+ http://www.marumo.ne.jp/junk/arib_std_b25-0.2.5.lzh
 
 【目的】
 
@@ -56,7 +56,8 @@
  「住基カード対応 IC カードリーダ」「e-Tax 対応 IC カードリーダ」
  などとして 4000 円程度で販売されているものが利用可能である
 
- 日立マクセル製の HX-520UJJ で正常に動作することを確認している
+ 日立マクセル製の HX-520UJJ と NTT コミュニケーションズの SCR3310 
+ で正常に動作することを確認している
 
 【ソースコードのライセンスについて】
 
@@ -191,6 +192,14 @@
 
 【更新履歴】
 
+ ・2012, 2/13 - ver. 0.2.5
+
+  WOWOW でノンスクランブル <-> スクランブル切り替え後に復号が
+  行われないことがあるバグを修正
+
+  http://www.marumo.ne.jp/db2012_2.htm#13 又は
+  http://www.marumo.ne.jp/junk/arib_std_b25-0.2.5.lzh
+
  ・2009, 4/19 - ver. 0.2.4
 
   終端パケットが野良パケット (PMT に記載されていない PID の
--- a/arib25/src/Makefile	Wed Nov 18 13:12:44 2009 +0900
+++ b/arib25/src/Makefile	Wed Feb 15 11:09:02 2012 +0900
@@ -1,7 +1,7 @@
 PREFIX = /usr/local
 MAJOR = 0
 MINOR = 2
-REVISION = 4
+REVISION = 5
 VER = $(MAJOR).$(MINOR).$(REVISION)
 
 DEST_HEADER = $(PREFIX)/include/arib25
--- a/arib25/src/arib_std_b25.c	Wed Nov 18 13:12:44 2009 +0900
+++ b/arib25/src/arib_std_b25.c	Wed Feb 15 11:09:02 2012 +0900
@@ -1,5 +1,6 @@
 #include <stdlib.h>
 #include <string.h>
+#include <stdio.h>
 
 #include "arib_std_b25.h"
 #include "arib_std_b25_error_code.h"
@@ -1403,8 +1404,14 @@
 			goto LAST;
 		}
 		dec[0]->ref += 1;
+	} else {
+		if (prv->decrypt.count == 1) {
+			dec[0] = prv->decrypt.head;
+			dec[0]->ref += 1;
+		}
 	}
 	head += length;
+
 	
 	/* unref old stream entries */
 	while( (strm = get_stream_list_head(&(pgrm->old_strm))) != NULL ){
@@ -1485,7 +1492,7 @@
 		}
 	}
 
-	return 0;
+	return r;
 }
 		
 static int32_t find_ca_descriptor_pid(uint8_t *head, uint8_t *tail, int32_t ca_system_id)
@@ -1755,6 +1762,22 @@
 
 	dec->m2->set_scramble_key(dec->m2, res.scramble_key);
 
+	if (0) {
+		int i;
+		fprintf(stdout, "----\n");
+		fprintf(stdout, "odd: ");
+		for(i=0;i<8;i++){
+			fprintf(stdout, " %02x", res.scramble_key[i]);
+		}
+		fprintf(stdout, "\n");
+		fprintf(stdout, "even:");
+		for(i=8;i<16;i++){
+			fprintf(stdout, " %02x", res.scramble_key[i]);
+		}
+		fprintf(stdout, "\n");
+		fflush(stdout);
+	}
+
 LAST:
 	if(sect.raw != NULL){
 		n = dec->ecm->ret(dec->ecm, &sect);
@@ -1766,6 +1789,42 @@
 	return r;
 }
 
+static void dump_pts(uint8_t *src, int32_t crypt)
+{
+	int32_t pts_dts_flag;
+	int64_t pts,dts;
+
+	src += 4; // TS 繝倥ャ繝驛ィ
+	src += 4; // start_code_prefix + stream_id 驛ィ
+	src += 2; // packet_length 驛ィ
+
+	pts_dts_flag = (src[1] >> 6) & 3;
+
+	src += 3;
+	if(pts_dts_flag & 2){
+		// PTS
+		pts = (src[0] >> 1) & 0x07;
+		pts <<= 15;
+		pts += ((src[1] << 8) + src[2]) >> 1;
+		pts <<= 15;
+		pts += ((src[3] << 8) + src[4]) >> 1;
+		src += 5;
+	}
+	if(pts_dts_flag & 1){
+		// DTS
+		dts = (src[0] >> 1) & 0x07;
+		dts <<= 15;
+		dts += ((src[1] << 8) + src[2]) >> 1;
+		dts <<= 15;
+		dts += ((src[3] << 8) + src[4]) >> 1;
+	}
+
+	if(pts_dts_flag == 2){
+		fprintf(stdout, "  key=%d, pts=%"PRId64"\n", crypt, pts/90);
+		fflush(stdout);
+	}
+}
+
 static int proc_arib_std_b25(ARIB_STD_B25_PRIVATE_DATA *prv)
 {
 	int r;
@@ -1860,7 +1919,11 @@
 		}else{
 			prv->map[pid].normal_packet += 1;
 		}
-
+#if 0
+		if( (hdr.payload_unit_start_indicator != 0) && (pid == 0x111) ){
+			dump_pts(curr, crypt);
+		}
+#endif
 		if(!append_work_buffer(&(prv->dbuf), curr, 188)){
 			r = ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY;
 			goto LAST;
@@ -2069,7 +2132,7 @@
 static int proc_emm(ARIB_STD_B25_PRIVATE_DATA *prv)
 {
 	int r;
-	int i,j,n;
+	int j,n;
 
 	int len;
 
@@ -2106,16 +2169,15 @@
 		head = sect.data;
 		tail = sect.tail - 4;
 
-		i = 0;
 		while( (head+13) <= tail ){
-			
+
 			extract_emm_fixed_part(&emm_hdr, head);
 			len = emm_hdr.associated_information_length+7;
 			if( (head+len) > tail ){
 				/* broken EMM element */
 				goto NEXT;
 			}
-			
+
 			for(j=0;j<prv->casid.count;j++){
 				if(prv->casid.data[j] == emm_hdr.card_id){
 					n = prv->bcas->proc_emm(prv->bcas, head, len);
--- a/arib25/src/b_cas_card.c	Wed Nov 18 13:12:44 2009 +0900
+++ b/arib25/src/b_cas_card.c	Wed Feb 15 11:09:02 2012 +0900
@@ -263,18 +263,18 @@
 		if( p+10 > tail ){
 			return B_CAS_CARD_ERROR_TRANSMIT_FAILED;
 		}
-		
+#if 0
 		{
 			int maker_id;
 			int version;
 			int check_code;
-			
+
 			maker_id = p[0];
 			version = p[1];
 			prv->id.data[i] = load_be_uint48(p+2);
 			check_code = load_be_uint16(p+8);
 		}
-		
+#endif
 		p += 10;
 	}
 
--- a/arib25/src/td.c	Wed Nov 18 13:12:44 2009 +0900
+++ b/arib25/src/td.c	Wed Feb 15 11:09:02 2012 +0900
@@ -14,6 +14,7 @@
 	#define __STDC_FORMAT_MACROS
 	#include <inttypes.h>
 	#include <unistd.h>
+	#include <sys/time.h>
 #endif
 
 #include "arib_std_b25.h"
@@ -36,7 +37,7 @@
 {
 	int n;
 	OPTION opt;
-	
+
 	#if defined(WIN32)
 	_CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
 	_CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
@@ -53,7 +54,9 @@
 		exit(EXIT_FAILURE);
 	}
 
-	test_arib_std_b25(argv[n+0], argv[n+1], &opt);
+	for(;n<=(argc-2);n+=2){
+		test_arib_std_b25(argv[n+0], argv[n+1], &opt);
+	}
 
 	#if defined(WIN32)
 	_CrtDumpMemoryLeaks();
@@ -64,8 +67,8 @@
 
 static void show_usage()
 {
-	fprintf(stderr, "b25 - ARIB STD-B25 test program ver. 0.2.4 (2009, 4/18)\n");
-	fprintf(stderr, "usage: b25 [options] src.m2t dst.m2t\n");
+	fprintf(stderr, "b25 - ARIB STD-B25 test program ver. 0.2.5 (2012, 2/13)\n");
+	fprintf(stderr, "usage: b25 [options] src.m2t dst.m2t [more pair ..]\n");
 	fprintf(stderr, "options:\n");
 	fprintf(stderr, "  -r round (integer, default=4)\n");
 	fprintf(stderr, "  -s strip\n");
@@ -154,13 +157,20 @@
 
 	int64_t total;
 	int64_t offset;
+#if defined(WIN32)
+	unsigned long tick,tock;
+#else
+	struct timeval tick,tock;
+	double millisec;
+#endif
+	double mbps;
 
 	ARIB_STD_B25 *b25;
 	B_CAS_CARD   *bcas;
 
 	ARIB_STD_B25_PROGRAM_INFO pgrm;
 
-	uint8_t data[8*1024];
+	uint8_t data[64*1024];
 
 	ARIB_STD_B25_BUFFER sbuf;
 	ARIB_STD_B25_BUFFER dbuf;
@@ -175,7 +185,7 @@
 		fprintf(stderr, "error - failed on _open(%s) [src]\n", src);
 		goto LAST;
 	}
-	
+
 	_lseeki64(sfd, 0, SEEK_END);
 	total = _telli64(sfd);
 	_lseeki64(sfd, 0, SEEK_SET);
@@ -229,6 +239,11 @@
 	}
 
 	offset = 0;
+#if defined(WIN32)
+	tock = GetTickCount();
+#else
+	gettimeofday(&tock, NULL);
+#endif
 	while( (n = _read(sfd, data, sizeof(data))) > 0 ){
 		sbuf.data = data;
 		sbuf.size = n;
@@ -252,11 +267,29 @@
 				goto LAST;
 			}
 		}
-		
+
 		offset += sbuf.size;
 		if(opt->verbose != 0){
 			m = (int)(10000*offset/total);
-			fprintf(stderr, "\rprocessing: %2d.%02d%% ", m/100, m%100);
+			mbps = 0.0;
+#if defined(WIN32)
+			tick = GetTickCount();
+			if (tick-tock > 100) {
+				mbps = offset;
+				mbps /= 1024;
+				mbps /= (tick-tock);
+			}
+#else
+			gettimeofday(&tick, NULL);
+			millisec = (tick.tv_sec - tock.tv_sec) * 1000;
+			millisec += (tick.tv_usec - tock.tv_usec) / 1000;
+			if(millisec > 100.0) {
+				mbps = offset;
+				mbps /= 1024;
+				mbps /= millisec;
+			}
+#endif
+			fprintf(stderr, "\rprocessing: %2d.%02d%% [%6.2f MB/sec]", m/100, m%100, mbps);
 		}
 	}
 
@@ -265,7 +298,7 @@
 		fprintf(stderr, "error - failed on ARIB_STD_B25::flush() : code=%d\n", code);
 		goto LAST;
 	}
-	
+
 	code = b25->get(b25, &dbuf);
 	if(code < 0){
 		fprintf(stderr, "error - failed on ARIB_STD_B25::get() : code=%d\n", code);
@@ -281,7 +314,25 @@
 	}
 
 	if(opt->verbose != 0){
-		fprintf(stderr, "\rprocessing: finish  \n");
+		mbps = 0.0;
+#if defined(WIN32)
+		tick = GetTickCount();
+		if (tick-tock > 100) {
+			mbps = offset;
+			mbps /= 1024;
+			mbps /= (tick-tock);
+		}
+#else
+		gettimeofday(&tick, NULL);
+		millisec = (tick.tv_sec - tock.tv_sec) * 1000;
+		millisec += (tick.tv_usec - tock.tv_usec) / 1000;
+		if(millisec > 100.0) {
+			mbps = offset;
+			mbps /= 1024;
+			mbps /= millisec;
+		}
+#endif
+		fprintf(stderr, "\rprocessing: finish  [%6.2f MB/sec]\n", mbps);
 		fflush(stderr);
 		fflush(stdout);
 	}