author | kui.zhang <kui.zhang@amlogic.com> | 2012-08-31 07:45:19 (GMT) |
---|---|---|
committer | kui.zhang <kui.zhang@amlogic.com> | 2012-08-31 07:45:19 (GMT) |
commit | d08a82eab77461718bdcf728cfcb4e1656296238 (patch) | |
tree | f46eb923c717aff37aec3c26a392db6a9118ae0a | |
parent | 13ab269d1919746ee585c4d1ab07b4efb274025e (diff) | |
download | libzvbi-d08a82eab77461718bdcf728cfcb4e1656296238.zip libzvbi-d08a82eab77461718bdcf728cfcb4e1656296238.tar.gz libzvbi-d08a82eab77461718bdcf728cfcb4e1656296238.tar.bz2 |
add ntsc so
-rwxr-xr-x | ntsc_decode/Android.mk | 4 | ||||
-rwxr-xr-x | ntsc_decode/decode.c | 421 | ||||
-rwxr-xr-x | ntsc_decode/sliced1.c | 25 | ||||
-rwxr-xr-x | ntsc_decode/test/Android.mk | 16 | ||||
-rwxr-xr-x | ntsc_decode/test/decode.c | 1415 |
5 files changed, 1452 insertions, 429 deletions
diff --git a/ntsc_decode/Android.mk b/ntsc_decode/Android.mk index 07effe5..9bdc56e 100755 --- a/ntsc_decode/Android.mk +++ b/ntsc_decode/Android.mk @@ -7,9 +7,9 @@ LOCAL_SHARED_LIBRARIES+= libzvbi LOCAL_C_INCLUDES:=$(LOCAL_PATH)/../src \ $(LOCAL_PATH)/ -LOCAL_MODULE:= xds_decode +LOCAL_MODULE:= ntsc_decode LOCAL_MODULE_TAGS := optional LOCAL_ARM_MODE := arm LOCAL_CFLAGS+=-D_REENTRANT -D_GNU_SOURCE -DENABLE_DVB=1 -DENABLE_V4L=1 -DENABLE_V4L2=1 -DHAVE_ICONV=1 -DPACKAGE=\"zvbi\" -DVERSION=\"0.2.33\" -DANDROID -DHAVE_GETOPT_LONG=1 LOCAL_SHARED_LIBRARIES += libicuuc liblog -include $(BUILD_EXECUTABLE) +include $(BUILD_SHARED_LIBRARY)
\ No newline at end of file diff --git a/ntsc_decode/decode.c b/ntsc_decode/decode.c index 7cfff30..c9545c6 100755 --- a/ntsc_decode/decode.c +++ b/ntsc_decode/decode.c @@ -279,30 +279,10 @@ xds_cb (vbi_xds_demux * xd, } static void -caption ( uint8_t buffer[4], +caption (const uint8_t buffer[2], unsigned int line) { - - if (option_decode_xds && 284== line) { - int c1; - int c2; - /*c1 = buffer[0];//vbi_unpar8 (buffer[0]); - c2 = buffer[1];//vbi_unpar8 (buffer[1]); - - //switch (c1) { - case 0x00: - //* Stuffing. - break; - case 0x01 ... 0x0E: - printf("line is 284 is %d %d\n",buffer[2],buffer[3]); - xds->subpacket[c1][c2].count = buffer[0] + buffer[1]; - xds->subpacket[c1][c2].buffer[0] = buffer[2]; - xds->subpacket[c1][c2].buffer[1] = buffer[3]; - break; - case 0x0F: - //* Packet terminator. - break; - }*/ + if (option_decode_xds && 284 == line) { if (!vbi_xds_demux_feed (xds, buffer)) { printf ("Parity error in XDS data.\n"); } @@ -822,7 +802,7 @@ wss_625 (const uint8_t buffer[2]) #endif /* 3 == VBI_VERSION_MINOR */ static vbi_bool -decode_frame ( vbi_sliced * s, +decode_frame (const vbi_sliced * s, unsigned int n_lines, const uint8_t * raw, const vbi_sampling_par *sp, @@ -865,10 +845,7 @@ decode_frame ( vbi_sliced * s, last_stream_time = stream_time; } printf("decode_frame while\n"); - static int i =0; - //******************temp*************************// - //s->id = VBI_SLICED_CAPTION_525; while (n_lines > 0) { switch (s->id) { case VBI_SLICED_TELETEXT_B_L10_625: @@ -888,11 +865,8 @@ decode_frame ( vbi_sliced * s, case VBI_SLICED_CAPTION_525_F1: case VBI_SLICED_CAPTION_525_F2: case VBI_SLICED_CAPTION_525: - //******************************************************************// - //printf("decode_frame VBI_SLICED_CAPTION_525\n"); caption (s->data, s->line); - //******************************************************************// - break; + break; case VBI_SLICED_WSS_625: #if 3 == VBI_VERSION_MINOR /* XXX port me back */ @@ -901,9 +875,7 @@ decode_frame ( vbi_sliced * s, break; case VBI_SLICED_WSS_CPR1204: - break; - - + break; } ++s; @@ -1010,393 +982,32 @@ long_options [] = { static int option_index; -int -main (int argc, - char ** argv) -{ - -//************************************************* - /*unsigned char pBuffer [5100] ; - memset(pBuffer,0, 5100 ); */ - #if defined(VBI_CC_SUPPORT) - typedef struct cc_data_s { - unsigned int vbi_type : 8; // vbi data type: us_cc, teletext,wss_625,wssj,vps.... - unsigned int field_id : 8; // field type: 0:even; 1:odd; - unsigned int nbytes : 16; // data byte count: cc:two bytes; tt: depends on tt spec - unsigned int line_num : 16; // vbi data line number - unsigned char b[2]; // : 8; // cc data1 - //unsigned int b2 : 8; // cc data2 - } cc_data_t; - #endif - - unsigned char pBuffer[] ={ - 0x00,0x01,0x02,0x00,0x15,0x00,0x00,0x00, - 0x00,0x01,0x02,0x00,0x15,0x00,0x01,0x05, - 0x00,0x01,0x02,0x00,0x15,0x00,0x41,0x40, - 0x00,0x01,0x02,0x00,0x15,0x00,0x0f,0x6a, - 0x00,0x01,0x02,0x00,0x15,0x00,0x00,0x00, - 0x00,0x01,0x02,0x00,0x15,0x00,0x00,0x00, - 0x00,0x01,0x02,0x00,0x15,0x00,0x15,0x2c, - 0x00,0x01,0x02,0x00,0x15,0x00,0x15,0x2e, - 0x00,0x01,0x02,0x00,0x15,0x00,0x15,0x20, - 0x00,0x01,0x02,0x00,0x15,0x00,0x16,0x46, - 0x00,0x01,0x02,0x00,0x15,0x00,0x20,0x20, - 0x00,0x01,0x02,0x00,0x15,0x00,0x10,0x22, - 0x00,0x01,0x02,0x00,0x15,0x00,0x43,0x6c, - 0x00,0x01,0x02,0x00,0x15,0x00,0x6f,0x73, - 0x00,0x01,0x02,0x00,0x15,0x00,0x65,0x64, - 0x00,0x01,0x02,0x00,0x15,0x00,0x20,0x43, - 0x00,0x01,0x02,0x00,0x15,0x00,0x61,0x70, - 0x00,0x01,0x02,0x00,0x15,0x00,0x74,0x69, - 0x00,0x01,0x02,0x00,0x15,0x00,0x6f,0x6e , - - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x2f, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a, - - 0x00,0x00,0x02,0x00,0x1c,0x01,0x41,0x00, - - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x45,0x00, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21, - - 0x00,0x00,0x02,0x00,0x1c,0x01,0x4f,0x00, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23, - - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x75,0x00, - - - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x2f, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a, - - 0x00,0x00,0x02,0x00,0x1c,0x01,0x41,0x00, - - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x45,0x00, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21, - - 0x00,0x00,0x02,0x00,0x1c,0x01,0x4f,0x00, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23, - - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x75,0x00, - - - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x2f, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a, - - 0x00,0x00,0x02,0x00,0x1c,0x01,0x41,0x00, - - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x45,0x00, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21, - - 0x00,0x00,0x02,0x00,0x1c,0x01,0x4f,0x00, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23, - - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x75,0x00, - - - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x2f, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a, - - 0x00,0x00,0x02,0x00,0x1c,0x01,0x41,0x00, - - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x45,0x00, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21, - - 0x00,0x00,0x02,0x00,0x1c,0x01,0x4f,0x00, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23, - - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x75,0x00, - }; - - unsigned char pBuffer11[] ={ 1,21, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x2f, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a, - - 0x00,0x00,0x02,0x00,0x1c,0x01,0x41,0x00, - - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x45,0x00, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21, - - 0x00,0x00,0x02,0x00,0x1c,0x01,0x4f,0x00, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23, - - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24, - 0x00,0x00,0x02,0x00,0x1c,0x01,0x75,0x00, - - }; - - - int length = N_ELEMENTS (pBuffer); - /*int write_len ; - static FILE *file_fd = NULL; - if(!file_fd){ - file_fd = fopen("/mnt/sda1/111.bin", "wb+"); - if(file_fd == NULL) - { - printf(">>> transfer_vod_fwrite(), fopen() error1111\n"); - } - } - write_len = fwrite(pBuffer, 1, length, file_fd); - printf("->>> Write kankan_file, size=%d write_len =%d\n", length,write_len); - if(file_fd != NULL){ - fclose(file_fd); - file_fd = NULL; - }*/ -//************************************************* - - - init_helpers (argc, argv); - printf("zkinit_helpers\n"); - option_in_file_format = FILE_FORMAT_SLICED; - - #ifdef HAVE_GETOPT_LONG - printf("HAVE_GETOPT_LONG\n"); - #else - printf("NOT_HAVE_GETOPT_LONG\n"); - #endif - - printf("_HAVEFAFDAFDASFD_GETOPT_LONG\n"); - while(FALSE) { // (;;) { - int c; - printf(" 111111111111"); - c = getopt_long (argc, argv, short_options, - long_options, &option_index); - printf("zk%d\n",c); - if (-1 == c) - break; - - switch (c) { - case 0: /* getopt_long() flag */ - break; - - case '1': - option_decode_8301 ^= TRUE; - break; - - case '2': - option_decode_8302 ^= TRUE; - break; - - case 'a': - option_decode_ttx = TRUE; - option_decode_8301 = TRUE; - option_decode_8302 = TRUE; - option_decode_caption = TRUE; - option_decode_idl = TRUE; - option_decode_vps = TRUE; - option_decode_wss = TRUE; - option_decode_xds = TRUE; - option_pfc_pgno = 0x1DF; - break; - - case 'b': - option_dump_bin ^= TRUE; - break; - - case 'c': - option_decode_caption ^= TRUE; - break; - case 'd': - assert (NULL != optarg); - option_idl_address = strtol (optarg, NULL, 0); - break; - case 'e': - option_dump_hex ^= TRUE; - break; - case 'h': - usage (stdout); - exit (EXIT_SUCCESS); - case 'i': - assert (NULL != optarg); - option_in_file_name = optarg; - break; - case 'j': - option_decode_idl ^= TRUE; - break; - case 'l': - assert (NULL != optarg); - option_idl_channel = strtol (optarg, NULL, 0); - break; - - case 'm': - option_dump_time ^= TRUE; - break; - - case 'n': - option_dump_network ^= TRUE; - break; - case 'p': - assert (NULL != optarg); - option_pfc_pgno = strtol (optarg, NULL, 16); - break; - - case 'q': - parse_option_quiet (); - break; - - case 'r': - option_decode_vps_other ^= TRUE; - break; - - case 's': - assert (NULL != optarg); - option_pfc_stream = strtol (optarg, NULL, 0); - break; - - case 't': - option_decode_ttx ^= TRUE; - break; - - case 'v': - option_decode_vps ^= TRUE; - break; - - case 'w': - option_decode_wss ^= TRUE; - break; - - case 'x': - option_decode_xds ^= TRUE; - break; - - case 'M': - assert (NULL != optarg); - option_metronome_tick = strtod (optarg, NULL); - break; - - case 'P': - option_in_file_format = FILE_FORMAT_DVB_PES; - break; - - case 'T': - option_in_ts_pid = parse_option_ts (); - option_in_file_format = FILE_FORMAT_DVB_TS; - break; - - case 'V': - printf (PROGRAM_NAME " " VERSION "\n"); - exit (EXIT_SUCCESS); - - default: - usage (stderr); - exit (EXIT_FAILURE); - } - } - - //****************************************temp*************** +int start_demux_ntsc(){ + unsigned char pBuffer [5100] ; + memset(pBuffer,0, 5100 ); option_decode_xds = TRUE; option_decode_caption = TRUE; - //option_in_file_name = argv[1]; - - printf("zkoption_decode_xds\n"); - //printf("option_in_file_name%s\n",option_in_file_name); - - if (0 != option_pfc_pgno) { - printf("option_pfc_pgno\n"); - pfc = vbi_pfc_demux_new (option_pfc_pgno, - option_pfc_stream, - page_function_clear_cb, - /* user_data */ NULL); - if (NULL == pfc) - no_mem_exit (); - } - - if (0 != option_idl_channel) { - printf("option_idl_channel\n"); - idl = vbi_idl_a_demux_new (option_idl_channel, - option_idl_address, - idl_format_a_cb, - /* user_data */ NULL); - if (NULL == idl) - no_mem_exit (); - } + int length = N_ELEMENTS (pBuffer); - if (option_decode_xds) { - printf("decode xds\n"); xds = vbi_xds_demux_new (xds_cb, /* used_data */ NULL); if (NULL == xds) no_mem_exit (); - }else - printf("not decode xds\n"); + rst = read_stream_new (pBuffer,length, option_in_file_format, option_in_ts_pid, decode_frame); - - printf("stream_loop\n"); - stream_loop (rst); + stream_loop (rst); stream_delete (rst); rst = NULL; @@ -1404,12 +1015,8 @@ main (int argc, vbi_xds_demux_delete (xds); xds = NULL; + + return TRUE; - vbi_idl_demux_delete (idl); - idl = NULL; - - vbi_pfc_demux_delete (pfc); - pfc = NULL; - - exit (EXIT_SUCCESS); } + diff --git a/ntsc_decode/sliced1.c b/ntsc_decode/sliced1.c index 0b4d731..25c234a 100755 --- a/ntsc_decode/sliced1.c +++ b/ntsc_decode/sliced1.c @@ -241,7 +241,6 @@ stream_delete (struct stream * st) vbi_bool stream_loop (struct stream * st) { - printf("stream_loop11\n"); return st->loop (st); } @@ -883,8 +882,6 @@ next_block (struct stream * st, if (buffer_size <= available) { memcpy (buffer, st->bp, buffer_size); - printf("block %d,%d %d %d \n",buffer[0],buffer[1],buffer[2],buffer[3]); - st->bp += buffer_size; return; } @@ -1029,15 +1026,10 @@ next_time_delta (struct stream * st, return TRUE; } } - c =c + '0'; - if(isdigit (c)) - printf("is digit\n"); - else - printf("isnot digit\n"); - + if ('-' != c && '.' != c && !isdigit (c)) bad_format_exit (); - return TRUE; + buffer[i] = c; } @@ -1047,7 +1039,6 @@ next_time_delta (struct stream * st, static vbi_bool read_loop_old_sliced (struct stream * st) { - int ii = 0; printf("start read_loop_old_sliced "); for (;;) { vbi_sliced *s; @@ -1079,10 +1070,10 @@ read_loop_old_sliced (struct stream * st) printf("n_lines = %d",n_lines); if ((unsigned int) n_lines > N_ELEMENTS (st->sliced)) n_lines = N_ELEMENTS (st->sliced); //bad_format_exit (); - + if(n_lines == 0) + break; - printf(" N_ELEMENTS (st->sliced)=%d \n", N_ELEMENTS (st->sliced)); s = st->sliced; raw = NULL; st->raw_valid = FALSE; @@ -1183,17 +1174,11 @@ read_loop_old_sliced (struct stream * st) st->stream_time); } else { printf("st->raw_valid && st->decode_raw isnot true\n"); - //printf(" st->sliced->line=%d \n",st->sliced->line); - //printf(" st->sliced->data=%c st->sliced->data[1]=%c \n",st->sliced->data,st->sliced->data[1]); - //printf(" s->data= %c s->data[1]=%c \n",s->data[0],s->data[1]); + success = st->callback (st->sliced, n_lines, raw, &sp, st->sample_time, st->stream_time); - if(ii == 0) - ii ++; - else - return FALSE; } free (raw); diff --git a/ntsc_decode/test/Android.mk b/ntsc_decode/test/Android.mk new file mode 100755 index 0000000..619f428 --- a/dev/null +++ b/ntsc_decode/test/Android.mk @@ -0,0 +1,16 @@ +LOCAL_PATH:= $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_SRC_FILES:=decode.c \ + ../sliced1.c +LOCAL_SHARED_LIBRARIES+= libzvbi + +LOCAL_C_INCLUDES:=$(LOCAL_PATH)/../../src \ + $(LOCAL_PATH)/../ + +LOCAL_MODULE:= xds_decode +LOCAL_MODULE_TAGS := optional +LOCAL_ARM_MODE := arm +LOCAL_CFLAGS+=-D_REENTRANT -D_GNU_SOURCE -DENABLE_DVB=1 -DENABLE_V4L=1 -DENABLE_V4L2=1 -DHAVE_ICONV=1 -DPACKAGE=\"zvbi\" -DVERSION=\"0.2.33\" -DANDROID -DHAVE_GETOPT_LONG=1 +LOCAL_SHARED_LIBRARIES += libicuuc liblog +include $(BUILD_EXECUTABLE) diff --git a/ntsc_decode/test/decode.c b/ntsc_decode/test/decode.c new file mode 100755 index 0000000..7cfff30 --- a/dev/null +++ b/ntsc_decode/test/decode.c @@ -0,0 +1,1415 @@ + /* + * zvbi-decode -- Decode sliced VBI data using low-level + * libzvbi functions + * + * Copyright (C) 2004, 2006, 2007 Michael H. Schimek + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +/* $Id: decode.c,v 1.32 2008/03/01 07:36:59 mschimek Exp $ */ + +/* For libzvbi version 0.2.x / 0.3.x. */ + +#undef NDEBUG + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <string.h> +#include <locale.h> +#include <assert.h> +#include <unistd.h> +#include <errno.h> +#include <time.h> +#ifdef HAVE_GETOPT_LONG +# include <getopt.h> +#endif + +#include "version.h" +#if 2 == VBI_VERSION_MINOR +# include "bcd.h" +# include "conv.h" +# include "pfc_demux.h" +# include "dvb_demux.h" +# include "idl_demux.h" +# include "xds_demux.h" +# include "vps.h" +# include "hamm.h" +# include "lang.h" +#elif 3 == VBI_VERSION_MINOR +# include "zvbi.h" +# include "misc.h" /* _vbi_to_ascii() */ +#else +# error VBI_VERSION_MINOR == ? +#endif + +#include "sliced.h" +#include "sliced1.h" + +#undef _ +#define _(x) x /* i18n TODO */ + +/* Will be installed one day. */ +#define PROGRAM_NAME "zvbi-decode" + +static const char * option_in_file_name; +static enum file_format option_in_file_format; +static unsigned int option_in_ts_pid; + +static vbi_pgno option_pfc_pgno; +static unsigned int option_pfc_stream; + +static vbi_bool option_decode_ttx; +static vbi_bool option_decode_8301; +static vbi_bool option_decode_8302; +static vbi_bool option_decode_caption; +static vbi_bool option_decode_xds; +static vbi_bool option_decode_idl; +static vbi_bool option_decode_vps; +static vbi_bool option_decode_vps_other; +static vbi_bool option_decode_wss; + +static vbi_bool option_dump_network; +static vbi_bool option_dump_hex; +static vbi_bool option_dump_bin; +static vbi_bool option_dump_time; +static double option_metronome_tick; + +static vbi_pgno option_pfc_pgno = 0; +static unsigned int option_pfc_stream = 0; + +static unsigned int option_idl_channel = 0; +static unsigned int option_idl_address = 0; + +static struct stream * rst; + +static vbi_pfc_demux * pfc; +static vbi_idl_demux * idl; +static vbi_xds_demux * xds; + +extern void +_vbi_pfc_block_dump (const vbi_pfc_block * pb, + FILE * fp, + vbi_bool binary); + +static void +put_cc_char (unsigned int c1, + unsigned int c2) +{ + uint16_t ucs2_str[1]; + + /* All caption characters are representable + in UTF-8, but not necessarily in ASCII. */ + ucs2_str[0] = vbi_caption_unicode ((c1 * 256 + c2) & 0x777F, + /* to_upper */ FALSE); + + vbi_fputs_iconv_ucs2 (stdout, + vbi_locale_codeset (), + ucs2_str, 1, + /* repl_char */ '?'); +} + +static void +caption_command (unsigned int line, + unsigned int c1, + unsigned int c2) +{ + unsigned int ch; + unsigned int a7; + unsigned int f; + unsigned int b7; + unsigned int u; + + printf ("CC line=%3u cmd 0x%02x 0x%02x ", line, c1, c2); + + if (0 == c1) { + printf ("null\n"); + return; + } else if (c2 < 0x20) { + printf ("invalid\n"); + return; + } + + /* Some common bit groups. */ + + ch = (c1 >> 3) & 1; /* channel */ + a7 = c1 & 7; + f = c1 & 1; /* field */ + b7 = (c2 >> 1) & 7; + u = c2 & 1; /* underline */ + + if (c2 >= 0x40) { + static const int row [16] = { + /* 0 */ 10, /* 0x1040 */ + /* 1 */ -1, /* unassigned */ + /* 2 */ 0, 1, 2, 3, /* 0x1140 ... 0x1260 */ + /* 6 */ 11, 12, 13, 14, /* 0x1340 ... 0x1460 */ + /* 10 */ 4, 5, 6, 7, 8, 9 /* 0x1540 ... 0x1760 */ + }; + unsigned int rrrr; + + /* Preamble Address Codes -- 001 crrr 1ri bbbu */ + + rrrr = a7 * 2 + ((c2 >> 5) & 1); + + if (c2 & 0x10) + printf ("PAC ch=%u row=%d column=%u u=%u\n", + ch, row[rrrr], b7 * 4, u); + else + printf ("PAC ch=%u row=%d color=%u u=%u\n", + ch, row[rrrr], b7, u); + return; + } + + /* Control codes -- 001 caaa 01x bbbu */ + + switch (a7) { + case 0: + if (c2 < 0x30) { + const char *mnemo [16] = { + "BWO", "BWS", "BGO", "BGS", + "BBO", "BBS", "BCO", "BCS", + "BRO", "BRS", "BYO", "BYS", + "BMO", "BMS", "BAO", "BAS" + }; + + printf ("%s ch=%u\n", mnemo[c2 & 0xF], ch); + return; + } + + break; + + case 1: + if (c2 < 0x30) { + printf ("mid-row ch=%u color=%u u=%u\n", ch, b7, u); + } else { + printf ("special character ch=%u 0x%02x%02x='", + ch, c1, c2); + put_cc_char (c1, c2); + puts ("'"); + } + + return; + + case 2: /* first group */ + case 3: /* second group */ + printf ("extended character ch=%u 0x%02x%02x='", ch, c1, c2); + put_cc_char (c1, c2); + puts ("'"); + return; + + case 4: /* f=0 */ + case 5: /* f=1 */ + if (c2 < 0x30) { + const char *mnemo [16] = { + "RCL", "BS", "AOF", "AON", + "DER", "RU2", "RU3", "RU4", + "FON", "RDC", "TR", "RTD", + "EDM", "CR", "ENM", "EOC" + }; + + printf ("%s ch=%u f=%u\n", mnemo[c2 & 0xF], ch, f); + return; + } + + break; + + case 6: + printf ("reserved\n"); + return; + + case 7: + switch (c2) { + case 0x21 ... 0x23: + printf ("TO%u ch=%u\n", c2 - 0x20, ch); + return; + + case 0x2D: + printf ("BT ch=%u\n", ch); + return; + + case 0x2E: + printf ("FA ch=%u\n", ch); + return; + + case 0x2F: + printf ("FAU ch=%u\n", ch); + return; + + default: + break; + } + + break; + } + + printf ("unknown\n"); +} + +static vbi_bool +xds_cb (vbi_xds_demux * xd, + const vbi_xds_packet * xp, + void * user_data) +{ + xd = xd; /* unused */ + user_data = user_data; + printf("************xds_cb**********\n"); + vbi_program_info *pi; + _vbi_xds_packet_dump (xp, stdout); + + return TRUE; /* no errors */ +} + +static void +caption ( uint8_t buffer[4], + unsigned int line) +{ + + if (option_decode_xds && 284== line) { + int c1; + int c2; + /*c1 = buffer[0];//vbi_unpar8 (buffer[0]); + c2 = buffer[1];//vbi_unpar8 (buffer[1]); + + //switch (c1) { + case 0x00: + //* Stuffing. + break; + case 0x01 ... 0x0E: + printf("line is 284 is %d %d\n",buffer[2],buffer[3]); + xds->subpacket[c1][c2].count = buffer[0] + buffer[1]; + xds->subpacket[c1][c2].buffer[0] = buffer[2]; + xds->subpacket[c1][c2].buffer[1] = buffer[3]; + break; + case 0x0F: + //* Packet terminator. + break; + }*/ + if (!vbi_xds_demux_feed (xds, buffer)) { + printf ("Parity error in XDS data.\n"); + } + } + + if (option_decode_caption + && (21 == line || 284 == line /* NTSC */ + || 22 == line /* PAL? */)) { + int c1; + int c2; + + c1 = buffer[0];//vbi_unpar8 (buffer[0]); + c2 = buffer[1];//vbi_unpar8 (buffer[1]); + + + + if ((c1 | c2) < 0) { + printf ("Parity error in CC line=%u " + " %s0x%02x %s0x%02x.\n", + line, + (c1 < 0) ? ">" : "", buffer[0] & 0xFF, + (c2 < 0) ? ">" : "", buffer[1] & 0xFF); + } else if (c1 >= 0x20) { + char text[2]; + + printf ("CC line=%3u text 0x%02x 0x%02x '", + line, c1, c2); + + /* All caption characters are representable + in UTF-8, but not necessarily in ASCII. */ + text[0] = c1; + text[1] = c2; /* may be zero */ + + /* Error ignored. */ + vbi_fputs_iconv (stdout, + /* dst_codeset */ + vbi_locale_codeset (), + /* src_codeset */ "EIA-608", + text, 2, + /* repl_char */ '?'); + + puts ("'"); + } else if (0 == c1 || c1 >= 0x10) { + caption_command (line, c1, c2); + } else if (option_decode_xds) { + printf ("CC line=%3u cmd 0x%02x 0x%02x ", + line, c1, c2); + if (0x0F == c1) + puts ("XDS packet end"); + else + puts ("XDS packet start/continue"); + } + } +} + +#if 3 == VBI_VERSION_MINOR /* XXX port me back */ + +static void +dump_cni (vbi_cni_type type, + unsigned int cni) +{ + vbi_network nk; + vbi_bool success; + + if (!option_dump_network) + return; + + success = vbi_network_init (&nk); + if (!success) + no_mem_exit (); + + success = vbi_network_set_cni (&nk, type, cni); + if (!success) + no_mem_exit (); + + _vbi_network_dump (&nk, stdout); + putchar ('\n'); + + vbi_network_destroy (&nk); +} + +#endif /* 3 == VBI_VERSION_MINOR */ + +static void +dump_bytes (const uint8_t * buffer, + unsigned int n_bytes) +{ + unsigned int j; + + if (option_dump_bin) { + fwrite (buffer, 1, n_bytes, stdout); + return; + } + + if (option_dump_hex) { + for (j = 0; j < n_bytes; ++j) + printf ("%02x ", buffer[j]); + } + + putchar ('>'); + + for (j = 0; j < n_bytes; ++j) { + /* Not all Teletext characters are representable + in ASCII or even UTF-8, but at this stage we don't + know the Teletext code page for a proper conversion. */ + char c = _vbi_to_ascii (buffer[j]); + + putchar (c); + } + + puts ("<"); +} + +#if 3 == VBI_VERSION_MINOR /* XXX port me back */ + +static void +packet_8301 (const uint8_t buffer[42], + unsigned int designation) +{ + unsigned int cni; + time_t time; + int gmtoff; + struct tm tm; + + if (!option_decode_8301) + return; + + if (!vbi_decode_teletext_8301_cni (&cni, buffer)) { + printf ("Error in Teletext " + "packet 8/30 format 1 CNI.\n"); + return; + } + + if (!vbi_decode_teletext_8301_local_time (&time, &gmtoff, buffer)) { + printf ("Error in Teletext " + "packet 8/30 format 1 local time.\n"); + return; + } + + printf ("Teletext packet 8/30/%u cni=%x time=%u gmtoff=%d ", + designation, cni, (unsigned int) time, gmtoff); + + gmtime_r (&time, &tm); + + printf ("(%4u-%02u-%02u %02u:%02u:%02u UTC)\n", + tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, + tm.tm_hour, tm.tm_min, tm.tm_sec); + + if (0 != cni) + dump_cni (VBI_CNI_TYPE_8301, cni); +} + +static void +packet_8302 (const uint8_t buffer[42], + unsigned int designation) +{ + unsigned int cni; + vbi_program_id pi; + + if (!option_decode_8302) + return; + + if (!vbi_decode_teletext_8302_cni (&cni, buffer)) { + printf ("Error in Teletext " + "packet 8/30 format 2 CNI.\n"); + return; + } + + if (!vbi_decode_teletext_8302_pdc (&pi, buffer)) { + printf ("Error in Teletext " + "packet 8/30 format 2 PDC data.\n"); + return; + } + + printf ("Teletext packet 8/30/%u cni=%x ", designation, cni); + + _vbi_program_id_dump (&pi, stdout); + + putchar ('\n'); + + if (0 != pi.cni) + dump_cni (pi.cni_type, pi.cni); +} + +#endif /* 3 == VBI_VERSION_MINOR */ + +static vbi_bool +page_function_clear_cb (vbi_pfc_demux * dx, + void * user_data, + const vbi_pfc_block * block) +{ + dx = dx; /* unused */ + user_data = user_data; + + _vbi_pfc_block_dump (block, stdout, option_dump_bin); + + return TRUE; +} + +static vbi_bool +idl_format_a_cb (vbi_idl_demux * idl, + const uint8_t * buffer, + unsigned int n_bytes, + unsigned int flags, + void * user_data) +{ + idl = idl; + user_data = user_data; + + if (!option_dump_bin) { + printf ("IDL-A%s%s ", + (flags & VBI_IDL_DATA_LOST) ? " <data lost>" : "", + (flags & VBI_IDL_DEPENDENT) ? " <dependent>" : ""); + } + + dump_bytes (buffer, n_bytes); + + return TRUE; +} + +static void +packet_idl (const uint8_t buffer[42], + unsigned int channel) +{ + int pa; /* packet address */ + int ft; /* format type */ + + printf ("IDL ch=%u ", channel); + + switch (channel) { + case 0: + assert (0); + + case 4: + case 12: + printf ("(Low bit rate audio) "); + + dump_bytes (buffer, 42); + + break; + + case 5: + case 6: + case 13: + case 14: + pa = vbi_unham8 (buffer[3]); + pa |= vbi_unham8 (buffer[4]) << 4; + pa |= vbi_unham8 (buffer[5]) << 8; + + if (pa < 0) { + printf ("Hamming error in Datavideo " + "packet-address byte.\n"); + return; + } + + printf ("(Datavideo) pa=0x%x ", pa); + + dump_bytes (buffer, 42); + + break; + + case 8: + case 9: + case 10: + case 11: + case 15: + ft = vbi_unham8 (buffer[2]); + if (ft < 0) { + printf ("Hamming error in IDL format " + "A or B format-type byte.\n"); + return; + } + + if (0 == (ft & 1)) { + int ial; /* interpretation and address length */ + unsigned int spa_length; + int spa; /* service packet address */ + unsigned int i; + + ial = vbi_unham8 (buffer[3]); + if (ial < 0) { + printf ("Hamming error in IDL format " + "A interpretation-and-address-" + "length byte.\n"); + return; + } + + spa_length = (unsigned int) ial & 7; + if (7 == spa_length) { + printf ("(Format A?) "); + dump_bytes (buffer, 42); + return; + } + + spa = 0; + + for (i = 0; i < spa_length; ++i) + spa |= vbi_unham8 (buffer[4 + i]) << (4 * i); + + if (spa < 0) { + printf ("Hamming error in IDL format " + "A service-packet-address byte.\n"); + return; + } + + printf ("(Format A) spa=0x%x ", spa); + } else if (1 == (ft & 3)) { + int an; /* application number */ + int ai; /* application identifier */ + + an = (ft >> 2); + + ai = vbi_unham8 (buffer[3]); + if (ai < 0) { + printf ("Hamming error in IDL format " + "B application-number byte.\n"); + return; + } + + printf ("(Format B) an=%d ai=%d ", an, ai); + } + + dump_bytes (buffer, 42); + + break; + + default: + dump_bytes (buffer, 42); + + break; + } +} + +static void +teletext (const uint8_t buffer[42], + unsigned int line) +{ + int pmag; + unsigned int magazine; + unsigned int packet; + + if (NULL != pfc) { + if (!vbi_pfc_demux_feed (pfc, buffer)) { + printf ("Error in Teletext " + "PFC packet.\n"); + return; + } + } + + if (NULL != idl) { + if (!vbi_idl_demux_feed (idl, buffer)) { + printf ("Error in Teletext " + "IDL packet.\n"); + return; + } + } + + if (!(option_decode_ttx | + option_decode_8301 | + option_decode_8302 | + option_decode_idl)) + return; + + pmag = vbi_unham16p (buffer); + if (pmag < 0) { + printf ("Hamming error in Teletext " + "packet number.\n"); + return; + } + + magazine = pmag & 7; + if (0 == magazine) + magazine = 8; + + packet = pmag >> 3; + + if (8 == magazine && 30 == packet) { + int designation; + + designation = vbi_unham8 (buffer[2]); + if (designation < 0 ) { + printf ("Hamming error in Teletext " + "packet 8/30 designation byte.\n"); + return; + } + + if (designation >= 0 && designation <= 1) { +#if 3 == VBI_VERSION_MINOR /* XXX port me back */ + packet_8301 (buffer, designation); +#endif + return; + } + + if (designation >= 2 && designation <= 3) { +#if 3 == VBI_VERSION_MINOR /* XXX port me back */ + packet_8302 (buffer, designation); +#endif + return; + } + } + + if (30 == packet || 31 == packet) { + if (option_decode_idl) { +#if 1 + packet_idl (buffer, pmag & 15); +#else + printf ("Teletext IDL packet %u/%2u ", + magazine, packet); + dump_bytes (buffer, /* n_bytes */ 42); +#endif + return; + } + } + + if (option_decode_ttx) { + printf ("Teletext line=%3u %x/%2u ", + line, magazine, packet); + dump_bytes (buffer, /* n_bytes */ 42); + return; + } +} + +static void +vps (const uint8_t buffer[13], + unsigned int line) +{ + if (option_decode_vps) { + unsigned int cni; +#if 3 == VBI_VERSION_MINOR + vbi_program_id pi; +#endif + if (option_dump_bin) { + printf ("VPS line=%3u ", line); + fwrite (buffer, 1, 13, stdout); + fflush (stdout); + return; + } + + if (!vbi_decode_vps_cni (&cni, buffer)) { + printf ("Error in VPS packet CNI.\n"); + return; + } + +#if 3 == VBI_VERSION_MINOR + if (!vbi_decode_vps_pdc (&pi, buffer)) { + printf ("Error in VPS packet PDC data.\n"); + return; + } + + printf ("VPS line=%3u ", line); + + _vbi_program_id_dump (&pi, stdout); + + putchar ('\n'); + + if (0 != pi.cni) + dump_cni (pi.cni_type, pi.cni); +#else + printf ("VPS line=%3u CNI=%x\n", line, cni); +#endif + } + + if (option_decode_vps_other) { + static char pr_label[2][20]; + static char label[2][20]; + static int l[2] = { 0, 0 }; + unsigned int i; + int c; + + i = (line != 16); + + c = vbi_rev8 (buffer[1]); + + if (c & 0x80) { + label[i][l[i]] = 0; + strcpy (pr_label[i], label[i]); + l[i] = 0; + } + + label[i][l[i]] = _vbi_to_ascii (c); + + l[i] = (l[i] + 1) % 16; + + printf ("VPS line=%3u bytes 3-10: " + "%02x %02x (%02x='%c') %02x %02x " + "%02x %02x %02x %02x (\"%s\")\n", + line, + buffer[0], buffer[1], + c, _vbi_to_ascii (c), + buffer[2], buffer[3], + buffer[4], buffer[5], buffer[6], buffer[7], + pr_label[i]); + } +} + +#if 3 == VBI_VERSION_MINOR /* XXX port me back */ + +static void +wss_625 (const uint8_t buffer[2]) +{ + if (option_decode_wss) { + vbi_aspect_ratio ar; + + if (!vbi_decode_wss_625 (&ar, buffer)) { + printf ("Error in WSS packet.\n"); + return; + } + + fputs ("WSS ", stdout); + + _vbi_aspect_ratio_dump (&ar, stdout); + + putchar ('\n'); + } +} + +#endif /* 3 == VBI_VERSION_MINOR */ + +static vbi_bool +decode_frame ( vbi_sliced * s, + unsigned int n_lines, + const uint8_t * raw, + const vbi_sampling_par *sp, + double sample_time, + int64_t stream_time) +{ + printf("decode_frame\n"); + static double metronome = 0.0; + static double last_sample_time = 0.0; + static int64_t last_stream_time = 0; + + raw = raw; /* unused */ + sp = sp; + + if (option_dump_time || option_metronome_tick > 0.0) { + /* Sample time: When we captured the data, in + seconds since 1970-01-01 (gettimeofday()). + Stream time: For ATSC/DVB the Presentation Time Stamp. + For analog the frame number multiplied by + the nominal frame period (1/25 or + 1001/30000 s). Both given in 90 kHz units. + Note this isn't fully implemented yet. */ + + if (option_metronome_tick > 0.0) { + printf ("ST %f (adv %+f, err %+f) PTS %" + PRId64 " (adv %+" PRId64 ", err %+f)\n", + sample_time, sample_time - last_sample_time, + sample_time - metronome, + stream_time, stream_time - last_stream_time, + (double) stream_time - metronome); + + metronome += option_metronome_tick; + } else { + printf ("ST %f (%+f) PTS %" PRId64 " (%+" PRId64 ")\n", + sample_time, sample_time - last_sample_time, + stream_time, stream_time - last_stream_time); + } + + last_sample_time = sample_time; + last_stream_time = stream_time; + } + printf("decode_frame while\n"); + static int i =0; + + //******************temp*************************// + //s->id = VBI_SLICED_CAPTION_525; + while (n_lines > 0) { + switch (s->id) { + case VBI_SLICED_TELETEXT_B_L10_625: + case VBI_SLICED_TELETEXT_B_L25_625: + case VBI_SLICED_TELETEXT_B_625: + teletext (s->data, s->line); + break; + + case VBI_SLICED_VPS: + case VBI_SLICED_VPS_F2: + vps (s->data, s->line); + break; + + case VBI_SLICED_CAPTION_625_F1: + case VBI_SLICED_CAPTION_625_F2: + case VBI_SLICED_CAPTION_625: + case VBI_SLICED_CAPTION_525_F1: + case VBI_SLICED_CAPTION_525_F2: + case VBI_SLICED_CAPTION_525: + //******************************************************************// + //printf("decode_frame VBI_SLICED_CAPTION_525\n"); + caption (s->data, s->line); + //******************************************************************// + break; + + case VBI_SLICED_WSS_625: +#if 3 == VBI_VERSION_MINOR /* XXX port me back */ + wss_625 (s->data); +#endif + break; + + case VBI_SLICED_WSS_CPR1204: + break; + + + } + + ++s; + --n_lines; + } + + return TRUE; +} + +static void +usage (FILE * fp) +{ + /* FIXME Supposed to be localized but we can't use #ifs + within the _() macro. */ + fprintf (fp, "\ +%s %s -- Low-level VBI decoder\n\n\ +Copyright (C) 2004, 2006, 2007 Michael H. Schimek\n\ +This program is licensed under GPLv2 or later. NO WARRANTIES.\n\n\ +Usage: %s [options] < sliced VBI data\n\ +-h | --help | --usage Print this message and exit\n\ +-q | --quiet Suppress progress and error messages\n\ +-V | --version Print the program version and exit\n\ +Input options:\n\ +-i | --input name Read the VBI data from this file instead of\n\ + standard input\n\ +-P | --pes Source is a DVB PES stream\n\ +-T | --ts pid Source is a DVB TS stream\n\ +Decoding options:\n" +#if 3 == VBI_VERSION_MINOR /* XXX port me back */ +"-1 | --8301 Teletext packet 8/30 format 1 (local time)\n\ +-2 | --8302 Teletext packet 8/30 format 2 (PDC)\n" +#endif +"-c | --cc Closed Caption\n\ +-j | --idl Any Teletext IDL packets (M/30, M/31)\n\ +-t | --ttx Decode any Teletext packet\n\ +-v | --vps Video Programming System (PDC)\n" +#if 3 == VBI_VERSION_MINOR /* XXX port me back */ +"-w | --wss Wide Screen Signalling\n" +#endif +"-x | --xds Decode eXtended Data Service (NTSC line 284)\n\ +-a | --all Everything above, e.g.\n\ + -i decode IDL packets\n\ + -a decode everything\n\ + -a -i everything except IDL\n\ +-l | --idl-ch N\n\ +-d | --idl-addr NNN Decode Teletext IDL format A data from channel N,\n\ + service packet address NNN (default 0)\n\ +-r | --vps-other Decode VPS data unrelated to PDC\n\ +-p | --pfc-pgno NNN\n\ +-s | --pfc-stream NN Decode Teletext Page Function Clear data\n\ + from page NNN (for example 1DF), stream NN\n\ + (default 0)\n\ +Modifying options:\n\ +-e | --hex With -t dump packets in hex and ASCII,\n\ + otherwise only ASCII\n\ +-n | --network With -1, -2, -v decode CNI and print\n\ + available information about the network\n\ +-b | --bin With -t, -p, -v dump data in binary format\n\ + instead of ASCII\n\ +-m | --time Dump capture timestamps\n\ +-M | --metronome tick Compare timestamps against a metronome advancing\n\ + by tick seconds per frame\n\ +", + PROGRAM_NAME, VERSION, program_invocation_name); +} + +static const char +short_options [] = "12abcd:ehi:jl:mnp:qrs:tvwxM:PT:V"; + +#ifdef HAVE_GETOPT_LONG +static const struct option +long_options [] = { + { "8301", no_argument, NULL, '1' }, + { "8302", no_argument, NULL, '2' }, + { "all", no_argument, NULL, 'a' }, + { "bin", no_argument, NULL, 'b' }, + { "cc", no_argument, NULL, 'c' }, + { "idl-addr", required_argument, NULL, 'd' }, + { "hex", no_argument, NULL, 'e' }, + { "help", no_argument, NULL, 'h' }, + { "usage", no_argument, NULL, 'h' }, + { "input", required_argument, NULL, 'i' }, + { "idl", no_argument, NULL, 'j' }, + { "idl-ch", required_argument, NULL, 'l' }, + { "time", no_argument, NULL, 'm' }, + { "network", no_argument, NULL, 'n' }, + { "pfc-pgno", required_argument, NULL, 'p' }, + { "quiet", no_argument, NULL, 'q' }, + { "vps-other", no_argument, NULL, 'r' }, + { "pfc-stream", required_argument, NULL, 's' }, + { "ttx", no_argument, NULL, 't' }, + { "vps", no_argument, NULL, 'v' }, + { "wss", no_argument, NULL, 'w' }, + { "xds", no_argument, NULL, 'x' }, + { "metronome", required_argument, NULL, 'M' }, + { "pes", no_argument, NULL, 'P' }, + { "ts", required_argument, NULL, 'T' }, + { "version", no_argument, NULL, 'V' }, + { NULL, 0, 0, 0 } +}; +#else +# define getopt_long(ac, av, s, l, i) getopt(ac, av, s) +#endif + +static int option_index; + +int +main (int argc, + char ** argv) +{ + +//************************************************* + /*unsigned char pBuffer [5100] ; + memset(pBuffer,0, 5100 ); */ + #if defined(VBI_CC_SUPPORT) + typedef struct cc_data_s { + unsigned int vbi_type : 8; // vbi data type: us_cc, teletext,wss_625,wssj,vps.... + unsigned int field_id : 8; // field type: 0:even; 1:odd; + unsigned int nbytes : 16; // data byte count: cc:two bytes; tt: depends on tt spec + unsigned int line_num : 16; // vbi data line number + unsigned char b[2]; // : 8; // cc data1 + //unsigned int b2 : 8; // cc data2 + } cc_data_t; + #endif + + unsigned char pBuffer[] ={ + 0x00,0x01,0x02,0x00,0x15,0x00,0x00,0x00, + 0x00,0x01,0x02,0x00,0x15,0x00,0x01,0x05, + 0x00,0x01,0x02,0x00,0x15,0x00,0x41,0x40, + 0x00,0x01,0x02,0x00,0x15,0x00,0x0f,0x6a, + 0x00,0x01,0x02,0x00,0x15,0x00,0x00,0x00, + 0x00,0x01,0x02,0x00,0x15,0x00,0x00,0x00, + 0x00,0x01,0x02,0x00,0x15,0x00,0x15,0x2c, + 0x00,0x01,0x02,0x00,0x15,0x00,0x15,0x2e, + 0x00,0x01,0x02,0x00,0x15,0x00,0x15,0x20, + 0x00,0x01,0x02,0x00,0x15,0x00,0x16,0x46, + 0x00,0x01,0x02,0x00,0x15,0x00,0x20,0x20, + 0x00,0x01,0x02,0x00,0x15,0x00,0x10,0x22, + 0x00,0x01,0x02,0x00,0x15,0x00,0x43,0x6c, + 0x00,0x01,0x02,0x00,0x15,0x00,0x6f,0x73, + 0x00,0x01,0x02,0x00,0x15,0x00,0x65,0x64, + 0x00,0x01,0x02,0x00,0x15,0x00,0x20,0x43, + 0x00,0x01,0x02,0x00,0x15,0x00,0x61,0x70, + 0x00,0x01,0x02,0x00,0x15,0x00,0x74,0x69, + 0x00,0x01,0x02,0x00,0x15,0x00,0x6f,0x6e , + + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x2f, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a, + + 0x00,0x00,0x02,0x00,0x1c,0x01,0x41,0x00, + + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x45,0x00, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21, + + 0x00,0x00,0x02,0x00,0x1c,0x01,0x4f,0x00, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23, + + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x75,0x00, + + + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x2f, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a, + + 0x00,0x00,0x02,0x00,0x1c,0x01,0x41,0x00, + + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x45,0x00, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21, + + 0x00,0x00,0x02,0x00,0x1c,0x01,0x4f,0x00, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23, + + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x75,0x00, + + + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x2f, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a, + + 0x00,0x00,0x02,0x00,0x1c,0x01,0x41,0x00, + + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x45,0x00, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21, + + 0x00,0x00,0x02,0x00,0x1c,0x01,0x4f,0x00, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23, + + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x75,0x00, + + + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x2f, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a, + + 0x00,0x00,0x02,0x00,0x1c,0x01,0x41,0x00, + + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x45,0x00, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21, + + 0x00,0x00,0x02,0x00,0x1c,0x01,0x4f,0x00, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23, + + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x75,0x00, + }; + + unsigned char pBuffer11[] ={ 1,21, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x2f, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a, + + 0x00,0x00,0x02,0x00,0x1c,0x01,0x41,0x00, + + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x45,0x00, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21, + + 0x00,0x00,0x02,0x00,0x1c,0x01,0x4f,0x00, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23, + + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24, + 0x00,0x00,0x02,0x00,0x1c,0x01,0x75,0x00, + + }; + + + int length = N_ELEMENTS (pBuffer); + /*int write_len ; + static FILE *file_fd = NULL; + if(!file_fd){ + file_fd = fopen("/mnt/sda1/111.bin", "wb+"); + if(file_fd == NULL) + { + printf(">>> transfer_vod_fwrite(), fopen() error1111\n"); + } + } + write_len = fwrite(pBuffer, 1, length, file_fd); + printf("->>> Write kankan_file, size=%d write_len =%d\n", length,write_len); + if(file_fd != NULL){ + fclose(file_fd); + file_fd = NULL; + }*/ +//************************************************* + + + init_helpers (argc, argv); + printf("zkinit_helpers\n"); + option_in_file_format = FILE_FORMAT_SLICED; + + #ifdef HAVE_GETOPT_LONG + printf("HAVE_GETOPT_LONG\n"); + #else + printf("NOT_HAVE_GETOPT_LONG\n"); + #endif + + printf("_HAVEFAFDAFDASFD_GETOPT_LONG\n"); + while(FALSE) { // (;;) { + int c; + printf(" 111111111111"); + c = getopt_long (argc, argv, short_options, + long_options, &option_index); + printf("zk%d\n",c); + if (-1 == c) + break; + + switch (c) { + case 0: /* getopt_long() flag */ + break; + + case '1': + option_decode_8301 ^= TRUE; + break; + + case '2': + option_decode_8302 ^= TRUE; + break; + + case 'a': + option_decode_ttx = TRUE; + option_decode_8301 = TRUE; + option_decode_8302 = TRUE; + option_decode_caption = TRUE; + option_decode_idl = TRUE; + option_decode_vps = TRUE; + option_decode_wss = TRUE; + option_decode_xds = TRUE; + option_pfc_pgno = 0x1DF; + break; + + case 'b': + option_dump_bin ^= TRUE; + break; + + case 'c': + option_decode_caption ^= TRUE; + break; + + case 'd': + assert (NULL != optarg); + option_idl_address = strtol (optarg, NULL, 0); + break; + + case 'e': + option_dump_hex ^= TRUE; + break; + + case 'h': + usage (stdout); + exit (EXIT_SUCCESS); + + case 'i': + assert (NULL != optarg); + option_in_file_name = optarg; + break; + + case 'j': + option_decode_idl ^= TRUE; + break; + + case 'l': + assert (NULL != optarg); + option_idl_channel = strtol (optarg, NULL, 0); + break; + + case 'm': + option_dump_time ^= TRUE; + break; + + case 'n': + option_dump_network ^= TRUE; + break; + + case 'p': + assert (NULL != optarg); + option_pfc_pgno = strtol (optarg, NULL, 16); + break; + + case 'q': + parse_option_quiet (); + break; + + case 'r': + option_decode_vps_other ^= TRUE; + break; + + case 's': + assert (NULL != optarg); + option_pfc_stream = strtol (optarg, NULL, 0); + break; + + case 't': + option_decode_ttx ^= TRUE; + break; + + case 'v': + option_decode_vps ^= TRUE; + break; + + case 'w': + option_decode_wss ^= TRUE; + break; + + case 'x': + option_decode_xds ^= TRUE; + break; + + case 'M': + assert (NULL != optarg); + option_metronome_tick = strtod (optarg, NULL); + break; + + case 'P': + option_in_file_format = FILE_FORMAT_DVB_PES; + break; + + case 'T': + option_in_ts_pid = parse_option_ts (); + option_in_file_format = FILE_FORMAT_DVB_TS; + break; + + case 'V': + printf (PROGRAM_NAME " " VERSION "\n"); + exit (EXIT_SUCCESS); + + default: + usage (stderr); + exit (EXIT_FAILURE); + } + } + + //****************************************temp*************** + option_decode_xds = TRUE; + option_decode_caption = TRUE; + //option_in_file_name = argv[1]; + + printf("zkoption_decode_xds\n"); + //printf("option_in_file_name%s\n",option_in_file_name); + + if (0 != option_pfc_pgno) { + printf("option_pfc_pgno\n"); + pfc = vbi_pfc_demux_new (option_pfc_pgno, + option_pfc_stream, + page_function_clear_cb, + /* user_data */ NULL); + if (NULL == pfc) + no_mem_exit (); + } + + if (0 != option_idl_channel) { + printf("option_idl_channel\n"); + idl = vbi_idl_a_demux_new (option_idl_channel, + option_idl_address, + idl_format_a_cb, + /* user_data */ NULL); + if (NULL == idl) + no_mem_exit (); + } + + if (option_decode_xds) { + printf("decode xds\n"); + xds = vbi_xds_demux_new (xds_cb, + /* used_data */ NULL); + if (NULL == xds) + no_mem_exit (); + }else + printf("not decode xds\n"); + + rst = read_stream_new (pBuffer,length, + option_in_file_format, + option_in_ts_pid, + decode_frame); + + printf("stream_loop\n"); + stream_loop (rst); + + stream_delete (rst); + rst = NULL; + + error_msg (_("End of stream.")); + + vbi_xds_demux_delete (xds); + xds = NULL; + + vbi_idl_demux_delete (idl); + idl = NULL; + + vbi_pfc_demux_delete (pfc); + pfc = NULL; + + exit (EXIT_SUCCESS); +} |