source: svn/newcon3bcm2_21bu/magnum/commonutils/xdm/bxdm_pp_output.c @ 22

Last change on this file since 22 was 22, checked in by phkim, 11 years ago
  1. phkim
  2. newcon3sk 를 kctv 로 브랜치 함
  • Property svn:executable set to *
File size: 86.8 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2003-2012, 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: bxdm_pp_output.c $
11 * $brcm_Revision: Hydra_Software_Devel/46 $
12 * $brcm_Date: 2/22/12 3:38p $
13 *
14 * [File Description:]
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /magnum/commonutils/xdm/bxdm_pp_output.c $
19 *
20 * Hydra_Software_Devel/46   2/22/12 3:38p btosi
21 * SW7405-4736: add instance number and picture ID to messages
22 *
23 * Hydra_Software_Devel/45   2/21/12 4:37p btosi
24 * SW7425-2424: force the initialization of
25 * ePolarityWhenDeltaStcWasNonZero
26 *
27 * Hydra_Software_Devel/44   2/10/12 11:17a btosi
28 * SW7425-2247: add support for bar data
29 *
30 * Hydra_Software_Devel/43   2/9/12 1:19p btosi
31 * SW7425-2180: added support for the MFD fields ePxlFmt and ulRowStride
32 *
33 * Hydra_Software_Devel/42   2/8/12 2:19p btosi
34 * SW7425-2253: added support for MFD.bChannelChange
35 *
36 * Hydra_Software_Devel/41   2/1/12 1:57p btosi
37 * SW7425-2270: add support for IgnoreNRTUnderflow
38 *
39 * Hydra_Software_Devel/40   1/31/12 12:03p nilesh
40 * SW7425-767: Removed "GAP" case for bIgnorePicture
41 *
42 * Hydra_Software_Devel/39   1/16/12 3:21p nilesh
43 * SW7425-767: Simplificed bStallStc and bIgnorePicture logic
44 *
45 * Hydra_Software_Devel/38   1/12/12 12:57p btosi
46 * SW7425-1001: added support for BAVC_MFD_Picture.bLast
47 *
48 * Hydra_Software_Devel/37   1/11/12 11:03a nilesh
49 * SW7425-767: STC "underflow" stall now has higher precedence than STC
50 * "FIC" stall.
51 *
52 * Hydra_Software_Devel/36   1/10/12 4:37p nilesh
53 * SW7425-767: Merge to mainline
54 *
55 * Hydra_Software_Devel/SW7425-767/1   1/4/12 10:43a nilesh
56 * SW7425-767: Prevent field inversion when STC is stalled in NRT mode
57 *
58 * Hydra_Software_Devel/35   1/5/12 10:48a btosi
59 * SW7405-5549: re-apply the CDT when the monitor refesh rate changes
60 * while the system is paused
61 *
62 * Hydra_Software_Devel/34   11/28/11 3:45p btosi
63 * SW7425-1781: copy the picture's serial number into uiDecoderPictureId
64 *
65 * Hydra_Software_Devel/33   10/3/11 2:19p btosi
66 * SW7425-1264:  support for a SW STC internal to XDM
67 *
68 * Hydra_Software_Devel/32   8/18/11 3:19p btosi
69 * SW7425-966: added support for eLeftRightEnhancedResolution
70 *
71 * Hydra_Software_Devel/31   6/30/11 12:44p nilesh
72 * SW7425-766: bIgnorePicture=true if the STC stalls before the first
73 * picture passes TSM.
74 *
75 * Hydra_Software_Devel/30   6/24/11 4:05p btosi
76 * SW7425-764: added support for eInterruptRefreshRate in the MFD
77 * structure
78 *
79 * Hydra_Software_Devel/29   6/21/11 9:45a btosi
80 * SW7425-104: merged bRepeatField changes to mainline
81 *
82 * Hydra_Software_Devel/SW7425-104/1   6/20/11 1:38p btosi
83 * SW7425-104: added support for the MFD bRepeatField flag
84 *
85 * Hydra_Software_Devel/28   6/9/11 2:41p nilesh
86 * SW7425-44: Set bIgnorePicture and bStallStc to TRUE (Decoder Underflow)
87 * by default if a picture is not selected.  Set the flags to FALSE if in
88 * playback mode and the STC has been validated
89 *
90 * Hydra_Software_Devel/27   6/7/11 4:59p nilesh
91 * SW7425-44: Add support for BAVC_MFD_Picture.bStallStc
92 *
93 * Hydra_Software_Devel/26   5/25/11 4:04p nilesh
94 * SW7425-44: Add support for BAVC_MFD_Picture.bIgnorePicture
95 *
96 * Hydra_Software_Devel/25   5/3/11 10:50a btosi
97 * SW7405-4736: fixed compile warning in non-debug build
98 *
99 * Hydra_Software_Devel/24   5/2/11 9:36a btosi
100 * SW7405-4736: added warnings for unsupported 3D types
101 *
102 * Hydra_Software_Devel/23   4/12/11 2:19p btosi
103 * SW7405-4736: added support for MFD debug messages
104 *
105 * Hydra_Software_Devel/22   3/8/11 2:52p btosi
106 * SW7425-138: fixed warning introduce with previous change
107 *
108 * Hydra_Software_Devel/21   3/8/11 11:56a btosi
109 * SW7425-138: added a check for a divisor of zero
110 *
111 * Hydra_Software_Devel/20   12/16/10 9:12a btosi
112 * SW7422-72: fixed warnings
113 *
114 * Hydra_Software_Devel/19   11/30/10 4:01p delkert
115 * SW7425-44: Fill in MFD pic struct entries ulOrigPTS and ePictureType to
116 * support transcode
117 *
118 * Hydra_Software_Devel/18   11/24/10 1:22p btosi
119 * SW7422-72: added bSetNextPointer for MVC on older DVD chips
120 *
121 * Hydra_Software_Devel/17   11/23/10 10:00a btosi
122 * SW7422-72: added logic to set pNext for MVC on older DVD chips
123 *
124 * Hydra_Software_Devel/16   11/22/10 3:12p btosi
125 * SW7422-72: renamed flag in BXDM_PictureProvider_3DSettings
126 *
127 * Hydra_Software_Devel/15   11/17/10 9:37a btosi
128 * SW7422-72: added new BXVD and XDM 3D API's
129 *
130 * Hydra_Software_Devel/14   11/8/10 2:38p btosi
131 * SW7405-4976: modified overscan calculation
132 *
133 * Hydra_Software_Devel/13   11/4/10 4:08p btosi
134 * SW7405-4974: moved where pNext is initialized
135 *
136 * Hydra_Software_Devel/12   10/29/10 11:18a btosi
137 * SW7422-27: merging 3D changes to mainline
138 *
139 * Hydra_Software_Devel/SW7422-72/2   10/29/10 10:39a btosi
140 * SW7422-72: added uiFrameNum to BXDM_Picture_3D
141 *
142 * Hydra_Software_Devel/SW7422-72/1   10/19/10 9:08a btosi
143 * SW7422-72: expanded support for 3D
144 *
145 * Hydra_Software_Devel/10   9/23/10 3:09p btosi
146 * SW7405-4736: add support for a XDM instance ID to help debug multi-
147 * channel issues
148 *
149 * Hydra_Software_Devel/9   8/10/10 4:16p btosi
150 * SW7405-4736: added PPB index to debug messages
151 *
152 * Hydra_Software_Devel/8   8/10/10 2:39p btosi
153 * SW7405-4736: added PPB index to debug messages
154 *
155 * Hydra_Software_Devel/7   8/10/10 2:32p btosi
156 * SW7405-4736: added PPB index to debug messages
157 *
158 * Hydra_Software_Devel/6   8/5/10 8:29a delkert
159 * SW7405-4703: Add HorizontalOverscanMode to allow bypass of Overscan
160 * calculation.  Added appropriate Get/Set APIs
161 *
162 * Hydra_Software_Devel/5   7/8/10 11:48a btosi
163 * SWBLURAY-21461: fixed coverity issue
164 *
165 * Hydra_Software_Devel/4   7/7/10 2:40p btosi
166 * SWBLURAY-21461: for MPEG and VC1, use the display width/height provided
167 * in the PPB
168 *
169 * Hydra_Software_Devel/3   6/18/10 4:24p delkert
170 * SW7405-3586: Fix uiDisplayedParityFailureCount for interlaced content
171 * on progressive display
172 *
173 * Hydra_Software_Devel/2   6/8/10 3:14p btosi
174 * SW7405-4378: fixed reporting of source size by the PictureParameter
175 * callback when the first picture(s) is dropped
176 *
177 * Hydra_Software_Devel/1   2/16/10 10:51a nilesh
178 * SW7405-2993: Initial XDM version
179 *
180 ***************************************************************************/
181
182#include "bstd.h"                /* standard types */
183#include "bkni.h"
184#include "bdbg.h"                /* Dbglib */
185#include "bfmt.h"
186
187#include "bxdm_pp.h"
188#include "bxdm_pp_priv.h"
189#include "bxdm_pp_output.h"
190#include "bxdm_pp_fic.h"
191#include "bxdm_pp_dbg.h"
192#include "bxdm_pp_callback_priv.h"
193#include "bxdm_pp_qm.h"
194
195BDBG_MODULE(BXDM_PPOUT);
196
197const char BXDM_PictureProvider_P_DISPMGR_OUTPUT_NODE[]="DMOUT:\t""$brcm_Revision: Hydra_Software_Devel/46 $";
198
199/* Console Output:
200   T - Top Field Interrupt
201   B - Bot Field Interrupt
202   F - Frame Interrupt
203   c - clipping occurred
204   p[x][y] - pan-scan occurred for protocol x on field y
205   M - muted
206*/
207
208/*******************************************************************************
209**
210**  Local functions.
211**
212*******************************************************************************/
213
214static void BXDM_PPOUT_S_UpdatePictureParameters(
215   BXDM_PictureProvider_Handle hXdmPP,
216   BAVC_MFD_Picture* pMFDPicture,
217   BXDM_PictureProvider_P_Picture_Context * pPictureContext,
218   bool bCachePictureParameters
219   )
220{
221   /* SW7405-4378: The issue was that the coded size/width and source size/width reported
222    * by the PictureParameter callback did not match at startup.   This only happened
223    * occasionally when playing a live stream.
224    *
225    * Turned out that the first picture was being dropped since the PCR offset was not valid.
226    * As a result the stMFDPicture was being reset to '0' by the call to
227    * BXDM_PPQM_P_InvalidatePictureContext.  However stUnifiedPicture was not being reset.
228    * The application would see the correct coded size for the stream but 0's for the source size.
229    *
230    * The fix is to cache the picture parameters in "stCachedPictureParameters" prior to a picture
231    * passing the TSM test.  The PictureParameter callback will report these value.  Once a picture
232    * is prompted for display, the PictureParameter callback will report the values from the
233    * selected picture.
234    */
235   if ( true == bCachePictureParameters )
236   {
237      BXDM_PictureProvider_P_PictureParameterInfo * pCachedParams = &(hXdmPP->stDMStatus.stCachedPictureParameters);
238
239      /* Just for debug. */
240      pCachedParams->bUseCachedPictureParameters = true;
241
242      pCachedParams->stUnifiedPicture  = *(pPictureContext->pstUnifiedPicture);
243      pCachedParams->stMFDPicture      = *pMFDPicture;
244
245      hXdmPP->stDMStatus.stPictureParameterInfo.pstUnifiedPicture = &(pCachedParams->stUnifiedPicture);
246      hXdmPP->stDMStatus.stPictureParameterInfo.pstMFDPicture = &(pCachedParams->stMFDPicture);
247   }
248   else
249   {
250      /* Just for debug. */
251      hXdmPP->stDMStatus.stCachedPictureParameters.bUseCachedPictureParameters = false;
252
253      hXdmPP->stDMStatus.stPictureParameterInfo.pstUnifiedPicture = pPictureContext->pstUnifiedPicture;
254      hXdmPP->stDMStatus.stPictureParameterInfo.pstMFDPicture = pMFDPicture;
255   }
256
257   BDBG_LEAVE(BXDM_PPOUT_S_UpdatePictureParameters);
258   return;
259} /* end of BXDM_PPOUT_S_UpdatePictureParameters() */
260
261static void BXDM_PPOUT_S_ConvertSourcePolarityToInterlaced(
262   const BXDM_PictureProvider_Handle hXdmPP,
263   const BXDM_PictureProvider_P_LocalState* pLocalState,
264   BAVC_Polarity * pPolarity
265   )
266{
267   BDBG_ENTER(BXDM_PPOUT_S_ConvertSourcePolarityToInterlaced);
268
269   if (BAVC_Polarity_eFrame == pLocalState->eVsyncPolarity)
270   {
271      /* If we're on a progressive display, we need to
272       * manually alternate between delivering Top or Bottom
273       * fields to the display */
274      switch ( hXdmPP->stDMState.stChannel.ePrevSourcePolarity )
275      {
276         case BAVC_Polarity_eTopField:
277            *pPolarity = BAVC_Polarity_eBotField;
278            break;
279
280         case BAVC_Polarity_eBotField:
281         case BAVC_Polarity_eFrame:
282         default:
283            *pPolarity = BAVC_Polarity_eTopField;
284            break;
285      }
286   }
287   else
288   {
289      /* If we're on an interlaced display, we just need to
290       * set the source polarity to equal the interrupt
291       * polarity */
292      *pPolarity = pLocalState->eVsyncPolarity;
293   }
294
295   BDBG_LEAVE(BXDM_PPOUT_S_ConvertSourcePolarityToInterlaced);
296   return;
297} /* end of BXDM_PPOUT_S_ConvertSourcePolarityToInterlaced() */
298
299static void BXDM_PPOUT_S_ApplySPOScanMode(
300   const BXDM_PictureProvider_Handle hXdmPP,
301   const BXDM_PictureProvider_P_LocalState* pLocalState,
302   const BXDM_PictureProvider_P_Picture_Context *pPictureContext,
303   BAVC_MFD_Picture* pMFDPicture,
304   uint32_t *puiOverrideBits
305   )
306{
307   const BXDM_PictureProvider_P_Picture_Params * pstPicParms= &( pPictureContext->stPicParms );
308
309   BDBG_ENTER(BXDM_PPOUT_S_ApplySPOScanMode);
310
311   switch ( pstPicParms->stDisplay.stStatic.eScanMode )
312   {
313      case BXDM_PictureProvider_P_ScanMode_eInterlaced:
314         /* Handle p->i source override */
315         if ( BAVC_Polarity_eFrame == pMFDPicture->eSourcePolarity )
316         {
317            BXVD_DBG_MSG(hXdmPP, ("%x:[%01x.%03x] Source Polarity Override: p->i",
318                                             hXdmPP->stDMState.stDecode.stDebug.uiVsyncCount,
319                                             hXdmPP->stDMConfig.uiInstanceID & 0xF,
320                                             pstPicParms->uiPPBIndex & 0xFFF
321                                             ));
322            *puiOverrideBits |= BXDM_PPDBG_Output_SPO_pToi;
323
324            BXDM_PPOUT_S_ConvertSourcePolarityToInterlaced(
325               hXdmPP,
326               pLocalState,
327               &(pMFDPicture->eSourcePolarity)
328               );
329         }
330         break;
331
332      case BXDM_PictureProvider_P_ScanMode_eProgressive:
333         /* Handle i->p source override */
334         if ( BAVC_Polarity_eFrame != pMFDPicture->eSourcePolarity )
335         {
336            BXVD_DBG_MSG(hXdmPP, ("%x:[%01x.%03x] Source Polarity Override: i->p",
337                                             hXdmPP->stDMState.stDecode.stDebug.uiVsyncCount,
338                                             hXdmPP->stDMConfig.uiInstanceID & 0xF,
339                                             pstPicParms->uiPPBIndex & 0xFFF
340                                             ));
341            *puiOverrideBits |= BXDM_PPDBG_Output_SPO_iTop;
342
343            pMFDPicture->eSourcePolarity = BAVC_Polarity_eFrame;
344         }
345         break;
346
347      default:
348         break;
349   }
350
351   BDBG_LEAVE(BXDM_PPOUT_S_ApplySPOScanMode);
352}
353
354static void BXDM_PPOUT_S_ApplySPODisplayFieldMode(
355   const BXDM_PictureProvider_Handle hXdmPP,
356   const BXDM_PictureProvider_P_LocalState* pLocalState,
357   const BXDM_PictureProvider_P_Picture_Context *pPictureContext,
358   BAVC_MFD_Picture* pMFDPicture,
359   uint32_t *puiOverrideBits
360   )
361{
362   const BXDM_PictureProvider_P_Picture_Params * pstPicParms= &( pPictureContext->stPicParms );
363
364   BDBG_ENTER(BXDM_PPOUT_S_ApplySPODisplayFieldMode);
365   BSTD_UNUSED(pLocalState);
366
367   /* Override the source polarity based on the eDisplayFieldMode
368    * setting */
369   if (BAVC_Polarity_eFrame != pMFDPicture->eSourcePolarity)
370   {
371      /* We only handle display field mode for interlaced source
372       * content */
373      switch ( pstPicParms->stDisplay.stDynamic.eDisplayFieldMode )
374      {
375         case BXDM_PictureProvider_DisplayFieldMode_eTopFieldOnly:
376            if ( pPictureContext->pstUnifiedPicture->stBufferInfo.ePulldown != BXDM_Picture_PullDown_eBottom )
377            {
378               BXVD_DBG_MSG(hXdmPP, ("%x:[%01x.%03x] Source Polarity Override: eTopFieldOnly",
379                                                hXdmPP->stDMState.stDecode.stDebug.uiVsyncCount,
380                                                hXdmPP->stDMConfig.uiInstanceID & 0xF,
381                                                pstPicParms->uiPPBIndex & 0xFFF
382                                                ));
383               pMFDPicture->eSourcePolarity = BAVC_Polarity_eTopField;
384               *puiOverrideBits |= BXDM_PPDBG_Output_SPO_TopField;
385            }
386            break;
387
388         case BXDM_PictureProvider_DisplayFieldMode_eBottomFieldOnly:
389            if ( pPictureContext->pstUnifiedPicture->stBufferInfo.ePulldown != BXDM_Picture_PullDown_eTop )
390            {
391               BXVD_DBG_MSG(hXdmPP, ("%x:[%01x.%03x] Source Polarity Override: eBotFieldOnly",
392                                                hXdmPP->stDMState.stDecode.stDebug.uiVsyncCount,
393                                                hXdmPP->stDMConfig.uiInstanceID & 0xF,
394                                                pstPicParms->uiPPBIndex & 0xFFF
395                                                ));
396               pMFDPicture->eSourcePolarity = BAVC_Polarity_eBotField;
397               *puiOverrideBits |= BXDM_PPDBG_Output_SPO_BottomField;
398            }
399            break;
400
401         case BXDM_PictureProvider_DisplayFieldMode_eSingleField:
402            /* We use the previous source polarity */
403            if ( ( pPictureContext->pstUnifiedPicture->stBufferInfo.ePulldown != BXDM_Picture_PullDown_eBottom ) /* PR50158: Not a dangling field */
404                 && ( pPictureContext->pstUnifiedPicture->stBufferInfo.ePulldown != BXDM_Picture_PullDown_eTop )
405                 && ( pstPicParms->stDisplay.stDynamic.eTrickPlayRepeatMode == BXDM_PictureProvider_P_RepeatMode_eField ) /* PR50157: Not a progressive-in-nature picture */
406                 && ( BAVC_Polarity_eFrame != hXdmPP->stDMState.stChannel.ePrevSourcePolarity ) /* PR56063: Handle switching from frame to field content */
407               )
408            {
409               BXVD_DBG_MSG(hXdmPP, ("%x:[%01x.%03x] Source Polarity Override: eSingleField",
410                                                   hXdmPP->stDMState.stDecode.stDebug.uiVsyncCount,
411                                                   hXdmPP->stDMConfig.uiInstanceID & 0xF,
412                                                   pstPicParms->uiPPBIndex & 0xFFF
413                                                   ));
414               pMFDPicture->eSourcePolarity = hXdmPP->stDMState.stChannel.ePrevSourcePolarity;
415               *puiOverrideBits |= BXDM_PPDBG_Output_SPO_SingleField;
416            }
417            break;
418
419         case BXDM_PictureProvider_DisplayFieldMode_eBothField:
420         default:
421            /* Keep track of display polarity failures for reporting via GetChannelStatus */
422            if (BAVC_Polarity_eFrame != pMFDPicture->eSourcePolarity)
423            {
424               /* SW7405-3586: If source interlaced, and display is progressive, only increment parity
425                  failure count if two fields in a row (or more) are the same polarity.
426                  So, T0 T0r B0 and T0 T1 B1 should each increment the value by 1, but T0 B0 T1 should not. */
427               if (BAVC_Polarity_eFrame == pMFDPicture->eInterruptPolarity)
428               {
429                  /* interlaced content on progressive display ... */
430                  if (pMFDPicture->eSourcePolarity == hXdmPP->stDMState.stChannel.ePrevSourcePolarity)
431                  {
432                     hXdmPP->stDMStatus.stCounters.uiDisplayedParityFailureCount++;
433                  }
434               }
435               else
436               {
437                  /* if interlaced content on interlaced display, verify interrupt polarity matches source polarity */
438                  if (pMFDPicture->eSourcePolarity != pMFDPicture->eInterruptPolarity)
439                  {
440                     hXdmPP->stDMStatus.stCounters.uiDisplayedParityFailureCount++;
441                  }
442               }
443            }
444            break;
445      }
446   }
447
448   BDBG_LEAVE(BXDM_PPOUT_S_ApplySPODisplayFieldMode);
449}
450static void BXDM_PPOUT_S_ApplySPOMPIM(
451   const BXDM_PictureProvider_Handle hXdmPP,
452   const BXDM_PictureProvider_P_LocalState* pLocalState,
453   const BXDM_PictureProvider_P_Picture_Context *pPictureContext,
454   BAVC_MFD_Picture* pMFDPicture,
455   uint32_t *puiOverrideBits
456   )
457{
458   BDBG_ENTER(BXDM_PPOUT_S_ApplySPOMPIM);
459
460   BSTD_UNUSED(pPictureContext);
461
462   /* Override the source polarity based on the
463    * eMovingContentInterpolationMode setting */
464   switch ( hXdmPP->stDMConfig.eScanModeOverride )
465   {
466      case BXDM_PictureProvider_ScanModeOverride_eInterlaced:
467         /* We need to force interlaced scanout */
468         if (pMFDPicture->eSourcePolarity == BAVC_Polarity_eFrame)
469         {
470            /*  We only need to worry about changing the source
471             *  polarity for content that is progressive */
472            BXVD_DBG_MSG(hXdmPP, ("%x:[%01x.%03x] Source Polarity Override: eInterlacedScanout",
473                                                   hXdmPP->stDMState.stDecode.stDebug.uiVsyncCount,
474                                                   hXdmPP->stDMConfig.uiInstanceID & 0xF,
475                                                   pPictureContext->stPicParms.uiPPBIndex & 0xFFF
476                                                   ));
477            *puiOverrideBits |= BXDM_PPDBG_Output_SPO_Interlaced;
478
479            BXDM_PPOUT_S_ConvertSourcePolarityToInterlaced(
480               hXdmPP,
481               pLocalState,
482               &(pMFDPicture->eSourcePolarity)
483               );
484         }
485         break;
486
487      case BXDM_PictureProvider_ScanModeOverride_eProgressive:
488         /* We're forcing progressive scanout, so just set source
489          * polarity to eFrame */
490         BXVD_DBG_MSG(hXdmPP, ("%x:[%01x.%03x] Source Polarity Override: eProgressiveScanout",
491                                                   hXdmPP->stDMState.stDecode.stDebug.uiVsyncCount,
492                                                   hXdmPP->stDMConfig.uiInstanceID & 0xF,
493                                                   pPictureContext->stPicParms.uiPPBIndex & 0xFFF
494                                                   ));
495         *puiOverrideBits |= BXDM_PPDBG_Output_SPO_Progressive;
496
497         pMFDPicture->eSourcePolarity = BAVC_Polarity_eFrame;
498         break;
499
500      default:
501      case BXDM_PictureProvider_ScanModeOverride_eDefault:
502         /* Do nothing */
503         break;
504   }
505
506   BDBG_LEAVE(BXDM_PPOUT_S_ApplySPOMPIM);
507   return;
508} /* end of BXDM_PPOUT_S_ApplyMPIMOverride() */
509
510BERR_Code BXDM_PPOUT_S_ApplySPOProgressive(
511   const BXDM_PictureProvider_Handle hXdmPP,
512   const BXDM_PictureProvider_P_LocalState* pLocalState,
513   BXDM_PictureProvider_P_Picture_Context* pstPicture,
514   BAVC_MFD_Picture* pMFDPicture,
515   uint32_t *puiOverrideBits
516   )
517{
518   /* Override picture's repeat mode based on SPIM setting */
519   switch ( pstPicture->stPicParms.stDisplay.stDynamic.eSourceFormatOverride )
520   {
521      case BXDM_PictureProvider_SourceFormatOverride_eProgressive:
522         if ( pstPicture->stPicParms.stTSM.stStatic.uiNumElements > 1 )
523         {
524            pstPicture->stPicParms.stDisplay.stDynamic.eRateConversionRepeatMode = BXDM_PictureProvider_P_RepeatMode_eFrame;
525            pstPicture->stPicParms.stDisplay.stDynamic.eTrickPlayRepeatMode = BXDM_PictureProvider_P_RepeatMode_eFrame;
526         }
527         break;
528
529      case BXDM_PictureProvider_SourceFormatOverride_eInterlaced:
530         pstPicture->stPicParms.stDisplay.stDynamic.eRateConversionRepeatMode = BXDM_PictureProvider_P_RepeatMode_eField;
531         pstPicture->stPicParms.stDisplay.stDynamic.eTrickPlayRepeatMode = BXDM_PictureProvider_P_RepeatMode_eField;
532         break;
533
534      default:
535         break;
536   }
537
538   /* Apply progressive override */
539   if ( ( pMFDPicture->eSourcePolarity != BAVC_Polarity_eFrame )
540        && ( pMFDPicture->eSourcePolarity != pLocalState->eVsyncPolarity )
541        && ( false == hXdmPP->stDMConfig.bCRCMode ) )
542   {
543      if ( BXDM_PictureProvider_P_RepeatMode_eFrame == pstPicture->stPicParms.stDisplay.stDynamic.eRateConversionRepeatMode )
544      {
545         /* We have inversion but the content can be treated as progressive at all times,
546          * so we toggle the source polarity accordingly
547          *
548          * Some cases where we want this to happen:
549          *  - 24i to 60Hz display
550          *  - 3:2 to 50Hz display
551          */
552         BXVD_DBG_MSG(hXdmPP,("%x:[%01x.%03x] Polarity Override: progressive both field",
553                                             hXdmPP->stDMState.stDecode.stDebug.uiVsyncCount,
554                                             hXdmPP->stDMConfig.uiInstanceID & 0xF,
555                                             pstPicture->stPicParms.uiPPBIndex & 0xFFF
556                                             ));
557         *puiOverrideBits |= BXDM_PPDBG_Output_SPO_ProgBothField;
558
559         BXDM_PPOUT_S_ConvertSourcePolarityToInterlaced(
560            hXdmPP,
561            pLocalState,
562            &(pMFDPicture->eSourcePolarity)
563            );
564      }
565      else if ( ( ( BXDM_PictureProvider_P_RepeatMode_eFrame == pstPicture->stPicParms.stDisplay.stDynamic.eTrickPlayRepeatMode )
566                  && ( ( BXDM_PICTUREPROVIDER_NORMAL_PLAYBACK_RATE != pLocalState->uiSlowMotionRate ) /* We're in a decoder (pause/play) trick mode, NOTE: this could be FF  */
567                       || ( BXDM_PictureProvider_P_STCTrickMode_eSlowMotion == pLocalState->eSTCTrickMode ) /* We're in an STC slow trick mode */
568                       || ( BXDM_PictureProvider_P_STCTrickMode_eSlowRewind == pLocalState->eSTCTrickMode ) /* SW7425-1264: using SW STC for slow rewind trick */
569                       || ( BXDM_PictureProvider_P_STCTrickMode_ePause == pLocalState->eSTCTrickMode ) /* We're in an STC pause trick mode */
570                       || ( ( true == pstPicture->stPicParms.stDisplay.stDynamic.bPPBRepeated ) /* non-rate conversion repeat */
571                            && ( pstPicture->stPicParms.stTSM.stDynamic.iStcPtsDifferenceEvaluated > (int32_t) pstPicture->stPicParms.stTSM.stStatic.stPTSDelta.uiWhole ) )
572                     )
573                 )
574              )
575      {
576         /* We have inversion but the content can be treated as progressive during non-rate conversion repeats,
577          * so we toggle the source polarity accordingly
578          *
579          * Some cases where we want this to happen:
580          *  - Pause/Slow motion for content that is progressive-in-nature
581          *  - unexpected repeats (errors, missing pictures, hold last picture, etc.)
582          *  */
583
584         BXVD_DBG_MSG(hXdmPP,("%x:[%01x.%03x] Polarity Override: progressive repeat",
585                                             hXdmPP->stDMState.stDecode.stDebug.uiVsyncCount,
586                                             hXdmPP->stDMConfig.uiInstanceID & 0xF,
587                                             pstPicture->stPicParms.uiPPBIndex & 0xFFF
588                                             ));
589         *puiOverrideBits |= BXDM_PPDBG_Output_SPO_ProgRepeat;
590
591         BXDM_PPOUT_S_ConvertSourcePolarityToInterlaced(
592            hXdmPP,
593            pLocalState,
594            &(pMFDPicture->eSourcePolarity)
595            );
596      }
597   }
598
599   return BERR_SUCCESS;
600
601}  /* end of BXDM_PPOUT_S_PerformProgressiveOverride() */
602
603static void BXDM_PPOUT_S_SetSourcePolarity(
604   const BXDM_PictureProvider_Handle hXdmPP,
605   BXDM_PictureProvider_P_Picture_Context *pPictureContext,
606   BXDM_PictureProvider_P_LocalState* pLocalState,
607   BAVC_MFD_Picture* pMFDPicture
608   )
609{
610   uint32_t uiOverrideBits = 0;
611
612   BDBG_ENTER(BXDM_PPOUT_S_SetSourcePolarity);
613
614   /* Set the source polarity to what DM specifies */
615   pMFDPicture->eSourcePolarity = pPictureContext->stPicParms.stDisplay.stDynamic.eSourcePolarity;
616
617   /* Override the source polarity based on the special cases as
618    * described in rate conversion table */
619   if ( false == hXdmPP->stDMConfig.bCRCMode )
620   {
621      /* The polarity may need be to overridden if the pulldown is interlaced
622       * and the source polarity doesn't match the interrupt polarity.
623       */
624      BXDM_PPOUT_S_ApplySPOProgressive(
625               hXdmPP,
626               pLocalState,
627               pPictureContext,
628               pMFDPicture,
629               &uiOverrideBits
630               );
631
632      BXDM_PPOUT_S_ApplySPOScanMode(
633               hXdmPP,
634               pLocalState,
635               pPictureContext,
636               pMFDPicture,
637               &uiOverrideBits
638               );
639
640      BXDM_PPOUT_S_ApplySPODisplayFieldMode(
641               hXdmPP,
642               pLocalState,
643               pPictureContext,
644               pMFDPicture,
645               &uiOverrideBits
646               );
647
648      BXDM_PPOUT_S_ApplySPOMPIM(
649               hXdmPP,
650               pLocalState,
651               pPictureContext,
652               pMFDPicture,
653               &uiOverrideBits
654               );
655   }
656
657   BXDM_PPDBG_P_OutputSPOLog(
658      hXdmPP,
659      uiOverrideBits
660      );
661
662   BDBG_LEAVE(BXDM_PPOUT_S_SetSourcePolarity);
663   return;
664} /* end of BXDM_PPOUT_S_SetSourcePolarity() */
665
666static void BXDM_PPOUT_S_SetMpegType(
667         const BXDM_PictureProvider_Handle hXdmPP,
668         BXDM_PictureProvider_P_Picture_Context *pPictureContext,
669         BAVC_MFD_Picture* pPicture
670         )
671{
672   const BXDM_Picture* pUnifiedPicture = pPictureContext->pstUnifiedPicture;
673   BAVC_MFD_Picture * pDefaultParams = &( hXdmPP->stDMState.stChannel.stDefaultPicParams );
674
675   if ( true == pUnifiedPicture->stBufferInfo.stChromaLocation[pPicture->eSourcePolarity].bValid )
676   {
677      pPicture->eMpegType = pUnifiedPicture->stBufferInfo.stChromaLocation[pPicture->eSourcePolarity].eMpegType;
678   }
679   else if ( true == pUnifiedPicture->stBufferInfo.stChromaLocation[BAVC_Polarity_eFrame].bValid )
680   {
681      pPicture->eMpegType = pUnifiedPicture->stBufferInfo.stChromaLocation[BAVC_Polarity_eFrame].eMpegType;
682   }
683   else if ( true == pUnifiedPicture->stBufferInfo.stChromaLocation[BAVC_Polarity_eTopField].bValid )
684   {
685      pPicture->eMpegType = pUnifiedPicture->stBufferInfo.stChromaLocation[BAVC_Polarity_eTopField].eMpegType;
686   }
687   else if ( true == pUnifiedPicture->stBufferInfo.stChromaLocation[BAVC_Polarity_eBotField].bValid )
688   {
689      pPicture->eMpegType = pUnifiedPicture->stBufferInfo.stChromaLocation[BAVC_Polarity_eBotField].eMpegType;
690   }
691   else
692   {
693      pPicture->eMpegType = pDefaultParams->eMpegType;
694   }
695}
696
697static void BXDM_PPOUT_S_SetPictureOrderCount(
698         const BXDM_PictureProvider_Handle hXdmPP,
699         BXDM_PictureProvider_P_Picture_Context *pPictureContext,
700         BAVC_MFD_Picture* pPicture
701         )
702{
703   const BXDM_Picture* pUnifiedPicture = pPictureContext->pstUnifiedPicture;
704   BAVC_MFD_Picture * pDefaultParams = &( hXdmPP->stDMState.stChannel.stDefaultPicParams );
705
706   /* Set defaults */
707   pPicture->ulIdrPicID = pDefaultParams->ulIdrPicID;
708   pPicture->int32_PicOrderCnt = pDefaultParams->int32_PicOrderCnt;
709   pPicture->hFgtHeap = pDefaultParams->hFgtHeap;
710   pPicture->pFgtSeiBufferAddress = pDefaultParams->pFgtSeiBufferAddress;
711
712   if ( ( NULL != pUnifiedPicture )
713        && ( true == pUnifiedPicture->stPOC.bValid ) )
714   {
715      pPicture->ulIdrPicID = pUnifiedPicture->stPOC.uiPictureId;
716
717      if ( true == pUnifiedPicture->stPOC.stPictureOrderCount[pPicture->eSourcePolarity].bValid )
718      {
719         pPicture->int32_PicOrderCnt = pUnifiedPicture->stPOC.stPictureOrderCount[pPicture->eSourcePolarity].iValue;
720      }
721      else if ( true == pUnifiedPicture->stPOC.stPictureOrderCount[BAVC_Polarity_eFrame].bValid )
722      {
723         pPicture->int32_PicOrderCnt = pUnifiedPicture->stPOC.stPictureOrderCount[BAVC_Polarity_eFrame].iValue;
724      }
725      else if ( true == pUnifiedPicture->stPOC.stPictureOrderCount[BAVC_Polarity_eTopField].bValid )
726      {
727         pPicture->int32_PicOrderCnt = pUnifiedPicture->stPOC.stPictureOrderCount[BAVC_Polarity_eTopField].iValue;
728      }
729      else if ( true == pUnifiedPicture->stPOC.stPictureOrderCount[BAVC_Polarity_eBotField].bValid )
730      {
731         pPicture->int32_PicOrderCnt = pUnifiedPicture->stPOC.stPictureOrderCount[BAVC_Polarity_eBotField].iValue;
732      }
733   }
734}
735
736static void BXDM_PPOUT_S_SetSourceBufferInformation(
737   const BXDM_PictureProvider_Handle hXdmPP,
738   BXDM_PictureProvider_P_Picture_Context *pPictureContext,
739   BAVC_MFD_Picture* pPicture
740   )
741{
742   const BXDM_Picture* pUnifiedPicture = pPictureContext->pstUnifiedPicture;
743   BXDM_PictureProvider_P_Picture_Params* pstPicParms= &( pPictureContext->stPicParms );
744   BMEM_Handle hPictureHeap = pPictureContext->pstUnifiedPicture->stBufferInfo.hHeap;
745   BAVC_MFD_Picture * pDefaultParams = &( hXdmPP->stDMState.stChannel.stDefaultPicParams );
746
747   BDBG_ENTER(BXDM_PPOUT_S_SetSourceBufferInformation);
748
749   BDBG_ASSERT(pPicture);
750   BDBG_ASSERT(hPictureHeap);
751
752   /* hHeap is always set to the AVD/XVD picture heap */
753   pPicture->hHeap = hPictureHeap;
754
755   if ( pUnifiedPicture )
756   {
757      /* bMute */
758      pPicture->bMute = false;
759
760      /* pLuminanceFrameBufferAddress */
761      pPicture->pLuminanceFrameBufferAddress = pUnifiedPicture->stBufferInfo.pLumaBufferVirtualAddress;
762      pPicture->pChrominanceFrameBufferAddress = pUnifiedPicture->stBufferInfo.pChromaBufferVirtualAddress;
763
764      /* ulLuminanceNMBY */
765      /* ulChrominanceNMBY */
766      pPicture->ulLuminanceNMBY = pUnifiedPicture->stBufferInfo.uiLumaStripeHeight >> 4;
767      pPicture->ulChrominanceNMBY = pUnifiedPicture->stBufferInfo.uiChromaStripeHeight >> 4;
768
769      /* ulSourceHorizontalSize (default) */
770      /* ulSourceVerticalSize (default) */
771      pPicture->ulSourceHorizontalSize = pUnifiedPicture->stBufferInfo.stSource.uiWidth;
772      pPicture->ulSourceVerticalSize = pUnifiedPicture->stBufferInfo.stSource.uiHeight;
773
774      /* eFrameRateCode, we want to send the application set default
775       * frame rate if the coded frame rate is unknown, so we use the
776       * frame rate value from the picture context parameters instead
777       * of the PPB directly */
778      pPicture->eFrameRateCode = pstPicParms->stTSM.stStatic.eFrameRate;
779
780      BXDM_PPOUT_S_SetMpegType(
781               hXdmPP,
782               pPictureContext,
783               pPicture);
784
785      /* eStripeWidth */
786      pPicture->eStripeWidth = pPictureContext->pstUnifiedPicture->stBufferInfo.eStripeWidth;
787
788      /* YCbCrType */
789      pPicture->eYCbCrType = pPictureContext->pstUnifiedPicture->stBufferInfo.eYCbCrType;
790
791      BXDM_PPOUT_S_SetPictureOrderCount(
792               hXdmPP,
793               pPictureContext,
794               pPicture);
795
796      /* SW7425-2181: if specified, set the pixel format. */
797      if ( true == pPictureContext->pstUnifiedPicture->stBufferInfo.stPixelFormat.bValid )
798      {
799         pPicture->ePxlFmt = pPictureContext->pstUnifiedPicture->stBufferInfo.stPixelFormat.ePixelFormat;
800      }
801
802      /* SW7425-2181: copy the stride from the unified picture. */
803      pPicture->ulRowStride = pPictureContext->pstUnifiedPicture->stBufferInfo.uiRowStride;
804
805   }
806   else
807   {
808      pPicture->bMute = pDefaultParams->bMute;
809      pPicture->pLuminanceFrameBufferAddress = pDefaultParams->pLuminanceFrameBufferAddress;
810      pPicture->pChrominanceFrameBufferAddress = pDefaultParams->pChrominanceFrameBufferAddress;
811      pPicture->ulLuminanceNMBY = pDefaultParams->ulLuminanceNMBY;
812      pPicture->ulChrominanceNMBY = pDefaultParams->ulChrominanceNMBY;
813      pPicture->ulSourceHorizontalSize = pDefaultParams->ulSourceHorizontalSize;
814      pPicture->ulSourceVerticalSize = pDefaultParams->ulSourceVerticalSize;
815      pPicture->eFrameRateCode = pDefaultParams->eFrameRateCode;
816      pPicture->eMpegType = pDefaultParams->eMpegType;
817      pPicture->eStripeWidth = pDefaultParams->eStripeWidth;
818      pPicture->eYCbCrType = pDefaultParams->eYCbCrType;
819   }
820
821
822   BDBG_LEAVE(BXDM_PPOUT_S_SetSourceBufferInformation);
823   return;
824} /* BXDM_PPOUT_S_SetSourceBufferInformation() */
825
826static void BXDM_PPOUT_S_SetClipping(
827   const BXDM_PictureProvider_Handle hXdmPP,
828   BXDM_PictureProvider_P_Picture_Context *pPictureContext,
829   BAVC_MFD_Picture* pPicture
830   )
831{
832   const BXDM_Picture* pUnifiedPicture = pPictureContext->pstUnifiedPicture;
833   bool bCrcMode = hXdmPP->stDMConfig.bCRCMode;
834   BAVC_MFD_Picture * pDefaultParams = &( hXdmPP->stDMState.stChannel.stDefaultPicParams );
835
836   BDBG_ENTER(BXDM_PPOUT_S_SetClipping);
837
838   BDBG_ASSERT(pPicture);
839
840   /* ulSourceClipTop */
841   /* ulSourceClipLeft */
842   pPicture->ulSourceClipTop = pDefaultParams->ulSourceClipTop;
843   pPicture->ulSourceClipLeft = pDefaultParams->ulSourceClipLeft;
844
845   if ( pUnifiedPicture )
846   {
847      if ( ( true == pUnifiedPicture->stClipping.bValid )
848           && ( false == bCrcMode ) )
849      {
850         pPicture->ulSourceHorizontalSize -= (pUnifiedPicture->stClipping.uiLeft + pUnifiedPicture->stClipping.uiRight);
851         pPicture->ulSourceVerticalSize -= (pUnifiedPicture->stClipping.uiTop + pUnifiedPicture->stClipping.uiBottom);
852
853         pPicture->ulSourceClipTop = pUnifiedPicture->stClipping.uiTop;
854         pPicture->ulSourceClipLeft = pUnifiedPicture->stClipping.uiLeft;
855      }
856   }
857
858   BDBG_LEAVE(BXDM_PPOUT_S_SetClipping);
859   return;
860} /* end of BXDM_PPOUT_S_SetClipping() */
861
862static void BXDM_PPOUT_S_SetPanScan(
863   const BXDM_PictureProvider_Handle hXdmPP,
864   BXDM_PictureProvider_P_Picture_Context *pPictureContext,
865   bool bCrcMode,
866   BAVC_MFD_Picture* pPicture
867   )
868{
869   const BXDM_Picture* pUnifiedPicture = pPictureContext->pstUnifiedPicture;
870   uint32_t uiSelectedElement;
871
872   BDBG_ENTER(BXDM_PPOUT_S_SetPanScan);
873
874   BDBG_ASSERT(pPicture);
875
876   pPicture->i32_HorizontalPanScan = 0;
877   pPicture->i32_VerticalPanScan = 0;
878
879   pPicture->ulDisplayHorizontalSize = pPicture->ulSourceHorizontalSize; /* needs to be the post cropped value */
880   pPicture->ulDisplayVerticalSize = pPicture->ulSourceVerticalSize; /* needs to be the post cropped value */
881
882   /* Handle Reverse Field Display - The reversal of the source
883    * polarity is handled during the PTS calculation done for each
884    * element (See BXDM_PPTSM_P_PtsCalculateParameters).  However, we
885    * need to reverse the selected element so that the display uses
886    * the proper pan-scan vector, if one exists */
887   if ( hXdmPP->stDMConfig.bReverseFields )
888   {
889      uiSelectedElement = pPictureContext->stPicParms.stTSM.stStatic.uiNumElements - (pPictureContext->stPicParms.stDisplay.stDynamic.uiSelectedElement + 1);
890   }
891   else
892   {
893      uiSelectedElement = pPictureContext->stPicParms.stDisplay.stDynamic.uiSelectedElement;
894   }
895
896   if ( pUnifiedPicture )
897   {
898
899      /* SWBLURAY-21461: for VC1, MPEG and AVS a display width/height may be
900       * included with the picture data.  Use these values if provided.
901       * This check needs to be after the "if (pUnifiedPicture)" to keep coverity happy.
902       */
903      if ( true == pUnifiedPicture->stBufferInfo.stDisplay.bValid )
904      {
905         pPicture->ulDisplayHorizontalSize = pUnifiedPicture->stBufferInfo.stDisplay.uiWidth;
906         pPicture->ulDisplayVerticalSize = pUnifiedPicture->stBufferInfo.stDisplay.uiHeight;
907      }
908
909      if ( ( 0 != pUnifiedPicture->stPanScan.uiCount )
910           && ( false == bCrcMode ) )
911      {
912         uint32_t uiPanScanIndex;
913
914         if ( uiSelectedElement < pUnifiedPicture->stPanScan.uiCount )
915         {
916            uiPanScanIndex = uiSelectedElement;
917         }
918         else
919         {
920            uiPanScanIndex = pUnifiedPicture->stPanScan.uiCount - 1;
921         }
922
923         switch ( pUnifiedPicture->stPanScan.stVector[uiPanScanIndex].eType )
924         {
925            case BXDM_Picture_PanScanVectorType_eSourceWindow:
926               pPicture->ulDisplayHorizontalSize = pUnifiedPicture->stPanScan.stVector[uiPanScanIndex].uiWidth;
927               pPicture->ulDisplayVerticalSize = pUnifiedPicture->stPanScan.stVector[uiPanScanIndex].uiHeight;
928
929               pPicture->i32_HorizontalPanScan = pUnifiedPicture->stPanScan.stVector[uiPanScanIndex].iHorizontal;
930               pPicture->i32_VerticalPanScan = pUnifiedPicture->stPanScan.stVector[uiPanScanIndex].iVertical;
931               break;
932
933            case BXDM_Picture_PanScanVectorType_eSourceCrop:
934               pPicture->ulDisplayHorizontalSize -= pUnifiedPicture->stPanScan.stVector[uiPanScanIndex].uiWidth;
935               pPicture->ulDisplayVerticalSize -= pUnifiedPicture->stPanScan.stVector[uiPanScanIndex].uiHeight;
936
937               pPicture->i32_HorizontalPanScan = pUnifiedPicture->stPanScan.stVector[uiPanScanIndex].iHorizontal;
938               pPicture->i32_VerticalPanScan = pUnifiedPicture->stPanScan.stVector[uiPanScanIndex].iVertical;
939               break;
940
941            case BXDM_Picture_PanScanVectorType_eDisplayWindow:
942               if ( true == pUnifiedPicture->stBufferInfo.stDisplay.bValid )
943               {
944                  pPicture->ulDisplayHorizontalSize = pUnifiedPicture->stPanScan.stVector[uiPanScanIndex].uiWidth * pPicture->ulSourceHorizontalSize / pUnifiedPicture->stBufferInfo.stDisplay.uiWidth;
945                  pPicture->ulDisplayVerticalSize = pUnifiedPicture->stPanScan.stVector[uiPanScanIndex].uiHeight * pPicture->ulSourceVerticalSize / pUnifiedPicture->stBufferInfo.stDisplay.uiHeight;
946
947                  pPicture->i32_HorizontalPanScan = pUnifiedPicture->stPanScan.stVector[uiPanScanIndex].iHorizontal * pPicture->ulSourceHorizontalSize / pUnifiedPicture->stBufferInfo.stDisplay.uiWidth;
948                  pPicture->i32_VerticalPanScan = pUnifiedPicture->stPanScan.stVector[uiPanScanIndex].iVertical * pPicture->ulSourceVerticalSize / pUnifiedPicture->stBufferInfo.stDisplay.uiHeight;
949               }
950               break;
951
952            default:
953               break;
954         }
955      }
956   }
957
958   BDBG_LEAVE(BXDM_PPOUT_S_SetPanScan);
959   return;
960} /* end of BXDM_PPOUT_S_SetPanScan() */
961
962static void BXDM_PPOUT_S_SetDisplayParameters(
963   const BXDM_PictureProvider_Handle hXdmPP,
964   BXDM_PictureProvider_P_Picture_Context *pPictureContext,
965   BAVC_MFD_Picture* pPicture
966   )
967{
968   const BXDM_Picture* pUnifiedPicture = pPictureContext->pstUnifiedPicture;
969   BAVC_MFD_Picture * pDefaultParams = &( hXdmPP->stDMState.stChannel.stDefaultPicParams );
970
971   BDBG_ENTER(BXDM_PPOUT_S_SetDisplayParameters);
972
973   BDBG_ASSERT(pPicture);
974
975   /* Set Defaults */
976   pPicture->eMatrixCoefficients = pDefaultParams->eMatrixCoefficients;
977   pPicture->eColorPrimaries = pDefaultParams->eColorPrimaries;
978   pPicture->eTransferCharacteristics = pDefaultParams->eTransferCharacteristics;
979
980   if ( pUnifiedPicture )
981   {
982      if ( true == pUnifiedPicture->stDisplayInfo.bValid )
983      {
984         /* Extract values from Picture */
985         pPicture->eMatrixCoefficients = pUnifiedPicture->stDisplayInfo.eMatrixCoefficients;
986         pPicture->eColorPrimaries = pUnifiedPicture->stDisplayInfo.eColorPrimaries;
987         pPicture->eTransferCharacteristics = pUnifiedPicture->stDisplayInfo.eTransferCharacteristics;
988      }
989   }
990
991   BDBG_LEAVE(BXDM_PPOUT_S_SetDisplayParameters);
992   return;
993} /* end of BXDM_PPOUT_S_SetDisplayParameters() */
994
995BERR_Code BXDM_PPOUT_P_ComputeSARScaling(
996         uint32_t uiOriginalSourceSizeX,
997         uint32_t uiOriginalSourceSizeY,
998         uint16_t uiOriginalSampleAspectRatioX,
999         uint16_t uiOriginalSampleAspectRatioY,
1000         uint32_t uiEffectiveSourceSizeX,
1001         uint32_t uiEffectiveSourceSizeY,
1002         uint16_t *puiEffectiveSampleAspectRatioX,
1003         uint16_t *puiEffectiveSampleAspectRatioY
1004         )
1005{
1006   BDBG_ASSERT(puiEffectiveSampleAspectRatioX);
1007   BDBG_ASSERT(puiEffectiveSampleAspectRatioY);
1008
1009   if ( 0 != uiEffectiveSourceSizeX )
1010   {
1011      *puiEffectiveSampleAspectRatioX = ( ( ( uiOriginalSampleAspectRatioX * uiOriginalSourceSizeX * 2048 ) + uiEffectiveSourceSizeX/2 ) / uiEffectiveSourceSizeX);
1012   }
1013
1014   if ( 0 != uiEffectiveSourceSizeY )
1015   {
1016      *puiEffectiveSampleAspectRatioY = ( ( ( uiOriginalSampleAspectRatioY * uiOriginalSourceSizeY * 2048 ) + uiEffectiveSourceSizeY/2 ) / uiEffectiveSourceSizeY);
1017   }
1018
1019   return BERR_TRACE(BERR_SUCCESS);
1020} /* end of BXDM_PPOUT_P_ComputeSARScaling() */
1021
1022static void BXDM_PPOUT_S_CalculateHorizontalOverscan(
1023   uint32_t uiSizeX,
1024   uint32_t uiSizeY,
1025   uint32_t uiSampleAspectRatioX,
1026   uint32_t uiSampleAspectRatioY,
1027   uint32_t *puiOverscan
1028   )
1029{
1030   uint32_t uiIdealWidth16x9;
1031   uint32_t uiIdealWidth4x3;
1032   uint32_t uiOverscan16x9;
1033   uint32_t uiOverscan4x3;
1034   uint32_t uiOverscan;
1035
1036   BDBG_ENTER(BXDM_PPOUT_S_CalculateHorizontalOverscan);
1037
1038   BDBG_ASSERT(puiOverscan);
1039
1040   *puiOverscan = 0;
1041
1042   if ( 0 != uiSampleAspectRatioX )
1043   {
1044      /* Determine overscan assuming 16x9 display region*/
1045      uiIdealWidth16x9 = (( uiSizeY * uiSampleAspectRatioY * 16 ) / ( uiSampleAspectRatioX * 9 ));
1046      if ( uiIdealWidth16x9 > uiSizeX )
1047      {
1048         uiOverscan16x9 = uiSizeX;
1049      }
1050      else
1051      {
1052         uiOverscan16x9 = uiSizeX - uiIdealWidth16x9;
1053      }
1054
1055      /* Determine overscan assuming 4x3 display region*/
1056      uiIdealWidth4x3 = (( uiSizeY * uiSampleAspectRatioY * 4 ) / ( uiSampleAspectRatioX * 3 ));
1057      if ( uiIdealWidth4x3 > uiSizeX )
1058      {
1059         uiOverscan4x3 = uiSizeX;
1060      }
1061      else
1062      {
1063         uiOverscan4x3 = uiSizeX - uiIdealWidth4x3;
1064      }
1065
1066      /* Pick the smallest resulting overscan */
1067      if ( uiOverscan4x3 < uiOverscan16x9 )
1068      {
1069         uiOverscan = uiOverscan4x3;
1070      }   
1071      else
1072      {
1073         uiOverscan = uiOverscan16x9;
1074      }
1075
1076      if ( ( uiOverscan > 0 )
1077            && ( uiOverscan <= 16 ) )
1078      {
1079         *puiOverscan = uiOverscan;
1080      }
1081
1082   }     /* end of if( 0 != uiSampleAspectRatioX )*/
1083
1084   BDBG_LEAVE(BXDM_PPOUT_S_CalculateHorizontalOverscan);
1085   return;
1086} /* end of BXDM_PPOUT_S_CalculateHorizontalOverscan() */
1087
1088static void BXDM_PPOUT_S_SetAspectRatio(
1089   const BXDM_PictureProvider_Handle hXdmPP,
1090   BXDM_PictureProvider_P_Picture_Context *pPictureContext,
1091   BAVC_MFD_Picture* pPicture
1092   )
1093{
1094   const BXDM_Picture* pUnifiedPicture = pPictureContext->pstUnifiedPicture;
1095   BAVC_MFD_Picture * pDefaultParams = &( hXdmPP->stDMState.stChannel.stDefaultPicParams );
1096
1097   uint32_t uiEffectiveSourceSizeX;
1098   uint32_t uiEffectiveSourceSizeY;
1099   uint32_t uiOriginalSourceSizeX;
1100   uint32_t uiOriginalSourceSizeY;
1101
1102   bool bResizeRequired = false;
1103
1104   uint32_t uiEffectiveOverscan;
1105   uint16_t uiEffectiveSampleAspectRatioX;
1106   uint16_t uiEffectiveSampleAspectRatioY;
1107
1108   uint32_t uiOriginalOverscan = 0;
1109   uint16_t uiOriginalSampleAspectRatioX=0;
1110   uint16_t uiOriginalSampleAspectRatioY=0;
1111
1112   BDBG_ENTER(BXDM_PPOUT_S_SetAspectRatio);
1113
1114   BDBG_ASSERT(pPicture);
1115
1116   /* EffectiveSourceSize: The dimensions of the actual picture buffer
1117    * EffectiveOverscan: The overscan of the coded source size ( = (OriginalOverscan * CodedSourceSize + DisplaySourceSize/2) / DisplaySourceSize )
1118    * EffectiveSAR: The SAR that includes scaling from EffectiveSourceSize to OriginalSourceSize and the OriginalSAR
1119    *
1120    * OriginalSourceSize: The dimensions of the original picture buffer
1121    *    * VC1: display size from vc1 extension
1122    *    * Others: EffectiveSourceSize
1123    * OriginalOverscan: The overscan of the OriginalSourceSize
1124    * OriginalSAR: The SAR that applies to the original source size
1125    *
1126    * 1) Compute OriginalOverscan
1127    * 2) Compute CodedOverscan
1128    * 3) Apply cropping based on CodedOverscan
1129    * 4) Compute
1130    */
1131
1132   pPicture->eAspectRatio = pDefaultParams->eAspectRatio;
1133   pPicture->uiSampleAspectRatioX = pDefaultParams->uiSampleAspectRatioX;
1134   pPicture->uiSampleAspectRatioY = pDefaultParams->uiSampleAspectRatioY;
1135
1136   if ( ( NULL != pUnifiedPicture )
1137        && ( true == pUnifiedPicture->stAspectRatio.bValid ) )
1138   {
1139      /* Populate Dimensions Parameters */
1140      uiEffectiveSourceSizeX = pPicture->ulSourceHorizontalSize;
1141      uiEffectiveSourceSizeY = pPicture->ulSourceVerticalSize;
1142
1143      uiOriginalSourceSizeX = uiEffectiveSourceSizeX;
1144      uiOriginalSourceSizeY = uiEffectiveSourceSizeY;
1145
1146      if ( true == pUnifiedPicture->stBufferInfo.stDisplay.bValid )
1147      {
1148         uiOriginalSourceSizeX = pUnifiedPicture->stBufferInfo.stDisplay.uiWidth;
1149         uiOriginalSourceSizeY = pUnifiedPicture->stBufferInfo.stDisplay.uiHeight;
1150      }
1151
1152      if ( ( uiEffectiveSourceSizeX != uiOriginalSourceSizeX )
1153           || ( uiEffectiveSourceSizeY != uiOriginalSourceSizeY ) )
1154      {
1155         bResizeRequired = true;
1156
1157         BXVD_DBG_MSG(hXdmPP, ("%x:[%01x.%03x] Source Scaling Required: %4dx%4d --> %4dx%4d",
1158                                          hXdmPP->stDMState.stDecode.stDebug.uiVsyncCount,
1159                                          hXdmPP->stDMConfig.uiInstanceID & 0xF,
1160                                          pPictureContext->stPicParms.uiPPBIndex & 0xFFF,
1161                                          uiEffectiveSourceSizeX,
1162                                          uiEffectiveSourceSizeY,
1163                                          uiOriginalSourceSizeX,
1164                                          uiOriginalSourceSizeY
1165                                          ));
1166      }
1167
1168      pPicture->eAspectRatio = pUnifiedPicture->stAspectRatio.eAspectRatio;
1169      uiOriginalSampleAspectRatioX = pUnifiedPicture->stAspectRatio.uiSampleAspectRatioX;
1170      uiOriginalSampleAspectRatioY = pUnifiedPicture->stAspectRatio.uiSampleAspectRatioY;
1171
1172      /* Handle SAR Overscan and Rescaling */
1173      if ( BFMT_AspectRatio_eSAR == pPicture->eAspectRatio )
1174      {
1175         /* If applicable, Calculate Original Overscan */
1176         if ( ( false == hXdmPP->stDMConfig.bCRCMode )
1177              && ( uiOriginalSampleAspectRatioX != uiOriginalSampleAspectRatioY )  /* Not Square Pixel */
1178              && ( false == ( ( BAVC_VideoCompressionStd_eH264 == pUnifiedPicture->stProtocol.eProtocol ) /* Not AVC protocol with overscan bit indicating no overscan */
1179                              && ( true == ( pUnifiedPicture->stOverscan.bValid ) )
1180                              && ( false == ( pUnifiedPicture->stOverscan.bOverscanAppropriate ) ) ) )
1181              /* SW7405-4703: bypass horizontal overscan calculation if desired */
1182              && (BXDM_PictureProvider_HorizontalOverscanMode_eDisable != hXdmPP->stDMConfig.eHorizontalOverscanMode)
1183            )
1184         {
1185            BXDM_PPOUT_S_CalculateHorizontalOverscan(
1186                     uiOriginalSourceSizeX,
1187                     uiOriginalSourceSizeY,
1188                     uiOriginalSampleAspectRatioX,
1189                     uiOriginalSampleAspectRatioY,
1190                     &uiOriginalOverscan
1191                     );
1192         }
1193
1194         if ( 0 != uiOriginalOverscan )
1195         {
1196            /* If applicable, Calculate Effective Overscan */
1197            if ( false == bResizeRequired )
1198            {
1199               uiEffectiveOverscan = uiOriginalOverscan;
1200            }
1201            else
1202            {
1203               uiEffectiveOverscan = ( ( ( uiOriginalOverscan * uiEffectiveSourceSizeX ) + uiOriginalSourceSizeX/2 ) / uiOriginalSourceSizeX );
1204            }
1205
1206            /* Populate Overscan */
1207            BXVD_DBG_MSG(hXdmPP, ("%x:[%01x.%03x] Applying overscan: %4dx%4d + sar:[%4d:%4d] --> %4dx%4d",
1208                                                   hXdmPP->stDMState.stDecode.stDebug.uiVsyncCount,
1209                                                   hXdmPP->stDMConfig.uiInstanceID & 0xF,
1210                                                   pPictureContext->stPicParms.uiPPBIndex & 0xFFF,
1211                                                   uiOriginalSourceSizeX,
1212                                                   uiOriginalSourceSizeY,
1213                                                   uiOriginalSampleAspectRatioX,
1214                                                   uiOriginalSampleAspectRatioY,
1215                                                   uiOriginalSourceSizeX - uiOriginalOverscan,
1216                                                   uiOriginalSourceSizeY
1217                                                   ));
1218
1219            uiOriginalSourceSizeX -= uiOriginalOverscan;
1220            uiEffectiveSourceSizeX -= uiEffectiveOverscan;
1221
1222            pPicture->ulSourceHorizontalSize -= uiEffectiveOverscan;
1223            pPicture->ulSourceClipLeft += (uiEffectiveOverscan+1)/2;
1224         }
1225
1226         /* Calculate Effective SAR */
1227
1228         uiEffectiveSampleAspectRatioX = uiOriginalSampleAspectRatioX;
1229         uiEffectiveSampleAspectRatioY = uiOriginalSampleAspectRatioY;
1230
1231         if ( true == bResizeRequired )
1232         {
1233            /* SW7405-2991: Handle VC1 source -> display scaling */
1234            BXDM_PPOUT_P_ComputeSARScaling(
1235                     uiOriginalSourceSizeX,
1236                     uiOriginalSourceSizeY,
1237                     uiOriginalSampleAspectRatioX,
1238                     uiOriginalSampleAspectRatioY,
1239                     uiEffectiveSourceSizeX,
1240                     uiEffectiveSourceSizeY,
1241                     &uiEffectiveSampleAspectRatioX,
1242                     &uiEffectiveSampleAspectRatioY
1243                     );
1244
1245            BXVD_DBG_MSG(hXdmPP, ("%x:[%01x.%03x] SAR Based Scaling Conversion: %4dx%4d --> %4dx%4d",
1246                                          hXdmPP->stDMState.stDecode.stDebug.uiVsyncCount,
1247                                          hXdmPP->stDMConfig.uiInstanceID & 0xF,
1248                                          pPictureContext->stPicParms.uiPPBIndex & 0xFFF,
1249                                          uiOriginalSampleAspectRatioX,
1250                                          uiOriginalSampleAspectRatioY,
1251                                          uiEffectiveSampleAspectRatioX,
1252                                          uiEffectiveSampleAspectRatioY
1253                                          ));
1254         }
1255
1256         /* Populate SAR */
1257         pPicture->uiSampleAspectRatioX = uiEffectiveSampleAspectRatioX;
1258         pPicture->uiSampleAspectRatioY = uiEffectiveSampleAspectRatioY;
1259      }
1260   }
1261
1262   BDBG_LEAVE(BXDM_PPOUT_S_SetAspectRatio);
1263   return;
1264} /* end of BXDM_PPOUT_S_SetAspectRatio() */
1265
1266static void BXDM_PPOUT_S_SetDigitalNoiseReduction(
1267   const BXDM_PictureProvider_Handle hXdmPP,
1268   BXDM_PictureProvider_P_Picture_Context *pPictureContext,
1269   BAVC_MFD_Picture* pPicture
1270   )
1271{
1272   const BXDM_Picture* pUnifiedPicture = pPictureContext->pstUnifiedPicture;
1273   BAVC_MFD_Picture * pDefaultParams = &( hXdmPP->stDMState.stChannel.stDefaultPicParams );
1274
1275   BDBG_ENTER(BXDM_PPOUT_S_SetDigitalNoiseReduction);
1276
1277   BDBG_ASSERT(pPicture);
1278
1279   /* Set defaults */
1280   pPicture->ulAdjQp = pDefaultParams->ulAdjQp;
1281
1282   if ( ( NULL != pUnifiedPicture )
1283       && ( pUnifiedPicture->stDigitalNoiseReduction.bValid ) )
1284   {
1285      pPicture->ulAdjQp = pUnifiedPicture->stDigitalNoiseReduction.uiAdjustedQuantizationParameter;
1286   }
1287
1288   BDBG_LEAVE(BXDM_PPOUT_S_SetDigitalNoiseReduction);
1289   return;
1290} /* end of BXDM_PPOUT_S_SetDigitalNoiseReduction() */
1291
1292static void BXDM_PPOUT_S_SetRangeRemapping(
1293   const BXDM_PictureProvider_Handle hXdmPP,
1294   BXDM_PictureProvider_P_Picture_Context *pPictureContext,
1295   BAVC_MFD_Picture* pPicture
1296   )
1297{
1298   const BXDM_Picture* pUnifiedPicture = pPictureContext->pstUnifiedPicture;
1299   BAVC_MFD_Picture * pDefaultParams = &( hXdmPP->stDMState.stChannel.stDefaultPicParams );
1300
1301   BDBG_ENTER(BXDM_PPOUT_S_SetRangeRemapping);
1302
1303   BDBG_ASSERT(pPicture);
1304
1305   /* Set defaults */
1306   pPicture->ulLumaRangeRemapping = pDefaultParams->ulLumaRangeRemapping;
1307   pPicture->ulChromaRangeRemapping = pDefaultParams->ulChromaRangeRemapping;
1308
1309   if ( ( NULL != pUnifiedPicture )
1310        && ( pUnifiedPicture->stRangeRemapping.bValid ) )
1311   {
1312      pPicture->ulLumaRangeRemapping = pUnifiedPicture->stRangeRemapping.uiLuma;
1313      pPicture->ulChromaRangeRemapping = pUnifiedPicture->stRangeRemapping.uiChroma;
1314   }
1315
1316   BDBG_LEAVE(BXDM_PPOUT_S_SetRangeRemapping);
1317   return;
1318} /* end of BXDM_PPOUT_S_SetRangeRemapping() */
1319
1320
1321static void BXDM_PPOUT_S_3DFixup(
1322   BXDM_PictureProvider_Handle hXdmPP,
1323   BXDM_PictureProvider_P_LocalState * pLocalState,
1324   BXDM_PictureProvider_P_Picture_Context * pstSelectedPicture,
1325   BAVC_MFD_Picture** pMFDPicture
1326   )
1327{
1328   BAVC_MFD_Picture* pBaseMFDPicture;
1329   BAVC_MFD_Picture* pExtendedMFDPicture;
1330   const BXDM_Picture* pUnifiedPicture = pstSelectedPicture->pstUnifiedPicture;
1331
1332   bool bFrame0IsLeft;
1333   BXDM_Picture_Orientation   eOrientation;
1334
1335   BDBG_ENTER(BXDM_PPOUT_S_3DFixup);
1336
1337   /* Handle Dependent Picture Data (e.g. for 3D content) */
1338   pBaseMFDPicture = *pMFDPicture;
1339   pBaseMFDPicture->eOrientation = BFMT_Orientation_e2D;
1340   pBaseMFDPicture->pEnhanced = NULL;
1341   pBaseMFDPicture->pNext = NULL;    /* TODO: get BD to use "pEnhanced" */
1342
1343
1344   if ( NULL == pUnifiedPicture )
1345   {
1346      return;
1347   }
1348
1349   /* SW7422-72: Generate the SEI message callback before filling in the MFD picture structure.
1350    * The middleware/application can use the contents of the SEI message to determine
1351    * if BXDM_PictureProvider_Set3D_isr needs to be called to force a specific
1352    * 3D orientation.
1353    */
1354   BXDM_PPCB_P_ExecuteSingleCallbackExt(
1355               hXdmPP,
1356               pLocalState,
1357               pstSelectedPicture,
1358               BXDM_PictureProvider_Callback_ePictureExtensionData
1359               );
1360
1361   /* Determine whether to use the 3D orientation specified by the
1362    * middleware/application or what has been delivered in-band by AVD.
1363    */
1364   if ( true == hXdmPP->stDMConfig.st3DSettings.bOverrideOrientation )
1365   {
1366      /* Use the orientation specified by the middleware/application. */
1367
1368      switch( hXdmPP->stDMConfig.st3DSettings.eOrientation )
1369      {
1370         case BXDM_PictureProvider_Orientation_eLeftRightFullFrame:
1371            eOrientation   = BXDM_Picture_Orientation_e3D_FullFrame;
1372            bFrame0IsLeft  = true;
1373            break;
1374
1375         case BXDM_PictureProvider_Orientation_eLeftRightEnhancedResolution:
1376            /* SW7425-966: This really means MVC/MRE content, i.e. a pair
1377             * of pictures where the base picture is SD LeftRight and the
1378             * dependent picture is enhancement data LeftRight
1379             */
1380            eOrientation   = BXDM_Picture_Orientation_e3D_FullFrame;
1381            bFrame0IsLeft  = true;
1382            break;
1383
1384         case BXDM_PictureProvider_Orientation_eRightLeftFullFrame:
1385            eOrientation   = BXDM_Picture_Orientation_e3D_FullFrame;
1386            bFrame0IsLeft  = false;
1387            break;
1388
1389         case BXDM_PictureProvider_Orientation_eLeftRight:
1390            eOrientation   = BXDM_Picture_Orientation_e3D_SideBySide;
1391            bFrame0IsLeft  = true;
1392            break;
1393
1394         case BXDM_PictureProvider_Orientation_eOverUnder:
1395            eOrientation   = BXDM_Picture_Orientation_e3D_TopBottom;
1396            bFrame0IsLeft  = true;
1397            break;
1398
1399         case BXDM_PictureProvider_Orientation_e2D:
1400         default:
1401            eOrientation   = BXDM_Picture_Orientation_e2D;
1402            bFrame0IsLeft  = true;
1403            break;
1404      }
1405   }
1406   else
1407   {
1408      /* Use the orientation delivered in-band by AVD. */
1409
1410      eOrientation = pUnifiedPicture->st3D.eOrientation;
1411
1412      if ( BXDM_Picture_FrameRelationship_eFrame0Left == pUnifiedPicture->st3D.eFrameRelationship
1413          || BXDM_Picture_FrameRelationship_eUnknown == pUnifiedPicture->st3D.eFrameRelationship
1414         )
1415      {
1416         bFrame0IsLeft = true;
1417      }
1418      else
1419      {
1420         bFrame0IsLeft = false;
1421      }
1422   }
1423
1424   if ( BXDM_Picture_Orientation_e3D_FullFrame == eOrientation )
1425   {
1426      if ( BXDM_PICTURE_MAX_3D_BUFFERS > hXdmPP->uiMFDPictureCount )
1427      {
1428         BXVD_DBG_ERR(hXdmPP, ("%x:[%01x.%03x] BXDM_PPOUT_S_3DFixup:: only %d buffers created in BXDM_PictureProvider_Create, 3D needs %d",
1429                                                hXdmPP->stDMState.stDecode.stDebug.uiVsyncCount,
1430                                                hXdmPP->stDMConfig.uiInstanceID & 0xF,
1431                                                pstSelectedPicture->stPicParms.uiPPBIndex & 0xFFF,
1432                                                hXdmPP->uiMFDPictureCount,
1433                                                BXDM_PICTURE_MAX_3D_BUFFERS));
1434         goto Done;
1435      }
1436
1437      /* A pair of frames. */
1438
1439      if ( NULL != pUnifiedPicture->pNextPicture )
1440      {
1441         /* Use entry '1' of the astMFDPicture array for the extended picture. */
1442         pExtendedMFDPicture = &(hXdmPP->astMFDPicture[ 1 ]);
1443
1444         /* Copy the base MFD Picture into the extended one */
1445         *pExtendedMFDPicture = *pBaseMFDPicture;
1446
1447         /* Set the fields that are different for the extended MFD picture. */
1448         pUnifiedPicture = (BXDM_Picture *) pUnifiedPicture->pNextPicture;
1449         pExtendedMFDPicture->hHeap = pUnifiedPicture->stBufferInfo.hHeap;
1450         pExtendedMFDPicture->pLuminanceFrameBufferAddress = pUnifiedPicture->stBufferInfo.pLumaBufferVirtualAddress;
1451         pExtendedMFDPicture->pChrominanceFrameBufferAddress = pUnifiedPicture->stBufferInfo.pChromaBufferVirtualAddress;
1452
1453         /* If frame 0 is the right picture, toggle the pointers.
1454          * VDC always wants the frame 0 to be the left picture.
1455          */
1456         if ( false == bFrame0IsLeft )
1457         {
1458            *pMFDPicture = &(hXdmPP->astMFDPicture[1]);
1459            pBaseMFDPicture = *pMFDPicture;
1460            pExtendedMFDPicture = &(hXdmPP->astMFDPicture[ 0 ]);
1461         }
1462
1463         /* Set the orientations */
1464         if ( true == hXdmPP->stDMConfig.st3DSettings.bOverrideOrientation
1465               && BXDM_PictureProvider_Orientation_eLeftRightEnhancedResolution == hXdmPP->stDMConfig.st3DSettings.eOrientation
1466            )
1467         {
1468            /* SW7425-966: This really means MVC/MRE content */
1469            pBaseMFDPicture->eOrientation = BFMT_Orientation_e3D_LeftRight;
1470            pExtendedMFDPicture->eOrientation = BFMT_Orientation_eLeftRight_Enhanced;
1471         }
1472         else
1473         {
1474            pBaseMFDPicture->eOrientation = BFMT_Orientation_e3D_Left;
1475            pExtendedMFDPicture->eOrientation = BFMT_Orientation_e3D_Right;
1476         }
1477
1478         /* Link the extended MFD structure to the base structure.  */
1479         pBaseMFDPicture->pEnhanced = pExtendedMFDPicture;
1480         pExtendedMFDPicture->pEnhanced = NULL;
1481
1482         /* To support the original MVC behavior on the older DVD chips,
1483          * set "pNext" as well as "pEnhanced"
1484          */
1485         if ( true == hXdmPP->stDMConfig.st3DSettings.bSetNextPointer )
1486         {
1487            pBaseMFDPicture->pNext = pExtendedMFDPicture;
1488            pExtendedMFDPicture->pNext = NULL;
1489         }
1490      }
1491      else
1492      {
1493         BXVD_DBG_ERR(hXdmPP, ("%x:[%01x.%03x] BXDM_PPOUT_S_3DFixup:: 3D pair does not have the second frame.",
1494                                                hXdmPP->stDMState.stDecode.stDebug.uiVsyncCount,
1495                                                hXdmPP->stDMConfig.uiInstanceID & 0xF,
1496                                                pstSelectedPicture->stPicParms.uiPPBIndex & 0xFFF));
1497      }
1498
1499   }
1500   else
1501   {
1502      /* A Single frame. The only packed 3D formats supported by VDC are SideBySide or TopBottom
1503       * with frame 0 as the left frame.  Treat all other cases as 2D.
1504       */
1505      switch( eOrientation )
1506      {
1507         case BXDM_Picture_Orientation_e3D_SideBySide:
1508            if ( true == bFrame0IsLeft )
1509            {
1510               pBaseMFDPicture->eOrientation = BFMT_Orientation_e3D_LeftRight;
1511            }
1512            else
1513            {
1514               pBaseMFDPicture->eOrientation = BFMT_Orientation_e2D;
1515
1516               BXVD_DBG_WRN(hXdmPP, ("%x:[%01x.%03x] Unsupported 3D orientation: right/left side-by-side overridden to 2D",
1517                              hXdmPP->stDMState.stDecode.stDebug.uiVsyncCount,
1518                              hXdmPP->stDMConfig.uiInstanceID & 0xF,
1519                              pstSelectedPicture->stPicParms.uiPPBIndex & 0xFFF
1520                              ));
1521            }
1522            break;
1523
1524         case BXDM_Picture_Orientation_e3D_TopBottom:
1525            if ( true == bFrame0IsLeft )
1526            {
1527               pBaseMFDPicture->eOrientation = BFMT_Orientation_e3D_OverUnder;
1528            }
1529            else
1530            {
1531               pBaseMFDPicture->eOrientation = BFMT_Orientation_e2D;
1532
1533               BXVD_DBG_WRN(hXdmPP, ("%x:[%01x.%03x] Unsupported 3D orientation: right/left top-bottom overridden to 2D",
1534                              hXdmPP->stDMState.stDecode.stDebug.uiVsyncCount,
1535                              hXdmPP->stDMConfig.uiInstanceID & 0xF,
1536                              pstSelectedPicture->stPicParms.uiPPBIndex & 0xFFF
1537                              ));
1538            }
1539            break;
1540
1541         case BXDM_Picture_Orientation_e3D_Checker:
1542            pBaseMFDPicture->eOrientation = BFMT_Orientation_e2D;
1543
1544            BXVD_DBG_WRN(hXdmPP, ("%x:[%01x.%03x] Unsupported 3D orientation: checker overridden to 2D",
1545                              hXdmPP->stDMState.stDecode.stDebug.uiVsyncCount,
1546                              hXdmPP->stDMConfig.uiInstanceID & 0xF,
1547                              pstSelectedPicture->stPicParms.uiPPBIndex & 0xFFF
1548                              ));
1549
1550            break;
1551
1552         case BXDM_Picture_Orientation_e3D_Column:
1553            pBaseMFDPicture->eOrientation = BFMT_Orientation_e2D;
1554
1555            BXVD_DBG_WRN(hXdmPP, ("%x:[%01x.%03x] Unsupported 3D orientation: column overridden to 2D",
1556                              hXdmPP->stDMState.stDecode.stDebug.uiVsyncCount,
1557                              hXdmPP->stDMConfig.uiInstanceID & 0xF,
1558                              pstSelectedPicture->stPicParms.uiPPBIndex & 0xFFF
1559                              ));
1560            break;
1561
1562         case BXDM_Picture_Orientation_e3D_Row:
1563            pBaseMFDPicture->eOrientation = BFMT_Orientation_e2D;
1564
1565            BXVD_DBG_WRN(hXdmPP, ("%x:[%01x.%03x] Unsupported 3D orientation: row overridden to 2D",
1566                              hXdmPP->stDMState.stDecode.stDebug.uiVsyncCount,
1567                              hXdmPP->stDMConfig.uiInstanceID & 0xF,
1568                              pstSelectedPicture->stPicParms.uiPPBIndex & 0xFFF
1569                              ));
1570            break;
1571
1572         case BXDM_Picture_Orientation_e2D:
1573         default:
1574            pBaseMFDPicture->eOrientation = BFMT_Orientation_e2D;
1575            break;
1576      }
1577   }
1578
1579Done:
1580
1581   BDBG_LEAVE(BXDM_PPOUT_S_3DFixup);
1582
1583   return;
1584
1585}     /* end of BXDM_PPOUT_S_3DFixup() */
1586
1587
1588void BXDM_PPOUT_P_CalculateStaticVdcData(
1589   BXDM_PictureProvider_Handle hXdmPP,
1590   BXDM_PictureProvider_P_Picture_Context *pPictureContext
1591   )
1592{
1593   BAVC_MFD_Picture* pMFDPicture = &pPictureContext->stMFDPicture;
1594   BAVC_MFD_Picture * pDefaultParams = &( hXdmPP->stDMState.stChannel.stDefaultPicParams );
1595
1596   /* Reset local MFD Picture */
1597   *pMFDPicture = hXdmPP->stDMState.stChannel.stDefaultPicParams;
1598
1599   /* Source Information (hHeap, pLuminanceFrameBufferAddress,
1600    * pChrominanceFrameBufferAddress, eStripeWidth, ulLuminanceNMBY,
1601    * ulChrominanceNMBY, ulSourceHorizontalSize, ulSourceVerticalSize,
1602    * eFrameRateCode, eMpegType, eYCbCrType) */
1603   BXDM_PPOUT_S_SetSourceBufferInformation(
1604      hXdmPP,
1605      pPictureContext,
1606      pMFDPicture
1607      );
1608
1609#if 0
1610   BKNI_Printf("[%d/%d - %p]\n", pMFDPicture->eSourcePolarity, pMFDPicture->eInterruptPolarity, pMFDPicture->pLuminanceFrameBufferAddress);
1611#endif
1612
1613   /* Clipping (ulSourceHorizontalSize, ulSourceVerticalSize,
1614    * ulSourceClipTop, ulSourceClipLeft) */
1615   BXDM_PPOUT_S_SetClipping(
1616      hXdmPP,
1617      pPictureContext,
1618      pMFDPicture
1619      );
1620
1621   /* Aspect Ratio (eAspectRatio, uiSampleAspectRatioX,
1622    * uiSampleAspectRatioY) */
1623   BXDM_PPOUT_S_SetAspectRatio(
1624      hXdmPP,
1625      pPictureContext,
1626      pMFDPicture
1627      );
1628
1629   /* Pan Scan (i32_HorizontalPanScan, i32_VerticalPanScan,
1630    * ulDisplayHorizontalSize, ulDisplayVerticalSize) */
1631   BXDM_PPOUT_S_SetPanScan(
1632      hXdmPP,
1633      pPictureContext,
1634      hXdmPP->stDMConfig.bCRCMode,
1635      pMFDPicture
1636      );
1637
1638   /* Display Parameters (eMatrixCoefficients, eColorPrimaries,
1639    * eTransferCharacteristics) */
1640   BXDM_PPOUT_S_SetDisplayParameters(
1641      hXdmPP,
1642      pPictureContext,
1643      pMFDPicture
1644      );
1645
1646   /* ulAdjQp */
1647   BXDM_PPOUT_S_SetDigitalNoiseReduction(
1648      hXdmPP,
1649      pPictureContext,
1650      pMFDPicture
1651      );
1652
1653   /* Range Re-mapping (ulLumaRangeRemapping,
1654    * ulChromaRangeRemapping) */
1655   BXDM_PPOUT_S_SetRangeRemapping(
1656      hXdmPP,
1657      pPictureContext,
1658      pMFDPicture
1659      );
1660
1661   /* Progressive Flags (bFrameProgressive, bStreamProgressive) */
1662   /* SW7405-5549: moved to BXDM_PPOUT_P_CalculateVdcData */
1663   /*pMFDPicture->bFrameProgressive = ( BXDM_PictureProvider_P_RepeatMode_eFrame == pPictureContext->stPicParms.stDisplay.stDynamic.eTrickPlayRepeatMode );*/
1664   pMFDPicture->bStreamProgressive = ( BXDM_Picture_Sequence_eProgressive == pPictureContext->pstUnifiedPicture->stPictureType.eSequence );
1665
1666   /* Unused Parameters (hSurface, ulRowStride) */
1667   pMFDPicture->hSurface = pDefaultParams->hSurface;
1668
1669   /* SW7425-44: parameters for encoder ... */
1670   pMFDPicture->ePictureType = pPictureContext->pstUnifiedPicture->stPictureType.eCoding;
1671
1672   /* SW7425-2247: support for "bar data". */
1673   pMFDPicture->eBarDataType        = pPictureContext->pstUnifiedPicture->stBarData.eBarDataType;
1674   pMFDPicture->ulTopLeftBarValue   = pPictureContext->pstUnifiedPicture->stBarData.uiTopLeftBarValue;
1675   pMFDPicture->ulBotRightBarValue  = pPictureContext->pstUnifiedPicture->stBarData.uiBotRightBarValue;
1676
1677   /* Only update the parameters BEFORE the first PPB has passed TSM */
1678   /* Update the Picture Parameter structure with the data for this PPB. */
1679   if (( true == hXdmPP->stDMState.stDecode.bFirstPPBSeen )
1680       && (false == hXdmPP->stDMState.stDecode.bFirstPPBHasBeenDisplayed))
1681   {
1682      BXDM_PPOUT_S_UpdatePictureParameters(
1683         hXdmPP,
1684         pMFDPicture,
1685         pPictureContext,
1686         true
1687         );
1688   }
1689} /* end of BXDM_PPOUT_P_CalculateStaticVdcData() */
1690
1691static void BXDM_PPOUT_S_SetStallStcAndIgnorePicture(
1692   BXDM_PictureProvider_Handle hXdmPP,
1693   BXDM_PictureProvider_P_LocalState* pLocalState,
1694   BXDM_PictureProvider_P_Picture_Context* pstPicture,
1695   BAVC_MFD_Picture* pMFDPicture
1696   )
1697{
1698   /* SW7425-44: Set the bIgnorePicture flag if we are repeating because of a stall scenario.
1699    * Set the bStallStc flag if video decoder is underflowing
1700    * See: http://twiki-01.broadcom.com/bin/view/Bsema/DisplayManagerV2TSM#Transcode_meta_data_sent_to_VDC
1701    */
1702
1703   /* Calculate STC Stall */
1704   {
1705      pMFDPicture->bStallStc = false;
1706
1707      /* SW7425-2270: remain in the "ignore" state until there are pictues on the queue. */
1708      if ( true == hXdmPP->stDMState.stDecode.stNonRealTime.bIgnoringUnderflow )
1709      {
1710         hXdmPP->stDMState.stDecode.stNonRealTime.bIgnoringUnderflow = ( true == pLocalState->bPictureQueueIsEmpty );
1711      }
1712
1713      /* SW7425-2270: only look to set bStallStc if the system is NOT ignoring underflows. */
1714      if ( false == hXdmPP->stDMState.stDecode.stNonRealTime.bIgnoringUnderflow )
1715      {
1716         /* This encoder stalled (underflow) */
1717         if ( ( pstPicture->stPicParms.stTSM.stDynamic.iStcPtsDifferenceEvaluated >= (int32_t) pstPicture->stPicParms.stTSM.stStatic.stPTSDelta.uiWhole ) /* next picture not available */
1718                && ( true == pLocalState->bPictureQueueIsEmpty ) ) /* decoder underflow */
1719         {
1720            if ( true == hXdmPP->stDMConfig.bIgnoreNRTUnderflow )
1721            {
1722               BDBG_MSG(("%x:[%01x.%03x] Ignoring Underflow",
1723                              hXdmPP->stDMState.stDecode.stDebug.uiVsyncCount,
1724                              hXdmPP->stDMConfig.uiInstanceID & 0xF,
1725                              pstPicture->stPicParms.uiPPBIndex & 0xFFF
1726                              ));
1727
1728               /* SW7425-2270: "bIgnoreNRTUnderflow" is a one shot, clear the flag once
1729                * the system enters this state.
1730                */
1731               hXdmPP->stDMConfig.bIgnoreNRTUnderflow = false;
1732               hXdmPP->stDMState.stDecode.stNonRealTime.bIgnoringUnderflow = true;
1733            }
1734            else
1735            {
1736               BDBG_MSG(("%x:[%01x.%03x] Underflow STC Stall",
1737                              hXdmPP->stDMState.stDecode.stDebug.uiVsyncCount,
1738                              hXdmPP->stDMConfig.uiInstanceID & 0xF,
1739                              pstPicture->stPicParms.uiPPBIndex & 0xFFF
1740                              ));
1741
1742               pMFDPicture->bStallStc = true;
1743            }
1744         }
1745         /* SW7425-767: Prevent field inversion when STC is stalled, by stalling until the T/B polarity matches */
1746         else if ( ( ( true == hXdmPP->stDMState.stDecode.stNonRealTime.bLastStcValid ) /* dSTC == 0 */
1747                     && ( hXdmPP->stDMState.stDecode.stNonRealTime.uiLastStc == pLocalState->uiStcSnapshot ) )
1748                   && ( hXdmPP->stDMState.stDecode.stNonRealTime.ePolarityWhenDeltaStcWasNonZero != pLocalState->eVsyncPolarity ) ) /* Polarity mismatch */
1749         {
1750            BDBG_MSG(("%x:[%01x.%03x] FIC STC Stall",
1751                              hXdmPP->stDMState.stDecode.stDebug.uiVsyncCount,
1752                              hXdmPP->stDMConfig.uiInstanceID & 0xF,
1753                              pstPicture->stPicParms.uiPPBIndex & 0xFFF
1754                              ));
1755
1756            pMFDPicture->bStallStc = true;
1757         }
1758      }
1759   }
1760
1761   /* Calculate Ignore Picture */
1762   {
1763      /* By default, if we're stalling the STC, we also want to ignore this picture */
1764      pMFDPicture->bIgnorePicture = pMFDPicture->bStallStc;
1765
1766      /* This encoder stalled (underflow) */
1767      if ( ( pstPicture->stPicParms.stTSM.stDynamic.iStcPtsDifferenceEvaluated >= (int32_t) pstPicture->stPicParms.stTSM.stStatic.stPTSDelta.uiWhole ) /* next picture not available */
1768                && ( true == pLocalState->bPictureQueueIsEmpty )  /* decoder underflow */
1769                && ( false == hXdmPP->stDMState.stDecode.stNonRealTime.bIgnoringUnderflow ) /* not ignoring the underflow */
1770         )
1771      {
1772         BDBG_MSG(("%x:[%01x.%03x] Underflow Ignore Pic",
1773                              hXdmPP->stDMState.stDecode.stDebug.uiVsyncCount,
1774                              hXdmPP->stDMConfig.uiInstanceID & 0xF,
1775                              pstPicture->stPicParms.uiPPBIndex & 0xFFF
1776                              ));
1777
1778         pMFDPicture->bIgnorePicture = true;
1779      }
1780
1781      /* The STC is stalled and this field has already been encoded, then don't encode the same field again */
1782      if ( ( ( true == hXdmPP->stDMState.stDecode.stNonRealTime.bLastStcValid ) /* dSTC == 0 */
1783             && ( hXdmPP->stDMState.stDecode.stNonRealTime.uiLastStc == pLocalState->uiStcSnapshot ) )
1784           && ( true == pstPicture->stPicParms.stDisplay.stDynamic.bPPBEncoded ) )
1785      {
1786         BDBG_MSG(("%x:[%01x.%03x] Repeated Ignore Pic",
1787                              hXdmPP->stDMState.stDecode.stDebug.uiVsyncCount,
1788                              hXdmPP->stDMConfig.uiInstanceID & 0xF,
1789                              pstPicture->stPicParms.uiPPBIndex & 0xFFF
1790                              ));
1791
1792         pMFDPicture->bIgnorePicture = true;
1793      }
1794   }
1795
1796   if ( false == pMFDPicture->bIgnorePicture )
1797   {
1798      pstPicture->stPicParms.stDisplay.stDynamic.bPPBEncoded = true;
1799   }
1800
1801   /* Keep track of interrupt polarity to aid FIC STC Stall logic
1802    * SW7425-2424: "bPolarityFieldValid" forces "ePolarityWhenDeltaStcWasNonZero"
1803    * to be set the first time through this code.
1804    */
1805   if ( (( true == hXdmPP->stDMState.stDecode.stNonRealTime.bLastStcValid )
1806               && ( hXdmPP->stDMState.stDecode.stNonRealTime.uiLastStc != pLocalState->uiStcSnapshot ))
1807        || ( false == hXdmPP->stDMState.stDecode.stNonRealTime.bPolarityFieldValid )
1808      )
1809   {
1810      /* dStc != 0 */
1811      /* STC advanced since last display interrupt,
1812       * so just record the current polarity
1813       */
1814      hXdmPP->stDMState.stDecode.stNonRealTime.ePolarityWhenDeltaStcWasNonZero = pLocalState->eVsyncPolarity;
1815      hXdmPP->stDMState.stDecode.stNonRealTime.bPolarityFieldValid = true;
1816   }
1817
1818   hXdmPP->stDMState.stDecode.stNonRealTime.uiLastStc = pLocalState->uiStcSnapshot;
1819   hXdmPP->stDMState.stDecode.stNonRealTime.bLastStcValid = true;
1820   hXdmPP->stDMState.stDecode.stNonRealTime.bLastStallStc = pMFDPicture->bStallStc;
1821   hXdmPP->stDMState.stDecode.stNonRealTime.bLastStallStcValid = true;
1822}
1823
1824void BXDM_PPOUT_P_CalculateVdcData(
1825   BXDM_PictureProvider_Handle hXdmPP,
1826   BXDM_PictureProvider_P_LocalState* pLocalState,
1827   BAVC_MFD_Picture** pMFDPicture
1828   )
1829{
1830   const BXDM_Picture* pUnifiedPicture = NULL;
1831   BAVC_MFD_Picture * pDefaultParams = &( hXdmPP->stDMState.stChannel.stDefaultPicParams );
1832   BAVC_MFD_Picture *pCurrentMFDPicture;
1833
1834   BXDM_PictureProvider_P_Picture_Context * pstSelectedPicture = &( hXdmPP->stDMState.stChannel.stSelectedPicture );
1835
1836   BDBG_ENTER(BXDM_PPOUT_P_CalculateVdcData);
1837
1838   BDBG_ASSERT(pMFDPicture);
1839   *pMFDPicture = &(hXdmPP->astMFDPicture[0]);
1840   pCurrentMFDPicture = *pMFDPicture;
1841
1842   /* If a PPB is not available, simply return without changing the "pCurrentMFDPicture" structure.
1843    * This leaves all the information intact from the last picture sent to XVD.
1844    * However, the "polarity" does need to be set, don't move this statement.
1845    * Also be certain that the picture is muted.
1846    */
1847   if ( NULL == pstSelectedPicture->pstUnifiedPicture )
1848   {
1849      /* eInterruptPolarity */
1850      pCurrentMFDPicture->eInterruptPolarity = pLocalState->eVsyncPolarity;
1851
1852      if ( ( true == hXdmPP->stDMConfig.bPlayback )
1853           && ( true == hXdmPP->stDMConfig.bSTCValid ) )
1854      {
1855         /* If in playback mode and the STC is valid, but we don't have a picture to display, yet,
1856          * then we want the encoder to encode the muted frames and increment the STC to ensure all
1857          * encoders start at the same time.  This would happen when the video decoder is the slave
1858          * and TSM has not passed, yet.
1859          * See: http://twiki-01.broadcom.com/bin/view/Arch/TranscodeMiscellaneous#Revisiting_Time_Zero_Approach_of */
1860         pCurrentMFDPicture->bIgnorePicture = false;
1861         pCurrentMFDPicture->bStallStc = false;
1862      }
1863      else
1864      {
1865         pCurrentMFDPicture->bIgnorePicture = pDefaultParams->bIgnorePicture;
1866         pCurrentMFDPicture->bStallStc = pDefaultParams->bStallStc;
1867      }
1868      pCurrentMFDPicture->bMute=true;
1869      pCurrentMFDPicture->bChannelChange = true; /* for SW7425-2253: */
1870   }
1871   else
1872   {
1873      pUnifiedPicture = pstSelectedPicture->pstUnifiedPicture;
1874
1875      /* Copy static MFD Picture info from the selected picture context */
1876      *pCurrentMFDPicture = pstSelectedPicture->stMFDPicture;
1877
1878      /* SW7405-5549: there is a remote chance that eTrickPlayRepeatMode could change after
1879       * BXDM_PPOUT_P_CalculateStaticVdcData has been called. This could come about if the
1880       * monitor refresh rate is changed while a stream is playing.  Hence the assignment needs
1881       * to be done here.
1882       */
1883      pCurrentMFDPicture->bFrameProgressive = ( BXDM_PictureProvider_P_RepeatMode_eFrame == pstSelectedPicture->stPicParms.stDisplay.stDynamic.eTrickPlayRepeatMode );
1884
1885      /* eInterruptPolarity */
1886      pCurrentMFDPicture->eInterruptPolarity = pLocalState->eVsyncPolarity;
1887
1888      /* pPictureInfo->eSourcePolarity */
1889      BXDM_PPOUT_S_SetSourcePolarity(
1890         hXdmPP,
1891         pstSelectedPicture,
1892         pLocalState,
1893         pCurrentMFDPicture
1894         );
1895
1896      /* Pan Scan (i32_HorizontalPanScan, i32_VerticalPanScan,
1897       * ulDisplayHorizontalSize, ulDisplayVerticalSize) */
1898      BXDM_PPOUT_S_SetPanScan(
1899         hXdmPP,
1900         pstSelectedPicture,
1901         hXdmPP->stDMConfig.bCRCMode,
1902         pCurrentMFDPicture
1903         );
1904
1905      /* eChrominanceInterpolationMode */
1906      if ( ( BAVC_Polarity_eFrame == pCurrentMFDPicture->eSourcePolarity )
1907           || ( BXDM_PictureProvider_P_RepeatMode_eFrame == pstSelectedPicture->stPicParms.stDisplay.stDynamic.eTrickPlayRepeatMode )
1908         )
1909      {
1910         pCurrentMFDPicture->eChrominanceInterpolationMode = BAVC_InterpolationMode_eFrame;
1911      }
1912      else
1913      {
1914         pCurrentMFDPicture->eChrominanceInterpolationMode = pDefaultParams->eChrominanceInterpolationMode;
1915      }
1916
1917      /* bPictureRepeatFlag - We set this to true if we're repeating the
1918       * same field from the same PPB */
1919      if ( ( true == pstSelectedPicture->stPicParms.stDisplay.stDynamic.bPPBRepeated )
1920           && ( pstSelectedPicture->pstUnifiedPicture == hXdmPP->stDMState.stChannel.stPreviousPicture.pstUnifiedPicture )
1921           && ( pCurrentMFDPicture->eSourcePolarity == hXdmPP->stDMState.stChannel.ePrevSourcePolarity )
1922           && ( false == hXdmPP->stDMState.stChannel.bPrevMute )
1923         )
1924      {
1925         pCurrentMFDPicture->bPictureRepeatFlag = true;
1926      }
1927      else
1928      {
1929         pCurrentMFDPicture->bPictureRepeatFlag = pDefaultParams->bPictureRepeatFlag;
1930      }
1931
1932      /* SW7425-104: Set the MFD bRepeatField flag based on how the picture was previously
1933       * delivered to VDC.  If an element is being repeated, set the flag.  Track which
1934       * elements are delivered for subsequent vsyncs.
1935       */
1936      if ( false == hXdmPP->stDMState.stChannel.bPrevMute )
1937      {
1938         switch ( pCurrentMFDPicture->eSourcePolarity )
1939         {
1940            case BAVC_Polarity_eFrame:
1941               pCurrentMFDPicture->bRepeatField = ( pstSelectedPicture->stPicParms.stDisplay.stDynamic.bFrameDelivered ) ? true : false ;
1942               pstSelectedPicture->stPicParms.stDisplay.stDynamic.bFrameDelivered = true;
1943               break;
1944
1945            case BAVC_Polarity_eBotField:
1946               pCurrentMFDPicture->bRepeatField = ( pstSelectedPicture->stPicParms.stDisplay.stDynamic.bBottomFieldDelivered ) ? true : false ;
1947               pstSelectedPicture->stPicParms.stDisplay.stDynamic.bBottomFieldDelivered = true;
1948               break;
1949
1950            case BAVC_Polarity_eTopField:
1951            default:
1952               pCurrentMFDPicture->bRepeatField = ( pstSelectedPicture->stPicParms.stDisplay.stDynamic.bTopFieldDelivered ) ? true : false ;
1953               pstSelectedPicture->stPicParms.stDisplay.stDynamic.bTopFieldDelivered = true;
1954               break;
1955
1956         }
1957      }
1958
1959
1960      /* PR49634: bIgnoreCadenceMatch - We set this to true if we're
1961       * not expecting polarity match so that we can turn off VDC's
1962       * cadence matching */
1963      BXDM_PPFIC_P_CalculateIgnoreCadenceMatch(
1964         hXdmPP,
1965         pLocalState,
1966         pstSelectedPicture
1967         );
1968      pCurrentMFDPicture->bIgnoreCadenceMatch = pstSelectedPicture->stPicParms.stDisplay.stDynamic.bIgnoreCadenceMatch;
1969
1970      BXDM_PPOUT_S_SetStallStcAndIgnorePicture(
1971         hXdmPP,
1972         pLocalState,
1973         pstSelectedPicture,
1974         pCurrentMFDPicture
1975         );
1976
1977      /* Remember the mute state from this vsync */
1978      hXdmPP->stDMState.stChannel.bPrevMute = pCurrentMFDPicture->bMute;
1979
1980      /* Keep track of the source polarity to help us decide what to set
1981       * the polarity of progressive content on a progressive display
1982       * when MPIM is set to eInterlaced.  We also use this value when
1983       * handling the eSingleField display field type */
1984      hXdmPP->stDMState.stChannel.ePrevSourcePolarity = pCurrentMFDPicture->eSourcePolarity;
1985
1986      BXDM_PPOUT_S_SetMpegType(
1987               hXdmPP,
1988               pstSelectedPicture,
1989               pCurrentMFDPicture
1990               );
1991
1992      BXDM_PPOUT_S_SetPictureOrderCount(
1993                hXdmPP,
1994                pstSelectedPicture,
1995                pCurrentMFDPicture);
1996
1997      /* Set the AFD (Active Format Description) based on the contents of the PPB.
1998       */
1999      pCurrentMFDPicture->bValidAfd = pUnifiedPicture->stActiveFormatDescription.bValid;
2000      if ( true == pCurrentMFDPicture->bValidAfd )
2001      {
2002         pCurrentMFDPicture->ulAfd = pUnifiedPicture->stActiveFormatDescription.uiValue;
2003      }
2004      else
2005      {
2006         pCurrentMFDPicture->ulAfd = 0;
2007      }
2008
2009      /* If the picture is NOT a repeat, bump the count of pictures delivered to VDC. */
2010      if ( false == pstSelectedPicture->stPicParms.stDisplay.stDynamic.bElementRepeated )
2011      {
2012         hXdmPP->stDMStatus.stCounters.uiDisplayedCount++;
2013      }
2014
2015      /* Only update the parameters AFTER the first PPB has passed TSM */
2016      /* Update the Picture Parameter structure with the data for this PPB. */
2017      if (true == hXdmPP->stDMState.stDecode.bFirstPPBHasBeenDisplayed)
2018      {
2019         BXDM_PPOUT_S_UpdatePictureParameters(
2020            hXdmPP,
2021            pCurrentMFDPicture,
2022            pstSelectedPicture,
2023            false
2024            );
2025      }
2026
2027      /* If CRC mode is enabled AND the element is not being repeated
2028       * then instruct VDC to generate the CRC.
2029       */
2030      if ( ( false == pstSelectedPicture->stPicParms.stDisplay.stDynamic.bElementRepeated )
2031           && ( true == hXdmPP->stDMConfig.bCRCMode )
2032         )
2033      {
2034         pCurrentMFDPicture->bCaptureCrc = true;
2035      }
2036      else
2037      {
2038         pCurrentMFDPicture->bCaptureCrc = false;
2039      }
2040
2041      /* SW7425-44: parameters for encoder ... */
2042      /* set original PTS for encoder use. Note: original PTS is either the original coded
2043         PTS of the selected picture or the interpolated PTS for this picture BEFORE any jitter
2044         correction or adjustments are made */
2045      BXDM_PPQM_P_GetPtsUnfiltered(pstSelectedPicture,
2046                                   BXDM_PictureProvider_P_PTSIndex_eActual,
2047                                   pstSelectedPicture->stPicParms.stTSM.stDynamic.uiTSMSelectedElement,
2048                                   &pCurrentMFDPicture->ulOrigPTS);
2049
2050      /* SW7425-764: copy the monitor refresh rate into the MFD structure. */
2051      pCurrentMFDPicture->eInterruptRefreshRate = pstSelectedPicture->stPicParms.stDisplay.stStatic.eBFMTRefreshRate;
2052
2053      /* SW7425-1781: copy the picture's serial number into uiDecoderPictureId */
2054      pCurrentMFDPicture->ulDecodePictureId = pUnifiedPicture->uiSerialNumber;
2055
2056      /* SW7425-2253: set "bChannelChange" if new pictures are NOT being decoded and delivered to VDC, i.e.
2057       * - BXVD_StopDecode has been called
2058       * - OR BXVD_StartDecode has been, but the first picture has not been sent to VDC.
2059       */
2060      pCurrentMFDPicture->bChannelChange = ( BXDM_PictureProvider_P_DecodeState_eStopped == hXdmPP->stDMState.stChannel.eDecodeState ); 
2061      pCurrentMFDPicture->bChannelChange |= ( false == hXdmPP->stDMState.stDecode.bFirstPPBHasBeenDisplayed ); 
2062   }
2063
2064   /* SW7425-1001: set "MFD.bLast" if
2065    * - "bLastPictureSeen" is true
2066    * - AND and the last field of the last picture has been delivered to VDC
2067    *   (as indicated by value of "iStcPtsDifferenceEvaluated")
2068    *
2069    * The use of "bSetLastPictureFlag" may be overkill, but it ensures that
2070    * once "MFD.bLast" is set, it stays set.
2071    */
2072   if ( ( pstSelectedPicture->stPicParms.stTSM.stDynamic.iStcPtsDifferenceEvaluated >= (int32_t) pstSelectedPicture->stPicParms.stTSM.stStatic.stPTSDelta.uiWhole )
2073         && ( true == pstSelectedPicture->stPicParms.stDisplay.stDynamic.bLastPictureSeen )
2074      )
2075   {
2076      pstSelectedPicture->stPicParms.stDisplay.stDynamic.bSetLastPictureFlag = true;
2077   }
2078
2079   pCurrentMFDPicture->bLast = pstSelectedPicture->stPicParms.stDisplay.stDynamic.bSetLastPictureFlag;
2080
2081   BXDM_PPDBG_P_OutputLog(
2082      hXdmPP,
2083      pLocalState,
2084      pCurrentMFDPicture
2085      );
2086
2087
2088   BXDM_PPOUT_S_3DFixup(
2089      hXdmPP,
2090      pLocalState,
2091      pstSelectedPicture,
2092      pMFDPicture
2093      );
2094
2095#if 0
2096   BKNI_Printf("m:%d,ip:%d,sp:%d,ar:(%d,%d:%d),fr:%d,mt:%d,yt:%d,%4dx%4d,nm:%3dx%3d,sw:%d,poc:(%2d,%2d),cl:%2dx%2d\n",
2097               pCurrentMFDPicture->bMute,
2098               pCurrentMFDPicture->eInterruptPolarity,
2099               pCurrentMFDPicture->eSourcePolarity,
2100               pCurrentMFDPicture->eAspectRatio,
2101               pCurrentMFDPicture->uiSampleAspectRatioX,
2102               pCurrentMFDPicture->uiSampleAspectRatioY,
2103               pCurrentMFDPicture->eFrameRateCode,
2104               pCurrentMFDPicture->eMpegType,
2105               pCurrentMFDPicture->eYCbCrType,
2106               pCurrentMFDPicture->ulSourceHorizontalSize,
2107               pCurrentMFDPicture->ulSourceVerticalSize,
2108               pCurrentMFDPicture->ulLuminanceNMBY,
2109               pCurrentMFDPicture->ulChrominanceNMBY,
2110               pCurrentMFDPicture->eStripeWidth,
2111               pCurrentMFDPicture->ulIdrPicID,
2112               pCurrentMFDPicture->int32_PicOrderCnt,
2113               pCurrentMFDPicture->ulSourceClipTop,
2114               pCurrentMFDPicture->ulSourceClipLeft
2115               );
2116#endif
2117
2118   BDBG_LEAVE(BXDM_PPOUT_P_CalculateVdcData);
2119   return;
2120} /* end of BXDM_PPOUT_P_CalculateVdcData() */
2121
2122/*
2123 * This routine will be called at "channel open" time to
2124 * handle initialization that only needs to occur once.
2125 * This is intend to reduce the initialization overhead
2126 * at "start decode" time.
2127 */
2128void BXDM_PPOUT_P_OpenChannel(
2129   BXDM_PictureProvider_Handle hXdmPP
2130   )
2131{
2132   BAVC_MFD_Picture * pDefaultParams = &( hXdmPP->stDMState.stChannel.stDefaultPicParams );
2133
2134   /*
2135    * Set the default picture parameters.
2136    */
2137   BKNI_Memset(
2138      &(hXdmPP->stDMState.stChannel.stDefaultPicParams),
2139      0,
2140      sizeof( hXdmPP->stDMState.stChannel.stDefaultPicParams )
2141      );
2142
2143   pDefaultParams->eInterruptPolarity = BAVC_Polarity_eTopField;
2144   pDefaultParams->bIgnorePicture = true;
2145   pDefaultParams->bStallStc = true;
2146   pDefaultParams->bMute = true;
2147   pDefaultParams->hHeap = NULL;
2148   pDefaultParams->eSourcePolarity = BAVC_Polarity_eTopField;
2149   pDefaultParams->eMatrixCoefficients = BAVC_MatrixCoefficients_eUnknown;
2150   pDefaultParams->eAspectRatio = BFMT_AspectRatio_eUnknown;
2151   pDefaultParams->eFrameRateCode = BAVC_FrameRateCode_eUnknown;
2152   pDefaultParams->hSurface = NULL;
2153   pDefaultParams->bStreamProgressive = false;
2154   pDefaultParams->bFrameProgressive = false;
2155   pDefaultParams->eMpegType = BAVC_MpegType_eMpeg2;
2156   pDefaultParams->eYCbCrType = BAVC_YCbCrType_e4_2_0;
2157   pDefaultParams->eChrominanceInterpolationMode = BAVC_InterpolationMode_eField;
2158   pDefaultParams->eColorPrimaries = BAVC_ColorPrimaries_eUnknown;
2159   pDefaultParams->eTransferCharacteristics = BAVC_TransferCharacteristics_eUnknown;
2160   pDefaultParams->pLuminanceFrameBufferAddress = NULL;
2161   pDefaultParams->pChrominanceFrameBufferAddress = NULL;
2162   pDefaultParams->bPictureRepeatFlag = false;
2163   pDefaultParams->bIgnoreCadenceMatch = false;
2164   pDefaultParams->pNext = NULL;
2165   pDefaultParams->bCaptureCrc = false;
2166   pDefaultParams->eStripeWidth = BAVC_StripeWidth_e64Byte;
2167   pDefaultParams->ulLumaRangeRemapping = 0x08;
2168   pDefaultParams->ulChromaRangeRemapping = 0x08;
2169   pDefaultParams->hFgtHeap = NULL;
2170   pDefaultParams->pFgtSeiBufferAddress = NULL;
2171   pDefaultParams->ePictureType = BAVC_PictureCoding_eUnknown;
2172   pDefaultParams->ePxlFmt = BPXL_INVALID;
2173   pDefaultParams->eBarDataType = BAVC_BarDataType_eInvalid;
2174   return;
2175
2176}  /* end of BXDM_PPOUT_P_OpenChannel() */
Note: See TracBrowser for help on using the repository browser.