author | kui.zhang <kui.zhang@amlogic.com> | 2012-09-13 08:03:18 (GMT) |
---|---|---|
committer | kui.zhang <kui.zhang@amlogic.com> | 2012-09-13 08:03:18 (GMT) |
commit | ec85d515ae90596d34e94bad55391e2cbf826cfa (patch) | |
tree | cbbe4f8a4d986d9c76f84d361ce11485a2e07038 | |
parent | 2f13afbce1e78dd8bb47ea1cbe5c58f5ee6fd9e1 (diff) | |
download | libzvbi-ec85d515ae90596d34e94bad55391e2cbf826cfa.zip libzvbi-ec85d515ae90596d34e94bad55391e2cbf826cfa.tar.gz libzvbi-ec85d515ae90596d34e94bad55391e2cbf826cfa.tar.bz2 |
rename file and add xds callback
-rwxr-xr-x | ntsc_decode/Android.mk | 8 | ||||
-rwxr-xr-x | ntsc_decode/am_ntsc_cc.c | 238 | ||||
-rwxr-xr-x | ntsc_decode/am_vbi.c | 421 | ||||
-rwxr-xr-x | ntsc_decode/include/am_vbi.h (renamed from ntsc_decode/am_ntsc_cc.h) | 27 | ||||
-rwxr-xr-x | ntsc_decode/include/am_vbi_internal.h (renamed from ntsc_decode/ntsc_dmx/am_vbi_internal.h) | 0 | ||||
-rwxr-xr-x | ntsc_decode/include/am_xds.h | 52 | ||||
-rwxr-xr-x | ntsc_decode/include/ntsc_dmx/vbi_dmx.h (renamed from ntsc_decode/ntsc_dmx/include/vbi_dmx.h) | 0 | ||||
-rwxr-xr-x | ntsc_decode/include/sliced_vbi.h (renamed from ntsc_decode/sliced_vbi.h) | 0 | ||||
-rwxr-xr-x | src/caption.c | 48 |
9 files changed, 524 insertions, 270 deletions
diff --git a/ntsc_decode/Android.mk b/ntsc_decode/Android.mk index ead118a..6eedb12 100755 --- a/ntsc_decode/Android.mk +++ b/ntsc_decode/Android.mk @@ -1,7 +1,7 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) -LOCAL_SRC_FILES:=am_ntsc_cc.c \ +LOCAL_SRC_FILES:=am_vbi.c \ sliced_vbi.c \ ntsc_dmx/am_vbi_dmx.c \ ntsc_dmx/linux_vbi/linux_ntsc.c @@ -9,9 +9,9 @@ LOCAL_SRC_FILES:=am_ntsc_cc.c \ LOCAL_SHARED_LIBRARIES+= libzvbi LOCAL_C_INCLUDES:=$(LOCAL_PATH)/../src \ - $(LOCAL_PATH)/ \ - $(LOCAL_PATH)/ntsc_dmx/ \ - $(LOCAL_PATH)/ntsc_dmx/include + $(LOCAL_PATH)/include/ \ + $(LOCAL_PATH)/include/ntsc_dmx/ + LOCAL_MODULE:= libntsc_decode LOCAL_MODULE_TAGS := optional diff --git a/ntsc_decode/am_ntsc_cc.c b/ntsc_decode/am_ntsc_cc.c deleted file mode 100755 index 017ca7e..0000000 --- a/ntsc_decode/am_ntsc_cc.c +++ b/dev/null @@ -1,238 +0,0 @@ -#undef NDEBUG - -#include <stdio.h> -#include <stdlib.h> -#include <pthread.h> -#include <unistd.h> -#include <string.h> -#include "vbi.h" -#include "exp-gfx.h" -#include "hamm.h" -#include "dvb_demux.h" -#include "sliced.h" -#include "sliced_vbi.h" -#include "am_ntsc_cc.h" -#include "vbi_dmx.h" - -/********************define variable***************************/ - - -typedef struct -{ - vbi_decoder *dec; - //vbi_search *search; - AM_NTSC_CC_Para_t para; - int page_no; - int sub_page_no; - vbi_bool disp_update; - vbi_bool running; - uint64_t pts; - pthread_mutex_t lock; - pthread_cond_t cond; - pthread_t thread; -}AM_NTSC_CC_Parser_t; - -vbi_pgno pgno = -1; - -//AM_NTSC_CC_Parser_t *parser = NULL; - -static void -reset (AM_NTSC_CC_Parser_t *parser) -{ - vbi_page page; - vbi_bool success; - int row; - - success = vbi_fetch_cc_page (parser->dec, &page, pgno, TRUE); - assert (success); - - for (row = 0; row <= page.rows; ++row) - render (parser,&page, row); - - vbi_unref_page (&page); -} - -/**********************************************************/ - - - void vbi_cc_show(AM_NTSC_CC_Parser_t *parser) -{ - - vbi_page page; - vbi_bool success; - int row; - //user_data = user_data; - - //if (pgno != -1 && parser->page_no != pgno) - // return; - - /* Fetching & rendering in the handler - is a bad idea, but this is only a test */ - AM_DEBUG("NTSC-------------------- vbi_cc_show****************\n"); - success = vbi_fetch_cc_page (parser->dec, &page, parser->page_no, TRUE); - AM_DEBUG("NTSC--------------1212------vbi_fetch_cc_page success****************\n"); - assert (success); - - int i ,j; - if(parser->para.draw_begin) - parser->para.draw_begin(parser); - - vbi_draw_cc_page_region (&page, VBI_PIXFMT_RGBA32_LE, parser->para.bitmap, - parser->para.pitch, 0, 0, page.columns, page.rows); - - if(parser->para.draw_end) - parser->para.draw_end(parser); - vbi_unref_page (&page); -} - - -static void* vbi_cc_thread(void *arg) -{ - AM_NTSC_CC_Parser_t *parser = (AM_NTSC_CC_Parser_t*)arg; - - pthread_mutex_lock(&parser->lock); - AM_DEBUG("NTSC***************________________ vbi_cc_thread parser->running = %d\n",parser->running); - while(parser->running) - { - AM_DEBUG("NTSC***************________________ vbi_cc_thread disp_update = %d\n",parser->disp_update); - while(parser->running && !parser->disp_update){ - pthread_cond_wait(&parser->cond, &parser->lock); - } - AM_DEBUG("NTSC***************________________ vbi_cc_thread disp_update = %d\n",parser->disp_update); - if(parser->disp_update){ - vbi_cc_show(parser); - parser->disp_update = FALSE; - } - } - pthread_mutex_unlock(&parser->lock); - - return NULL; -} - -static void vbi_cc_handler(vbi_event * ev,void * user_data) -{ - AM_NTSC_CC_Parser_t *parser = (AM_NTSC_CC_Parser_t*)user_data; - AM_DEBUG("NTSC-------------------- vbi_cc_handler****************"); - //if(parser->page_no != ev->ev.caption.pgno){ - parser->page_no = ev->ev.caption.pgno; - parser->disp_update = AM_TRUE; - pthread_cond_signal(&parser->cond); - - //vbi_cc_show(parser); - //} -} - -/**********************************************************/ - -static vbi_bool -decode_frame (const vbi_sliced * sliced, - unsigned int n_lines, - const uint8_t * raw, - const vbi_sampling_par *sp, - double sample_time, - int64_t stream_time, - void * user_data) -{ - AM_DEBUG("NTSC-------------------- decode_frame\n"); - if(user_data == NULL) return FALSE; - AM_NTSC_CC_Parser_t *parser = (AM_NTSC_CC_Parser_t*)user_data; - raw = raw; - sp = sp; - stream_time = stream_time; /* unused */ - - vbi_decode (parser->dec, sliced, n_lines, sample_time); - return TRUE; -} - - - - vbi_bool -decode_vbi (int dev_no, int fid, const uint8_t *data, int len, void *user_data){ - - AM_DEBUG("NTSC-------------------- decode_vbi len = %d\n",len); - AM_NTSC_CC_Parser_t *parser = (AM_NTSC_CC_Parser_t*)user_data; - if(user_data == NULL) - AM_DEBUG("NTSC-------------------- decode_vbi NOT user_data "); - - int length = len; - struct stream *st; - if(len < 0 || data == NULL) - goto error; - st = read_stream_new (data,length,FILE_FORMAT_SLICED, - 0,decode_frame,parser); - - stream_loop (st); - stream_delete (st); - return AM_SUCCESS; - - error: - return AM_FAILURE; - -} - - - - vbi_bool AM_NTSC_Create(AM_NTSC_CC_Handle_t *handle, AM_NTSC_CC_Para_t *para) -{ - if(!para || !handle) - { - return AM_VBI_DMX_ERROR_BASE; - } - AM_NTSC_CC_Parser_t* parser = (AM_NTSC_CC_Parser_t*)malloc(sizeof(AM_NTSC_CC_Parser_t)); - if(!parser) - { - return AM_VBI_DMX_ERR_NOT_ALLOCATED; - } - memset(parser, 0, sizeof(AM_NTSC_CC_Parser_t)); - vbi_bool success; - parser->dec = vbi_decoder_new (); - assert (NULL != parser->dec); - success = vbi_event_handler_add (parser->dec, VBI_EVENT_CAPTION, - vbi_cc_handler, parser); - assert (success); - pthread_mutex_init(&parser->lock, NULL); - pthread_cond_init(&parser->cond, NULL); - - *handle = parser; - parser->para = *para; - return AM_SUCCESS; -} - - - AM_ErrorCode_t AM_NTSC_CC_Start(AM_NTSC_CC_Handle_t handle) -{ - AM_DEBUG("NTSC-------------------- ******************AM_NTSC_CC_Start \n"); - AM_NTSC_CC_Parser_t *parser = (AM_NTSC_CC_Para_t*)handle; - vbi_bool ret = AM_SUCCESS; - - if(!parser) - { - AM_DEBUG("NTSC-------------------- ******************AM_CC_ERR_INVALID_HANDLE \n"); - return AM_CC_ERR_INVALID_HANDLE; - } - - pthread_mutex_lock(&parser->lock); - - if(!parser->running) - { - parser->running = AM_TRUE; - if(pthread_create(&parser->thread, NULL, vbi_cc_thread, parser)) - { - parser->running = AM_FALSE; - ret = AM_CC_ERR_CANNOT_CREATE_THREAD; - } - } - pthread_mutex_unlock(&parser->lock); - - return AM_SUCCESS; -} - -void* AM_VBI_CC_GetUserData(AM_NTSC_CC_Handle_t handle) -{ - AM_NTSC_CC_Parser_t *parser = (AM_NTSC_CC_Para_t*)handle; - if(!parser) - { - return NULL; - } - return parser->para.user_data; -} diff --git a/ntsc_decode/am_vbi.c b/ntsc_decode/am_vbi.c new file mode 100755 index 0000000..c66ab06 --- a/dev/null +++ b/ntsc_decode/am_vbi.c @@ -0,0 +1,421 @@ +#undef NDEBUG + +#include <stdio.h> +#include <stdlib.h> +#include <pthread.h> +#include <unistd.h> +#include <string.h> +#include "vbi.h" +#include "exp-gfx.h" +#include "hamm.h" +#include "dvb_demux.h" +#include "sliced.h" +#include "sliced_vbi.h" +#include "am_vbi.h" +#include "vbi_dmx.h" +#include "am_xds.h" +/********************define variable***************************/ + + +typedef struct +{ + vbi_decoder *dec; + //vbi_search *search; + AM_VBI_CC_Para_t cc_para; + AM_VBI_XDS_Para_t xds_para; + int page_no; + int sub_page_no; + vbi_bool disp_update; + vbi_bool running; + uint64_t pts; + pthread_mutex_t lock; + pthread_cond_t cond; + pthread_t thread; +}AM_VBI_Parser_t; + +vbi_pgno pgno = -1; + +//AM_VBI_Parser_t *parser = NULL; + +static void +reset (AM_VBI_Parser_t *parser) +{ + vbi_page page; + vbi_bool success; + int row; + + success = vbi_fetch_cc_page (parser->dec, &page, pgno, TRUE); + assert (success); + + for (row = 0; row <= page.rows; ++row) + render (parser,&page, row); + + vbi_unref_page (&page); +} + +/**********************************************************/ + + + void vbi_cc_show(AM_VBI_Parser_t *parser) +{ + + vbi_page page; + vbi_bool success; + int row; + //user_data = user_data; + + //if (pgno != -1 && parser->page_no != pgno) + // return; + + /* Fetching & rendering in the handler + is a bad idea, but this is only a test */ + AM_DEBUG("NTSC-------------------- vbi_cc_show****************\n"); + success = vbi_fetch_cc_page (parser->dec, &page, parser->page_no, TRUE); + AM_DEBUG("NTSC--------------1212------vbi_fetch_cc_page success****************\n"); + assert (success); + + int i ,j; + if(parser->cc_para.draw_begin) + parser->cc_para.draw_begin(parser); + + vbi_draw_cc_page_region (&page, VBI_PIXFMT_RGBA32_LE, parser->cc_para.bitmap, + parser->cc_para.pitch, 0, 0, page.columns, page.rows); + + if(parser->cc_para.draw_end) + parser->cc_para.draw_end(parser); + vbi_unref_page (&page); +} + + +static void* vbi_cc_thread(void *arg) +{ + AM_VBI_Parser_t *parser = (AM_VBI_Parser_t*)arg; + + pthread_mutex_lock(&parser->lock); + AM_DEBUG("NTSC***************________________ vbi_cc_thread parser->running = %d\n",parser->running); + while(parser->running) + { + AM_DEBUG("NTSC***************________________ vbi_cc_thread disp_update = %d\n",parser->disp_update); + while(parser->running && !parser->disp_update){ + pthread_cond_wait(&parser->cond, &parser->lock); + } + AM_DEBUG("NTSC***************________________ vbi_cc_thread disp_update = %d\n",parser->disp_update); + if(parser->disp_update){ + vbi_cc_show(parser); + parser->disp_update = FALSE; + } + } + pthread_mutex_unlock(&parser->lock); + + return NULL; +} + +static void vbi_cc_handler(vbi_event * ev,void * user_data) +{ + AM_VBI_Parser_t *parser = (AM_VBI_Parser_t*)user_data; + AM_DEBUG("NTSC-------------------- vbi_cc_handler****************"); + //if(parser->page_no != ev->ev.caption.pgno){ + parser->page_no = ev->ev.caption.pgno; + parser->disp_update = AM_TRUE; + pthread_cond_signal(&parser->cond); + + //vbi_cc_show(parser); + //} +} + + + + + + +static void vbi_xds_handler (vbi_event * ev, void * user_data) +{ + AM_DEBUG("xds-------------------- xds_handler****************"); + AM_VBI_Parser_t *parser = (AM_VBI_Parser_t*)user_data; + + + if(ev == NULL) + return; + vbi_program_info * prog_info = ev->ev.prog_info; + vbi_xds_subclass_program xds_program; + switch(ev->type) + { + case VBI_EVENT_ASPECT : + /* program identification number */ + if(!(prog_info->month == -1 && prog_info->day == -1 + && prog_info->hour == -1 && prog_info->min == -1 )) + { + xds_program = VBI_XDS_PROGRAM_ID; + AM_DEBUG("xds*********VBI_XDS_PROGRAM_ID \n"); + break; + } + /* program name */ + if(!(prog_info->title[0] == 0)) + { + xds_program = VBI_XDS_PROGRAM_NAME; + AM_DEBUG("xds*********VBI_XDS_PROGRAM_NAME \n"); + break; + } + /* program aspect ratio */ + if(!(prog_info->aspect.first_line == prog_info->aspect.last_line == -1 && prog_info->aspect.ratio == 0.0)) + { + xds_program = VBI_XDS_PROGRAM_ASPECT_RATIO; + AM_DEBUG("xds*********VBI_XDS_PROGRAM_ASPECT_RATIO \n"); + break; + } + + break; + case VBI_EVENT_PROG_INFO : + /* 02 Program Length */ + if(!(prog_info->length_hour == -1 && prog_info->length_min == -1 &&prog_info->elapsed_hour == -1 && + prog_info->elapsed_min == -1 &&prog_info->elapsed_sec == -1 )) + { + xds_program = VBI_XDS_PROGRAM_LENGTH; + AM_DEBUG("xds*********VBI_XDS_PROGRAM_LENGTH \n"); + break; + } + + /* 04 Program type */ + /* + * If unknown type_classf == VBI_PROG_CLASSF_NONE. + * VBI_PROG_CLASSF_EIA_608 can have up to 32 tags + * identifying 96 keywords. Their numerical value + * is given here instead of composing a string for + * easier filtering. Use vbi_prog_type_str_by_id to + * get the keywords. A zero marks the end. + */ + if(!(prog_info->type_classf == VBI_PROG_CLASSF_NONE)) + { + xds_program = VBI_XDS_PROGRAM_TYPE; + AM_DEBUG("xds*********VBI_XDS_PROGRAM_TYPE \n"); + break; + } + + /* 05 Program rating */ + /* + * For details STFW for "v-chip" + * If unknown rating_auth == VBI_RATING_NONE + */ + if(!(prog_info->rating_auth == VBI_RATING_AUTH_NONE)) + { + xds_program = VBI_XDS_PROGRAM_RATING; + AM_DEBUG("xds*********VBI_XDS_PROGRAM_RATING \n"); + break; + } + + /* 06 Program Audio Services */ + /* + * BTSC audio (two independent tracks) is flagged according to XDS, + * Zweiton/NICAM/EIA-J audio is flagged mono/none, stereo/none or + * mono/mono for bilingual transmissions. + */ + if((prog_info->audio[0].mode != VBI_AUDIO_MODE_UNKNOWN) || + (prog_info->audio[1].mode != VBI_AUDIO_MODE_UNKNOWN)) + { + xds_program = VBI_XDS_PROGRAM_AUDIO_SERVICES; + AM_DEBUG("xds*********VBI_XDS_PROGRAM_AUDIO_SERVICES \n"); + break; + } + + /* 07 Program Caption Services */ + /* + * Bits 0...7 corresponding to Caption page 1...8. + * Note for the current program this information is also + * available via vbi_classify_page(). + * + * If unknown caption_services == -1, _language[] = NULL + */ + if(!(prog_info->caption_services == -1)) + { + xds_program = VBI_XDS_PROGRAM_CAPTION_SERVICES; + AM_DEBUG("xds*********VBI_XDS_PROGRAM_CAPTION_SERVICES \n"); + break; + } + break; + + } + + if(prog_info->rating_auth != VBI_RATING_AUTH_NONE) + { + AM_DEBUG("xds**********prog_info->rating_auth = %d\n",prog_info->rating_auth ); + + if(prog_info->rating_auth == VBI_RATING_AUTH_MPAA) + AM_DEBUG("xds**********result*******************VBI_RATING_AUTH_MPAA\n"); + if(prog_info->rating_auth == VBI_RATING_AUTH_TV_US) + AM_DEBUG("xds**********result*******************VBI_RATING_AUTH_TV_US\n"); + if(prog_info->rating_auth == VBI_RATING_AUTH_TV_CA_EN) + AM_DEBUG("xds**********result*******************VBI_RATING_AUTH_TV_CA_EN\n"); + if(prog_info->rating_auth == VBI_RATING_AUTH_TV_CA_FR) + AM_DEBUG("xds**********result*******************VBI_RATING_AUTH_TV_CA_FR\n"); + if(prog_info->rating_auth == VBI_RATING_AUTH_NONE) + AM_DEBUG("result*******************VBI_RATING_AUTH_NONE\n"); + + if (prog_info->rating_dlsv == VBI_RATING_D) + AM_DEBUG("xds**********result*******************VBI_RATING_D\n"); + if (prog_info->rating_dlsv == VBI_RATING_L) + AM_DEBUG("xds**********result*******************VBI_RATING_L\n"); + if (prog_info->rating_dlsv == VBI_RATING_S) + AM_DEBUG("xds**********result*******************VBI_RATING_S\n"); + if (prog_info->rating_dlsv == VBI_RATING_V) + AM_DEBUG("xds**********result*******************VBI_RATING_V\n"); + AM_DEBUG("xds**********result*******************prog_info->rating_id = %d\n",prog_info->rating_id ); + + } + + parser->xds_para.xds_callback(parser,xds_program,prog_info); + +} + +/**********************************************************/ + +static vbi_bool +decode_frame (const vbi_sliced * sliced, + unsigned int n_lines, + const uint8_t * raw, + const vbi_sampling_par *sp, + double sample_time, + int64_t stream_time, + void * user_data) +{ + AM_DEBUG("NTSC-------------------- decode_frame\n"); + if(user_data == NULL) return FALSE; + AM_VBI_Parser_t *parser = (AM_VBI_Parser_t*)user_data; + raw = raw; + sp = sp; + stream_time = stream_time; /* unused */ + + vbi_decode (parser->dec, sliced, n_lines, sample_time); + return TRUE; +} + + + + vbi_bool +decode_vbi (int dev_no, int fid, const uint8_t *data, int len, void *user_data){ + + AM_DEBUG("NTSC-------------------- decode_vbi len = %d\n",len); + AM_VBI_Parser_t *parser = (AM_VBI_Parser_t*)user_data; + if(user_data == NULL) + AM_DEBUG("NTSC-------------------- decode_vbi NOT user_data "); + + int length = len; + struct stream *st; + if(len < 0 || data == NULL) + goto error; + st = read_stream_new (data,length,FILE_FORMAT_SLICED, + 0,decode_frame,parser); + + stream_loop (st); + stream_delete (st); + return AM_SUCCESS; + + error: + return AM_FAILURE; + +} + + void init_vbi_decoder( AM_VBI_Parser_t* parser) + { + memset(parser, 0, sizeof(AM_VBI_Parser_t)); + parser->dec = vbi_decoder_new (); + assert (NULL != parser->dec); + pthread_mutex_init(&parser->lock, NULL); + pthread_cond_init(&parser->cond, NULL); + } + + + + +vbi_bool AM_VBI_CC_Create(AM_VBI_Handle_t *handle, AM_VBI_CC_Para_t *para) +{ + AM_VBI_Parser_t* parser = NULL; + if(*handle == NULL) + { + + parser = (AM_VBI_Parser_t*)malloc(sizeof(AM_VBI_Parser_t)); + if(!parser) + { + return AM_VBI_DMX_ERR_NOT_ALLOCATED; + } + init_vbi_decoder(parser); + }else + parser = (AM_VBI_Parser_t*)handle; + + vbi_bool success; + success = vbi_event_handler_add (parser->dec, VBI_EVENT_CAPTION, + vbi_cc_handler, parser); + + //****************************************************** + //success = vbi_event_handler_add (parser->dec, VBI_EVENT_ASPECT | VBI_EVENT_PROG_INFO, + // vbi_xds_handler, parser); + //************************************************ + assert (success); + parser->cc_para = *para; + *handle = parser; + return AM_SUCCESS; +} + + + AM_ErrorCode_t AM_VBI_CC_Start(AM_VBI_Handle_t handle) +{ + AM_DEBUG("NTSC-------------------- ******************AM_NTSC_CC_Start \n"); + AM_VBI_Parser_t *parser = (AM_VBI_Parser_t*)handle; + vbi_bool ret = AM_SUCCESS; + + if(!parser) + { + AM_DEBUG("NTSC-------------------- ******************AM_CC_ERR_INVALID_HANDLE \n"); + return AM_CC_ERR_INVALID_HANDLE; + } + + pthread_mutex_lock(&parser->lock); + + if(!parser->running) + { + parser->running = AM_TRUE; + if(pthread_create(&parser->thread, NULL, vbi_cc_thread, parser)) + { + parser->running = AM_FALSE; + ret = AM_CC_ERR_CANNOT_CREATE_THREAD; + } + } + pthread_mutex_unlock(&parser->lock); + + return AM_SUCCESS; +} + +void* AM_VBI_CC_GetUserData(AM_VBI_Handle_t handle) +{ + AM_VBI_Parser_t *parser = (AM_VBI_Parser_t*)handle; + if(!parser) + { + return NULL; + } + return parser->cc_para.user_data; +} + +vbi_bool AM_VBI_XDS_Create(AM_VBI_Handle_t *handle,AM_VBI_XDS_Para_t *para) +{ + vbi_bool ret = AM_SUCCESS; + AM_VBI_Parser_t* parser; + if(*handle == NULL) + { + AM_DEBUG("NTSC-------------------- ******************AM_XDS_Create handle is null \n"); + parser = (AM_VBI_Parser_t*)malloc(sizeof(AM_VBI_Parser_t)); + if(!parser) + { + return AM_VBI_DMX_ERR_NOT_ALLOCATED; + } + init_vbi_decoder(parser); + *handle = parser; + }else + parser = (AM_VBI_Parser_t*)*handle; + parser->xds_para = *para; + AM_DEBUG("NTSC--------------- ******************vbi_event_handler_add xds_handle \n"); + ret = vbi_event_handler_add (parser->dec, VBI_EVENT_ASPECT | VBI_EVENT_PROG_INFO, + vbi_xds_handler, parser); + + assert (ret); + return AM_SUCCESS; + +}
\ No newline at end of file diff --git a/ntsc_decode/am_ntsc_cc.h b/ntsc_decode/include/am_vbi.h index 43c317a..68d4418 100755 --- a/ntsc_decode/am_ntsc_cc.h +++ b/ntsc_decode/include/am_vbi.h @@ -23,6 +23,7 @@ #include "tables.h" #include "vbi.h" #include <android/log.h> +#include <am_xds.h> #ifdef __cplusplus extern "C" { @@ -51,13 +52,16 @@ enum AM_CC_ErrorCode * Type definitions ***************************************************************************/ /**\brief Teletext分析器句柄*/ -typedef void* AM_NTSC_CC_Handle_t; +typedef void* AM_VBI_Handle_t; /**\brief 开始绘制*/ -typedef void (*AM_VBI_CC_DrawBegin_t)(AM_NTSC_CC_Handle_t handle); +typedef void (*AM_VBI_CC_DrawBegin_t)(AM_VBI_Handle_t handle); /**\brief 结束绘制*/ -typedef void (*AM_VBI_CC_DrawEnd_t)(AM_NTSC_CC_Handle_t handle); +typedef void (*AM_VBI_CC_DrawEnd_t)(AM_VBI_Handle_t handle); + +/**\brief notify xds data*/ +typedef void (*AM_VBI_xds_callback_t)(AM_VBI_Handle_t handle, vbi_xds_subclass_program xds_program,vbi_program_info * prog_info); typedef struct { @@ -67,17 +71,26 @@ typedef void (*AM_VBI_CC_DrawEnd_t)(AM_NTSC_CC_Handle_t handle); uint8_t *bitmap; /**< 绘图缓冲区*/ int pitch; /**< 绘图缓冲区每行字节数*/ void *user_data; /**< 用户定义数据*/ -}AM_NTSC_CC_Para_t; +}AM_VBI_CC_Para_t; + + typedef struct +{ + AM_VBI_xds_callback_t xds_callback; /**< notify to user */ +}AM_VBI_XDS_Para_t; -extern vbi_bool AM_NTSC_Create(AM_NTSC_CC_Handle_t *handle, AM_NTSC_CC_Para_t *para); -extern vbi_bool AM_NTSC_CC_Start(AM_NTSC_CC_Handle_t handle); +extern vbi_bool AM_VBI_CC_Create(AM_VBI_Handle_t *handle, AM_VBI_CC_Para_t *para); + +extern vbi_bool AM_VBI_CC_Start(AM_VBI_Handle_t handle); extern vbi_bool decode_vbi (int dev_no, int fid, const uint8_t *data, int len, void *user_data); -extern void* AM_VBI_CC_GetUserData(AM_NTSC_CC_Handle_t handle); +extern void* AM_VBI_CC_GetUserData(AM_VBI_Handle_t handle); + + +extern vbi_bool AM_VBI_XDS_Create(AM_VBI_Handle_t *handle,AM_VBI_XDS_Para_t *para); #ifdef __cplusplus } diff --git a/ntsc_decode/ntsc_dmx/am_vbi_internal.h b/ntsc_decode/include/am_vbi_internal.h index 398d2d4..398d2d4 100755 --- a/ntsc_decode/ntsc_dmx/am_vbi_internal.h +++ b/ntsc_decode/include/am_vbi_internal.h diff --git a/ntsc_decode/include/am_xds.h b/ntsc_decode/include/am_xds.h new file mode 100755 index 0000000..c3358e7 --- a/dev/null +++ b/ntsc_decode/include/am_xds.h @@ -0,0 +1,52 @@ +/*************************************************************************** + * Copyright C 2009 by Amlogic, Inc. All Rights Reserved. + */ +/**\file + * \brief Teletext模块(version 2) + * + * \author kui.zhang <kui.zhang@amlogic.com> + * \date 2012-09-13: create the document + ***************************************************************************/ + + + +#ifndef _AM_XDS +#define _AM_XDS + + +#include <unistd.h> +#include "misc.h" +#include "trigger.h" +#include "format.h" +#include "lang.h" +#include "hamm.h" +#include "tables.h" +#include "vbi.h" +#include <android/log.h> +#ifdef __cplusplus +extern "C" +{ +#endif + + +typedef enum { + VBI_XDS_PROGRAM_ID = 0x01, + VBI_XDS_PROGRAM_LENGTH, + VBI_XDS_PROGRAM_NAME, + VBI_XDS_PROGRAM_TYPE, + VBI_XDS_PROGRAM_RATING, + VBI_XDS_PROGRAM_AUDIO_SERVICES, + VBI_XDS_PROGRAM_CAPTION_SERVICES, + VBI_XDS_PROGRAM_CGMS, + VBI_XDS_PROGRAM_ASPECT_RATIO, + + VBI_XDS_PROGRAM_DATA = 0x0C, + + VBI_XDS_PROGRAM_MISC_DATA, + VBI_XDS_PROGRAM_DESCRIPTION_BEGIN = 0x10, + VBI_XDS_PROGRAM_DESCRIPTION_END = 0x18 +} vbi_xds_subclass_program; + + + +#endif diff --git a/ntsc_decode/ntsc_dmx/include/vbi_dmx.h b/ntsc_decode/include/ntsc_dmx/vbi_dmx.h index 36abfb5..36abfb5 100755 --- a/ntsc_decode/ntsc_dmx/include/vbi_dmx.h +++ b/ntsc_decode/include/ntsc_dmx/vbi_dmx.h diff --git a/ntsc_decode/sliced_vbi.h b/ntsc_decode/include/sliced_vbi.h index 1b884fd..1b884fd 100755 --- a/ntsc_decode/sliced_vbi.h +++ b/ntsc_decode/include/sliced_vbi.h diff --git a/src/caption.c b/src/caption.c index 804c0f9..90e7a67 100755 --- a/src/caption.c +++ b/src/caption.c @@ -34,11 +34,17 @@ #include "hamm.h" #include "tables.h" #include "vbi.h" +#include <android/log.h> #define elements(array) (sizeof(array) / sizeof(array[0])) +#define LOG_TAG "ZVBI" +#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) +#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) + + #define ITV_DEBUG(x) /* x */ -#define XDS_SEP_DEBUG(x) /* x */ x +#define XDS_SEP_DEBUG /* x */ printf #define XDS_SEP_DUMP(x) /* x */ #define CC_DUMP(x) /* x */ #define CC_TEXT_DUMP(x) /* x */ @@ -147,7 +153,7 @@ static inline void xds_decoder(vbi_decoder *vbi, int _class, int type, uint8_t *buffer, int length) { - XDS_SEP_DEBUG(printf("xds_decoder _class = %d,type = %d, buffer[0]=%02x, buffer[1]=%02x length = %d,\n",_class ,type,buffer[0], buffer[1],length)); + XDS_SEP_DEBUG("xds_decoder _class = %d,type = %d, buffer[0]=%02x, buffer[1]=%02x length = %d,\n",_class ,type,buffer[0], buffer[1],length); vbi_network *n = &vbi->network.ev.network; vbi_program_info *pi; int neq, i; @@ -164,7 +170,7 @@ xds_decoder(vbi_decoder *vbi, int _class, int type, case XDS_CURRENT: /* 0 */ case XDS_FUTURE: /* 1 */ if (!(vbi->event_mask & (VBI_EVENT_ASPECT | VBI_EVENT_PROG_INFO))){ - XDS_SEP_DEBUG(printf("vbi->event_mask & VBI_EVENT_ASPECT | VBI_EVENT_PROG_INFO")); + XDS_SEP_DEBUG("vbi->event_mask & VBI_EVENT_ASPECT | VBI_EVENT_PROG_INFO"); return; } pi = &vbi->prog_info[_class]; @@ -290,7 +296,7 @@ xds_decoder(vbi_decoder *vbi, int _class, int type, r = buffer[0] & 7; g = buffer[1] & 7; - XDS_SEP_DEBUG(printf("r = %d,g = %d\n",r,g)); + XDS_SEP_DEBUG("r = %d,g = %d\n",r,g); if (buffer[0] & 0x20) dlsv |= VBI_RATING_D; if (buffer[1] & 0x08) @@ -329,9 +335,9 @@ xds_decoder(vbi_decoder *vbi, int _class, int type, //***************************************zk //callback - e.type = VBI_EVENT_PROG_INFO; - e.ev.prog_info = pi; - caption_send_event(vbi, &e); + //e.type = VBI_EVENT_PROG_INFO; + //e.ev.prog_info = pi; + //caption_send_event(vbi, &e); //*******************************************finish break; @@ -489,7 +495,7 @@ xds_decoder(vbi_decoder *vbi, int _class, int type, e.ev.prog_info = pi; caption_send_event(vbi, &e); - XDS_SEP_DEBUG(printf("caption_send_event VBI_EVENT_PROG_INFO\n")); + XDS_SEP_DEBUG("caption_send_event VBI_EVENT_PROG_INFO\n"); vbi->cc.info_cycle[_class] = 0; /* all changes reported */ } @@ -599,10 +605,10 @@ xds_separator(vbi_decoder *vbi, uint8_t *buf) int c2 = vbi_unpar8 (buf[1]); unsigned int class, type; - XDS_SEP_DEBUG(printf("XDS %02x %02x\n", buf[0], buf[1])); + XDS_SEP_DEBUG("XDS %02x %02x\n", buf[0], buf[1]); if ((c1 | c2) < 0) { - XDS_SEP_DEBUG(printf("XDS tx error, discard current packet\n")); + XDS_SEP_DEBUG("XDS tx error, discard current packet\n"); if (sp) { sp->count = 0; @@ -619,7 +625,7 @@ xds_separator(vbi_decoder *vbi, uint8_t *buf) if (class > elements(cc->sub_packet) || c2 > (int) elements(cc->sub_packet[0])) { - XDS_SEP_DEBUG(printf("XDS ignore packet %d/0x%02x\n", class, c2)); + XDS_SEP_DEBUG("XDS ignore packet %d/0x%02x\n", class, c2); cc->curr_sp = NULL; return; } @@ -630,7 +636,7 @@ xds_separator(vbi_decoder *vbi, uint8_t *buf) sp->chksum = c1 + c2; sp->count = 2; } else if (!sp->count) { - XDS_SEP_DEBUG(printf("XDS can't continue %d/0x%02x\n", class, c2)); + XDS_SEP_DEBUG("XDS can't continue %d/0x%02x\n", class, c2); cc->curr_sp = NULL; } @@ -646,11 +652,11 @@ xds_separator(vbi_decoder *vbi, uint8_t *buf) type = (sp - cc->sub_packet[0]) % elements(cc->sub_packet[0]); if (sp->chksum & 0x7F) { - XDS_SEP_DEBUG(printf("XDS ignore packet %d/0x%02x, " - "checksum error\n", class, type)); + XDS_SEP_DEBUG("XDS ignore packet %d/0x%02x, " + "checksum error\n", class, type); } else if (sp->count <= 2) { - XDS_SEP_DEBUG(printf("XDS ignore empty packet " - "%d/0x%02x\n", class, type)); + XDS_SEP_DEBUG("XDS ignore empty packet " + "%d/0x%02x\n", class, type); } else { xds_decoder(vbi, class, type, sp->buffer, sp->count - 2); @@ -672,9 +678,9 @@ xds_separator(vbi_decoder *vbi, uint8_t *buf) return; if (sp->count >= 32 + 2) { - XDS_SEP_DEBUG(printf("XDS packet length overflow, discard %d/0x%02x\n", + XDS_SEP_DEBUG("XDS packet length overflow, discard %d/0x%02x\n", (sp - cc->sub_packet[0]) / elements(cc->sub_packet[0]), - (sp - cc->sub_packet[0]) % elements(cc->sub_packet[0]))); + (sp - cc->sub_packet[0]) % elements(cc->sub_packet[0])); sp->count = 0; sp->chksum = 0; @@ -905,7 +911,7 @@ _vbi_inline void caption_command(vbi_decoder *vbi, struct caption *cc, unsigned char c1, unsigned char c2, vbi_bool field2) { - XDS_SEP_DEBUG(printf("caption_command\n")); + XDS_SEP_DEBUG("caption_command\n"); cc_channel *ch; int chan, col, i; int last_row; @@ -995,7 +1001,7 @@ caption_command(vbi_decoder *vbi, struct caption *cc, c.unicode = vbi_caption_unicode (0x1130 | (c2 & 15), /* to_upper */ FALSE); - XDS_SEP_DEBUG(printf("vbi_caption_unicode %c\n",c.unicode)); + XDS_SEP_DEBUG("vbi_caption_unicode %c\n",c.unicode); put_char(cc, ch, c); } } else { /* Midrow Codes 001 c001 010 xxxu */ @@ -1247,7 +1253,7 @@ caption_command(vbi_decoder *vbi, struct caption *cc, void vbi_decode_caption(vbi_decoder *vbi, int line, uint8_t *buf) { - XDS_SEP_DEBUG(printf("vbi_decode_caption\n")); + XDS_SEP_DEBUG("vbi_decode_caption\n"); struct caption *cc = &vbi->cc; char c1 = buf[0] & 0x7F; int field2 = 1, i; |