| 1 | /**************************************************************************** |
|---|
| 2 | * 'Copyright (c) 2004 Digital Stream Technologies Inc. All Rights Reserved. |
|---|
| 3 | * |
|---|
| 4 | * Module: dsthalcc.cpp |
|---|
| 5 | * Author: Jun-ku Park, hwatk@dstreamtech.com |
|---|
| 6 | * Description: DST HAL Closed Caption |
|---|
| 7 | * |
|---|
| 8 | * notes: hwatk20040602 |
|---|
| 9 | * |
|---|
| 10 | * TO DO LIST |
|---|
| 11 | * |
|---|
| 12 | ***************************************************************************/ |
|---|
| 13 | |
|---|
| 14 | /****************************************************************************** |
|---|
| 15 | * Global variable declaration |
|---|
| 16 | ******************************************************************************/ |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | /****************************************************************************** |
|---|
| 20 | * Imported variable declaration |
|---|
| 21 | ******************************************************************************/ |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | /****************************************************************************** |
|---|
| 25 | * Imported function declaration |
|---|
| 26 | ******************************************************************************/ |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | /****************************************************************************** |
|---|
| 30 | * Local definitions |
|---|
| 31 | ******************************************************************************/ |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | /****************************************************************************** |
|---|
| 35 | * Local typedefs |
|---|
| 36 | ******************************************************************************/ |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | /****************************************************************************** |
|---|
| 40 | * Local function prototypes |
|---|
| 41 | ******************************************************************************/ |
|---|
| 42 | |
|---|
| 43 | #include <stdio.h> |
|---|
| 44 | #include <stdlib.h> |
|---|
| 45 | #include <errno.h> |
|---|
| 46 | #include <sys/stat.h> |
|---|
| 47 | #include <sys/time.h> |
|---|
| 48 | |
|---|
| 49 | #include "dsthalcommon.h" |
|---|
| 50 | #include "dsthalcapcc.h" |
|---|
| 51 | #include "dsthalcap.h" |
|---|
| 52 | #include "dstddcap.h" |
|---|
| 53 | |
|---|
| 54 | #ifdef DMALLOC |
|---|
| 55 | #include <dmalloc.h> |
|---|
| 56 | #endif |
|---|
| 57 | |
|---|
| 58 | //#include "dstddcapcc.h" |
|---|
| 59 | //#include "dstddcap.h" |
|---|
| 60 | |
|---|
| 61 | DHL_RESULT Init_VBI_Thread(void); |
|---|
| 62 | static DHL_RESULT Start_VBI_Thread(void); |
|---|
| 63 | DHL_RESULT Stop_VBI_Thread(void); |
|---|
| 64 | int capcc_debug = 0; |
|---|
| 65 | extern DS_U32 gdhlCapDbgLvl; |
|---|
| 66 | |
|---|
| 67 | #if 0 |
|---|
| 68 | __Public_Functions_____________________________________________________ () |
|---|
| 69 | #endif |
|---|
| 70 | |
|---|
| 71 | DHL_CAP_CC_CONFIG g_CC_Config; |
|---|
| 72 | DHL_RESULT DHL_CAP_CC_Init(void) |
|---|
| 73 | { |
|---|
| 74 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 75 | |
|---|
| 76 | dhlResult = Init_VBI_Thread(); |
|---|
| 77 | if ( dhlResult != DHL_OK ) { |
|---|
| 78 | printf("%s| ERROR: LINE=%d\n", __FUNCTION__, __LINE__); |
|---|
| 79 | dhlResult = DHL_FAIL; |
|---|
| 80 | goto done; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | dhlResult = Start_VBI_Thread(); |
|---|
| 84 | if ( dhlResult != DHL_OK ) { |
|---|
| 85 | printf("%s| ERROR: LINE=%d\n", __FUNCTION__, __LINE__); |
|---|
| 86 | dhlResult = DHL_FAIL; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | done: |
|---|
| 90 | return dhlResult; |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | DHL_RESULT DHL_CAP_CC_PresetVideoSource( DHL_CAP_CC_INPUT videoInput ) |
|---|
| 94 | { |
|---|
| 95 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 96 | |
|---|
| 97 | /* Video ÀÔ·Â ¼³Á¤ */ |
|---|
| 98 | g_CC_Config.CCVideoSrc = videoInput; |
|---|
| 99 | |
|---|
| 100 | return dhlResult; |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | DHL_RESULT DHL_CAP_CC_ChangeVideoSource( DHL_CAP_CC_INPUT videoInput ) |
|---|
| 104 | { |
|---|
| 105 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 106 | |
|---|
| 107 | /* Video ÀÔ·Â ¼³Á¤ */ |
|---|
| 108 | g_CC_Config.CCVideoSrc = videoInput; |
|---|
| 109 | |
|---|
| 110 | return dhlResult; |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | DHL_RESULT DHL_CAP_CC_Start(void) |
|---|
| 114 | { |
|---|
| 115 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 116 | DHL_CAP_VIDEO_INPUT vi; |
|---|
| 117 | |
|---|
| 118 | vi = DHL_CAP_GetVideoSrc(0); |
|---|
| 119 | if ( vi >= DHL_CAP_ATV_VIDEO_START && vi < DHL_CAP_YPBPR_VIDEO_START ) |
|---|
| 120 | DD_CAP_ResetVBI(0); |
|---|
| 121 | else |
|---|
| 122 | DD_CAP_ResetVBI(1); |
|---|
| 123 | |
|---|
| 124 | #if 1 |
|---|
| 125 | dhlResult = Start_VBI_Thread(); |
|---|
| 126 | if ( dhlResult != DHL_OK ) { |
|---|
| 127 | printf("%s| ERROR: LINE=%d\n", __FUNCTION__, __LINE__); |
|---|
| 128 | dhlResult = DHL_FAIL; |
|---|
| 129 | } |
|---|
| 130 | #endif |
|---|
| 131 | |
|---|
| 132 | if(!DHL_ERROR(dhlResult)) |
|---|
| 133 | DHL_DbgPrintf(gdhlCapDbgLvl,DHLDBG_CAP,"|success|\r\n"); |
|---|
| 134 | |
|---|
| 135 | return dhlResult; |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | DHL_RESULT DHL_CAP_CC_Stop(void) |
|---|
| 139 | { |
|---|
| 140 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 141 | |
|---|
| 142 | #if 1 |
|---|
| 143 | dhlResult = Stop_VBI_Thread(); |
|---|
| 144 | if ( dhlResult != DHL_OK ) { |
|---|
| 145 | printf("%s| ERROR: LINE=%d\n", __FUNCTION__, __LINE__); |
|---|
| 146 | dhlResult = DHL_FAIL; |
|---|
| 147 | } |
|---|
| 148 | #endif |
|---|
| 149 | |
|---|
| 150 | return dhlResult; |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | DHL_RESULT DHL_CAP_CC_Close(void) |
|---|
| 154 | { |
|---|
| 155 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 156 | |
|---|
| 157 | return dhlResult; |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | DHL_RESULT DHL_CAP_CC_SetCallback( P_DHL_CAP_CC_CALLBACK cbFunc, DHL_CAP_CC_INPUT videoInput ) |
|---|
| 161 | { |
|---|
| 162 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 163 | |
|---|
| 164 | g_CC_Config.cbFunc[videoInput-DHL_CAP_CC_INPUT_START] = cbFunc; |
|---|
| 165 | |
|---|
| 166 | return dhlResult; |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | static void CbCapCC(DHL_CAP_CC_INPUT ccVideoSrc, DS_U8 *pVbiBuffer, int Length) |
|---|
| 170 | { |
|---|
| 171 | int i, nField; |
|---|
| 172 | |
|---|
| 173 | for (i = 0; i < Length; i+=3) { |
|---|
| 174 | if ( pVbiBuffer[i] & 0x01 ) |
|---|
| 175 | nField = 1; |
|---|
| 176 | else |
|---|
| 177 | nField = 2; |
|---|
| 178 | |
|---|
| 179 | if ( g_CC_Config.cbFunc[ccVideoSrc-DHL_CAP_CC_INPUT_START] ) |
|---|
| 180 | (g_CC_Config.cbFunc[ccVideoSrc-DHL_CAP_CC_INPUT_START])(ccVideoSrc, nField, pVbiBuffer[i+1], pVbiBuffer[i+2]); |
|---|
| 181 | |
|---|
| 182 | if (capcc_debug==1) { |
|---|
| 183 | #define ASCII(x) ( ( ( (x) >= ' ' ) && ( (x) <= '~' ) ) ? (x) : '.' ) |
|---|
| 184 | if (nField==2) /* CH2 */ |
|---|
| 185 | printf( "\t\t\t\t\t[0x%x] [%x %x] %c%c\n", pVbiBuffer[i], pVbiBuffer[i+1], pVbiBuffer[i+2], ASCII(pVbiBuffer[i+1]), ASCII(pVbiBuffer[i+2]) ); |
|---|
| 186 | else |
|---|
| 187 | printf( "[0x%x] [%x %x] %c%c\n", pVbiBuffer[i], pVbiBuffer[i+1], pVbiBuffer[i+2], ASCII(pVbiBuffer[i+1]), ASCII(pVbiBuffer[i+2]) ); |
|---|
| 188 | } |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | #if 0 |
|---|
| 194 | __Internal_Functions_____________________________________________________ () |
|---|
| 195 | #endif |
|---|
| 196 | static DS_BOOL bVBI_ThreadActive = _FALSE_; |
|---|
| 197 | static DS_BOOL bVBI_ThreadActiveReq = _FALSE_; |
|---|
| 198 | |
|---|
| 199 | #define VBI_THREAD_DELAY 100 |
|---|
| 200 | #define VBI_THREAD_PRIORITY 150 |
|---|
| 201 | #define VBI_THREAD_STACKSIZE 32768 |
|---|
| 202 | |
|---|
| 203 | #define VBI_SIZE 1024*10 |
|---|
| 204 | |
|---|
| 205 | static DS_U8 vbiBuffer[VBI_SIZE]; |
|---|
| 206 | static DS_U32 vbiThreadId = (DS_U32)0; |
|---|
| 207 | void DHL_CAP_VBIThread(DS_U32 arg) |
|---|
| 208 | { |
|---|
| 209 | DHL_RESULT dhlResult; |
|---|
| 210 | int len; |
|---|
| 211 | DHL_CAP_VIDEO_INPUT vi; |
|---|
| 212 | DHL_CAP_CC_INPUT capVi; |
|---|
| 213 | |
|---|
| 214 | while(1) { |
|---|
| 215 | // |
|---|
| 216 | // Start ÀÌÀüÀ̰ųª, StopÇÑ °æ¿ì ±×³É IDLE. |
|---|
| 217 | // |
|---|
| 218 | if ( bVBI_ThreadActiveReq == _FALSE_) { |
|---|
| 219 | OS_mDelay(VBI_THREAD_DELAY); |
|---|
| 220 | bVBI_ThreadActive = _FALSE_; |
|---|
| 221 | continue; |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | OS_mDelay(VBI_THREAD_DELAY); |
|---|
| 225 | bVBI_ThreadActive = _TRUE_; |
|---|
| 226 | |
|---|
| 227 | // |
|---|
| 228 | // Main Path |
|---|
| 229 | // |
|---|
| 230 | vi = DHL_CAP_GetVideoSrc(0); |
|---|
| 231 | if ( vi >= DHL_CAP_ATV_VIDEO_START && vi <= DHL_CAP_YPBPR_VIDEO_STOP ) { |
|---|
| 232 | len = VBI_SIZE; |
|---|
| 233 | if ( vi >= DHL_CAP_ATV_VIDEO_START && vi < DHL_CAP_YPBPR_VIDEO_START ) |
|---|
| 234 | dhlResult = DD_CAP_GetVBI(0, vbiBuffer, &len); |
|---|
| 235 | else |
|---|
| 236 | dhlResult = DD_CAP_GetVBI(1, vbiBuffer, &len); |
|---|
| 237 | if ( dhlResult != DHL_OK ) { |
|---|
| 238 | printf("|%s| ERROR, LINE=%d\n", __FUNCTION__, __LINE__); |
|---|
| 239 | continue; |
|---|
| 240 | } |
|---|
| 241 | |
|---|
| 242 | if ( len > 0 ) { |
|---|
| 243 | if ( vi >= DHL_CAP_ATV_VIDEO_START && vi <= DHL_CAP_YPBPR_VIDEO_STOP ) |
|---|
| 244 | capVi = DHL_CAP_CC_NTSC_INPUT; |
|---|
| 245 | else |
|---|
| 246 | capVi = DHL_CAP_CC_YPBPR_INPUT; |
|---|
| 247 | |
|---|
| 248 | CbCapCC( capVi, vbiBuffer, len ); |
|---|
| 249 | } |
|---|
| 250 | } |
|---|
| 251 | |
|---|
| 252 | // |
|---|
| 253 | // PIP Path |
|---|
| 254 | // |
|---|
| 255 | vi = DHL_CAP_GetVideoSrc(1); |
|---|
| 256 | if ( vi >= DHL_CAP_ATV_VIDEO_START && vi <= DHL_CAP_YPBPR_VIDEO_STOP ) { |
|---|
| 257 | len = VBI_SIZE; |
|---|
| 258 | dhlResult = DD_CAP_GetVBI(1, vbiBuffer, &len); |
|---|
| 259 | if ( dhlResult != DHL_OK ) { |
|---|
| 260 | printf("|%s| ERROR, LINE=%d\n", __FUNCTION__, __LINE__); |
|---|
| 261 | continue; |
|---|
| 262 | } |
|---|
| 263 | |
|---|
| 264 | if ( len > 0 ) { |
|---|
| 265 | if ( vi >= DHL_CAP_ATV_VIDEO_START && vi <= DHL_CAP_YPBPR_VIDEO_STOP ) |
|---|
| 266 | capVi = DHL_CAP_CC_NTSC_INPUT; |
|---|
| 267 | else |
|---|
| 268 | capVi = DHL_CAP_CC_YPBPR_INPUT; |
|---|
| 269 | |
|---|
| 270 | CbCapCC( capVi, vbiBuffer, len ); |
|---|
| 271 | } |
|---|
| 272 | } |
|---|
| 273 | } |
|---|
| 274 | } |
|---|
| 275 | |
|---|
| 276 | DHL_RESULT Init_VBI_Thread(void) |
|---|
| 277 | { |
|---|
| 278 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 279 | |
|---|
| 280 | bVBI_ThreadActiveReq = _FALSE_; |
|---|
| 281 | bVBI_ThreadActive = _FALSE_; |
|---|
| 282 | vbiThreadId = OS_SpawnTask( DHL_CAP_VBIThread, "tVBIMonitor", 0, 4096, (DS_U32)0); |
|---|
| 283 | if ( !vbiThreadId ) { |
|---|
| 284 | printf("ERROR: Cannot create function tvVIMonitor.\n"); |
|---|
| 285 | dhlResult = DHL_FAIL_OUT_OF_RESOURCE; |
|---|
| 286 | } |
|---|
| 287 | |
|---|
| 288 | return dhlResult; |
|---|
| 289 | } |
|---|
| 290 | |
|---|
| 291 | static DHL_RESULT Start_VBI_Thread(void) |
|---|
| 292 | { |
|---|
| 293 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 294 | volatile DS_U32 timeout; |
|---|
| 295 | |
|---|
| 296 | if ( bVBI_ThreadActiveReq && bVBI_ThreadActive ) { |
|---|
| 297 | goto done; |
|---|
| 298 | } |
|---|
| 299 | bVBI_ThreadActiveReq = _TRUE_; |
|---|
| 300 | |
|---|
| 301 | timeout = OS_GetTickCount()+50; |
|---|
| 302 | do { |
|---|
| 303 | if ( bVBI_ThreadActive == _TRUE_ ) |
|---|
| 304 | break; |
|---|
| 305 | OS_mDelay(VBI_THREAD_DELAY); |
|---|
| 306 | } while(timeout>OS_GetTickCount()); |
|---|
| 307 | |
|---|
| 308 | if ( bVBI_ThreadActive != _TRUE_ && timeout>OS_GetTickCount() ) { |
|---|
| 309 | printf("|%s| ERROR: LINE=%d\n", __FUNCTION__, __LINE__); |
|---|
| 310 | dhlResult = DHL_FAIL; |
|---|
| 311 | } |
|---|
| 312 | |
|---|
| 313 | done: |
|---|
| 314 | return dhlResult; |
|---|
| 315 | } |
|---|
| 316 | |
|---|
| 317 | DHL_RESULT Stop_VBI_Thread(void) |
|---|
| 318 | { |
|---|
| 319 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 320 | volatile DS_U32 timeout; |
|---|
| 321 | |
|---|
| 322 | if ( !bVBI_ThreadActiveReq && !bVBI_ThreadActive ) { |
|---|
| 323 | goto done; |
|---|
| 324 | } |
|---|
| 325 | |
|---|
| 326 | // |
|---|
| 327 | // MAIN/PIP Áß Çϳª¶óµµ ½ÃÀ۵Ǿî ÀÖÀ¸¸é, Á¤ÁöÇÏÁö ¾Ê´Â´Ù. |
|---|
| 328 | // |
|---|
| 329 | bVBI_ThreadActiveReq = _FALSE_; |
|---|
| 330 | |
|---|
| 331 | timeout = OS_GetTickCount()+50; |
|---|
| 332 | do { |
|---|
| 333 | if ( bVBI_ThreadActive == _FALSE_ ) |
|---|
| 334 | break; |
|---|
| 335 | OS_mDelay(VBI_THREAD_DELAY); |
|---|
| 336 | } while(timeout>OS_GetTickCount()); |
|---|
| 337 | |
|---|
| 338 | if ( bVBI_ThreadActive != _FALSE_ && timeout>OS_GetTickCount() ) |
|---|
| 339 | dhlResult = DHL_FAIL; |
|---|
| 340 | |
|---|
| 341 | done: |
|---|
| 342 | return dhlResult; |
|---|
| 343 | } |
|---|
| 344 | |
|---|
| 345 | void hcapcc_dbg(int nDbg) |
|---|
| 346 | { |
|---|
| 347 | capcc_debug = nDbg; |
|---|
| 348 | } |
|---|