author | kui.zhang <kui.zhang@amlogic.com> | 2012-09-11 13:15:36 (GMT) |
---|---|---|
committer | kui.zhang <kui.zhang@amlogic.com> | 2012-09-11 13:15:36 (GMT) |
commit | 0f5fae24c6a18bbf2720939ebab7731efeeff566 (patch) | |
tree | c47ee9c6e8b5e6be7a7bb0a3b9d4fb699d54b221 | |
parent | e38667e52d851e93009e73f45fb22e27bb4a5239 (diff) | |
download | libzvbi-0f5fae24c6a18bbf2720939ebab7731efeeff566.zip libzvbi-0f5fae24c6a18bbf2720939ebab7731efeeff566.tar.gz libzvbi-0f5fae24c6a18bbf2720939ebab7731efeeff566.tar.bz2 |
modify cc
-rwxr-xr-x | ntsc_decode/Android.mk | 3 | ||||
-rwxr-xr-x | ntsc_decode/am_ntsc_cc.c | 543 | ||||
-rwxr-xr-x | ntsc_decode/am_ntsc_cc.h | 30 | ||||
-rwxr-xr-x | ntsc_decode/caption.c | 2 | ||||
-rwxr-xr-x | ntsc_decode/decode.c | 45 | ||||
-rwxr-xr-x | ntsc_decode/decode.h | 22 | ||||
-rwxr-xr-x | ntsc_decode/ntsc_dmx/am_vbi_dmx.c | 31 | ||||
-rwxr-xr-x | ntsc_decode/ntsc_dmx/am_vbi_internal.h | 3 | ||||
-rwxr-xr-x | ntsc_decode/ntsc_dmx/include/vbi_dmx.h | 58 | ||||
-rwxr-xr-x | ntsc_decode/ntsc_dmx/linux_vbi/linux_ntsc.c | 51 | ||||
-rwxr-xr-x | ntsc_decode/ntsc_dmx/test/Android.mk | 1 | ||||
-rwxr-xr-x | ntsc_decode/ntsc_dmx/test/vbi_test.c | 9 | ||||
-rwxr-xr-x | ntsc_decode/sliced1.c | 20 | ||||
-rwxr-xr-x | ntsc_decode/sliced1.h | 6 | ||||
-rwxr-xr-x | ntsc_decode/test/caption.c | 2 | ||||
-rwxr-xr-x | ntsc_decode/test/decode.c | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | src/caption.c | 42 |
17 files changed, 321 insertions, 549 deletions
diff --git a/ntsc_decode/Android.mk b/ntsc_decode/Android.mk index 5820bba..4f8231b 100755 --- a/ntsc_decode/Android.mk +++ b/ntsc_decode/Android.mk @@ -4,7 +4,8 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES:=am_ntsc_cc.c \ sliced1.c \ ntsc_dmx/am_vbi_dmx.c \ - ntsc_dmx/linux_vbi/linux_ntsc.c + ntsc_dmx/linux_vbi/linux_ntsc.c \ + decode.c LOCAL_SHARED_LIBRARIES+= libzvbi diff --git a/ntsc_decode/am_ntsc_cc.c b/ntsc_decode/am_ntsc_cc.c index 5b94be5..5975579 100755 --- a/ntsc_decode/am_ntsc_cc.c +++ b/ntsc_decode/am_ntsc_cc.c @@ -5,9 +5,6 @@ #include <pthread.h> #include <unistd.h> #include <string.h> - - - #include "vbi.h" #include "exp-gfx.h" #include "hamm.h" @@ -15,6 +12,10 @@ #include "sliced.h" #include "sliced1.h" #include "am_ntsc_cc.h" +#include "vbi_dmx.h" + +/********************define variable***************************/ + typedef struct { @@ -31,305 +32,97 @@ typedef struct pthread_t thread; }AM_NTSC_CC_Parser_t; -/********************define variable***************************/ -#define XDS_SEP_DEBUG(x) /* x */ x - vbi_pgno pgno = -1; -vbi_dvb_demux * dx; - -/* - * Rudimentary render code for CC test. - * Attention: RGB 5:6:5 little endian only. - */ - -#define DISP_WIDTH 640 -#define DISP_HEIGHT 480 - -#define CELL_WIDTH 16 -#define CELL_HEIGHT 26 -AM_NTSC_CC_Parser_t *parser; -uint32_t * ximgdata; -int shift = 0, step = 3; -int sh_first, sh_last; -vbi_rgba row_buffer[64 * CELL_WIDTH * CELL_HEIGHT]; -#define COLORKEY 0x80FF80 /* where video looks through */ - -#define RGB565(rgba) \ - (((((rgba) >> 16) & 0xF8) << 8) | ((((rgba) >> 8) & 0xFC) << 3) \ - | (((rgba) & 0xF8) >> 3)) - -/********************define function***************************/ - - static void -draw_blank (int column, - int width) -{ - vbi_rgba *canvas = row_buffer + column * CELL_WIDTH; - int x, y; - - for (y = 0; y < CELL_HEIGHT; y++) { - for (x = 0; x < CELL_WIDTH * width; x++) - canvas[x] = COLORKEY; - canvas += sizeof(row_buffer) / sizeof(row_buffer[0]) - / CELL_HEIGHT; - } -} - - -static void -draw_row (uint32_t * canvas, - vbi_page * pg, - int row) -{ - int i, j, num_tspaces = 0; - vbi_rgba *s = row_buffer; - XDS_SEP_DEBUG(printf("draw_row = %d\n",row)); - for (i = 0; i < pg->columns; ++i) { - XDS_SEP_DEBUG(printf("%02x ", pg->text[row * pg->columns + i].unicode)); - if (pg->text[row * pg->columns + i].opacity - == VBI_TRANSPARENT_SPACE) { - num_tspaces++; - continue; - } - if (num_tspaces > 0) { - draw_blank(i - num_tspaces, num_tspaces); - num_tspaces = 0; - } - - // vbi_draw_cc_page_region (pg, VBI_PIXFMT_RGBA32_LE, - // row_buffer + i * CELL_WIDTH, - // sizeof(row_buffer) / CELL_HEIGHT, - // i, row, 1, 1); - - vbi_draw_cc_page_region (pg, VBI_PIXFMT_RGBA32_LE, - parser->para.bitmap + i * CELL_WIDTH, - sizeof(row_buffer) / CELL_HEIGHT, - i, row, 1, 1); - } - - if (num_tspaces > 0) - draw_blank(i - num_tspaces, num_tspaces); - - XDS_SEP_DEBUG(printf("\npg->columns * CELL_WIDTH= %d\n",pg->columns * CELL_WIDTH)); - return; - for (i = 0; i < CELL_HEIGHT; i++) { - for (j = 0; j < pg->columns * CELL_WIDTH; j++){ - canvas[j] = RGB565(s[j]); - } - s += sizeof(row_buffer) / sizeof(row_buffer[0]) / CELL_HEIGHT; - - canvas += DISP_WIDTH; - } -} +//AM_NTSC_CC_Parser_t *parser = NULL; static void -bump (int n, - vbi_bool draw) +reset (AM_NTSC_CC_Parser_t *parser) { - uint32_t *canvas = ximgdata + 45 * DISP_WIDTH; - XDS_SEP_DEBUG(printf("bump")); - return; - if (shift < n) - n = shift; - - if (shift <= 0 || n <= 0) - return; + vbi_page page; + vbi_bool success; + int row; - memmove (canvas + (sh_first * CELL_HEIGHT) * DISP_WIDTH, - canvas + (sh_first * CELL_HEIGHT + n) * DISP_WIDTH, - ((sh_last - sh_first + 1) * CELL_HEIGHT - n) - * DISP_WIDTH * 2); + success = vbi_fetch_cc_page (parser->dec, &page, pgno, TRUE); + assert (success); - //if (draw) - // XPutImage (display, window, gc, ximage, - // 0, 0, 0, 0, DISP_WIDTH, DISP_HEIGHT); + for (row = 0; row <= page.rows; ++row) + render (parser,&page, row); - shift -= n; + vbi_unref_page (&page); } +/**********************************************************/ -static void -render (vbi_page * pg, - int row) + void vbi_cc_show(AM_NTSC_CC_Parser_t *parser) { - //* ushort *canvas = ximgdata + 48 + 45 * DISP_WIDTH; - XDS_SEP_DEBUG(printf("render row %d\n",row)); - if (shift > 0) { - bump(shift, FALSE); - //draw_video (48, 45 + sh_last * CELL_HEIGHT, - // DISP_WIDTH - 48, CELL_HEIGHT); - } - XDS_SEP_DEBUG(printf("render draw_row %d\n",ximgdata + 48 + (45 + row * CELL_HEIGHT) * DISP_WIDTH)); - if(parser->para.draw_begin) - parser->para.draw_begin(parser); - draw_row (ximgdata + 48 + (45 + row * CELL_HEIGHT) * DISP_WIDTH, - pg, row); - if(parser->para.draw_end) - parser->para.draw_end(parser); - - //XPutImage (display, window, gc, ximage, - // 0, 0, 0, 0, DISP_WIDTH, DISP_HEIGHT); -} - - -static void NTSC_CC_show(AM_NTSC_CC_Parser_t *parser) -{ vbi_page page; - vbi_bool cached; + vbi_bool success; + int row; + //user_data = user_data; - //cached = vbi_fetch_vt_page(parser->dec, &page, vbi_dec2bcd(parser->page_no), parser->sub_page_no, VBI_WST_LEVEL_3p5, 25, AM_TRUE); - //if(!cached) + //if (pgno != -1 && parser->page_no != pgno) // return; - - //parser->sub_page_no = page.subno; - //if(parser->para.draw_begin) - // parser->para.draw_begin(parser); + /* 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); - /*{ - char buf[256]; - int i, j; - - for(i=0; i<page.rows; i++){ - char *ptr = buf; - for(j=0; j<page.columns; j++){ - sprintf(ptr, "%02x", page.text[i*page.columns+j].unicode); - ptr += 2; - } - - AM_DEBUG(1, "text %02d: %s", i, buf); - } - }*/ + int i ,j; + if(parser->para.draw_begin) + parser->para.draw_begin(parser); - //vbi_draw_vt_page_region(&page, VBI_PIXFMT_RGBA32_LE, parser->para.bitmap, parser->para.pitch, - // 0, 0, page.columns, page.rows, 1, 1, parser->para.is_subtitle); - - //if(parser->para.draw_end) - // parser->para.draw_end(parser); + vbi_draw_cc_page_region (&page, VBI_PIXFMT_RGBA32_LE, parser->para.bitmap, + parser->para.pitch, 0, 0, page.columns, page.rows); - //vbi_unref_page(&page); -} - - - - - - - - - - - -static void -reset (void) -{ - 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 (&page, row); - + if(parser->para.draw_end) + parser->para.draw_end(parser); vbi_unref_page (&page); } -/**********************************************************/ -static void* ntsc_cc_thread(void *arg) + +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){ - ntsc_cc_show(parser); + vbi_cc_show(parser); parser->disp_update = FALSE; } } - pthread_mutex_unlock(&parser->lock); return NULL; } - - void ntsc_cc_show(AM_NTSC_CC_Parser_t *parser) -{ - vbi_page page; - vbi_bool success; - int row; - vbi_event * ev; - //user_data = user_data; - - if (pgno != -1 && ev->ev.caption.pgno != pgno) - return; - - /* Fetching & rendering in the handler - is a bad idea, but this is only a test */ - - success = vbi_fetch_cc_page (parser->dec, &page, ev->ev.caption.pgno, TRUE); - assert (success); - - if(parser->para.draw_begin) - parser->para.draw_begin(parser); - - for (row = page.dirty.y0; row <= page.dirty.y1; ++row) - render (&page, row); - - if(parser->para.draw_end) - parser->para.draw_end(parser); - vbi_unref_page (&page); -} -/**********************************************************/ -static void -cc_handler (vbi_event * ev, - void * user_data) +static void vbi_cc_handler(vbi_event * ev,void * user_data) { - - printf("cc_handler\n"); - vbi_page page; - vbi_bool success; - int row; - - user_data = user_data; - - if (pgno != -1 && ev->ev.caption.pgno != pgno) - return; - - /* Fetching & rendering in the handler - is a bad idea, but this is only a test */ - - success = vbi_fetch_cc_page (parser->dec, &page, ev->ev.caption.pgno, TRUE); - assert (success); - XDS_SEP_DEBUG(printf("cc_handler***********success = %d\n",success)); -#if 1 /* optional */ - if (abs (page.dirty.roll) > page.rows) { - XDS_SEP_DEBUG(printf("clear")); - //clear (&page); - } else if (page.dirty.roll == -1) { - XDS_SEP_DEBUG(printf("roll_up")); - //roll_up (&page, page.dirty.y0, page.dirty.y1); - } else { -#endif - for (row = page.dirty.y0; row <= page.dirty.y1; ++row) - render (&page, row); - } - vbi_unref_page (&page); + 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, @@ -337,235 +130,109 @@ decode_frame (const vbi_sliced * sliced, const uint8_t * raw, const vbi_sampling_par *sp, double sample_time, - int64_t stream_time) + int64_t stream_time, + void * user_data) { - printf("decode_frame\n"); + 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; +} - /* xevent (1e6 / 30); */ - 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 FALSE; + return AM_VBI_DMX_ERROR_BASE; } - parser = (AM_NTSC_CC_Parser_t*)malloc(sizeof(AM_NTSC_CC_Parser_t)); + AM_NTSC_CC_Parser_t* parser = (AM_NTSC_CC_Parser_t*)malloc(sizeof(AM_NTSC_CC_Parser_t)); if(!parser) { - return FALSE; + 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, - cc_handler, /* used_data */ NULL); + vbi_cc_handler, parser); assert (success); pthread_mutex_init(&parser->lock, NULL); pthread_cond_init(&parser->cond, NULL); *handle = parser; parser->para = *para; - return TRUE; + return AM_SUCCESS; } - vbi_bool AM_NTSC_CC_Start(AM_NTSC_CC_Handle_t handle) + AM_ErrorCode_t AM_NTSC_CC_Start(AM_NTSC_CC_Handle_t handle) { - __android_log_print(ANDROID_LOG_INFO, "NTSC_CC", "AM_NTSC_CC_Start"); + AM_DEBUG("NTSC-------------------- ******************AM_NTSC_CC_Start \n"); AM_NTSC_CC_Parser_t *parser = (AM_NTSC_CC_Para_t*)handle; - 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, - }; - int length = N_ELEMENTS (pBuffer); - struct stream *st; - st = read_stream_new (pBuffer,length, - FILE_FORMAT_SLICED, - 0, - decode_frame); - - //st = read_stream_new (/* filename: stdin */ NULL, - // FILE_FORMAT_SLICED, - // /* ts_pid */ 0, - // decode_frame); - //if(parser->para.draw_begin) - // parser->para.draw_begin(parser); - - stream_loop (st); - - //if(parser->para.draw_end) - // parser->para.draw_end(parser); - - stream_delete (st); - //} - - printf ("Done.\n"); - - //for (;;) - // xevent (33333); - - vbi_decoder_delete (parser->dec); - - - /* vbi_bool ret = AM_SUCCESS; if(!parser) - { - return AM_TT2_ERR_INVALID_HANDLE; + { + 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, tt2_thread, parser)) + if(pthread_create(&parser->thread, NULL, vbi_cc_thread, parser)) { parser->running = AM_FALSE; - ret = AM_TT2_ERR_CANNOT_CREATE_THREAD; + ret = AM_CC_ERR_CANNOT_CREATE_THREAD; } } - pthread_mutex_unlock(&parser->lock); -*/ - - return TRUE; + 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_ntsc_cc.h b/ntsc_decode/am_ntsc_cc.h index a474db5..43c317a 100755 --- a/ntsc_decode/am_ntsc_cc.h +++ b/ntsc_decode/am_ntsc_cc.h @@ -28,6 +28,25 @@ extern "C" { #endif + + +enum AM_CC_ErrorCode +{ + AM_CC_ERROR_BASE =0, + AM_CC_ERR_INVALID_PARAM, /**< 参数无效*/ + AM_CC_ERR_INVALID_HANDLE, /**< 句柄无效*/ + AM_CC_ERR_NOT_SUPPORTED, /**< 不支持的操作*/ + AM_CC_ERR_CREATE_DECODE, /**< 打开cc解码器失败*/ + AM_CC_ERR_OPEN_PES, /**< 打开PES通道失败*/ + AM_CC_ERR_SET_BUFFER, /**< 设置PES 缓冲区失败*/ + AM_CC_ERR_NO_MEM, /**< 空闲内存不足*/ + AM_CC_ERR_CANNOT_CREATE_THREAD, /**< 无法创建线程*/ + AM_CC_ERR_NOT_RUN, /**< 无法创建线程*/ + AM_CC_INIT_DISPLAY_FAILED, /**< 初始化显示屏幕失败*/ + AM_CC_ERR_END +}; + + /**************************************************************************** * Type definitions ***************************************************************************/ @@ -35,15 +54,15 @@ extern "C" typedef void* AM_NTSC_CC_Handle_t; /**\brief 开始绘制*/ -typedef void (*AM_TT2_DrawBegin_t)(AM_NTSC_CC_Handle_t handle); +typedef void (*AM_VBI_CC_DrawBegin_t)(AM_NTSC_CC_Handle_t handle); /**\brief 结束绘制*/ -typedef void (*AM_TT2_DrawEnd_t)(AM_NTSC_CC_Handle_t handle); +typedef void (*AM_VBI_CC_DrawEnd_t)(AM_NTSC_CC_Handle_t handle); typedef struct { - AM_TT2_DrawBegin_t draw_begin; /**< 开始绘制*/ - AM_TT2_DrawEnd_t draw_end; /**< 结束绘制*/ + AM_VBI_CC_DrawBegin_t draw_begin; /**< 开始绘制*/ + AM_VBI_CC_DrawEnd_t draw_end; /**< 结束绘制*/ vbi_bool is_subtitle; /**< 是否为字幕*/ uint8_t *bitmap; /**< 绘图缓冲区*/ int pitch; /**< 绘图缓冲区每行字节数*/ @@ -55,7 +74,10 @@ extern vbi_bool AM_NTSC_Create(AM_NTSC_CC_Handle_t *handle, AM_NTSC_CC_Para_t *p extern vbi_bool AM_NTSC_CC_Start(AM_NTSC_CC_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); #ifdef __cplusplus } diff --git a/ntsc_decode/caption.c b/ntsc_decode/caption.c index def1f99..323839e 100755 --- a/ntsc_decode/caption.c +++ b/ntsc_decode/caption.c @@ -909,7 +909,7 @@ main (int argc, st = read_stream_new (pBuffer,length, FILE_FORMAT_SLICED, 0, - decode_frame); + decode_frame,NULL); //st = read_stream_new (/* filename: stdin */ NULL, // FILE_FORMAT_SLICED, diff --git a/ntsc_decode/decode.c b/ntsc_decode/decode.c index f5bb719..fd9ff57 100755 --- a/ntsc_decode/decode.c +++ b/ntsc_decode/decode.c @@ -63,7 +63,7 @@ #include "sliced.h" #include "sliced1.h" - +#include "decode.h" #undef _ #define _(x) x /* i18n TODO */ @@ -107,6 +107,11 @@ static vbi_xds_demux * xds; NTSC_XDS_status_cb ntsc_xds_callback = NULL; +void decode_ntsc_xds_set_callback(NTSC_XDS_status_cb cb_ptr){ + printf("decode_ntsc_xds_set_callback"); + ntsc_xds_callback = cb_ptr; +} + extern void _vbi_pfc_block_dump (const vbi_pfc_block * pb, FILE * fp, @@ -277,15 +282,19 @@ xds_cb (vbi_xds_demux * xd, vbi_program_info *pi; _vbi_xds_packet_dump (xp, stdout); - ntsc_xds_callback(NTSC_XDS_CB_STATUS,vbi_xds_subclass_program); + ntsc_xds_callback(NTSC_XDS_CB_STATUS,1); return TRUE; /* no errors */ } static void -caption (const uint8_t buffer[2], +caption ( uint8_t buffer[2], unsigned int line) { + printf("***********caption*********bype1=%d bype2=%d\n",buffer[0],buffer[1]); + buffer[0] = vbi_unpar8 (buffer[0]); + buffer[1] = vbi_unpar8 (buffer[1]); + printf("***********caption*********modify bype1=%d bype2=%d",buffer[0],buffer[1]); if (option_decode_xds && 284 == line) { if (!vbi_xds_demux_feed (xds, buffer)) { printf ("Parity error in XDS data.\n"); @@ -298,6 +307,8 @@ caption (const uint8_t buffer[2], int c1; int c2; + //c1 = vbi_unpar8 (buffer[0]); + //c2 = vbi_unpar8 (buffer[1]); c1 = buffer[0];//vbi_unpar8 (buffer[0]); c2 = buffer[1];//vbi_unpar8 (buffer[1]); @@ -988,7 +999,26 @@ static int option_index; - + vbi_bool +decode_vbi_test (int dev_no, int fid, const uint8_t *data, int len, void *user_data){ + option_decode_xds = TRUE; + option_decode_caption = TRUE; + printf("decode_vbi len = %d\n",len); + 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,NULL); + + stream_loop (st); + stream_delete (st); + error: + return 0; + +} @@ -1010,7 +1040,7 @@ int start_demux_ntsc(){ rst = read_stream_new (pBuffer,length, option_in_file_format, option_in_ts_pid, - decode_frame); + decode_frame,NULL); stream_loop (rst); stream_delete (rst); @@ -1025,7 +1055,4 @@ int start_demux_ntsc(){ } -void decode_ntsc_xds_set_callback(NTSC_XDS_status_cb cb_ptr){ - printf("decode_ntsc_xds_set_callback"); - ntsc_xds_callback = cb_ptr; -} + diff --git a/ntsc_decode/decode.h b/ntsc_decode/decode.h index c2166b3..d7c0247 100755 --- a/ntsc_decode/decode.h +++ b/ntsc_decode/decode.h @@ -7,17 +7,29 @@ * Author: kui zhang
*
*******************************************************************/
+
+#ifndef _DECODE_H_
+#define _DECODE_H_
+
-#ifndef _TRANSFER_VOD_H_
-#define _TRANSFER_VOD_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/types.h>
-#include<unistd.h>
+#include <unistd.h>
+
+
+#include <unistd.h>
+#include "misc.h"
+#include "trigger.h"
+#include "format.h"
+#include "lang.h"
+#include "hamm.h"
+#include "tables.h"
+#include "vbi.h"
#define NTSC_XDS_CB_STATUS 0x1000
#define NTSC_XDS_CB_STATUS_STARTED 0x1001
@@ -35,6 +47,6 @@ int start_demux_ntsc(); void decode_ntsc_xds_set_callback(NTSC_XDS_status_cb cb_ptr);
+vbi_bool decode_vbi_test (int dev_no, int fid, const uint8_t *data, int len, void *user_data);
-
-
+#endif
diff --git a/ntsc_decode/ntsc_dmx/am_vbi_dmx.c b/ntsc_decode/ntsc_dmx/am_vbi_dmx.c index cd71608..713c7c0 100755 --- a/ntsc_decode/ntsc_dmx/am_vbi_dmx.c +++ b/ntsc_decode/ntsc_dmx/am_vbi_dmx.c @@ -66,7 +66,7 @@ static inline AM_ErrorCode_t dmx_get_dev(int dev_no, AM_VBI_Device_t **dev) if((dev_no<0) || (dev_no>=DMX_DEV_COUNT)) { AM_DEBUG("invalid demux device number %d, must in(%d~%d)", dev_no, 0, DMX_DEV_COUNT-1); - return AM_DMX_ERR_INVALID_DEV_NO; + return AM_VBI_DMX_ERR_INVALID_DEV_NO; } *dev = &dmx_devices[dev_no]; @@ -81,7 +81,7 @@ static inline AM_ErrorCode_t dmx_get_openned_dev(int dev_no, AM_VBI_Device_t **d if(!(*dev)->openned) { AM_DEBUG( "demux device %d has not been openned", dev_no); - return AM_DMX_ERR_INVALID_DEV_NO; + return AM_VBI_DMX_ERR_INVALID_DEV_NO; } return AM_SUCCESS; @@ -95,7 +95,7 @@ static inline AM_ErrorCode_t dmx_get_used_filter(AM_VBI_Device_t *dev, int filte if((filter_id<0) || (filter_id>=DMX_FILTER_COUNT)) { AM_DEBUG( "invalid filter id, must in %d~%d", 0, DMX_FILTER_COUNT-1); - return AM_DMX_ERR_INVALID_ID; + return AM_VBI_DMX_ERR_INVALID_ID; } filter = &dev->filters[filter_id]; @@ -103,7 +103,7 @@ static inline AM_ErrorCode_t dmx_get_used_filter(AM_VBI_Device_t *dev, int filte if(!filter->used) { AM_DEBUG( "filter %d has not been allocated", filter_id); - return AM_DMX_ERR_NOT_ALLOCATED; + return AM_VBI_DMX_ERR_NOT_ALLOCATED; } *pf = filter; @@ -114,7 +114,7 @@ static inline AM_ErrorCode_t dmx_get_used_filter(AM_VBI_Device_t *dev, int filte static void* dmx_data_thread(void *arg) { AM_VBI_Device_t *dev = (AM_VBI_Device_t*)arg; - static uint8_t sec_buf[4096]; + static uint8_t sec_buf[128]; uint8_t *sec; int sec_len; AM_VBI_FilterMask_t mask; @@ -123,9 +123,9 @@ static void* dmx_data_thread(void *arg) while(dev->enable_thread) { //**********************************temp**************** - AM_DEBUG( "***************thread count = %d\n",count); - if(count ++ == 100) - break; + AM_DEBUG( "***************!!!!thread count = %d\n",count++); + //if(count ++ == 100) + // break; //**********************************finish**************** AM_DMX_FILTER_MASK_CLEAR(&mask); int id; @@ -173,7 +173,7 @@ static void* dmx_data_thread(void *arg) #ifndef DMX_WAIT_CB pthread_mutex_unlock(&dev->lock); #endif - if(ret==AM_DMX_ERR_TIMEOUT) + if(ret==AM_VBI_DMX_ERR_TIMEOUT) { sec = NULL; sec_len = 0; @@ -208,6 +208,7 @@ static void* dmx_data_thread(void *arg) } else AM_DEBUG( "poll fail \n"); + usleep(1000 * 200); } return NULL; @@ -286,7 +287,7 @@ static int dmx_free_filter(AM_VBI_Device_t *dev, AM_VBI_Filter_t *filter) * - AM_SUCCESS 鎴愬姛 * - 鍏朵粬鍊 閿欒浠g爜(瑙乤m_dmx.h) */ -AM_ErrorCode_t AM_NTSC_DMX_Open(int dev_no, const AM_DMX_OpenPara_t *para) +AM_ErrorCode_t AM_NTSC_DMX_Open(int dev_no, const AM_VBI_DMX_OpenPara_t *para) { AM_VBI_Device_t *dev; AM_ErrorCode_t ret = AM_SUCCESS; @@ -300,7 +301,7 @@ AM_ErrorCode_t AM_NTSC_DMX_Open(int dev_no, const AM_DMX_OpenPara_t *para) if(dev->openned) { AM_DEBUG( "demux device %d has already been openned", dev_no); - ret = AM_DMX_ERR_BUSY; + ret = AM_VBI_DMX_ERR_BUSY; goto final; } @@ -322,7 +323,7 @@ AM_ErrorCode_t AM_NTSC_DMX_Open(int dev_no, const AM_DMX_OpenPara_t *para) { pthread_mutex_destroy(&dev->lock); pthread_cond_destroy(&dev->cond); - ret = AM_DMX_ERR_CANNOT_CREATE_THREAD; + ret = AM_VBI_DMX_ERR_CANNOT_CREATE_THREAD; } } @@ -404,7 +405,7 @@ AM_ErrorCode_t AM_NTSC_DMX_AllocateFilter(int dev_no, int *fhandle) if(fid>=DMX_FILTER_COUNT) { AM_DEBUG( "no free section filter"); - ret = AM_DMX_ERR_NO_FREE_FILTER; + ret = AM_VBI_DMX_ERR_NO_FREE_FILTER; } if(ret==AM_SUCCESS) @@ -559,7 +560,7 @@ AM_ErrorCode_t AM_NTSC_DMX_SetBufferSize(int dev_no, int fhandle, int size) if(!dev->drv->set_buf_size) { AM_DEBUG( "do not support set_buf_size"); - ret = AM_DMX_ERR_NOT_SUPPORTED; + ret = AM_VBI_DMX_ERR_NOT_SUPPORTED; } if(ret==AM_SUCCESS) @@ -662,7 +663,7 @@ AM_ErrorCode_t AM_NTSC_DMX_SetSource(int dev_no, AM_VBI_DMX_Source_t src) if(!dev->drv->set_source) { AM_DEBUG( "do not support set_source"); - ret = AM_DMX_ERR_NOT_SUPPORTED; + ret = AM_VBI_DMX_ERR_NOT_SUPPORTED; } if(ret==AM_SUCCESS) diff --git a/ntsc_decode/ntsc_dmx/am_vbi_internal.h b/ntsc_decode/ntsc_dmx/am_vbi_internal.h index 9656373..398d2d4 100755 --- a/ntsc_decode/ntsc_dmx/am_vbi_internal.h +++ b/ntsc_decode/ntsc_dmx/am_vbi_internal.h @@ -28,6 +28,7 @@ #endif +typedef int vbi_bool; /**************************************************************************** * Macro definitions ***************************************************************************/ @@ -59,7 +60,7 @@ typedef uint32_t AM_VBI_FilterMask_t; /**\brief 瑙e鐢ㄨ澶囬┍鍔*/ typedef struct { - AM_ErrorCode_t (*open)(AM_VBI_Device_t *dev, const AM_DMX_OpenPara_t *para); + AM_ErrorCode_t (*open)(AM_VBI_Device_t *dev, const AM_VBI_DMX_OpenPara_t *para); AM_ErrorCode_t (*close)(AM_VBI_Device_t *dev); AM_ErrorCode_t (*alloc_filter)(AM_VBI_Device_t *dev, AM_VBI_Filter_t *filter); AM_ErrorCode_t (*free_filter)(AM_VBI_Device_t *dev, AM_VBI_Filter_t *filter); diff --git a/ntsc_decode/ntsc_dmx/include/vbi_dmx.h b/ntsc_decode/ntsc_dmx/include/vbi_dmx.h index ff04cd1..36abfb5 100755 --- a/ntsc_decode/ntsc_dmx/include/vbi_dmx.h +++ b/ntsc_decode/ntsc_dmx/include/vbi_dmx.h @@ -30,7 +30,7 @@ #include <sys/mman.h> #include <sched.h> #include <signal.h> - +#include <android/log.h> #ifdef __cplusplus extern "C" @@ -48,20 +48,20 @@ extern "C" /**\brief 瑙e鐢ㄦā鍧楅敊璇唬鐮*/ enum AM_VBI_ErrorCode { - AM_DMX_ERROR_BASE, - AM_DMX_ERR_INVALID_DEV_NO, /**< 璁惧鍙锋棤鏁*/ - AM_DMX_ERR_INVALID_ID, /**< 杩囨护鍣↖D鏃犳晥*/ - AM_DMX_ERR_BUSY, /**< 璁惧宸茬粡琚墦寮*/ - AM_DMX_ERR_NOT_ALLOCATED, /**< 璁惧娌℃湁鍒嗛厤*/ - AM_DMX_ERR_CANNOT_CREATE_THREAD, /**< 鏃犳硶鍒涘缓绾跨▼*/ - AM_DMX_ERR_CANNOT_OPEN_DEV, /**< 鏃犳硶鎵撳紑璁惧*/ - AM_DMX_ERR_NOT_SUPPORTED, /**< 涓嶆敮鎸佺殑鎿嶄綔*/ - AM_DMX_ERR_NO_FREE_FILTER, /**< 娌℃湁绌洪棽鐨剆ection杩囨护鍣*/ - AM_DMX_ERR_NO_MEM, /**< 绌洪棽鍐呭瓨涓嶈冻*/ - AM_DMX_ERR_TIMEOUT, /**< 绛夊緟璁惧鏁版嵁瓒呮椂*/ - AM_DMX_ERR_SYS, /**< 绯荤粺鎿嶄綔閿欒*/ - AM_DMX_ERR_NO_DATA, /**< 娌℃湁鏀跺埌鏁版嵁*/ - AM_DMX_ERR_END + AM_VBI_DMX_ERROR_BASE = 0, + AM_VBI_DMX_ERR_INVALID_DEV_NO, /**< 璁惧鍙锋棤鏁*/ + AM_VBI_DMX_ERR_INVALID_ID, /**< 杩囨护鍣↖D鏃犳晥*/ + AM_VBI_DMX_ERR_BUSY, /**< 璁惧宸茬粡琚墦寮*/ + AM_VBI_DMX_ERR_NOT_ALLOCATED, /**< 璁惧娌℃湁鍒嗛厤*/ + AM_VBI_DMX_ERR_CANNOT_CREATE_THREAD, /**< 鏃犳硶鍒涘缓绾跨▼*/ + AM_VBI_DMX_ERR_CANNOT_OPEN_DEV, /**< 鏃犳硶鎵撳紑璁惧*/ + AM_VBI_DMX_ERR_NOT_SUPPORTED, /**< 涓嶆敮鎸佺殑鎿嶄綔*/ + AM_VBI_DMX_ERR_NO_FREE_FILTER, /**< 娌℃湁绌洪棽鐨剆ection杩囨护鍣*/ + AM_VBI_DMX_ERR_NO_MEM, /**< 绌洪棽鍐呭瓨涓嶈冻*/ + AM_VBI_DMX_ERR_TIMEOUT, /**< 绛夊緟璁惧鏁版嵁瓒呮椂*/ + AM_VBI_DMX_ERR_SYS, /**< 绯荤粺鎿嶄綔閿欒*/ + AM_VBI_DMX_ERR_NO_DATA, /**< 娌℃湁鏀跺埌鏁版嵁*/ + AM_VBI_DMX_ERR_END }; #define VBI_IOC_MAGIC 'X' @@ -91,9 +91,19 @@ enum AM_VBI_ErrorCode #define AM_FALSE (0) #endif -#define AM_DEBUG printf -typedef int vbi_bool; +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "VBI_DEMUX" +#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 AM_DEBUG printf +#define AM_DEBUG LOGI + typedef int AM_ErrorCode_t; @@ -113,7 +123,7 @@ typedef enum typedef struct { int foo; -} AM_DMX_OpenPara_t; +} AM_VBI_DMX_OpenPara_t; /**\brief 鏁版嵁鍥炶皟鍑芥暟 * data涓烘暟鎹紦鍐插尯鎸囬拡锛宭en涓烘暟鎹暱搴︺傚鏋渄ata==NULL琛ㄧずdemux鎺ユ敹鏁版嵁瓒呮椂銆 @@ -131,7 +141,7 @@ typedef void (*AM_DMX_DataCb) (int dev_no, int fhandle, const uint8_t *data, int * - AM_SUCCESS 鎴愬姛 * - 鍏朵粬鍊 閿欒浠g爜(瑙乤m_dmx.h) */ -extern AM_ErrorCode_t AM_DMX_Open(int dev_no, const AM_DMX_OpenPara_t *para); +extern AM_ErrorCode_t AM_NTSC_DMX_Open(int dev_no, const AM_VBI_DMX_OpenPara_t *para); /**\brief 鍏抽棴瑙e鐢ㄨ澶 * \param dev_no 瑙e鐢ㄨ澶囧彿 @@ -139,7 +149,7 @@ extern AM_ErrorCode_t AM_DMX_Open(int dev_no, const AM_DMX_OpenPara_t *para); * - AM_SUCCESS 鎴愬姛 * - 鍏朵粬鍊 閿欒浠g爜(瑙乤m_dmx.h) */ -extern AM_ErrorCode_t AM_DMX_Close(int dev_no); +extern AM_ErrorCode_t AM_NTSC_DMX_Close(int dev_no); /**\brief 鍒嗛厤涓涓繃婊ゅ櫒 * \param dev_no 瑙e鐢ㄨ澶囧彿 @@ -148,7 +158,7 @@ extern AM_ErrorCode_t AM_DMX_Close(int dev_no); * - AM_SUCCESS 鎴愬姛 * - 鍏朵粬鍊 閿欒浠g爜(瑙乤m_dmx.h) */ -//extern AM_ErrorCode_t AM_DMX_AllocateFilter(int dev_no, int *fhandle); +extern AM_ErrorCode_t AM_NTSC_DMX_AllocateFilter(int dev_no, int *fhandle); /**\brief 璁惧畾Section杩囨护鍣 * \param dev_no 瑙e鐢ㄨ澶囧彿 @@ -185,7 +195,7 @@ extern AM_ErrorCode_t AM_DMX_Close(int dev_no); * - AM_SUCCESS 鎴愬姛 * - 鍏朵粬鍊 閿欒浠g爜(瑙乤m_dmx.h) */ -//extern AM_ErrorCode_t AM_DMX_StartFilter(int dev_no, int fhandle); +extern AM_ErrorCode_t AM_NTSC_DMX_StartFilter(int dev_no, int fhandle); /**\brief 鍋滄涓涓繃婊ゅ櫒 * \param dev_no 瑙e鐢ㄨ澶囧彿 @@ -204,7 +214,7 @@ extern AM_ErrorCode_t AM_DMX_Close(int dev_no); * - AM_SUCCESS 鎴愬姛 * - 鍏朵粬鍊 閿欒浠g爜(瑙乤m_dmx.h) */ -extern AM_ErrorCode_t AM_DMX_SetBufferSize(int dev_no, int fhandle, int size); +extern AM_ErrorCode_t AM_NTSC_DMX_SetBufferSize(int dev_no, int fhandle, int size); /**\brief 鍙栧緱涓涓繃婊ゅ櫒瀵瑰簲鐨勫洖璋冨嚱鏁板拰鐢ㄦ埛鍙傛暟 * \param dev_no 瑙e鐢ㄨ澶囧彿 @@ -226,7 +236,7 @@ extern AM_ErrorCode_t AM_DMX_SetBufferSize(int dev_no, int fhandle, int size); * - AM_SUCCESS 鎴愬姛 * - 鍏朵粬鍊 閿欒浠g爜(瑙乤m_dmx.h) */ -//extern AM_ErrorCode_t AM_DMX_SetCallback(int dev_no, int fhandle, AM_DMX_DataCb cb, void *data); +extern AM_ErrorCode_t AM_NTSC_DMX_SetCallback(int dev_no, int fhandle, AM_DMX_DataCb cb, void *data); /**\brief 璁剧疆瑙e鐢ㄨ澶囩殑杈撳叆婧 * \param dev_no 瑙e鐢ㄨ澶囧彿 diff --git a/ntsc_decode/ntsc_dmx/linux_vbi/linux_ntsc.c b/ntsc_decode/ntsc_dmx/linux_vbi/linux_ntsc.c index b132ad8..0791ac1 100755 --- a/ntsc_decode/ntsc_dmx/linux_vbi/linux_ntsc.c +++ b/ntsc_decode/ntsc_dmx/linux_vbi/linux_ntsc.c @@ -36,7 +36,7 @@ typedef struct * Static data definitions ***************************************************************************/ -static AM_ErrorCode_t vbi_open(AM_VBI_Device_t *dev, const AM_DMX_OpenPara_t *para); +static AM_ErrorCode_t vbi_open(AM_VBI_Device_t *dev, const AM_VBI_DMX_OpenPara_t *para); static AM_ErrorCode_t vbi_close(AM_VBI_Device_t *dev); static AM_ErrorCode_t vbi_alloc_filter(AM_VBI_Device_t *dev, AM_VBI_Filter_t *filter); static AM_ErrorCode_t vbi_free_filter(AM_VBI_Device_t *dev, AM_VBI_Filter_t *filter); @@ -67,7 +67,7 @@ const AM_VBI_Driver_t linux_vbi_drv = { * Static functions ***************************************************************************/ -static AM_ErrorCode_t vbi_open(AM_VBI_Device_t *dev, const AM_DMX_OpenPara_t *para) +static AM_ErrorCode_t vbi_open(AM_VBI_Device_t *dev, const AM_VBI_DMX_OpenPara_t *para) { VbiDmx_t *dmx; int i; @@ -76,7 +76,7 @@ static AM_ErrorCode_t vbi_open(AM_VBI_Device_t *dev, const AM_DMX_OpenPara_t *pa if(!dmx) { AM_DEBUG( "not enough memory"); - return AM_DMX_ERR_NO_MEM; + return AM_VBI_DMX_ERR_NO_MEM; } //snprintf(dmx->dev_name, sizeof(dmx->dev_name), "/dev/vbi", dev->dev_no); @@ -103,11 +103,11 @@ static AM_ErrorCode_t vbi_alloc_filter(AM_VBI_Device_t *dev, AM_VBI_Filter_t *fi VbiDmx_t *dmx = (VbiDmx_t*)dev->drv_data; int fd; - fd = open(dmx->dev_name, O_RDWR|O_NONBLOCK); + fd = open(dmx->dev_name, O_RDWR|O_NONBLOCK);//fd = open(dmx->dev_name, O_RDWR|O_NONBLOCK); if(fd==-1) { AM_DEBUG("cannot open \"%s\" (%s)", dmx->dev_name, strerror(errno)); - return AM_DMX_ERR_CANNOT_OPEN_DEV; + return AM_VBI_DMX_ERR_CANNOT_OPEN_DEV; }else AM_DEBUG("can open fd=%d\n",fd); @@ -173,7 +173,7 @@ static AM_ErrorCode_t vbi_enable_filter(AM_VBI_Device_t *dev, AM_VBI_Filter_t *f if(ret==-1) { AM_DEBUG( "start filter failed (%s)", strerror(errno)); - return AM_DMX_ERR_SYS; + return AM_VBI_DMX_ERR_SYS; } return AM_SUCCESS; @@ -192,7 +192,7 @@ static AM_ErrorCode_t vbi_set_buf_size(AM_VBI_Device_t *dev, AM_VBI_Filter_t *fi //if(ret==-1) //{ // AM_DEBUG( "set buffer size failed (%s)", strerror(errno)); - // return AM_DMX_ERR_SYS; + // return AM_VBI_DMX_ERR_SYS; //} //**************************temp****************************/// @@ -200,7 +200,7 @@ static AM_ErrorCode_t vbi_set_buf_size(AM_VBI_Device_t *dev, AM_VBI_Filter_t *fi if(ret==-1) { AM_DEBUG( "set buffer size failed (%s)", strerror(errno)); - return AM_DMX_ERR_SYS; + return AM_VBI_DMX_ERR_SYS; } int cc_type = 1; @@ -208,7 +208,7 @@ static AM_ErrorCode_t vbi_set_buf_size(AM_VBI_Device_t *dev, AM_VBI_Filter_t *fi if(ret==-1) { AM_DEBUG( "set buffer size failed (%s)", strerror(errno)); - return AM_DMX_ERR_SYS; + return AM_VBI_DMX_ERR_SYS; } //**************************finish****************************/// @@ -236,14 +236,14 @@ static AM_ErrorCode_t vbi_poll(AM_VBI_Device_t *dev, AM_VBI_FilterMask_t *mask, } if(!cnt) - return AM_DMX_ERR_TIMEOUT; + return AM_VBI_DMX_ERR_TIMEOUT; AM_DEBUG("vbi_poll *********poll cnt = %d fds[0].fd =%d \n",cnt,fds[0].fd); ret = poll(fds, cnt, timeout); if(ret<=0) { - AM_DEBUG("vbi_poll *********AM_DMX_ERR_TIMEOUT \n"); - return AM_DMX_ERR_TIMEOUT; + AM_DEBUG("vbi_poll *********AM_VBI_DMX_ERR_TIMEOUT \n"); + return AM_VBI_DMX_ERR_TIMEOUT; } for(i=0; i<cnt; i++) @@ -265,24 +265,29 @@ static AM_ErrorCode_t vbi_read(AM_VBI_Device_t *dev, AM_VBI_Filter_t *filter, ui struct pollfd pfd; if(fd==-1) - return AM_DMX_ERR_NOT_ALLOCATED; + return AM_VBI_DMX_ERR_NOT_ALLOCATED; pfd.events = POLLIN|POLLERR; pfd.fd = fd; - printf("vbi_read******************pfd.fd = %d \n",pfd.fd); + AM_DEBUG("vbi_read******************pfd.fd = %d \n",pfd.fd); ret = poll(&pfd, 1, 0); - if(ret<=0) - return AM_DMX_ERR_NO_DATA; - + if(ret<=0){ + return AM_VBI_DMX_ERR_NO_DATA; + AM_DEBUG( "vbi_read************AM_VBI_DMX_ERR_NO_DATA\n"); + } + ret = read(fd, buf, len); if(ret<=0) { if(errno==ETIMEDOUT) - return AM_DMX_ERR_TIMEOUT; - AM_DEBUG( "read demux failed (%s) %d", strerror(errno), errno); - return AM_DMX_ERR_SYS; - } - + return AM_VBI_DMX_ERR_TIMEOUT; + AM_DEBUG( "read demux failed (%s) %d\n", strerror(errno), errno); + return AM_VBI_DMX_ERR_SYS; + }else + AM_DEBUG("vbi_read************read result = %d\n",ret); + + AM_DEBUG("buf[0] =%d, buf[1] =%d, buf[2] =%d, buf[3] =%d, buf[4] =%d,buf[5] =%d, buf[6] =%d, buf[7] =%d \n", + buf[0], buf[1], buf[2], buf[3], buf[4],buf[5], buf[6], buf[7]); *size = ret; return AM_SUCCESS; } @@ -304,6 +309,6 @@ static AM_ErrorCode_t vbi_set_source(AM_VBI_Device_t *dev, AM_VBI_DMX_Source_t s break; } -return AM_DMX_ERR_CANNOT_OPEN_DEV; +return AM_VBI_DMX_ERR_CANNOT_OPEN_DEV; } diff --git a/ntsc_decode/ntsc_dmx/test/Android.mk b/ntsc_decode/ntsc_dmx/test/Android.mk index 938aa40..024b30c 100755 --- a/ntsc_decode/ntsc_dmx/test/Android.mk +++ b/ntsc_decode/ntsc_dmx/test/Android.mk @@ -7,6 +7,7 @@ LOCAL_SHARED_LIBRARIES+= libzvbi libntsc_decode LOCAL_C_INCLUDES:=$(LOCAL_PATH)/../../../src \ $(LOCAL_PATH)/../ \ + $(LOCAL_PATH)/../../ \ $(LOCAL_PATH)/../include LOCAL_MODULE:= vbi_test diff --git a/ntsc_decode/ntsc_dmx/test/vbi_test.c b/ntsc_decode/ntsc_dmx/test/vbi_test.c index 95353a0..defa96a 100755 --- a/ntsc_decode/ntsc_dmx/test/vbi_test.c +++ b/ntsc_decode/ntsc_dmx/test/vbi_test.c @@ -13,7 +13,7 @@ #include <signal.h> #include <stdio.h> #include <vbi_dmx.h> - +#include <decode.h> #define VBI_IOC_MAGIC 'X' @@ -186,11 +186,14 @@ int main(int argc, char *argv[]) } static void dump_bytes(int dev_no, int fid, const uint8_t *data, int len, void *user_data){ - printf("dump_bytes"); + printf("dump_bytes len = %d\n",len); + decode_vbi_test( dev_no, fid, data, len, user_data); } + + void demux_vbi_start(){ int fid; - AM_DMX_OpenPara_t para; + AM_VBI_DMX_OpenPara_t para; memset(¶, 0, sizeof(para)); printf("*******************************\n\n"); if( AM_NTSC_DMX_Open(VBI_DEV_NO, ¶) != AM_SUCCESS) { diff --git a/ntsc_decode/sliced1.c b/ntsc_decode/sliced1.c index 25c234a..62e684a 100755 --- a/ntsc_decode/sliced1.c +++ b/ntsc_decode/sliced1.c @@ -125,6 +125,7 @@ struct stream { int fd; vbi_bool close_fd; + void *userdata ; }; #ifndef HAVE_PROGRAM_INVOCATION_NAME @@ -847,7 +848,7 @@ read_loop_pes_ts (struct stream * st) if (!st->callback (st->sliced, n_lines, /* raw */ NULL, /* sp */ NULL, - sample_time, pts)) + sample_time, pts,NULL)) return FALSE; } @@ -1120,7 +1121,7 @@ read_loop_old_sliced (struct stream * st) case 0: s->id = VBI_SLICED_CAPTION_525; next_block (st, s->data, 2); - + printf(" s->data[0] =%d ,s->data[1] = %d \n",s->data[0],s->data[1]); break; case 1: @@ -1171,14 +1172,16 @@ read_loop_old_sliced (struct stream * st) st->sliced2_lines, raw, &sp, st->sample_time, - st->stream_time); + st->stream_time, + st->userdata); } else { printf("st->raw_valid && st->decode_raw isnot true\n"); - + success = st->callback (st->sliced, n_lines, raw, &sp, st->sample_time, - st->stream_time); + st->stream_time, + st->userdata); } free (raw); @@ -1297,7 +1300,8 @@ read_stream_new (const char * fbuffer, int length, enum file_format file_format, unsigned int ts_pid, - stream_callback_fn * callback) + stream_callback_fn * callback , + void *userdata) { struct stream *st; @@ -1370,12 +1374,14 @@ read_stream_new (const char * fbuffer, st->bp = st->buffer; st->end = st->buffer; + printf("finish read_stream_new" ); //***************************************add buffer********* memset (st->buffer, 0,sizeof (st->buffer)); memcpy (st->buffer,fbuffer, length); st->end = st->buffer + length; + st->userdata = userdata; //printf("st->bp,st->end,length === %d %d %d",st->bp,st->end,length ); //***************************************finish********* return st; @@ -1449,7 +1455,7 @@ capture_loop (struct stream * st) } if (!st->callback (sliced, n_lines, raw, &st->sp, - sample_time, stream_time)) + sample_time, stream_time,NULL)) return FALSE; } diff --git a/ntsc_decode/sliced1.h b/ntsc_decode/sliced1.h index 6901277..1b884fd 100755 --- a/ntsc_decode/sliced1.h +++ b/ntsc_decode/sliced1.h @@ -68,7 +68,8 @@ stream_callback_fn (const vbi_sliced * sliced, const uint8_t * raw, const vbi_sampling_par *sp, double sample_time, - int64_t stream_time); + int64_t stream_time, + void *user_data); struct stream; @@ -136,7 +137,8 @@ extern struct stream * read_stream_new (const char * pbuffer,int length, enum file_format file_format, unsigned int ts_pid, - stream_callback_fn * callback); + stream_callback_fn * callback, + void *userdata); #if 2 == VBI_VERSION_MINOR diff --git a/ntsc_decode/test/caption.c b/ntsc_decode/test/caption.c index def1f99..323839e 100755 --- a/ntsc_decode/test/caption.c +++ b/ntsc_decode/test/caption.c @@ -909,7 +909,7 @@ main (int argc, st = read_stream_new (pBuffer,length, FILE_FORMAT_SLICED, 0, - decode_frame); + decode_frame,NULL); //st = read_stream_new (/* filename: stdin */ NULL, // FILE_FORMAT_SLICED, diff --git a/ntsc_decode/test/decode.c b/ntsc_decode/test/decode.c index 7cfff30..adb699f 100755 --- a/ntsc_decode/test/decode.c +++ b/ntsc_decode/test/decode.c @@ -1392,7 +1392,7 @@ main (int argc, rst = read_stream_new (pBuffer,length, option_in_file_format, option_in_ts_pid, - decode_frame); + decode_frame,NULL); printf("stream_loop\n"); stream_loop (rst); diff --git a/src/caption.c b/src/caption.c index 5aaba2d..804c0f9 100644..100755 --- a/src/caption.c +++ b/src/caption.c @@ -38,7 +38,7 @@ #define elements(array) (sizeof(array) / sizeof(array[0])) #define ITV_DEBUG(x) /* x */ -#define XDS_SEP_DEBUG(x) /* x */ +#define XDS_SEP_DEBUG(x) /* x */ x #define XDS_SEP_DUMP(x) /* x */ #define CC_DUMP(x) /* x */ #define CC_TEXT_DUMP(x) /* x */ @@ -147,6 +147,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)); vbi_network *n = &vbi->network.ev.network; vbi_program_info *pi; int neq, i; @@ -162,9 +163,10 @@ xds_decoder(vbi_decoder *vbi, int _class, int type, switch (_class) { case XDS_CURRENT: /* 0 */ case XDS_FUTURE: /* 1 */ - if (!(vbi->event_mask & (VBI_EVENT_ASPECT | VBI_EVENT_PROG_INFO))) + 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")); return; - + } pi = &vbi->prog_info[_class]; neq = 0; @@ -288,7 +290,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)); if (buffer[0] & 0x20) dlsv |= VBI_RATING_D; if (buffer[1] & 0x08) @@ -324,6 +326,13 @@ xds_decoder(vbi_decoder *vbi, int _class, int type, pi->rating_id = r; pi->rating_dlsv = dlsv; } + + //***************************************zk + //callback + e.type = VBI_EVENT_PROG_INFO; + e.ev.prog_info = pi; + caption_send_event(vbi, &e); + //*******************************************finish break; } @@ -470,16 +479,17 @@ xds_decoder(vbi_decoder *vbi, int _class, int type, printf("[type %d cycle %08x class %d neq %d]\n", type, vbi->cc.info_cycle[_class], _class, neq); - if (neq) /* first occurence of this type with this data */ + if (neq){ /* first occurence of this type with this data */ vbi->cc.info_cycle[_class] |= 1 << type; + } else if (vbi->cc.info_cycle[_class] & (1 << type)) { /* Second occurance of this type with same data */ - + e.type = VBI_EVENT_PROG_INFO; e.ev.prog_info = pi; caption_send_event(vbi, &e); - + XDS_SEP_DEBUG(printf("caption_send_event VBI_EVENT_PROG_INFO\n")); vbi->cc.info_cycle[_class] = 0; /* all changes reported */ } @@ -646,7 +656,7 @@ xds_separator(vbi_decoder *vbi, uint8_t *buf) XDS_SEP_DUMP( for (i = 0; i < sp->count - 2; i++) - printf("%c", _vbi_to_ascii (sp->buffer[i])); + printf("%c", (sp->buffer[i])); //printf("%c", _vbi_to_ascii (sp->buffer[i])); printf(" %d/0x%02x\n", class, type); ) } @@ -895,6 +905,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")); cc_channel *ch; int chan, col, i; int last_row; @@ -984,7 +995,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)); put_char(cc, ch, c); } } else { /* Midrow Codes 001 c001 010 xxxu */ @@ -1236,6 +1247,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")); struct caption *cc = &vbi->cc; char c1 = buf[0] & 0x7F; int field2 = 1, i; @@ -1258,7 +1270,7 @@ vbi_decode_caption(vbi_decoder *vbi, int line, uint8_t *buf) fflush(stdout); ) - if (vbi_unpar8 (buf[0]) >= 0) { + if (vbi_unpar8 (buf[0]) >= 0) { //vbi_unpar8 (buf[0]) >= 0 if (c1 == 0) { goto finish; } else if (c1 <= 0x0F) { @@ -1282,7 +1294,8 @@ vbi_decode_caption(vbi_decoder *vbi, int line, uint8_t *buf) goto finish; } - if (vbi_unpar8 (buf[0]) < 0) { + //if ( (buf[0]) < 0) { //vbi_unpar8 (buf[0]) < 0 + if ( vbi_unpar8 (buf[0]) < 0) { // c1 = 127; buf[0] = c1; /* traditional 'bad' glyph, ccfont has */ buf[1] = c1; /* room, design a special glyph? */ @@ -1304,7 +1317,8 @@ vbi_decode_caption(vbi_decoder *vbi, int line, uint8_t *buf) break; /* XDS field 1?? */ case 0x10 ... 0x1F: - if (vbi_unpar8 (buf[1]) >= 0) { + //if ( (buf[1]) >= 0) { // vbi_unpar8 (buf[1]) + if ( vbi_unpar8 (buf[1]) >= 0) { if (!field2 && buf[0] == cc->last[0] && buf[1] == cc->last[1]) { @@ -1356,8 +1370,8 @@ vbi_decode_caption(vbi_decoder *vbi, int line, uint8_t *buf) c = ch->attr; for (i = 0; i < 2; i++) { - char ci = vbi_unpar8 (buf[i]) & 0x7F; /* 127 if bad */ - + //char ci = (buf[i]) & 0x7F; /* 127 if bad */ //vbi_unpar8 (buf[i]) + char ci = vbi_unpar8 (buf[i]) & 0x7F; /* 127 if bad */ if (ci <= 0x1F) /* 0x00 no char, 0x01 ... 0x1F invalid */ continue; |