source: svn/newcon3bcm2_21bu/dst/dmw/src/cc/cc_ddi_lg2500.c

Last change on this file was 76, checked in by megakiss, 10 years ago

1W 대기전력을 만족시키기 위하여 POWEROFF시 튜너를 Standby 상태로 함

  • Property svn:executable set to *
File size: 11.9 KB
Line 
1
2#include "DHL_DBG.h"
3#include "DHL_OSAL.h"
4#include "DHL_OSAL_Config.h"
5
6#include "cc_config.h"
7#include "cc_def.h"
8#include "cc_private.h"
9
10#include "DMW_Dummy.h"
11
12#include <stdarg.h> /* for va_list */
13//#include <string.h>
14
15#define MAX_NUM_PIC_UD_Q CC_NUM_PIC_USER_Q
16
17#define IS_FONT_BMF (FONT_ID==FONT_BMF)
18
19static tDCC_PicUDRaw p_ud_buf[MAX_NUM_PIC_UD_Q];
20
21// zooyouny: »ç¿ëµÇ´Â °÷ ¾øÀ½
22// static tDCCDDI_MSGQ p_ud_msgq;
23static int p_ud_buf_wr_idx=0;
24static tDCC_UserCallback p_ud_callback = NULL;
25
26#include "DHL_Graphic.h"
27#include "DHL_AVCAP.h"
28//#include "DHL_AVCAP_Priv.h"
29#include "DMG_Draw.h"
30
31#if IS_FONT_JUNGLE
32//.#include "utfAPI.h"
33#elif IS_FONT_MLF
34#include "MLSupport.h"
35#elif IS_FONT_BMF
36#include "BMF.h"
37#endif
38
39
40#if 0
41__Local_Func__() {}
42#endif
43
44
45static void p_check_region(int x, int y, int w, int h)
46{
47        BOOL bvalid=((x>=0) && (y>=0) && (x+w<720) && (y+h<480));
48       
49        if(!bvalid) 
50                CCPRINT("error", "! fatal error : region(%d,%d,%d,%d)\n", x, y, w, h);
51        //DHL_ASSERT(bvalid, "!! FATAL ERROR : CC check region failed\n");
52}
53
54
55
56static UINT16 p_remap_char(UINT16 ch)
57{
58#if FONT_ID==FONT_BMF
59        struct {
60                UINT16 orig;
61                UINT16 dst;
62        } table[]={
63                {0x520, 0x20},{0x521, 0x20},{0x522, 0x20},{0x525, 0x2026},
64                {0x52a, 0x0160},{0x52c, 0x0152},{0x530, 0xb7},{0x531, 0x2018},
65                {0x532, 0x2019},{0x533, 0x201c},{0x534, 0x201d},{0x535, 0x2022},
66                {0x539, 0x2122},{0x53a, 0x0161},{0x53c, 0x0153},{0x53d, 0x2120},
67                {0x53f, 0x0178},{0x576, 0x215b},{0x577, 0x215c},{0x578, 0x215d},
68                {0x579, 0x215e},{0x57a, 0x2503},{0x57b, 0x2512},{0x57c, 0x2517},
69                {0x57d, 0x2501},{0x57e, 0x251b},{0x57f, 0x250f},{0x5ff, 0x266a},
70                {0x5a0, 0x1a0}
71        };
72       
73        int i;
74       
75        for(i=0; i<sizeof(table)/sizeof(table[0]); i++) {
76                if(ch==table[i].orig) return table[i].dst;
77        }
78       
79        return ch;
80
81#elif FONT_ID==FONT_JUNGLE
82        //0x5xx´ë¸¦ 0x1xx´ë·Î ¿Å±è
83        if((ch&0x500)==0x500)
84                return ch&(~0x400);
85        else
86                return ch;
87
88#endif
89}
90
91//static FILE *p_fd;
92
93
94void *DCCDDI_Malloc(int size)
95{
96        return DHL_OS_Malloc(size);
97}
98
99
100void DCCDDI_Printf(const char *fmt, ...)
101{
102        char buf[512];
103        va_list v;
104
105        va_start(v, fmt);
106
107        vsnprintf(buf, 512, fmt, v);
108
109        va_end(v);
110
111        DHL_OS_Printf("%s", buf);
112}
113
114
115
116void DCCDDI_SpawnTask(void *func)
117{
118        DHL_OS_CreateTask((DHL_OS_TASKFUNCTION)func, "CC", TASK_PRI_DCC_DMX, 16384, 0);
119}
120
121
122tDCCDDI_MSGQ DCCDDI_CreateMessageQueue(char *pname, UINT32 num_msgq, UINT32 size_msgq)
123{
124        return (tDCCDDI_MSGQ)DHL_OS_CreateMessageQueue(pname, 0, num_msgq, size_msgq);
125}
126
127
128tDCCDDI_SEM DCCDDI_CreateMutexSemaphore(char *pname)
129{
130        return (tDCCDDI_SEM)DHL_OS_CreateMutexSemaphore(pname);
131}
132
133
134tDCCDDI_SEM DCCDDI_CreateBinarySemaphore(char *pname)
135{
136        return (tDCCDDI_SEM)DHL_OS_CreateBinarySemaphore(pname, 0, 0);
137}
138
139
140void DCCDDI_SendMessage(tDCCDDI_MSGQ id, void *buf, UINT32 len)
141{
142        DHL_OS_SendMessage((DHL_OS_MSGQ_ID)id, buf);
143}
144
145
146int DCCDDI_ReceiveMessage(tDCCDDI_MSGQ id, void *buf, UINT32 max_len, int *rcv_len)
147{
148        return DHL_OS_ReceiveMessage((DHL_OS_MSGQ_ID)id, buf, DHL_TIMEOUT_FOREVER);
149}
150
151
152int DCCDDI_ReceiveMessage_Wait(tDCCDDI_MSGQ id, void *buf, UINT32 max_len, int *rcv_len, UINT32 msec)
153{
154        return DHL_OS_ReceiveMessage((DHL_OS_MSGQ_ID)id, buf, msec);
155}
156
157int DCCDDI_ReceiveMessage_NoWait(tDCCDDI_MSGQ id, void *buf, UINT32 max_len, int *rcv_len)
158{
159        return DHL_OS_ReceiveMessage((DHL_OS_MSGQ_ID)id, buf, 0);
160}
161
162
163void DCCDDI_TakeSemaphore(tDCCDDI_SEM id)
164{
165        DHL_OS_TakeSemaphore((DHL_OS_SEMA_ID)id, DHL_TIMEOUT_FOREVER);
166}
167
168void DCCDDI_GiveSemaphore(tDCCDDI_SEM id)
169{
170        DHL_OS_GiveSemaphore((DHL_OS_SEMA_ID)id);
171}
172
173void DCCDDI_Delay(UINT32 msec)
174{
175        DHL_OS_Delay(msec);
176}
177
178UINT32 DCCDDI_GetCurMs()
179{
180        return DHL_OS_GetMsCount();
181}
182
183
184#if 0
185__Picture_User_Data__() {}
186#endif
187
188static BOOL p_check_cc_validity(UINT8 *buf, int *psize, int *ofs)
189{
190        int i;
191        BOOL batsc=FALSE;
192        BOOL bscte=FALSE;
193        int size=*psize;
194       
195        //atsc identifier ȤÀº scte20ÀÇ 03ÀÌ ¿Í¾ßÇϴµ¥, ±×·¸Áö ¾ÊÀº °æ¿ìµµ ÀÖÀ½
196        //±×·¸Áö ¾ÊÀº °æ¿ì¶ó¸é user_data_start_code¸¦ °Ë»öÇØºÁ¾ß ÇÔ(0x000001b2)
197        //atsc id
198       
199        for(i=0, *ofs=0; i<size-4; i++) {
200                if(buf[i]==0x47 && buf[i+1]==0x41 && buf[i+2]==0x39 && buf[i+3]==0x34) {
201                        batsc=TRUE;
202                        *ofs=i;
203                        size-=i;
204                        break;
205                }
206
207#if 0   //¾Æ·¡ ÄÚµå´Â ÀÇ¹Ì ¾ø´Â ÄÚµåÀÓ..¿ÀÈ÷·Á ºÎÀÛ¿ëÀ» ÀÏÀ¸Å³ ¼ö ÀÖÀ¸¹Ç·Î
208                        //¿¹¸¦ µé¾î 0x000001b2 ´ÙÀ½¿¡ ¹Ù·Î 0x47413934°¡ ¿À´Â °Ô ¾Æ´Ï¶ó
209                        //Áß°£¿¡ ´Ù¸¥ ÄÚµå °ªÀÌ ¿Ã ¼ö ÀÖÀ½.
210                if(i<size-8 && buf[i]==0x0 && buf[i+1]==0x0 && buf[i+2]==0x1 && buf[i+3]==0xb2) {
211                       
212                        if(buf[i+4]==0x47 && buf[i+5]==0x41 && buf[i+6]==0x39 && buf[i+7]==0x34)
213                                batsc=TRUE;
214                        else
215                                bscte=TRUE;
216                        *ofs=i+4;
217                        size-=i+4;
218                        break;
219                }
220#endif
221        }
222       
223        if(!batsc && !bscte && buf[0]==0x3) bscte=TRUE; //¹Ù·Î 0x3ºÎÅÍ ³¯¶ó¿È.
224       
225        if(!batsc && !bscte) {
226                CCPRINT("ddi", "bad cc data\n");
227                return FALSE;
228        }
229       
230        if(size<5+2+(buf[*ofs+5]&0x1f)*3) { //size°¡ ½ÇÁ¦ CC dataº¸´Ù ÀÛÀ¸¸é ¿¡·¯ÀÓ.
231                CCPRINT("ddi", "cc data size is not enough(%d)\n", size);
232                return FALSE;
233        }
234       
235        *psize=5+2+(buf[*ofs+5]&0x1f)*3; //½ÇÁ¦ ó¸®ÇÒ sizeÀÓ.
236
237        return TRUE;
238}
239
240
241static void p_user_data(tDHL_AVCallbackType cb_type, UINT32 param)
242{
243        static UINT32 count=0;
244        static BOOL bprev_valid=FALSE;
245        BOOL bcur_valid;
246        int offset=0;
247
248        UINT8 *pdata=(UINT8 *)((UINT32 *)param)[0];
249        int size=((UINT32 *)param)[1];
250
251        if (cb_type != eDHL_CB_VideoUserData)
252        {
253                DHL_OS_Printf("|%s| wrong userdata callback(cb_type:0x%x).\n",
254                              __FUNCTION__, cb_type);
255               
256                return;
257        }
258       
259        //p_print_pic_ud(pdata, size);
260       
261        //¿©±â¼­ ¾à°£ÀÇ Å×½ºÆ®¸¦ °ÅÃÄ ¾µ¸ð ¾ø´Â ÆÄÀϵéÀ» °É·¯³½´Ù.
262        bcur_valid=p_check_cc_validity(pdata, &size, &offset);
263
264        if (MAX_SIZE_PIC_UD <= size)
265        {
266                //ÀÌ °æ¿ì additional cc data°¡ ÀÖÀ¸¸é ¹ß»ýÇÒ ¼ö ÀÖÀ½.
267                //additional cc data¸¦ Áö¿ö¹ö¸®°í ³²Àº ³ª¸ÓÁö¸¸ ó¸®ÇÔ.
268               
269                DHL_OS_Printf("|%s| too big userdata size(MAX : %d, data : %d). discard.\n", 
270                        __FUNCTION__, MAX_SIZE_PIC_UD, size);
271               
272                return;
273        }       
274       
275       
276       
277        if(!bcur_valid) {
278                CCPRINT("ddi", "!! all invalid packet!!\n");
279                if(bprev_valid) bprev_valid=FALSE;
280                else            return;
281        }
282        else {
283                bprev_valid=TRUE;
284        }
285       
286        pdata = &(pdata[offset]);
287        memcpy(p_ud_buf[p_ud_buf_wr_idx].data, (void *)pdata,
288               size);
289        p_ud_buf[p_ud_buf_wr_idx].size = size;
290
291#if 0
292        p_ud_buf[p_ud_buf_wr_idx].pic_type = ((UINT32 *)param)[2];
293#else
294        p_ud_buf[p_ud_buf_wr_idx].pic_type = eDCC_PIC_CT_I;
295#endif
296
297#if 0 //scte20_21À» Áö¿øÇÒ °æ¿ì ¾Æ·¡ ±¸ÇöÀÌ ¹Ýµå½Ã ÇÊ¿äÇÔ.
298        p_ud_buf[p_ud_buf_wr_idx].pic_structure=pPic->pictureStructure[0];
299        p_ud_buf[p_ud_buf_wr_idx].top_field_first = pPic->topFieldFirst;
300        p_ud_buf[p_ud_buf_wr_idx].repeat_first_field = pPic->repeatFirstField;
301        p_ud_buf[p_ud_buf_wr_idx].ms_rcv=count++;
302#endif
303       
304        if(p_ud_callback) 
305                p_ud_callback(&p_ud_buf[p_ud_buf_wr_idx]);
306               
307        if(++p_ud_buf_wr_idx>=MAX_NUM_PIC_UD_Q) 
308                p_ud_buf_wr_idx=0;
309}
310
311
312void DCCDDI_SetUserCallback(tDCC_UserCallback func)
313{
314        p_ud_callback=func;
315}
316
317
318// zooyouny: »ç¿ëµÇ´Â °÷ ¾øÀ½
319#if 0
320tDCC_PicUDRaw *DCCDDI_GetUserData()
321{
322        int err;
323        int rcv_len;
324        int idx;
325       
326        err=DCCDDI_ReceiveMessage_Wait(p_ud_msgq, &idx, sizeof(idx), &rcv_len, 10);
327       
328        if(err) return NULL;
329               
330        return &p_ud_buf[idx];
331}
332#endif
333
334int DCCDDI_Feeding608(BOOL is_even, UINT8 data1, UINT8 data2, BOOL is_end)
335{
336        BOOL VDEC_StoreCCData(UINT8 field, UINT8 data1, UINT8 data2, BOOL is_end);
337
338        VDEC_StoreCCData(is_even, data1, data2, is_end);
339
340        return 0;
341}
342
343
344#if 0
345__Graphic__() {}
346#endif
347
348static tDMG_FontAttr p_backup_font;
349
350void DCCDDI_GraphicStart(UINT8 resolution)
351{
352        DMG_GetFontAttr(&p_backup_font);
353        DMG_SetFont(eDMG_FONT_JUNGLE);
354}
355
356void DCCDDI_GraphicStop()
357{
358        DMG_SetFont(eDMG_FONT_BMF);
359        DMG_SetFontAttr(&p_backup_font);
360        DMG_EraseRect(0, 0, 720, 480, 0);
361        DMG_AutoRefresh();
362}
363
364void DCCDDI_DrawBox(int x, int y, int w, int h, int color)
365{
366        CCPRINT("ddi", "DCCDDI_DrawBox(%d,%d,%d,%d,%d)\n", x, y, w, h, color);
367       
368        if(w<=0 || h<=0) return;
369       
370        p_check_region(x, y, w, h);
371       
372        DMG_EraseRect(x, y, w, h, color);
373}
374
375//height°¡ -À̸é up, +À̸é down
376void DCCDDI_BLT(int x, int y, int w, int h, int height)
377{
378        tDHL_GrpRect r1, r2;
379
380        CCPRINT("ddi", "DCCDDI_BLT(%d,%d,%d,%d,%d)\n", x, y, w, h, height);
381       
382        if(height==0 || h==0) return;
383               
384        p_check_region(x, y, w, h);
385        p_check_region(x, y+height, w, h);
386       
387        DHL_FILLRECT(&r1, x, y, w, h);
388        DHL_FILLRECT(&r2, x, y+height, w, h);
389       
390        DMG_BLT(CC_PLANE, CC_TEMP_PLANE, &r1, &r1);
391        DMG_BLT(CC_TEMP_PLANE, CC_PLANE, &r1, &r2);
392}
393
394void DCCDDI_DrawHLine(int x, int y, int w, int color)
395{
396        if(w<=0) return;
397               
398        p_check_region(x, y, w, 1);
399
400        DMG_DrawHLine(x, y, w, color);
401}
402
403
404void DCCDDI_Refresh()
405{
406
407}
408
409
410#if 0
411__Font__() {}
412#endif
413
414#define USE_MARGINE 0
415
416#if IS_FONT_JUNGLE
417//static UT_FC p_reg_fc;
418#elif IS_FONT_MLF
419static RML_FC p_reg_fc;
420#elif IS_FONT_BMF
421static BMF_FC p_reg_fc;
422#endif
423
424
425static struct {
426        int size;
427        BOOL is_italic;
428        BOOL is_underline;
429        BOOL is_unicode; //2byte. ÇѱÛÀÎ °æ¿ì unicode/¿Ï¼ºÇü Áß ¾î´À °ÍÀÎÁö..
430        BOOL is_p16; 
431        int font_style;
432        int edge_type;
433} p_font_attr;
434
435
436
437#define USE_FONT_CACHE 0
438        //font cache¸¦ »ç¿ëÇÔ.
439       
440#define CH_BLANK 0x20
441#define MAX_CH_W (p_font_attr.size*8/10)
442        //neverdai analog cc¿¡¸¸ »ç¿ëÇÔ.
443
444#if IS_FONT_JUNGLE
445
446
447#if USE_FONT_CACHE
448
449#define IMG_CACHE_SIZE 128
450
451static struct {
452        UINT16 ch;
453       
454        SINT8 x;
455        SINT8 y;
456        SINT8 w;
457        SINT8 h;
458        SINT8 pitch;
459       
460        UINT8 buf[512]; //ÃÖ´ë 45»çÀÌÁî ±ÛÀÚ±îÁö ÀúÀåÇÒ ¼ö ÀÖÀ½.
461} p_ut_img_cache[IMG_CACHE_SIZE];//¾à 6.5K Á¤µµ
462
463static int p_cache_idx;
464
465#endif // USE_FONT_CACHE
466
467#endif /* IS_FONT_JUNGLE */
468
469
470
471int DCCDDI_PrintCh(int x, int y, UINT16 ch, int c_font, int c_edge)
472{
473        tDMG_FontAttr attr;
474        int width;
475       
476        if(!p_font_attr.is_unicode) {
477                //¿Ï¼ºÇüÀ» unicode·Î º¯°æÇÔ.                   
478                ch=DCCUtil_Ksx1001toUnicode(ch);
479                CCPRINT("ddi", "convert to ksx1001(0x%x)\n", ch);
480        }
481       
482        ch=p_remap_char(ch);
483       
484        DMG_GetFontAttr(&attr);
485        attr.c_edge=DMG_ConvertDefColor(c_edge);
486        DMG_SetFontAttr(&attr);
487       
488        p_check_region(x, y, 20, 20); //´ë·« width, height¸¦ 20À¸·Î ÇÔ.
489       
490        width=DMG_PrintCh(x, y, ch, c_font);
491
492        DHL_PostDraw(CC_PLANE, x, y, width, DMG_GetChHeight(ch));
493       
494        return width;
495}
496
497
498int DCCDDI_GetChWidth(UINT16 ch)
499{
500        if(!p_font_attr.is_unicode) {
501                //¿Ï¼ºÇüÀ» unicode·Î º¯°æÇÔ.                   
502                CCPRINT("ddi_ch", "convert to ksx1001(0x%x->0x%x)\n", ch, DCCUtil_Ksx1001toUnicode(ch));
503                ch=DCCUtil_Ksx1001toUnicode(ch);
504        }
505
506        ch=p_remap_char(ch);
507       
508        return DMG_GetChWidth(ch);
509}
510
511
512int DCCDDI_GetChHeight(UINT16 ch)
513{
514        if(!p_font_attr.is_unicode) {
515                //¿Ï¼ºÇüÀ» unicode·Î º¯°æÇÔ.                   
516                CCPRINT("ddi_ch", "convert to ksx1001(0x%x)\n", ch);
517                ch=DCCUtil_Ksx1001toUnicode(ch);
518        }
519
520        ch=p_remap_char(ch);
521
522        return DMG_GetChHeight(ch);
523}
524
525
526void DCCDDI_SetFontAttr(int size, BOOL is_italic, BOOL is_underline, UINT8 font_style, 
527        UINT8 edge_type, BOOL is_p16)
528{
529        tDMG_FontAttr attr;
530       
531        DMG_GetFontAttr(&attr);
532       
533        attr.size=size;
534        attr.is_italic=is_italic;
535        attr.is_underline=is_underline;
536       
537        if(is_p16) {
538                attr.font_style=eDMG_FS_KOREAN;
539        }
540        else {
541                attr.font_style=(tDMG_FontStyle)font_style;
542        }
543       
544        attr.edge_type=(tDMG_EdgeType)edge_type;
545       
546        DMG_SetFontAttr(&attr);
547       
548}
549
550
551#if 0
552__Init__() {}
553#endif
554
555void DCCDDI_Init()
556{
557// zooyouny: »ç¿ëµÇ´Â °÷ ¾øÀ½
558//      p_ud_msgq=DCCDDI_CreateMessageQueue("udmsgq", MAX_NUM_PIC_UD_Q, sizeof(int));
559       
560#if IS_FONT_JUNGLE
561                //ut_InitFontContext(&p_reg_fc, 0, 0);
562#elif IS_FONT_MLF
563        RML_InitFontContext(&p_reg_fc, 0, 0);
564#elif IS_FONT_BMF
565        BMF_InitFontContext(&p_reg_fc, 0, 0);
566#endif
567        memset(p_ud_buf, 0, sizeof(tDCC_PicUDRaw) * MAX_NUM_PIC_UD_Q);
568
569        /* user data callback ¼³Á¤ */
570        DHL_AV_SetCallback(eDHL_CB_VideoUserData, p_user_data);
571       
572        {
573                void VDEC_StartVBICaption(void);
574
575                VDEC_StartVBICaption();
576        }
577}
578
579void DCCDDI_SetKoreanMode(BOOL is_unicode)
580{
581        //unicode¸¦ ¾µ °ÍÀÎÁö.
582        p_font_attr.is_unicode=is_unicode;
583}
584
585
586#if 0
587___Debug___()
588#endif
589
590void cc_ddi_info()
591{
592
593}
594
Note: See TracBrowser for help on using the repository browser.