diff 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
line wrap: on
line diff
--- 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);