source: svn/trunk/zasc/app/DST_CCTask.cpp @ 76

Last change on this file since 76 was 2, checked in by phkim, 11 years ago

1.phkim

  1. revision copy newcon3sk r27
File size: 3.9 KB
Line 
1#include "DST_WinManager.h"
2#include "DST_CommonAPI.h"
3#include "DST_ChannelTune.h"
4#include "DST_DB_Engine.h"
5#include "DST_DB.h"
6
7static bool bCCEngineReady = false;
8
9static bool bAutoDetectUnicode = false; // CC µ¥ÀÌÅ͸¦ ºÐ¼®ÇÏ¿© ÀÚµ¿À¸·Î ¿Ï¼ºÇüÀÎÁö À¯´ÏÄÚµåÀÎÁö ¾Ë¾Æ³½´Ù.
10
11void DST_708_Callback(DS_U8 *bytearray,int size)
12{
13        if (size == 0) return;
14        if (bCCEngineReady == false) return;
15        // Sequence Header°¡ ¿Ã¹Ù¸¥Áö È®ÀÎÇØº»´Ù.
16        if (size == -1) // Sequence Header ¿¡·¯°¡ ³­ °æ¿ì
17        {
18                DST_Printf("Sequence Header Error\n");
19                DST_SendWindowEventWithOnlyCmd(WM_SEQ_ERROR);
20                return;
21        }
22
23        if (size > 31) return;
24
25        int nCharTotal = 0;
26        int nCharLatin = 0;
27        int nCharWanSung = 0;
28       
29        for (int i=0; i < size-2; i++)
30        {
31                if (bytearray[i] != 0x18) continue;
32                nCharTotal++;
33                if (bytearray[i+1] == 0)
34                {
35                        nCharLatin++;
36                }
37                if (bytearray[i+1] >= 0xA1 && bytearray[i+1]  <= 0xFE && bytearray[i+2] >= 0xA1 && bytearray[i+2] <= 0xFE) 
38                {
39                        nCharWanSung++;
40                }
41                i+=2;
42        }
43        bool isWanSung = true;
44        //DST_Printf("nCharTotal = %d\n", nCharTotal);
45        //DST_Printf("nCharLatin = %d\n", nCharLatin);
46        //DST_Printf("nCharWanSung = %d\n", nCharWanSung);
47        // ½ÇÁ¦·Î CC ¹®ÀÚ°¡ ÀÖ´Ù¸é À¸·Î ÀÎÆ÷¹è³Ê ¾ÆÀÌÄÜÀÇ Á¤¹Ðµµ¸¦ ³ôÀδÙ.
48        if (nCharTotal > 0)
49        {
50                //T();
51                DST_g_CC_DataReceiveTick = DST_OS_GetTickCount();
52        }
53        if (DST_EEPROM_GetCC() == 0) return; // ÀÎÆ÷¹è³Ê CC ¾ÆÀÌÄÜ Á¤º¸¸¦ ¾÷µ¥ÀÌÆ® Çϰí CC ²¨Á®ÀÖÀ¸¸é ¸¶¹«¸®
54                       
55        int nCount = nCharTotal - nCharLatin;
56        if (nCount < 0) nCount = 0;
57        if (nCount > 0)
58        {
59                if ((nCharWanSung * 100 /  nCount) < 50) isWanSung = false;
60        }
61        //DST_Printf("isWanSung = %d\n", isWanSung);   
62       
63        bAutoDetectUnicode = !isWanSung; // À¯´ÏÄÚµå ¿©ºÎ ÀÚµ¿°ËÃâ
64
65        SWinEventMsg msg;
66        msg.cmd = WM_CS1;
67        msg.data[0] = size;
68        memcpy(&msg.data[1], bytearray, size);
69        DST_SendWindowEvent(msg);
70}
71
72typedef void (*CC708_CallBack)(DS_U8 *bytearray,int size);
73extern "C" void SetCC708_CallBack(CC708_CallBack callback);
74
75
76static bool DST_CCAvailable()
77{
78        if (DST_g_SignalState != SM_GOOD_SIGNAL) return false; // ½ÅÈ£ »óŰ¡ ÁÁÀº °æ¿ì¿¡¸¸ CC¸¦ º¸¿©ÁÖµµ·Ï ÇÔ
79//      if (DST_g_SleepState != 0) return false; // normal »óŰ¡ ¾Æ´Ï¸é CC ´Ý´Â´Ù
80        if (DST_EEPROM_GetCC() == 0) return false;
81        if (DST_g_LastTuneTime == 0) return false;
82        if (DST_IsVideoPlay() == false) return false;
83        if (DST_g_LastTuneTryTime > DST_OS_GetTickCount()) DST_g_LastTuneTryTime = DST_OS_GetTickCount();
84        if (DST_OS_GetTickCount() - DST_g_LastTuneTryTime < DST_OS_GetTicksPerSecond() * 3) return false;
85        for (int id = (int)WIN_NULL+1; id < (int)WIN_CAPTION; id++)
86        {
87                if (id == WIN_VOLUME) continue;
88                if (id == WIN_VOLUME_MUTE) continue;
89                if (DST_GetWin((DST_WinID)id)) return false;
90        }
91        return true;
92}
93 
94static void tCCManager()
95{
96        DST_OS_Delay(DST_OS_GetTicksPerSecond()*3); // 3ÃÊ ½¬°í ½ÃÀÛ
97        bCCEngineReady = true;
98        DST_CreateWin(WIN_CAPTION, WIN_NULL, 1); 
99        while (1)
100        {
101                DST_OS_Delay(DST_OS_GetTicksPerSecond()/10);
102                CWindow *pWin = DST_GetWin(WIN_CAPTION);
103                if (DST_CCAvailable())
104                {
105                        if (pWin) continue;
106                        DST_CreateWin(WIN_CAPTION, WIN_NULL, 1);
107                        for (int i = 0; i < 5; i++)
108                        {
109                                DST_OS_Delay(DST_OS_GetTicksPerSecond()/10);// ½ÇÁ¦ À©µµ¿ì°¡ »ý¼ºµÉ¶§±îÁö ´ë±â
110                                if (DST_GetWin(WIN_CAPTION)) break;
111                        }
112                }
113                else
114                {
115                        if (pWin == 0) continue;
116                        DST_SendWindowEventWithOnlyCmd(WM_CC_CLOSE);
117                        for (int i = 0; i < 5; i++)
118                        {
119                                DST_OS_Delay(DST_OS_GetTicksPerSecond()/10);// ½ÇÁ¦ À©µµ¿ì°¡ »ý¼ºµÉ¶§±îÁö ´ë±â
120                                if (DST_GetWin(WIN_CAPTION)==0) break;
121                        }
122                }
123        }
124}
125
126void DST_CCManagerInit()
127{
128        static int TaskID = 0;
129        if (TaskID != 0) return;
130        TaskID = DST_OS_SpawnTask((void(*)(void *))tCCManager, (char*)"CCManager", APP_TASK_PRIO_CC_MGR, WIN_MGR_TASK_STACKSIZE,  0);
131}
132
133void DST_CheckCCDescription(DS_U8 /*nServiceNumber*/, bool *bKorean, bool *bWideScreen, bool *bUnicode)
134{
135        *bKorean = DST_g_CC_bCCKorean;
136        *bWideScreen = DST_g_CC_bWideScreen;
137        //*bUnicode = DST_g_CC_bUnicode; // CC µð½ºÅ©¸³ÅÍ »ç¿ë
138        *bUnicode = bAutoDetectUnicode;  // ÀÚµ¿ °ËÃâ
139}
Note: See TracBrowser for help on using the repository browser.