| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2002-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: bcmindexerpriv.h $ |
|---|
| 11 | * $brcm_Revision: 14 $ |
|---|
| 12 | * $brcm_Date: 6/22/10 11:13a $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: Private types and prototypes for bcmindexer & bcmplayer |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: /BSEAV/lib/bcmplayer/src/bcmindexerpriv.h $ |
|---|
| 19 | * |
|---|
| 20 | * 14 6/22/10 11:13a erickson |
|---|
| 21 | * SW7405-4465: add BNAV_Indexer_Settings.ptsBasedFrameRate for PTS-based |
|---|
| 22 | * offline indexing |
|---|
| 23 | * |
|---|
| 24 | * 13 5/13/10 9:51a erickson |
|---|
| 25 | * SW7405-4105: add full packet parsing support. enabled >10 ITB's per TS |
|---|
| 26 | * packet. |
|---|
| 27 | * |
|---|
| 28 | * 12 3/16/10 2:17p erickson |
|---|
| 29 | * CDSTRMANA-294: support indexing of field-encoded MPEG streams |
|---|
| 30 | * |
|---|
| 31 | * 11 2/25/10 10:42a erickson |
|---|
| 32 | * SW7400-2685: fix bcmindexer's handling of adjacent I frames |
|---|
| 33 | * |
|---|
| 34 | * 10 11/11/09 4:39p erickson |
|---|
| 35 | * SWDEPRECATED-3668: make global into a const |
|---|
| 36 | * |
|---|
| 37 | * 9 2/25/09 5:04p erickson |
|---|
| 38 | * PR52471: make global data const |
|---|
| 39 | * |
|---|
| 40 | * 8 4/2/08 11:44a gmohile |
|---|
| 41 | * PR 41170 : Fix coverity CID 7943 |
|---|
| 42 | * |
|---|
| 43 | * 7 4/2/08 9:32a erickson |
|---|
| 44 | * PR41171: fix misspelling |
|---|
| 45 | * |
|---|
| 46 | * 6 2/5/08 3:52p gmohile |
|---|
| 47 | * PR 38979 : Add Random Access indicator in index file |
|---|
| 48 | * |
|---|
| 49 | * 5 12/27/07 3:27p erickson |
|---|
| 50 | * PR37035: if there's a gap in the recording, reset the timestamp base so |
|---|
| 51 | * that it is skipped |
|---|
| 52 | * |
|---|
| 53 | * 4 10/8/07 7:40p vishk |
|---|
| 54 | * PR 35262: LIB-Converity (CID 421): OVERRUN_STATIC, |
|---|
| 55 | * |
|---|
| 56 | * 3 10/3/07 9:33a vishk |
|---|
| 57 | * PR 35262: LIB-Converity (CID 421): OVERRUN_STATIC, |
|---|
| 58 | * |
|---|
| 59 | * 2 3/28/07 11:48p erickson |
|---|
| 60 | * PR27189: changed SEI indexing logic. previously, we including trailing |
|---|
| 61 | * SEI's with SPS's and PPS's. with this code, we are including leading |
|---|
| 62 | * SEI's with SPS's, PPS's and pictures. this is needed for trick modes |
|---|
| 63 | * on streams that use SEI recovery points. |
|---|
| 64 | * |
|---|
| 65 | * Irvine_BSEAVSW_Devel/16 3/6/06 1:20p erickson |
|---|
| 66 | * PR19853: added VC1 PES support |
|---|
| 67 | * |
|---|
| 68 | * Irvine_BSEAVSW_Devel/15 7/13/05 2:10p erickson |
|---|
| 69 | * PR16138: added new NAV version for AVC support, PPS and SPS support |
|---|
| 70 | * added, refactored player to better support this with less code |
|---|
| 71 | * duplication |
|---|
| 72 | * |
|---|
| 73 | * Irvine_BSEAVSW_Devel/14 9/21/04 4:06p erickson |
|---|
| 74 | * PR12728: cleaned up pedantic warnings |
|---|
| 75 | * |
|---|
| 76 | * Irvine_BSEAVSW_Devel/13 2/14/03 1:57p erickson |
|---|
| 77 | * New naming convention |
|---|
| 78 | * Fixed looping from previous rework |
|---|
| 79 | * Removed bcmindexer _getParam/_setParam |
|---|
| 80 | * Did not change code shared between tsplayer and bcmplayer |
|---|
| 81 | * Refactored settings, playmode and other structures |
|---|
| 82 | * |
|---|
| 83 | * Irvine_HDDemo_Devel/12 9/26/02 3:4p erickson |
|---|
| 84 | * Changed bcmindexer vchip from 3 bits to 16 bits packed into 12 bits. |
|---|
| 85 | * The index is NOT backward compatible, but the 3 bit version had only |
|---|
| 86 | * been released for 1 day. |
|---|
| 87 | * |
|---|
| 88 | * Irvine_HDDemo_Devel/11 9/10/02 10:37a erickson |
|---|
| 89 | * converted vchip from 16 bits in [7] to 3 bits in [5] |
|---|
| 90 | * |
|---|
| 91 | * Irvine_HDDemo_Devel\9 7/2/02 4:52p erickson |
|---|
| 92 | * added some parens for the macros |
|---|
| 93 | * |
|---|
| 94 | * Irvine_HDDemo_Devel\8 4/17/02 1:16p erickson |
|---|
| 95 | * Made sBcmIndexEntry public |
|---|
| 96 | * Added timestamp |
|---|
| 97 | * |
|---|
| 98 | * Irvine_HDDemo_Devel\7 4/16/02 12:58p erickson |
|---|
| 99 | * Changed header |
|---|
| 100 | * |
|---|
| 101 | * |
|---|
| 102 | ***************************************************************************/ |
|---|
| 103 | #ifndef BCMINDEXERPRIV_H |
|---|
| 104 | #define BCMINDEXERPRIV_H |
|---|
| 105 | |
|---|
| 106 | /******************************* |
|---|
| 107 | * |
|---|
| 108 | * BNAV_Entry |
|---|
| 109 | * |
|---|
| 110 | ******/ |
|---|
| 111 | |
|---|
| 112 | /* defines and typedefs used internally by both bcmplayer and bcmindexer */ |
|---|
| 113 | |
|---|
| 114 | #define BNAV_set_frameType( pEntry, frameType ) \ |
|---|
| 115 | ((pEntry)->words[0] &= 0x00fffffful, \ |
|---|
| 116 | (pEntry)->words[0] |= ((unsigned long)(frameType) << 24)) |
|---|
| 117 | #define BNAV_get_frameType( pEntry ) \ |
|---|
| 118 | ((eSCType)((pEntry)->words[0] >> 24)) |
|---|
| 119 | #define BNAV_set_seqHdrStartOffset( pEntry, seqHdrStartOffset ) \ |
|---|
| 120 | ((pEntry)->words[0] &= 0xff000000ul, \ |
|---|
| 121 | (pEntry)->words[0] |= ((seqHdrStartOffset) & 0x00fffffful)) |
|---|
| 122 | #define BNAV_get_seqHdrStartOffset( pEntry ) \ |
|---|
| 123 | ((unsigned long)((pEntry)->words[0] & 0xffffff)) |
|---|
| 124 | |
|---|
| 125 | #define BNAV_set_seqHdrSize( pEntry, seqHdrSize ) \ |
|---|
| 126 | ((pEntry)->words[1] &= 0x0000fffful, \ |
|---|
| 127 | (pEntry)->words[1] |= ((unsigned long)(seqHdrSize) << 16)) |
|---|
| 128 | #define BNAV_get_seqHdrSize( pEntry ) \ |
|---|
| 129 | ((unsigned short)(((pEntry)->words[1] >> 16) & 0xffff)) |
|---|
| 130 | #define BNAV_set_refFrameOffset( pEntry, refFrameOffset ) \ |
|---|
| 131 | ((pEntry)->words[1] &= 0xffff00fful, \ |
|---|
| 132 | (pEntry)->words[1] |= ((unsigned long)(refFrameOffset) << 8)) |
|---|
| 133 | #define BNAV_get_refFrameOffset( pEntry ) \ |
|---|
| 134 | ((unsigned char)(((pEntry)->words[1] >> 8) & 0xff)) |
|---|
| 135 | |
|---|
| 136 | #define BNAV_set_version( pEntry, version ) \ |
|---|
| 137 | ((pEntry)->words[1] &= 0xffffff0ful, \ |
|---|
| 138 | (pEntry)->words[1] |= (unsigned long)(((version) & 0xf) << 4)) |
|---|
| 139 | #define BNAV_get_version( pEntry ) \ |
|---|
| 140 | ((unsigned char)((pEntry)->words[1] & 0xf0)>>4) |
|---|
| 141 | |
|---|
| 142 | /* NOTE: Lower 4 bits of [1] available */ |
|---|
| 143 | |
|---|
| 144 | #define BNAV_set_frameOffsetHi( pEntry, frameOffsetHi ) \ |
|---|
| 145 | ((pEntry)->words[2] = (frameOffsetHi)) |
|---|
| 146 | #define BNAV_get_frameOffsetHi( pEntry ) \ |
|---|
| 147 | ((pEntry)->words[2]) |
|---|
| 148 | #define BNAV_set_frameOffsetLo( pEntry, frameOffsetLo ) \ |
|---|
| 149 | ((pEntry)->words[3] = (frameOffsetLo)) |
|---|
| 150 | #define BNAV_get_frameOffsetLo( pEntry ) \ |
|---|
| 151 | ((pEntry)->words[3]) |
|---|
| 152 | #define BNAV_set_framePts( pEntry, framePts ) \ |
|---|
| 153 | ((pEntry)->words[4] = (framePts)) |
|---|
| 154 | #define BNAV_get_framePts( pEntry ) \ |
|---|
| 155 | ((pEntry)->words[4]) |
|---|
| 156 | /** |
|---|
| 157 | * Maximum frameSize is 256 MB (28 bits). This should |
|---|
| 158 | * be large enough for the largest HD I-frame possible. |
|---|
| 159 | **/ |
|---|
| 160 | #define BNAV_set_frameSize( pEntry, frameSize ) \ |
|---|
| 161 | ((pEntry)->words[5] &= 0xf0000000ul, \ |
|---|
| 162 | (pEntry)->words[5] |= ((unsigned long)(frameSize) & 0x0ffffffful)) |
|---|
| 163 | #define BNAV_get_frameSize( pEntry ) \ |
|---|
| 164 | ((pEntry)->words[5] & 0x0ffffffful) |
|---|
| 165 | |
|---|
| 166 | /* NOTE: Upper 4 bits of [5] available */ |
|---|
| 167 | |
|---|
| 168 | #define BNAV_set_timestamp( pEntry, timestamp) \ |
|---|
| 169 | ((pEntry)->words[6] = (timestamp)) |
|---|
| 170 | #define BNAV_get_timestamp( pEntry ) \ |
|---|
| 171 | ((pEntry)->words[6]) |
|---|
| 172 | |
|---|
| 173 | /** |
|---|
| 174 | * 12 bits for packed vchip information. See BNAV_pack_vchip and |
|---|
| 175 | * BNAV_unpack_vchip. |
|---|
| 176 | **/ |
|---|
| 177 | #define BNAV_set_packed_vchip( pEntry, vchipdata) \ |
|---|
| 178 | ((pEntry)->words[7] &= 0xfffff000ul, \ |
|---|
| 179 | (pEntry)->words[7] |= (unsigned long)((vchipdata) & 0xfff)) |
|---|
| 180 | #define BNAV_get_packed_vchip( pEntry ) \ |
|---|
| 181 | ((unsigned short)((pEntry)->words[7] & 0xfff)) |
|---|
| 182 | |
|---|
| 183 | /* NOTE: Upper 20 bits of [7] available */ |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | /******************************* |
|---|
| 187 | * |
|---|
| 188 | * BNAV_AVC_Entry |
|---|
| 189 | * |
|---|
| 190 | ******/ |
|---|
| 191 | /* SPS is sequence parameter set. 24 bits allows 16 MB offset in stream. */ |
|---|
| 192 | #define BNAV_set_SPS_Offset( pEntry, seqHdrStartOffset ) \ |
|---|
| 193 | ((pEntry)->words[8] &= 0xff000000ul, \ |
|---|
| 194 | (pEntry)->words[8] |= ((seqHdrStartOffset) & 0x00fffffful)) |
|---|
| 195 | #define BNAV_get_SPS_Offset( pEntry ) \ |
|---|
| 196 | ((unsigned long)((pEntry)->words[8] & 0xffffff)) |
|---|
| 197 | |
|---|
| 198 | /* 16 bits allows 64 KB for SPS, which is far more than enough. */ |
|---|
| 199 | #define BNAV_set_SPS_Size( pEntry, seqHdrStartOffset ) \ |
|---|
| 200 | ((pEntry)->words[9] &= 0xffff0000ul, \ |
|---|
| 201 | (pEntry)->words[9] |= ((seqHdrStartOffset) & 0x0000fffful)) |
|---|
| 202 | #define BNAV_get_SPS_Size( pEntry ) \ |
|---|
| 203 | ((unsigned long)((pEntry)->words[9] & 0xffff)) |
|---|
| 204 | |
|---|
| 205 | #define BNAV_set_RandomAccessIndicator( pEntry, randomAccessIndicator) \ |
|---|
| 206 | (((BNAV_AVC_Entry*)pEntry)->words[10] &= 0xfffffffeul, \ |
|---|
| 207 | ((BNAV_AVC_Entry*)pEntry)->words[10] |= ((randomAccessIndicator) & 0x00000001ul)) |
|---|
| 208 | #define BNAV_get_RandomAccessIndicator( pEntry ) \ |
|---|
| 209 | ((unsigned long)(((BNAV_AVC_Entry*)pEntry)->words[10] & 0x1)) |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | /* Convert eSCType to a string */ |
|---|
| 213 | extern const char * const BNAV_frameTypeStr[]; |
|---|
| 214 | |
|---|
| 215 | typedef enum |
|---|
| 216 | { |
|---|
| 217 | eSCTypeSeqHdr, /* Sequence header */ |
|---|
| 218 | eSCTypeIFrame, /* I-frame */ |
|---|
| 219 | eSCTypePFrame, /* P-frame */ |
|---|
| 220 | eSCTypeBFrame, /* B-frame */ |
|---|
| 221 | eSCTypeGOPHdr, /* GOP header */ |
|---|
| 222 | eSCTypeRPFrame, /* Reference picture frame */ |
|---|
| 223 | eSCTypeUnknown /* Unknown or "don't care" frame type */ |
|---|
| 224 | } eSCType; |
|---|
| 225 | |
|---|
| 226 | /** |
|---|
| 227 | * Convert 12 bit vchip data to 16 bit vchip data. |
|---|
| 228 | **/ |
|---|
| 229 | unsigned short BNAV_unpack_vchip(unsigned short packed_vchip); |
|---|
| 230 | |
|---|
| 231 | /** |
|---|
| 232 | * Convert 16 bit vchip data to 12 bit vchip data, checking the 16 bit |
|---|
| 233 | * data for bits 6 and 14. If bits 6 and 14 are both 1, the vchip data |
|---|
| 234 | * is valid and BNAV_pack_vchip returns 0 and the packed value is |
|---|
| 235 | * written to *packed_vchip. Otherwise it returns -1 and *packed_vchip is left unchanged. |
|---|
| 236 | */ |
|---|
| 237 | int BNAV_pack_vchip(unsigned short unpacked_vchip, unsigned short *packed_vchip); |
|---|
| 238 | |
|---|
| 239 | struct BNAV_Indexer_HandleImpl |
|---|
| 240 | { |
|---|
| 241 | BNAV_Indexer_Settings settings; |
|---|
| 242 | |
|---|
| 243 | unsigned long TransRecordByteCount; /* Running counter of number of bytes |
|---|
| 244 | recorded */ |
|---|
| 245 | unsigned long TransRecordByteCountHi; /* Running counter of number of bytes recorded (hi word) */ |
|---|
| 246 | |
|---|
| 247 | unsigned long TransByteOffset; /* Running count of number of bytes |
|---|
| 248 | processed in cur packet */ |
|---|
| 249 | |
|---|
| 250 | char seqHdrFlag; /* Flag indicating if MPEG2 sequence header information was found. */ |
|---|
| 251 | char isISlice; /* Flag indicating that we found an |
|---|
| 252 | I-slice or I-frame */ |
|---|
| 253 | char isHits; /* Flag indicating we're dealing with a |
|---|
| 254 | HITS-stream */ |
|---|
| 255 | char hitFirstISlice; /* Flag indicating that we've hit the |
|---|
| 256 | first I-slice */ |
|---|
| 257 | unsigned long seqHdrSize; /* Number of bytes in the sequence |
|---|
| 258 | header */ |
|---|
| 259 | unsigned long seqHdrStartOffset; /* Sequence header offset (in bytes) relative to frame offset */ |
|---|
| 260 | unsigned long picStart; /* Offset of start of picture */ |
|---|
| 261 | unsigned long picEnd; /* Offset of end of picture */ |
|---|
| 262 | unsigned fieldEncodedCount; /* count of fields in a field encoded picture */ |
|---|
| 263 | unsigned char rfo; /* Reference frame offset counter */ |
|---|
| 264 | |
|---|
| 265 | BNAV_Entry curEntry; /* The current MPEG2 structure that is being populated */ |
|---|
| 266 | BNAV_AVC_Entry avcEntry; /* The current AVC structure that is being populated. */ |
|---|
| 267 | |
|---|
| 268 | unsigned long next_pts; /* pts buffer for next picture frame */ |
|---|
| 269 | bool random_access_indicator; |
|---|
| 270 | |
|---|
| 271 | long starttime; /* base timestamp for calculating NAV timestamp */ |
|---|
| 272 | long lasttime; /* last timestamp written to NAV entry */ |
|---|
| 273 | struct { |
|---|
| 274 | unsigned frameCount; |
|---|
| 275 | unsigned lastPts; |
|---|
| 276 | unsigned rate; /* in 45KHz/frame units */ |
|---|
| 277 | } ptsBasedFrameRate; |
|---|
| 278 | |
|---|
| 279 | unsigned prev_pc; /* previous picture code */ |
|---|
| 280 | int prev_I_rfo; /* This contains the rfo for the previous |
|---|
| 281 | I frame, until the next P frame is detected. |
|---|
| 282 | This value is added to the rfo of the open gop |
|---|
| 283 | B frames. */ |
|---|
| 284 | unsigned short vchip; /* Current packed vchip state */ |
|---|
| 285 | |
|---|
| 286 | struct { |
|---|
| 287 | #define MAX_GOP_SIZE 50 |
|---|
| 288 | BNAV_Entry entry[MAX_GOP_SIZE]; |
|---|
| 289 | int total_entries; |
|---|
| 290 | } reverse; |
|---|
| 291 | |
|---|
| 292 | /* this information is used to report BNAV_Indexer_GetPosition consistently */ |
|---|
| 293 | int totalEntriesWritten; |
|---|
| 294 | BNAV_Entry lastEntryWritten; |
|---|
| 295 | int allowOpenGopBs; |
|---|
| 296 | |
|---|
| 297 | /* define structures for AVC indexing */ |
|---|
| 298 | #define TOTAL_PPS_ID 256 |
|---|
| 299 | #define TOTAL_SPS_ID 32 |
|---|
| 300 | struct { |
|---|
| 301 | int current_sps, current_pps; /* if -1, then no SPS or PPS being captured */ |
|---|
| 302 | int is_reference_picture; /* if true, then this picture has at least one slice that is referenced by another slice. |
|---|
| 303 | this picture is not dropppable. */ |
|---|
| 304 | struct { |
|---|
| 305 | unsigned long offset; |
|---|
| 306 | unsigned long size; |
|---|
| 307 | int sps_id; |
|---|
| 308 | } pps[TOTAL_PPS_ID]; |
|---|
| 309 | struct { |
|---|
| 310 | unsigned long offset; |
|---|
| 311 | unsigned long size; |
|---|
| 312 | } sps[TOTAL_SPS_ID]; |
|---|
| 313 | unsigned long current_sei; |
|---|
| 314 | bool current_sei_valid; |
|---|
| 315 | } avc; |
|---|
| 316 | |
|---|
| 317 | /* instead of complicated wraparound logic, I buffer a minimum amount before |
|---|
| 318 | processing PES payload. MIN_PES_PAYLOAD includes the startcode byte itself. */ |
|---|
| 319 | #define MIN_PES_PAYLOAD 5 |
|---|
| 320 | struct { |
|---|
| 321 | unsigned char buf[MIN_PES_PAYLOAD + 2]; |
|---|
| 322 | int bufsize; |
|---|
| 323 | int sccount; |
|---|
| 324 | uint64_t offset; |
|---|
| 325 | |
|---|
| 326 | bool vc1_interlace; |
|---|
| 327 | uint64_t sequence_offset; |
|---|
| 328 | int sequence_size; |
|---|
| 329 | uint64_t entrypoint_offset; |
|---|
| 330 | int entrypoint_size; |
|---|
| 331 | } pes; |
|---|
| 332 | |
|---|
| 333 | /* bcmindexer "full packet" support allows bcmindexer to process a whole TS packet in the ITB. |
|---|
| 334 | The whole TS packet is needed if the # of ITB's is greater than 10 per TS packet. |
|---|
| 335 | You must #define BXPT_STARTCODE_BUFFER_WORKAROUND in XPT PI to enable this feature in the FW. */ |
|---|
| 336 | unsigned fullPacketCount; |
|---|
| 337 | #define BCMINDEXER_TS_PACKET_SIZE 188 |
|---|
| 338 | uint8_t fullPacket[BCMINDEXER_TS_PACKET_SIZE]; |
|---|
| 339 | struct { |
|---|
| 340 | unsigned offset, offsetHi; |
|---|
| 341 | } lastPacketOffset; |
|---|
| 342 | }; |
|---|
| 343 | |
|---|
| 344 | int BNAV_P_FeedPES_VC1(BNAV_Indexer_Handle handle, uint8_t *p_bfr, unsigned size); |
|---|
| 345 | |
|---|
| 346 | int BNAV_Indexer_completeFrameAux(BNAV_Indexer_Handle handle, |
|---|
| 347 | void *data, /* data points to either a BNAV_Entry or a BNAV_AVC_Entry. */ |
|---|
| 348 | int size /* size of data */ |
|---|
| 349 | ); |
|---|
| 350 | |
|---|
| 351 | #endif |
|---|