source: svn/newcon3bcm2_21bu/magnum/commonutils/vdb/3556/B2/bvdb.c @ 46

Last change on this file since 46 was 46, checked in by megakiss, 11 years ago

459Mhz로 OTC 주파수 변경

  • Property svn:executable set to *
File size: 101.0 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2003-2010, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: bvdb.c $
11 * $brcm_Revision: Hydra_Software_Devel/73 $
12 * $brcm_Date: 9/13/10 9:11p $
13 *
14 * Module Description:
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /magnum/commonutils/vdb/3548/B0/bvdb.c $
19 *
20 * Hydra_Software_Devel/73   9/13/10 9:11p vineetr
21 * SW3548-3079: Temporarily holding off on this change, until Jerry can
22 * re-confirm.
23 *
24 * Hydra_Software_Devel/72   9/13/10 8:47p vineetr
25 * SW3548-3079: Adding support for top bottom half res to side by side
26 * half res.
27 *
28 * Hydra_Software_Devel/71   7/13/10 5:11p vineetr
29 * SW3548-2987: Preliminary changes to support new 1080p@30Hz format. The
30 * final update to the usage modes in the VDB table are still pending,
31 * since I am waiting for the RTS to be re-analyzed. Until then, these
32 * changes are 'harmless'.
33 * Hydra_Software_Devel/70   6/2/10 4:18p vineetr
34 * SW3548-2962: There is now an officially supported way (in Nexus) to
35 * change the BVN configuration at run time. Whenever that API is called,
36 * BVDB_ValidateConfigId() is called and we now clear the cached info
37 * when that happens.
38 *
39 * Hydra_Software_Devel/67   4/15/10 2:33p jerrylim
40 * SW3556-1096: Added BERR_TRACE in all return cases for easier error
41 * tracking and added unknown
42 *
43 * Hydra_Software_Devel/66   3/31/10 10:32a jerrylim
44 * SW3548-2828: Added a new 3D format - 2160i48
45 *
46 * Hydra_Software_Devel/65   1/29/10 4:52p jerrylim
47 * SW3548-2744: Add 3D RTS support to config 2
48 *
49 * Hydra_Software_Devel/64   1/27/10 11:06a jerrylim
50 * SW3548-2726: Set clipping max to real maximu so the first comparison
51 * can be alwasys passed. And messages added in PIP display search
52 * function for easier debugging
53 *
54 * Hydra_Software_Devel/63   1/19/10 8:34p jerrylim
55 * SW3548-2726: Added 3D support to config 14. The changes were made based
56 * on 3548_Usage_Modes.xls Rev.2.74
57 *
58 * Hydra_Software_Devel/62   1/8/10 4:43p jerrylim
59 * SW3556-968, SW3548-2683: Added one more buffer to config 14 to support
60 * 50Hz <-> 60Hz. Disabled MNR/BNR for the secondary window in config 11.
61 * # of lines of 3D signal changed to 2205. The changes are based on
62 * 3548_Usage_Modes.xls Rev.2.69 8-Jan-10
63 *
64 * Hydra_Software_Devel/61   12/24/09 3:08p jerrylim
65 * SW3548-2683: Changed cropping size to 36% in FULL.8 and recalculated
66 * PBP mode. The changes were maded based on 3548_Usage_Modes.xls
67 * Rev.2.65 2009.12.24
68 *
69 * Hydra_Software_Devel/60   12/18/09 6:47p jerrylim
70 * SW3556-933: added 1440x480p@60 to BVDB_GetInputFormatGroup()
71 *
72 * Hydra_Software_Devel/59   12/16/09 5:36p jerrylim
73 * SW3548-2668: bpb will be changed to support none/pbp/pip modes, and
74 * this is a temporary change in order not to break the  build
75 *
76 * Hydra_Software_Devel/58   12/14/09 6:52p jerrylim
77 * SW3556-915: The purpose of havging PC groups in VDB is not to indicate
78 * support PC formats, but to do format grouping so RTS settings can be
79 * applied to a proper group. VDB function should not block other modules
80 * by returning invalid format as long as its RTS settings can be found
81 *
82 * Hydra_Software_Devel/57   12/10/09 11:04a jerrylim
83 * SW3556-871: Video window rectangle setting is slow in MHEG
84 * certification -> A concept so called *cached usage modes* is
85 * introduced where it returns usage mode in the cached in case of cache
86 * hit
87 *
88 * Hydra_Software_Devel/56   11/2/09 12:45p jessem
89 * SW3548-2574: Corrected determination of pDisplayedAspectRatio when
90 * eAspectRatioCorrection is BVDB_AspectRatio_eAllSrc.
91 *
92 * Hydra_Software_Devel/55   10/9/09 10:59a jessem
93 * SW3556-821: Modified algorithm to find interlaced formats in
94 * BVDB_GetInputFormatGroup.
95 *
96 * Hydra_Software_Devel/54   10/1/09 1:56p jessem
97 * SW3548-2506, SW3556-818:
98 * 1. Added config 14 support (SW3548-2506).
99 * 2. Added WXGA and XGA support for config 7 (SW3556-818).
100 * 3. Added 1024x768_PC@60 and 1024x768_PC@85 input format groups.
101 * 4. Modified algorithm to search for progressive input formats in
102 * BVDB_GetInputFormatGroup.
103 *
104 * Hydra_Software_Devel/53   9/23/09 11:36a jessem
105 * SW3548-2497: Added additional support for certain DivX streams.
106 *
107 * Hydra_Software_Devel/52   9/22/09 6:13p jessem
108 * SW3548-2495: Added support for DivX formats.
109 *
110 * Hydra_Software_Devel/51   9/22/09 10:25a jessem
111 * SW3548-2491: Added missing break for 720p60 case in
112 * BDV_GetInputFormatGroup.
113 *
114 * Hydra_Software_Devel/50   9/21/09 2:31p jessem
115 * SW3548-2451, SW3548-2481: Removed checks for MFD input type for SD,
116 * 480p, 576p and 720p sources in BVDB_GetInputFormatGroup.
117 *
118 * Hydra_Software_Devel/49   9/11/09 2:58p jessem
119 * SW3548-2463, SW3548-2465:
120 * 1. Fixed algorithm for checking 4:3 and 16:9 sources as displayed in
121 * 4:3 or 16:9 panels.
122 * 2. Fixed FULL.12 check to include source's aspect ratio.
123 *
124 * Hydra_Software_Devel/48   9/3/09 3:39p jessem
125 * SW3548-2451: Modified BVDB_GetInputFormatGroup to handle MPEG streams
126 * with non-standard framerates. This is only limited to formats with
127 * dimensions less than 1280x720.
128 *
129 * Hydra_Software_Devel/47   8/28/09 6:44p jessem
130 * SW3548-2378: Changed BDBG_ERR to BDBG_MSG in BVDB_GetVideoDisplayMode
131 *
132 * Hydra_Software_Devel/46   8/28/09 3:59p jessem
133 * SW3548-2378: Added check to validate clip amount for dot-by-dot mode in
134 * BVDB_GetVideoDisplayMode.
135 *
136 * Hydra_Software_Devel/45   8/27/09 3:41p jessem
137 * SW3548-2419:
138 * 1. Added config 13 support.
139 * 2. Added RTS tables 241 to 255 for config 13 support.
140 * 3. Added bJpeg parameter to BVDB_GetInputFormatGroup.
141 * 4. Added BVDB_InputFormatGroup_eJpeg_540 and replaced
142 * BVDB_InputFormatGroup_eJpeg with BVDB_InputFormatGroup_eJpeg_1080.
143 * 5. Added  BVDB_Osd_e960_540p_32bpp.
144 *
145 * Hydra_Software_Devel/44   8/25/09 5:30p jessem
146 * SW3548-2374: Fixed comparison of full mode clip amount limits against
147 * user clip amounts.
148 *
149 * Hydra_Software_Devel/43   8/17/09 10:44a jessem
150 * PR 57390: Corrected checks for minimum and maximum FULL window sizes in
151 * BVDB_GetVideoDisplayMode.
152 *
153 * Hydra_Software_Devel/42   8/12/09 5:45p jessem
154 * PR 57101, PR 57604: Updated config 9 RTS and usage modes.
155 *
156 * Hydra_Software_Devel/41   8/5/09 5:57p jessem
157 * PR 57391, PR 57392:
158 * 1. Added 1920x1080 PC @ 60 Group. Renamed 1024x768_PC@60 Group to
159 * 1366x768_PC@60 Group , 1280x768_PC@85 Group to 1366x768_PC@85 Group.
160 * Added 1920x1080_PC@60 usage mdoes to all configurations (57391).
161 * 2.  Removed and modified certain invalid PC formats (57392).
162 *
163 * Hydra_Software_Devel/40   7/28/09 2:28p jessem
164 * PR 57101: Modified logic to check display modes for FULL and PIG modes
165 * in BVDB_GetVideoDisplayMode.
166 *
167 * Hydra_Software_Devel/39   7/21/09 4:33p jessem
168 * PR 52453, PR 55504, PR 56585:
169 * 1. Modified config 10's RTS, tolerance and bias for 480i/576i usage
170 * modes to use CAP-SCL orientation for all main window modes and inputs.
171 * 2. Separated FULL.7 from usage modes that have this as part of all FULL
172 * display modes. This applies to configs 1, 2, 3, 6, 7, 10, 11, 12.
173 * 3. Recategorized formats with H and W that are less than or equal to
174 * 1366x768 to either 1024x768 PC @ 60 Group or 1280x768 PC @ 85 Group.
175 * 4. Added OSD support for monitor modes in config 3 (PR 56585).
176 *
177 * Hydra_Software_Devel/38   7/14/09 2:39p jessem
178 * PR 56794: Changed BVDB_Handle to BVDB_P_Context in BVDB_CreateVdb.
179 *
180 * Hydra_Software_Devel/37   5/27/09 11:07a jessem
181 * PR 52226: Modified conditionals for BVDB_InputFormatGroup_e1280_768_PC
182 * and BVDB_InputFormatGroup_e1400_1050_75_PC in
183 * BVDB_GetInputFormatGroup().
184 *
185 * Hydra_Software_Devel/36   4/27/09 11:17a jessem
186 * PR 51743: Added bPbp parameter to BVDB_GetVideoDisplayMode to
187 * distinguish Main PBP from Main PIG use. RTS needs to distinguish
188 * between Main PBP and Main PIG. See DTV_Questionnaire.xls PIP.2 mode.
189 *
190 * Hydra_Software_Devel/35   4/24/09 2:06p jessem
191 * PR 51709, PR 53506, PR 54578:
192 * 1. Modified Config 9 support and associated RTS tables. Added RTS 177
193 * to 180 (51709).
194 * 2. Added config 10 support and RTS tables 201 to 215 (53506).
195 * 3. Added struct BVDB_OsdInfo and replaced BVDB_eOsd field in
196 * BVDB_UsageMode with this new struct to accommodate ulReserved values
197 * for OSD(51709 and 53506).
198 * 4. Modified BVDB_VideoGetDisplayMode to handle unknown
199 * BFMT_AspectRatio_eUnknown (54578).
200 *
201 * Hydra_Software_Devel/34   4/21/09 4:46p jessem
202 * PR 51743: Added correct conditional for FULL vs PIG modes in
203 * BVDB_GetVideoDisplayMode.
204 *
205 * Hydra_Software_Devel/33   4/14/09 3:58p jessem
206 * PR 51743: Removed goto dones. Check of pstTempMode is non-NULL before
207 * freeing.
208 *
209 * Hydra_Software_Devel/32   4/13/09 3:38p jessem
210 * PR 51743: Modified  BVDB_GetDisplaySrcAs and BVDB_GetVideoDisplayModes
211 * to handle source aspect ratio and aspect ratio correction.
212 *
213 * Hydra_Software_Devel/31   4/7/09 10:37a jessem
214 * PR 53682: Added stringent check for MPEG formats in
215 * BVDB_GetInputFormatGroup.
216 *
217 * Hydra_Software_Devel/30   4/6/09 3:15p jessem
218 * PR 53902: Modified BVDB_GetInputFormatGroup to ignore frame rate of
219 * ATSC/SMPTE formats when input is MFD.
220 *
221 * Hydra_Software_Devel/29   4/3/09 3:50p jessem
222 * PR 53783: Moved BVDB_P_MAX/MIN macro to bvdc_priv.h.
223 *
224 * Hydra_Software_Devel/28   4/2/09 4:21p pntruong
225 * PR53783: VDB: Unable to look up MFD 1920x1088i source.
226 *
227 * Hydra_Software_Devel/27   3/30/09 2:53p jessem
228 * PR 53682: Added lookup for 1080p24/25/30 in BVDB_GetInputFormatGroup.
229 * Also added helper macro to determine if a given value is within
230 * tolerance of nominal.
231 *
232 * Hydra_Software_Devel/26   3/30/09 11:32a jessem
233 * PR 53682: Added check for HDDVI input in BVDB_GetInputFormatGroup.
234 *
235 * Hydra_Software_Devel/25   3/27/09 11:33a jessem
236 * PR 52818: Corrected conditional checks for NTSC and PAL input format
237 * groups.
238 *
239 * Hydra_Software_Devel/24   3/24/09 5:48p jessem
240 * PR 53388: Added BFMT_AspectRatio param to BVDB_GetInputFormatGroup.
241 *
242 * Hydra_Software_Devel/23   3/24/09 3:35p jessem
243 * PR 53388: Changed implementation of BVDB_GetInputFormatGroup.
244 *
245 * Hydra_Software_Devel/22   3/19/09 3:39p jessem
246 * PR 53388: Modified BVDB_GetInputFormatGroup()'s parameter list and
247 * implementation.
248 *
249 * Hydra_Software_Devel/21   3/18/09 11:27p jessem
250 * PR 53395: Added BFMT_VideoFmt_eDVI_848x480p_60Hz and
251 * BFMT_VideoFmt_eDVI_1064x600p_60Hz to BVDB_GetInputFormatGroup.
252 *
253 * Hydra_Software_Devel/20   3/16/09 2:24p jessem
254 * PR 53008, PR 53261:
255 * 1. Made condition to check for dot-by-dot stricter (53008).
256 * 2. Made condition to check for full mode to include checking the
257 * requested window size against the minimum and maximum size allowed.
258 *
259 * Hydra_Software_Devel/19   3/12/09 2:36p jessem
260 * PR 52226: Reclassified BFMT_VideoFmt_eDVI_1280x768p_Red and
261 * BFMT_VideoFmt_eDVI_1400x1050p_60Hz_Red  to
262 * BVDB_InputFormatGroup_e1400_1050_75_PC.
263 *
264 * Hydra_Software_Devel/18   3/9/09 7:32p jessem
265 * PR 52940: Fixed incorrect array dereference in
266 * BVDB_GetMemoryAllocation.
267 *
268 * Hydra_Software_Devel/17   3/6/09 4:14p jessem
269 * PR 52520: Added BVDB_Input parameter to BVDB_GetVideoDisplayMode to
270 * handle monitor out cases.  Corrected ulMinWinHeight field for all
271 * monitor modes for all configs in astConfigVideoDispModeInfo.
272 *
273 * Hydra_Software_Devel/16   3/4/09 5:52p jessem
274 * PR 52520: Fixed determination of error condition when no display modes
275 * are found. Added placeholder for config 7 in
276 * astConfigVideoDispModeInfo array.
277 *
278 * Hydra_Software_Devel/15   3/4/09 11:55a jessem
279 * PR 52568: Removed support for custom format 1340x725p@60hz.
280 *
281 * Hydra_Software_Devel/14   3/3/09 4:14p jessem
282 * PR 52568, PR 51472, PR 52520:
283 * 1. Added support for custom format 1340x725p@60hz (52568). 2. Added
284 * suuport for modified config 2 RTS to eliminate CAP compression support
285 * and increase compression level for MAD for 1080psf and 1080i MFD PIG
286 * usage modes ( 51472).
287 * 3. Added error return value if video display mode is not found (52520).
288 *
289 * Hydra_Software_Devel/13   2/25/09 5:45p jessem
290 * PR 46299, PR  52479, PR 52520: Added PAL B, B1, D, D1, G, H, I, K.
291 * Added BFMT_VideoFmt_eDVI_1280x768p_Red.  Added
292 * BVDB_GetVideoDisplayMode.
293 *
294 * Hydra_Software_Devel/12   2/20/09 4:16p jessem
295 * PR 51709: Added config 9 support. Removed BVDB_GetNumberOfConfigs and
296 * replaced it wth BVDB_ValidateConfigId. Removed BVDB_Handle parameter
297 * from BVDB_GetMemoryAllocation. Added RTS 161 to 177.
298 *
299 * Hydra_Software_Devel/11   2/18/09 11:47a jessem
300 * PR 51848: Removed references to VDC. Removed global access to config
301 * info. Added helper functions to access these instead.
302 *
303 * Hydra_Software_Devel/10   2/17/09 6:49p jessem
304 * PR 50031, PR 51848: Added config 8. Added BVDB_GetNumberOfConfigs() and
305 * BVDB_GetMemoryAllocation() functions to VDB API and support for these
306 * new functions.
307 *
308 * Hydra_Software_Devel/9   1/14/09 2:39p jessem
309 * PR 51109: Allocated correct size for acStr.
310 *
311 * Hydra_Software_Devel/8   1/5/09 12:37p jessem
312 * PR 50327: Added features to config 3.
313 *
314 * Hydra_Software_Devel/7   12/9/08 3:58p jessem
315 * PR 49051, PR 46591, PR 48974, PR 49929, PR 49870, PR 49932: Added
316 * support for dot-by-dot in configs 1 and 2. Added config for 1066Mhz
317 * x16 (demo). Added config 6. Added features to config 1 and 2.
318 *
319 * Hydra_Software_Devel/6   11/20/08 5:01p jessem
320 * PR49373, PR49374, PR49375, PR49388, PR 49402, PR 49403, PR 49404, PR
321 * 49406, PR49427, PR49428, PR49429, PR49431, PR49432, PR49433, PR49434,
322 * PR49435, PR49435, PR49436, PR49437, PR49438, PR49440: Updated PR list
323 * in checkin comments.
324 *
325 * Hydra_Software_Devel/5   11/19/08 5:55p jessem
326 * PR49373, PR49374, PR49375, PR49388, PR 49402, PR 49403, PR 49404, PR 49406,
327 * PR49427, PR49428, PR49429, PR49431, PR49432, PR49433, PR49434, PR49435,
328 * PR49435, PR49436, PR49437, PR49438, PR49440: Fixed strcpy and strcat Coverity
329 * issues.
330 *
331 * Hydra_Software_Devel/4   11/13/08 7:05p jessem
332 * PR 48588: Added config 4 for 1080p/1080i/720p switchable output format.
333 *
334 * Hydra_Software_Devel/3   10/21/08 11:00a jessem
335 * PR 46299: Split BVDB_InputFormatGroup_e1400_1050_PC to
336 * BVDB_InputFormatGroup_e1400_1050_75_PC and
337 * BVDB_InputFormatGroup_e1400_1050_60_PC.
338 *
339 * Hydra_Software_Devel/2   10/17/08 2:53p jessem
340 * PR 46299: Replaced old A0 config support with 800MHZ WXGA and 1080P
341 * configs support.
342 *
343 * Hydra_Software_Devel/1   10/2/08 3:48p jessem
344 * PR 46299: Initial version
345 *
346 ***************************************************************************/
347#include <stdio.h>
348#include <stdlib.h>
349#include <string.h>
350#include "bstd.h"
351#include "berr.h"
352#include "bkni.h"
353#include "bfmt.h"
354#include "blst_circleq.h"
355#include "bdbg.h"
356
357#include "bvdb.h"
358#include "bvdb_priv.h"
359#include "bvdb_viddispmode_priv.h"
360
361BDBG_MODULE(BVDB);
362
363
364/* In case a matched input format is not found, then it tries search this table
365 * if there's any match. This table is a collection of formats which cannot be
366 * grouped using the standard decision making process. The input format group
367 * used in this table is based on the RTS analysis tool. Note that this table
368 * contains non-PC formats only
369 *
370 *                     ********** NOTE **********
371 * Each group of sources must be in the order from low to high frame rate where
372 * a group means sources which have same width, height and progressiveness */
373static BVDB_P_NonPcNonStandardFomat stNonPcNonStandardFormats[] =
374{
375    /* EIA/CEA-861-B (aslo in HDMI) 1440x480p without pixel repetition */
376    {1440,  480, true, 60000, false, BVDB_InputFormatGroup_e720p_60},
377
378    /* HDMI1.4 3D Video VIC 32 */
379    {1920, 2205, true, 23976, true, BVDB_InputFormatGroup_e1080p3d_24},
380    {1920, 2205, true, 24000, true, BVDB_InputFormatGroup_e1080p3d_24},
381
382    /* HDMI1.4 3D Video VIC 34 */
383    {1920, 2205, true, 30000, true, BVDB_InputFormatGroup_e1080p3d_30},
384
385    /* HDMI1.4 3D Video VIC 19 */
386    {1280, 1470, true, 50000, true, BVDB_InputFormatGroup_e720p3d_50},
387
388    /* HDMI1.4 3D Video VIC 4 */
389    {1280, 1470, true, 59940, true, BVDB_InputFormatGroup_e720p3d_60},
390    {1280, 1470, true, 60000, true, BVDB_InputFormatGroup_e720p3d_60},
391
392    /* wireless 3D Video 2160i48 */
393    {1920, 2160, false, 47952, true, BVDB_InputFormatGroup_e1080p3d_24},
394    {1920, 2160, false, 48000, true, BVDB_InputFormatGroup_e1080p3d_24},
395};
396
397/* Public Functions */
398BERR_Code BVDB_CreateVdb
399    ( BVDB_Handle            *phVdb,
400      uint32_t               *pulEntries)
401{
402    BERR_Code err = BERR_SUCCESS;
403    BVDB_P_Context *pVdb;
404    BVDB_UsageMode *pstVdbEntries;
405    uint32_t i, ulVdbTableSize;
406
407    /* create head */
408    pVdb = (BVDB_P_Context *)BKNI_Malloc(sizeof(BVDB_P_Context));
409    if (pVdb == NULL)
410    {
411        BDBG_ERR(("Out of memory"));
412        return BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);
413    }
414
415    BLST_CQ_INIT(pVdb);
416
417    err = BVDB_P_GetVdbTableSize(&ulVdbTableSize);
418    if (err != BERR_SUCCESS)
419    {
420        return BERR_TRACE(err);
421    }
422
423    pstVdbEntries = (BVDB_UsageMode *)BKNI_Malloc(sizeof(BVDB_UsageMode) * ulVdbTableSize);
424    if (pstVdbEntries == NULL)
425    {
426        BDBG_ERR(("Out of memory."));
427        err = BERR_OUT_OF_SYSTEM_MEMORY;
428        return BERR_TRACE(err);
429    }
430
431    err = BVDB_P_GetVdbEntries(pstVdbEntries);
432    if (err != BERR_SUCCESS)
433    {
434        return BERR_TRACE(err);
435    }
436
437    for (i=0; i<ulVdbTableSize; i++)
438    {
439        BVDB_UsageMode *pUsageMode;
440
441        pUsageMode = (BVDB_UsageMode *)BKNI_Malloc(sizeof(BVDB_UsageMode));
442        if (pUsageMode == NULL)
443        {
444            do
445            {
446                pUsageMode = BLST_CQ_FIRST(pVdb);
447                BLST_CQ_REMOVE_HEAD(pVdb, link);
448                BKNI_Free(pUsageMode);
449            } while (!BLST_CQ_EMPTY(pVdb));
450
451            BKNI_Free(pVdb);
452            BDBG_ERR(("Out of memory"));
453            return BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);
454        }
455
456        /* copy from array to doubly-linked list */
457        BKNI_Memcpy((void *)pUsageMode, (void *)&pstVdbEntries[i], sizeof(BVDB_UsageMode));
458
459        BLST_CQ_INSERT_TAIL(pVdb, pUsageMode, link);
460    }
461
462    /* All done. now return the new fresh context to user. */
463    *phVdb = (BVDB_Handle)pVdb;
464    *pulEntries = ulVdbTableSize;
465
466    BKNI_Free(pstVdbEntries);
467
468    return BERR_TRACE(err);
469}
470
471BERR_Code BVDB_ValidateVdb
472    ( BVDB_Handle             hVdb,
473      uint32_t                     configId )
474{
475    BERR_Code        err = BERR_SUCCESS;
476    BVDB_P_Context  *pVdb;
477    BVDB_UsageMode  *pMode;
478
479    BVDB_P_GET_CONTEXT(hVdb, pVdb);
480
481    pMode = BLST_CQ_FIRST(pVdb);
482
483    if (0 == configId)
484    {
485        do
486        {
487            err |= BVDB_P_ValidateVdbEntry(pVdb, pMode);
488            pMode = BVDB_P_UsageMode_GetNextNode(pMode);
489        } while (pMode != BLST_CQ_FIRST(pVdb));
490    }
491    else
492    {
493        do
494        {
495            if (configId == BVDB_P_GetConfigId(pMode->acId))
496            {
497                err |= BVDB_P_ValidateVdbEntry(pVdb, pMode);
498            }
499            pMode = BVDB_P_UsageMode_GetNextNode(pMode);
500        } while (pMode != BLST_CQ_FIRST(pVdb));
501    }
502
503    return BERR_TRACE(err);
504}
505
506BERR_Code BVDB_DestroyVdb
507    ( BVDB_Handle             hVdb  )
508{
509    BVDB_UsageMode *pMode;
510    BVDB_P_Context *pVdb;
511
512    BVDB_P_GET_CONTEXT(hVdb, pVdb);
513
514    while (!BLST_CQ_EMPTY(pVdb))
515    {
516        pMode = BLST_CQ_FIRST(pVdb);
517        BLST_CQ_REMOVE_HEAD(pVdb, link);
518        BKNI_Free(pMode);
519    }
520
521    BKNI_Free((void*)pVdb);
522    pVdb = NULL;
523
524    return BERR_TRACE(BERR_SUCCESS);
525}
526
527
528BERR_Code BVDB_PrintUsageMode
529    ( const BVDB_UsageMode    *pstUsageMode )
530{
531    BERR_Code err = BERR_SUCCESS;
532    char acStr[BVDB_MAX_STRLEN+1];
533    char acStr1[BVDB_MAX_STRLEN+1];
534    char acStr2[BVDB_MAX_STRLEN+1];
535    BVDB_VideoDisplayMode stDispMode = pstUsageMode->stDisplayMode;
536
537    BDBG_ASSERT(pstUsageMode);
538
539    /* ID */
540    BDBG_P_PrintString("VDB ID: %s\n", pstUsageMode->acId);
541
542    /* Input format */
543    BVDB_P_GetInputStr(pstUsageMode->eInput, acStr);
544    BVDB_P_GetInputFormatGroupStr(pstUsageMode->eInputFormatGroup, acStr1);
545    BDBG_P_PrintString("\tInput type: %s, format: %s\n", acStr, acStr1);
546
547    /* Display */
548    BVDB_P_GetDisplayTypeStr(pstUsageMode->stDisplay.eType, acStr);
549    BVDB_P_GetOutputResolutionStr(pstUsageMode->stDisplay.eResolution, acStr1);
550    BVDB_P_GetAspectRatioStr(pstUsageMode->stDisplay.eAspectRatio, acStr2);
551    BDBG_P_PrintString("\tDisplay: %s, resolution: %s, aspect ratio: %s\n", acStr, acStr1, acStr2);
552
553    /* Window */
554    BVDB_P_GetWindowStr(pstUsageMode->eWindow, acStr);
555    BDBG_P_PrintString("\tWindow: %s\n", acStr);
556
557    /* display usage mode */
558    BVDB_P_GetVideoDisplayModeStr(&stDispMode, acStr);
559    BDBG_P_PrintString("\tVideo Display Usage Mode: %s\n", acStr);
560
561    /* OSD size */
562    BDBG_P_PrintString("\tOSD: %dx%d@%dbpp (reserved %d)\n",
563                                    pstUsageMode->stOsd.ulWidth, pstUsageMode->stOsd.ulHeight, pstUsageMode->stOsd.ulBitsPerPixel,
564                                    pstUsageMode->stOsd.ulReserved);
565
566    /* 3D comb */
567    BVDB_P_GetStateStr(pstUsageMode->e3dComb, acStr);
568    BDBG_P_PrintString("\t3D Comb: %s\n", acStr);
569
570    /* oversample */
571    BVDB_P_GetStateStr(pstUsageMode->eOversample, acStr);
572    BDBG_P_PrintString("\tOversample: %s\n", acStr);
573
574    BVDB_P_GetStateStr(pstUsageMode->eMnrBnr, acStr);
575    BVDB_P_GetStateStr(pstUsageMode->eDcr, acStr1);
576    BVDB_P_GetPixelFormatStr(pstUsageMode->stAnr.ePixelFormat, pstUsageMode->stAnr.eState, acStr2);
577    BDBG_P_PrintString("\tMNR/BNR: %s, DCR %s, ANR: %s (reserved %d)\n", acStr, acStr1, acStr2, pstUsageMode->stAnr.ulReserved);
578
579    /* CAP/VFD */
580    BVDB_P_GetPixelFormatStr(pstUsageMode->stCapVfd.ePixelFormat, pstUsageMode->stCapVfd.eState, acStr);
581    BDBG_P_PrintString("\tCAP/VFD: %s (reserved %d)\n", acStr, pstUsageMode->stCapVfd.ulReserved);
582
583    /* MAD */
584    BVDB_P_GetPixelFormatStr(pstUsageMode->stMad.ePixelFormat, pstUsageMode->stMad.eState, acStr);
585    if (pstUsageMode->stMad.eState == BVDB_State_eYes)
586    {
587        char acTemp[BVDB_MAX_STRLEN];
588
589        BVDB_P_GetFieldStoreCntStr(pstUsageMode->stMad.eFieldStore, acTemp);
590        BVDB_P_STRCAT(acTemp, "\t");
591        BVDB_P_STRCAT(acTemp, acStr);
592        BVDB_P_STRCPY(acStr, acTemp);
593    }
594    else
595    {
596        if (pstUsageMode->stMad.ePixelFormat == BVDB_PixelFmt_eInvalid)
597            BVDB_P_STRCAT(acStr, "\tn/a");
598        else
599            BVDB_P_STRCPY(acStr, "\tno");
600    }
601    BDBG_P_PrintString("\tMAD: %s (reserved %d)\n", acStr, pstUsageMode->stMad.ulReserved);
602
603    /* RTS */
604    BVDB_P_GetRtsSetStr(pstUsageMode->eRtsSet, acStr);
605    BDBG_P_PrintString("\tRTS: %s\n", acStr);
606
607    /* SCL-CAP tolerance and bias */
608    BVDB_P_GetSclCapBiasStr(pstUsageMode->eSclCapBias, acStr);
609    BDBG_P_PrintString("\tSCL-CAP tolerance: %d, bias: %s\n", pstUsageMode->ulSclCapTolerance, acStr);
610
611    return BERR_TRACE(err);
612}
613
614BERR_Code BVDB_PrintVdb
615    ( BVDB_Handle             hVdb )
616{
617    BVDB_UsageMode *pstTemp;
618    BVDB_P_Context *pVdb;
619
620    BVDB_P_GET_CONTEXT(hVdb, pVdb);
621
622    pstTemp = BLST_CQ_FIRST(pVdb);
623
624    do
625    {
626        BVDB_PrintUsageMode(pstTemp);
627        pstTemp = BVDB_P_UsageMode_GetNextNode(pstTemp);
628    } while(pstTemp != BLST_CQ_FIRST(pVdb));
629
630    return BERR_TRACE(BERR_SUCCESS);
631}
632
633
634BERR_Code BVDB_GetInputFormatGroup
635    ( const BVDB_Handle                  hVdb,
636      const uint32_t                     ulHeight,
637      const uint32_t                     ulWidth,
638      const uint32_t                     ulFrameRate,
639      const bool                         bProgressive,
640      const bool                         bJpeg,
641      const BVDB_Input                   eInput,
642      BVDB_InputFormatGroup             *peInputFormatGroup )
643{
644    BERR_Code                err = BERR_SUCCESS;
645    BVDB_P_Context          *pVdb;
646    uint32_t                 ulTempHeight = ulHeight;
647    BVDB_InputFormatGroup    eNonPcInputFormatGroup;
648
649    BVDB_P_GET_CONTEXT(hVdb, pVdb);
650
651    *peInputFormatGroup    = BVDB_InputFormatGroup_eInvalid;
652    eNonPcInputFormatGroup = BVDB_InputFormatGroup_eInvalid;
653
654    if(BVDB_Input_eMfd == eInput)
655    {
656        ulTempHeight = BVDB_P_MIN(ulHeight, BFMT_1080I_HEIGHT);
657    }
658
659    if (bJpeg)
660    {
661        *peInputFormatGroup = (ulTempHeight <= BFMT_1080I_HEIGHT/2) ?
662            BVDB_InputFormatGroup_eJpeg_540 : BVDB_InputFormatGroup_eJpeg_1080;
663    }
664    else
665    {
666        /* Let's see if we have a match in the non-standard format list. This list
667         * grows on-demand basis. Note that frame rates are compared for a match
668         * using "range". In case we haven't found a match using the standard
669         * way, they we'll use this match if there's a match here */
670        if (*peInputFormatGroup == BVDB_InputFormatGroup_eInvalid)
671        {
672            /* For non-PC formats */
673            if (eInput != BVDB_Input_eVga)
674            {
675                uint32_t i;
676                uint32_t numEntry;
677
678                numEntry = sizeof(stNonPcNonStandardFormats) / sizeof(BVDB_P_NonPcNonStandardFomat);
679                for (i = 0; i < numEntry; i++)
680                {
681                    if ((ulHeight == stNonPcNonStandardFormats[i].height) &&
682                        (ulWidth == stNonPcNonStandardFormats[i].width) &&
683                        (bProgressive == stNonPcNonStandardFormats[i].bProgressive) &&
684                        (ulFrameRate <= stNonPcNonStandardFormats[i].frameRate))
685                    {
686                        eNonPcInputFormatGroup = stNonPcNonStandardFormats[i].eInputFormatGroup;
687
688                        /* Now we have a match in the non-standard format array.
689                         * If the matched format is a 3D source, return right
690                         * away because the following search does not consider
691                         * the 3D sources */
692                        if (stNonPcNonStandardFormats[i].b3dSource &&
693                            (eInput == BVDB_Input_eHdDvi))
694                        {
695                            * peInputFormatGroup = eNonPcInputFormatGroup;
696                            return BERR_TRACE(BERR_SUCCESS);
697                        }
698                        break;
699                    }
700                }
701            }
702        }
703
704        if (!bProgressive)
705        {
706            /* the only interlaced VESA format! */
707            if ((ulWidth == 1024 && ulTempHeight == 768 &&
708                (eInput == BVDB_Input_eVga || eInput == BVDB_Input_eHdDvi) &&
709                 ulFrameRate == 86958) &&
710                *peInputFormatGroup == BVDB_InputFormatGroup_eInvalid)
711            {
712                *peInputFormatGroup = BVDB_InputFormatGroup_e1366_768_85_PC;
713            }
714
715            if (((ulFrameRate >= 59940 && ulFrameRate <= 60000) ||
716                 (ulFrameRate >= 23976 && ulFrameRate <= 24000) ||
717                 (ulFrameRate >= 29970 && ulFrameRate <= 30000)) &&
718                *peInputFormatGroup == BVDB_InputFormatGroup_eInvalid)
719            {
720                if (ulTempHeight <= BFMT_NTSC_HEIGHT)
721                {
722                    if (ulWidth <= 544)
723                    {
724                        *peInputFormatGroup = BVDB_InputFormatGroup_e544_480i_60;
725                    }
726                    else if (ulWidth <= BFMT_NTSC_WIDTH)
727                    {
728                        *peInputFormatGroup =  BVDB_InputFormatGroup_eNtsc;
729                    }
730                }
731
732                if (ulTempHeight <= BFMT_PAL_HEIGHT && ulWidth <= BFMT_PAL_WIDTH &&
733                    *peInputFormatGroup == BVDB_InputFormatGroup_eInvalid)
734                {
735                    *peInputFormatGroup = BVDB_InputFormatGroup_ePal_60;
736                }
737
738                if (ulTempHeight <= BFMT_1080I_HEIGHT && *peInputFormatGroup == BVDB_InputFormatGroup_eInvalid)
739                {
740                    if (ulWidth <= 1440)
741                    {
742                        *peInputFormatGroup = BVDB_InputFormatGroup_e1440_1080i_60;
743                    }
744                    else if (ulWidth <= BFMT_1080I_WIDTH)
745                    {
746                        *peInputFormatGroup = BVDB_InputFormatGroup_e1080i_60;
747                    }
748                }
749            }
750
751            if ((ulFrameRate == 50000 || ulFrameRate == 25000) &&
752                *peInputFormatGroup == BVDB_InputFormatGroup_eInvalid)
753            {
754                if (ulTempHeight <= BFMT_PAL_HEIGHT)
755                {
756                    if (ulWidth <= 544)
757                    {
758                        *peInputFormatGroup = BVDB_InputFormatGroup_e544_576i_50;
759                    }
760                    else if (ulWidth <= BFMT_PAL_WIDTH)
761                    {
762                        *peInputFormatGroup = BVDB_InputFormatGroup_ePal;
763                    }
764                }
765
766                if (ulTempHeight <= BFMT_1080I_HEIGHT && *peInputFormatGroup == BVDB_InputFormatGroup_eInvalid)
767                {
768                    if (ulWidth <= 1440)
769                    {
770                        *peInputFormatGroup = BVDB_InputFormatGroup_e1440_1080i_50;
771                    }
772                    else if (ulWidth <= BFMT_1080I_WIDTH)
773                    {
774                        *peInputFormatGroup = BVDB_InputFormatGroup_e1080i_50;
775                    }
776                }
777            }
778
779            /* In case there's no match, use the non standard match if any */
780            if (*peInputFormatGroup == BVDB_InputFormatGroup_eInvalid)
781            {
782                *peInputFormatGroup = eNonPcInputFormatGroup;
783            }
784        }
785        else
786        {
787            if (ulFrameRate >= 59934 && ulFrameRate <= 60000 &&
788                *peInputFormatGroup == BVDB_InputFormatGroup_eInvalid)
789            {
790                if (ulWidth <= BFMT_480P_WIDTH && ulTempHeight <= BFMT_480P_HEIGHT)
791                {
792                    *peInputFormatGroup = BVDB_InputFormatGroup_e480p;
793                }
794                else if (ulWidth <= BFMT_720P_WIDTH && ulTempHeight <= BFMT_720P_HEIGHT)
795                {
796                    *peInputFormatGroup = BVDB_InputFormatGroup_e720p_60;
797                }
798                else if (ulTempHeight == BFMT_1080P_HEIGHT && ulWidth == BFMT_1080P_WIDTH)
799                {
800                    *peInputFormatGroup = (eInput != BVDB_Input_eVga) ? BVDB_InputFormatGroup_e1080p_60 :
801                            BVDB_InputFormatGroup_e1920_1080_60_PC;
802                }
803                else if (ulTempHeight <= BFMT_1080P_HEIGHT && ulWidth < BFMT_1080P_WIDTH &&
804                        eInput == BVDB_Input_eMfd)
805                {
806                    *peInputFormatGroup = BVDB_InputFormatGroup_e1440_1080p_30;
807                }
808            }
809
810            if (ulFrameRate == 50000 &&
811                *peInputFormatGroup == BVDB_InputFormatGroup_eInvalid)
812            {
813                if (ulWidth <= BFMT_576P_WIDTH && ulTempHeight <= BFMT_576P_HEIGHT)
814                {
815                    *peInputFormatGroup = BVDB_InputFormatGroup_e576p;
816                }
817                else if (ulWidth <= BFMT_720P_WIDTH && ulTempHeight <= BFMT_720P_HEIGHT)
818                {
819                    *peInputFormatGroup = BVDB_InputFormatGroup_e720p_50;
820                }
821                else if (ulTempHeight == BFMT_1080P_HEIGHT && ulWidth == BFMT_1080P_WIDTH)
822                {
823                    *peInputFormatGroup = BVDB_InputFormatGroup_e1080p_50;
824                }
825                else if (ulTempHeight <= BFMT_1080P_HEIGHT && ulWidth < BFMT_1080P_WIDTH &&
826                        eInput == BVDB_Input_eMfd)
827                {
828                    *peInputFormatGroup = BVDB_InputFormatGroup_e1440_1080p_25;
829                }
830            }
831
832            if ((ulFrameRate == 23976 || ulFrameRate == 24000) &&
833                *peInputFormatGroup == BVDB_InputFormatGroup_eInvalid)
834            {
835                if (ulWidth <= BFMT_720P_WIDTH && ulTempHeight <= BFMT_720P_HEIGHT)
836                {
837                    *peInputFormatGroup = BVDB_InputFormatGroup_e720p_24;
838                }
839                else if (ulTempHeight == BFMT_1080P_HEIGHT)
840                {
841                    if (ulWidth == BFMT_1080P_WIDTH)
842                    {
843                        *peInputFormatGroup = BVDB_InputFormatGroup_e1080p_24;
844                    }
845                    else if (ulWidth < BFMT_1080P_WIDTH)
846                    {
847                        *peInputFormatGroup = BVDB_InputFormatGroup_e1440_1080p_24;
848                    }
849                }
850                else if (ulTempHeight <= BFMT_1080P_HEIGHT && ulWidth < BFMT_1080P_WIDTH &&
851                        eInput == BVDB_Input_eMfd)
852                {
853                    *peInputFormatGroup = BVDB_InputFormatGroup_e1440_1080p_24;
854                }
855            }
856
857            if (ulFrameRate == 25000 &&
858                *peInputFormatGroup == BVDB_InputFormatGroup_eInvalid)
859            {
860                if (ulWidth <= BFMT_720P_WIDTH && ulTempHeight <= BFMT_720P_HEIGHT)
861                {
862                    *peInputFormatGroup = BVDB_InputFormatGroup_e720p_25;
863                }
864                else if (ulTempHeight == BFMT_1080P_HEIGHT)
865                {
866                    if (ulWidth == BFMT_1080P_WIDTH)
867                    {
868                        *peInputFormatGroup = BVDB_InputFormatGroup_e1080p_25;
869                    }
870                    else if (ulWidth < BFMT_1080P_WIDTH)
871                    {
872                        *peInputFormatGroup = BVDB_InputFormatGroup_e1440_1080p_25;
873                    }
874                }
875                else if (ulTempHeight <= BFMT_1080P_HEIGHT && ulWidth < BFMT_1080P_WIDTH &&
876                        eInput == BVDB_Input_eMfd)
877                {
878                    *peInputFormatGroup = BVDB_InputFormatGroup_e1440_1080p_25;
879                }
880            }
881
882            if ((ulFrameRate == 29970 || ulFrameRate == 30000) &&
883                *peInputFormatGroup == BVDB_InputFormatGroup_eInvalid)
884            {
885                if (ulWidth <= BFMT_720P_WIDTH && ulTempHeight <= BFMT_720P_HEIGHT)
886                {
887                    *peInputFormatGroup = BVDB_InputFormatGroup_e720p_30;
888                }
889                else if (ulTempHeight == BFMT_1080P_HEIGHT)
890                {
891                    if (ulWidth == BFMT_1080P_WIDTH)
892                    {
893                        *peInputFormatGroup = BVDB_InputFormatGroup_e1080p_30;
894                    }
895                    else if (ulWidth < BFMT_1080P_WIDTH)
896                    {
897                        *peInputFormatGroup = BVDB_InputFormatGroup_e1440_1080p_30;
898                    }
899                }
900                else if (ulTempHeight <= BFMT_1080P_HEIGHT && ulWidth < BFMT_1080P_WIDTH &&
901                        eInput == BVDB_Input_eMfd)
902                {
903                    *peInputFormatGroup = BVDB_InputFormatGroup_e1440_1080p_30;
904                }
905            }
906
907            /* In case there's no match, use the non standard match if any */
908            if (*peInputFormatGroup == BVDB_InputFormatGroup_eInvalid)
909            {
910                *peInputFormatGroup = eNonPcInputFormatGroup;
911            }
912
913            /* The purpose here is not to tell where the input PC format is
914             * supported or not. The purpose is to pick a PC group so a proper
915             * RTS settings can be applied. Currently, RTS analysis
916             * differentiates PC input whether its numbers of line are greater
917             * than 700. We try to find the PC group more accurately, and if not
918             * found, then the PC ground is picked based on number of lines.
919             * There is not reason to block other modules by returning the
920             * invalid format as long as the RTS settings cover it. */
921            if (*peInputFormatGroup == BVDB_InputFormatGroup_eInvalid)
922            {
923                if (ulFrameRate <= 60000 + ((60000 * 1)/10)/100)
924                {
925                    if (ulWidth <= 1024 && ulTempHeight <= 768)
926                    {
927                        *peInputFormatGroup = BVDB_InputFormatGroup_e1024_768_60_PC;
928                    }
929                    else if (ulWidth <= 1366 && ulTempHeight <= 768)
930                    {
931                        *peInputFormatGroup = BVDB_InputFormatGroup_e1366_768_60_PC;
932                    }
933                    else if (ulWidth >= 1280 && ulTempHeight >= 960 &&
934                            ulWidth <= 1400 && ulTempHeight <= 1050)
935                    {
936                        *peInputFormatGroup = BVDB_InputFormatGroup_e1400_1050_60_PC;
937                    }
938                    else if (ulWidth == 1920 && ulTempHeight == 1080)
939                    {
940                        *peInputFormatGroup = BVDB_InputFormatGroup_e1920_1080_60_PC;
941                    }
942                    else if (ulWidth == 1600 && ulTempHeight == 1200)
943                    {
944                        *peInputFormatGroup = BVDB_InputFormatGroup_e1600_1200_60_PC;
945                    }
946
947                    /* accurate search failed. Pick a group based on # of lines */
948                    if (ulTempHeight <=768)
949                    {
950                        *peInputFormatGroup = BVDB_InputFormatGroup_e1024_768_60_PC;
951                    }
952                    else if (ulTempHeight <= 1050)
953                    {
954                        *peInputFormatGroup = BVDB_InputFormatGroup_e1400_1050_60_PC;
955                    }
956                    else if (ulTempHeight <= 1080)
957                    {
958                        *peInputFormatGroup = BVDB_InputFormatGroup_e1920_1080_60_PC;
959                    }
960                    else if (ulTempHeight <= 1200)
961                    {
962                        *peInputFormatGroup = BVDB_InputFormatGroup_e1600_1200_60_PC;
963                    }
964                }
965                else /* odd rates */
966                {
967                    if (ulWidth <= 1024 && ulTempHeight <= 768)
968                    {
969                        *peInputFormatGroup = BVDB_InputFormatGroup_e1024_768_85_PC;
970                    }
971                    else if (ulWidth <= 1366 && ulTempHeight <= 768)
972                    {
973                        *peInputFormatGroup = BVDB_InputFormatGroup_e1366_768_85_PC;
974                    }
975                    else if (ulWidth >= 1152 && ulTempHeight >= 864 &&
976                             ulWidth <= 1400 && ulTempHeight <= 1050)
977                    {
978                        *peInputFormatGroup = BVDB_InputFormatGroup_e1400_1050_75_PC;
979                    }
980
981                    /* accurate search failed. Pick a group based on # of lines */
982                    if (ulTempHeight <=768)
983                    {
984                        *peInputFormatGroup = BVDB_InputFormatGroup_e1366_768_85_PC;
985                    }
986                    else if (ulTempHeight <= 1050)
987                    {
988                        *peInputFormatGroup = BVDB_InputFormatGroup_e1400_1050_75_PC;
989                    }
990                }
991            }
992        }
993    }
994
995    if (*peInputFormatGroup == BVDB_InputFormatGroup_eInvalid)
996        err = BERR_NOT_SUPPORTED;
997
998    return BERR_TRACE(err);
999}
1000
1001
1002BERR_Code BVDB_AddVdbEntry
1003    ( BVDB_Handle             hVdb,
1004      const BVDB_UsageMode   *pstUsageMode )
1005{
1006    BERR_Code             err = BERR_SUCCESS;
1007    BVDB_P_Context       *pVdb;
1008    BVDB_VideoDisplayMode stDispMode = pstUsageMode->stDisplayMode;
1009    BVDB_UsageMode        stUsageMode;
1010
1011    BVDB_P_GET_CONTEXT(hVdb, pVdb);
1012
1013    BKNI_Memcpy((void*)&stUsageMode, (void *)pstUsageMode, sizeof(BVDB_UsageMode));
1014
1015    /* Create ID based on given parameters */
1016    if (BVDB_P_CreateId(pVdb, &stUsageMode) == BERR_SUCCESS)
1017    {
1018        BVDB_UsageMode *pCurr, *pNext, *pPrev = NULL, *pInsert = NULL;
1019        bool bInsertPointBefore = false, bInsertPointAfter = false;
1020        BVDB_P_DispModeType eDispMode, eInsertDispMode;
1021
1022        /* Validate Entry */
1023        err = BVDB_P_ValidateVdbEntry(NULL, &stUsageMode);
1024
1025        if (err == BERR_SUCCESS)
1026        {
1027            pCurr = BLST_CQ_FIRST(pVdb);
1028            do
1029            {
1030                /* search for similar input format, display and window */
1031                if ((pCurr->eInputFormatGroup == stUsageMode.eInputFormatGroup) &&
1032                    (pCurr->stDisplay.eType == stUsageMode.stDisplay.eType) &&
1033                    (pCurr->stDisplay.eResolution == stUsageMode.stDisplay.eResolution) &&
1034                    (pCurr->stDisplay.eAspectRatio == stUsageMode.stDisplay.eAspectRatio) &&
1035                    (pCurr->eWindow == stUsageMode.eWindow))
1036                {
1037                    eDispMode = BVDB_P_GetVideoDisplayModeType(&pCurr->stDisplayMode);
1038                    eInsertDispMode = BVDB_P_GetVideoDisplayModeType(&stDispMode);
1039                    pNext = BVDB_P_UsageMode_GetNextNode(pCurr);
1040                    pPrev = BVDB_P_UsageMode_GetPrevNode(pCurr);
1041
1042                    if (((pCurr->eInput == stUsageMode.eInput) && (eDispMode < eInsertDispMode)) || /* compare inputs and display mode */
1043                        ((pCurr->eInput < stUsageMode.eInput) && (stUsageMode.eInput < pNext->eInput))) /* compare inputs */
1044                    {
1045                        bInsertPointAfter = true;
1046                        break;
1047                    }
1048                    else if (((pCurr->eInput == stUsageMode.eInput) && (eDispMode > eInsertDispMode)) || /* compare inputs and display mode */
1049                        ((pCurr->eInput > stUsageMode.eInput) && (stUsageMode.eInput > pPrev->eInput))) /* compare inputs */
1050                    {
1051                        bInsertPointBefore = true;
1052                        break;
1053                    }
1054                }
1055                pCurr = BVDB_P_UsageMode_GetNextNode(pCurr);
1056            } while (pCurr != BLST_CQ_FIRST(pVdb));
1057
1058            pInsert = (BVDB_UsageMode *)BKNI_Malloc(sizeof(BVDB_UsageMode));
1059            if (pInsert == NULL)
1060            {
1061                BDBG_ERR(("Out of memory"));
1062                return BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);
1063            }
1064
1065            BKNI_Memcpy((void *)pInsert, (void *)&stUsageMode, sizeof(BVDB_UsageMode));
1066
1067            /* compare input of above usage mode with to be inserted usage mode. */
1068            if (bInsertPointAfter)
1069            {
1070                BLST_CQ_INSERT_AFTER(pVdb, pCurr, pInsert, link);
1071            }
1072            else if (bInsertPointBefore)
1073            {
1074                BLST_CQ_INSERT_BEFORE(pVdb, pCurr, pInsert, link);
1075            }
1076            else /* add at tail */
1077            {
1078                BLST_CQ_INSERT_TAIL(pVdb, pInsert, link);
1079            }
1080            BDBG_MSG(("Added usage mode %s", stUsageMode.acId));
1081        }
1082    }
1083    else
1084    {
1085        BDBG_ERR(("Failed to add usage mode due to bad parameters entered"));
1086        err = BERR_INVALID_PARAMETER;
1087    }
1088    return BERR_TRACE(err);
1089}
1090
1091BERR_Code BVDB_RemoveVdbEntry
1092    ( BVDB_Handle             hVdb,
1093      const BVDB_UsageMode   *pstUsageMode )
1094{
1095    BERR_Code        err = BERR_SUCCESS;
1096    BVDB_P_Context  *pVdb;
1097    BVDB_UsageMode  *pCurr;
1098    bool             bFound = false;
1099
1100    BVDB_P_GET_CONTEXT(hVdb, pVdb);
1101
1102    pCurr = BLST_CQ_FIRST(pVdb);
1103    do
1104    {
1105        if (strcmp(pCurr->acId, pstUsageMode->acId) == 0)
1106        {
1107            bFound = true;
1108            break;
1109        }
1110        pCurr = BVDB_P_UsageMode_GetNextNode(pCurr);
1111    } while (pCurr != BLST_CQ_FIRST(pVdb));
1112
1113    if (bFound)
1114    {
1115        /* remove entry */
1116        BLST_CQ_REMOVE(pVdb, pCurr, link);
1117        BKNI_Free(pCurr);
1118    }
1119    else
1120    {
1121        BDBG_ERR(("ID not found"));
1122        err = BERR_INVALID_PARAMETER;
1123    }
1124
1125    return BERR_TRACE(err);
1126}
1127
1128static bool bCacheFilled[BVDB_Window_eMonitor + 1];
1129
1130BERR_Code BVDB_GetVdbEntry
1131    ( BVDB_Handle                       hVdb,
1132      BVDB_UsageMode                   *pstUsageMode )
1133{
1134    BERR_Code                err = BERR_SUCCESS;
1135    BVDB_P_Context          *pVdb;
1136    BVDB_UsageMode          *pstTemp;
1137    bool                     bFound = false;
1138    BVDB_VideoDisplayMode   *pMode, *pSearchMode;
1139    uint32_t                 ulUsrId, ulTempId;
1140    BVDB_UsageMode          *pTempUsageMode;
1141    static BVDB_UsageMode    stCachedUsageMode[BVDB_Window_eMonitor + 1];
1142
1143    BVDB_P_GET_CONTEXT(hVdb, pVdb);
1144
1145    ulUsrId = BVDB_P_GetConfigId(pstUsageMode->acId);
1146
1147    /* Find a cache hit:
1148     *
1149     * As the entire table search may take long, which may affect real time
1150     * operation, a concept so called "cached VDB mode" is introduced here.
1151     * VDB usage mode cache holds the latest VDB usage mode for each window
1152     * (i.e., Main, Pip, Monitor). And whenever there's a new query for the
1153     * VDB usage mode, it looks at the cached mode first because it's very
1154     * likely that the match is there. If it matches (Cache hit), then it
1155     * simply returns the* cached VDB usage mode. Otherwise, (Cache miss) it
1156     * has to search the entire usage mode table.
1157     *
1158     * Note: Of course the larger cache, the better performance. The # of cached
1159     * Usage mode can be extended if faster response is required.
1160     */
1161
1162    /* See if there's a match with the cached usage mode info */
1163    pTempUsageMode = &stCachedUsageMode[pstUsageMode->eWindow];
1164
1165    /* Make sure size of BVDB_VideoDisplayMode is 4 bytes */
1166    BDBG_ASSERT(sizeof(BVDB_VideoDisplayMode) == sizeof(uint32_t));
1167
1168    pMode = &pTempUsageMode->stDisplayMode;
1169    pSearchMode = &(pstUsageMode->stDisplayMode);
1170
1171    if (bCacheFilled[pstUsageMode->eWindow])
1172    {
1173        BDBG_ASSERT(BVDB_P_GetConfigId(pstUsageMode->acId) == BVDB_P_GetConfigId(pTempUsageMode->acId));
1174
1175        /* Matched! Return immediately without searching the whole usage mode array */
1176        if ((pstUsageMode->eInputFormatGroup == pTempUsageMode->eInputFormatGroup) &&
1177            (pstUsageMode->stDisplay.eType == pTempUsageMode->stDisplay.eType) &&
1178            (pstUsageMode->stDisplay.eResolution == pTempUsageMode->stDisplay.eResolution) &&
1179            (pstUsageMode->stDisplay.eAspectRatio == pTempUsageMode->stDisplay.eAspectRatio) &&
1180            (pstUsageMode->eWindow == pTempUsageMode->eWindow) &&
1181            (pstUsageMode->eInput == pTempUsageMode->eInput) &&
1182            ((*(uint32_t*)pMode) & (*(uint32_t *)pSearchMode)))
1183        {
1184            BKNI_Memcpy(pstUsageMode, pTempUsageMode, sizeof(BVDB_UsageMode));
1185            return BERR_TRACE(err);
1186        }
1187    }
1188
1189    /* Unfortunately the cached usage mode doesn't match. Must search the whole usage
1190     * modes for the match */
1191    pstTemp = BLST_CQ_FIRST(pVdb);
1192    do
1193    {
1194        pMode = &pstTemp->stDisplayMode;
1195        pSearchMode = &(pstUsageMode->stDisplayMode);
1196        ulTempId = BVDB_P_GetConfigId(pstTemp->acId);
1197
1198        if ((ulUsrId == ulTempId) &&
1199            (pstUsageMode->eInputFormatGroup == pstTemp->eInputFormatGroup) &&
1200            (pstUsageMode->stDisplay.eType == pstTemp->stDisplay.eType) &&
1201            (pstUsageMode->stDisplay.eResolution == pstTemp->stDisplay.eResolution) &&
1202            (pstUsageMode->stDisplay.eAspectRatio == pstTemp->stDisplay.eAspectRatio) &&
1203            (pstUsageMode->eWindow == pstTemp->eWindow) &&
1204            (pstUsageMode->eInput == pstTemp->eInput) &&
1205            ((*(uint32_t*)pMode) & (*(uint32_t *)pSearchMode)))
1206        {
1207            bFound = true;
1208            break;
1209        }
1210        pstTemp = BVDB_P_UsageMode_GetNextNode(pstTemp);
1211    } while (pstTemp != BLST_CQ_FIRST(pVdb));
1212
1213    if (bFound == false)
1214        err = BERR_INVALID_PARAMETER;
1215    else
1216    {
1217        BKNI_Memcpy(pstUsageMode, pstTemp, sizeof(BVDB_UsageMode));
1218        BKNI_Memcpy(pTempUsageMode, pstTemp, sizeof(BVDB_UsageMode));
1219        bCacheFilled[pstUsageMode->eWindow] = true;
1220    }
1221
1222    return BERR_TRACE(err);
1223}
1224
1225BERR_Code BVDB_GetVdbEntryById
1226    ( BVDB_Handle                       hVdb,
1227      BVDB_UsageMode                   *pstUsageMode )
1228{
1229    BERR_Code       err = BERR_SUCCESS;
1230    BVDB_P_Context *pVdb;
1231    BVDB_UsageMode *pstTemp;
1232    bool            bFound = false;
1233
1234    BVDB_P_GET_CONTEXT(hVdb, pVdb);
1235
1236    pstTemp = BLST_CQ_FIRST(pVdb);
1237    do
1238    {
1239        if (strcmp(pstUsageMode->acId, pstTemp->acId) == 0)
1240        {
1241            BKNI_Memcpy((void *)pstUsageMode, (void *)pstTemp, sizeof(BVDB_UsageMode));
1242            bFound = true;
1243            break;
1244        }
1245        pstTemp = BVDB_P_UsageMode_GetNextNode(pstTemp);
1246    } while (pstTemp != BLST_CQ_FIRST(pVdb));
1247
1248    if (bFound == false)
1249        err = BERR_INVALID_PARAMETER;
1250
1251    return BERR_TRACE(err);
1252}
1253
1254BERR_Code BVDB_GetClippedSize
1255    ( BVDB_Handle             hVdb,
1256      BVDB_VideoDisplayMode  *pstDispMode,
1257      uint32_t               *pulHeight,
1258      uint32_t               *pulWidth )
1259{
1260    BERR_Code err = BERR_SUCCESS;
1261    uint32_t ulH, ulW;
1262    BVDB_VideoDisplayModeInfo stInfo;
1263
1264    BSTD_UNUSED(hVdb);
1265
1266    err = BVDB_P_GetVideoDispModeInfo(pstDispMode, &stInfo);
1267    if (err != BERR_SUCCESS)
1268    {
1269        return BERR_TRACE(err);
1270    }
1271
1272    /* get new active size */
1273    if (stInfo.ulSrcHeightClipAmount != 0)
1274    {
1275        ulH = (*pulHeight * (100 - stInfo.ulSrcHeightClipAmount))/100;
1276        if (((*pulHeight * (100 - stInfo.ulSrcHeightClipAmount))%100) >= 5)
1277            *pulHeight = ulH + 1;
1278        else
1279            *pulHeight = ulH;
1280    }
1281
1282    if (stInfo.ulSrcWidthClipAmount != 0)
1283    {
1284        ulW = (*pulWidth * (100 - stInfo.ulSrcWidthClipAmount))/100;
1285        if (((*pulWidth * (100 - stInfo.ulSrcWidthClipAmount))%100) >= 5)
1286            *pulWidth = ulW + 1;
1287        else
1288            *pulWidth = ulW;
1289    }
1290
1291    return BERR_TRACE(err);
1292}
1293
1294BERR_Code BVDB_GetDisplaySourceAs
1295    ( BVDB_Handle                   hVdb,
1296      BVDB_VideoDisplayMode        *pstDispMode,
1297      const uint32_t                ulSrcHeight,
1298      const uint32_t                ulSrcWidth,
1299      const BVDB_Display           *pstDisplay,
1300      const BFMT_AspectRatio        eSrcAspectRatio,
1301      const uint16_t                uiSampleAspectRatioX,
1302      const uint16_t                uiSampleAspectRatioY,
1303      const BVDB_AspectRatio        eAspectRatioCorrection,
1304      BVDB_DisplaySourceAs         *peDisplaySourceAs )
1305{
1306    BERR_Code err = BERR_SUCCESS;
1307    BVDB_VideoDisplayModeInfo stInfo;
1308    BFMT_AspectRatio eLocalSrcAspectRatio;
1309    uint32_t ulFrameAspectRatio = 0;
1310
1311    BSTD_UNUSED(hVdb);
1312
1313    eLocalSrcAspectRatio = eSrcAspectRatio;
1314
1315    /* Handle unknown source aspect ratio */
1316    if (BFMT_AspectRatio_eUnknown == eLocalSrcAspectRatio)
1317    {
1318        uint32_t ulHVRatio = (ulSrcWidth * 100) / ulSrcHeight;
1319
1320        eLocalSrcAspectRatio = BVDB_P_EQ_DELTA(ulHVRatio, 130, 25) ?
1321            BFMT_AspectRatio_e4_3 : BFMT_AspectRatio_eSquarePxl;
1322
1323        BDBG_MSG(("changing eLocalSrcAspectRatio from eUnknown to %d", eLocalSrcAspectRatio));
1324    }
1325
1326    if (eAspectRatioCorrection == BVDB_AspectRatio_eAllSrc)
1327    {
1328        /* Get the frame aspect ratio based on the clipped dimensions. */
1329        if (eLocalSrcAspectRatio == BFMT_AspectRatio_eSAR)
1330        {
1331            if (0 == uiSampleAspectRatioX || 0 == uiSampleAspectRatioY)
1332            {
1333                uint32_t ulHVRatio = (ulSrcWidth * 100) / ulSrcHeight;
1334
1335                eLocalSrcAspectRatio = BVDB_P_EQ_DELTA(ulHVRatio, 130, 25) ?
1336                    BFMT_AspectRatio_e4_3 : BFMT_AspectRatio_eSquarePxl;
1337
1338                ulFrameAspectRatio = (eLocalSrcAspectRatio == BFMT_AspectRatio_e4_3) ?
1339                        (4 * 100)/3 : ulHVRatio;
1340            }
1341            else
1342            {
1343                /* Get frame aspect ratio based on clipped size */
1344                ulFrameAspectRatio = (uiSampleAspectRatioX * ulSrcWidth * 100) /
1345                                 (uiSampleAspectRatioY * ulSrcHeight);
1346            }
1347        }
1348        else
1349        {
1350            uint32_t ulPixelAspectRatio;
1351            uint32_t ulFrameAspectRatioX, ulFrameAspectRatioY;
1352            uint32_t ulConvFactor;
1353
1354            switch(eLocalSrcAspectRatio)
1355            {
1356                case BFMT_AspectRatio_e16_9:
1357                    ulFrameAspectRatioX = 16;
1358                    ulFrameAspectRatioY = 9;
1359                    break;
1360                case BFMT_AspectRatio_e15_9:
1361                    ulFrameAspectRatioX = 15;
1362                    ulFrameAspectRatioY = 9;
1363                    break;
1364                case BFMT_AspectRatio_e4_3:
1365                    ulFrameAspectRatioX = 4;
1366                    ulFrameAspectRatioY = 3;
1367                    break;
1368                case BFMT_AspectRatio_e221_1:
1369                    ulFrameAspectRatioX = 221;
1370                    ulFrameAspectRatioY = 1;
1371                    break;
1372                case BFMT_AspectRatio_eSquarePxl:
1373                    ulFrameAspectRatioX = 1;
1374                    ulFrameAspectRatioY = 1;
1375                    break;
1376                default:
1377                    BDBG_ERR(("BVDB_AspectRatio_eAllSrc failed because eLocalSrcAspectRatio=%d", eLocalSrcAspectRatio));
1378                    return BERR_TRACE(BERR_INVALID_PARAMETER);
1379            }
1380
1381            if ((ulFrameAspectRatioX * 100)/ulFrameAspectRatioY == (ulSrcWidth * 100)/ulSrcHeight)
1382            {
1383                ulPixelAspectRatio = 1;
1384                ulConvFactor = 100;
1385            }
1386            else
1387            {
1388                ulPixelAspectRatio = (((ulFrameAspectRatioX * 100)/ulFrameAspectRatioY) * 100)/((ulSrcWidth * 100)/ulSrcHeight);
1389                ulConvFactor = 1;
1390            }
1391
1392            /* Get frame aspect ratio based on clipped size */
1393            ulFrameAspectRatio = (ulPixelAspectRatio * ulSrcWidth * ulConvFactor) /
1394                                 (1 * ulSrcHeight);
1395
1396            BDBG_MSG(("eAspectRatioCorrection = %d", eAspectRatioCorrection));
1397            BDBG_MSG(("ulPixelAspectRatio = %d", ulPixelAspectRatio));
1398            BDBG_MSG(("ulFrameAspectRatioX = %d", ulFrameAspectRatioX));
1399            BDBG_MSG(("ulFrameAspectRatioY = %d", ulFrameAspectRatioY));
1400            BDBG_MSG(("ulSrcWidth = %d", ulSrcWidth));
1401            BDBG_MSG(("ulSrcHeight = %d", ulSrcHeight));
1402        }
1403    }
1404    else if (eAspectRatioCorrection == BVDB_AspectRatio_eAllDest)
1405    {
1406        switch (pstDisplay->eAspectRatio)
1407        {
1408            case BVDB_AspectRatio_e16_9:
1409                ulFrameAspectRatio = BVDB_P_ASPECT_RATIO_16_9;
1410                break;
1411            case BVDB_AspectRatio_e4_3:
1412                ulFrameAspectRatio = BVDB_P_ASPECT_RATIO_4_3;
1413                break;
1414            default:
1415                BDBG_ERR(("Display panel aspect ratio is not supported."));
1416                err = BERR_INVALID_PARAMETER;
1417        }
1418    }
1419    else if (eAspectRatioCorrection == BVDB_AspectRatio_eBypass)
1420    {
1421        if (eLocalSrcAspectRatio == BFMT_AspectRatio_eSAR)
1422        {
1423            if (0 == uiSampleAspectRatioX || 0 == uiSampleAspectRatioY)
1424            {
1425                uint32_t ulHVRatio = (ulSrcWidth * 100) / ulSrcHeight;
1426
1427                eLocalSrcAspectRatio = BVDB_P_EQ_DELTA(ulHVRatio, 130, 25) ?
1428                    BFMT_AspectRatio_e4_3 : BFMT_AspectRatio_eSquarePxl;
1429
1430                ulFrameAspectRatio = (eLocalSrcAspectRatio == BFMT_AspectRatio_e4_3) ?
1431                        (4 * 100)/3 : ulHVRatio;
1432            }
1433            else
1434            {
1435                ulFrameAspectRatio = (uiSampleAspectRatioX * ulSrcWidth * 100) /
1436                             (uiSampleAspectRatioY * ulSrcHeight);
1437            }
1438        }
1439        else
1440        {
1441            switch (eLocalSrcAspectRatio)
1442            {
1443                case BFMT_AspectRatio_e16_9:
1444                    ulFrameAspectRatio = BVDB_P_ASPECT_RATIO_16_9;
1445                    break;
1446                case BFMT_AspectRatio_e15_9:
1447                    ulFrameAspectRatio = BVDB_P_ASPECT_RATIO_15_9;
1448                    break;
1449                case BFMT_AspectRatio_e4_3:
1450                    ulFrameAspectRatio = BVDB_P_ASPECT_RATIO_4_3;
1451                    break;
1452                case BFMT_AspectRatio_e221_1:
1453                    ulFrameAspectRatio = BVDB_P_ASPECT_RATIO_221;
1454                    break;
1455                case BFMT_AspectRatio_eSquarePxl:
1456                    ulFrameAspectRatio = (ulSrcWidth * 100) / ulSrcHeight;
1457                    break;
1458                default:
1459                    BDBG_ERR(("BVDB_AspectRatio_eBypass failed because eLocalSrcAspectRatio=%d", eLocalSrcAspectRatio));
1460                    return BERR_TRACE(BERR_INVALID_PARAMETER);
1461            }
1462        }
1463    }
1464    else
1465    {
1466        BDBG_ERR(("Specified aspect ratio correction %d is not supported.", eAspectRatioCorrection));
1467        return BERR_TRACE(BERR_INVALID_PARAMETER);
1468    }
1469
1470    BDBG_MSG(("Display is %s", (pstDisplay->eAspectRatio == BVDB_AspectRatio_e16_9) ?
1471        "16:9" : ((pstDisplay->eAspectRatio == BVDB_AspectRatio_e4_3) ? "4:3" :
1472        "unknown")));
1473
1474    BDBG_MSG(("Source AR is %s", (ulFrameAspectRatio == BVDB_P_ASPECT_RATIO_16_9) ? "16:9" :
1475        (ulFrameAspectRatio <= BVDB_P_ASPECT_RATIO_16_9) ? "4:3" : "other"));
1476
1477    err = BVDB_P_GetVideoDispModeInfo(pstDispMode, &stInfo);
1478    if (err != BERR_SUCCESS) {
1479        return BERR_TRACE(err);
1480    }
1481
1482    if (pstDisplay->eAspectRatio == BVDB_AspectRatio_e16_9)
1483    {
1484        *peDisplaySourceAs = (ulFrameAspectRatio >= BVDB_P_ASPECT_RATIO_16_9) ?
1485            stInfo.eDisplay16_9SrcOn16_9Display :
1486            stInfo.eDisplay4_3SrcOn16_9dDisplay;
1487    }
1488    else if (pstDisplay->eAspectRatio == BVDB_AspectRatio_e4_3)
1489    {
1490        *peDisplaySourceAs = (ulFrameAspectRatio <= BVDB_P_ASPECT_RATIO_16_9) ?
1491            stInfo.eDisplay16_9SrcOn4_3Display :
1492            stInfo.eDisplay4_3SrcOn4_3Display;
1493    }
1494    else
1495    {
1496        BDBG_ERR(("Invalid display aspect ratio %d.", pstDisplay->eAspectRatio));
1497        err = BERR_INVALID_PARAMETER;
1498    }
1499
1500    return BERR_TRACE(err);
1501}
1502
1503BERR_Code BVDB_ValidateConfigId
1504    ( BVDB_Handle             hVdb,
1505      const uint32_t          ulConfigId )
1506{
1507    BERR_Code err = BERR_SUCCESS;
1508    bool bFound = false;
1509    BVDB_UsageMode *pstUsageMode;
1510    BVDB_P_Context *pVdb;
1511
1512    BVDB_P_GET_CONTEXT(hVdb, pVdb);
1513
1514    pstUsageMode = BLST_CQ_FIRST(pVdb);
1515    do
1516    {
1517        if (ulConfigId == BVDB_P_GetConfigId(pstUsageMode->acId))
1518        {
1519            bFound = true;
1520            break;
1521        }
1522        pstUsageMode = BVDB_P_UsageMode_GetNextNode(pstUsageMode);
1523    } while (pstUsageMode != BLST_CQ_FIRST(pVdb));
1524
1525    if (bFound == false)
1526        err = BERR_INVALID_PARAMETER;
1527
1528    /* need some way to clear the cache when switching id's. BVDB_ValidateConfigId could be repurposed to that end. */
1529    BKNI_Memset(bCacheFilled, 0, sizeof(bCacheFilled));
1530
1531    return BERR_TRACE(err);
1532}
1533
1534BERR_Code BVDB_ValidateSourceClipAmount
1535    ( BVDB_Handle                  hVdb,
1536      const BVDB_UsageMode        *pstUsageMode,
1537      const uint32_t               ulSrcHeight,
1538      const uint32_t               ulSrcWidth,
1539      const uint32_t               ulHeightClipAmount,
1540      const uint32_t               ulWidthClipAmount )
1541{
1542    BERR_Code                   err = BERR_SUCCESS;
1543    BVDB_P_Context             *pVdb;
1544    BVDB_VideoDisplayModeInfo   stInfo;
1545    BVDB_VideoDisplayMode       stDispMode = pstUsageMode->stDisplayMode;
1546
1547    BVDB_P_GET_CONTEXT(hVdb, pVdb);
1548
1549    err = BVDB_P_GetVideoDispModeInfo(&stDispMode, &stInfo );
1550    if (err == BERR_SUCCESS)
1551    {
1552        /* validate */
1553        if ((pstUsageMode->stDisplay.eType == BVDB_Display_eSecondary50 ||
1554             pstUsageMode->stDisplay.eType == BVDB_Display_eSecondary60) &&
1555             (BVDB_DISP_MODE_IS_MON_1(&pstUsageMode->stDisplayMode) ||
1556              BVDB_DISP_MODE_IS_MON_3(&pstUsageMode->stDisplayMode)))
1557        {
1558            if (((ulHeightClipAmount * 100)/ulSrcHeight) < stInfo.ulSrcHeightClipAmount &&
1559                ((ulHeightClipAmount * 100)/ulSrcHeight) > 0)
1560            {
1561                BDBG_ERR(("Total source height clip[%d percent] amount for secondary display must follow main window.",
1562                    ((ulHeightClipAmount * 100)/ulSrcHeight)));
1563                err = BERR_INVALID_PARAMETER;
1564            }
1565
1566            if (((ulWidthClipAmount * 100)/ulSrcWidth) < stInfo.ulSrcWidthClipAmount &&
1567                ((ulWidthClipAmount * 100)/ulSrcWidth) > 0)
1568            {
1569                BDBG_ERR(("Total source width clip[%d percent] amount for secondary display must follow main window.",
1570                    ((ulWidthClipAmount * 100)/ulSrcWidth)));
1571                err = BERR_INVALID_PARAMETER;
1572            }
1573        }
1574        else
1575        {
1576            if (((ulHeightClipAmount * 100)/ulSrcHeight) > stInfo.ulSrcHeightClipAmount)
1577            {
1578                BDBG_ERR(("Total source height clip amount [%d percent] exceeds max[%d percent] allowed.",
1579                    ((ulHeightClipAmount * 100)/ulSrcHeight), stInfo.ulSrcHeightClipAmount));
1580                err = BERR_INVALID_PARAMETER;
1581            }
1582
1583            if (((ulWidthClipAmount * 100)/ulSrcWidth)  > stInfo.ulSrcWidthClipAmount)
1584            {
1585                BDBG_ERR(("Total source width clip[%d percent] amount exceeds max[%d percent] allowed.",
1586                    ((ulWidthClipAmount * 100)/ulSrcWidth), stInfo.ulSrcWidthClipAmount));
1587                err = BERR_INVALID_PARAMETER;
1588            }
1589        }
1590    }
1591    return BERR_TRACE(err);
1592}
1593
1594BERR_Code BVDB_GetMemoryAllocation
1595    (const uint32_t               ulConfigId,
1596     const BVDB_Window            eWindow,
1597     const BVDB_Input             eInput,
1598     BVDB_Heap_Settings          *pstHeapSettings,
1599     uint32_t                    *pulHeapSize )
1600{
1601    BERR_Code err = BERR_SUCCESS;
1602    uint32_t i, j, k;
1603    bool bFound = false;
1604    uint32_t ulNumConfigs;
1605    BVDB_P_Config_MemAlloc *pstConfigMemAlloc;
1606
1607    BDBG_ASSERT(pstHeapSettings);
1608
1609    err = BVDB_P_GetNumConfigs(&ulNumConfigs);
1610    if (err != BERR_SUCCESS)
1611    {
1612        return BERR_TRACE(err);
1613    }
1614
1615    pstConfigMemAlloc = (BVDB_P_Config_MemAlloc *)BKNI_Malloc(sizeof(BVDB_P_Config_MemAlloc) * ulNumConfigs * BVDB_P_NUM_WINDOW_HEAPS);
1616    if (pstConfigMemAlloc == NULL)
1617    {
1618        BDBG_ERR(("Out of memory."));
1619        err = BERR_OUT_OF_SYSTEM_MEMORY;
1620        return BERR_TRACE(err);
1621    }
1622
1623    err = BVDB_P_GetConfigMemAllocArray(pstConfigMemAlloc);
1624    if (err != BERR_SUCCESS)
1625    {
1626        return BERR_TRACE(err);
1627    }
1628
1629    /* Search for config */
1630    for (k=0; k<ulNumConfigs; k++)
1631    {
1632        /* configuration ID starts at 1 */
1633        if (ulConfigId == pstConfigMemAlloc[k * BVDB_P_NUM_WINDOW_HEAPS].ulConfigId)
1634        {
1635            bFound = true;
1636            break;
1637        }
1638    }
1639
1640    if (bFound)
1641    {
1642        BDBG_MSG(("Found configuration %d", ulConfigId));
1643        bFound = false;
1644
1645        /* Search for window */
1646        for (i=0; i<BVDB_P_NUM_WINDOW_HEAPS; i++)
1647        {
1648            if (eWindow == pstConfigMemAlloc[(k * BVDB_P_NUM_WINDOW_HEAPS) + i].eWindow)
1649            {
1650                bFound = true;
1651                break;
1652            }
1653        }
1654
1655        if (bFound)
1656        {
1657            if (eWindow == BVDB_Window_eMain)
1658            {
1659                BDBG_MSG(("Found MAIN window"));
1660                bFound = false;
1661
1662                /* Search for input. Is it MPEG or no? */
1663                for (j=0; j<2; j++)
1664                {
1665                    BVDB_Input eLocalInput = eInput;
1666
1667                    if (eLocalInput == BVDB_Input_eInvalid)
1668                    {
1669                        err = BERR_INVALID_PARAMETER;
1670                        BDBG_ERR(("Invalid input."));
1671                        return BERR_TRACE(err);
1672                    }
1673                    else if (eLocalInput != BVDB_Input_eMfd)
1674                    {
1675                        /* Force all valid non-MPEG inputs to use VDEC */
1676                        eLocalInput = BVDB_Input_eComponent;
1677                        BDBG_MSG(("Found non-MFD input"));
1678                    }
1679                    else
1680                    {
1681                        BDBG_MSG(("Found MFD input %d, %d", eLocalInput, j));
1682                    }
1683
1684                    if (eLocalInput == pstConfigMemAlloc[(k * BVDB_P_NUM_WINDOW_HEAPS) + i + j].eInput)
1685                    {
1686                        *pstHeapSettings = pstConfigMemAlloc[(k * BVDB_P_NUM_WINDOW_HEAPS) + i + j].stHeapSettings;
1687                        *pulHeapSize = pstConfigMemAlloc[(k * BVDB_P_NUM_WINDOW_HEAPS) + i + j].ulHeapSize;
1688                        bFound = true;
1689                        break;
1690                    }
1691                }
1692            }
1693            else /* PIP or Monitor */
1694            {
1695                *pstHeapSettings = pstConfigMemAlloc[(k * BVDB_P_NUM_WINDOW_HEAPS) + i].stHeapSettings;
1696                *pulHeapSize = pstConfigMemAlloc[(k * BVDB_P_NUM_WINDOW_HEAPS) + i].ulHeapSize;
1697            }
1698        }
1699        else
1700        {
1701            err = BERR_INVALID_PARAMETER;
1702            BDBG_ERR(("Invalid window."));
1703            return BERR_TRACE(err);
1704        }
1705
1706    }
1707    else
1708    {
1709        err = BERR_INVALID_PARAMETER;
1710        BDBG_ERR(("Configuration %d not found.", ulConfigId));
1711        return BERR_TRACE(err);
1712    }
1713
1714    BKNI_Free(pstConfigMemAlloc);
1715
1716    return BERR_TRACE(err);
1717}
1718BERR_Code BVDB_GetVideoDisplayMode
1719    ( BVDB_Handle                  hVdb,
1720      const uint32_t               ulConfigId,
1721      const BVDB_Display          *pstDisplay,
1722      const BVDB_Window            eWindow,
1723      const bool                   ePipType,
1724      const BVDB_Input             eInput,
1725      const uint32_t               ulSrcHeight,
1726      const uint32_t               ulSrcWidth,
1727      const uint32_t               ulSrcHeightClipAmount,
1728      const uint32_t               ulSrcWidthClipAmount,
1729      const uint32_t               ulDestHeight,
1730      const uint32_t               ulDestWidth,
1731      const BFMT_AspectRatio       eSrcAspectRatio,
1732      const uint16_t               uiSampleAspectRatioX,
1733      const uint16_t               uiSampleAspectRatioY,
1734      const BVDB_AspectRatio       eAspectRatioCorrection,
1735      BVDB_VideoDisplayMode       *pstDispMode,
1736      BFMT_AspectRatio            *pDisplayedAspectRatio )
1737{
1738    BERR_Code                       err = BERR_SUCCESS;
1739    BVDB_P_Context                 *pVdb;
1740    uint32_t                        k;
1741    uint32_t                        ulHeightClipAmount, ulWidthClipAmount;
1742    uint32_t                        ulPrevClipHeightDiff, ulClipHeightDiff;
1743    uint32_t                        ulPrevClipWidthDiff, ulClipWidthDiff;
1744    uint32_t                        ulDisplayHeight, ulDisplayWidth;
1745    BVDB_P_Config_VideoDisplayModes stCfgVidDispModes;
1746    uint32_t                        ulDispMinH, ulDispMinW, ulDispMaxH, ulDispMaxW;
1747    uint32_t                        ulFrameAspectRatio = 0, ulDestAspectRatio = 0;
1748    BVDB_AspectRatio                eDestAspectRatio;
1749    BVDB_DisplaySourceAs            eDisplaySrcAs;
1750    uint32_t                        ulClippedHeight, ulClippedWidth;
1751    BFMT_AspectRatio                eLocalSrcAspectRatio;
1752    uint32_t                        ulModeSrcHeightClipAmount = 0, ulModeSrcWidthClipAmount = 0;
1753    BVDB_VideoDisplayMode           st3dDispMode;
1754    BVDB_VideoDisplayMode          *pst3dDispMode;
1755    uint32_t                       *pul3dDispMode;
1756    uint32_t                       *pulDispMode;
1757
1758    BVDB_P_GET_CONTEXT(hVdb, pVdb);
1759
1760    /* reset */
1761    ulPrevClipHeightDiff = BVDB_P_MAX_SRC_CLIP_HEIGHT_AMOUNT;
1762    ulPrevClipWidthDiff = BVDB_P_MAX_SRC_CLIP_WIDTH_AMOUNT;
1763    ulClipHeightDiff = ulClipWidthDiff = 0;
1764
1765    BDBG_ASSERT(sizeof(BVDB_VideoDisplayMode) == sizeof(uint32_t));
1766    pst3dDispMode = &st3dDispMode;
1767    pul3dDispMode = (uint32_t *) pst3dDispMode;
1768    pulDispMode   = (uint32_t *) pstDispMode;
1769    * pul3dDispMode = 0;
1770    * pulDispMode   = 0;
1771
1772    *pDisplayedAspectRatio = BFMT_AspectRatio_eUnknown;
1773
1774    /* Get display panel info */
1775    err = BVDB_P_GetDisplaySize(pstDisplay->eResolution, &ulDisplayHeight, &ulDisplayWidth);
1776    if (err != BERR_SUCCESS)
1777    {
1778        return BERR_TRACE(err);
1779    }
1780
1781    /* Get config's video display mode information */
1782    err = BVDB_P_GetConfigVideoDisplayModeInfo(ulConfigId, &stCfgVidDispModes);
1783    if (err != BERR_SUCCESS)
1784    {
1785        return BERR_TRACE(err);
1786    }
1787
1788    /* Get clip amount percentage */
1789    ulHeightClipAmount  = (ulSrcHeightClipAmount * 100)/ulSrcHeight;
1790    ulWidthClipAmount  = (ulSrcWidthClipAmount * 100)/ulSrcWidth;
1791
1792    /* Get clipped dimensions */
1793    ulClippedHeight = ulSrcHeight - ulSrcHeightClipAmount;
1794    ulClippedWidth = ulSrcWidth - ulSrcWidthClipAmount;
1795
1796    eLocalSrcAspectRatio = eSrcAspectRatio;
1797
1798    /* Handle unknown source aspect ratio */
1799    if (BFMT_AspectRatio_eUnknown == eLocalSrcAspectRatio)
1800    {
1801        uint32_t ulHVRatio = (ulSrcWidth * 100) / ulSrcHeight;
1802
1803        eLocalSrcAspectRatio = BVDB_P_EQ_DELTA(ulHVRatio, 130, 25) ?
1804            BFMT_AspectRatio_e4_3 : BFMT_AspectRatio_eSquarePxl;
1805
1806        BDBG_MSG(("changing eLocalSrcAspectRatio from eUnknown to %d", eLocalSrcAspectRatio));
1807    }
1808
1809    if (eAspectRatioCorrection == BVDB_AspectRatio_eAllSrc)
1810    {
1811        /* Get the frame aspect ratio based on the clipped dimensions. */
1812        if (eLocalSrcAspectRatio == BFMT_AspectRatio_eSAR)
1813        {
1814            if (0 == uiSampleAspectRatioX || 0 == uiSampleAspectRatioY)
1815            {
1816                uint32_t ulHVRatio = (ulClippedWidth * 100) / ulClippedHeight;
1817
1818                eLocalSrcAspectRatio = BVDB_P_EQ_DELTA(ulHVRatio, 130, 25) ?
1819                    BFMT_AspectRatio_e4_3 : BFMT_AspectRatio_eSquarePxl;
1820
1821                ulFrameAspectRatio = (eLocalSrcAspectRatio == BFMT_AspectRatio_e4_3) ?
1822                        (4 * 100)/3 : ulHVRatio;
1823            }
1824            else
1825            {
1826                /* Get frame aspect ratio based on clipped size */
1827                ulFrameAspectRatio = (uiSampleAspectRatioX * ulClippedWidth * 100) /
1828                                 (uiSampleAspectRatioY * ulClippedHeight);
1829            }
1830        }
1831        else
1832        {
1833            uint32_t ulPixelAspectRatio;
1834            uint32_t ulFrameAspectRatioX, ulFrameAspectRatioY;
1835            uint32_t ulConvFactor;
1836
1837            switch(eLocalSrcAspectRatio)
1838            {
1839                case BFMT_AspectRatio_e16_9:
1840                    ulFrameAspectRatioX = 16;
1841                    ulFrameAspectRatioY = 9;
1842                    break;
1843                case BFMT_AspectRatio_e15_9:
1844                    ulFrameAspectRatioX = 15;
1845                    ulFrameAspectRatioY = 9;
1846                    break;
1847                case BFMT_AspectRatio_e4_3:
1848                    ulFrameAspectRatioX = 4;
1849                    ulFrameAspectRatioY = 3;
1850                    break;
1851                case BFMT_AspectRatio_e221_1:
1852                    ulFrameAspectRatioX = 221;
1853                    ulFrameAspectRatioY = 1;
1854                    break;
1855                case BFMT_AspectRatio_eSquarePxl:
1856                    ulFrameAspectRatioX = 1;
1857                    ulFrameAspectRatioY = 1;
1858                    break;
1859                default:
1860                    err = BERR_INVALID_PARAMETER;
1861                    return BERR_TRACE(err);
1862            }
1863
1864            if ((ulFrameAspectRatioX * 100)/ulFrameAspectRatioY == (ulSrcWidth * 100)/ulSrcHeight)
1865            {
1866                ulPixelAspectRatio = 1;
1867                ulConvFactor = 100;
1868            }
1869            else
1870            {
1871                ulPixelAspectRatio = (((ulFrameAspectRatioX * 100)/ulFrameAspectRatioY) * 100)/((ulSrcWidth * 100)/ulSrcHeight);
1872                ulConvFactor = 1;
1873            }
1874
1875            /* Get frame aspect ratio based on clipped size */
1876            ulFrameAspectRatio = (ulPixelAspectRatio * ulClippedWidth * ulConvFactor) /
1877                                 (1 * ulClippedHeight);
1878
1879            BDBG_MSG(("eAspectRatioCorrection = %d", eAspectRatioCorrection));
1880            BDBG_MSG(("ulPixelAspectRatio = %d", ulPixelAspectRatio));
1881            BDBG_MSG(("ulFrameAspectRatioX = %d", ulFrameAspectRatioX));
1882            BDBG_MSG(("ulFrameAspectRatioY = %d", ulFrameAspectRatioY));
1883            BDBG_MSG(("ulSrcWidth = %d", ulSrcWidth));
1884            BDBG_MSG(("ulSrcHeight = %d", ulSrcHeight));
1885        }
1886    }
1887    else if (eAspectRatioCorrection == BVDB_AspectRatio_eAllDest)
1888    {
1889        switch (pstDisplay->eAspectRatio)
1890        {
1891            case BVDB_AspectRatio_e16_9:
1892                ulFrameAspectRatio = BVDB_P_ASPECT_RATIO_16_9;
1893                break;
1894            case BVDB_AspectRatio_e4_3:
1895                ulFrameAspectRatio = BVDB_P_ASPECT_RATIO_4_3;
1896                break;
1897            default:
1898                BDBG_ERR(("Display panel aspect ratio is not supported."));
1899                err = BERR_INVALID_PARAMETER;
1900        }
1901    }
1902    else if (eAspectRatioCorrection == BVDB_AspectRatio_eBypass)
1903    {
1904        if (eLocalSrcAspectRatio == BFMT_AspectRatio_eSAR)
1905        {
1906            if (0 == uiSampleAspectRatioX || 0 == uiSampleAspectRatioY)
1907            {
1908                uint32_t ulHVRatio = (ulSrcWidth * 100) / ulSrcHeight;
1909
1910                eLocalSrcAspectRatio = BVDB_P_EQ_DELTA(ulHVRatio, 130, 25) ?
1911                    BFMT_AspectRatio_e4_3 : BFMT_AspectRatio_eSquarePxl;
1912
1913                ulFrameAspectRatio = (eLocalSrcAspectRatio == BFMT_AspectRatio_e4_3) ?
1914                        (4 * 100)/3 : ulHVRatio;
1915            }
1916            else
1917            {
1918                ulFrameAspectRatio = (uiSampleAspectRatioX * ulSrcWidth * 100) /
1919                             (uiSampleAspectRatioY * ulSrcHeight);
1920            }
1921        }
1922        else
1923        {
1924            switch (eLocalSrcAspectRatio)
1925            {
1926                case BFMT_AspectRatio_e16_9:
1927                    ulFrameAspectRatio = BVDB_P_ASPECT_RATIO_16_9;
1928                    break;
1929                case BFMT_AspectRatio_e15_9:
1930                    ulFrameAspectRatio = BVDB_P_ASPECT_RATIO_15_9;
1931                    break;
1932                case BFMT_AspectRatio_e4_3:
1933                    ulFrameAspectRatio = BVDB_P_ASPECT_RATIO_4_3;
1934                    break;
1935                case BFMT_AspectRatio_e221_1:
1936                    ulFrameAspectRatio = BVDB_P_ASPECT_RATIO_221;
1937                    break;
1938                case BFMT_AspectRatio_eSquarePxl:
1939                    ulFrameAspectRatio = (ulSrcWidth * 100) / ulSrcHeight;
1940                    break;
1941                default:
1942                    err = BERR_INVALID_PARAMETER;
1943                    return BERR_TRACE(err);
1944            }
1945        }
1946    }
1947    else
1948    {
1949        BDBG_ERR(("Specified aspect ratio correction is not supported."));
1950        err = BERR_INVALID_PARAMETER;
1951        return BERR_TRACE(err);
1952    }
1953
1954    /* Get dest window aspect ratio */
1955    ulDestAspectRatio = (ulDestWidth * 100)/ulDestHeight;
1956
1957    if (ulDestAspectRatio < BVDB_P_ASPECT_RATIO_16_9)
1958    {
1959        eDestAspectRatio = BVDB_AspectRatio_e4_3;
1960    }
1961    else if (ulDestAspectRatio == BVDB_P_ASPECT_RATIO_16_9)
1962    {
1963        eDestAspectRatio = BVDB_AspectRatio_e16_9;
1964    }
1965    else
1966    {
1967        eDestAspectRatio = BVDB_AspectRatio_eCustom;
1968    }
1969
1970    if (eAspectRatioCorrection == BVDB_AspectRatio_eAllDest)
1971    {
1972        if (pstDisplay->eAspectRatio == BVDB_AspectRatio_e16_9)
1973        {
1974            *pDisplayedAspectRatio = BFMT_AspectRatio_e16_9;
1975        }
1976        else if (pstDisplay->eAspectRatio == BVDB_AspectRatio_e4_3)
1977        {
1978            *pDisplayedAspectRatio = BFMT_AspectRatio_e4_3;
1979        }
1980        else
1981        {
1982            *pDisplayedAspectRatio = BFMT_AspectRatio_eUnknown;
1983        }
1984    }
1985    else if (eAspectRatioCorrection == BVDB_AspectRatio_eBypass)
1986    {
1987        if (eDestAspectRatio == BVDB_AspectRatio_e4_3)
1988        {
1989            *pDisplayedAspectRatio = BFMT_AspectRatio_e4_3;
1990        }
1991        else if (eDestAspectRatio == BVDB_AspectRatio_e16_9)
1992        {
1993            *pDisplayedAspectRatio = BFMT_AspectRatio_e16_9;
1994        }
1995        else
1996        {
1997            if (ulDestAspectRatio > BVDB_P_ASPECT_RATIO_16_9)
1998                *pDisplayedAspectRatio = BFMT_AspectRatio_e16_9;
1999            else
2000                *pDisplayedAspectRatio = BFMT_AspectRatio_eUnknown;
2001        }
2002    }
2003    else if (eAspectRatioCorrection == BVDB_AspectRatio_eAllSrc)
2004    {
2005        /* any AR less than 16:9 is a pillarbox on a 16:9 panel */
2006        if (ulFrameAspectRatio < BVDB_P_ASPECT_RATIO_16_9)
2007        {
2008            *pDisplayedAspectRatio = BFMT_AspectRatio_e4_3;
2009        }
2010        else if (ulFrameAspectRatio == BVDB_P_ASPECT_RATIO_16_9)
2011        {
2012            *pDisplayedAspectRatio = BFMT_AspectRatio_e16_9;
2013        }
2014        else
2015        {
2016            /* aspect ratio > 16:9 is unsupported in RTS */
2017            if (ulDestAspectRatio == BVDB_P_ASPECT_RATIO_16_9)
2018                *pDisplayedAspectRatio = BFMT_AspectRatio_e16_9; /* cap it at 16:9 */
2019            else
2020                *pDisplayedAspectRatio = BFMT_AspectRatio_eUnknown;
2021        }
2022    }
2023
2024    /* Get eDisplaySrcAs given the src and dest apsect ratios */
2025    if (ulFrameAspectRatio < BVDB_P_ASPECT_RATIO_16_9)
2026    {
2027        if (pstDisplay->eAspectRatio == BVDB_AspectRatio_e16_9)
2028        {
2029            if (*pDisplayedAspectRatio == BFMT_AspectRatio_e16_9)
2030            {
2031                eDisplaySrcAs = BVDB_DisplaySourceAs_eFull;
2032            }
2033            else if (*pDisplayedAspectRatio == BFMT_AspectRatio_e4_3)
2034            {
2035                eDisplaySrcAs = BVDB_DisplaySourceAs_ePillarbox;
2036            }
2037            else
2038            {
2039                eDisplaySrcAs = BVDB_DisplaySourceAs_eInvalid;
2040            }
2041        }
2042        else if (pstDisplay->eAspectRatio == BVDB_AspectRatio_e4_3)
2043        {
2044            if (*pDisplayedAspectRatio == BFMT_AspectRatio_e16_9)
2045            {
2046                eDisplaySrcAs = BVDB_DisplaySourceAs_eLetterbox;
2047            }
2048            else if (*pDisplayedAspectRatio == BFMT_AspectRatio_e4_3)
2049            {
2050                eDisplaySrcAs = BVDB_DisplaySourceAs_eFull;
2051            }
2052            else
2053            {
2054                eDisplaySrcAs = BVDB_DisplaySourceAs_eInvalid;
2055            }
2056        }
2057        else
2058        {
2059            eDisplaySrcAs = BVDB_DisplaySourceAs_eInvalid;
2060        }
2061    }
2062    else if (ulFrameAspectRatio == BVDB_P_ASPECT_RATIO_16_9)
2063    {
2064        if (pstDisplay->eAspectRatio == BVDB_AspectRatio_e16_9)
2065        {
2066            if (*pDisplayedAspectRatio == BFMT_AspectRatio_e16_9)
2067            {
2068                eDisplaySrcAs = BVDB_DisplaySourceAs_eFull;
2069            }
2070            else if (*pDisplayedAspectRatio == BFMT_AspectRatio_e4_3)
2071            {
2072                eDisplaySrcAs = BVDB_DisplaySourceAs_ePillarbox;
2073            }
2074            else
2075            {
2076                eDisplaySrcAs = BVDB_DisplaySourceAs_eInvalid;
2077            }
2078        }
2079        else if (pstDisplay->eAspectRatio == BVDB_AspectRatio_e4_3)
2080        {
2081            if (*pDisplayedAspectRatio == BFMT_AspectRatio_e16_9)
2082            {
2083                eDisplaySrcAs = BVDB_DisplaySourceAs_eLetterbox;
2084            }
2085            else if (*pDisplayedAspectRatio == BFMT_AspectRatio_e4_3)
2086            {
2087                eDisplaySrcAs = BVDB_DisplaySourceAs_eFull;
2088            }
2089            else
2090            {
2091                eDisplaySrcAs = BVDB_DisplaySourceAs_eInvalid;
2092            }
2093        }
2094        else
2095        {
2096            eDisplaySrcAs = BVDB_DisplaySourceAs_eInvalid;
2097        }
2098    }
2099    else
2100    {
2101        if (pstDisplay->eAspectRatio == BVDB_AspectRatio_e16_9)
2102        {
2103            if (*pDisplayedAspectRatio == BFMT_AspectRatio_e16_9)
2104            {
2105                eDisplaySrcAs = BVDB_DisplaySourceAs_eFull;
2106            }
2107            else if (*pDisplayedAspectRatio == BFMT_AspectRatio_e4_3)
2108            {
2109                eDisplaySrcAs = BVDB_DisplaySourceAs_ePillarbox;
2110            }
2111            else
2112            {
2113                eDisplaySrcAs = BVDB_DisplaySourceAs_eInvalid;
2114            }
2115        }
2116        else if (pstDisplay->eAspectRatio == BVDB_AspectRatio_e4_3)
2117        {
2118            if (*pDisplayedAspectRatio == BFMT_AspectRatio_e16_9)
2119            {
2120                eDisplaySrcAs = BVDB_DisplaySourceAs_eLetterbox;
2121            }
2122            else if (*pDisplayedAspectRatio == BFMT_AspectRatio_e4_3)
2123            {
2124                eDisplaySrcAs = BVDB_DisplaySourceAs_eFull;
2125            }
2126            else
2127            {
2128                eDisplaySrcAs = BVDB_DisplaySourceAs_eInvalid;
2129            }
2130        }
2131        else
2132        {
2133            eDisplaySrcAs = BVDB_DisplaySourceAs_eInvalid;
2134        }
2135    }
2136
2137    BDBG_MSG(("ulFrameAspectRatio = %d", ulFrameAspectRatio));
2138    BDBG_MSG(("ulDestAspectRatio = %d (%d)", ulDestAspectRatio, BVDB_P_ASPECT_RATIO_16_9));
2139    BDBG_MSG(("eDestAspectRatio = %d", eDestAspectRatio));
2140    BDBG_MSG(("*pDisplayedAspectRatio = %s", (*pDisplayedAspectRatio == BFMT_AspectRatio_e16_9) ? "16:9" :
2141                                            (*pDisplayedAspectRatio == BFMT_AspectRatio_e4_3) ? "4:3" :
2142                                            "other"));
2143    BDBG_MSG(("eDisplaySrcAs = %s", (eDisplaySrcAs == BVDB_DisplaySourceAs_eFull) ? "FULL":
2144                                    (eDisplaySrcAs == BVDB_DisplaySourceAs_eLetterbox) ? "LBOX" :
2145                                    (eDisplaySrcAs == BVDB_DisplaySourceAs_ePillarbox) ? "PBOX" :
2146                                    "other"));
2147    BDBG_MSG(("Source AR is %s", (ulFrameAspectRatio == BVDB_P_ASPECT_RATIO_16_9) ? "16:9" :
2148        (ulFrameAspectRatio <= BVDB_P_ASPECT_RATIO_16_9) ? "4:3" : "other"));
2149    BDBG_MSG(("Display is %s", (pstDisplay->eAspectRatio == BVDB_AspectRatio_e16_9) ?
2150        "16:9" : ((pstDisplay->eAspectRatio == BVDB_AspectRatio_e4_3) ? "4:3" :
2151        "unknown")));
2152
2153    BDBG_MSG(("Display size (wxh) = %d x %d", ulDisplayWidth, ulDisplayHeight));
2154    BDBG_MSG(("Clipped source (wxh) = %d x %d", ulClippedWidth, ulClippedHeight));
2155
2156    BDBG_MSG(("Destination window size (wxh) = %d x %d", ulDestWidth, ulDestHeight));
2157    BDBG_MSG(("Clip Amount(in percent, wxh) = %d x %d", ulWidthClipAmount, ulHeightClipAmount));
2158
2159    /* evaluate if display is primary */
2160    if (BVDB_P_IsDisplayPrimary(pstDisplay->eType))
2161    {
2162        /* In case of 3D sources, searching a matched display mode does not make
2163         * sense because RTS is calculated for and fixed to one predefined
2164         * display mode which is FULL.1 for main and PIP.1 for secondary window
2165         * with an assumption of no cropping and (min window size == max window
2166         * size) */
2167        if (eInput == BVDB_Input_eHdDvi)
2168        {
2169            uint32_t i;
2170            uint32_t numEntry;
2171
2172            numEntry = sizeof(stNonPcNonStandardFormats) / sizeof(BVDB_P_NonPcNonStandardFomat);
2173            for (i = 0; i < numEntry; i++)
2174            {
2175                if ((ulSrcHeight == stNonPcNonStandardFormats[i].height) &&
2176                    (ulSrcWidth == stNonPcNonStandardFormats[i].width) &&
2177                    stNonPcNonStandardFormats[i].b3dSource)
2178                {
2179                    if (eWindow == BVDB_Window_eMain)
2180                    {
2181                        st3dDispMode.ulFull1 = 1;
2182                        st3dDispMode.ulFull2 = 1;
2183                        st3dDispMode.ulFull3 = 1;
2184                        st3dDispMode.ulFull4 = 1;
2185                        st3dDispMode.ulFull5 = 1;
2186                        st3dDispMode.ulFull6 = 1;
2187                        st3dDispMode.ulFull8 = 1;
2188                        st3dDispMode.ulFull9 = 1;
2189                        BDBG_MSG(("Could be 3D main and set to FULL.1/FULL.2/FULL.3/FULL.4/FULL.5/FULL.6/FULL.8/FULL.9"));;
2190                    }
2191                    else
2192                    {
2193                        st3dDispMode.ulPip1  = 1;
2194                        BDBG_MSG(("Could be 3D PIP and set to PIP.1"));;
2195                    }
2196                    break;
2197                }
2198            }
2199        }
2200
2201        /* evaluate if window is main or pip */
2202        if (eWindow == BVDB_Window_eMain)
2203        {
2204            /* Check for cases that satisfies dot-by-dot and return FULL.7. The RTS should satisfy
2205             * PIG.2 as well for most configs.
2206             *
2207             * Note, that there are some configs that have different RTS for dot-by-dot and
2208             * PIG.2. However, the PIG size for those configs are different than the dot-by-dot
2209             * size hence the display mode will be returned accordingly.
2210             */
2211            if (ulDestWidth == ulClippedWidth && ulDestHeight == ulClippedHeight &&
2212                ulClippedWidth <= ulDisplayWidth && ulClippedHeight <= ulDisplayHeight &&
2213                ulHeightClipAmount <= stCfgVidDispModes.astFullModes[6].stVideoDisplayMode.ulSrcHeightClipAmount &&
2214                ulWidthClipAmount <=  stCfgVidDispModes.astFullModes[6].stVideoDisplayMode.ulSrcWidthClipAmount &&
2215                stCfgVidDispModes.astFullModes[6].bEnabled)
2216            {
2217                pstDispMode->ulFull7 = 1;
2218            }
2219            /* Check for PBP case */
2220            else if (((BVDB_PipType) ePipType == BVDB_PipType_ePbp) &&
2221                      stCfgVidDispModes.astPipModes[1].bEnabled)
2222            {
2223                pstDispMode->ulPip2 = 1;
2224            }
2225            else /* Check for FULL modes */
2226            {
2227                for (k=0; k<BVDB_P_NUM_FULL_MODES; k++)
2228                {
2229                    switch (eDisplaySrcAs)
2230                    {
2231                        case BVDB_DisplaySourceAs_eFull:
2232                            ulDispMinH = ulDispMaxH = (ulDisplayHeight *
2233                                stCfgVidDispModes.astFullModes[k].stVideoDisplayMode.ulMaxWinHeight)/100;
2234                            ulDispMinW = ulDispMaxW = (ulDisplayWidth *
2235                                    stCfgVidDispModes.astFullModes[k].stVideoDisplayMode.ulMaxWinWidth)/100;
2236                            break;
2237                        case BVDB_DisplaySourceAs_ePillarbox:
2238                            ulDispMinH = ulDispMaxH = (ulDisplayHeight *
2239                                stCfgVidDispModes.astFullModes[k].stVideoDisplayMode.ulMaxWinHeight)/100;
2240                            ulDispMinW = (ulDisplayWidth *
2241                                stCfgVidDispModes.astFullModes[k].stVideoDisplayMode.ulMinWinWidth)/100;
2242                            ulDispMaxW = (ulDisplayWidth *
2243                                stCfgVidDispModes.astFullModes[k].stVideoDisplayMode.ulMaxWinWidth)/100;
2244                            break;
2245                        case BVDB_DisplaySourceAs_eLetterbox:
2246                            ulDispMinH = (ulDisplayHeight *
2247                                stCfgVidDispModes.astFullModes[k].stVideoDisplayMode.ulMinWinHeight)/100;
2248                            ulDispMaxH = (ulDisplayHeight *
2249                                stCfgVidDispModes.astFullModes[k].stVideoDisplayMode.ulMaxWinHeight)/100;
2250                            ulDispMinW = ulDispMaxW = (ulDisplayWidth *
2251                                    stCfgVidDispModes.astFullModes[k].stVideoDisplayMode.ulMaxWinWidth)/100;
2252                            break;
2253                        default:
2254                            ulDispMinH = (ulDisplayHeight *
2255                                stCfgVidDispModes.astFullModes[k].stVideoDisplayMode.ulMinWinHeight)/100;
2256
2257                            ulDispMinW = (ulDisplayWidth *
2258                                stCfgVidDispModes.astFullModes[k].stVideoDisplayMode.ulMinWinWidth)/100;
2259
2260                            ulDispMaxH = (ulDisplayHeight *
2261                                stCfgVidDispModes.astFullModes[k].stVideoDisplayMode.ulMaxWinHeight)/100;
2262
2263                            ulDispMaxW = (ulDisplayWidth *
2264                                stCfgVidDispModes.astFullModes[k].stVideoDisplayMode.ulMaxWinWidth)/100;
2265                    }
2266
2267                    if (ulDestHeight >= ulDispMinH && ulDestHeight <= ulDispMaxH &&
2268                        ulDestWidth >= ulDispMinW && ulDestWidth <= ulDispMaxW  &&
2269                        stCfgVidDispModes.astFullModes[k].bEnabled)
2270                    {
2271                        BDBG_MSG(("Primary display %d's FULL window for FULL.%d", pstDisplay->eType, k+1));
2272
2273                        /* compare clip amounts and display source as */
2274                        ulModeSrcHeightClipAmount = stCfgVidDispModes.astFullModes[k].stVideoDisplayMode.ulSrcHeightClipAmount;
2275                        ulModeSrcWidthClipAmount = stCfgVidDispModes.astFullModes[k].stVideoDisplayMode.ulSrcWidthClipAmount;
2276
2277                        BDBG_MSG(("ulModeSrcHeightClipAmount = %d", ulModeSrcHeightClipAmount));
2278                        BDBG_MSG(("ulHeightClipAmount = %d", ulHeightClipAmount));
2279                        BDBG_MSG(("ulModeSrcWidthClipAmount = %d", ulModeSrcWidthClipAmount));
2280                        BDBG_MSG(("ulWidthClipAmount = %d", ulWidthClipAmount));
2281
2282                        if (ulHeightClipAmount <= ulModeSrcHeightClipAmount &&
2283                            ulWidthClipAmount <= ulModeSrcWidthClipAmount)
2284                        {
2285                            BVDB_VideoDisplayModeInfo stInfo = stCfgVidDispModes.astFullModes[k].stVideoDisplayMode;
2286
2287                            ulClipHeightDiff = ulModeSrcHeightClipAmount - ulHeightClipAmount;
2288                            ulClipWidthDiff = ulModeSrcWidthClipAmount - ulWidthClipAmount;
2289
2290                            BDBG_MSG(("ulClipHeightDiff = %d", ulClipHeightDiff));
2291                            BDBG_MSG(("ulClipWidthDiff = %d", ulClipWidthDiff));
2292                            BDBG_MSG(("ulPrevClipHeightDiff = %d", ulPrevClipHeightDiff));
2293                            BDBG_MSG(("ulPrevClipWidthDiff = %d", ulPrevClipWidthDiff));
2294
2295                            /* get closest clip amount match */
2296                            if (ulClipHeightDiff <= ulPrevClipHeightDiff &&
2297                                ulClipWidthDiff <= ulPrevClipWidthDiff)
2298                            {
2299                                bool bFoundMode = false;
2300
2301                                if (ulFrameAspectRatio >= BVDB_P_ASPECT_RATIO_16_9)
2302                                {
2303                                    if (pstDisplay->eAspectRatio == BVDB_AspectRatio_e16_9)
2304                                    {
2305                                        if ((*pDisplayedAspectRatio == BFMT_AspectRatio_e16_9 ||
2306                                            *pDisplayedAspectRatio == BFMT_AspectRatio_e4_3) &&
2307                                            eDisplaySrcAs == stInfo.eDisplay16_9SrcOn16_9Display)
2308                                        {
2309                                            *((uint32_t *)pstDispMode) = (0x1 << k);
2310                                            bFoundMode = true;
2311                                        }
2312                                    }
2313                                    else if (pstDisplay->eAspectRatio == BVDB_AspectRatio_e4_3)
2314                                    {
2315                                        if ((*pDisplayedAspectRatio == BFMT_AspectRatio_e16_9 ||
2316                                            *pDisplayedAspectRatio == BFMT_AspectRatio_e4_3) &&
2317                                            eDisplaySrcAs == stInfo.eDisplay16_9SrcOn4_3Display)
2318                                        {
2319                                            *((uint32_t *)pstDispMode) = (0x1 << k);
2320                                            bFoundMode = true;
2321                                        }
2322                                    }
2323                                }
2324                                else if (ulFrameAspectRatio < BVDB_P_ASPECT_RATIO_16_9)
2325                                {
2326                                    if (pstDisplay->eAspectRatio == BVDB_AspectRatio_e16_9)
2327                                    {
2328                                        if ((*pDisplayedAspectRatio == BFMT_AspectRatio_e16_9 ||
2329                                            *pDisplayedAspectRatio == BFMT_AspectRatio_e4_3) &&
2330                                            eDisplaySrcAs == stInfo.eDisplay4_3SrcOn16_9dDisplay)
2331                                        {
2332                                            *((uint32_t *)pstDispMode) = (0x1 << k);
2333                                            bFoundMode = true;
2334                                        }
2335                                    }
2336                                    else if (pstDisplay->eAspectRatio == BVDB_AspectRatio_e4_3)
2337                                    {
2338                                        if ((*pDisplayedAspectRatio == BFMT_AspectRatio_e16_9 ||
2339                                            *pDisplayedAspectRatio == BFMT_AspectRatio_e4_3) &&
2340                                            eDisplaySrcAs == stInfo.eDisplay4_3SrcOn4_3Display)
2341                                        {
2342                                            *((uint32_t *)pstDispMode) = (0x1 << k);
2343                                            bFoundMode = true;
2344                                        }
2345                                    }
2346                                }
2347
2348                                if (bFoundMode)
2349                                {
2350                                    ulPrevClipHeightDiff = ulClipHeightDiff;
2351                                    ulPrevClipWidthDiff = ulClipWidthDiff;
2352                                }
2353                            }
2354                        }
2355                    }
2356                }
2357
2358                /* Check for PIG Modes */
2359                if (*((uint32_t *)pstDispMode) == 0)
2360                {
2361                    /* reset */
2362                    ulPrevClipHeightDiff = BVDB_P_MAX_SRC_CLIP_HEIGHT_AMOUNT;
2363                    ulPrevClipWidthDiff = BVDB_P_MAX_SRC_CLIP_WIDTH_AMOUNT;
2364
2365                    for (k = BVDB_P_NUM_FULL_MODES;
2366                         k < BVDB_P_NUM_FULL_MODES + BVDB_P_NUM_PIG_MODES;
2367                        k++)
2368                    {
2369
2370                        BDBG_MSG(("Primary display %d's PIG.%d window", pstDisplay->eType, (k+1)-BVDB_P_NUM_FULL_MODES));
2371
2372                        ulModeSrcHeightClipAmount = stCfgVidDispModes.astPigModes[k-BVDB_P_NUM_FULL_MODES].stVideoDisplayMode.ulSrcHeightClipAmount;
2373                        ulModeSrcWidthClipAmount = stCfgVidDispModes.astPigModes[k-BVDB_P_NUM_FULL_MODES].stVideoDisplayMode.ulSrcWidthClipAmount;
2374
2375                        BDBG_MSG(("ulModeSrcHeightClipAmount = %d", ulModeSrcHeightClipAmount));
2376                        BDBG_MSG(("ulHeightClipAmount = %d", ulHeightClipAmount));
2377                        BDBG_MSG(("ulModeSrcWidthClipAmount = %d", ulModeSrcWidthClipAmount));
2378                        BDBG_MSG(("ulWidthClipAmount = %d", ulWidthClipAmount));
2379
2380                        if (ulHeightClipAmount <= ulModeSrcHeightClipAmount &&
2381                            ulWidthClipAmount <= ulModeSrcWidthClipAmount)
2382                        {
2383                            uint32_t ulTempMinH, ulTempMinW, ulTempMaxH, ulTempMaxW;
2384
2385                            BDBG_MSG(("ulClipHeightDiff = %d", ulClipHeightDiff));
2386                            BDBG_MSG(("ulClipWidthDiff = %d", ulClipWidthDiff));
2387                            BDBG_MSG(("ulPrevClipHeightDiff = %d", ulPrevClipHeightDiff));
2388                            BDBG_MSG(("ulPrevClipWidthDiff = %d", ulPrevClipWidthDiff));
2389
2390                            ulTempMinH = (ulDisplayHeight *
2391                                stCfgVidDispModes.astPigModes[k-BVDB_P_NUM_FULL_MODES].stVideoDisplayMode.ulMinWinHeight)/100;
2392
2393                            ulTempMinW = (ulDisplayWidth *
2394                                stCfgVidDispModes.astPigModes[k-BVDB_P_NUM_FULL_MODES].stVideoDisplayMode.ulMinWinWidth)/100;
2395
2396                            ulTempMaxH = (ulDisplayHeight *
2397                                stCfgVidDispModes.astPigModes[k-BVDB_P_NUM_FULL_MODES].stVideoDisplayMode.ulMaxWinHeight)/100;
2398
2399                            ulTempMaxW = (ulDisplayWidth *
2400                                stCfgVidDispModes.astPigModes[k-BVDB_P_NUM_FULL_MODES].stVideoDisplayMode.ulMaxWinWidth)/100;
2401
2402
2403                            BDBG_MSG(("ulTempMinH = %d", ulTempMinH));
2404                            BDBG_MSG(("ulTempMinW = %d", ulTempMinW));
2405                            BDBG_MSG(("ulTempMaxH = %d", ulTempMaxH));
2406                            BDBG_MSG(("ulTempMaxW = %d", ulTempMaxW));
2407
2408                            if  (ulDestHeight >= ulTempMinH && ulDestWidth >= ulTempMinW &&
2409                                 ulDestHeight <= ulTempMaxH && ulDestWidth <= ulTempMaxW)
2410                            {
2411                                ulClipHeightDiff = ulModeSrcHeightClipAmount - ulHeightClipAmount;
2412                                ulClipWidthDiff = ulModeSrcWidthClipAmount - ulWidthClipAmount;
2413
2414                                /* get closest clip amount match */
2415                                if (ulClipHeightDiff <= ulPrevClipHeightDiff &&
2416                                    ulClipWidthDiff <= ulPrevClipWidthDiff &&
2417                                    stCfgVidDispModes.astPigModes[k-BVDB_P_NUM_FULL_MODES].bEnabled)
2418                                {
2419                                    ulPrevClipHeightDiff = ulClipHeightDiff;
2420                                    ulPrevClipWidthDiff = ulClipWidthDiff;
2421
2422                                    *((uint32_t *)pstDispMode) = (0x1 << k);
2423                                    *pDisplayedAspectRatio = BFMT_AspectRatio_eUnknown;
2424                                }
2425                            }
2426                        }
2427                    }
2428                }
2429            }
2430        }
2431        else /* PIP */
2432        {
2433
2434            for (k = BVDB_P_NUM_FULL_MODES + BVDB_P_NUM_PIG_MODES;
2435                 k < BVDB_P_NUM_FULL_MODES + BVDB_P_NUM_PIG_MODES + BVDB_P_NUM_PIP_MODES;
2436                 k++)
2437            {
2438                BDBG_MSG(("Primary display %d's PIP.%d window", pstDisplay->eType, (k+1)-BVDB_P_NUM_FULL_MODES-BVDB_P_NUM_PIG_MODES));
2439
2440
2441                /* compare clip amounts and if PIP2, destination size as well */
2442                ulModeSrcHeightClipAmount = stCfgVidDispModes.astPipModes[k-(BVDB_P_NUM_FULL_MODES + BVDB_P_NUM_PIG_MODES)].stVideoDisplayMode.ulSrcHeightClipAmount;
2443                ulModeSrcWidthClipAmount = stCfgVidDispModes.astPipModes[k-(BVDB_P_NUM_FULL_MODES + BVDB_P_NUM_PIG_MODES)].stVideoDisplayMode.ulSrcWidthClipAmount;
2444
2445                BDBG_MSG(("ulModeSrcHeightClipAmount = %d, ulModeSrcWidthClipAmount  = %d", ulModeSrcHeightClipAmount, ulModeSrcWidthClipAmount));
2446                BDBG_MSG(("ulHeightClipAmount  = %d, ulWidthClipAmount = %d", ulHeightClipAmount, ulWidthClipAmount));
2447
2448                if (ulHeightClipAmount <= ulModeSrcHeightClipAmount &&
2449                    ulWidthClipAmount <= ulModeSrcWidthClipAmount)
2450                {
2451                    ulClipHeightDiff = ulModeSrcHeightClipAmount - ulHeightClipAmount;
2452                    ulClipWidthDiff = ulModeSrcWidthClipAmount - ulWidthClipAmount;
2453
2454                    /* get closest clip amount match */
2455                    if (ulClipHeightDiff < ulPrevClipHeightDiff &&
2456                        ulClipWidthDiff < ulPrevClipWidthDiff &&
2457                        stCfgVidDispModes.astPipModes[k-(BVDB_P_NUM_FULL_MODES + BVDB_P_NUM_PIG_MODES)].bEnabled)
2458                    {
2459                        ulPrevClipHeightDiff = ulClipHeightDiff;
2460                        ulPrevClipWidthDiff = ulClipWidthDiff;
2461                        *((uint32_t *)pstDispMode) = (0x1 << k);
2462                        *pDisplayedAspectRatio = BFMT_AspectRatio_eUnknown;
2463                    }
2464                }
2465            }
2466        }
2467
2468        * pulDispMode |= * pul3dDispMode;
2469    }
2470    else /* Secondary display */
2471    {
2472        for (k = BVDB_P_NUM_FULL_MODES + BVDB_P_NUM_PIG_MODES + BVDB_P_NUM_PIP_MODES;
2473             k < BVDB_P_NUM_FULL_MODES + BVDB_P_NUM_PIG_MODES + BVDB_P_NUM_PIP_MODES + BVDB_P_NUM_MON_MODES;
2474             k++)
2475        {
2476            BDBG_MSG(("Secondary display, MONITOR.%d window", (k+1)-(BVDB_P_NUM_FULL_MODES + BVDB_P_NUM_PIG_MODES + BVDB_P_NUM_PIP_MODES)));
2477
2478            /* compare clip amounts */
2479            ulModeSrcHeightClipAmount = stCfgVidDispModes.astMonitorModes[k-(BVDB_P_NUM_FULL_MODES +
2480                                                    BVDB_P_NUM_PIG_MODES +
2481                                                    BVDB_P_NUM_PIP_MODES)].stVideoDisplayMode.ulSrcHeightClipAmount;
2482            ulModeSrcWidthClipAmount = stCfgVidDispModes.astMonitorModes[k-(BVDB_P_NUM_FULL_MODES +
2483                                                    BVDB_P_NUM_PIG_MODES +
2484                                                    BVDB_P_NUM_PIP_MODES)].stVideoDisplayMode.ulSrcWidthClipAmount;
2485
2486            if (ulHeightClipAmount <= ulModeSrcHeightClipAmount &&
2487                ulWidthClipAmount <= ulModeSrcWidthClipAmount)
2488            {
2489                ulClipHeightDiff = ulModeSrcHeightClipAmount - ulHeightClipAmount;
2490                ulClipWidthDiff = ulModeSrcWidthClipAmount - ulWidthClipAmount;
2491
2492                /* get closest clip amount match */
2493                if (ulClipHeightDiff <= ulPrevClipHeightDiff &&
2494                    ulClipWidthDiff <= ulPrevClipWidthDiff &&
2495                    stCfgVidDispModes.astMonitorModes[k-(BVDB_P_NUM_FULL_MODES +
2496                                                    BVDB_P_NUM_PIG_MODES +
2497                                                    BVDB_P_NUM_PIP_MODES)].bEnabled)
2498                {
2499                    bool bFoundMode = false;
2500                    BVDB_VideoDisplayModeInfo stInfo = stCfgVidDispModes.astMonitorModes[k-(BVDB_P_NUM_FULL_MODES +
2501                                                    BVDB_P_NUM_PIG_MODES +
2502                                                    BVDB_P_NUM_PIP_MODES)].stVideoDisplayMode;
2503
2504
2505                    if (*pDisplayedAspectRatio == BFMT_AspectRatio_e4_3 &&
2506                        eDisplaySrcAs == stInfo.eDisplay4_3SrcOn4_3Display)
2507                    {
2508                        if (eInput == BVDB_Input_eMfd)
2509                        {
2510                            pstDispMode->ulMon1 = 1;
2511                        }
2512                        else
2513                        {
2514                            *((uint32_t *)pstDispMode) |= (0x1 << k);
2515                        }
2516                        bFoundMode = true;
2517                    }
2518                    else if (*pDisplayedAspectRatio == BFMT_AspectRatio_e16_9 &&
2519                            eDisplaySrcAs == stInfo.eDisplay16_9SrcOn4_3Display)
2520                    {
2521                        if (eInput == BVDB_Input_eMfd)
2522                        {
2523                            pstDispMode->ulMon3 = 1;
2524                        }
2525                        else
2526                        {
2527                            *((uint32_t *)pstDispMode) |= (0x1 << k);
2528                        }
2529                        bFoundMode = true;
2530                    }
2531
2532                    if (bFoundMode)
2533                    {
2534                        ulPrevClipHeightDiff = ulClipHeightDiff;
2535                        ulPrevClipWidthDiff = ulClipWidthDiff;
2536                    }
2537                }
2538            }
2539        }
2540    }
2541
2542    BDBG_MSG(("\tVideo Display Mode = 0x%x", *((uint32_t *)pstDispMode)));
2543
2544    if (BVDB_DISP_MODE_IS_FULL(pstDispMode) == 0 &&
2545        BVDB_DISP_MODE_IS_PIG(pstDispMode) == 0 &&
2546        BVDB_DISP_MODE_IS_PIP(pstDispMode) == 0 &&
2547        BVDB_DISP_MODE_IS_MON(pstDispMode) == 0)
2548    {
2549        *pDisplayedAspectRatio = BFMT_AspectRatio_eUnknown;
2550        BDBG_ERR(("No video display mode found."));
2551        err = BERR_INVALID_PARAMETER;
2552    }
2553
2554    return BERR_TRACE(err);
2555}
2556
Note: See TracBrowser for help on using the repository browser.