| 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: bvbilib.c $ |
|---|
| 11 | * $brcm_Revision: Hydra_Software_Devel/22 $ |
|---|
| 12 | * $brcm_Date: 1/8/10 1:12p $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: /magnum/syslib/vbilib/bvbilib.c $ |
|---|
| 19 | * |
|---|
| 20 | * Hydra_Software_Devel/22 1/8/10 1:12p darnstein |
|---|
| 21 | * SW3556-979: I added an API function that points to the oldest piece of |
|---|
| 22 | * data in the encode queue. |
|---|
| 23 | * |
|---|
| 24 | * Hydra_Software_Devel/21 10/31/08 5:43p darnstein |
|---|
| 25 | * PR41248: Port over conventional comments from 7401 branch. |
|---|
| 26 | * |
|---|
| 27 | * Hydra_Software_Devel/20 9/11/07 5:16p darnstein |
|---|
| 28 | * PR25708: First release of SCTE encoder software. |
|---|
| 29 | * |
|---|
| 30 | * Hydra_Software_Devel/19 5/26/06 1:20p darnstein |
|---|
| 31 | * PR21710: A field handle can be dequeued for encoding at any one of |
|---|
| 32 | * three times: top field, bottom field, or FRAME. FRAME is the new |
|---|
| 33 | * choice. The field handles themselves continue to be defined as top |
|---|
| 34 | * field, bottom field, or both. The new logic is when a field handle is |
|---|
| 35 | * dequeued at time FRAME, it is always encoded immediately. The rest of |
|---|
| 36 | * the logic is the same: a "top" field handle is only dequeued and |
|---|
| 37 | * encoded at "top field" time, same for bottoms. When setting up field |
|---|
| 38 | * interrupt callbacks, for progressive video output, the argument |
|---|
| 39 | * BAVC_Polarity_eFrame should be used now. |
|---|
| 40 | * |
|---|
| 41 | * Hydra_Software_Devel/18 3/22/05 11:11a darnstein |
|---|
| 42 | * PR 14477: Measure encode queue depth. For diagnostic purposes. |
|---|
| 43 | * |
|---|
| 44 | * Hydra_Software_Devel/17 2/28/05 5:44p darnstein |
|---|
| 45 | * PR 14040: Don't use BERR_TRACE() when a "queue full" condition is |
|---|
| 46 | * encountered. This wil prevent the complaints from flooding in at 50 to |
|---|
| 47 | * 60 Hz. |
|---|
| 48 | * |
|---|
| 49 | * Hydra_Software_Devel/16 2/28/05 2:25p darnstein |
|---|
| 50 | * PR 14040: BVBIlib_Encode_Enqueue_isr() simply refuses service if the |
|---|
| 51 | * BVBIlib encoding queue is full. |
|---|
| 52 | * |
|---|
| 53 | * Hydra_Software_Devel/15 11/30/04 4:25p darnstein |
|---|
| 54 | * PR 13391: Handle an error condition a bit more nicely. In reality, |
|---|
| 55 | * this is only an improvement if the user has passed in a bad parameter |
|---|
| 56 | * to BVBIlib_Decode_Data_isr(). |
|---|
| 57 | * |
|---|
| 58 | * Hydra_Software_Devel/14 11/11/04 2:09p darnstein |
|---|
| 59 | * PR 12900: Call BDBG_WRN when queue overflows. |
|---|
| 60 | * |
|---|
| 61 | * Hydra_Software_Devel/13 7/27/04 11:11a darnstein |
|---|
| 62 | * PR 9080: don't use private functions to access field handle usage count |
|---|
| 63 | * in BVBI porting interface. It is against the rules. |
|---|
| 64 | * |
|---|
| 65 | * Hydra_Software_Devel/12 6/17/04 5:58p darnstein |
|---|
| 66 | * PR 9080: special handling when encoding field handles with polarity |
|---|
| 67 | * mask zero. Before, placing such a field handle on the encode queue |
|---|
| 68 | * would stall the queue forever. |
|---|
| 69 | * |
|---|
| 70 | * Hydra_Software_Devel/11 2/27/04 6:16p darnstein |
|---|
| 71 | * PR 9080: fix misuse of BDBG_ASSERT macro. |
|---|
| 72 | * |
|---|
| 73 | * Hydra_Software_Devel/10 2/9/04 10:30a darnstein |
|---|
| 74 | * PR 9080: Add function BERR_Code BVBIlib_Encode_NoData_isr() to API. |
|---|
| 75 | * Bug fix: In BVBIlib_encode_data_isr(), if next field handle has the |
|---|
| 76 | * wrong parity, then instruct BVBI module to encode nothing for next |
|---|
| 77 | * field. |
|---|
| 78 | * |
|---|
| 79 | * Hydra_Software_Devel/9 1/30/04 3:07p darnstein |
|---|
| 80 | * PR 9080: fix a stupid bug in the "flush" function. |
|---|
| 81 | * |
|---|
| 82 | * Hydra_Software_Devel/8 1/27/04 6:23p darnstein |
|---|
| 83 | * PR 9080: Don't check for overrun errors on encoding. It is only |
|---|
| 84 | * possible for closed caption encoding, anyway. |
|---|
| 85 | * |
|---|
| 86 | * Hydra_Software_Devel/7 1/15/04 4:34p darnstein |
|---|
| 87 | * PR 9080: fix a problem with usage count management of field handles. |
|---|
| 88 | * |
|---|
| 89 | * Hydra_Software_Devel/6 1/8/04 7:25p darnstein |
|---|
| 90 | * PR 9080: Add capability to query for encoding errors from field |
|---|
| 91 | * handles. Bug fixes. |
|---|
| 92 | * |
|---|
| 93 | * Hydra_Software_Devel/5 12/19/03 5:09p darnstein |
|---|
| 94 | * PR 9080: several changes. Including: adapt to changed BAVC enum for |
|---|
| 95 | * field polarity. |
|---|
| 96 | * |
|---|
| 97 | * Hydra_Software_Devel/4 12/3/03 2:54p darnstein |
|---|
| 98 | * Add function BVBIlib_Encode_Flush_isr(). |
|---|
| 99 | * |
|---|
| 100 | * Hydra_Software_Devel/3 10/21/03 3:01p darnstein |
|---|
| 101 | * Fix usage of BDBG_ENTER(), BDBG_LEAVE(). |
|---|
| 102 | * |
|---|
| 103 | * Hydra_Software_Devel/2 10/17/03 3:46p darnstein |
|---|
| 104 | * Encoding function turns of VBI if there is no queued data for it to |
|---|
| 105 | * encode. |
|---|
| 106 | * |
|---|
| 107 | * Hydra_Software_Devel/1 10/14/03 11:31a darnstein |
|---|
| 108 | * Initial version |
|---|
| 109 | * |
|---|
| 110 | ***************************************************************************/ |
|---|
| 111 | #include "bstd.h" |
|---|
| 112 | #include "berr.h" |
|---|
| 113 | #include "berr_ids.h" |
|---|
| 114 | #include "bdbg.h" /* Dbglib */ |
|---|
| 115 | #include "bkni.h" /* malloc */ |
|---|
| 116 | #include "bvbi.h" /* VBI p.i. API */ |
|---|
| 117 | #include "bvbi_prot.h" /* VBI p.i. protected data structures */ |
|---|
| 118 | #include "bvbilib.h" /* This module. */ |
|---|
| 119 | #include "bvbilib_priv.h" /* VBI lib internal data structures */ |
|---|
| 120 | |
|---|
| 121 | BDBG_MODULE(BVBIlib); |
|---|
| 122 | |
|---|
| 123 | /*************************************************************************** |
|---|
| 124 | * Forward declarations of static (private) functions |
|---|
| 125 | ***************************************************************************/ |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | /*************************************************************************** |
|---|
| 129 | * Implementation of "BVBIlib_" API functions |
|---|
| 130 | ***************************************************************************/ |
|---|
| 131 | |
|---|
| 132 | /*************************************************************************** |
|---|
| 133 | * |
|---|
| 134 | */ |
|---|
| 135 | BERR_Code BVBIlib_Open( |
|---|
| 136 | BVBIlib_Handle *pVbilHandle, |
|---|
| 137 | BVBI_Handle vbiHandle |
|---|
| 138 | ) |
|---|
| 139 | { |
|---|
| 140 | BVBIlib_P_Handle *pVbilib; |
|---|
| 141 | |
|---|
| 142 | BDBG_ENTER(BVBIlib_Open); |
|---|
| 143 | |
|---|
| 144 | if((!pVbilHandle) || |
|---|
| 145 | (!vbiHandle) ) |
|---|
| 146 | { |
|---|
| 147 | BDBG_ERR(("Invalid parameter\n")); |
|---|
| 148 | BDBG_LEAVE(BVBIlib_Open); |
|---|
| 149 | return BERR_TRACE(BERR_INVALID_PARAMETER); |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | /* Alloc the main VBI context. */ |
|---|
| 153 | pVbilib = (BVBIlib_P_Handle*)(BKNI_Malloc(sizeof(BVBIlib_P_Handle))); |
|---|
| 154 | |
|---|
| 155 | if(!pVbilib) |
|---|
| 156 | { |
|---|
| 157 | return BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY); |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | /* Clear out the context and set defaults. */ |
|---|
| 161 | BKNI_Memset((void*)pVbilib, 0x0, sizeof(BVBIlib_P_Handle)); |
|---|
| 162 | |
|---|
| 163 | /* Initialize magic number to the size of the struct */ |
|---|
| 164 | pVbilib->ulBlackMagic = sizeof(BVBIlib_P_Handle); |
|---|
| 165 | |
|---|
| 166 | /* Store the VBI handle for later use */ |
|---|
| 167 | pVbilib->hBvbi = vbiHandle; |
|---|
| 168 | |
|---|
| 169 | /* Initialize empty lists of decode and encode contexts */ |
|---|
| 170 | BLST_Q_INIT(&pVbilib->decode_contexts); |
|---|
| 171 | BLST_Q_INIT(&pVbilib->encode_contexts); |
|---|
| 172 | |
|---|
| 173 | /* All done. now return the new fresh context to user. */ |
|---|
| 174 | *pVbilHandle = (BVBIlib_Handle)pVbilib; |
|---|
| 175 | |
|---|
| 176 | BDBG_LEAVE(BVBIlib_Open); |
|---|
| 177 | return BERR_SUCCESS; |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | /*************************************************************************** |
|---|
| 182 | * |
|---|
| 183 | */ |
|---|
| 184 | void BVBIlib_Close( BVBIlib_Handle vbilHandle ) |
|---|
| 185 | { |
|---|
| 186 | BVBIlib_P_Handle *pVbil; |
|---|
| 187 | |
|---|
| 188 | BDBG_ENTER(BVBIlib_Close); |
|---|
| 189 | |
|---|
| 190 | /* check parameters */ |
|---|
| 191 | BVBILIB_P_GET_CONTEXT(vbilHandle, pVbil); |
|---|
| 192 | BDBG_ASSERT (pVbil != NULL); |
|---|
| 193 | |
|---|
| 194 | /* Refuse service if user left any decoder objects open */ |
|---|
| 195 | BDBG_ASSERT (BLST_Q_EMPTY (&pVbil->decode_contexts)); |
|---|
| 196 | |
|---|
| 197 | /* Refuse service if user left any encoder objects open */ |
|---|
| 198 | BDBG_ASSERT (BLST_Q_EMPTY (&pVbil->encode_contexts)); |
|---|
| 199 | |
|---|
| 200 | /* The handle is about to become invalid */ |
|---|
| 201 | pVbil->ulBlackMagic = 0; |
|---|
| 202 | |
|---|
| 203 | /* Release context in system memory */ |
|---|
| 204 | BKNI_Free((void*)pVbil); |
|---|
| 205 | |
|---|
| 206 | BDBG_LEAVE(BVBIlib_Close); |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | /*************************************************************************** |
|---|
| 211 | * |
|---|
| 212 | */ |
|---|
| 213 | BERR_Code BVBIlib_Decode_Create( |
|---|
| 214 | BVBIlib_Handle vbilHandle, |
|---|
| 215 | BVBIlib_List_Handle vbillHandle, |
|---|
| 216 | BVBI_Decode_Handle decHdl, |
|---|
| 217 | BVBIlib_Decode_Handle * pDeclHdl ) |
|---|
| 218 | { |
|---|
| 219 | BVBIlib_P_Handle *pVbil; |
|---|
| 220 | BVBIlib_P_Decode_Handle *pVbildec; |
|---|
| 221 | |
|---|
| 222 | BDBG_ENTER(BVBIlib_Decode_Create); |
|---|
| 223 | |
|---|
| 224 | BVBILIB_P_GET_CONTEXT(vbilHandle, pVbil); |
|---|
| 225 | if((!pVbil ) || |
|---|
| 226 | (!vbillHandle) || |
|---|
| 227 | (!decHdl ) || |
|---|
| 228 | (!pDeclHdl ) ) |
|---|
| 229 | { |
|---|
| 230 | BDBG_ERR(("Invalid parameter\n")); |
|---|
| 231 | return BERR_TRACE(BERR_INVALID_PARAMETER); |
|---|
| 232 | } |
|---|
| 233 | |
|---|
| 234 | /* Alloc the main context. */ |
|---|
| 235 | pVbildec = |
|---|
| 236 | (BVBIlib_P_Decode_Handle*)(BKNI_Malloc( |
|---|
| 237 | sizeof(BVBIlib_P_Decode_Handle))); |
|---|
| 238 | if(!pVbildec) |
|---|
| 239 | { |
|---|
| 240 | return BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY); |
|---|
| 241 | } |
|---|
| 242 | |
|---|
| 243 | /* TODO: verify that the supplied VBI_Handle "owns" the supplied |
|---|
| 244 | VBI_Decode_Handle */ |
|---|
| 245 | |
|---|
| 246 | /* Clear out the context and set defaults. */ |
|---|
| 247 | BKNI_Memset((void*)pVbildec, 0x0, sizeof(BVBIlib_P_Decode_Handle)); |
|---|
| 248 | |
|---|
| 249 | /* Initialize magic number to the size of the struct */ |
|---|
| 250 | pVbildec->ulBlackMagic = sizeof(BVBIlib_P_Decode_Handle); |
|---|
| 251 | |
|---|
| 252 | /* Store all handles passed in */ |
|---|
| 253 | pVbildec->pVbilib = pVbil; |
|---|
| 254 | pVbildec->hVbiDec = decHdl; |
|---|
| 255 | pVbildec->hVbill = vbillHandle; |
|---|
| 256 | |
|---|
| 257 | /* Join up with the controlling BVBIlib_Handle */ |
|---|
| 258 | BLST_Q_INSERT_HEAD (&pVbil->decode_contexts, pVbildec, link); |
|---|
| 259 | |
|---|
| 260 | /* All done. now return the new fresh context to user. */ |
|---|
| 261 | *pDeclHdl = (BVBIlib_Decode_Handle)pVbildec; |
|---|
| 262 | |
|---|
| 263 | BDBG_LEAVE(BVBIlib_Decode_Create); |
|---|
| 264 | return BERR_SUCCESS; |
|---|
| 265 | } |
|---|
| 266 | |
|---|
| 267 | |
|---|
| 268 | /*************************************************************************** |
|---|
| 269 | * |
|---|
| 270 | */ |
|---|
| 271 | BERR_Code BVBIlib_Encode_Create( |
|---|
| 272 | BVBIlib_Handle vbilHandle, |
|---|
| 273 | BVBIlib_List_Handle vbillHandle, |
|---|
| 274 | BVBI_Encode_Handle encHdl, |
|---|
| 275 | int nMaxQueue, |
|---|
| 276 | BVBIlib_Encode_Handle * pEnclHdl ) |
|---|
| 277 | { |
|---|
| 278 | BVBIlib_P_Handle *pVbil; |
|---|
| 279 | BVBIlib_P_Encode_Handle *pVbilenc; |
|---|
| 280 | BVBIlib_P_FieldHanger *hanger; |
|---|
| 281 | int iHandle; |
|---|
| 282 | |
|---|
| 283 | BDBG_ENTER(BVBIlib_Encode_Create); |
|---|
| 284 | |
|---|
| 285 | BVBILIB_P_GET_CONTEXT(vbilHandle, pVbil); |
|---|
| 286 | if((!pVbil ) || |
|---|
| 287 | (!vbillHandle) || |
|---|
| 288 | (!encHdl ) || |
|---|
| 289 | (!pEnclHdl ) ) |
|---|
| 290 | { |
|---|
| 291 | BDBG_ERR(("Invalid parameter\n")); |
|---|
| 292 | return BERR_TRACE(BERR_INVALID_PARAMETER); |
|---|
| 293 | } |
|---|
| 294 | |
|---|
| 295 | /* Alloc the main context. */ |
|---|
| 296 | pVbilenc = |
|---|
| 297 | (BVBIlib_P_Encode_Handle*)(BKNI_Malloc( |
|---|
| 298 | sizeof(BVBIlib_P_Encode_Handle))); |
|---|
| 299 | if(!pVbilenc) |
|---|
| 300 | { |
|---|
| 301 | return BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY); |
|---|
| 302 | } |
|---|
| 303 | |
|---|
| 304 | /* TODO: verify that the supplied VBI_Handle "owns" the supplied |
|---|
| 305 | VBI_Encode_Handle */ |
|---|
| 306 | |
|---|
| 307 | /* Clear out the context and set defaults. */ |
|---|
| 308 | BKNI_Memset((void*)pVbilenc, 0x0, sizeof(BVBIlib_P_Encode_Handle)); |
|---|
| 309 | |
|---|
| 310 | /* Initialize magic number to the size of the struct */ |
|---|
| 311 | pVbilenc->ulBlackMagic = sizeof(BVBIlib_P_Encode_Handle); |
|---|
| 312 | |
|---|
| 313 | /* Store handles and options passed in */ |
|---|
| 314 | pVbilenc->pVbilib = pVbil; |
|---|
| 315 | pVbilenc->hVbiEnc = encHdl; |
|---|
| 316 | pVbilenc->hVbill = vbillHandle; |
|---|
| 317 | pVbilenc->nMaxQueue = nMaxQueue; |
|---|
| 318 | |
|---|
| 319 | /* Join up with the controlling BVBIlib_Handle */ |
|---|
| 320 | BLST_Q_INSERT_HEAD (&pVbil->encode_contexts, pVbilenc, link); |
|---|
| 321 | |
|---|
| 322 | /* Initialize empty lists of field handle hangers */ |
|---|
| 323 | BLST_Q_INIT(&pVbilenc->encode_queue); |
|---|
| 324 | pVbilenc->encode_queue_length = 0; |
|---|
| 325 | BLST_Q_INIT(&pVbilenc->empty_hangers); |
|---|
| 326 | |
|---|
| 327 | /* Create a sufficient number of empty handle hangers */ |
|---|
| 328 | for (iHandle = 0 ; iHandle < nMaxQueue ; ++iHandle) |
|---|
| 329 | { |
|---|
| 330 | hanger = |
|---|
| 331 | (BVBIlib_P_FieldHanger*)(BKNI_Malloc( |
|---|
| 332 | sizeof(BVBIlib_P_FieldHanger))); |
|---|
| 333 | if(!hanger) |
|---|
| 334 | { |
|---|
| 335 | BVBIlib_Encode_Destroy ((BVBIlib_Encode_Handle)pVbilenc); |
|---|
| 336 | BDBG_LEAVE(BVBIlib_Encode_Create); |
|---|
| 337 | return BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY); |
|---|
| 338 | } |
|---|
| 339 | hanger->hField = NULL; |
|---|
| 340 | BLST_Q_INSERT_HEAD (&pVbilenc->empty_hangers, hanger, link); |
|---|
| 341 | } |
|---|
| 342 | |
|---|
| 343 | /* All done. now return the new fresh context to user. */ |
|---|
| 344 | *pEnclHdl = (BVBIlib_Encode_Handle)pVbilenc; |
|---|
| 345 | |
|---|
| 346 | BDBG_LEAVE(BVBIlib_Encode_Create); |
|---|
| 347 | return BERR_SUCCESS; |
|---|
| 348 | } |
|---|
| 349 | |
|---|
| 350 | |
|---|
| 351 | /*************************************************************************** |
|---|
| 352 | * |
|---|
| 353 | */ |
|---|
| 354 | BERR_Code BVBIlib_Decode_Destroy( BVBIlib_Decode_Handle declHdl ) |
|---|
| 355 | { |
|---|
| 356 | BVBIlib_P_Decode_Handle *pVbildec; |
|---|
| 357 | |
|---|
| 358 | BDBG_ENTER(BVBIlib_Decode_Destroy); |
|---|
| 359 | |
|---|
| 360 | /* check parameters */ |
|---|
| 361 | BVBILIB_P_GET_DECODE_CONTEXT(declHdl, pVbildec); |
|---|
| 362 | if(!pVbildec) |
|---|
| 363 | { |
|---|
| 364 | BDBG_ERR(("Invalid parameter\n")); |
|---|
| 365 | return BERR_TRACE(BERR_INVALID_PARAMETER); |
|---|
| 366 | } |
|---|
| 367 | |
|---|
| 368 | /* Unlink from parent handle */ |
|---|
| 369 | BLST_Q_REMOVE (&pVbildec->pVbilib->decode_contexts, pVbildec, link); |
|---|
| 370 | |
|---|
| 371 | /* The handle is now invalid */ |
|---|
| 372 | pVbildec->ulBlackMagic = 0; |
|---|
| 373 | |
|---|
| 374 | /* Release context in system memory */ |
|---|
| 375 | BKNI_Free((void*)pVbildec); |
|---|
| 376 | |
|---|
| 377 | BDBG_LEAVE(BVBIlib_Decode_Destroy); |
|---|
| 378 | return BERR_SUCCESS; |
|---|
| 379 | } |
|---|
| 380 | |
|---|
| 381 | |
|---|
| 382 | /*************************************************************************** |
|---|
| 383 | * |
|---|
| 384 | */ |
|---|
| 385 | BERR_Code BVBIlib_Encode_Destroy( BVBIlib_Encode_Handle enclHdl ) |
|---|
| 386 | { |
|---|
| 387 | BVBIlib_P_Encode_Handle *pVbilenc; |
|---|
| 388 | BVBIlib_P_FieldHanger *hanger; |
|---|
| 389 | BERR_Code eErr = BERR_SUCCESS; |
|---|
| 390 | |
|---|
| 391 | BDBG_ENTER(BVBIlib_Encode_Destroy); |
|---|
| 392 | |
|---|
| 393 | /* check parameters */ |
|---|
| 394 | BVBILIB_P_GET_ENCODE_CONTEXT(enclHdl, pVbilenc); |
|---|
| 395 | if(!pVbilenc) |
|---|
| 396 | { |
|---|
| 397 | BDBG_ERR(("Invalid parameter\n")); |
|---|
| 398 | return BERR_TRACE(BERR_INVALID_PARAMETER); |
|---|
| 399 | } |
|---|
| 400 | |
|---|
| 401 | /* Unlink from parent handle */ |
|---|
| 402 | BLST_Q_REMOVE (&pVbilenc->pVbilib->encode_contexts, pVbilenc, link); |
|---|
| 403 | |
|---|
| 404 | /* Clear out list of unused field handle hangers */ |
|---|
| 405 | /* coverity[alias] */ |
|---|
| 406 | /* coverity[use_after_free] */ |
|---|
| 407 | while ((hanger = BLST_Q_FIRST (&pVbilenc->empty_hangers)) != NULL) |
|---|
| 408 | { |
|---|
| 409 | BLST_Q_REMOVE (&pVbilenc->empty_hangers, hanger, link); |
|---|
| 410 | /* coverity[freed_arg] */ |
|---|
| 411 | BKNI_Free ((void*)hanger); |
|---|
| 412 | } |
|---|
| 413 | |
|---|
| 414 | /* Complain if user still has some field handles in queue */ |
|---|
| 415 | if (!BLST_Q_EMPTY (&pVbilenc->encode_queue)) |
|---|
| 416 | { |
|---|
| 417 | eErr = BVBIlib_USER_LEAK; |
|---|
| 418 | } |
|---|
| 419 | |
|---|
| 420 | /* The handle is now invalid */ |
|---|
| 421 | pVbilenc->ulBlackMagic = 0; |
|---|
| 422 | |
|---|
| 423 | /* Release context in system memory */ |
|---|
| 424 | BKNI_Free((void*)pVbilenc); |
|---|
| 425 | |
|---|
| 426 | BDBG_LEAVE(BVBIlib_Encode_Destroy); |
|---|
| 427 | return eErr; |
|---|
| 428 | } |
|---|
| 429 | |
|---|
| 430 | |
|---|
| 431 | /*************************************************************************** |
|---|
| 432 | * |
|---|
| 433 | */ |
|---|
| 434 | BERR_Code BVBIlib_Decode_Data_isr( |
|---|
| 435 | BVBIlib_Decode_Handle declHdl, |
|---|
| 436 | BVBI_Field_Handle * pFieldHandle, |
|---|
| 437 | BAVC_Polarity polarity |
|---|
| 438 | ) |
|---|
| 439 | { |
|---|
| 440 | BVBIlib_P_Decode_Handle *pVbildec; |
|---|
| 441 | BVBI_Field_Handle hField = 0; |
|---|
| 442 | BERR_Code eErr = BERR_SUCCESS; |
|---|
| 443 | |
|---|
| 444 | BDBG_ENTER(BVBIlib_Decode_Data_isr); |
|---|
| 445 | |
|---|
| 446 | /* check parameters */ |
|---|
| 447 | BVBILIB_P_GET_DECODE_CONTEXT(declHdl, pVbildec); |
|---|
| 448 | if(!pVbildec) |
|---|
| 449 | { |
|---|
| 450 | BDBG_ERR(("Invalid parameter\n")); |
|---|
| 451 | return BERR_TRACE(BERR_INVALID_PARAMETER); |
|---|
| 452 | } |
|---|
| 453 | |
|---|
| 454 | /* Obtain a free field handle */ |
|---|
| 455 | eErr = BVBIlib_List_Obtain_isr (pVbildec->hVbill, &hField); |
|---|
| 456 | if (eErr != BERR_SUCCESS) |
|---|
| 457 | { |
|---|
| 458 | hField = 0; |
|---|
| 459 | BDBG_LEAVE(BVBIlib_Decode_Data_isr); |
|---|
| 460 | return eErr; |
|---|
| 461 | } |
|---|
| 462 | |
|---|
| 463 | /* Call into BVBI module to decode */ |
|---|
| 464 | eErr = BVBI_Decode_Data_isr (pVbildec->hVbiDec, hField, polarity); |
|---|
| 465 | |
|---|
| 466 | /* Prevent a memory leak */ |
|---|
| 467 | if (eErr != BERR_SUCCESS) |
|---|
| 468 | { |
|---|
| 469 | BVBIlib_List_Return_isr (pVbildec->hVbill, hField); |
|---|
| 470 | hField = 0; |
|---|
| 471 | } |
|---|
| 472 | |
|---|
| 473 | /* Return data to caller */ |
|---|
| 474 | *pFieldHandle = hField; |
|---|
| 475 | |
|---|
| 476 | BDBG_LEAVE(BVBIlib_Decode_Data_isr); |
|---|
| 477 | return eErr; |
|---|
| 478 | } |
|---|
| 479 | |
|---|
| 480 | |
|---|
| 481 | /*************************************************************************** |
|---|
| 482 | * |
|---|
| 483 | */ |
|---|
| 484 | BERR_Code BVBIlib_Encode_Enqueue_isr( |
|---|
| 485 | BVBIlib_Encode_Handle enclHdl, |
|---|
| 486 | BVBI_Field_Handle fieldHandle |
|---|
| 487 | ) |
|---|
| 488 | { |
|---|
| 489 | BVBIlib_P_Encode_Handle *pVbilenc; |
|---|
| 490 | BVBIlib_P_FieldHanger *hanger; |
|---|
| 491 | |
|---|
| 492 | BDBG_ENTER(BVBIlib_Encode_Enqueue_isr); |
|---|
| 493 | |
|---|
| 494 | /* check parameters */ |
|---|
| 495 | BVBILIB_P_GET_ENCODE_CONTEXT(enclHdl, pVbilenc); |
|---|
| 496 | if(!pVbilenc) |
|---|
| 497 | { |
|---|
| 498 | BDBG_ERR(("Invalid parameter\n")); |
|---|
| 499 | return BERR_TRACE(BERR_INVALID_PARAMETER); |
|---|
| 500 | } |
|---|
| 501 | |
|---|
| 502 | /* If there are no empty hangers available */ |
|---|
| 503 | if ((hanger = BLST_Q_FIRST (&pVbilenc->empty_hangers)) == NULL) |
|---|
| 504 | { |
|---|
| 505 | /* The input queue must be full. Deny service. */ |
|---|
| 506 | return BVBIlib_QUEUE_FULL; |
|---|
| 507 | /* Programming note: no BERR_TRACE(), because this statement is likely |
|---|
| 508 | to occur 50 to 60 times per second if it occurs at all. */ |
|---|
| 509 | } |
|---|
| 510 | |
|---|
| 511 | /* Use the first empty hanger (obtained above) */ |
|---|
| 512 | BLST_Q_REMOVE (&pVbilenc->empty_hangers, hanger, link); |
|---|
| 513 | |
|---|
| 514 | /* Enqueue caller's data for subsequent encoding */ |
|---|
| 515 | hanger->hField = fieldHandle; |
|---|
| 516 | BLST_Q_INSERT_TAIL (&pVbilenc->encode_queue, hanger, link); |
|---|
| 517 | ++pVbilenc->encode_queue_length; |
|---|
| 518 | |
|---|
| 519 | /* Increment use count of field handle */ |
|---|
| 520 | BVBI_Field_Increment_UsageCount_isr (fieldHandle); |
|---|
| 521 | |
|---|
| 522 | BDBG_LEAVE(BVBIlib_Encode_Enqueue_isr); |
|---|
| 523 | return BERR_SUCCESS; |
|---|
| 524 | } |
|---|
| 525 | |
|---|
| 526 | |
|---|
| 527 | /*************************************************************************** |
|---|
| 528 | * |
|---|
| 529 | */ |
|---|
| 530 | BERR_Code BVBIlib_Encode_Data_isr( |
|---|
| 531 | BVBIlib_Encode_Handle enclHdl, |
|---|
| 532 | BAVC_Polarity polarity |
|---|
| 533 | ) |
|---|
| 534 | { |
|---|
| 535 | BVBIlib_P_Encode_Handle *pVbilenc; |
|---|
| 536 | BVBIlib_P_FieldHanger *hanger; |
|---|
| 537 | BERR_Code eErr = BERR_SUCCESS; |
|---|
| 538 | |
|---|
| 539 | BDBG_ENTER(BVBIlib_Encode_Data_isr); |
|---|
| 540 | |
|---|
| 541 | /* check parameters */ |
|---|
| 542 | BVBILIB_P_GET_ENCODE_CONTEXT(enclHdl, pVbilenc); |
|---|
| 543 | if(!pVbilenc) |
|---|
| 544 | { |
|---|
| 545 | BDBG_ERR(("Invalid parameter\n")); |
|---|
| 546 | return BERR_TRACE(BERR_INVALID_PARAMETER); |
|---|
| 547 | } |
|---|
| 548 | |
|---|
| 549 | /* If there is a queued field handle available */ |
|---|
| 550 | if ((hanger = BLST_Q_FIRST (&pVbilenc->encode_queue)) != NULL) |
|---|
| 551 | { |
|---|
| 552 | /* Check polarity */ |
|---|
| 553 | uint32_t myMask; |
|---|
| 554 | uint32_t fieldMask; |
|---|
| 555 | myMask = (uint32_t)1 << (uint32_t)polarity; |
|---|
| 556 | eErr = BVBI_Field_GetPolarity_isr (hanger->hField, &fieldMask); |
|---|
| 557 | BDBG_ASSERT (eErr == BERR_SUCCESS); |
|---|
| 558 | if (fieldMask == 0) |
|---|
| 559 | { |
|---|
| 560 | /* A field handle with no polarity. Get rid of it, or |
|---|
| 561 | * it will stay in the queue forever. The following code |
|---|
| 562 | * block is a repeat of what appears below, but without |
|---|
| 563 | * comments. |
|---|
| 564 | */ |
|---|
| 565 | BLST_Q_REMOVE (&pVbilenc->encode_queue, hanger, link); |
|---|
| 566 | --pVbilenc->encode_queue_length; |
|---|
| 567 | BVBI_Field_Decrement_UsageCount_isr (hanger->hField); |
|---|
| 568 | if (BVBI_Field_Get_UsageCount_isr (hanger->hField) == 0) |
|---|
| 569 | { |
|---|
| 570 | BVBIlib_List_Return_isr (pVbilenc->hVbill, hanger->hField); |
|---|
| 571 | } |
|---|
| 572 | hanger->hField = NULL; |
|---|
| 573 | BLST_Q_INSERT_TAIL (&pVbilenc->empty_hangers, hanger, link); |
|---|
| 574 | |
|---|
| 575 | /* Cause the encoder hardware to output no VBI next field */ |
|---|
| 576 | eErr = BVBI_Encode_Data_isr (pVbilenc->hVbiEnc, NULL, polarity); |
|---|
| 577 | } |
|---|
| 578 | else if ((polarity == BAVC_Polarity_eFrame) || |
|---|
| 579 | ((myMask & fieldMask) == myMask ) ) |
|---|
| 580 | { |
|---|
| 581 | /* |
|---|
| 582 | * Normal case |
|---|
| 583 | */ |
|---|
| 584 | /* Remove from input queue */ |
|---|
| 585 | BLST_Q_REMOVE (&pVbilenc->encode_queue, hanger, link); |
|---|
| 586 | --pVbilenc->encode_queue_length; |
|---|
| 587 | |
|---|
| 588 | /* Give to hardware for encoding at next field */ |
|---|
| 589 | eErr = |
|---|
| 590 | BVBI_Encode_Data_isr ( |
|---|
| 591 | pVbilenc->hVbiEnc, hanger->hField, polarity); |
|---|
| 592 | |
|---|
| 593 | /* Decrement use count of field handle */ |
|---|
| 594 | BVBI_Field_Decrement_UsageCount_isr (hanger->hField); |
|---|
| 595 | |
|---|
| 596 | /* Recycle the field handle if appropriate */ |
|---|
| 597 | if (BVBI_Field_Get_UsageCount_isr (hanger->hField) == 0) |
|---|
| 598 | { |
|---|
| 599 | BVBIlib_List_Return_isr (pVbilenc->hVbill, hanger->hField); |
|---|
| 600 | } |
|---|
| 601 | |
|---|
| 602 | /* Recycle the hanger in any case */ |
|---|
| 603 | hanger->hField = NULL; |
|---|
| 604 | BLST_Q_INSERT_TAIL (&pVbilenc->empty_hangers, hanger, link); |
|---|
| 605 | } |
|---|
| 606 | else |
|---|
| 607 | { |
|---|
| 608 | /* |
|---|
| 609 | * Field mismatch. The field handle stays in the queue until |
|---|
| 610 | * the next interrupt. |
|---|
| 611 | */ |
|---|
| 612 | /* Cause the encoder hardware to output no VBI next field */ |
|---|
| 613 | eErr = BVBI_Encode_Data_isr (pVbilenc->hVbiEnc, NULL, polarity); |
|---|
| 614 | } |
|---|
| 615 | } |
|---|
| 616 | else |
|---|
| 617 | { |
|---|
| 618 | /* Cause the encoder hardware to output no VBI next field */ |
|---|
| 619 | eErr = BVBI_Encode_Data_isr (pVbilenc->hVbiEnc, NULL, polarity); |
|---|
| 620 | } |
|---|
| 621 | |
|---|
| 622 | BDBG_LEAVE(BVBIlib_Encode_Encode_Data_isr); |
|---|
| 623 | return eErr; |
|---|
| 624 | } |
|---|
| 625 | |
|---|
| 626 | |
|---|
| 627 | /*************************************************************************** |
|---|
| 628 | * |
|---|
| 629 | */ |
|---|
| 630 | BERR_Code BVBIlib_Encode_GetOldestDatum_isr( |
|---|
| 631 | BVBIlib_Encode_Handle enclHdl, |
|---|
| 632 | BVBI_Field_Handle* pFieldHandle) |
|---|
| 633 | { |
|---|
| 634 | BVBIlib_P_Encode_Handle *pVbilenc; |
|---|
| 635 | BVBIlib_P_FieldHanger *hanger; |
|---|
| 636 | BVBI_Field_Handle hField = NULL; |
|---|
| 637 | |
|---|
| 638 | BDBG_ENTER(BVBIlib_Encode_GetOldestDatum_isr); |
|---|
| 639 | |
|---|
| 640 | /* check parameters */ |
|---|
| 641 | BVBILIB_P_GET_ENCODE_CONTEXT(enclHdl, pVbilenc); |
|---|
| 642 | if ((!pVbilenc) || (!pFieldHandle)) |
|---|
| 643 | { |
|---|
| 644 | BDBG_ERR(("Invalid parameter\n")); |
|---|
| 645 | return BERR_TRACE(BERR_INVALID_PARAMETER); |
|---|
| 646 | } |
|---|
| 647 | |
|---|
| 648 | /* If there is a queued field handle available */ |
|---|
| 649 | if ((hanger = BLST_Q_FIRST (&pVbilenc->encode_queue)) != NULL) |
|---|
| 650 | { |
|---|
| 651 | hField = hanger->hField; |
|---|
| 652 | } |
|---|
| 653 | |
|---|
| 654 | /* Return what we got, if anything. */ |
|---|
| 655 | *pFieldHandle = hField; |
|---|
| 656 | return BERR_SUCCESS; |
|---|
| 657 | } |
|---|
| 658 | |
|---|
| 659 | |
|---|
| 660 | /*************************************************************************** |
|---|
| 661 | * |
|---|
| 662 | */ |
|---|
| 663 | BERR_Code BVBIlib_Encode_NoData_isr( |
|---|
| 664 | BVBIlib_Encode_Handle enclHdl, |
|---|
| 665 | BAVC_Polarity polarity |
|---|
| 666 | ) |
|---|
| 667 | { |
|---|
| 668 | BVBIlib_P_Encode_Handle *pVbilenc; |
|---|
| 669 | BERR_Code eErr = BERR_SUCCESS; |
|---|
| 670 | |
|---|
| 671 | BDBG_ENTER(BVBIlib_Encode_NoData_isr); |
|---|
| 672 | |
|---|
| 673 | /* check parameters */ |
|---|
| 674 | BVBILIB_P_GET_ENCODE_CONTEXT(enclHdl, pVbilenc); |
|---|
| 675 | if(!pVbilenc) |
|---|
| 676 | { |
|---|
| 677 | BDBG_ERR(("Invalid parameter\n")); |
|---|
| 678 | return BERR_TRACE(BERR_INVALID_PARAMETER); |
|---|
| 679 | } |
|---|
| 680 | |
|---|
| 681 | /* Cause the encoder hardware to output no VBI next field */ |
|---|
| 682 | eErr = BVBI_Encode_Data_isr (pVbilenc->hVbiEnc, NULL, polarity); |
|---|
| 683 | |
|---|
| 684 | BDBG_LEAVE(BVBIlib_Encode_Encode_Data_isr); |
|---|
| 685 | return eErr; |
|---|
| 686 | } |
|---|
| 687 | |
|---|
| 688 | |
|---|
| 689 | /*************************************************************************** |
|---|
| 690 | * |
|---|
| 691 | */ |
|---|
| 692 | BERR_Code BVBIlib_Encode_Flush_isr( BVBIlib_Encode_Handle enclHdl ) |
|---|
| 693 | { |
|---|
| 694 | BVBIlib_P_Encode_Handle *pVbilenc; |
|---|
| 695 | BVBIlib_P_FieldHanger *hanger; |
|---|
| 696 | BERR_Code eErr = BERR_SUCCESS; |
|---|
| 697 | |
|---|
| 698 | BDBG_ENTER(BVBIlib_Encode_Flush_isr); |
|---|
| 699 | |
|---|
| 700 | /* check parameters */ |
|---|
| 701 | BVBILIB_P_GET_ENCODE_CONTEXT(enclHdl, pVbilenc); |
|---|
| 702 | if(!pVbilenc) |
|---|
| 703 | { |
|---|
| 704 | BDBG_ERR(("Invalid parameter\n")); |
|---|
| 705 | return BERR_TRACE(BERR_INVALID_PARAMETER); |
|---|
| 706 | } |
|---|
| 707 | |
|---|
| 708 | /* While there are queued field handles available */ |
|---|
| 709 | while ((hanger = BLST_Q_FIRST (&pVbilenc->encode_queue)) != NULL) |
|---|
| 710 | { |
|---|
| 711 | /* Remove from input queue */ |
|---|
| 712 | BLST_Q_REMOVE (&pVbilenc->encode_queue, hanger, link); |
|---|
| 713 | --pVbilenc->encode_queue_length; |
|---|
| 714 | |
|---|
| 715 | /* Decrement use count of field handle */ |
|---|
| 716 | BVBI_Field_Decrement_UsageCount_isr (hanger->hField); |
|---|
| 717 | |
|---|
| 718 | /* Recycle the field handle if appropriate */ |
|---|
| 719 | if (BVBI_Field_Get_UsageCount_isr (hanger->hField) == 0) |
|---|
| 720 | { |
|---|
| 721 | BVBIlib_List_Return_isr (pVbilenc->hVbill, hanger->hField); |
|---|
| 722 | } |
|---|
| 723 | |
|---|
| 724 | /* Recycle the hanger too */ |
|---|
| 725 | hanger->hField = NULL; |
|---|
| 726 | BLST_Q_INSERT_TAIL (&pVbilenc->empty_hangers, hanger, link); |
|---|
| 727 | } |
|---|
| 728 | |
|---|
| 729 | BDBG_LEAVE(BVBIlib_Encode_Encode_Flush_isr); |
|---|
| 730 | return eErr; |
|---|
| 731 | } |
|---|
| 732 | |
|---|
| 733 | |
|---|
| 734 | /*************************************************************************** |
|---|
| 735 | * |
|---|
| 736 | */ |
|---|
| 737 | int BVBIlib_GetQueueLength (BVBIlib_Encode_Handle enclHdl) |
|---|
| 738 | { |
|---|
| 739 | BVBIlib_P_Encode_Handle *pVbilenc; |
|---|
| 740 | |
|---|
| 741 | BDBG_ENTER(BVBIlib_Encode_Flush_isr); |
|---|
| 742 | |
|---|
| 743 | /* check parameters */ |
|---|
| 744 | BVBILIB_P_GET_ENCODE_CONTEXT(enclHdl, pVbilenc); |
|---|
| 745 | BDBG_ASSERT (pVbilenc); |
|---|
| 746 | |
|---|
| 747 | /* Return value as requested */ |
|---|
| 748 | return pVbilenc->encode_queue_length; |
|---|
| 749 | } |
|---|
| 750 | |
|---|
| 751 | /* End of File */ |
|---|