| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2003-2010, 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: budp_dccparse.h $ |
|---|
| 11 | * $brcm_Revision: Hydra_Software_Devel/3 $ |
|---|
| 12 | * $brcm_Date: 10/28/10 3:58p $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: /magnum/commonutils/udp/budp_dccparse.h $ |
|---|
| 19 | * |
|---|
| 20 | * Hydra_Software_Devel/3 10/28/10 3:58p darnstein |
|---|
| 21 | * SW3548-2364: trivial implementation of _isr functions for parsing. |
|---|
| 22 | * |
|---|
| 23 | * Hydra_Software_Devel/2 10/21/10 4:38p darnstein |
|---|
| 24 | * SW7401-2571: cut over to the DSS userdata parser that DSS customer |
|---|
| 25 | * engineers perfer. |
|---|
| 26 | * |
|---|
| 27 | * Hydra_Software_Devel/1 7/27/10 5:06p darnstein |
|---|
| 28 | * SW3548-3022: userdata parsing software. |
|---|
| 29 | * |
|---|
| 30 | ***************************************************************************/ |
|---|
| 31 | |
|---|
| 32 | /*= Module Overview ********************************************************* |
|---|
| 33 | <verbatim> |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | Overview |
|---|
| 37 | BUDPCCparse module provides parsing of digital closed caption |
|---|
| 38 | data. Digital closed caption data occurs as userdata in MPEG |
|---|
| 39 | bitstreams. There are three standards supported: DVS 157, ATSC 53, |
|---|
| 40 | and DVS 053. |
|---|
| 41 | |
|---|
| 42 | In general, this software accepts a buffer of data that contains the |
|---|
| 43 | MPEG userdata. It parses out the closed caption data, and returns |
|---|
| 44 | it as a pair of bytes. These two bytes can then be sent directly |
|---|
| 45 | to a digital (EIA-708-B) closed caption encoder. Byte pairs that |
|---|
| 46 | have an associated bIsAnalog value of "true" may be sent directly |
|---|
| 47 | to an analog closed caption (line 21) encoder. |
|---|
| 48 | |
|---|
| 49 | </verbatim> |
|---|
| 50 | ***************************************************************************/ |
|---|
| 51 | |
|---|
| 52 | #ifndef BUDPDCCPARSE_H__ |
|---|
| 53 | #define BUDPDCCPARSE_H__ |
|---|
| 54 | |
|---|
| 55 | #include "bstd.h" |
|---|
| 56 | #include "bavc.h" |
|---|
| 57 | #include "berr.h" |
|---|
| 58 | #include "bavc.h" |
|---|
| 59 | #include "budp.h" |
|---|
| 60 | |
|---|
| 61 | #ifdef __cplusplus |
|---|
| 62 | extern "C" { |
|---|
| 63 | #endif |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | /***************************************************************************** |
|---|
| 67 | * Structures |
|---|
| 68 | *****************************************************************************/ |
|---|
| 69 | |
|---|
| 70 | /*************************************************************************** |
|---|
| 71 | Summary: |
|---|
| 72 | This enum specifies the format used to encode a pair of closed caption data |
|---|
| 73 | bytes into MPEG userdata. |
|---|
| 74 | ***************************************************************************/ |
|---|
| 75 | typedef enum { |
|---|
| 76 | BUDP_DCCparse_Format_Unknown = 0, |
|---|
| 77 | BUDP_DCCparse_Format_DVS157, |
|---|
| 78 | BUDP_DCCparse_Format_ATSC53, |
|---|
| 79 | BUDP_DCCparse_Format_DVS053, |
|---|
| 80 | BUDP_DCCparse_Format_SEI, |
|---|
| 81 | BUDP_DCCparse_Format_SEI2, |
|---|
| 82 | BUDP_DCCparse_Format_AFD53, |
|---|
| 83 | BUDP_DCCparse_Format_Divicom |
|---|
| 84 | } |
|---|
| 85 | BUDP_DCCparse_Format; |
|---|
| 86 | |
|---|
| 87 | /*************************************************************************** |
|---|
| 88 | Summary: |
|---|
| 89 | This structure describes a "piece" of closed caption data extracted |
|---|
| 90 | from MPEG userdata. |
|---|
| 91 | |
|---|
| 92 | Description: |
|---|
| 93 | BUDP_DCCparse_ccdata is a data structure that models |
|---|
| 94 | MPEG syntax within userdata. Mostly, it reflects bitstream |
|---|
| 95 | items that are common among the different standards for |
|---|
| 96 | closed caption data within userdata. |
|---|
| 97 | |
|---|
| 98 | For most applications, the only fields of interest are |
|---|
| 99 | bIsAnalog, polarity, and format. |
|---|
| 100 | |
|---|
| 101 | If set, bIsAnalog indicates that the datum is suitable for |
|---|
| 102 | EIA-608-A analog encoding. If not set, the datum is either |
|---|
| 103 | EIA-708-B only, or could not be parse properly. |
|---|
| 104 | |
|---|
| 105 | If bIsAnalog is set, then the field polarity indicates |
|---|
| 106 | whether the datum should be sent to a top or bottom field |
|---|
| 107 | of an analog video wave form. |
|---|
| 108 | |
|---|
| 109 | The format field indicates the method of encoding the closed |
|---|
| 110 | caption datum into MPEG userdata. This field is important |
|---|
| 111 | because in some bitstreams, multiple copies of the closed |
|---|
| 112 | caption data will be present, with each copy encoded in a |
|---|
| 113 | different format. Before such data can be sent to any sort |
|---|
| 114 | of closed caption processor (analog or digital) one and |
|---|
| 115 | only one format must be chosen by the application designer. |
|---|
| 116 | ***************************************************************************/ |
|---|
| 117 | typedef struct { |
|---|
| 118 | bool bIsAnalog; |
|---|
| 119 | BAVC_Polarity polarity; |
|---|
| 120 | BUDP_DCCparse_Format format; |
|---|
| 121 | uint8_t cc_valid; |
|---|
| 122 | uint8_t cc_priority; |
|---|
| 123 | uint8_t line_offset; |
|---|
| 124 | union { |
|---|
| 125 | uint8_t field_number; /* For DVS 157 formatted data */ |
|---|
| 126 | uint8_t cc_type; /* For all other formatted data */ |
|---|
| 127 | } seq; |
|---|
| 128 | uint8_t cc_data_1; |
|---|
| 129 | uint8_t cc_data_2; |
|---|
| 130 | uint8_t active_format; |
|---|
| 131 | } |
|---|
| 132 | BUDP_DCCparse_ccdata; |
|---|
| 133 | |
|---|
| 134 | /***************************************************************************** |
|---|
| 135 | * Public API |
|---|
| 136 | *****************************************************************************/ |
|---|
| 137 | |
|---|
| 138 | /***************************************************************************** |
|---|
| 139 | Summary: |
|---|
| 140 | Parses digital closed caption data from a buffer of MPEG userdata. |
|---|
| 141 | |
|---|
| 142 | Description: |
|---|
| 143 | This function accepts a "packet" of MPEG userdata and searches it for |
|---|
| 144 | digital closed caption data. It can recognize closed caption data that |
|---|
| 145 | conforms to one of these standards: DVS 157, ATSC 53, or DVS 053. |
|---|
| 146 | |
|---|
| 147 | In order to avoid having an output array of indefinite length, this |
|---|
| 148 | function will only parse at most one "packet" of MPEG userdata from its |
|---|
| 149 | input. A "packet" is defined as the userdata that lies between two |
|---|
| 150 | successive userdata start codes (0x000001B2). Therefore, several calls to |
|---|
| 151 | this function may be necessary to parse out all the userdata. Parsing will |
|---|
| 152 | be complete when the function returns a *pBytesParsed argument such that |
|---|
| 153 | (offset + *pBytesParsed == pUserdata_info->ui32UserDataBufSize). |
|---|
| 154 | |
|---|
| 155 | Consider that the closed caption data can only be |
|---|
| 156 | encoded analog if the associated bIsAnalog field is set. |
|---|
| 157 | This consideration, together with the need to call the |
|---|
| 158 | function multiple times (previous paragraph) implies that |
|---|
| 159 | the typical usage of this function is as follows: |
|---|
| 160 | |
|---|
| 161 | size_t offset = 0; |
|---|
| 162 | while (offset < info->ui32UserDataBufSize) |
|---|
| 163 | { |
|---|
| 164 | eStatus = |
|---|
| 165 | BUDP_DCCparse_isr (info, offset, &bytesParsed, &cc_count, ccdata); |
|---|
| 166 | if (eStatus == BERR_SUCCESS) |
|---|
| 167 | { |
|---|
| 168 | int icount; |
|---|
| 169 | for (icount = 0 ; icount < cc_count ; ++icount) |
|---|
| 170 | { |
|---|
| 171 | BUDP_DCCparse_ccdata* pccdata = &ccdata[icount]; |
|---|
| 172 | if (pccdata->bIsAnalog == true) |
|---|
| 173 | { |
|---|
| 174 | // Send pccdata->cc_data_1 and pccdata->cc_data_2 |
|---|
| 175 | // to analog closed caption encoder, if any. These |
|---|
| 176 | // bytes must be sent on video field with polarity |
|---|
| 177 | // pcc->polarity. |
|---|
| 178 | } |
|---|
| 179 | // Possibly, send pccdata->cc_data_1 and pccdata->cc_data_2 |
|---|
| 180 | // to digital closed caption encoder. The customer must |
|---|
| 181 | // know if EIA-708-B processing is appropriate. |
|---|
| 182 | } |
|---|
| 183 | } |
|---|
| 184 | else if (eStatus == BERR_BUDP_NO_DATA) |
|---|
| 185 | { |
|---|
| 186 | // Just keep looping, there may be more data to process. |
|---|
| 187 | } |
|---|
| 188 | else |
|---|
| 189 | { |
|---|
| 190 | // A real error, get out quick. |
|---|
| 191 | return eStatus; |
|---|
| 192 | } |
|---|
| 193 | offset += bytesParsed; |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | Returns: |
|---|
| 197 | BERR_SUCCESS - The handle was successfully created. |
|---|
| 198 | BERR_INVALID_PARAMETER - One of the supplied parameters was invalid, |
|---|
| 199 | possibly NULL. |
|---|
| 200 | BERR_BUDP_NO_DATA - No closed caption data was found. As the above |
|---|
| 201 | programming example shows, this is not really |
|---|
| 202 | an error. |
|---|
| 203 | BERR_BUDP_PARSE_ERROR - Closed caption data was detected, but could not |
|---|
| 204 | be successfully parsed. |
|---|
| 205 | |
|---|
| 206 | See Also: |
|---|
| 207 | *****************************************************************************/ |
|---|
| 208 | BERR_Code BUDP_DCCparse_isr ( |
|---|
| 209 | const BAVC_USERDATA_info* |
|---|
| 210 | pUserdata_info, /* [in] The MPEG userdata to be parsed. */ |
|---|
| 211 | size_t offset, /* [in] Parsing will start at this offset in the |
|---|
| 212 | input buffer |
|---|
| 213 | userdata_info->pUserDataBuffer. */ |
|---|
| 214 | size_t* pBytesParsed, /* [out] The number of bytes parsed from the |
|---|
| 215 | input buffer |
|---|
| 216 | userdata_info->pUserDataBuffer. */ |
|---|
| 217 | uint8_t* pcc_count, /* [out] The length of the following output |
|---|
| 218 | array. Will be between 0 and 31. */ |
|---|
| 219 | BUDP_DCCparse_ccdata* |
|---|
| 220 | pCCdata /* [out] An array holding extracted closed |
|---|
| 221 | caption data. The user must provide an |
|---|
| 222 | array of length 32, to accomodate the |
|---|
| 223 | maximum data that the standards will |
|---|
| 224 | allow. */ |
|---|
| 225 | ); |
|---|
| 226 | #define BUDP_DCCparse BUDP_DCCparse_isr |
|---|
| 227 | |
|---|
| 228 | /***************************************************************************** |
|---|
| 229 | Summary: |
|---|
| 230 | Parses digital closed caption data from a buffer of SEI userdata. |
|---|
| 231 | |
|---|
| 232 | Description: |
|---|
| 233 | This function accepts a "packet" of SEI userdata and searches |
|---|
| 234 | it for digital closed caption data. SEI is the closed caption |
|---|
| 235 | format for DSS bitstreams that are AVC MPEG-4. The userdata |
|---|
| 236 | occurs in the NAL. |
|---|
| 237 | |
|---|
| 238 | In order to avoid having an output array of indefinite |
|---|
| 239 | length, this function will only parse at most one "packet" |
|---|
| 240 | of userdata from its input. A "packet" is defined as the |
|---|
| 241 | userdata that lies between two successive userdata start |
|---|
| 242 | codes (0x000001B2). Therefore, several calls to this |
|---|
| 243 | function may be necessary to parse out all the userdata. |
|---|
| 244 | Parsing will be complete when the function returns a |
|---|
| 245 | *pBytesParsed argument such that (offset + *pBytesParsed == |
|---|
| 246 | pUserdata_info->ui32UserDataBufSize). |
|---|
| 247 | |
|---|
| 248 | Consider that the closed caption data can only be |
|---|
| 249 | encoded analog if the associated bIsAnalog field is set. |
|---|
| 250 | This consideration, together with the need to call the |
|---|
| 251 | function multiple times (previous paragraph) implies that |
|---|
| 252 | the typical usage of this function is as follows: |
|---|
| 253 | |
|---|
| 254 | size_t offset = 0; |
|---|
| 255 | while (offset < info->ui32UserDataBufSize) |
|---|
| 256 | { |
|---|
| 257 | eStatus = |
|---|
| 258 | BUDP_DCCparse_SEI_isr ( |
|---|
| 259 | info, offset, &bytesParsed, &cc_count, ccdata); |
|---|
| 260 | if (eStatus == BERR_SUCCESS) |
|---|
| 261 | { |
|---|
| 262 | int icount; |
|---|
| 263 | for (icount = 0 ; icount < cc_count ; ++icount) |
|---|
| 264 | { |
|---|
| 265 | BUDP_DCCparse_ccdata* pccdata = &ccdata[icount]; |
|---|
| 266 | if (pccdata->bIsAnalog == true) |
|---|
| 267 | { |
|---|
| 268 | // Send pccdata->cc_data_1 and pccdata->cc_data_2 |
|---|
| 269 | // to analog closed caption encoder, if any. These |
|---|
| 270 | // bytes must be sent on video field with polarity |
|---|
| 271 | // pcc->polarity. |
|---|
| 272 | } |
|---|
| 273 | // Possibly, send pccdata->cc_data_1 and pccdata->cc_data_2 |
|---|
| 274 | // to digital closed caption encoder. The customer must |
|---|
| 275 | // know if EIA-708-B processing is appropriate. |
|---|
| 276 | } |
|---|
| 277 | } |
|---|
| 278 | else if (eStatus == BERR_BUDP_NO_DATA) |
|---|
| 279 | { |
|---|
| 280 | // Just keep looping, there may be more data to process. |
|---|
| 281 | } |
|---|
| 282 | else |
|---|
| 283 | { |
|---|
| 284 | // A real error, get out quick. |
|---|
| 285 | return eStatus; |
|---|
| 286 | } |
|---|
| 287 | offset += bytesParsed; |
|---|
| 288 | } |
|---|
| 289 | |
|---|
| 290 | Returns: |
|---|
| 291 | BERR_SUCCESS - The handle was successfully created. |
|---|
| 292 | BERR_INVALID_PARAMETER - One of the supplied parameters was invalid, |
|---|
| 293 | possibly NULL. |
|---|
| 294 | BERR_BUDP_NO_DATA - No closed caption data was found. As the above |
|---|
| 295 | programming example shows, this is not really |
|---|
| 296 | an error. |
|---|
| 297 | BERR_BUDP_PARSE_ERROR - Closed caption data was detected, but could not |
|---|
| 298 | be successfully parsed. |
|---|
| 299 | |
|---|
| 300 | See Also: |
|---|
| 301 | *****************************************************************************/ |
|---|
| 302 | BERR_Code BUDP_DCCparse_SEI_isr ( |
|---|
| 303 | const BAVC_USERDATA_info* |
|---|
| 304 | pUserdata_info, /* [in] The MPEG userdata to be parsed. */ |
|---|
| 305 | size_t offset, /* [in] Parsing will start at this offset in the |
|---|
| 306 | input buffer |
|---|
| 307 | userdata_info->pUserDataBuffer. */ |
|---|
| 308 | size_t* pBytesParsed, /* [out] The number of bytes parsed from the |
|---|
| 309 | input buffer |
|---|
| 310 | userdata_info->pUserDataBuffer. */ |
|---|
| 311 | uint8_t* pcc_count, /* [out] The length of the following output |
|---|
| 312 | array. Will be between 0 and 31. */ |
|---|
| 313 | BUDP_DCCparse_ccdata* |
|---|
| 314 | pCCdata /* [out] An array holding extracted closed |
|---|
| 315 | caption data. The user must provide an |
|---|
| 316 | array of length 32, to accomodate the |
|---|
| 317 | maximum data that the standards will |
|---|
| 318 | allow. */ |
|---|
| 319 | ); |
|---|
| 320 | #define BUDP_DCCparse_SEI BUDP_DCCparse_SEI_isr |
|---|
| 321 | |
|---|
| 322 | /***************************************************************************** |
|---|
| 323 | Summary: |
|---|
| 324 | Parses digital closed caption data from a buffer of userdata containing |
|---|
| 325 | closed caption data in proprietary "Divicom" format. |
|---|
| 326 | |
|---|
| 327 | Description: |
|---|
| 328 | This function accepts a "packet" of userdata and searches it for |
|---|
| 329 | digital closed caption data. The closed caption data shall be in a |
|---|
| 330 | proprietary format started by DiviCom Inc. |
|---|
| 331 | |
|---|
| 332 | In order to avoid having an output array of indefinite |
|---|
| 333 | length, this function will only parse at most one "packet" |
|---|
| 334 | of userdata from its input. A "packet" is defined as the |
|---|
| 335 | userdata that lies between two successive userdata start |
|---|
| 336 | codes (0x000001B2). Therefore, several calls to this |
|---|
| 337 | function may be necessary to parse out all the userdata. |
|---|
| 338 | Parsing will be complete when the function returns a |
|---|
| 339 | *pBytesParsed argument such that (offset + *pBytesParsed == |
|---|
| 340 | pUserdata_info->ui32UserDataBufSize). |
|---|
| 341 | |
|---|
| 342 | Consider that the closed caption data can only be |
|---|
| 343 | encoded analog if the associated bIsAnalog field is set. |
|---|
| 344 | This consideration, together with the need to call the |
|---|
| 345 | function multiple times (previous paragraph) implies that |
|---|
| 346 | the typical usage of this function is as follows: |
|---|
| 347 | |
|---|
| 348 | size_t offset = 0; |
|---|
| 349 | while (offset < info->ui32UserDataBufSize) |
|---|
| 350 | { |
|---|
| 351 | eStatus = |
|---|
| 352 | BUDP_DCCparse_Divicom_isr ( |
|---|
| 353 | info, offset, &bytesParsed, &cc_count, ccdata); |
|---|
| 354 | if (eStatus == BERR_SUCCESS) |
|---|
| 355 | { |
|---|
| 356 | int icount; |
|---|
| 357 | for (icount = 0 ; icount < cc_count ; ++icount) |
|---|
| 358 | { |
|---|
| 359 | BUDP_DCCparse_ccdata* pccdata = &ccdata[icount]; |
|---|
| 360 | if (pccdata->bIsAnalog == true) |
|---|
| 361 | { |
|---|
| 362 | // Send pccdata->cc_data_1 and pccdata->cc_data_2 |
|---|
| 363 | // to analog closed caption encoder, if any. These |
|---|
| 364 | // bytes must be sent on video field with polarity |
|---|
| 365 | // pcc->polarity. |
|---|
| 366 | } |
|---|
| 367 | // Possibly, send pccdata->cc_data_1 and pccdata->cc_data_2 |
|---|
| 368 | // to digital closed caption encoder. The customer must |
|---|
| 369 | // know if EIA-708-B processing is appropriate. |
|---|
| 370 | } |
|---|
| 371 | } |
|---|
| 372 | else if (eStatus == BERR_BUDP_NO_DATA) |
|---|
| 373 | { |
|---|
| 374 | // Just keep looping, there may be more data to process. |
|---|
| 375 | } |
|---|
| 376 | else |
|---|
| 377 | { |
|---|
| 378 | // A real error, get out quick. |
|---|
| 379 | return eStatus; |
|---|
| 380 | } |
|---|
| 381 | offset += bytesParsed; |
|---|
| 382 | } |
|---|
| 383 | |
|---|
| 384 | Returns: |
|---|
| 385 | BERR_SUCCESS - The handle was successfully created. |
|---|
| 386 | BERR_INVALID_PARAMETER - One of the supplied parameters was invalid, |
|---|
| 387 | possibly NULL. |
|---|
| 388 | BERR_BUDP_NO_DATA - No closed caption data was found. As the above |
|---|
| 389 | programming example shows, this is not really |
|---|
| 390 | an error. |
|---|
| 391 | BERR_BUDP_PARSE_ERROR - Closed caption data was detected, but could not |
|---|
| 392 | be successfully parsed. |
|---|
| 393 | |
|---|
| 394 | See Also: |
|---|
| 395 | *****************************************************************************/ |
|---|
| 396 | BERR_Code BUDP_DCCparse_Divicom_isr ( |
|---|
| 397 | const BAVC_USERDATA_info* |
|---|
| 398 | pUserdata_info, /* [in] The MPEG userdata to be parsed. */ |
|---|
| 399 | size_t offset, /* [in] Parsing will start at this offset in the |
|---|
| 400 | input buffer |
|---|
| 401 | userdata_info->pUserDataBuffer. */ |
|---|
| 402 | size_t* pBytesParsed, /* [out] The number of bytes parsed from the |
|---|
| 403 | input buffer |
|---|
| 404 | userdata_info->pUserDataBuffer. */ |
|---|
| 405 | uint8_t* pcc_count, /* [out] The length of the following output |
|---|
| 406 | array. Will be between 0 and 31. */ |
|---|
| 407 | BUDP_DCCparse_ccdata* |
|---|
| 408 | pCCdata /* [out] An array holding extracted closed |
|---|
| 409 | caption data. The user must provide an |
|---|
| 410 | array of length 32, to accomodate the |
|---|
| 411 | maximum data that the standards will |
|---|
| 412 | allow. */ |
|---|
| 413 | ); |
|---|
| 414 | #define BUDP_DCCparse_Divicom BUDP_DCCparse_Divicom_isr |
|---|
| 415 | |
|---|
| 416 | #ifdef __cplusplus |
|---|
| 417 | } |
|---|
| 418 | #endif |
|---|
| 419 | |
|---|
| 420 | #endif /* BUDPDCCPARSE_H__ */ |
|---|