source: svn/trunk/newcon3bcm2_21bu/magnum/portinginterface/vbi/7552/bvbi_enc.c

Last change on this file was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 62.7 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2003-2011, 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: bvbi_enc.c $
11 * $brcm_Revision: Hydra_Software_Devel/21 $
12 * $brcm_Date: 3/22/11 12:57p $
13 *
14 * Module Description:
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /magnum/portinginterface/vbi/7400/bvbi_enc.c $
19 *
20 * Hydra_Software_Devel/21   3/22/11 12:57p darnstein
21 * SW7420-1693: CGMS for 480P video needs to take "VEC double rate
22 * sampling" into account.
23 *
24 * Hydra_Software_Devel/20   3/15/11 5:12p darnstein
25 * SW7335-1139: "Method 2" for CGMS-B is the default, if hardware can
26 * support it.
27 *
28 * Hydra_Software_Devel/19   3/2/11 3:38p darnstein
29 * SW7422-261: More problems with line numbering for PAL-M and multi-line
30 * closed captioning. This time, chipsets whose CCE cores lack "SCTE"
31 * extensions were affected.
32 *
33 * Hydra_Software_Devel/18   11/16/10 5:12p darnstein
34 * SW7405-4995: don't use memcmp on structs. Compare each struct field
35 * individually.
36 *
37 * Hydra_Software_Devel/17   10/8/10 6:10p darnstein
38 * SW7405-4931: there were errors in previous check-in.
39 *
40 * Hydra_Software_Devel/16   10/8/10 6:01p darnstein
41 * SW7405-4931: Functions BVBI_Encode_Set* check for unsupported hardware
42 * feature.
43 *
44 * Hydra_Software_Devel/15   10/1/10 2:49p darnstein
45 * SW7422-46: Adapt to 7422 and 7425 chipsets.
46 *
47 * Hydra_Software_Devel/14   5/25/10 11:54a darnstein
48 * SW7405-4393: last check-in was too complete.
49 *
50 * Hydra_Software_Devel/13   5/24/10 2:24p darnstein
51 * SW7405-4393: last check-in was incomplete.
52 *
53 * Hydra_Software_Devel/12   5/24/10 2:02p darnstein
54 * SW7405-4393: free a certain pointer when other operations fail. Memory
55 * leak.
56 *
57 * Hydra_Software_Devel/11   4/9/10 7:45p darnstein
58 * SW7125-258,SW7125-259,SW7125-260: When creating decoder object, do all
59 * ocations in a different order. This simplifies error-recovery logic
60 * for the benefit of Coverity.
61 *
62 * Hydra_Software_Devel/10   3/3/10 8:07p darnstein
63 * SW7420-598: Adjust #ifdefs that select capabilities CGMS-B, CGMS-Bd.
64 *
65 * Hydra_Software_Devel/9   12/10/09 6:46p darnstein
66 * SW7420-498: Move memory management from "apply changes" functions to
67 * "create" functions. Applies to teletext memory only.
68 *
69 * Hydra_Software_Devel/8   11/18/09 3:54p darnstein
70 * SW7468-24: Gemstar options now placed in dedicated data structure.
71 *
72 * Hydra_Software_Devel/7   6/30/09 5:51p darnstein
73 * PR56342: support for 7550 chipset.
74 *
75 * Hydra_Software_Devel/6   4/6/09 2:38p darnstein
76 * PR53826: simplify the #if statements that indicate chip capabilities.
77 *
78 * Hydra_Software_Devel/5   3/30/09 1:26p darnstein
79 * PR53666: completely remove automatic VBI enable/disable logic. It was
80 * doing almost nothing, and causing this PR.
81 *
82 * Hydra_Software_Devel/4   2/9/09 7:58p darnstein
83 * PR45819: minor update for 7420 and CGMSAE core: version numbers.
84 *
85 * Hydra_Software_Devel/3   12/17/08 8:12p darnstein
86 * PR46112: allow CGMS-A and CGMS-B output at the same time.
87 *
88 * Hydra_Software_Devel/2   12/8/08 7:36p darnstein
89 * PR49987: fix bug in BVBI_Encode_Create(). Affects 656 output.
90 *
91 * Hydra_Software_Devel/1   12/3/08 8:01p darnstein
92 * PR45819:
93 *
94 ***************************************************************************/
95
96#include "bstd.h"           /* standard types */
97#include "bdbg.h"           /* Dbglib */
98#include "bkni.h"                       /* For critical sections */
99#include "bvbi.h"           /* VBI processing, this module. */
100#include "bvbi_priv.h"      /* VBI internal data structures */
101
102BDBG_MODULE(BVBI);
103
104
105/***************************************************************************
106* Forward declarations of static (private) functions
107***************************************************************************/
108
109static BERR_Code BVBI_P_Encode_ApplyChanges (
110        BVBI_P_Encode_Handle* pVbi_Enc, BVBI_P_Encode_CNState* cnState, bool force);
111
112static BERR_Code BVBI_P_Encode_Set_VBI (
113        BVBI_Encode_Handle encodeHandle,
114        bool bEnabled,
115        uint32_t ulSelect_Standard);
116
117static BERR_Code BVBI_P_Encode_Get_VBI (
118        BVBI_Encode_Handle encodeHandle,
119        bool* pbEnabled,
120        uint32_t ulSelect_Standard);
121
122static BERR_Code BVBI_P_Encode_656_Set_VBI (
123        BVBI_Encode_Handle encodeHandle,
124        bool bEnabled,
125        uint32_t ulSelect_Standard);
126
127static BERR_Code BVBI_P_Encode_656_Get_VBI (
128        BVBI_Encode_Handle encodeHandle,
129        bool* pbEnabled,
130        uint32_t ulSelect_Standard);
131
132static BERR_Code BVBI_P_Encode_XSER_Set_VBI (
133        BVBI_Encode_Handle encodeHandle,
134        bool bEnabled,
135        uint32_t ulSelect_Standard);
136
137static BERR_Code BVBI_P_Encode_XSER_Get_VBI (
138        BVBI_Encode_Handle encodeHandle,
139        bool* pbEnabled,
140        uint32_t ulSelect_Standard);
141
142static bool BVBI_P_Encode_IsDirty (
143        BVBI_P_Encode_Handle *pVbi_Enc,
144        uint32_t nextActive, uint32_t ulSelect_Standard);
145
146static void BVBI_P_Encode_ChangesApplied (BVBI_P_Encode_Handle *pVbi_Enc);
147
148static void P_UnionAllocatedCores (
149        const uint8_t hwCoreIndexA[BVBI_P_EncCoreType_eLAST],
150        const uint8_t hwCoreIndexB[BVBI_P_EncCoreType_eLAST],
151        uint8_t hwCoreIndexResult[BVBI_P_EncCoreType_eLAST]);
152
153static bool P_GsOptionsEqual (
154        const BVBI_GSOptions* p1, const BVBI_GSOptions* p2);
155static bool P_XserSettingsEqual (
156        const BVBI_XSER_Settings* p1, const BVBI_XSER_Settings* p2);
157
158
159/***************************************************************************
160* Implementation of "BVBI_" API functions
161***************************************************************************/
162
163/***************************************************************************
164 *
165 */
166BERR_Code BVBI_Encode_Create(BVBI_Handle vbiHandle,
167                           BAVC_VbiPath eDest,
168                           BVBI_Encode_Handle *pEncodeHandle)
169{
170        BVBI_P_EncCoreType eType;
171        BVBI_P_Handle *pVbi;
172        BVBI_P_TTData* pttDataT = NULL;
173        BVBI_P_TTData* pttDataB = NULL;
174        BERR_Code eErr = BERR_SUCCESS;
175        BVBI_P_Encode_Handle *pVbi_Enc = NULL;
176        bool bVbiEncReserved = false;
177#if (BVBI_P_NUM_ANCI656_656 > 0)
178        bool bAnci656Reserved = false;
179#endif
180
181        BDBG_ENTER(BVBI_Encode_Create);
182
183        /* check parameters */
184        BVBI_P_GET_CONTEXT(vbiHandle, pVbi);
185        if((!pVbi) || (!pEncodeHandle))
186        {
187                BDBG_ERR(("Invalid parameter\n"));
188                eErr = BERR_TRACE(BERR_INVALID_PARAMETER);
189                goto BVBI_Encode_Create_Done;
190        }
191        if ((eDest != BAVC_VbiPath_eVec0)
192#if (BVBI_P_NUM_VEC >= 2)
193     && (eDest != BAVC_VbiPath_eVec1)
194#endif
195#if (BVBI_P_NUM_VEC >= 3)
196         && (eDest != BAVC_VbiPath_eVec2)
197#endif
198#if (BVBI_P_NUM_PTVEC >= 1)
199         && (eDest != BAVC_VbiPath_eBypass0)
200#endif
201#if (BVBI_P_NUM_PTVEC >= 2)
202         && (eDest != BAVC_VbiPath_eBypass1)
203#endif
204        )
205        {
206                BDBG_ERR(("Invalid parameter\n"));
207                eErr = BERR_TRACE(BERR_INVALID_PARAMETER);
208                goto BVBI_Encode_Create_Done;
209        }
210
211        /* Check to see if the caller has already opened an encode handle that
212           controls the same video destination */
213        for (pVbi_Enc = BLST_D_FIRST (&pVbi->encode_contexts) ;
214                 pVbi_Enc ;
215                 pVbi_Enc = BLST_D_NEXT (pVbi_Enc, link))
216        {
217                if (pVbi_Enc->eDest == eDest)
218                {
219                        BDBG_ERR(("Multiple handles for one VBI core\n"));
220                        eErr = BERR_TRACE(BVBI_ERR_HW_CONFLICT);
221                        goto BVBI_Encode_Create_Done;
222                }
223        }
224
225        /* Alloc the VBI encode handle. */
226        pVbi_Enc =
227                (BVBI_P_Encode_Handle*)(BKNI_Malloc(sizeof(BVBI_P_Encode_Handle)));
228        if(!pVbi_Enc)
229        {
230                eErr = BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);
231                goto BVBI_Encode_Create_Done;
232        }
233
234        /* Clear out the context and set defaults. */
235        BKNI_Memset((void*)pVbi_Enc, 0x0, sizeof(BVBI_P_Encode_Handle));
236        pVbi_Enc->bDisabled = false;
237        pVbi_Enc->eDest     = eDest;
238        pVbi_Enc->pVbi      = pVbi;
239
240        /* Set current/next state to defaults */
241        pVbi_Enc->curr.eVideoFormat             = BFMT_VideoFmt_eNTSC;
242        pVbi_Enc->curr.ePixRep                  = BAVC_HDMI_PixelRepetition_eNone;
243        pVbi_Enc->curr.h656options.e656Format   = BVBI_656Fmt_SAA7113;
244        pVbi_Enc->curr.h656options.sdid         = BVBI_P_p656_SetEEbits(0);
245        pVbi_Enc->curr.ulActive_Standards       = 0x0;
246        pVbi_Enc->curr.ulActive_656_Standards   = 0x0;
247        pVbi_Enc->curr.gsOptions.bTvg2x         = false;
248        pVbi_Enc->curr.gsOptions.baseline_top   = 10;
249        pVbi_Enc->curr.gsOptions.linemask_top   = 0x01F;
250        pVbi_Enc->curr.gsOptions.baseline_bot   = 273;
251        pVbi_Enc->curr.gsOptions.linemask_bot   = 0x01F;
252        pVbi_Enc->curr.amolType                 = BVBI_AMOL_Type_I;
253        pVbi_Enc->curr.scteType                 = BVBI_SCTE_Type_CCONLY;
254        pVbi_Enc->curr.eCsc                     = BVBI_CSC_SCTE_NTSCYIQ;
255        pVbi_Enc->curr.eCoCsc                   = BVBI_CSC_NONE;
256#if defined(BVBI_P_CGMSAE_VER1) || defined(BVBI_P_CGMSAE_VER2) || \
257    defined(BVBI_P_CGMSAE_VER4)
258        pVbi_Enc->curr.bCea805dStyle            = false;
259#else
260        pVbi_Enc->curr.bCea805dStyle            = true;
261#endif
262        pVbi_Enc->curr.bPR18010_bad_line_number = false;
263        pVbi_Enc->curr.xserSettings             = *BVBI_P_GetDefaultXserSettings();
264
265        /* Clear out list of "in use" VEC hardware cores */
266        for (eType = 0 ; eType < BVBI_P_EncCoreType_eLAST ; ++eType)
267        {
268                pVbi_Enc->curr.hwCoreIndex[eType] = 0xFF;
269        }
270
271        /* Allocate VBI_ENC core. This is a bit of a kludge. */
272        eErr = BVBI_P_Encode_ReserveCore (
273                eDest, BVBI_P_SELECT_VBIENC, 
274                pVbi->vecHwCoreMask, pVbi->vecHwCoreMask_656, 
275                pVbi_Enc->curr.hwCoreIndex);
276        if (eErr != BERR_SUCCESS)
277        {
278                BDBG_ERR(("Hardware allocate failure\n"));
279                goto BVBI_Encode_Create_Done;
280        }
281        bVbiEncReserved = true;
282
283        /* Allocating ANCI656 core is another kludge */
284#if (BVBI_P_NUM_ANCI656_656 > 0) /** { **/
285        if (BVBI_P_is656 (pVbi_Enc->eDest))
286        {
287                eErr = BVBI_P_Encode_ReserveCore (
288                        eDest, BVBI_P_SELECT_ANCI, 
289                        pVbi->vecHwCoreMask, pVbi->vecHwCoreMask_656, 
290                        pVbi_Enc->curr.hwCoreIndex);
291                if (eErr != BERR_SUCCESS)
292                {
293                        BDBG_ERR(("Hardware allocate failure\n"));
294                        goto BVBI_Encode_Create_Done;
295                }
296                bAnci656Reserved = true;
297        }
298#endif /** } **/
299
300        /* Next state is the same as current state for now. */
301        pVbi_Enc->next = pVbi_Enc->curr;
302
303        /* Special initialization for CGMS */
304#ifdef P_CGMS_SOFTWARE_CRC
305        pVbi_Enc->last_cgms_user = 0;
306        pVbi_Enc->last_cgms_formatted =
307                BVPI_P_CGMS_format_data (pVbi_Enc->last_cgms_user);
308#endif
309
310        /* Initialize teletext pointers for LCO */
311        pttDataT = (BVBI_P_TTData*)(BKNI_Malloc(sizeof(BVBI_P_TTData)));
312        if(!pttDataT)
313        {
314                eErr = BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);
315                goto BVBI_Encode_Create_Done;
316        }
317        BKNI_Memset((void*)pttDataT, 0x0, sizeof(BVBI_P_TTData));
318        eErr = BVBI_P_TTData_Alloc (
319                pVbi->hMem, BVBI_TT_MAX_LINES, BVBI_TT_MAX_LINELENGTH, pttDataT);
320        if (eErr != BERR_SUCCESS)
321        {
322                eErr = BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);
323                goto BVBI_Encode_Create_Done;
324        }
325
326        pttDataB = (BVBI_P_TTData*)(BKNI_Malloc(sizeof(BVBI_P_TTData)));
327        if(!pttDataB)
328        {
329                eErr = BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);
330                goto BVBI_Encode_Create_Done;
331        }
332        BKNI_Memset((void*)pttDataB, 0x0, sizeof(BVBI_P_TTData));
333        eErr = BVBI_P_TTData_Alloc (
334                pVbi->hMem, BVBI_TT_MAX_LINES, BVBI_TT_MAX_LINELENGTH, pttDataB);
335        if (eErr != BERR_SUCCESS)
336        {
337                eErr = BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);
338                goto BVBI_Encode_Create_Done;
339        }
340
341        /* Allocate empty space for SCTE data */
342        eErr = BVBI_P_Encode_AllocScte (
343                pVbi->hMem,
344                pVbi_Enc->hTopScteNrtv,
345                pVbi_Enc->hBotScteNrtv,
346                pVbi_Enc->hTopScteMono,
347                pVbi_Enc->hBotScteMono,
348                &pVbi_Enc->sctePamData
349        );
350        if (eErr != BERR_SUCCESS)
351        {
352                eErr = BERR_TRACE (eErr);
353                goto BVBI_Encode_Create_Done;
354        }
355        /* Programming note:
356         * This is the last possible failure in this function. Therefore, there is
357         * no need to undo this action during error handling.
358         */
359
360        /* Smart pointers come last. This will make the error handling logic easier
361         * for Coverity to understand. */
362        BVBI_P_LCOP_CREATE (pVbi_Enc, topTTDataO, pttDataT, clink);
363        BVBI_P_LCOP_CREATE (pVbi_Enc, botTTDataO, pttDataB, clink);
364
365        /* Link encode context into VBI handle's list */
366        BLST_D_INSERT_HEAD (&pVbi->encode_contexts, pVbi_Enc, link);
367
368        /* All done. now return the new fresh context to user. */
369        *pEncodeHandle = (BVBI_Encode_Handle)pVbi_Enc;
370
371        /* Initialize magic number to the size of the struct */
372        pVbi_Enc->ulBlackMagic = sizeof(BVBI_P_Encode_Handle);
373
374  BVBI_Encode_Create_Done:
375
376        BDBG_LEAVE(BVBI_Encode_Create);
377
378        if (BERR_SUCCESS != eErr) 
379        {
380                if (NULL != pttDataB)
381                {
382                        BVBI_P_TTData_Alloc (pVbi->hMem, 0, 0, pttDataB);
383                        BKNI_Free ((void*)pttDataB); 
384                }
385                if (NULL != pttDataT)
386                {
387                        BVBI_P_TTData_Alloc (pVbi->hMem, 0, 0, pttDataT);
388                        BKNI_Free ((void*)pttDataT); 
389                }
390                if (NULL != pVbi_Enc)
391                {
392#if (BVBI_P_NUM_ANCI656_656 > 0) /** { **/
393                        if (bAnci656Reserved)
394                        {
395                                BVBI_P_Encode_ReleaseCore (
396                                        eDest, BVBI_P_SELECT_ANCI, 0x0,
397                                        pVbi->vecHwCoreMask, pVbi->vecHwCoreMask_656, 
398                                        pVbi_Enc->curr.hwCoreIndex);
399                        }
400#endif /** } **/
401                        if (bVbiEncReserved)
402                        {
403                                BVBI_P_Encode_ReleaseCore (
404                                        eDest, BVBI_P_SELECT_VBIENC, 0x0,
405                                        pVbi->vecHwCoreMask, pVbi->vecHwCoreMask_656, 
406                                        pVbi_Enc->curr.hwCoreIndex);
407                        }
408                        pVbi_Enc->ulBlackMagic = 0x0;
409                        BKNI_Free ((void*)pVbi_Enc);
410                }
411        }
412
413        return eErr;
414}
415
416/***************************************************************************
417 *
418 */
419BERR_Code BVBI_Encode_Destroy(BVBI_Encode_Handle encodeHandle)
420{
421        uint32_t ulSelect_Standard;
422        BVBI_P_Handle *pVbi;
423        BVBI_P_Encode_Handle* pVbi_Enc;
424        BVBI_P_TTData* pttData;
425        BERR_Code eErr = BERR_SUCCESS;
426
427        BDBG_ENTER(BVBI_Encode_Destroy);
428
429        /* check parameters */
430        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
431        if(!pVbi_Enc)
432        {
433                BDBG_ERR(("Invalid parameter\n"));
434                return BERR_TRACE(BERR_INVALID_PARAMETER);
435        }
436
437        /* Shut down any active cores */
438        pVbi_Enc->next.ulActive_Standards = 0x0;
439        pVbi_Enc->next.ulActive_656_Standards = 0x0;
440        eErr = BVBI_Encode_ApplyChanges( encodeHandle );
441
442        /* Deallocate bulky data if necessary */
443        pVbi = pVbi_Enc->pVbi;
444        BVBI_P_LCOP_DESTROY (pVbi_Enc, topTTDataO, &pVbi->ttFreelist, clink);
445        pttData = BVBI_P_LCOP_GET (pVbi_Enc, topTTDataO);
446        BVBI_P_TTData_Alloc (pVbi->hMem, 0, 0, pttData);
447        BKNI_Free ((void*)pttData);
448        BVBI_P_LCOP_DESTROY (pVbi_Enc, botTTDataO, &pVbi->ttFreelist, clink);
449        pttData = BVBI_P_LCOP_GET (pVbi_Enc, botTTDataO);
450        BVBI_P_TTData_Alloc (pVbi->hMem, 0, 0, pttData);
451        BKNI_Free ((void*)pttData);
452        BVBI_P_Encode_FreeScte (
453                pVbi->hMem,
454                pVbi_Enc->hTopScteNrtv,
455                pVbi_Enc->hBotScteNrtv,
456                pVbi_Enc->hTopScteMono,
457                pVbi_Enc->hBotScteMono,
458                &pVbi_Enc->sctePamData
459        );
460
461        /* Release hardware cores for re-use */
462        for (ulSelect_Standard = 0x1 ; ulSelect_Standard < BVBI_P_SELECT_LAST ; 
463                 ulSelect_Standard <<= 1)
464        {
465                BVBI_P_Encode_ReleaseCore (
466                        pVbi_Enc->eDest, ulSelect_Standard, 0x0,
467                        pVbi->vecHwCoreMask, pVbi->vecHwCoreMask_656, 
468                        pVbi_Enc->next.hwCoreIndex);
469        }
470
471        /* Unlink from parent VBI context */
472        BLST_D_REMOVE (&pVbi->encode_contexts, pVbi_Enc, link);
473
474        /* The handle is invalid */
475        pVbi_Enc->ulBlackMagic = 0;
476
477        /* Release context in system memory */
478        BKNI_Free((void*)pVbi_Enc);
479
480        BDBG_LEAVE(BVBI_Encode_Destroy);
481        return eErr;
482}
483
484/***************************************************************************
485 *
486 */
487BERR_Code BVBI_Encode_ApplyChanges( BVBI_Encode_Handle encodeHandle )
488{
489        BVBI_P_Encode_Handle *pVbi_Enc;
490        BERR_Code eErr;
491
492        BDBG_ENTER(BVBI_Encode_ApplyChanges);
493
494        /* check parameters */
495        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
496        if(!pVbi_Enc)
497        {
498                BDBG_ERR(("Invalid parameter\n"));
499                eErr = BERR_TRACE(BERR_INVALID_PARAMETER);
500                goto done;
501        }
502
503        /* Try to apply changes */
504        eErr = BVBI_P_Encode_ApplyChanges (pVbi_Enc, &pVbi_Enc->next, false);
505
506        /* On failure, restore state. */
507        if (eErr != BERR_SUCCESS)
508        {
509                (void)BVBI_P_Encode_ApplyChanges (pVbi_Enc, &pVbi_Enc->curr, true);
510                goto done;
511        }
512
513        /* Hardware should now be fully programmed */
514        BVBI_P_Encode_ChangesApplied (pVbi_Enc);
515
516done:
517        BDBG_LEAVE(BVBI_Encode_ApplyChanges);
518        return eErr;
519}
520
521/***************************************************************************
522 *
523 */
524BERR_Code BVBI_Encode_SetGemstarOptions(
525        BVBI_Encode_Handle encodeHandle,
526        const BVBI_GSOptions* gsOptions
527)
528{
529        BVBI_P_Encode_Handle *pVbi_Enc;
530
531        BDBG_ENTER(BVBI_Encode_SetGemstarOptions);
532
533        /* check parameters */
534        if (gsOptions == 0x0)
535        {
536                BDBG_ERR(("Invalid parameter\n"));
537                return BERR_TRACE(BERR_INVALID_PARAMETER);
538        }
539        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
540        if (!pVbi_Enc)
541        {
542                BDBG_ERR(("Invalid parameter\n"));
543                return BERR_TRACE(BERR_INVALID_PARAMETER);
544        }
545
546        if (gsOptions->baseline_bot <= 256)
547        {
548                BDBG_ERR(("Invalid parameter\n"));
549                return BERR_TRACE(BERR_INVALID_PARAMETER);
550        }
551
552        /* Remember options as requested */
553        pVbi_Enc->next.gsOptions = *gsOptions;
554
555        BDBG_LEAVE(BVBI_Encode_SetGemstarOptions);
556        return BERR_SUCCESS;
557}
558
559/***************************************************************************
560 *
561 */
562BERR_Code BVBI_Encode_GetGemstarOptions(
563        BVBI_Encode_Handle encodeHandle,
564        BVBI_GSOptions*    gsOptions
565)
566{
567        BVBI_P_Encode_Handle *pVbi_Enc;
568
569        BDBG_ENTER(BVBI_Encode_GetGemstarOptions);
570
571        /* check parameters */
572        if (gsOptions == 0x0)
573        {
574                BDBG_ERR(("Invalid parameter\n"));
575                return BERR_TRACE(BERR_INVALID_PARAMETER);
576        }
577        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
578        if (!pVbi_Enc)
579        {
580                BDBG_ERR(("Invalid parameter\n"));
581                return BERR_TRACE(BERR_INVALID_PARAMETER);
582        }
583
584        /* Return options as requested */
585        *gsOptions = pVbi_Enc->curr.gsOptions;
586
587        BDBG_LEAVE(BVBI_Encode_GetGemstarOptions);
588        return BERR_SUCCESS;
589}
590
591/***************************************************************************
592 *
593 */
594BERR_Code BVBI_Encode_SetAMOLOptions(
595        BVBI_Encode_Handle encodeHandle,
596        BVBI_AMOL_Type     amolType
597)
598{
599        BVBI_P_Encode_Handle *pVbi_Enc;
600
601        BDBG_ENTER(BVBI_Encode_SetAMOLOptions);
602
603        /* check parameters */
604        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
605        if (!pVbi_Enc)
606        {
607                BDBG_ERR(("Invalid parameter\n"));
608                return BERR_TRACE(BERR_INVALID_PARAMETER);
609        }
610
611        switch (amolType)
612        {
613        case BVBI_AMOL_Type_I:
614        case BVBI_AMOL_Type_II_Lowrate:
615        case BVBI_AMOL_Type_II_Highrate:
616                break;
617
618        default:
619                BDBG_ERR(("Invalid parameter\n"));
620                return BERR_TRACE(BERR_INVALID_PARAMETER);
621        }
622
623        /* Remember options as requested */
624        pVbi_Enc->next.amolType = amolType;
625
626        BDBG_LEAVE(BVBI_Encode_SetAMOLOptions);
627        return BERR_SUCCESS;
628}
629
630/***************************************************************************
631 *
632 */
633BERR_Code BVBI_Encode_SetSCTEOptions(
634        BVBI_Encode_Handle encodeHandle,
635        BVBI_SCTE_Type     scteType
636)
637{
638        BVBI_P_Encode_Handle *pVbi_Enc;
639
640        BDBG_ENTER(BVBI_Encode_SetSCTEOptions);
641
642        /* check parameters */
643        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
644        if (!pVbi_Enc)
645        {
646                BDBG_ERR(("Invalid parameter\n"));
647                return BERR_TRACE(BERR_INVALID_PARAMETER);
648        }
649
650        switch (scteType)
651        {
652        case BVBI_SCTE_Type_CCONLY:
653        case BVBI_SCTE_Type_CCNRTV:
654        case BVBI_SCTE_Type_CCPAM:
655        case BVBI_SCTE_Type_CCMONO:
656                break;
657
658        default:
659                BDBG_ERR(("Invalid parameter\n"));
660                return BERR_TRACE(BERR_INVALID_PARAMETER);
661        }
662
663        /* Remember options as requested */
664        pVbi_Enc->next.scteType = scteType;
665
666        BDBG_LEAVE(BVBI_Encode_SetSCTEOptions);
667        return BERR_SUCCESS;
668}
669
670/***************************************************************************
671 *
672 */
673BERR_Code BVBI_Encode_GetAMOLOptions(
674        BVBI_Encode_Handle encodeHandle,
675        BVBI_AMOL_Type*    pAmolType
676)
677{
678        BVBI_P_Encode_Handle *pVbi_Enc;
679
680        BDBG_ENTER(BVBI_Encode_GetAMOLOptions);
681
682        /* check parameters */
683        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
684        if (!pVbi_Enc)
685        {
686                BDBG_ERR(("Invalid parameter\n"));
687                return BERR_TRACE(BERR_INVALID_PARAMETER);
688        }
689
690        if (pAmolType == 0x0)
691        {
692                BDBG_ERR(("Invalid parameter\n"));
693                return BERR_TRACE(BERR_INVALID_PARAMETER);
694        }
695
696        /* Return options as requested */
697        *pAmolType = pVbi_Enc->curr.amolType;
698
699        BDBG_LEAVE(BVBI_Encode_GetAMOLOptions);
700        return BERR_SUCCESS;
701}
702
703/***************************************************************************
704 *
705 */
706BERR_Code BVBI_Encode_GetSCTEOptions(
707        BVBI_Encode_Handle encodeHandle,
708        BVBI_SCTE_Type*    pScteType
709)
710{
711        BVBI_P_Encode_Handle *pVbi_Enc;
712
713        BDBG_ENTER(BVBI_Encode_GetSCTEOptions);
714
715        /* check parameters */
716        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
717        if (!pVbi_Enc)
718        {
719                BDBG_ERR(("Invalid parameter\n"));
720                return BERR_TRACE(BERR_INVALID_PARAMETER);
721        }
722
723        if (pScteType == 0x0)
724        {
725                BDBG_ERR(("Invalid parameter\n"));
726                return BERR_TRACE(BERR_INVALID_PARAMETER);
727        }
728
729        /* Return options as requested */
730        *pScteType = pVbi_Enc->curr.scteType;
731
732        BDBG_LEAVE(BVBI_Encode_GetSCTEOptions);
733        return BERR_SUCCESS;
734}
735
736/***************************************************************************
737 *
738 */
739BERR_Code BVBI_Encode_SetVideoFormat(BVBI_Encode_Handle encodeHandle,
740                                                                         BFMT_VideoFmt eVideoFormat)
741{
742        BVBI_P_Encode_Handle *pVbi_Enc;
743
744        BDBG_ENTER(BVBI_Encode_SetVideoFormat);
745
746        /* check parameters */
747        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
748        if(!pVbi_Enc)
749        {
750                BDBG_ERR(("Invalid parameter\n"));
751                BDBG_LEAVE(BVBI_Encode_SetVideoFormat);
752                return BERR_TRACE(BERR_INVALID_PARAMETER);
753        }
754
755        /* Remember format as requested */
756        pVbi_Enc->next.eVideoFormat = eVideoFormat;
757
758        BDBG_LEAVE(BVBI_Encode_SetVideoFormat);
759        return BERR_SUCCESS;
760}
761
762/***************************************************************************
763 *
764 */
765BERR_Code BVBI_Encode_SetHdmiPixelRepetition( 
766        BVBI_Encode_Handle encodeHandle,
767        BAVC_HDMI_PixelRepetition ePixRep
768)
769{
770#ifdef BVBI_P_HAS_CROSSBAR_VEC
771
772        BDBG_ENTER(BVBI_Encode_SetHdmiPixelRepetition);
773        BSTD_UNUSED (encodeHandle);
774        BSTD_UNUSED (ePixRep);
775#else
776        BVBI_P_Encode_Handle *pVbi_Enc;
777
778        BDBG_ENTER(BVBI_Encode_SetHdmiPixelRepetition);
779
780        /* check parameters */
781        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
782        if(!pVbi_Enc)
783        {
784                BDBG_ERR(("Invalid parameter\n"));
785                BDBG_LEAVE(BVBI_Encode_SetHdmiPixelRepetition);
786                return BERR_TRACE(BERR_INVALID_PARAMETER);
787        }
788
789        /* Remember format as requested */
790        pVbi_Enc->next.ePixRep = ePixRep;
791#endif
792
793        BDBG_LEAVE(BVBI_Encode_SetHdmiPixelRepetition);
794        return BERR_SUCCESS;
795}
796
797/***************************************************************************
798 *
799 */
800BERR_Code BVBI_Encode_GetVideoFormat(BVBI_Encode_Handle encodeHandle,
801                                                                         BFMT_VideoFmt *peVideoFormat)
802{
803        BVBI_P_Encode_Handle *pVbi_Enc;
804
805        BDBG_ENTER(BVBI_Encode_GetVideoFormat);
806
807        /* check parameters */
808        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
809        if((!pVbi_Enc) || (!peVideoFormat))
810        {
811                BDBG_ERR(("Invalid parameter\n"));
812                return BERR_TRACE(BERR_INVALID_PARAMETER);
813        }
814
815        /* Return format as requested */
816        *peVideoFormat = pVbi_Enc->curr.eVideoFormat;
817
818        BDBG_LEAVE(BVBI_Encode_GetVideoFormat);
819        return BERR_SUCCESS;
820}
821
822/***************************************************************************
823 *
824 */
825BERR_Code BVBI_Encode_GetHdmiPixelRepetition(
826        BVBI_Encode_Handle encodeHandle,
827        BAVC_HDMI_PixelRepetition* pePixRep)
828{
829        BVBI_P_Encode_Handle *pVbi_Enc;
830
831        BDBG_ENTER(BVBI_Encode_GetHdmiPixelRepetition);
832
833        /* check parameters */
834        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
835        if((!pVbi_Enc) || (!pePixRep))
836        {
837                BDBG_ERR(("Invalid parameter\n"));
838                return BERR_TRACE(BERR_INVALID_PARAMETER);
839        }
840
841        /* Return format as requested */
842        *pePixRep = pVbi_Enc->curr.ePixRep;
843
844        BDBG_LEAVE(BVBI_Encode_GetHdmiPixelRepetition);
845        return BERR_SUCCESS;
846}
847
848/***************************************************************************
849 *
850 */
851BERR_Code BVBI_Encode_SetCSC (
852    BVBI_Encode_Handle encodeHandle, BVBI_CSC eCsc, BVBI_CSC eCoCsc)
853{
854        BVBI_P_Encode_Handle *pVbi_Enc;
855
856        BDBG_ENTER(BVBI_Encode_SetCSC);
857
858        /* check parameters */
859        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
860        if(!pVbi_Enc)
861        {
862                BDBG_ERR(("Invalid parameter\n"));
863                BDBG_LEAVE(BVBI_Encode_SetCSC);
864                return BERR_TRACE(BERR_INVALID_PARAMETER);
865        }
866        switch (eCsc)
867        {
868        case BVBI_CSC_SCTE_MYIQ:
869        case BVBI_CSC_SCTE_NTSCYIQ:
870        case BVBI_CSC_SCTE_YUV:
871        case BVBI_CSC_SCTE_CO:
872        case BVBI_CSC_NONE:
873                break;
874        default:
875                BDBG_ERR(("Invalid parameter\n"));
876                BDBG_LEAVE(BVBI_Encode_SetCSC);
877                return BERR_TRACE(BERR_INVALID_PARAMETER);
878                break;
879        }
880        switch (eCoCsc)
881        {
882        case BVBI_CSC_SCTE_MYIQ:
883        case BVBI_CSC_SCTE_NTSCYIQ:
884        case BVBI_CSC_SCTE_YUV:
885        case BVBI_CSC_SCTE_CO:
886        case BVBI_CSC_NONE:
887                break;
888        default:
889                BDBG_ERR(("Invalid parameter\n"));
890                BDBG_LEAVE(BVBI_Encode_SetCSC);
891                return BERR_TRACE(BERR_INVALID_PARAMETER);
892                break;
893        }
894
895        /* Remember format as requested */
896        pVbi_Enc->next.eCsc   = eCsc;
897        pVbi_Enc->next.eCoCsc = eCsc;
898
899        BDBG_LEAVE(BVBI_Encode_SetCSC);
900        return BERR_SUCCESS;
901}
902
903/***************************************************************************
904 *
905 */
906BERR_Code BVBI_Encode_GetCSC(
907        BVBI_Encode_Handle encodeHandle, BVBI_CSC *peCsc, BVBI_CSC *peCoCsc)
908{
909        BVBI_P_Encode_Handle *pVbi_Enc;
910
911        BDBG_ENTER(BVBI_Encode_GetCSC);
912
913        /* check parameters */
914        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
915        if ((!pVbi_Enc) || (!peCsc) || (!peCoCsc))
916        {
917                BDBG_ERR(("Invalid parameter\n"));
918                return BERR_TRACE(BERR_INVALID_PARAMETER);
919        }
920
921        /* Return format as requested */
922        *peCsc   = pVbi_Enc->curr.eCsc;
923        *peCoCsc = pVbi_Enc->curr.eCoCsc;
924
925        BDBG_LEAVE(BVBI_Encode_GetCSC);
926        return BERR_SUCCESS;
927}
928
929/***************************************************************************
930 *
931 */
932BERR_Code BVBI_Encode_SetCGMSBstyle(BVBI_Encode_Handle encodeHandle, 
933                                            bool bCea805dStyle)
934{
935        BVBI_P_Encode_Handle *pVbi_Enc;
936
937        BDBG_ENTER(BVBI_Encode_SetCGMSBstyle);
938
939        /* check parameters */
940        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
941        if(!pVbi_Enc)
942        {
943                BDBG_ERR(("Invalid parameter\n"));
944                BDBG_LEAVE(BVBI_Encode_GetCGMSBstyle);
945                return BERR_TRACE(BERR_INVALID_PARAMETER);
946        }
947#if !defined(BVBI_P_CGMSAE_VER3) && !defined(BVBI_P_CGMSAE_VER5)
948        if (bCea805dStyle)
949        {
950                BDBG_ERR(("CGMS-B not supported by VEC hardware\n"));
951                BDBG_LEAVE(BVBI_Encode_GetCGMSBstyle);
952                return BERR_TRACE (BERR_NOT_SUPPORTED);
953        }
954#endif
955
956        /* Remember format as requested */
957        pVbi_Enc->next.bCea805dStyle = bCea805dStyle;
958
959        BDBG_LEAVE(BVBI_Encode_SetCGMSBstyle);
960        return BERR_SUCCESS;
961}
962
963/***************************************************************************
964 *
965 */
966BERR_Code BVBI_Encode_GetCGMSBstyle(BVBI_Encode_Handle encodeHandle, 
967                                            bool* pbCea805dStyle)
968{
969        BVBI_P_Encode_Handle *pVbi_Enc;
970
971        BDBG_ENTER(BVBI_Encode_SetCGMSBstyle);
972
973        /* check parameters */
974        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
975        if ((!pVbi_Enc) || (!pbCea805dStyle))
976        {
977                BDBG_ERR(("Invalid parameter\n"));
978                return BERR_TRACE(BERR_INVALID_PARAMETER);
979        }
980
981        /* Return format as requested */
982        *pbCea805dStyle = pVbi_Enc->curr.bCea805dStyle;
983
984        BDBG_LEAVE(BVBI_Encode_SetCGMSBstyle);
985        return BERR_SUCCESS;
986}
987
988/***************************************************************************
989 *
990 */
991BERR_Code BVBI_Encode_656_SetFormat(BVBI_Encode_Handle encodeHandle,
992                                                                        BVBI_656Fmt anci656Fmt,
993                                                                        uint8_t sdid)
994{
995        BVBI_P_Encode_Handle *pVbi_Enc;
996
997        BDBG_ENTER(BVBI_Encode_656_SetFormat);
998
999        /* check parameters */
1000        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
1001        if(!pVbi_Enc)
1002        {
1003                BDBG_ERR(("Invalid parameter\n"));
1004                BDBG_LEAVE(BVBI_Encode_SetVideoFormat);
1005                return BERR_TRACE(BERR_INVALID_PARAMETER);
1006        }
1007
1008        /* Remember format as requested */
1009        switch (anci656Fmt)
1010        {
1011        case BVBI_656Fmt_SAA7113:
1012        case BVBI_656Fmt_Modified_SAA7113:
1013        case BVBI_656Fmt_SAA7114:
1014        case BVBI_656Fmt_SAA7115:
1015        case BVBI_656Fmt_SMPTE291:
1016                pVbi_Enc->next.h656options.e656Format = anci656Fmt;
1017                break;
1018        default:
1019                BDBG_LEAVE(BVBI_Encode_SetVideoFormat);
1020                return BERR_TRACE(BERR_INVALID_PARAMETER);
1021        }
1022
1023        /* Remember other options */
1024        pVbi_Enc->next.h656options.sdid = BVBI_P_p656_SetEEbits (sdid);
1025
1026        BDBG_LEAVE(BVBI_Encode_656_SetFormat);
1027        return BERR_SUCCESS;
1028}
1029
1030/***************************************************************************
1031 *
1032 */
1033BERR_Code BVBI_Encode_656_GetFormat(BVBI_Encode_Handle encodeHandle,
1034                                                                        BVBI_656Fmt* pAnci656Fmt,
1035                                                                        uint8_t* psdid)
1036{
1037        BVBI_P_Encode_Handle *pVbi_Enc;
1038
1039        BDBG_ENTER(BVBI_Encode_656_GetFormat);
1040
1041        /* check parameters */
1042        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
1043        if ((!pVbi_Enc) || (!pAnci656Fmt) || (!psdid))
1044        {
1045                BDBG_ERR(("Invalid parameter\n"));
1046                return BERR_TRACE(BERR_INVALID_PARAMETER);
1047        }
1048
1049        /* Return data as requested */
1050        *pAnci656Fmt = pVbi_Enc->curr.h656options.e656Format;
1051        *psdid       = pVbi_Enc->curr.h656options.sdid;
1052
1053        BDBG_LEAVE(BVBI_Encode_656_GetFormat);
1054        return BERR_SUCCESS;
1055}
1056
1057/***************************************************************************
1058 *
1059 */
1060BERR_Code BVBI_Encode_XSER_SetOptions (
1061        BVBI_Encode_Handle encodeHandle,
1062        BVBI_XSER_Settings* pSettings)
1063{
1064        BVBI_P_Encode_Handle* pVbi_Enc;
1065
1066        BDBG_ENTER(BVBI_Encode_XSER_SetOptions);
1067
1068        /* check parameters */
1069        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
1070        if ((!pVbi_Enc) || (!pSettings))
1071        {
1072                BDBG_ERR(("Invalid parameter\n"));
1073                return BERR_TRACE(BERR_INVALID_PARAMETER);
1074        }
1075
1076        /* TODO: validate contents of caller's pSettings. */
1077
1078        /* Record change to desired state */
1079        pVbi_Enc->next.xserSettings = *pSettings;
1080
1081        /* Success */
1082        BDBG_LEAVE (BVBI_Encode_XSER_SetOptions);
1083        return BERR_SUCCESS;
1084}
1085
1086/***************************************************************************
1087 *
1088 */
1089BERR_Code BVBI_Encode_XSER_GetOptions (
1090        BVBI_Encode_Handle encodeHandle,
1091        BVBI_XSER_Settings* pSettings)
1092{
1093        BVBI_P_Encode_Handle* pVbi_Enc;
1094
1095        BDBG_ENTER(BVBI_P_Encode_XSER_Get_VBI);
1096
1097        /* check parameters */
1098        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
1099        if ((!pVbi_Enc) || (!pSettings))
1100        {
1101                BDBG_ERR(("Invalid parameter\n"));
1102                return BERR_TRACE(BERR_INVALID_PARAMETER);
1103        }
1104
1105        /* Send info to caller */
1106        *pSettings = pVbi_Enc->curr.xserSettings;
1107
1108        /* Success */
1109        BDBG_LEAVE (BVBI_P_Encode_XSER_Get_VBI);
1110        return BERR_SUCCESS;
1111}
1112
1113
1114/***************************************************************************
1115 *
1116 */
1117BERR_Code BVBI_Encode_Data_isr( BVBI_Encode_Handle encodeHandle,
1118                                                                BVBI_Field_Handle fieldHandle,
1119                                                                BAVC_Polarity polarity )
1120{
1121        uint32_t whatActive;
1122        BVBI_P_Encode_Handle* pVbi_Enc;
1123        BVBI_P_Field_Handle*  pVbi_Fld;
1124        BVBI_P_Handle*        pVbi;
1125        BVBI_P_Encode_CNState* currentState;
1126        BERR_Code eErr = BERR_SUCCESS;
1127
1128        BDBG_ENTER(BVBI_Encode_Data_isr);
1129
1130        /* check parameters */
1131        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
1132        if(!pVbi_Enc)
1133        {
1134                BDBG_ERR(("Invalid parameter\n"));
1135                return BERR_TRACE(BERR_INVALID_PARAMETER);
1136        }
1137        if (fieldHandle)
1138        {
1139                BVBI_P_GET_FIELD_CONTEXT(fieldHandle, pVbi_Fld);
1140                if(!pVbi_Fld)
1141                {
1142                        BDBG_ERR(("Invalid parameter\n"));
1143                        return BERR_TRACE(BERR_INVALID_PARAMETER);
1144                }
1145        }
1146        else
1147        {
1148                pVbi_Fld = NULL;
1149        }
1150        currentState = &pVbi_Enc->curr;
1151
1152        /* If user has provided field data to encode */
1153        if (pVbi_Fld)
1154        {
1155                /* For convenience */
1156                pVbi = pVbi_Enc->pVbi;
1157
1158                /* Check polarity */
1159                if (polarity != BAVC_Polarity_eFrame)
1160                {
1161                        uint32_t mask = (uint32_t)1 << (uint32_t)polarity;
1162                        if ((pVbi_Fld->polarityMask & mask) != mask )
1163                        {
1164                                return BERR_TRACE(BVBI_ERR_INVALID_FIELD_POLARITY);
1165                        }
1166                }
1167
1168                /* Encode the various forms of VBI data as configured */
1169                whatActive =
1170                        currentState->ulActive_Standards |
1171                        currentState->ulActive_656_Standards |
1172                        currentState->ulActive_XSER_Standards;
1173                if ( (whatActive               & BVBI_P_SELECT_CC           ) &&
1174                         (pVbi_Fld->ulWhichPresent & BVBI_P_SELECT_CC           ) &&
1175                         !(pVbi_Fld->ulErrInfo     & BVBI_LINE_ERROR_CC_NOENCODE)    )
1176                {
1177                        (void)BVBI_P_CC_Encode_Data_isr (
1178                                        pVbi_Enc->pVbi->hReg,
1179                                        BVBI_P_is656(pVbi_Enc->eDest),
1180                                        pVbi_Enc->curr.hwCoreIndex[BVBI_P_EncCoreType_eCCE],
1181                                        polarity,
1182                                        pVbi_Fld->usCCData );
1183                }
1184                if ( (whatActive               & BVBI_P_SELECT_CGMSA          ) &&
1185                         (pVbi_Fld->ulWhichPresent & BVBI_P_SELECT_CGMSA          ) &&
1186                         !(pVbi_Fld->ulErrInfo     & BVBI_LINE_ERROR_CGMS_NOENCODE)    )
1187                {
1188                        /* Avoid a lengthy calculation if possible */
1189                        /* Transform data from user format to encoder format */
1190                        uint32_t ulData = pVbi_Fld->ulCGMSData;
1191#ifdef P_CGMS_SOFTWARE_CRC
1192                        if (ulData == pVbi_Enc->last_cgms_user)
1193                        {
1194                                ulData = pVbi_Enc->last_cgms_formatted;
1195                        }
1196                        else
1197                        {
1198                                pVbi_Enc->last_cgms_user = ulData;
1199                                if (pVbi_Enc->curr.eVideoFormat != BFMT_VideoFmt_e576p_50Hz)
1200                                        ulData = BVPI_P_CGMS_format_data (ulData);
1201                                pVbi_Enc->last_cgms_formatted = ulData;
1202                        }
1203#else
1204                        if (pVbi_Enc->curr.eVideoFormat != BFMT_VideoFmt_e576p_50Hz)
1205                                ulData = BVPI_P_CGMS_format_data (ulData);
1206#endif
1207
1208                        (void)BVBI_P_CGMSA_Encode_Data_isr (
1209                                        pVbi_Enc->pVbi->hReg,
1210                                        BVBI_P_is656(pVbi_Enc->eDest),
1211                                        pVbi_Enc->curr.hwCoreIndex[BVBI_P_EncCoreType_eCGMSAE],
1212                                        polarity,
1213                                        ulData );
1214                }
1215#if defined(BVBI_P_CGMSAE_VER2) || defined(BVBI_P_CGMSAE_VER3) || \
1216    defined(BVBI_P_CGMSAE_VER5)  /** { **/
1217                if ( (whatActive               & BVBI_P_SELECT_CGMSB          ) &&
1218                         (pVbi_Fld->ulWhichPresent & BVBI_P_SELECT_CGMSB          ) &&
1219                         !(pVbi_Fld->ulErrInfo     & BVBI_LINE_ERROR_CGMS_NOENCODE)    )
1220                {
1221                        (void)BVBI_P_CGMSB_Encode_Data_isr (
1222                                        pVbi_Enc->pVbi->hReg,
1223                                        BVBI_P_is656(pVbi_Enc->eDest),
1224                                        pVbi_Enc->curr.hwCoreIndex[BVBI_P_EncCoreType_eCGMSAE],
1225                                        polarity,
1226                                        *(pVbi_Fld->pCgmsbDatum));
1227                }
1228#endif /** } **/
1229                if ( (whatActive               & BVBI_P_SELECT_WSS           ) &&
1230                         (pVbi_Fld->ulWhichPresent & BVBI_P_SELECT_WSS           ) &&
1231                         !(pVbi_Fld->ulErrInfo     & BVBI_LINE_ERROR_WSS_NOENCODE)    )
1232                {
1233                        (void)BVBI_P_WSS_Encode_Data_isr (
1234                                        pVbi_Enc->pVbi->hReg,
1235                                        BVBI_P_is656(pVbi_Enc->eDest),
1236                                        pVbi_Enc->curr.hwCoreIndex[BVBI_P_EncCoreType_eWSE],
1237                                        polarity,
1238                                        pVbi_Fld->usWSSData );
1239                }
1240
1241                if ( (whatActive               & BVBI_P_SELECT_VPS           ) &&
1242                         (pVbi_Fld->ulWhichPresent & BVBI_P_SELECT_VPS           ) &&
1243                         !(pVbi_Fld->ulErrInfo     & BVBI_LINE_ERROR_VPS_NOENCODE)    )
1244                {
1245                        (void)BVBI_P_VPS_Encode_Data_isr (
1246                                        pVbi_Enc->pVbi->hReg,
1247                                        BVBI_P_is656(pVbi_Enc->eDest),
1248                                        pVbi_Enc->curr.hwCoreIndex[BVBI_P_EncCoreType_eWSE],
1249                                        polarity,
1250                                        pVbi_Fld->pVPSData );
1251                }
1252#if (BVBI_P_NUM_TTE > 0) || (BVBI_P_NUM_TTE_656 > 0)
1253                if ( (whatActive               & BVBI_P_SELECT_TT                 ) &&
1254                         (pVbi_Fld->ulWhichPresent & BVBI_P_SELECT_TT                 ) &&
1255                         !(pVbi_Fld->ulErrInfo     & BVBI_LINE_ERROR_TELETEXT_NOENCODE)    )
1256                {
1257                        BVBI_P_TTData* pttData;
1258                        if (polarity == BAVC_Polarity_eTopField)
1259                        {
1260                                BVBI_P_LCOP_COPY_isr (
1261                                        pVbi_Fld, TTDataO, pVbi_Enc, topTTDataO,
1262                                        &pVbi->ttFreelist, clink);
1263                                pttData = BVBI_P_LCOP_GET_isr (pVbi_Enc, topTTDataO);
1264                        }
1265                        else
1266                        {
1267                                BVBI_P_LCOP_COPY_isr (
1268                                        pVbi_Fld, TTDataO, pVbi_Enc, botTTDataO,
1269                                        &pVbi->ttFreelist, clink);
1270                                pttData = BVBI_P_LCOP_GET_isr (pVbi_Enc, botTTDataO);
1271                        }
1272                        (void)BVBI_P_TT_Encode_Data_isr (
1273                                        pVbi_Enc->pVbi->hReg,
1274                                        pVbi_Enc->pVbi->hMem,
1275                                        BVBI_P_is656(pVbi_Enc->eDest),
1276                                        pVbi_Enc->curr.hwCoreIndex[BVBI_P_EncCoreType_eTTE],
1277                                        currentState->eVideoFormat,
1278                                        polarity,
1279                                        currentState->bPR18010_bad_line_number,
1280                                        pttData);
1281                }
1282#endif
1283#if (BVBI_P_NUM_GSE > 0)
1284                if ( (whatActive               & BVBI_P_SELECT_GS                ) &&
1285                         (pVbi_Fld->ulWhichPresent & BVBI_P_SELECT_GS                ) &&
1286                         !(pVbi_Fld->ulErrInfo     & BVBI_LINE_ERROR_GEMSTAR_NOENCODE)    )
1287                {
1288                        (void)BVBI_P_GS_Encode_Data_isr (
1289                                        pVbi_Enc->pVbi->hReg,
1290                                        BVBI_P_is656(pVbi_Enc->eDest),
1291                                        pVbi_Enc->curr.hwCoreIndex[BVBI_P_EncCoreType_eGSE],
1292                                        currentState->eVideoFormat,
1293                                        polarity,
1294                                        pVbi_Fld->pGSData );
1295                }
1296#endif
1297#if (BVBI_P_NUM_AMOLE > 0)
1298                if ( (whatActive               & BVBI_P_SELECT_AMOL              ) &&
1299                         (pVbi_Fld->ulWhichPresent & BVBI_P_SELECT_AMOL              ) &&
1300                         !(pVbi_Fld->ulErrInfo     & BVBI_LINE_ERROR_AMOL_NOENCODE   )    )
1301                {
1302                        (void)BVBI_P_AMOL_Encode_Data_isr (
1303                                        pVbi_Enc->pVbi->hReg,
1304                                        BVBI_P_is656(pVbi_Enc->eDest),
1305                                        pVbi_Enc->curr.hwCoreIndex[BVBI_P_EncCoreType_eAMOLE],
1306                                        currentState->eVideoFormat,
1307                                        polarity,
1308                                        pVbi_Fld->amolType,
1309                                        pVbi_Fld->pAmolData );
1310                }
1311#endif
1312                if ( (whatActive               & BVBI_P_SELECT_MCC              ) &&
1313                         (pVbi_Fld->ulWhichPresent & BVBI_P_SELECT_MCC              ) &&
1314                         !(pVbi_Fld->ulErrInfo     & BVBI_LINE_ERROR_MCC_NOENCODE   )    )
1315                {
1316                        (void)BVBI_P_MCC_Encode_Data_isr (
1317                                        pVbi_Enc->pVbi->hReg,
1318                                        BVBI_P_is656(pVbi_Enc->eDest),
1319                                        pVbi_Enc->curr.hwCoreIndex[BVBI_P_EncCoreType_eCCE],
1320                                        currentState->eVideoFormat,
1321                                        polarity,
1322                                        currentState->bPR18010_bad_line_number,
1323                                        pVbi_Fld->pMCCData );
1324                }
1325#if (BVBI_P_NUM_SCTEE > 0)  /** { **/
1326                if ( (whatActive               & BVBI_P_SELECT_SCTE              ) &&
1327                         (pVbi_Fld->ulWhichPresent & BVBI_P_SELECT_SCTE              ) &&
1328                         !(pVbi_Fld->ulErrInfo     & BVBI_LINE_ERROR_SCTE_NOENCODE   )    )
1329                {
1330                        (void)BVBI_P_SCTE_Encode_Data_isr (
1331                                        pVbi_Enc->pVbi->hReg,
1332                                        pVbi_Enc->pVbi->hMem,
1333                                        BVBI_P_is656(pVbi_Enc->eDest),
1334                                        pVbi_Enc->curr.hwCoreIndex[BVBI_P_EncCoreType_eSCTE],
1335                                        currentState->eVideoFormat,
1336                                        polarity,
1337                                        currentState->scteType,
1338                                        pVbi_Fld->pPScteData,
1339                                        pVbi_Enc->hTopScteNrtv,
1340                                        pVbi_Enc->hBotScteNrtv,
1341                                        pVbi_Enc->hTopScteMono,
1342                                        pVbi_Enc->hBotScteMono,
1343                                        &pVbi_Enc->sctePamData);
1344                }
1345#endif /** } BVBI_P_NUM_SCTEE **/
1346        }
1347
1348        BDBG_LEAVE(BVBI_Encode_Data_isr);
1349        return eErr;
1350}
1351
1352/***************************************************************************
1353 *
1354 */
1355static BERR_Code BVBI_P_Encode_ApplyChanges (
1356        BVBI_P_Encode_Handle *pVbi_Enc, BVBI_P_Encode_CNState* cnState, bool force)
1357{
1358        BVBI_P_Handle *pVbi;
1359        uint32_t nextActive;
1360        bool isActive;
1361        BERR_Code eErr;
1362        uint8_t hwCoreIndex[BVBI_P_EncCoreType_eLAST];
1363        BERR_Code firstErr= BERR_SUCCESS;
1364
1365        BDBG_ENTER(BVBI_P_Encode_ApplyChanges);
1366
1367        /* Get back pointer to VBI module, for convenience. */
1368        pVbi = pVbi_Enc->pVbi;
1369
1370        /* Cannot do closed caption and multi-line closed caption  at the
1371         * same time, because the same hardware core is used for both forms.
1372         */
1373        if ((cnState->ulActive_Standards & BVBI_P_SELECT_MCC) &&
1374            (cnState->ulActive_Standards & BVBI_P_SELECT_CC)    )
1375        {
1376                eErr = BVBI_ERR_CORE_CONFLICT;
1377                if (firstErr == BERR_SUCCESS)
1378                        firstErr = eErr;
1379                if (!force)
1380                        goto done;
1381        }
1382
1383        /* Form union of cores presently in use, and cores in use after changes are
1384         * applied. Thus, we will be able to program cores that will later be
1385         * disconnected */
1386        P_UnionAllocatedCores (
1387                pVbi_Enc->curr.hwCoreIndex, pVbi_Enc->next.hwCoreIndex, hwCoreIndex);
1388
1389        /* Connect new encoder cores as required */
1390        BVBI_P_Encode_ConnectCores (
1391                pVbi->hReg, pVbi_Enc->eDest, hwCoreIndex);
1392
1393        /* This step has to be done in advance of the programming of individual
1394           encoder cores. Otherwise, the VEC may hang. See PR19719. */
1395        eErr = BERR_TRACE (BVBI_P_VE_Enc_Program (
1396                pVbi->hReg,
1397                BVBI_P_is656(pVbi_Enc->eDest),
1398                hwCoreIndex[BVBI_P_EncCoreType_eVBIENC],
1399                cnState->ulActive_Standards,
1400                cnState->ulActive_656_Standards,
1401                cnState->eVideoFormat));
1402        if (eErr != BERR_SUCCESS)
1403        {
1404                if (firstErr == BERR_SUCCESS)
1405                        firstErr = eErr;
1406                if (!force)
1407                        goto done;
1408        }
1409
1410#if (BVBI_P_HAS_XSER_TT)
1411        eErr = BERR_TRACE (BVBI_P_ITU656_Enc_Program (
1412                pVbi->hReg,
1413                &cnState->xserSettings,
1414                cnState->ulActive_XSER_Standards));
1415        if (eErr != BERR_SUCCESS)
1416        {
1417                if (firstErr == BERR_SUCCESS)
1418                        firstErr = eErr;
1419                if (!force)
1420                        goto done;
1421        }
1422#endif
1423
1424        /*
1425         * Program encoder cores not already done
1426         */
1427
1428        /* Union of all VBI outputs for next state */
1429        nextActive =
1430                cnState->ulActive_Standards |
1431                cnState->ulActive_656_Standards |
1432                cnState->ulActive_XSER_Standards;
1433
1434        isActive = ((nextActive & BVBI_P_SELECT_CC) != 0);
1435        if (force || BVBI_P_Encode_IsDirty (pVbi_Enc, nextActive, BVBI_P_SELECT_CC))
1436        {
1437                eErr = BERR_TRACE (BVBI_P_CC_Enc_Program (
1438                        pVbi->hReg,
1439                        BVBI_P_is656(pVbi_Enc->eDest),
1440                        hwCoreIndex[BVBI_P_EncCoreType_eCCE],
1441                        isActive,
1442                        cnState->bPR18010_bad_line_number,
1443                        cnState->eVideoFormat));
1444                if (eErr != BERR_SUCCESS)
1445                {
1446                        if (firstErr == BERR_SUCCESS)
1447                                firstErr = eErr;
1448                        if (!force)
1449                                goto done;
1450                }
1451        }
1452        isActive = ((nextActive & BVBI_P_SELECT_CGMSA) != 0);
1453        if (force ||
1454                BVBI_P_Encode_IsDirty (pVbi_Enc, nextActive, BVBI_P_SELECT_CGMSA))
1455        {
1456                eErr = BERR_TRACE (BVBI_P_CGMSA_Enc_Program (
1457                        pVbi->hReg,
1458                        BVBI_P_is656(pVbi_Enc->eDest),
1459                        hwCoreIndex[BVBI_P_EncCoreType_eCGMSAE],
1460                        isActive,
1461                        cnState->eVideoFormat,
1462                        cnState->ePixRep));
1463                if (eErr != BERR_SUCCESS)
1464                {
1465                        if (firstErr == BERR_SUCCESS)
1466                                firstErr = eErr;
1467                        if (!force)
1468                                goto done;
1469                }
1470        }
1471#if defined(BVBI_P_CGMSAE_VER2) || defined(BVBI_P_CGMSAE_VER3) || \
1472    defined(BVBI_P_CGMSAE_VER5)  /** { **/
1473        isActive = ((nextActive & BVBI_P_SELECT_CGMSB) != 0);
1474        if (force ||
1475                BVBI_P_Encode_IsDirty (pVbi_Enc, nextActive, BVBI_P_SELECT_CGMSB))
1476        {
1477                eErr = BERR_TRACE (BVBI_P_CGMSB_Enc_Program (
1478                        pVbi->hReg,
1479                        BVBI_P_is656(pVbi_Enc->eDest),
1480                        hwCoreIndex[BVBI_P_EncCoreType_eCGMSAE],
1481                        isActive,
1482                        cnState->eVideoFormat,
1483                        cnState->ePixRep,
1484                        cnState->bCea805dStyle));
1485                if (eErr != BERR_SUCCESS)
1486                {
1487                        if (firstErr == BERR_SUCCESS)
1488                                firstErr = eErr;
1489                        if (!force)
1490                                goto done;
1491                }
1492        }
1493#endif /** } **/
1494        isActive = ((nextActive & BVBI_P_SELECT_WSS) != 0);
1495        if (force ||
1496                BVBI_P_Encode_IsDirty (pVbi_Enc, nextActive, BVBI_P_SELECT_WSS))
1497        {
1498                eErr = BERR_TRACE (BVBI_P_WSS_Enc_Program (
1499                        pVbi->hReg,
1500                        BVBI_P_is656(pVbi_Enc->eDest),
1501                        hwCoreIndex[BVBI_P_EncCoreType_eWSE],
1502                        isActive,
1503                        cnState->bPR18010_bad_line_number,
1504                        cnState->eVideoFormat));
1505                if (eErr != BERR_SUCCESS)
1506                {
1507                        if (firstErr == BERR_SUCCESS)
1508                                firstErr = eErr;
1509                        if (!force)
1510                                goto done;
1511                }
1512        }
1513        isActive = ((nextActive & BVBI_P_SELECT_VPS) != 0);
1514        if (force ||
1515                BVBI_P_Encode_IsDirty (pVbi_Enc, nextActive, BVBI_P_SELECT_VPS))
1516        {
1517                eErr = BERR_TRACE (BVBI_P_VPS_Enc_Program (
1518                        pVbi->hReg,
1519                        BVBI_P_is656(pVbi_Enc->eDest),
1520                        hwCoreIndex[BVBI_P_EncCoreType_eWSE],
1521                        isActive,
1522                        cnState->eVideoFormat));
1523                if (eErr != BERR_SUCCESS)
1524                {
1525                        if (firstErr == BERR_SUCCESS)
1526                                firstErr = eErr;
1527                        if (!force)
1528                                goto done;
1529                }
1530        }
1531        isActive = ((nextActive & BVBI_P_SELECT_TT) != 0);
1532        if (force || BVBI_P_Encode_IsDirty (pVbi_Enc, nextActive, BVBI_P_SELECT_TT))
1533        {
1534                /* Find DRAM for teletext storage */
1535                BVBI_P_TTData* ptopData;
1536                BVBI_P_TTData* pbotData;
1537                BVBI_P_LCOP_WRITE (
1538                        pVbi_Enc, topTTDataO, &pVbi->ttFreelist, clink);
1539                ptopData =  BVBI_P_LCOP_GET (pVbi_Enc, topTTDataO);
1540                BVBI_P_LCOP_WRITE (
1541                        pVbi_Enc, botTTDataO, &pVbi->ttFreelist, clink);
1542                pbotData =  BVBI_P_LCOP_GET (pVbi_Enc, botTTDataO);
1543
1544#if (BVBI_P_NUM_TTE > 0) || (BVBI_P_NUM_TTE_656 > 0)
1545                /* coverity[var_deref_model: FALSE] */
1546                eErr = BERR_TRACE (BVBI_P_TT_Enc_Program (
1547                        pVbi->hReg,
1548                        pVbi->hMem,
1549                        BVBI_P_is656(pVbi_Enc->eDest),
1550                        hwCoreIndex[BVBI_P_EncCoreType_eTTE],
1551                        isActive,
1552                        ((cnState->ulActive_XSER_Standards & BVBI_P_SELECT_TT) != 0),
1553                        cnState->eVideoFormat,
1554                        pVbi->tteShiftDirMsb2Lsb,
1555                        &cnState->xserSettings,
1556                        ptopData,
1557                        pbotData
1558                ));
1559                if (eErr != BERR_SUCCESS)
1560                {
1561                        if (firstErr == BERR_SUCCESS)
1562                                firstErr = eErr;
1563                        if (!force)
1564                                goto done;
1565                }
1566#endif
1567        }
1568
1569#if (BVBI_P_NUM_GSE > 0)
1570        isActive = ((nextActive & BVBI_P_SELECT_GS) != 0);
1571        if (force || BVBI_P_Encode_IsDirty (pVbi_Enc, nextActive, BVBI_P_SELECT_GS))
1572        {
1573                eErr = BERR_TRACE (BVBI_P_GS_Enc_Program (
1574                        pVbi->hReg,
1575                        BVBI_P_is656(pVbi_Enc->eDest),
1576                        hwCoreIndex[BVBI_P_EncCoreType_eGSE],
1577                        isActive,
1578                        cnState->eVideoFormat,
1579                        &cnState->gsOptions
1580                ));
1581                if (eErr != BERR_SUCCESS)
1582                {
1583                        if (firstErr == BERR_SUCCESS)
1584                                firstErr = eErr;
1585                        if (!force)
1586                                goto done;
1587                }
1588        }
1589#endif
1590#if (BVBI_P_NUM_AMOLE > 0)
1591        isActive = ((nextActive & BVBI_P_SELECT_AMOL) != 0);
1592        if (force ||
1593                BVBI_P_Encode_IsDirty (pVbi_Enc, nextActive, BVBI_P_SELECT_AMOL))
1594        {
1595                eErr = BERR_TRACE (BVBI_P_AMOL_Enc_Program (
1596                        pVbi->hReg,
1597                        BVBI_P_is656(pVbi_Enc->eDest),
1598                        hwCoreIndex[BVBI_P_EncCoreType_eAMOLE],
1599                        isActive,
1600                        cnState->eVideoFormat,
1601                        cnState->amolType
1602                ));
1603                if (eErr != BERR_SUCCESS)
1604                {
1605                        if (firstErr == BERR_SUCCESS)
1606                                firstErr = eErr;
1607                        if (!force)
1608                                goto done;
1609                }
1610        }
1611#endif
1612        isActive = ((nextActive & BVBI_P_SELECT_MCC) != 0);
1613        /* Cannot initialize both CC and MCC. It is one or the other. */
1614        if ((nextActive & BVBI_P_SELECT_CC) == 0)
1615        {
1616                if (force ||
1617                        BVBI_P_Encode_IsDirty (pVbi_Enc, nextActive, BVBI_P_SELECT_MCC))
1618                {
1619                        eErr = BERR_TRACE (BVBI_P_MCC_Enc_Program (
1620                                pVbi->hReg,
1621                                BVBI_P_is656(pVbi_Enc->eDest),
1622                                hwCoreIndex[BVBI_P_EncCoreType_eCCE],
1623                                isActive,
1624                                cnState->eVideoFormat
1625                        ));
1626                        if (eErr != BERR_SUCCESS)
1627                        {
1628                                if (firstErr == BERR_SUCCESS)
1629                                        firstErr = eErr;
1630                                if (!force)
1631                                        goto done;
1632                        }
1633                }
1634        }
1635#if (BVBI_P_NUM_SCTEE > 0)  /** { **/
1636        isActive = ((nextActive & BVBI_P_SELECT_SCTE) != 0);
1637        if (force ||
1638                BVBI_P_Encode_IsDirty (pVbi_Enc, nextActive, BVBI_P_SELECT_SCTE))
1639        {
1640                eErr = BERR_TRACE (BVBI_P_SCTE_Enc_Program (
1641                        pVbi->hReg,
1642                        BVBI_P_is656(pVbi_Enc->eDest),
1643                        hwCoreIndex[BVBI_P_EncCoreType_eSCTE],
1644                        isActive,
1645                        cnState->eVideoFormat,
1646                        cnState->scteType,
1647                        cnState->eCsc,
1648                        cnState->eCoCsc
1649                ));
1650                if (eErr != BERR_SUCCESS)
1651                {
1652                        if (firstErr == BERR_SUCCESS)
1653                                firstErr = eErr;
1654                        if (!force)
1655                                goto done;
1656                }
1657        }
1658#endif /** } BVBI_P_NUM_SCTEE **/
1659
1660/*
1661 * The 7118, 7601 chipsets have no ANCI656 core
1662 * If modular VEC, there is only one ANCI656 core, associated with the
1663 * Ancillary VEC path
1664 * Otherwise, there is one ANCI656 core per VEC path.
1665 */
1666#if (BVBI_P_NUM_ANCI656_656 > 0) /** { **/
1667        if (hwCoreIndex[BVBI_P_EncCoreType_eANCI] != 0xFF)
1668        {
1669                if (BVBI_P_is656 (pVbi_Enc->eDest))
1670                {
1671                        eErr = BERR_TRACE (BVBI_P_A656_Enc_Program (
1672                                pVbi->hReg,
1673                                hwCoreIndex[BVBI_P_EncCoreType_eANCI],
1674                                &cnState->h656options,
1675                                cnState->bPR18010_bad_line_number,
1676                                cnState->eVideoFormat));
1677                        if (eErr != BERR_SUCCESS)
1678                        {
1679                                if (firstErr == BERR_SUCCESS)
1680                                        firstErr = eErr;
1681                                if (!force)
1682                                        goto done;
1683                        }
1684                }
1685        }
1686#endif /** } BVBI_P_NUM_ANCI656 **/
1687/* TODO: Does the ANCI656 core need to be connected via the crossbar? */
1688
1689        /* Disconnect old cores no longer required */
1690        BVBI_P_Encode_ConnectCores (
1691                pVbi->hReg, pVbi_Enc->eDest, pVbi_Enc->next.hwCoreIndex);
1692
1693done:
1694        BDBG_LEAVE(BVBI_P_Encode_ApplyChanges);
1695        return firstErr;
1696}
1697
1698/***************************************************************************
1699 *
1700 */
1701
1702BERR_Code BVBI_Encode_SetCC(BVBI_Encode_Handle encodeHandle, bool bEnabled)
1703{
1704        return BVBI_P_Encode_Set_VBI (encodeHandle, bEnabled, BVBI_P_SELECT_CC);
1705}
1706BERR_Code BVBI_Encode_SetCGMSA(BVBI_Encode_Handle encodeHandle, bool bEnabled)
1707{
1708        return BVBI_P_Encode_Set_VBI (encodeHandle, bEnabled, BVBI_P_SELECT_CGMSA);
1709}
1710BERR_Code BVBI_Encode_SetCGMSB(BVBI_Encode_Handle encodeHandle, bool bEnabled)
1711{
1712#if defined(BVBI_P_CGMSAE_VER2) || defined(BVBI_P_CGMSAE_VER3) || \
1713    defined(BVBI_P_CGMSAE_VER5)  /** { **/
1714#else
1715        BSTD_UNUSED(encodeHandle);
1716        if (bEnabled)
1717        {
1718                BDBG_ERR(("No CGMS-B hardware feature"));
1719                return BERR_TRACE(BVBI_ERR_HW_UNSUPPORTED);
1720        }
1721#endif
1722        return BVBI_P_Encode_Set_VBI (encodeHandle, bEnabled, BVBI_P_SELECT_CGMSB);
1723}
1724BERR_Code BVBI_Encode_SetWSS(BVBI_Encode_Handle encodeHandle, bool bEnabled)
1725{
1726        return BVBI_P_Encode_Set_VBI (encodeHandle, bEnabled, BVBI_P_SELECT_WSS);
1727}
1728BERR_Code BVBI_Encode_SetVPS(BVBI_Encode_Handle encodeHandle, bool bEnabled)
1729{
1730        return BVBI_P_Encode_Set_VBI (encodeHandle, bEnabled, BVBI_P_SELECT_VPS);
1731}
1732BERR_Code BVBI_Encode_SetTeletext(
1733        BVBI_Encode_Handle encodeHandle, bool bEnabled)
1734{
1735#if (BVBI_P_NUM_TTE > 0) || (BVBI_P_NUM_TTE_656 > 0)
1736#else
1737        BSTD_UNUSED(encodeHandle);
1738        if (bEnabled)
1739        {
1740                BDBG_ERR(("No teletext hardware feature"));
1741                return BERR_TRACE(BVBI_ERR_HW_UNSUPPORTED);
1742        }
1743#endif
1744        return BVBI_P_Encode_Set_VBI (encodeHandle, bEnabled, BVBI_P_SELECT_TT);
1745}
1746BERR_Code BVBI_Encode_SetGemstar(
1747        BVBI_Encode_Handle encodeHandle, bool bEnabled)
1748{
1749#if (BVBI_P_NUM_GSE > 0)
1750#else
1751        BSTD_UNUSED(encodeHandle);
1752        if (bEnabled)
1753        {
1754                BDBG_ERR(("No Gemstar hardware feature"));
1755                return BERR_TRACE(BVBI_ERR_HW_UNSUPPORTED);
1756        }
1757#endif
1758        return BVBI_P_Encode_Set_VBI (encodeHandle, bEnabled, BVBI_P_SELECT_GS);
1759}
1760BERR_Code BVBI_Encode_SetAMOL(
1761        BVBI_Encode_Handle encodeHandle, bool bEnabled)
1762{
1763#if (BVBI_P_NUM_AMOLE > 0)
1764#else
1765        BSTD_UNUSED(encodeHandle);
1766        if (bEnabled)
1767        {
1768                BDBG_ERR(("No AMOL hardware feature"));
1769                return BERR_TRACE(BVBI_ERR_HW_UNSUPPORTED);
1770        }
1771#endif
1772        return BVBI_P_Encode_Set_VBI (encodeHandle, bEnabled, BVBI_P_SELECT_AMOL);
1773}
1774BERR_Code BVBI_Encode_SetMCC(
1775        BVBI_Encode_Handle encodeHandle, bool bEnabled)
1776{
1777        return BVBI_P_Encode_Set_VBI (encodeHandle, bEnabled, BVBI_P_SELECT_MCC);
1778}
1779BERR_Code BVBI_Encode_SetSCTE(
1780        BVBI_Encode_Handle encodeHandle, bool bEnabled)
1781{
1782#if (BVBI_P_NUM_SCTEE > 0) 
1783#else
1784        BSTD_UNUSED(encodeHandle);
1785        if (bEnabled)
1786        {
1787                BDBG_ERR(("No SCTE hardware feature"));
1788                return BERR_TRACE(BVBI_ERR_HW_UNSUPPORTED);
1789        }
1790#endif
1791        return BVBI_P_Encode_Set_VBI (encodeHandle, bEnabled, BVBI_P_SELECT_SCTE);
1792}
1793
1794BERR_Code BVBI_Encode_GetCC(BVBI_Encode_Handle encodeHandle, bool* pbEnabled)
1795{
1796        return BVBI_P_Encode_Get_VBI (encodeHandle, pbEnabled, BVBI_P_SELECT_CC);
1797}
1798BERR_Code BVBI_Encode_GetCGMSA(BVBI_Encode_Handle encodeHandle, bool* pbEnabled)
1799{
1800        return BVBI_P_Encode_Get_VBI (encodeHandle, pbEnabled, BVBI_P_SELECT_CGMSA);
1801}
1802BERR_Code BVBI_Encode_GetCGMSB(BVBI_Encode_Handle encodeHandle, bool* pbEnabled)
1803{
1804        return BVBI_P_Encode_Get_VBI (encodeHandle, pbEnabled, BVBI_P_SELECT_CGMSB);
1805}
1806BERR_Code BVBI_Encode_GetWSS(BVBI_Encode_Handle encodeHandle, bool* pbEnabled)
1807{
1808        return BVBI_P_Encode_Get_VBI (encodeHandle, pbEnabled, BVBI_P_SELECT_WSS);
1809}
1810BERR_Code BVBI_Encode_GetVPS(BVBI_Encode_Handle encodeHandle, bool* pbEnabled)
1811{
1812        return BVBI_P_Encode_Get_VBI (encodeHandle, pbEnabled, BVBI_P_SELECT_VPS);
1813}
1814BERR_Code BVBI_Encode_GetTeletext(
1815        BVBI_Encode_Handle encodeHandle, bool* pbEnabled)
1816{
1817        return BVBI_P_Encode_Get_VBI (encodeHandle, pbEnabled, BVBI_P_SELECT_TT);
1818}
1819BERR_Code BVBI_Encode_GetGemstar(
1820        BVBI_Encode_Handle encodeHandle, bool* pbEnabled)
1821{
1822        return BVBI_P_Encode_Get_VBI (encodeHandle, pbEnabled, BVBI_P_SELECT_GS);
1823}
1824BERR_Code BVBI_Encode_GetAMOL(
1825        BVBI_Encode_Handle encodeHandle, bool* pbEnabled)
1826{
1827        return BVBI_P_Encode_Get_VBI (encodeHandle, pbEnabled, BVBI_P_SELECT_AMOL);
1828}
1829BERR_Code BVBI_Encode_GetMCC(
1830        BVBI_Encode_Handle encodeHandle, bool* pbEnabled)
1831{
1832        return BVBI_P_Encode_Get_VBI (encodeHandle, pbEnabled, BVBI_P_SELECT_MCC);
1833}
1834BERR_Code BVBI_Encode_GetSCTE(
1835        BVBI_Encode_Handle encodeHandle, bool* pbEnabled)
1836{
1837        return BVBI_P_Encode_Get_VBI (encodeHandle, pbEnabled, BVBI_P_SELECT_SCTE);
1838}
1839
1840BERR_Code BVBI_Encode_656_SetCC(BVBI_Encode_Handle encodeHandle, bool bEnabled)
1841{
1842        return BVBI_P_Encode_656_Set_VBI (encodeHandle, bEnabled, BVBI_P_SELECT_CC);
1843}
1844BERR_Code BVBI_Encode_656_SetWSS(BVBI_Encode_Handle encodeHandle, bool bEnabled)
1845{
1846        return BVBI_P_Encode_656_Set_VBI (
1847                encodeHandle, bEnabled, BVBI_P_SELECT_WSS);
1848}
1849BERR_Code BVBI_Encode_656_SetTeletext(
1850        BVBI_Encode_Handle encodeHandle, bool bEnabled)
1851{
1852        return BVBI_P_Encode_656_Set_VBI (encodeHandle, bEnabled, BVBI_P_SELECT_TT);
1853}
1854BERR_Code BVBI_Encode_656_SetGemstar(
1855        BVBI_Encode_Handle encodeHandle, bool bEnabled)
1856{
1857        return BVBI_P_Encode_656_Set_VBI (encodeHandle, bEnabled, BVBI_P_SELECT_GS);
1858}
1859BERR_Code BVBI_Encode_656_SetAMOL(
1860        BVBI_Encode_Handle encodeHandle, bool bEnabled)
1861{
1862        return BVBI_P_Encode_656_Set_VBI (
1863                encodeHandle, bEnabled, BVBI_P_SELECT_AMOL);
1864}
1865BERR_Code BVBI_Encode_656_SetMCC(
1866        BVBI_Encode_Handle encodeHandle, bool bEnabled)
1867{
1868        return BVBI_P_Encode_656_Set_VBI (
1869                encodeHandle, bEnabled, BVBI_P_SELECT_MCC);
1870}
1871BERR_Code BVBI_Encode_656_SetSCTE(
1872        BVBI_Encode_Handle encodeHandle, bool bEnabled)
1873{
1874        return BVBI_P_Encode_656_Set_VBI (
1875                encodeHandle, bEnabled, BVBI_P_SELECT_SCTE);
1876}
1877
1878BERR_Code BVBI_Encode_656_GetCC(
1879        BVBI_Encode_Handle encodeHandle, bool* pbEnabled)
1880{
1881        return BVBI_P_Encode_656_Get_VBI (
1882                encodeHandle, pbEnabled, BVBI_P_SELECT_CC);
1883}
1884BERR_Code BVBI_Encode_656_GetWSS(
1885        BVBI_Encode_Handle encodeHandle, bool* pbEnabled)
1886{
1887        return BVBI_P_Encode_656_Get_VBI (
1888                encodeHandle, pbEnabled, BVBI_P_SELECT_WSS);
1889}
1890BERR_Code BVBI_Encode_656_GetTeletext(
1891        BVBI_Encode_Handle encodeHandle, bool* pbEnabled)
1892{
1893        return BVBI_P_Encode_656_Get_VBI (
1894                encodeHandle, pbEnabled, BVBI_P_SELECT_TT);
1895}
1896BERR_Code BVBI_Encode_656_GetGemstar(
1897        BVBI_Encode_Handle encodeHandle, bool* pbEnabled)
1898{
1899        return BVBI_P_Encode_656_Get_VBI (
1900                encodeHandle, pbEnabled, BVBI_P_SELECT_GS);
1901}
1902BERR_Code BVBI_Encode_656_GetAMOL(
1903        BVBI_Encode_Handle encodeHandle, bool* pbEnabled)
1904{
1905        return BVBI_P_Encode_656_Get_VBI (
1906                encodeHandle, pbEnabled, BVBI_P_SELECT_AMOL);
1907}
1908BERR_Code BVBI_Encode_656_GetMCC(
1909        BVBI_Encode_Handle encodeHandle, bool* pbEnabled)
1910{
1911        return BVBI_P_Encode_656_Get_VBI (
1912                encodeHandle, pbEnabled, BVBI_P_SELECT_MCC);
1913}
1914BERR_Code BVBI_Encode_656_GetSCTE(
1915        BVBI_Encode_Handle encodeHandle, bool* pbEnabled)
1916{
1917        return BVBI_P_Encode_656_Get_VBI (
1918                encodeHandle, pbEnabled, BVBI_P_SELECT_SCTE);
1919}
1920
1921BERR_Code BVBI_Encode_XSER_SetTeletext(
1922        BVBI_Encode_Handle encodeHandle, bool bEnabled)
1923{
1924        return
1925                BVBI_P_Encode_XSER_Set_VBI (encodeHandle, bEnabled, BVBI_P_SELECT_TT);
1926}
1927BERR_Code BVBI_Encode_XSER_GetTeletext(
1928        BVBI_Encode_Handle encodeHandle, bool* pbEnabled)
1929{
1930        return BVBI_P_Encode_XSER_Get_VBI (
1931                encodeHandle, pbEnabled, BVBI_P_SELECT_TT);
1932}
1933
1934/***************************************************************************
1935* Static (private) functions
1936***************************************************************************/
1937
1938/***************************************************************************
1939 *
1940 */
1941static BERR_Code BVBI_P_Encode_Set_VBI(
1942        BVBI_Encode_Handle encodeHandle,
1943        bool bEnabled,
1944        uint32_t ulSelect_Standard)
1945{
1946        BVBI_P_Encode_Handle* pVbi_Enc;
1947        bool bIs656;
1948        BERR_Code eErr;
1949
1950
1951        BDBG_ENTER(BVBI_P_Encode_Set_VBI);
1952
1953        /* check parameters */
1954        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
1955        if(!pVbi_Enc)
1956        {
1957                BDBG_ERR(("Invalid parameter\n"));
1958                return BERR_TRACE(BERR_INVALID_PARAMETER);
1959        }
1960
1961        /* Is VEC path for 656 out? */
1962        bIs656 = BVBI_P_is656 (pVbi_Enc->eDest);
1963
1964        /* Record change to desired state */
1965        if (bEnabled)
1966        {
1967                /* If path is for 656, we have an error */
1968                if (bIs656)
1969                {
1970                        BDBG_ERR(("This VEC path only for 656 output"));
1971                        return BERR_TRACE(BVBI_ERR_HW_UNSUPPORTED);
1972                }
1973
1974                /* Reserve the required chip core */
1975                eErr = BVBI_P_Encode_ReserveCore (
1976                        pVbi_Enc->eDest, ulSelect_Standard, 
1977                        pVbi_Enc->pVbi->vecHwCoreMask, pVbi_Enc->pVbi->vecHwCoreMask_656, 
1978                        pVbi_Enc->next.hwCoreIndex);
1979                if (eErr != BERR_SUCCESS)
1980                {
1981                        BDBG_ERR(("Allocate failure\n"));
1982                        return BERR_TRACE(eErr);
1983                }
1984               
1985                /* Hardware configuration comes later */
1986                pVbi_Enc->next.ulActive_Standards |= ulSelect_Standard;
1987        }
1988        else
1989        {
1990                /* If path is for 656, we have no work to do */
1991                if (bIs656)
1992                {
1993                        BDBG_LEAVE(BVBI_P_Encode_Set_VBI);
1994                        return BERR_SUCCESS;
1995                }
1996
1997                /* Hardware configuration comes later */
1998                pVbi_Enc->next.ulActive_Standards &= ~ulSelect_Standard;
1999
2000                /* Release hardware core (most of the time) */
2001                BVBI_P_Encode_ReleaseCore (
2002                        pVbi_Enc->eDest, ulSelect_Standard, 
2003                        pVbi_Enc->next.ulActive_Standards, 
2004                        pVbi_Enc->pVbi->vecHwCoreMask, pVbi_Enc->pVbi->vecHwCoreMask_656, 
2005                        pVbi_Enc->next.hwCoreIndex);
2006        }
2007
2008        BDBG_LEAVE(BVBI_P_Encode_Set_VBI);
2009        return BERR_SUCCESS;
2010}
2011
2012/***************************************************************************
2013 *
2014 */
2015static BERR_Code BVBI_P_Encode_Get_VBI(
2016        BVBI_Encode_Handle encodeHandle,
2017        bool* pbEnabled,
2018        uint32_t ulSelect_Standard)
2019{
2020        BVBI_P_Encode_Handle* pVbi_Enc;
2021
2022        BDBG_ENTER(BVBI_P_Encode_Get_VBI);
2023
2024        /* check parameters */
2025        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
2026        if((!pVbi_Enc) || (!pbEnabled))
2027        {
2028                BDBG_ERR(("Invalid parameter\n"));
2029                BDBG_LEAVE(BVBI_P_Encode_Get_VBI);
2030                return BERR_TRACE(BERR_INVALID_PARAMETER);
2031        }
2032
2033        /* Return info */
2034        *pbEnabled =
2035                ((pVbi_Enc->curr.ulActive_Standards & ulSelect_Standard) != 0);
2036
2037        BDBG_LEAVE(BVBI_P_Encode_Get_VBI);
2038        return BERR_SUCCESS;
2039}
2040
2041/***************************************************************************
2042 *
2043 */
2044static BERR_Code BVBI_P_Encode_656_Set_VBI(
2045        BVBI_Encode_Handle encodeHandle,
2046        bool bEnabled,
2047        uint32_t ulSelect_Standard)
2048{
2049        BVBI_P_Encode_Handle* pVbi_Enc;
2050        bool bIs656;
2051        BERR_Code eErr;
2052
2053        BDBG_ENTER(BVBI_P_Encode_656_Set_VBI);
2054
2055        /* check parameters */
2056        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
2057        if(!pVbi_Enc)
2058        {
2059                BDBG_ERR(("Invalid parameter\n"));
2060                return BERR_TRACE(BERR_INVALID_PARAMETER);
2061        }
2062
2063        /* Is VEC path for 656 out? */
2064        bIs656 = BVBI_P_is656 (pVbi_Enc->eDest);
2065
2066        /* Record change to desired state */
2067        if (bEnabled)
2068        {
2069                /* If path is not for 656, we have an error */
2070                if (!bIs656)
2071                {
2072                        BDBG_ERR(("This VEC path not for 656 output"));
2073                        return BERR_TRACE(BVBI_ERR_HW_UNSUPPORTED);
2074                }
2075
2076                /* Reserve the required chip core */
2077                eErr = BVBI_P_Encode_ReserveCore (
2078                        pVbi_Enc->eDest, ulSelect_Standard, 
2079                        pVbi_Enc->pVbi->vecHwCoreMask, pVbi_Enc->pVbi->vecHwCoreMask_656, 
2080                        pVbi_Enc->next.hwCoreIndex);
2081                if (eErr != BERR_SUCCESS)
2082                {
2083                        BDBG_ERR(("Allocate failure\n"));
2084                        return BERR_TRACE(eErr);
2085                }
2086               
2087                /* Hardware configuration comes later */
2088                pVbi_Enc->next.ulActive_656_Standards |= ulSelect_Standard;
2089        }
2090        else
2091        {
2092                /* If path is not for 656, we have no work to do */
2093                if (!bIs656)
2094                {
2095                        BDBG_LEAVE(BVBI_P_Encode_656_Set_VBI);
2096                        return BERR_SUCCESS;
2097                }
2098
2099                /* Hardware configuration comes later */
2100                pVbi_Enc->next.ulActive_656_Standards &= ~ulSelect_Standard;
2101
2102                /* Release hardware core (most of the time) */
2103                BVBI_P_Encode_ReleaseCore (
2104                        pVbi_Enc->eDest, ulSelect_Standard,
2105                        pVbi_Enc->next.ulActive_656_Standards, 
2106                        pVbi_Enc->pVbi->vecHwCoreMask, pVbi_Enc->pVbi->vecHwCoreMask_656, 
2107                        pVbi_Enc->next.hwCoreIndex);
2108        }
2109
2110        BDBG_LEAVE(BVBI_P_Encode_656_Set_VBI);
2111        return BERR_SUCCESS;
2112}
2113
2114/***************************************************************************
2115 *
2116 */
2117static BERR_Code BVBI_P_Encode_656_Get_VBI(
2118        BVBI_Encode_Handle encodeHandle,
2119        bool* pbEnabled,
2120        uint32_t ulSelect_Standard)
2121{
2122        BVBI_P_Encode_Handle* pVbi_Enc;
2123
2124        BDBG_ENTER(BVBI_P_Encode_656_Get_VBI);
2125
2126        /* check parameters */
2127        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
2128        if((!pVbi_Enc) || (!pbEnabled))
2129        {
2130                BDBG_ERR(("Invalid parameter\n"));
2131                BDBG_LEAVE(BVBI_P_Encode_656_Get_VBI);
2132                return BERR_TRACE(BERR_INVALID_PARAMETER);
2133        }
2134
2135        /* Return info */
2136        *pbEnabled =
2137                ((pVbi_Enc->curr.ulActive_656_Standards & ulSelect_Standard) != 0);
2138
2139        BDBG_LEAVE(BVBI_P_Encode_656_Get_VBI);
2140        return BERR_SUCCESS;
2141}
2142
2143/***************************************************************************
2144 *
2145 */
2146static BERR_Code BVBI_P_Encode_XSER_Set_VBI(
2147        BVBI_Encode_Handle encodeHandle,
2148        bool bEnabled,
2149        uint32_t ulSelect_Standard)
2150{
2151        BVBI_P_Encode_Handle* pVbi_Enc;
2152
2153        BDBG_ENTER(BVBI_P_Encode_XSER_Set_VBI);
2154
2155        /* check parameters */
2156        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
2157        if(!pVbi_Enc)
2158        {
2159                BDBG_ERR(("Invalid parameter\n"));
2160                return BERR_TRACE(BERR_INVALID_PARAMETER);
2161        }
2162
2163        /* Record change to desired state */
2164        if (bEnabled)
2165        {
2166                pVbi_Enc->next.ulActive_XSER_Standards |= ulSelect_Standard;
2167        }
2168        else
2169        {
2170                pVbi_Enc->next.ulActive_XSER_Standards &= ~ulSelect_Standard;
2171        }
2172
2173        BDBG_LEAVE(BVBI_P_Encode_XSER_Set_VBI);
2174        return BERR_SUCCESS;
2175}
2176
2177/***************************************************************************
2178 *
2179 */
2180static BERR_Code BVBI_P_Encode_XSER_Get_VBI(
2181        BVBI_Encode_Handle encodeHandle,
2182        bool* pbEnabled,
2183        uint32_t ulSelect_Standard)
2184{
2185        BVBI_P_Encode_Handle* pVbi_Enc;
2186
2187        BDBG_ENTER(BVBI_P_Encode_XSER_Get_VBI);
2188
2189        /* check parameters */
2190        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
2191        if((!pVbi_Enc) || (!pbEnabled))
2192        {
2193                BDBG_ERR(("Invalid parameter\n"));
2194        BDBG_LEAVE(BVBI_P_Encode_Get_VBI);
2195                return BERR_TRACE(BERR_INVALID_PARAMETER);
2196        }
2197
2198        /* Return info */
2199        *pbEnabled =
2200                ((pVbi_Enc->curr.ulActive_XSER_Standards & ulSelect_Standard) != 0);
2201
2202        BDBG_LEAVE(BVBI_P_Encode_XSER_Get_VBI);
2203        return BERR_SUCCESS;
2204}
2205
2206/***************************************************************************
2207 *
2208 */
2209static bool BVBI_P_Encode_IsDirty (
2210        BVBI_P_Encode_Handle *pVbi_Enc,
2211        uint32_t nextActive, uint32_t ulSelect_Standard)
2212{
2213        BVBI_P_Encode_CNState* currentState = &pVbi_Enc->curr;
2214        BVBI_P_Encode_CNState* nextState    = &pVbi_Enc->next;
2215        uint32_t currentActive =
2216                currentState->ulActive_Standards |
2217                currentState->ulActive_656_Standards |
2218                currentState->ulActive_XSER_Standards;
2219
2220        bool retval = (
2221                 (currentActive & ulSelect_Standard) !=
2222                 (nextActive    & ulSelect_Standard)   );
2223
2224        if ((nextActive & ulSelect_Standard) != 0)
2225        {
2226                retval = 
2227                        retval || (nextState->eVideoFormat != currentState->eVideoFormat);
2228
2229                if (ulSelect_Standard == BVBI_P_SELECT_AMOL)
2230                {
2231                        retval = retval || (nextState->amolType != currentState->amolType);
2232                }
2233                if (ulSelect_Standard == BVBI_P_SELECT_SCTE)
2234                {
2235                        retval = retval || (nextState->scteType != currentState->scteType);
2236                        retval = retval || (nextState->eCsc     != currentState->eCsc    );
2237                        retval = retval || (nextState->eCoCsc   != currentState->eCoCsc  );
2238                }
2239                if (ulSelect_Standard == BVBI_P_SELECT_CGMSA)
2240                {
2241                        retval = 
2242                                retval ||
2243                                        (nextState->ePixRep != currentState->ePixRep);
2244                }
2245                if (ulSelect_Standard == BVBI_P_SELECT_CGMSB)
2246                {
2247                        retval = 
2248                                retval || 
2249                                        (nextState->bCea805dStyle != currentState->bCea805dStyle);
2250                        retval = 
2251                                retval ||
2252                                        (nextState->ePixRep != currentState->ePixRep);
2253                }
2254                if (ulSelect_Standard == BVBI_P_SELECT_GS)
2255                {
2256                        retval = retval ||
2257                                !P_GsOptionsEqual (
2258                                        &nextState->gsOptions, &currentState->gsOptions);
2259                }
2260                if (ulSelect_Standard == BVBI_P_SELECT_TT)
2261                {
2262                        retval = retval ||
2263                                !P_XserSettingsEqual (
2264                                        &nextState->xserSettings, &currentState->xserSettings);
2265                }
2266        }
2267
2268        return retval;
2269}
2270
2271/***************************************************************************
2272 *
2273 */
2274static void BVBI_P_Encode_ChangesApplied (BVBI_P_Encode_Handle *pVbi_Enc)
2275{
2276        pVbi_Enc->curr = pVbi_Enc->next;
2277}
2278
2279/***************************************************************************
2280 *
2281 */
2282bool BVBI_P_is656 (BAVC_VbiPath eDest)
2283{
2284        bool bIs656;
2285
2286        switch (eDest)
2287        {
2288        case BAVC_VbiPath_eVec0:
2289        case BAVC_VbiPath_eVec1:
2290        case BAVC_VbiPath_eVec2:
2291                bIs656 = false;
2292                break;
2293
2294        case BAVC_VbiPath_eBypass0:
2295        case BAVC_VbiPath_eBypass1:
2296                bIs656 = true;
2297                break;
2298
2299        default:
2300                bIs656 = false;
2301                BDBG_ASSERT (0);
2302                break;
2303        }
2304
2305        return bIs656;
2306}
2307
2308/***************************************************************************
2309 *
2310 */
2311void P_UnionAllocatedCores (
2312        const uint8_t hwCoreIndexA[BVBI_P_EncCoreType_eLAST],
2313        const uint8_t hwCoreIndexB[BVBI_P_EncCoreType_eLAST],
2314        uint8_t hwCoreIndexResult[BVBI_P_EncCoreType_eLAST])
2315{
2316        BVBI_P_EncCoreType eType;
2317
2318        for (eType = 0 ; eType < BVBI_P_EncCoreType_eLAST ; ++eType)
2319        {
2320                uint8_t indexA = hwCoreIndexA[eType];
2321                if (indexA == 0xFF)
2322                        hwCoreIndexResult[eType] = hwCoreIndexB[eType];
2323                else
2324                        hwCoreIndexResult[eType] = indexA;
2325        }
2326}
2327
2328
2329/***************************************************************************
2330 *
2331 */
2332static bool P_GsOptionsEqual (
2333        const BVBI_GSOptions* p1, const BVBI_GSOptions* p2)
2334{
2335        BDBG_ASSERT (BVBI_GSOptions_Version == 1);
2336
2337        return 
2338                (p1->bTvg2x       == p2->bTvg2x      ) &&
2339                (p1->baseline_top == p2->baseline_top) &&
2340                (p1->linemask_top == p2->linemask_top) &&
2341                (p1->baseline_bot == p2->baseline_bot) &&
2342                (p1->linemask_bot == p2->linemask_bot) ;
2343}
2344
2345/***************************************************************************
2346 *
2347 */
2348static bool P_XserSettingsEqual (
2349        const BVBI_XSER_Settings* p1, const BVBI_XSER_Settings* p2)
2350{
2351        BDBG_ASSERT (BVBI_XSER_Settings_Version == 1);
2352
2353        return
2354                (p1->xsSerialDataContent    == p2->xsSerialDataContent   ) &&
2355                (p1->ttSerialDataSync       == p2->ttSerialDataSync      ) &&
2356                (p1->iTTserialDataSyncDelay == p2->iTTserialDataSyncDelay) ;
2357}
2358
2359
2360/**********************
2361* Engineering special *
2362**********************/
2363
2364/***************************************************************************
2365 *
2366 */
2367BERR_Code BVBI_P_Encode_SetPR18010_behavior(
2368        BVBI_Encode_Handle encodeHandle, bool bPR18010_bad_line_number )
2369{
2370        BVBI_P_Encode_Handle *pVbi_Enc;
2371        BERR_Code eErr = BERR_SUCCESS;
2372
2373        BDBG_ENTER(BVBI_Encode_SetPR18010_behavior);
2374
2375        /* check parameters */
2376        BVBI_P_GET_ENCODE_CONTEXT(encodeHandle, pVbi_Enc);
2377        if(!pVbi_Enc)
2378        {
2379                BDBG_ERR(("Invalid parameter\n"));
2380                eErr = BERR_TRACE(BERR_INVALID_PARAMETER);
2381                goto done;
2382        }
2383
2384        /* Accept user's setting */
2385        pVbi_Enc->next.bPR18010_bad_line_number = bPR18010_bad_line_number;
2386
2387done:
2388        BDBG_LEAVE(BVBI_Encode_SetPR18010_behavior);
2389        return eErr;
2390
2391}
Note: See TracBrowser for help on using the repository browser.