| 1 | /*************************************************************************** |
|---|
| 2 | * (c)2007-2011 Broadcom Corporation |
|---|
| 3 | * |
|---|
| 4 | * This program is the proprietary software of Broadcom Corporation and/or its licensors, |
|---|
| 5 | * and may only be used, duplicated, modified or distributed pursuant to the terms and |
|---|
| 6 | * conditions of a separate, written license agreement executed between you and Broadcom |
|---|
| 7 | * (an "Authorized License"). Except as set forth in an Authorized License, Broadcom grants |
|---|
| 8 | * no license (express or implied), right to use, or waiver of any kind with respect to the |
|---|
| 9 | * Software, and Broadcom expressly reserves all rights in and to the Software and all |
|---|
| 10 | * intellectual property rights therein. IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU |
|---|
| 11 | * HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY |
|---|
| 12 | * NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE. |
|---|
| 13 | * |
|---|
| 14 | * Except as expressly set forth in the Authorized License, |
|---|
| 15 | * |
|---|
| 16 | * 1. This program, including its structure, sequence and organization, constitutes the valuable trade |
|---|
| 17 | * secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof, |
|---|
| 18 | * and to use this information only in connection with your use of Broadcom integrated circuit products. |
|---|
| 19 | * |
|---|
| 20 | * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" |
|---|
| 21 | * AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR |
|---|
| 22 | * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO |
|---|
| 23 | * THE SOFTWARE. BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES |
|---|
| 24 | * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, |
|---|
| 25 | * LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION |
|---|
| 26 | * OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF |
|---|
| 27 | * USE OR PERFORMANCE OF THE SOFTWARE. |
|---|
| 28 | * |
|---|
| 29 | * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS |
|---|
| 30 | * LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR |
|---|
| 31 | * EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR |
|---|
| 32 | * USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF |
|---|
| 33 | * THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT |
|---|
| 34 | * ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE |
|---|
| 35 | * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF |
|---|
| 36 | * ANY LIMITED REMEDY. |
|---|
| 37 | * |
|---|
| 38 | * $brcm_Workfile: nexus_astm.h $ |
|---|
| 39 | * $brcm_Revision: 11 $ |
|---|
| 40 | * $brcm_Date: 8/8/11 6:22p $ |
|---|
| 41 | * |
|---|
| 42 | * Module Description: |
|---|
| 43 | * |
|---|
| 44 | * Revision History: |
|---|
| 45 | * |
|---|
| 46 | * $brcm_Log: /nexus/modules/astm/7400/include/nexus_astm.h $ |
|---|
| 47 | * |
|---|
| 48 | * 11 8/8/11 6:22p bandrews |
|---|
| 49 | * SW3548-1159: merge timestamp check bool with max allowable diff; zero |
|---|
| 50 | * means disabled; nonzero means enabled |
|---|
| 51 | * |
|---|
| 52 | * 10 8/8/11 6:10p bandrews |
|---|
| 53 | * SW3548-1159: merge recovery API to main |
|---|
| 54 | * |
|---|
| 55 | * 9 8/8/11 6:04p bandrews |
|---|
| 56 | * SWDTV-7819: add support for tsm threshold adjustment |
|---|
| 57 | * |
|---|
| 58 | * 8 8/26/10 3:06p bandrews |
|---|
| 59 | * SW3556-1128: update comments in nexus_astm.h to reflect support for |
|---|
| 60 | * PVR/media |
|---|
| 61 | * |
|---|
| 62 | * 7 2/9/10 8:40p mphillip |
|---|
| 63 | * SW3548-1161: Tag with correct JIRA |
|---|
| 64 | * |
|---|
| 65 | * 6 2/9/10 8:36p mphillip |
|---|
| 66 | * SW3548-111: Expose additional tunable params from astmlib |
|---|
| 67 | * |
|---|
| 68 | * 5 1/20/09 9:34a erickson |
|---|
| 69 | * PR50938: merge |
|---|
| 70 | * |
|---|
| 71 | * PR50938/1 1/8/09 11:11p bandrews |
|---|
| 72 | * PR50938: Added capability to disable automatic lifecycle control |
|---|
| 73 | * |
|---|
| 74 | * 4 11/25/08 4:02p vsilyaev |
|---|
| 75 | * PR 40090: Fixed return type of NEXUS_Astm_Start |
|---|
| 76 | * |
|---|
| 77 | * 3 11/18/08 11:13a erickson |
|---|
| 78 | * PR35457: added overview |
|---|
| 79 | * |
|---|
| 80 | * 2 3/26/08 9:46p bandrews |
|---|
| 81 | * PR40090: stc channel must be passed to astm before video is started |
|---|
| 82 | * |
|---|
| 83 | * 1 3/24/08 3:16p bandrews |
|---|
| 84 | * PR40090: API changes |
|---|
| 85 | **************************************************************************/ |
|---|
| 86 | #ifndef NEXUS_ASTM_H__ |
|---|
| 87 | #define NEXUS_ASTM_H__ |
|---|
| 88 | |
|---|
| 89 | /*=*********************************** |
|---|
| 90 | Module Overview |
|---|
| 91 | |
|---|
| 92 | This interface allows the system to adapt to bad TSM environments including |
|---|
| 93 | bad PCR's, missing PCR's, bad PTS's, etc. ASTM monitors the system and moves |
|---|
| 94 | the decoders into and out of TSM mode as needed. The goal is to keep seeing |
|---|
| 95 | and hearing the audio and video with the best lispsync possible, even if TSM |
|---|
| 96 | is not possible. |
|---|
| 97 | |
|---|
| 98 | The ASTM algorithm can be summarized as follows: |
|---|
| 99 | |
|---|
| 100 | Presentation Control |
|---|
| 101 | - ASTM monitors both audio and video decoders looking for TSM failures. |
|---|
| 102 | - A TSM failure is defined as a certain number of PTS errors. The current |
|---|
| 103 | threshold is 10,but that is programmable. |
|---|
| 104 | - If both decoders are failing, ASTM will try a PTS master mode first. |
|---|
| 105 | - If only one decoder is failing, ASTM will enter directly into non-TSM |
|---|
| 106 | mode. |
|---|
| 107 | - If either decoder is still failing after trying a master mode, it will |
|---|
| 108 | switch to non-TSM mode. |
|---|
| 109 | |
|---|
| 110 | Clock Recovery |
|---|
| 111 | - ASTM monitors the receipt of PCRs looking for high jitter |
|---|
| 112 | - The jitter tolerance threshold and consecutive out-of-tolerance counter |
|---|
| 113 | are programmable. |
|---|
| 114 | - If the incoming clock reference has high jitter, ASTM will decouple the |
|---|
| 115 | timebase from the input clock (and couple it to the internal crystal) |
|---|
| 116 | - If the incoming clock reference returns to low jitter, ASTM will recouple |
|---|
| 117 | the timebase to the input clock |
|---|
| 118 | |
|---|
| 119 | If the application manually puts a decoder into vsync mode, ASTM will not |
|---|
| 120 | move it into TSM mode. The application can also manually set the three |
|---|
| 121 | controls ASTM provides: |
|---|
| 122 | - presentation control (PTS or output clock), |
|---|
| 123 | - stc source (PCR or PTS, with which PTS is used being a preference), and |
|---|
| 124 | - clock coupling (input or crystal). |
|---|
| 125 | Any manual setting will not be overridden by ASTM. |
|---|
| 126 | |
|---|
| 127 | See nexus/examples/astm.c for an example. |
|---|
| 128 | |
|---|
| 129 | **************************************/ |
|---|
| 130 | |
|---|
| 131 | #include "nexus_video_decoder.h" |
|---|
| 132 | #include "nexus_audio_decoder.h" |
|---|
| 133 | #include "nexus_stc_channel.h" |
|---|
| 134 | #include "nexus_timebase.h" |
|---|
| 135 | |
|---|
| 136 | #ifdef __cplusplus |
|---|
| 137 | extern "C" |
|---|
| 138 | { |
|---|
| 139 | #endif |
|---|
| 140 | |
|---|
| 141 | /** |
|---|
| 142 | Summary: |
|---|
| 143 | Handle for Astm interface |
|---|
| 144 | **/ |
|---|
| 145 | typedef struct NEXUS_Astm * NEXUS_AstmHandle; |
|---|
| 146 | |
|---|
| 147 | /** |
|---|
| 148 | Summary: |
|---|
| 149 | Determines what controls the rate of presentation |
|---|
| 150 | **/ |
|---|
| 151 | typedef enum NEXUS_AstmPresentationRateControl |
|---|
| 152 | { |
|---|
| 153 | NEXUS_AstmPresentationRateControl_eAdaptive, /* adapts to current conditions */ |
|---|
| 154 | NEXUS_AstmPresentationRateControl_eTimeStamp, /* frames are released based |
|---|
| 155 | on their time stamp */ |
|---|
| 156 | NEXUS_AstmPresentationRateControl_eOutputClock, /* frames are released based |
|---|
| 157 | on output clock rate (timestamps are ignored) */ |
|---|
| 158 | NEXUS_AstmPresentationRateControl_eMax |
|---|
| 159 | } NEXUS_AstmPresentationRateControl; |
|---|
| 160 | |
|---|
| 161 | /** |
|---|
| 162 | Summary: |
|---|
| 163 | Determines what quantity is used to seed the STC |
|---|
| 164 | **/ |
|---|
| 165 | typedef enum NEXUS_AstmStcSource |
|---|
| 166 | { |
|---|
| 167 | NEXUS_AstmStcSource_eAdaptive, /* adapts to current conditions */ |
|---|
| 168 | NEXUS_AstmStcSource_eClockReference, /* PCR, SCR, RTS, etc. */ |
|---|
| 169 | NEXUS_AstmStcSource_ePts, /* Presentation Time Stamp, per ISO 13818-1 */ |
|---|
| 170 | NEXUS_AstmStcSource_eMax |
|---|
| 171 | } NEXUS_AstmStcSource; |
|---|
| 172 | |
|---|
| 173 | /** |
|---|
| 174 | Summary: |
|---|
| 175 | Describes whether the timebases will be coupled to the input or the crystal |
|---|
| 176 | **/ |
|---|
| 177 | typedef enum NEXUS_AstmClockCoupling |
|---|
| 178 | { |
|---|
| 179 | NEXUS_AstmClockCoupling_eAdaptive, /* adapts to current conditions */ |
|---|
| 180 | NEXUS_AstmClockCoupling_eInputClock, /* PCR, VSYNC, HSYNC, etc. */ |
|---|
| 181 | NEXUS_AstmClockCoupling_eInternalClock, /* internal XTAL */ |
|---|
| 182 | NEXUS_AstmClockCoupling_eMax /* enum terminator */ |
|---|
| 183 | } NEXUS_AstmClockCoupling; |
|---|
| 184 | |
|---|
| 185 | /** |
|---|
| 186 | Summary: |
|---|
| 187 | Describes whether the timebases will be coupled to the input or the crystal |
|---|
| 188 | **/ |
|---|
| 189 | typedef enum NEXUS_AstmClockRate |
|---|
| 190 | { |
|---|
| 191 | NEXUS_AstmClockRate_e45Khz = 45000, |
|---|
| 192 | NEXUS_AstmClockRate_e27Mhz = 27000000, |
|---|
| 193 | NEXUS_AstmClockRate_eMax /* enum terminator */ |
|---|
| 194 | } NEXUS_AstmClockRate; |
|---|
| 195 | |
|---|
| 196 | /* |
|---|
| 197 | Summary: |
|---|
| 198 | What controls the rate of releasing frames for presentation? |
|---|
| 199 | Description: |
|---|
| 200 | This enum represents a selection between TSM mode and VSYNC / non-TSM mode. |
|---|
| 201 | Basically, we are deciding if frames will be released for presentation based |
|---|
| 202 | on their timestamp, or based on the rate of the output clock. |
|---|
| 203 | */ |
|---|
| 204 | typedef enum NEXUS_PresentationRateControl |
|---|
| 205 | { |
|---|
| 206 | NEXUS_PresentationRateControl_eTimeStamp, /* frames are released based on their time stamp */ |
|---|
| 207 | NEXUS_PresentationRateControl_eOutputClock, /* frames are released based on output clock rate (timestamps are ignored) */ |
|---|
| 208 | NEXUS_PresentationRateControl_eMax /* enum terminator */ |
|---|
| 209 | } NEXUS_PresentationRateControl; |
|---|
| 210 | |
|---|
| 211 | #define NEXUS_ASTM_AUDIO_DECODERS 2 |
|---|
| 212 | |
|---|
| 213 | /** |
|---|
| 214 | Summary: |
|---|
| 215 | Settings for NEXUS_Astm |
|---|
| 216 | **/ |
|---|
| 217 | typedef struct NEXUS_AstmPresenterConfig |
|---|
| 218 | { |
|---|
| 219 | unsigned minimumTimeBetweenEvents;/* minimum time that must elapse between receiving events, in ms. used with presentation processing frequency to determine size of |
|---|
| 220 | event ring buffer. if events come more often than this time, the event buffer may overflow, and newer events will be lost */ |
|---|
| 221 | unsigned passEventCountThreshold; /* how many pass events must be received before deeming this presenter as "passing", in events */ |
|---|
| 222 | unsigned failEventCountThreshold; /* how many fail events must be received before deeming this presenter as "failing", in events */ |
|---|
| 223 | bool tsmThresholdAdjustment; /* if true, during certain types of failures ASTM will attempt to adjust the TSM threshold instead of entering non-TSM mode */ |
|---|
| 224 | bool manageRateControl; /* if true, presentation rate control changes performed by ASTM will affect this presenter */ |
|---|
| 225 | unsigned tsmRecoveryAcquisitionPeriod; /* how often do we schedule attempts to adjust the PTS offset for TSM recovery in non-TSM mode, in ms */ |
|---|
| 226 | unsigned tsmRecoveryTrackingTimeout; /* once we see a TSM pass, how long do we count them and then compare to frames decoded, in ms */ |
|---|
| 227 | unsigned ptsStcDiffAdjustmentThreshold; /* if the abs(pts/stc diff) is below this, we don't adjust, only applies in non-TSM mode during tsm recovery acquisition */ |
|---|
| 228 | unsigned maxAllowableFirstPtsStcDiff; /* if we exceed this, presentation rate control will be changed to output clock for the exceeding presenter; this behavior is disabled when set to zero */ |
|---|
| 229 | } NEXUS_AstmPresenterConfig; |
|---|
| 230 | |
|---|
| 231 | /** |
|---|
| 232 | Summary: |
|---|
| 233 | Settings for NEXUS_Astm |
|---|
| 234 | **/ |
|---|
| 235 | typedef struct NEXUS_AstmSettings |
|---|
| 236 | { |
|---|
| 237 | bool enabled; |
|---|
| 238 | bool enableAutomaticLifecycleControl; /* if true, ASTM will auto-start/stop |
|---|
| 239 | based on decoder start/stop conditions; if false, the app will be |
|---|
| 240 | responsible for starting/stopping ASTM */ |
|---|
| 241 | NEXUS_AstmPresentationRateControl presentationRateControl; |
|---|
| 242 | NEXUS_AstmStcSource stcSource; |
|---|
| 243 | NEXUS_AstmClockCoupling clockCoupling; |
|---|
| 244 | NEXUS_StcChannelHandle stcChannel; |
|---|
| 245 | NEXUS_VideoDecoderHandle videoDecoder; /* Astm supports one video decoder */ |
|---|
| 246 | NEXUS_AudioDecoderHandle audioDecoder[NEXUS_ASTM_AUDIO_DECODERS]; /* Both |
|---|
| 247 | audio decoders must be for the same program. Two audio decoders are used |
|---|
| 248 | for PCM and compressed pass-through configurations. */ |
|---|
| 249 | void * stcMaster; /* points to video decoder handle or either audio decoder handle |
|---|
| 250 | for pts master mode or adaptive mode */ |
|---|
| 251 | unsigned int syncLimit; /* in a master mode, this is the limit on the difference |
|---|
| 252 | between PTS and STC to which the master mode is applied in the decoder. |
|---|
| 253 | Beyond this limit, the decoder applies it's normal TSM processing. */ |
|---|
| 254 | NEXUS_AstmPresenterConfig videoPresenterConfig; /* Astm supports one video decoder */ |
|---|
| 255 | NEXUS_AstmPresenterConfig audioPresenterConfig[NEXUS_ASTM_AUDIO_DECODERS]; |
|---|
| 256 | struct |
|---|
| 257 | { |
|---|
| 258 | unsigned minimumTimeBetweenEvents; /* minimum time that must elapse between receiving events, in ms. used with processing frequency to determine size of event |
|---|
| 259 | ring buffer. if events come more often than this time, the event buffer may overflow, and newer events will be lost */ |
|---|
| 260 | unsigned deviationThreshold; /* threshold above which abs value of clock reference rate difference to STC will be considered deviant */ |
|---|
| 261 | unsigned deviantCountThreshold; /* how many deviant clock coupling measurements must be received before deeming the clock reference bad and decoupling |
|---|
| 262 | the timebases from the input */ |
|---|
| 263 | unsigned idealCountThreshold; /* how many ideal clock coupling measurements must be received before deeming the clock reference good and recoupling the timebases to the input */ |
|---|
| 264 | unsigned initialAcquisitionTime; /* time just after calling start before processing clock reference event queue for the first time, in ms */ |
|---|
| 265 | unsigned processingFrequency; /* after initial acquisition period, how often clock reference event queue will be processed for deviants, in ms */ |
|---|
| 266 | unsigned idealProcessingFrequency; /* after detecting deviants, how often clock reference event queue will be processed for ideals, in ms */ |
|---|
| 267 | unsigned settlingTime; /* after changing clock coupling modes, how long we will wait for clock reference to settle in the new mode */ |
|---|
| 268 | } clockCouplingConfig; /* clock coupling config */ |
|---|
| 269 | |
|---|
| 270 | struct |
|---|
| 271 | { |
|---|
| 272 | unsigned initialAcquisitionTime; /* time just after calling start before processing presenter event queues for the first time, in ms */ |
|---|
| 273 | unsigned processingFrequency; /* after initial acquisition period, how often presenter event queues will be processed, in ms */ |
|---|
| 274 | unsigned tsmDisabledWatchdogTimeout; /* after entering TSM-disabled mode, how long before we attempt to re-enter TSM-enabled mode unconditionally */ |
|---|
| 275 | unsigned settlingTime; /* after changing presentation modes, how long we will wait for presenters to settle in the new mode */ |
|---|
| 276 | NEXUS_PresentationRateControl preferredPresentationRateControl; /* This is used as the highest level presentation rate control goal of ASTM's presentation task */ |
|---|
| 277 | } presentationConfig; /* presentation config */ |
|---|
| 278 | } NEXUS_AstmSettings; |
|---|
| 279 | |
|---|
| 280 | /** |
|---|
| 281 | Summary: |
|---|
| 282 | Get default settings |
|---|
| 283 | **/ |
|---|
| 284 | void NEXUS_Astm_GetDefaultSettings( |
|---|
| 285 | NEXUS_AstmSettings * pSettings /* [out] */ |
|---|
| 286 | ); |
|---|
| 287 | |
|---|
| 288 | /** |
|---|
| 289 | Summary: |
|---|
| 290 | Create a new Astm. |
|---|
| 291 | |
|---|
| 292 | Description: |
|---|
| 293 | You will need one Astm for every program for which you want adaptive system time management. |
|---|
| 294 | |
|---|
| 295 | You cannot attach a decoder to more than one Astm at a time. |
|---|
| 296 | **/ |
|---|
| 297 | NEXUS_AstmHandle NEXUS_Astm_Create( /* attr{destructor=NEXUS_Astm_Destroy} */ |
|---|
| 298 | const NEXUS_AstmSettings * pSettings |
|---|
| 299 | ); |
|---|
| 300 | |
|---|
| 301 | /** |
|---|
| 302 | Summary: |
|---|
| 303 | **/ |
|---|
| 304 | void NEXUS_Astm_Destroy( |
|---|
| 305 | NEXUS_AstmHandle handle |
|---|
| 306 | ); |
|---|
| 307 | |
|---|
| 308 | /** |
|---|
| 309 | Summary: |
|---|
| 310 | Get current settings. |
|---|
| 311 | **/ |
|---|
| 312 | void NEXUS_Astm_GetSettings( |
|---|
| 313 | NEXUS_AstmHandle handle, |
|---|
| 314 | NEXUS_AstmSettings * pSettings /* [out] */ |
|---|
| 315 | ); |
|---|
| 316 | |
|---|
| 317 | /** |
|---|
| 318 | Summary: |
|---|
| 319 | Apply new settings. |
|---|
| 320 | **/ |
|---|
| 321 | NEXUS_Error NEXUS_Astm_SetSettings( |
|---|
| 322 | NEXUS_AstmHandle handle, |
|---|
| 323 | const NEXUS_AstmSettings * pSettings |
|---|
| 324 | ); |
|---|
| 325 | |
|---|
| 326 | /* |
|---|
| 327 | Summary: |
|---|
| 328 | Start ASTM processing |
|---|
| 329 | */ |
|---|
| 330 | NEXUS_Error NEXUS_Astm_Start( |
|---|
| 331 | NEXUS_AstmHandle astm |
|---|
| 332 | ); |
|---|
| 333 | |
|---|
| 334 | /* |
|---|
| 335 | Summary: |
|---|
| 336 | Stop ASTM processing |
|---|
| 337 | */ |
|---|
| 338 | void NEXUS_Astm_Stop( |
|---|
| 339 | NEXUS_AstmHandle astm |
|---|
| 340 | ); |
|---|
| 341 | |
|---|
| 342 | #ifdef __cplusplus |
|---|
| 343 | } |
|---|
| 344 | #endif |
|---|
| 345 | |
|---|
| 346 | #endif |
|---|
| 347 | |
|---|
| 348 | |
|---|