| [2] | 1 | /**************************************************************************** |
|---|
| 2 | *_Copyright (c) 2004 DST Technologies Inc. All Rights Reserved. |
|---|
| 3 | * |
|---|
| 4 | * Module: dsthaldmx.c |
|---|
| 5 | * |
|---|
| 6 | * Description: DST DEMULTIPLEX INTERFACE IMPLEMENTATION |
|---|
| 7 | * |
|---|
| 8 | * |
|---|
| 9 | * notes: jfet20040603 |
|---|
| 10 | * |
|---|
| 11 | ***************************************************************************/ |
|---|
| 12 | |
|---|
| 13 | #include "dsthalcommon.h" |
|---|
| 14 | #include "dsthaldmx.h" |
|---|
| 15 | //#include "dstdddemux.h" |
|---|
| 16 | #include "dsthallocal.h" |
|---|
| 17 | |
|---|
| 18 | #include "dstdddmx.h" |
|---|
| 19 | |
|---|
| 20 | #ifdef DMALLOC |
|---|
| 21 | #include <dmalloc.h> |
|---|
| 22 | #endif |
|---|
| 23 | |
|---|
| 24 | /****************************************************************************** |
|---|
| 25 | * Global variable declaration |
|---|
| 26 | ******************************************************************************/ |
|---|
| 27 | DS_U32 g_dhlDmxDbgLvl = 1; |
|---|
| 28 | DS_U32 g_CurrentTSInput = DHL_DMX_TS_INPUT0; |
|---|
| 29 | |
|---|
| 30 | /****************************************************************************** |
|---|
| 31 | * Imported variable declaration |
|---|
| 32 | ******************************************************************************/ |
|---|
| 33 | |
|---|
| 34 | /****************************************************************************** |
|---|
| 35 | * Imported function declaration |
|---|
| 36 | ******************************************************************************/ |
|---|
| 37 | |
|---|
| 38 | /****************************************************************************** |
|---|
| 39 | * Local definitions |
|---|
| 40 | ******************************************************************************/ |
|---|
| 41 | |
|---|
| 42 | /****************************************************************************** |
|---|
| 43 | * Local variable declaration |
|---|
| 44 | ******************************************************************************/ |
|---|
| 45 | static DS_BOOL s_bScrambleCheckStarted = _FALSE_; |
|---|
| 46 | static int s_iScrambleCheckTimeout = 170; |
|---|
| 47 | |
|---|
| 48 | /****************************************************************************** |
|---|
| 49 | * Local typedefs |
|---|
| 50 | ******************************************************************************/ |
|---|
| 51 | |
|---|
| 52 | /****************************************************************************** |
|---|
| 53 | * Local function prototypes |
|---|
| 54 | ******************************************************************************/ |
|---|
| 55 | |
|---|
| 56 | /******************************************************************************** |
|---|
| 57 | FUNCTION: |
|---|
| 58 | DHL_DMX_INIT |
|---|
| 59 | |
|---|
| 60 | Purpose: |
|---|
| 61 | |
|---|
| 62 | Arguments: |
|---|
| 63 | |
|---|
| 64 | Returns: |
|---|
| 65 | DHL_RESULT success - DHL_OK |
|---|
| 66 | fail - DHL_FAIL |
|---|
| 67 | *********************************************************************************/ |
|---|
| 68 | DHL_RESULT DHL_DMX_Init(void) |
|---|
| 69 | { |
|---|
| 70 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 71 | static int dmxInit = 0; |
|---|
| 72 | |
|---|
| 73 | if ( dmxInit == 1 ) |
|---|
| 74 | return dhlResult; |
|---|
| 75 | |
|---|
| 76 | dmxInit = 1; |
|---|
| 77 | |
|---|
| 78 | dhlResult = DD_DMX_Init(); |
|---|
| 79 | |
|---|
| 80 | SysENSURE(dhlResult == DHL_OK); |
|---|
| 81 | |
|---|
| 82 | return dhlResult; |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | /******************************************************************************** |
|---|
| 86 | FUNCTION: |
|---|
| 87 | DHL_DMX_START |
|---|
| 88 | |
|---|
| 89 | Purpose: |
|---|
| 90 | demultiplex component start |
|---|
| 91 | Arguments: |
|---|
| 92 | |
|---|
| 93 | Returns: |
|---|
| 94 | DHL_RESULT if success - DHL_OK fail - DHL_FAIL |
|---|
| 95 | *********************************************************************************/ |
|---|
| 96 | DHL_RESULT DHL_DMX_Start(void) |
|---|
| 97 | { |
|---|
| 98 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 99 | |
|---|
| 100 | dhlResult = DD_DMX_Start(); |
|---|
| 101 | |
|---|
| 102 | SysENSURE(dhlResult == DHL_OK); |
|---|
| 103 | |
|---|
| 104 | return dhlResult; |
|---|
| 105 | } |
|---|
| 106 | /******************************************************************************** |
|---|
| 107 | FUNCTION: |
|---|
| 108 | DHL_DMX_STOP |
|---|
| 109 | |
|---|
| 110 | Purpose: |
|---|
| 111 | demultiplex components stop (pipe) |
|---|
| 112 | Arguments: |
|---|
| 113 | |
|---|
| 114 | Returns: |
|---|
| 115 | DHL_RESULT if success - DHL_OK fail - DHL_FAIL |
|---|
| 116 | *********************************************************************************/ |
|---|
| 117 | DHL_RESULT DHL_DMX_Stop(void) |
|---|
| 118 | { |
|---|
| 119 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 120 | |
|---|
| 121 | dhlResult = DD_DMX_Stop(); |
|---|
| 122 | |
|---|
| 123 | SysENSURE(dhlResult == DHL_OK); |
|---|
| 124 | |
|---|
| 125 | return dhlResult; |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | /******************************************************************************** |
|---|
| 129 | FUNCTION: |
|---|
| 130 | DHL_DMX_CLOSE |
|---|
| 131 | |
|---|
| 132 | Purpose: |
|---|
| 133 | demultiplex components close (stop->disconncet->close) |
|---|
| 134 | |
|---|
| 135 | Arguments: |
|---|
| 136 | |
|---|
| 137 | Returns: |
|---|
| 138 | DHL_RESULT if success - DHL_OK fail - DHL_FAIL |
|---|
| 139 | *********************************************************************************/ |
|---|
| 140 | DHL_RESULT DHL_DMX_Close(void) |
|---|
| 141 | { |
|---|
| 142 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 143 | |
|---|
| 144 | dhlResult = DD_DMX_Close(); |
|---|
| 145 | |
|---|
| 146 | SysENSURE(dhlResult == DHL_OK); |
|---|
| 147 | |
|---|
| 148 | return dhlResult; |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | DHL_RESULT DHL_DMX_PresetInput( DHL_DMX_INPUT tsInput ) |
|---|
| 152 | { |
|---|
| 153 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 154 | |
|---|
| 155 | g_CurrentTSInput = tsInput; |
|---|
| 156 | |
|---|
| 157 | return dhlResult; |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | DHL_RESULT DHL_DMX_ChangeInput( DHL_DMX_INPUT tsInput ) |
|---|
| 161 | { |
|---|
| 162 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 163 | |
|---|
| 164 | SysREQUIRE( tsInput >= DHL_DMX_TS_INPUT_START && tsInput <= DHL_DMX_TS_INPUT_END ); |
|---|
| 165 | |
|---|
| 166 | g_CurrentTSInput = tsInput; |
|---|
| 167 | |
|---|
| 168 | return dhlResult; |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | DS_BOOL DHL_DMX_IsScrambled(void) |
|---|
| 172 | { |
|---|
| 173 | DS_BOOL bScrambled = _FALSE_; |
|---|
| 174 | volatile DS_U32 curTick; |
|---|
| 175 | |
|---|
| 176 | curTick = OS_GetTickCount(); |
|---|
| 177 | do { |
|---|
| 178 | OS_mDelay( 10 ); |
|---|
| 179 | if ( DD_DMX_IsScrambled() ) |
|---|
| 180 | { |
|---|
| 181 | bScrambled = _TRUE_; |
|---|
| 182 | break; |
|---|
| 183 | } |
|---|
| 184 | } while ( (OS_GetTickCount()) < (curTick+s_iScrambleCheckTimeout) ); |
|---|
| 185 | |
|---|
| 186 | return bScrambled; |
|---|
| 187 | } |
|---|
| 188 | |
|---|
| 189 | DS_BOOL DHL_DMX_IsScrambleCheckStarted(void) |
|---|
| 190 | { |
|---|
| 191 | return s_bScrambleCheckStarted; |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | /******************************************************************************** |
|---|
| 195 | FUNCTION: |
|---|
| 196 | DHL_DMX_SetPID4DetectScramble |
|---|
| 197 | |
|---|
| 198 | Purpose: |
|---|
| 199 | Set video/audio PID for detect scrambled channel |
|---|
| 200 | Arguments: |
|---|
| 201 | [in]uVidPID - Video PID |
|---|
| 202 | [in]uPcrPID - Video PID |
|---|
| 203 | Returns: |
|---|
| 204 | DHL_RESULT if success - DHL_OK fail - DHL_FAIL |
|---|
| 205 | *********************************************************************************/ |
|---|
| 206 | DHL_RESULT DHL_DMX_SetPID4DetectScramble(DS_U16 uVidPID, DS_U16 uAudPID) |
|---|
| 207 | { |
|---|
| 208 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 209 | |
|---|
| 210 | if ( s_bScrambleCheckStarted == _TRUE_ ) |
|---|
| 211 | { |
|---|
| 212 | DD_DMX_ResetPID4DetectScramble(); |
|---|
| 213 | s_bScrambleCheckStarted = _FALSE_; |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | dhlResult = DD_DMX_SetPID4DetectScramble(uVidPID, uAudPID); |
|---|
| 217 | SysASSERT( dhlResult == DHL_OK ); |
|---|
| 218 | |
|---|
| 219 | s_bScrambleCheckStarted = _TRUE_; |
|---|
| 220 | |
|---|
| 221 | return dhlResult; |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | DHL_RESULT DHL_DMX_ResetPID4DetectScramble(void) |
|---|
| 225 | { |
|---|
| 226 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 227 | |
|---|
| 228 | if ( s_bScrambleCheckStarted == _FALSE_ ) |
|---|
| 229 | { |
|---|
| 230 | DHL_DbgPrintf(g_dhlDmxDbgLvl,DHLDBG_DMX,"skipped.\n" ); |
|---|
| 231 | return dhlResult; |
|---|
| 232 | } |
|---|
| 233 | |
|---|
| 234 | dhlResult = DD_DMX_ResetPID4DetectScramble(); |
|---|
| 235 | SysASSERT( dhlResult == DHL_OK ); |
|---|
| 236 | |
|---|
| 237 | s_bScrambleCheckStarted = _FALSE_; |
|---|
| 238 | |
|---|
| 239 | return dhlResult; |
|---|
| 240 | } |
|---|
| 241 | |
|---|
| 242 | DHL_RESULT DHL_DMX_SetPID4DetectScrambleEx(DS_U16 uVidPID) |
|---|
| 243 | { |
|---|
| 244 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 245 | |
|---|
| 246 | if ( s_bScrambleCheckStarted == _TRUE_ ) |
|---|
| 247 | { |
|---|
| 248 | DD_DMX_ResetPID4DetectScramble(); |
|---|
| 249 | s_bScrambleCheckStarted = _FALSE_; |
|---|
| 250 | } |
|---|
| 251 | |
|---|
| 252 | dhlResult = DD_DMX_SetPID4DetectScrambleEx(uVidPID); |
|---|
| 253 | SysASSERT( dhlResult == DHL_OK ); |
|---|
| 254 | |
|---|
| 255 | s_bScrambleCheckStarted = _TRUE_; |
|---|
| 256 | |
|---|
| 257 | return dhlResult; |
|---|
| 258 | } |
|---|
| 259 | |
|---|
| 260 | DHL_RESULT DHL_DMX_SetPID4DetectScrambleExAudio(DS_U16 uAudPID) |
|---|
| 261 | { |
|---|
| 262 | return DHL_DMX_SetPID4DetectScrambleEx(uAudPID); |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | DHL_RESULT DHL_DMX_ResetPID4DetectScrambleEx(void) |
|---|
| 266 | { |
|---|
| 267 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 268 | |
|---|
| 269 | if ( s_bScrambleCheckStarted == _FALSE_ ) |
|---|
| 270 | { |
|---|
| 271 | DHL_DbgPrintf(g_dhlDmxDbgLvl,DHLDBG_DMX,"skipped.\n" ); |
|---|
| 272 | return dhlResult; |
|---|
| 273 | } |
|---|
| 274 | |
|---|
| 275 | dhlResult = DD_DMX_ResetPID4DetectScrambleEx(); |
|---|
| 276 | SysASSERT( dhlResult == DHL_OK ); |
|---|
| 277 | |
|---|
| 278 | s_bScrambleCheckStarted = _FALSE_; |
|---|
| 279 | |
|---|
| 280 | return dhlResult; |
|---|
| 281 | } |
|---|
| 282 | |
|---|
| 283 | DHL_RESULT DHL_DMX_ResetPID4DetectScrambleAudio(void) |
|---|
| 284 | { |
|---|
| 285 | return DHL_DMX_ResetPID4DetectScrambleEx(); |
|---|
| 286 | } |
|---|
| 287 | |
|---|
| 288 | |
|---|
| 289 | DHL_RESULT DHL_DMX_CheckScramble(DS_BOOL *pScrambled, int timeOut, DS_BOOL (*ckfn)(void)) |
|---|
| 290 | { |
|---|
| 291 | DS_BOOL bScrambled = DS_FALSE; |
|---|
| 292 | volatile DS_U32 curTick; |
|---|
| 293 | |
|---|
| 294 | curTick = OS_GetTickCount(); |
|---|
| 295 | do { |
|---|
| 296 | OS_mDelay( 10 ); |
|---|
| 297 | if ( DD_DMX_IsScrambled() ) { |
|---|
| 298 | //DHL_DbgPrintf(gdhlDmxDbgLvl,DHLDBG_DMX,"Scrambled!\n"); |
|---|
| 299 | fprintf(stderr,"Scrambled!\n"); |
|---|
| 300 | bScrambled = DS_TRUE; |
|---|
| 301 | break; |
|---|
| 302 | } |
|---|
| 303 | |
|---|
| 304 | if (ckfn && (*ckfn)()) |
|---|
| 305 | return DHL_FAIL_CANCELLED; |
|---|
| 306 | |
|---|
| 307 | } while ( (OS_GetTickCount()) < (curTick+timeOut) ); |
|---|
| 308 | |
|---|
| 309 | if (pScrambled) |
|---|
| 310 | *pScrambled = bScrambled; |
|---|
| 311 | |
|---|
| 312 | return DHL_OK; |
|---|
| 313 | } |
|---|
| 314 | |
|---|
| 315 | void hset_scheck_timeout(int i) |
|---|
| 316 | { |
|---|
| 317 | printf("s_iScrambleCheckTimeout: %d -> %d\n", s_iScrambleCheckTimeout, i); |
|---|
| 318 | |
|---|
| 319 | s_iScrambleCheckTimeout = i; |
|---|
| 320 | } |
|---|