| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2004-2011, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: bsynclib.c $ |
|---|
| 11 | * $brcm_Revision: Hydra_Software_Devel/9 $ |
|---|
| 12 | * $brcm_Date: 7/8/11 2:40p $ |
|---|
| 13 | * |
|---|
| 14 | * Revision History: |
|---|
| 15 | * |
|---|
| 16 | * $brcm_Log: /magnum/syslib/synclib/noarch/bsynclib.c $ |
|---|
| 17 | * |
|---|
| 18 | * Hydra_Software_Devel/9 7/8/11 2:40p bandrews |
|---|
| 19 | * SW7405-3884: punch RMD settings through properly, hParent wasn't set |
|---|
| 20 | * during create |
|---|
| 21 | * |
|---|
| 22 | * Hydra_Software_Devel/8 7/2/10 6:04p bandrews |
|---|
| 23 | * SW7405-4436: added channel index to algo debug messages |
|---|
| 24 | * |
|---|
| 25 | * Hydra_Software_Devel/7 5/28/10 6:31p bandrews |
|---|
| 26 | * SW7405-4436: printing channel index in dbg messages |
|---|
| 27 | * |
|---|
| 28 | * Hydra_Software_Devel/6 3/22/10 5:44p bandrews |
|---|
| 29 | * sw7408-83: add unconditional video unmute |
|---|
| 30 | * |
|---|
| 31 | * Hydra_Software_Devel/5 3/5/10 8:04p bandrews |
|---|
| 32 | * SW7325-688: default full screen required to false |
|---|
| 33 | * |
|---|
| 34 | * Hydra_Software_Devel/4 7/24/09 4:15p bandrews |
|---|
| 35 | * PR48566: support preferred units |
|---|
| 36 | * |
|---|
| 37 | * Hydra_Software_Devel/3 10/30/08 10:34p bandrews |
|---|
| 38 | * PR48566: Added support for preferred callback units |
|---|
| 39 | * |
|---|
| 40 | * Hydra_Software_Devel/2 4/3/08 2:33p bandrews |
|---|
| 41 | * PR40090: synclib needs to have different contexts for syslib callbacks |
|---|
| 42 | * and synclib callbacks |
|---|
| 43 | * |
|---|
| 44 | * Hydra_Software_Devel/1 3/24/08 3:09p bandrews |
|---|
| 45 | * PR40865: Fixed |
|---|
| 46 | * |
|---|
| 47 | * Hydra_Software_Devel/2 1/3/08 5:17p bandrews |
|---|
| 48 | * PR37951: Updated based on initial feedback |
|---|
| 49 | * |
|---|
| 50 | * Hydra_Software_Devel/1 12/12/07 2:53p bandrews |
|---|
| 51 | * PR37951: Initial check-in |
|---|
| 52 | ***************************************************************************/ |
|---|
| 53 | |
|---|
| 54 | #include "bstd.h" |
|---|
| 55 | #include "bsyslib_list.h" |
|---|
| 56 | #include "bsynclib.h" |
|---|
| 57 | #include "bsynclib_priv.h" |
|---|
| 58 | #include "bsynclib_channel_priv.h" |
|---|
| 59 | |
|---|
| 60 | BDBG_MODULE(synclib); |
|---|
| 61 | |
|---|
| 62 | /* |
|---|
| 63 | Summary: |
|---|
| 64 | Returns the default global SYNC lib module settings |
|---|
| 65 | Description: |
|---|
| 66 | */ |
|---|
| 67 | void BSYNClib_GetDefaultSettings( |
|---|
| 68 | BSYNClib_Settings * psSettings /* [out] */ |
|---|
| 69 | ) |
|---|
| 70 | { |
|---|
| 71 | BDBG_ENTER(BSYNClib_GetDefaultSettings); |
|---|
| 72 | |
|---|
| 73 | BDBG_ASSERT(psSettings); |
|---|
| 74 | |
|---|
| 75 | psSettings->bEnabled = true; |
|---|
| 76 | psSettings->sVideo.bRequireFullScreen = false; |
|---|
| 77 | psSettings->sVideo.uiTsmLockTimeout = BSYNCLIB_VIDEO_TSM_LOCK_TIMER_DEFAULT_TIMEOUT; |
|---|
| 78 | psSettings->sVideo.uiUnmuteTimeout = BSYNCLIB_VIDEO_UNMUTE_DEFAULT_TIMEOUT; |
|---|
| 79 | psSettings->sVideo.uiUnconditionalUnmuteTimeout = BSYNCLIB_VIDEO_UNCONDITIONAL_UNMUTE_DEFAULT_TIMEOUT; |
|---|
| 80 | psSettings->sVideo.sRateMismatchDetection.uiTimeout = BSYNCLIB_VIDEO_RATE_MISMATCH_DETECTION_TIMER_DEFAULT_TIMEOUT; |
|---|
| 81 | psSettings->sVideo.sRateMismatchDetection.uiAcceptableMtbcLower = BSYNCLIB_VIDEO_RATE_MISMATCH_DETECTION_DEFAULT_ACCEPTABLE_MTBC_LOWER; |
|---|
| 82 | psSettings->sVideo.sRateMismatchDetection.uiAcceptableMtbcUpper = BSYNCLIB_VIDEO_RATE_MISMATCH_DETECTION_DEFAULT_ACCEPTABLE_MTBC_UPPER; |
|---|
| 83 | psSettings->sVideo.sRateMismatchDetection.uiAcceptableTtlc = BSYNCLIB_VIDEO_RATE_MISMATCH_DETECTION_DEFAULT_ACCEPTABLE_TTLC; |
|---|
| 84 | psSettings->sVideo.sRateRematchDetection.uiTimeout = BSYNCLIB_VIDEO_RATE_REMATCH_DETECTION_TIMER_DEFAULT_TIMEOUT; |
|---|
| 85 | psSettings->sVideo.sRateRematchDetection.uiAcceptableTtlc = BSYNCLIB_VIDEO_RATE_REMATCH_DETECTION_DEFAULT_ACCEPTABLE_TTLC; |
|---|
| 86 | psSettings->sAudio.uiUnmuteTimeout = BSYNCLIB_AUDIO_UNMUTE_DEFAULT_TIMEOUT; |
|---|
| 87 | psSettings->sAudio.uiReceiverDelayCompensation = BSYNCLIB_AUDIO_RECEIVER_DELAY_COMPENSATION_DEFAULT; |
|---|
| 88 | psSettings->sAudio.uiUnconditionalUnmuteTimeout = BSYNCLIB_AUDIO_UNCONDITIONAL_UNMUTE_DEFAULT_TIMEOUT; |
|---|
| 89 | |
|---|
| 90 | BDBG_LEAVE(BSYNClib_GetDefaultSettings); |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | /* |
|---|
| 94 | Summary: |
|---|
| 95 | Opens the global SYNC lib module |
|---|
| 96 | Description: |
|---|
| 97 | */ |
|---|
| 98 | BERR_Code BSYNClib_Open( |
|---|
| 99 | const BSYNClib_Settings * psSettings, |
|---|
| 100 | BSYNClib_Handle * phSync /* [out] */ |
|---|
| 101 | ) |
|---|
| 102 | { |
|---|
| 103 | BERR_Code rc = BERR_SUCCESS; |
|---|
| 104 | BSYNClib_Handle hSync = NULL; |
|---|
| 105 | |
|---|
| 106 | BDBG_ENTER(BSYNClib_Open); |
|---|
| 107 | |
|---|
| 108 | BDBG_ASSERT(phSync); |
|---|
| 109 | |
|---|
| 110 | hSync = (BSYNClib_Handle)BKNI_Malloc(sizeof(struct BSYNClib_Impl)); |
|---|
| 111 | if (!hSync) |
|---|
| 112 | { |
|---|
| 113 | rc = BERR_OUT_OF_SYSTEM_MEMORY; |
|---|
| 114 | *phSync = NULL; |
|---|
| 115 | goto end; |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | BKNI_Memset(hSync, 0, sizeof(struct BSYNClib_Impl)); |
|---|
| 119 | |
|---|
| 120 | if (psSettings) |
|---|
| 121 | { |
|---|
| 122 | hSync->sSettings = *psSettings; |
|---|
| 123 | } |
|---|
| 124 | else |
|---|
| 125 | { |
|---|
| 126 | BSYNClib_GetDefaultSettings(&hSync->sSettings); |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | if (BSYNClib_P_Enabled(hSync)) |
|---|
| 130 | { |
|---|
| 131 | hSync->hChannels = BSYSlib_List_Create(); |
|---|
| 132 | |
|---|
| 133 | BDBG_MSG(("Settings Summary:")); |
|---|
| 134 | BDBG_MSG((" sync correction: %s", hSync->sSettings.bEnabled ? "enabled" : "disabled")); |
|---|
| 135 | BDBG_MSG((" video")); |
|---|
| 136 | BDBG_MSG((" full screen: %s", hSync->sSettings.sVideo.bRequireFullScreen ? "required" : "not required")); |
|---|
| 137 | BDBG_MSG((" TSM lock timeout: %d milliseconds", hSync->sSettings.sVideo.uiTsmLockTimeout)); |
|---|
| 138 | BDBG_MSG((" unmute timeout: %d milliseconds", hSync->sSettings.sVideo.uiUnmuteTimeout)); |
|---|
| 139 | BDBG_MSG((" unconditional unmute timeout: %d milliseconds", hSync->sSettings.sVideo.uiUnconditionalUnmuteTimeout)); |
|---|
| 140 | BDBG_MSG((" rate mismatch detection")); |
|---|
| 141 | BDBG_MSG((" timeout: %d milliseconds", hSync->sSettings.sVideo.sRateMismatchDetection.uiTimeout)); |
|---|
| 142 | BDBG_MSG((" acceptable mtbc lower bound: %d milliseconds", hSync->sSettings.sVideo.sRateMismatchDetection.uiAcceptableMtbcLower)); |
|---|
| 143 | BDBG_MSG((" acceptable mtbc upper bound: %d milliseconds", hSync->sSettings.sVideo.sRateMismatchDetection.uiAcceptableMtbcUpper)); |
|---|
| 144 | BDBG_MSG((" acceptable ttlc: %d milliseconds", hSync->sSettings.sVideo.sRateMismatchDetection.uiAcceptableTtlc)); |
|---|
| 145 | BDBG_MSG((" rate rematch detection")); |
|---|
| 146 | BDBG_MSG((" timeout: %d milliseconds", hSync->sSettings.sVideo.sRateRematchDetection.uiTimeout)); |
|---|
| 147 | BDBG_MSG((" acceptable ttlc: %d milliseconds", hSync->sSettings.sVideo.sRateRematchDetection.uiAcceptableTtlc)); |
|---|
| 148 | BDBG_MSG((" audio")); |
|---|
| 149 | BDBG_MSG((" unmute timeout: %d milliseconds", hSync->sSettings.sAudio.uiUnmuteTimeout)); |
|---|
| 150 | BDBG_MSG((" unconditional unmute timeout: %d milliseconds", hSync->sSettings.sAudio.uiUnconditionalUnmuteTimeout)); |
|---|
| 151 | BDBG_MSG((" receiver delay compensation: %d milliseconds", hSync->sSettings.sAudio.uiReceiverDelayCompensation)); |
|---|
| 152 | } |
|---|
| 153 | else |
|---|
| 154 | { |
|---|
| 155 | BDBG_MSG(("Settings Summary:")); |
|---|
| 156 | BDBG_MSG((" sync correction: %s", BSYNClib_P_Enabled(hSync) ? "enabled" : "disabled")); |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | *phSync = hSync; |
|---|
| 160 | |
|---|
| 161 | end: |
|---|
| 162 | |
|---|
| 163 | BDBG_LEAVE(BSYNClib_Open); |
|---|
| 164 | return rc; |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | /* |
|---|
| 169 | Summary: |
|---|
| 170 | Closes the global SYNC lib module |
|---|
| 171 | Description: |
|---|
| 172 | */ |
|---|
| 173 | void BSYNClib_Close( |
|---|
| 174 | BSYNClib_Handle hSync |
|---|
| 175 | ) |
|---|
| 176 | { |
|---|
| 177 | BSYNClib_Channel_Handle hChn; |
|---|
| 178 | BSYSlib_List_IteratorHandle hIterator; |
|---|
| 179 | |
|---|
| 180 | BDBG_ENTER(BSYNClib_Close); |
|---|
| 181 | |
|---|
| 182 | BDBG_ASSERT(hSync); |
|---|
| 183 | |
|---|
| 184 | if (BSYNClib_P_Enabled(hSync)) |
|---|
| 185 | { |
|---|
| 186 | hIterator = BSYSlib_List_AcquireIterator(hSync->hChannels); |
|---|
| 187 | |
|---|
| 188 | while (BSYSlib_List_HasNext(hIterator)) |
|---|
| 189 | { |
|---|
| 190 | hChn = (BSYNClib_Channel_Handle)BSYSlib_List_Next(hIterator); |
|---|
| 191 | BSYNClib_DestroyChannel(hSync, hChn); |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | BSYSlib_List_ReleaseIterator(hIterator); |
|---|
| 195 | |
|---|
| 196 | BSYSlib_List_Destroy(hSync->hChannels); |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | /* free me */ |
|---|
| 200 | BKNI_Free(hSync); |
|---|
| 201 | |
|---|
| 202 | BDBG_LEAVE(BSYNClib_Close); |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | #define BSYNCLIB_P_DEFAULT_SOURCE_PREFERRED_UNITS BSYNClib_Units_e45KhzTicks |
|---|
| 206 | #define BSYNCLIB_P_DEFAULT_VIDEO_SINK_PREFERRED_UNITS BSYNClib_Units_e60HzVsyncs |
|---|
| 207 | #define BSYNCLIB_P_DEFAULT_AUDIO_SINK_PREFERRED_UNITS BSYNClib_Units_eMilliseconds |
|---|
| 208 | |
|---|
| 209 | /* |
|---|
| 210 | Summary: |
|---|
| 211 | Returns the default settings for the specified channel index |
|---|
| 212 | Description: |
|---|
| 213 | */ |
|---|
| 214 | void BSYNClib_GetChannelDefaultSettings( |
|---|
| 215 | BSYNClib_Channel_Settings * psSettings /* default channel settings [out] */ |
|---|
| 216 | ) |
|---|
| 217 | { |
|---|
| 218 | BDBG_ENTER(BSYNClib_GetChannelDefaultSettings); |
|---|
| 219 | |
|---|
| 220 | BDBG_ASSERT(psSettings); |
|---|
| 221 | |
|---|
| 222 | BKNI_Memset(psSettings, 0, sizeof(BSYNClib_Channel_Settings)); |
|---|
| 223 | |
|---|
| 224 | psSettings->sVideo.sSource.cbDelay.preferredDelayUnits = BSYNCLIB_P_DEFAULT_SOURCE_PREFERRED_UNITS; |
|---|
| 225 | psSettings->sVideo.sSource.cbDelay.preferredNotificationThresholdUnits = BSYNCLIB_P_DEFAULT_SOURCE_PREFERRED_UNITS; |
|---|
| 226 | psSettings->sVideo.sSink.cbDelay.preferredDelayUnits = BSYNCLIB_P_DEFAULT_VIDEO_SINK_PREFERRED_UNITS; |
|---|
| 227 | psSettings->sVideo.sSink.cbDelay.preferredNotificationThresholdUnits = BSYNCLIB_P_DEFAULT_VIDEO_SINK_PREFERRED_UNITS; |
|---|
| 228 | psSettings->sAudio.sSource.cbDelay.preferredDelayUnits = BSYNCLIB_P_DEFAULT_SOURCE_PREFERRED_UNITS; |
|---|
| 229 | psSettings->sAudio.sSource.cbDelay.preferredNotificationThresholdUnits = BSYNCLIB_P_DEFAULT_SOURCE_PREFERRED_UNITS; |
|---|
| 230 | psSettings->sAudio.sSink.cbDelay.preferredDelayUnits = BSYNCLIB_P_DEFAULT_AUDIO_SINK_PREFERRED_UNITS; |
|---|
| 231 | psSettings->sAudio.sSink.cbDelay.preferredNotificationThresholdUnits = BSYNCLIB_P_DEFAULT_AUDIO_SINK_PREFERRED_UNITS; |
|---|
| 232 | |
|---|
| 233 | BDBG_LEAVE(BSYNClib_GetChannelDefaultSettings); |
|---|
| 234 | } |
|---|
| 235 | |
|---|
| 236 | /* |
|---|
| 237 | Summary: |
|---|
| 238 | Creates a SYNC lib channel |
|---|
| 239 | Description: |
|---|
| 240 | */ |
|---|
| 241 | BERR_Code BSYNClib_CreateChannel( |
|---|
| 242 | BSYNClib_Handle hSync, |
|---|
| 243 | const BSYNClib_Channel_Settings * psSettings, |
|---|
| 244 | BSYNClib_Channel_Handle * phChn /* [out] */ |
|---|
| 245 | ) |
|---|
| 246 | { |
|---|
| 247 | BERR_Code rc = BERR_SUCCESS; |
|---|
| 248 | BSYNClib_Channel_Handle hChn = NULL; |
|---|
| 249 | BSYNClib_Channel_Settings sSettings; |
|---|
| 250 | |
|---|
| 251 | BDBG_ENTER(BSYNClib_CreateChannel); |
|---|
| 252 | |
|---|
| 253 | BDBG_ASSERT(hSync); |
|---|
| 254 | BDBG_ASSERT(phChn); |
|---|
| 255 | |
|---|
| 256 | if (BSYNClib_P_Enabled(hSync)) |
|---|
| 257 | { |
|---|
| 258 | if (!psSettings) |
|---|
| 259 | { |
|---|
| 260 | BSYNClib_GetChannelDefaultSettings(&sSettings); |
|---|
| 261 | psSettings = &sSettings; |
|---|
| 262 | } |
|---|
| 263 | |
|---|
| 264 | rc = BSYNClib_Channel_P_Create(&hSync->sSettings, psSettings, &hChn); |
|---|
| 265 | if (rc) goto end; |
|---|
| 266 | |
|---|
| 267 | hChn->hParent = hSync; |
|---|
| 268 | |
|---|
| 269 | BSYSlib_List_AddElement(hSync->hChannels, hChn); |
|---|
| 270 | hChn->iIndex = BSYSlib_List_IndexOf(hSync->hChannels, hChn); |
|---|
| 271 | BDBG_MSG(("chn %p is index %d", hChn, hChn->iIndex)); |
|---|
| 272 | hChn->sVideo.hChn = hChn; |
|---|
| 273 | hChn->sAudio.hChn = hChn; |
|---|
| 274 | } |
|---|
| 275 | |
|---|
| 276 | *phChn = hChn; |
|---|
| 277 | |
|---|
| 278 | end: |
|---|
| 279 | |
|---|
| 280 | BDBG_LEAVE(BSYNClib_CreateChannel); |
|---|
| 281 | return rc; |
|---|
| 282 | } |
|---|
| 283 | |
|---|
| 284 | /* |
|---|
| 285 | Summary: |
|---|
| 286 | Closes a SYNC lib channel |
|---|
| 287 | Description: |
|---|
| 288 | */ |
|---|
| 289 | void BSYNClib_DestroyChannel( |
|---|
| 290 | BSYNClib_Handle hSync, |
|---|
| 291 | BSYNClib_Channel_Handle hChn |
|---|
| 292 | ) |
|---|
| 293 | { |
|---|
| 294 | BDBG_ENTER(BSYNClib_DestroyChannel); |
|---|
| 295 | |
|---|
| 296 | if (BSYNClib_P_Enabled(hSync)) |
|---|
| 297 | { |
|---|
| 298 | BDBG_ASSERT(hSync); |
|---|
| 299 | BDBG_ASSERT(hChn); |
|---|
| 300 | |
|---|
| 301 | BSYSlib_List_RemoveElement(hSync->hChannels, hChn); |
|---|
| 302 | |
|---|
| 303 | BSYNClib_Channel_P_Destroy(hChn); |
|---|
| 304 | } |
|---|
| 305 | |
|---|
| 306 | BDBG_LEAVE(BSYNClib_DestroyChannel); |
|---|
| 307 | } |
|---|
| 308 | |
|---|