| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2002, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: bcmDccTransport.c $ |
|---|
| 11 | * $brcm_Revision: \main\SanJose_MSTV_Devel\1 $ |
|---|
| 12 | * $brcm_Date: 3/12/02 4:45p $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: $ |
|---|
| 19 | * |
|---|
| 20 | * \main\SanJose_MSTV_Devel\1 3/12/02 4:45p erikg |
|---|
| 21 | * Merge from SanJose_MSTV_Devel_erikg_mpegccxport2_2002_03_06_1118_38 |
|---|
| 22 | * |
|---|
| 23 | * \main\SanJose_MSTV_Devel_erikg_mpegccxport2_2002_03_06_1118_38\5 3/12/02 3:59p erikg |
|---|
| 24 | * fleshed out _QueryDetectedFormats |
|---|
| 25 | * |
|---|
| 26 | * \main\SanJose_MSTV_Devel_erikg_mpegccxport2_2002_03_06_1118_38\4 3/12/02 2:57p erikg |
|---|
| 27 | * debugged using base platform |
|---|
| 28 | * |
|---|
| 29 | * \main\SanJose_MSTV_Devel_erikg_mpegccxport2_2002_03_06_1118_38\3 3/7/02 4:21p erikg |
|---|
| 30 | * more fleshing out |
|---|
| 31 | * |
|---|
| 32 | * \main\SanJose_MSTV_Devel_erikg_mpegccxport2_2002_03_06_1118_38\2 3/6/02 2:21p erikg |
|---|
| 33 | * fleshed out some of the functions |
|---|
| 34 | * |
|---|
| 35 | * \main\SanJose_MSTV_Devel_erikg_mpegccxport2_2002_03_06_1118_38\1 3/6/02 11:29a erikg |
|---|
| 36 | * new source files |
|---|
| 37 | * |
|---|
| 38 | ***************************************************************************/ |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | /***************************************************************************/ |
|---|
| 44 | /* E X A M P L E S O U R C E C O D E */ |
|---|
| 45 | /* B E G I N */ |
|---|
| 46 | |
|---|
| 47 | #if 0 |
|---|
| 48 | EDeviceErrCode eDevError ; |
|---|
| 49 | unsigned long ulMainSize ; |
|---|
| 50 | unsigned long ulMainErrorFlag ; |
|---|
| 51 | unsigned long ulMainPicInfo ; |
|---|
| 52 | unsigned char * pCCMainBuffer ; |
|---|
| 53 | DCC_OUTBUF_INFO CC608BufInfo ; |
|---|
| 54 | unsigned char * pCCPair ; |
|---|
| 55 | unsigned int NumCCPairs ; |
|---|
| 56 | unsigned int pair ; |
|---|
| 57 | |
|---|
| 58 | do |
|---|
| 59 | { |
|---|
| 60 | /* |
|---|
| 61 | * Get a pointer into the ring buffer for the next |
|---|
| 62 | * user data. The pointer is valid until we call |
|---|
| 63 | * bcmMPIUpdateClosedCaptionStatus(). |
|---|
| 64 | */ |
|---|
| 65 | eDevError = bcmMPIReadClosedCaptionStatus( |
|---|
| 66 | pDevice, /* MPEG device */ |
|---|
| 67 | &m_MpegCCaptionHandle, /* CC handle */ |
|---|
| 68 | &pCCMainBuffer, /* ptr returned here */ |
|---|
| 69 | &ulMainSize, /* size returned here */ |
|---|
| 70 | &ulMainErrorFlag, /* error returned here */ |
|---|
| 71 | &ulMainPicInfo) ; /* info returned here */ |
|---|
| 72 | |
|---|
| 73 | if ( eDevError != eDeviceSuccess ) |
|---|
| 74 | { |
|---|
| 75 | /* handle error condition */ |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | if ( ulMainErrorFlag ) |
|---|
| 79 | { |
|---|
| 80 | /* handle error condition */ |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | /* |
|---|
| 84 | * Did we get anything? If so, parse it and |
|---|
| 85 | * queue up the Closed Captioning for encode. |
|---|
| 86 | */ |
|---|
| 87 | if ( ulMainSize ) |
|---|
| 88 | { |
|---|
| 89 | /* |
|---|
| 90 | * Parse the Picture User Data area(s) returned |
|---|
| 91 | * the the bcmMPIReadClosedCaptionStatus() call. |
|---|
| 92 | */ |
|---|
| 93 | dccerr = DccTransport_Process( |
|---|
| 94 | pTransObj, /* transport object */ |
|---|
| 95 | pCCMainBuffer, /* pInputBuf */ |
|---|
| 96 | ulMainSize, /* InputBufSize */ |
|---|
| 97 | //ulMainPicInfo, /* picture info */ |
|---|
| 98 | &CC608BufInfo, /* 608 output buf descriptor */ |
|---|
| 99 | NULL) ; /* DTVCC output buf descriptor */ |
|---|
| 100 | |
|---|
| 101 | if ( dccerr != dccSuccess ) |
|---|
| 102 | { |
|---|
| 103 | /* handle error condition */ |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | /* |
|---|
| 107 | * Queue up the 608 data for encoding later by the ISR. |
|---|
| 108 | * DccTransport_Process gives us data in groups of 3 |
|---|
| 109 | * bytes. The first is an indicator of which field. |
|---|
| 110 | * The next two bytes are the CC data pair. |
|---|
| 111 | */ |
|---|
| 112 | NumCCPairs = CC608BufInfo.OutputBytesProduced / 3 ; |
|---|
| 113 | |
|---|
| 114 | for ( pair=0 ; pair < NumCCPairs ; pair++) |
|---|
| 115 | { |
|---|
| 116 | if ( CC608BufInfo.pOutputBuf[pair*3] == DCC_608_FIELD_TOP ) |
|---|
| 117 | ulField = CC_QUEUE_FLAG_TOP : |
|---|
| 118 | else |
|---|
| 119 | ulField = CC_QUEUE_FLAG_BOTTOM : |
|---|
| 120 | |
|---|
| 121 | pCCPair = &CC608BufInfo.pOutputBuf[pair*3+1] ; |
|---|
| 122 | ok = bCCEQueueAdd( |
|---|
| 123 | eCCE_VEC1, /* which VEC */ |
|---|
| 124 | ulField, /* which field */ |
|---|
| 125 | pCCPair) ; /* 2 CC bytes */ |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | /* |
|---|
| 129 | * Relinquish access to the buffer. |
|---|
| 130 | */ |
|---|
| 131 | bcmMPIUpdateClosedCaptionStatus( |
|---|
| 132 | pDevice, /* MPEG device */ |
|---|
| 133 | &m_MpegCCaptionHandle, /* CC handle */ |
|---|
| 134 | pCCMainBuffer) ; /* buffer ptr */ |
|---|
| 135 | |
|---|
| 136 | } /* end if ( ulMainSize ) */ |
|---|
| 137 | |
|---|
| 138 | } while ( ulMainSize ) ; |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | #endif |
|---|
| 142 | |
|---|
| 143 | /* E N D */ |
|---|
| 144 | /* E X A M P L E S O U R C E C O D E */ |
|---|
| 145 | /***************************************************************************/ |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | #include "bcmDccTransport.h" |
|---|
| 150 | #include "bcmDccPriv.h" |
|---|
| 151 | #include "bcmDccTransportParse.h" |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | /************************************************************************** |
|---|
| 156 | * |
|---|
| 157 | * Function: DccTransport_Init |
|---|
| 158 | * |
|---|
| 159 | * Inputs: |
|---|
| 160 | * pObj - object to init |
|---|
| 161 | * OutputType - defines which 608 CC type to output |
|---|
| 162 | * |
|---|
| 163 | * Outputs: |
|---|
| 164 | * pObj - object state is modified |
|---|
| 165 | * |
|---|
| 166 | * Returns: dccSuccess or a standard DCCERR error code |
|---|
| 167 | * |
|---|
| 168 | * Description: |
|---|
| 169 | * |
|---|
| 170 | * This function initializes an MPEG CC transport session. |
|---|
| 171 | * |
|---|
| 172 | **************************************************************************/ |
|---|
| 173 | DCCERR |
|---|
| 174 | DccTransport_Init( |
|---|
| 175 | DCC_TRANSPORT_OBJECT * pObj, |
|---|
| 176 | DCC_CC608_TYPE OutputType) |
|---|
| 177 | { |
|---|
| 178 | /* |
|---|
| 179 | * Validate |
|---|
| 180 | */ |
|---|
| 181 | if ( NULL == pObj ) |
|---|
| 182 | { |
|---|
| 183 | DccPrintf(("DccTransport_Init: null pointer as argument\n")) ; |
|---|
| 184 | return(dccErrNullPointer) ; |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | /* |
|---|
| 188 | * Set the 608 output type. |
|---|
| 189 | */ |
|---|
| 190 | switch ( OutputType ) |
|---|
| 191 | { |
|---|
| 192 | case CC608_A53 : |
|---|
| 193 | case CC608_DVS157 : |
|---|
| 194 | case CC608_A53Preferred : |
|---|
| 195 | pObj->CC608Type = OutputType ; |
|---|
| 196 | break ; |
|---|
| 197 | |
|---|
| 198 | default : |
|---|
| 199 | DccPrintf(("DccTransport_Init: bad OutputType 0x%08x\n", OutputType)) ; |
|---|
| 200 | return(dccErrBadOutputType) ; |
|---|
| 201 | break ; |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | /* |
|---|
| 205 | * Initialize the MUX state. This essentially |
|---|
| 206 | * zeroes out all of the type counters. |
|---|
| 207 | */ |
|---|
| 208 | CC608Mux_Init(&pObj->CC608MuxState) ; |
|---|
| 209 | |
|---|
| 210 | /* |
|---|
| 211 | * all done |
|---|
| 212 | */ |
|---|
| 213 | return(dccSuccess) ; |
|---|
| 214 | |
|---|
| 215 | } /* DccTransport_Init */ |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | /************************************************************************** |
|---|
| 219 | * |
|---|
| 220 | * Function: DccTransport_Fini |
|---|
| 221 | * |
|---|
| 222 | * Inputs: |
|---|
| 223 | * pObj - object, previously init'ed |
|---|
| 224 | * |
|---|
| 225 | * Outputs: |
|---|
| 226 | * <none> |
|---|
| 227 | * |
|---|
| 228 | * Returns: dccSuccess or a standard DCCERR error code |
|---|
| 229 | * |
|---|
| 230 | * Description: |
|---|
| 231 | * |
|---|
| 232 | * This function undoes the initialization done by DccTransport_Init. |
|---|
| 233 | * |
|---|
| 234 | **************************************************************************/ |
|---|
| 235 | DCCERR |
|---|
| 236 | DccTransport_Fini(DCC_TRANSPORT_OBJECT * pObj) |
|---|
| 237 | { |
|---|
| 238 | /* nothing to do */ |
|---|
| 239 | return(dccSuccess) ; |
|---|
| 240 | |
|---|
| 241 | } /* DccTransport_Fini */ |
|---|
| 242 | |
|---|
| 243 | |
|---|
| 244 | /************************************************************************** |
|---|
| 245 | * |
|---|
| 246 | * Function: DccTransport_Process |
|---|
| 247 | * |
|---|
| 248 | * Inputs: |
|---|
| 249 | * pObj - object, previously init'ed |
|---|
| 250 | * pInputBuf - input buffer, holds 1/more User Data |
|---|
| 251 | * InputBufSize - size in bytes of input buffer |
|---|
| 252 | * ulPicInfo - picture info from bcmMPIReadCCStatus |
|---|
| 253 | * |
|---|
| 254 | * Outputs: |
|---|
| 255 | * p608BufInfo - describes output buf for 608, or NULL |
|---|
| 256 | * pDTVCCBufInfo - describes output buf for DTVCC, or NULL |
|---|
| 257 | * |
|---|
| 258 | * Returns: dccSuccess or a standard DCCERR error code |
|---|
| 259 | * |
|---|
| 260 | * Description: |
|---|
| 261 | * |
|---|
| 262 | * Reads the input buffer and copies CC data to the output buffer(s). This |
|---|
| 263 | * function parses the looking for DTVCC Closed Captioning data or the type |
|---|
| 264 | * of 608 CC data specified in the DccTransport_Init function. This function |
|---|
| 265 | * scans up to InputBufSize bytes of the pInputBuf buffer. The parsing logic |
|---|
| 266 | * looks for Picture User Data start_codes, namely, the byte sequence 00 00 01 B2. |
|---|
| 267 | * |
|---|
| 268 | * If multiple Picture User Data areas are found, each will be processed in order, |
|---|
| 269 | * and the CC bytes extracted from each will be copied to the output buffer(s). If |
|---|
| 270 | * DTVCC Closed Captioning data is found and if pDTVCCBufInfo is not NULL, then |
|---|
| 271 | * DTVCC data is parsed and copied to pDTVCCBufInfo. |
|---|
| 272 | * |
|---|
| 273 | * If p608BufInfo is not NULL, then this function will copy 608 Closed Captioning |
|---|
| 274 | * data according to the OutputType argument in the DccTransport_Init( ) call: |
|---|
| 275 | * |
|---|
| 276 | * CC608_A53: Only valid CC bytes from ATSC A/53 will be output. |
|---|
| 277 | * CC608_DVS157: Only valid CC Bytes from DVS157 will be output. |
|---|
| 278 | * CC608_A53Preferred: This function will track the presence of both A53 |
|---|
| 279 | * and DVS157 formats. If only one format is detected, |
|---|
| 280 | * it will be output. If both formats are detected, A53 |
|---|
| 281 | * will be output. This algorithm uses a sliding window |
|---|
| 282 | * approach. |
|---|
| 283 | * |
|---|
| 284 | **************************************************************************/ |
|---|
| 285 | DCCERR |
|---|
| 286 | DccTransport_Process( |
|---|
| 287 | DCC_TRANSPORT_OBJECT * pObj, |
|---|
| 288 | unsigned char * pInputBuf, |
|---|
| 289 | unsigned int InputBufSize, |
|---|
| 290 | //unsigned long ulPicInfo, |
|---|
| 291 | DCC_OUTBUF_INFO * p608BufInfo, |
|---|
| 292 | DCC_OUTBUF_INFO * pDTVCCBufInfo) |
|---|
| 293 | { |
|---|
| 294 | DCCERR dccerr = dccSuccess ; |
|---|
| 295 | unsigned int StartCodeIndex ; |
|---|
| 296 | unsigned char * pInputCur = pInputBuf ; |
|---|
| 297 | unsigned int InputCurSize = InputBufSize ; |
|---|
| 298 | |
|---|
| 299 | /* |
|---|
| 300 | * Validate Arguments |
|---|
| 301 | */ |
|---|
| 302 | if ( pObj == NULL || pInputBuf == NULL ) |
|---|
| 303 | { |
|---|
| 304 | DccPrintf(("DccTransport_Process: null pointer as argument\n")) ; |
|---|
| 305 | return(dccErrNullPointer) ; |
|---|
| 306 | } |
|---|
| 307 | |
|---|
| 308 | /* |
|---|
| 309 | * Prep output buffers. |
|---|
| 310 | */ |
|---|
| 311 | if ( p608BufInfo ) |
|---|
| 312 | { |
|---|
| 313 | p608BufInfo->OutputBytesProduced = 0 ; |
|---|
| 314 | p608BufInfo->DccError = dccSuccess ; |
|---|
| 315 | } |
|---|
| 316 | if ( pDTVCCBufInfo ) |
|---|
| 317 | { |
|---|
| 318 | pDTVCCBufInfo->OutputBytesProduced = 0 ; |
|---|
| 319 | pDTVCCBufInfo->DccError = dccSuccess ; |
|---|
| 320 | } |
|---|
| 321 | |
|---|
| 322 | /* |
|---|
| 323 | * Subtract from each type counter. |
|---|
| 324 | */ |
|---|
| 325 | CC608Mux_LeakAll(&pObj->CC608MuxState) ; |
|---|
| 326 | |
|---|
| 327 | /* |
|---|
| 328 | * Loop thru for each user data area. Note that each |
|---|
| 329 | * is delineated by a 4-byte start code. |
|---|
| 330 | */ |
|---|
| 331 | while ( NextStartCode(pInputCur, InputCurSize, &StartCodeIndex) ) |
|---|
| 332 | { |
|---|
| 333 | /* move to the start code, and just beyond it */ |
|---|
| 334 | pInputCur += (StartCodeIndex + 4) ; |
|---|
| 335 | InputCurSize -= (StartCodeIndex + 4) ; |
|---|
| 336 | |
|---|
| 337 | /* |
|---|
| 338 | * Call ParsePicUserDataForCC to do the |
|---|
| 339 | * real work. If it returns an error (dccerr) |
|---|
| 340 | * it's such that we can't continue, so break out. |
|---|
| 341 | */ |
|---|
| 342 | dccerr = ParseOnePicUserDataForCC( |
|---|
| 343 | pObj, /* transport session object */ |
|---|
| 344 | pInputCur, /* input buffer, remaining */ |
|---|
| 345 | InputCurSize, /* input buffer size, remaining */ |
|---|
| 346 | // ulPicInfo, /* picture info from MPEG UD extraction call */ |
|---|
| 347 | p608BufInfo, /* output buffer info for 608 type */ |
|---|
| 348 | pDTVCCBufInfo) ; /* output buffer info for DTVCC type */ |
|---|
| 349 | if ( dccerr ) |
|---|
| 350 | { |
|---|
| 351 | DccPrintf(("DccTransport_Process: parsing error 0x%08x\n", dccerr)) ; |
|---|
| 352 | break ; |
|---|
| 353 | } |
|---|
| 354 | |
|---|
| 355 | } /* end while ( find_next_start_code ) */ |
|---|
| 356 | |
|---|
| 357 | return(dccerr) ; |
|---|
| 358 | |
|---|
| 359 | } /* DccTransport_Process */ |
|---|
| 360 | |
|---|
| 361 | /************************************************************************** |
|---|
| 362 | * |
|---|
| 363 | * Function: DccTransport_QueryDetectedFormats |
|---|
| 364 | * |
|---|
| 365 | * Inputs: |
|---|
| 366 | * pObj - object, previously init'ed |
|---|
| 367 | * |
|---|
| 368 | * Outputs: |
|---|
| 369 | * pDetectedFormats - bitmask, each bit reps one format |
|---|
| 370 | * DCC_TYPE_DVS157 |
|---|
| 371 | * DCC_TYPE_A53_608 |
|---|
| 372 | * DCC_TYPE_A53_DTVCC |
|---|
| 373 | * DCC_TYPE_UNKNOWN |
|---|
| 374 | * |
|---|
| 375 | * Returns: dccSuccess or a standard DCCERR error code |
|---|
| 376 | * |
|---|
| 377 | * Description: |
|---|
| 378 | * |
|---|
| 379 | * This function retrieves a bitmask representing which formats have been |
|---|
| 380 | * detected in the stream. This is useful because on any call to |
|---|
| 381 | * DccTransport_Process, the caller cannot merely look at the number of bytes |
|---|
| 382 | * output for each output buffer to determine the detected formats. |
|---|
| 383 | * |
|---|
| 384 | **************************************************************************/ |
|---|
| 385 | DCCERR |
|---|
| 386 | DccTransport_QueryDetectedFormats( |
|---|
| 387 | DCC_TRANSPORT_OBJECT * pObj, |
|---|
| 388 | unsigned int * pDetectedFormats) |
|---|
| 389 | { |
|---|
| 390 | /* |
|---|
| 391 | * validate |
|---|
| 392 | */ |
|---|
| 393 | if ( NULL == pObj || NULL == pDetectedFormats ) |
|---|
| 394 | { |
|---|
| 395 | DccPrintf(("DccTransport_QueryDetectedFormats: null pointer as argument\n")) ; |
|---|
| 396 | return(dccErrNullPointer) ; |
|---|
| 397 | } |
|---|
| 398 | |
|---|
| 399 | /* |
|---|
| 400 | * clear the bitmask |
|---|
| 401 | */ |
|---|
| 402 | *pDetectedFormats = 0 ; |
|---|
| 403 | |
|---|
| 404 | /* |
|---|
| 405 | * set each bit as appropriate |
|---|
| 406 | */ |
|---|
| 407 | if ( CC608Mux_IsDetected(&pObj->CC608MuxState, cctDVS157) ) |
|---|
| 408 | *pDetectedFormats |= DCC_TYPE_DVS157 ; |
|---|
| 409 | if ( CC608Mux_IsDetected(&pObj->CC608MuxState, cctA053_608) ) |
|---|
| 410 | *pDetectedFormats |= DCC_TYPE_A53_608 ; |
|---|
| 411 | if ( CC608Mux_IsDetected(&pObj->CC608MuxState, cctA053_DTVCC) ) |
|---|
| 412 | *pDetectedFormats |= DCC_TYPE_A53_DTVCC ; |
|---|
| 413 | if ( CC608Mux_IsDetected(&pObj->CC608MuxState, cctUnknown) ) |
|---|
| 414 | *pDetectedFormats |= DCC_TYPE_UNKNOWN ; |
|---|
| 415 | |
|---|
| 416 | return(dccSuccess) ; |
|---|
| 417 | |
|---|
| 418 | } /* DccTransport_QueryDetectedFormats */ |
|---|
| 419 | |
|---|
| 420 | |
|---|
| 421 | |
|---|
| 422 | |
|---|
| 423 | |
|---|
| 424 | |
|---|