14 #define __STDC_FORMAT_MACROS
20 #include "arib_std_b25.h"
21 #include "b_cas_card.h"
31 static void show_usage();
32 static int parse_arg(OPTION
*dst
, int argc
, char **argv
);
33 static void test_arib_std_b25(const char *src
, const char *dst
, OPTION
*opt
);
34 static void show_bcas_power_on_control_info(B_CAS_CARD
*bcas
);
36 int main(int argc
, char **argv
)
42 _CrtSetReportMode( _CRT_WARN
, _CRTDBG_MODE_FILE
);
43 _CrtSetReportFile( _CRT_WARN
, _CRTDBG_FILE_STDOUT
);
44 _CrtSetReportMode( _CRT_ERROR
, _CRTDBG_MODE_FILE
);
45 _CrtSetReportFile( _CRT_ERROR
, _CRTDBG_FILE_STDOUT
);
46 _CrtSetReportMode( _CRT_ASSERT
, _CRTDBG_MODE_FILE
);
47 _CrtSetReportFile( _CRT_ASSERT
, _CRTDBG_FILE_STDOUT
);
48 _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF
|_CRTDBG_DELAY_FREE_MEM_DF
|_CRTDBG_CHECK_ALWAYS_DF
|_CRTDBG_LEAK_CHECK_DF
);
51 n
= parse_arg(&opt
, argc
, argv
);
57 for(;n
<=(argc
-2);n
+=2){
58 test_arib_std_b25(argv
[n
+0], argv
[n
+1], &opt
);
62 _CrtDumpMemoryLeaks();
68 static void show_usage()
70 fprintf(stderr
, "b25 - ARIB STD-B25 test program ver. 0.2.5 (2012, 2/13)\n");
71 fprintf(stderr
, "usage: b25 [options] src.m2t dst.m2t [more pair ..]\n");
72 fprintf(stderr
, "options:\n");
73 fprintf(stderr
, " -r round (integer, default=4)\n");
74 fprintf(stderr
, " -s strip\n");
75 fprintf(stderr
, " 0: keep null(padding) stream (default)\n");
76 fprintf(stderr
, " 1: strip null stream\n");
77 fprintf(stderr
, " -m EMM\n");
78 fprintf(stderr
, " 0: ignore EMM (default)\n");
79 fprintf(stderr
, " 1: send EMM to B-CAS card\n");
80 fprintf(stderr
, " -p power_on_control_info\n");
81 fprintf(stderr
, " 0: do nothing additionaly\n");
82 fprintf(stderr
, " 1: show B-CAS EMM receiving request (default)\n");
83 fprintf(stderr
, " -v verbose\n");
84 fprintf(stderr
, " 0: silent\n");
85 fprintf(stderr
, " 1: show processing status (default)\n");
86 fprintf(stderr
, "\n");
89 static int parse_arg(OPTION
*dst
, int argc
, char **argv
)
100 if(argv
[i
][0] != '-'){
106 dst
->emm
= atoi(argv
[i
]+2);
108 dst
->emm
= atoi(argv
[i
+1]);
114 dst
->power_ctrl
= atoi(argv
[i
]+2);
116 dst
->power_ctrl
= atoi(argv
[i
+1]);
122 dst
->round
= atoi(argv
[i
]+2);
124 dst
->round
= atoi(argv
[i
+1]);
130 dst
->strip
= atoi(argv
[i
]+2);
132 dst
->strip
= atoi(argv
[i
+1]);
138 dst
->verbose
= atoi(argv
[i
]+2);
140 dst
->verbose
= atoi(argv
[i
+1]);
145 fprintf(stderr
, "error - unknown option '-%c'\n", argv
[i
][1]);
153 static void test_arib_std_b25(const char *src
, const char *dst
, OPTION
*opt
)
161 unsigned long tick
,tock
;
163 struct timeval tick
,tock
;
171 ARIB_STD_B25_PROGRAM_INFO pgrm
;
173 uint8_t data
[64*1024];
175 ARIB_STD_B25_BUFFER sbuf
;
176 ARIB_STD_B25_BUFFER dbuf
;
183 sfd
= _open(src
, _O_BINARY
|_O_RDONLY
|_O_SEQUENTIAL
);
185 fprintf(stderr
, "error - failed on _open(%s) [src]\n", src
);
189 _lseeki64(sfd
, 0, SEEK_END
);
190 total
= _telli64(sfd
);
191 _lseeki64(sfd
, 0, SEEK_SET
);
193 b25
= create_arib_std_b25();
195 fprintf(stderr
, "error - failed on create_arib_std_b25()\n");
199 code
= b25
->set_multi2_round(b25
, opt
->round
);
201 fprintf(stderr
, "error - failed on ARIB_STD_B25::set_multi2_round() : code=%d\n", code
);
205 code
= b25
->set_strip(b25
, opt
->strip
);
207 fprintf(stderr
, "error - failed on ARIB_STD_B25::set_strip() : code=%d\n", code
);
211 code
= b25
->set_emm_proc(b25
, opt
->emm
);
213 fprintf(stderr
, "error - failed on ARIB_STD_B25::set_emm_proc() : code=%d\n", code
);
217 bcas
= create_b_cas_card();
219 fprintf(stderr
, "error - failed on create_b_cas_card()\n");
223 code
= bcas
->init(bcas
);
225 fprintf(stderr
, "error - failed on B_CAS_CARD::init() : code=%d\n", code
);
229 code
= b25
->set_b_cas_card(b25
, bcas
);
231 fprintf(stderr
, "error - failed on ARIB_STD_B25::set_b_cas_card() : code=%d\n", code
);
235 dfd
= _open(dst
, _O_BINARY
|_O_WRONLY
|_O_SEQUENTIAL
|_O_CREAT
|_O_TRUNC
, _S_IREAD
|_S_IWRITE
);
237 fprintf(stderr
, "error - failed on _open(%s) [dst]\n", dst
);
243 tock
= GetTickCount();
245 gettimeofday(&tock
, NULL
);
247 while( (n
= _read(sfd
, data
, sizeof(data
))) > 0 ){
251 code
= b25
->put(b25
, &sbuf
);
253 fprintf(stderr
, "error - failed on ARIB_STD_B25::put() : code=%d\n", code
);
257 code
= b25
->get(b25
, &dbuf
);
259 fprintf(stderr
, "error - failed on ARIB_STD_B25::get() : code=%d\n", code
);
264 n
= _write(dfd
, dbuf
.data
, dbuf
.size
);
266 fprintf(stderr
, "error failed on _write(%d)\n", dbuf
.size
);
272 if(opt
->verbose
!= 0){
273 m
= (int)(10000*offset
/total
);
276 tick
= GetTickCount();
277 if (tick
-tock
> 100) {
283 gettimeofday(&tick
, NULL
);
284 millisec
= (tick
.tv_sec
- tock
.tv_sec
) * 1000;
285 millisec
+= (tick
.tv_usec
- tock
.tv_usec
) / 1000;
286 if(millisec
> 100.0) {
292 fprintf(stderr
, "\rprocessing: %2d.%02d%% [%6.2f MB/sec]", m
/100, m
%100, mbps
);
296 code
= b25
->flush(b25
);
298 fprintf(stderr
, "error - failed on ARIB_STD_B25::flush() : code=%d\n", code
);
302 code
= b25
->get(b25
, &dbuf
);
304 fprintf(stderr
, "error - failed on ARIB_STD_B25::get() : code=%d\n", code
);
309 n
= _write(dfd
, dbuf
.data
, dbuf
.size
);
311 fprintf(stderr
, "error - failed on _write(%d)\n", dbuf
.size
);
316 if(opt
->verbose
!= 0){
319 tick
= GetTickCount();
320 if (tick
-tock
> 100) {
326 gettimeofday(&tick
, NULL
);
327 millisec
= (tick
.tv_sec
- tock
.tv_sec
) * 1000;
328 millisec
+= (tick
.tv_usec
- tock
.tv_usec
) / 1000;
329 if(millisec
> 100.0) {
335 fprintf(stderr
, "\rprocessing: finish [%6.2f MB/sec]\n", mbps
);
340 n
= b25
->get_program_count(b25
);
342 fprintf(stderr
, "error - failed on ARIB_STD_B25::get_program_count() : code=%d\n", code
);
346 code
= b25
->get_program_info(b25
, &pgrm
, i
);
348 fprintf(stderr
, "error - failed on ARIB_STD_B25::get_program_info(%d) : code=%d\n", i
, code
);
351 if(pgrm
.ecm_unpurchased_count
> 0){
352 fprintf(stderr
, "warning - unpurchased ECM is detected\n");
353 fprintf(stderr
, " channel: %d\n", pgrm
.program_number
);
354 fprintf(stderr
, " unpurchased ECM count: %d\n", pgrm
.ecm_unpurchased_count
);
355 fprintf(stderr
, " last ECM error code: %04x\n", pgrm
.last_ecm_error_code
);
357 fprintf(stderr
, " undecrypted TS packet: %d\n", pgrm
.undecrypted_packet_count
);
358 fprintf(stderr
, " total TS packet: %d\n", pgrm
.total_packet_count
);
360 fprintf(stderr
, " undecrypted TS packet: %"PRId64
"\n", pgrm
.undecrypted_packet_count
);
361 fprintf(stderr
, " total TS packet: %"PRId64
"\n", pgrm
.total_packet_count
);
366 if(opt
->power_ctrl
!= 0){
367 show_bcas_power_on_control_info(bcas
);
393 static void show_bcas_power_on_control_info(B_CAS_CARD
*bcas
)
397 B_CAS_PWR_ON_CTRL_INFO pwc
;
399 code
= bcas
->get_pwr_on_ctrl(bcas
, &pwc
);
401 fprintf(stderr
, "error - failed on B_CAS_CARD::get_pwr_on_ctrl() : code=%d\n", code
);
406 fprintf(stdout
, "no EMM receiving request\n");
410 fprintf(stdout
, "total %d EMM receiving request\n", pwc
.count
);
411 for(i
=0;i
<pwc
.count
;i
++){
412 fprintf(stdout
, "+ [%d] : tune ", i
);
413 switch(pwc
.data
[i
].network_id
){
415 w
= pwc
.data
[i
].transport_id
;
416 fprintf(stdout
, "BS-%d/TS-%d ", ((w
>> 4) & 0x1f), (w
& 7));
420 w
= pwc
.data
[i
].transport_id
;
421 fprintf(stdout
, "ND-%d/TS-%d ", ((w
>> 4) & 0x1f), (w
& 7));
424 fprintf(stdout
, "unknown(b:0x%02x,n:0x%04x,t:0x%04x) ", pwc
.data
[i
].broadcaster_group_id
, pwc
.data
[i
].network_id
, pwc
.data
[i
].transport_id
);
427 fprintf(stdout
, "between %04d %02d/%02d ", pwc
.data
[i
].s_yy
, pwc
.data
[i
].s_mm
, pwc
.data
[i
].s_dd
);
428 fprintf(stdout
, "to %04d %02d/%02d ", pwc
.data
[i
].l_yy
, pwc
.data
[i
].l_mm
, pwc
.data
[i
].l_dd
);
429 fprintf(stdout
, "least %d hours\n", pwc
.data
[i
].hold_time
);