/*************************************************************************** * Copyright (c) 2002-2010, Broadcom Corporation * All Rights Reserved * Confidential Property of Broadcom Corporation * * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. * * $brcm_Workfile: bcmindexerpriv.h $ * $brcm_Revision: 14 $ * $brcm_Date: 6/22/10 11:13a $ * * Module Description: Private types and prototypes for bcmindexer & bcmplayer * * Revision History: * * $brcm_Log: /BSEAV/lib/bcmplayer/src/bcmindexerpriv.h $ * * 14 6/22/10 11:13a erickson * SW7405-4465: add BNAV_Indexer_Settings.ptsBasedFrameRate for PTS-based * offline indexing * * 13 5/13/10 9:51a erickson * SW7405-4105: add full packet parsing support. enabled >10 ITB's per TS * packet. * * 12 3/16/10 2:17p erickson * CDSTRMANA-294: support indexing of field-encoded MPEG streams * * 11 2/25/10 10:42a erickson * SW7400-2685: fix bcmindexer's handling of adjacent I frames * * 10 11/11/09 4:39p erickson * SWDEPRECATED-3668: make global into a const * * 9 2/25/09 5:04p erickson * PR52471: make global data const * * 8 4/2/08 11:44a gmohile * PR 41170 : Fix coverity CID 7943 * * 7 4/2/08 9:32a erickson * PR41171: fix misspelling * * 6 2/5/08 3:52p gmohile * PR 38979 : Add Random Access indicator in index file * * 5 12/27/07 3:27p erickson * PR37035: if there's a gap in the recording, reset the timestamp base so * that it is skipped * * 4 10/8/07 7:40p vishk * PR 35262: LIB-Converity (CID 421): OVERRUN_STATIC, * * 3 10/3/07 9:33a vishk * PR 35262: LIB-Converity (CID 421): OVERRUN_STATIC, * * 2 3/28/07 11:48p erickson * PR27189: changed SEI indexing logic. previously, we including trailing * SEI's with SPS's and PPS's. with this code, we are including leading * SEI's with SPS's, PPS's and pictures. this is needed for trick modes * on streams that use SEI recovery points. * * Irvine_BSEAVSW_Devel/16 3/6/06 1:20p erickson * PR19853: added VC1 PES support * * Irvine_BSEAVSW_Devel/15 7/13/05 2:10p erickson * PR16138: added new NAV version for AVC support, PPS and SPS support * added, refactored player to better support this with less code * duplication * * Irvine_BSEAVSW_Devel/14 9/21/04 4:06p erickson * PR12728: cleaned up pedantic warnings * * Irvine_BSEAVSW_Devel/13 2/14/03 1:57p erickson * New naming convention * Fixed looping from previous rework * Removed bcmindexer _getParam/_setParam * Did not change code shared between tsplayer and bcmplayer * Refactored settings, playmode and other structures * * Irvine_HDDemo_Devel/12 9/26/02 3:4p erickson * Changed bcmindexer vchip from 3 bits to 16 bits packed into 12 bits. * The index is NOT backward compatible, but the 3 bit version had only * been released for 1 day. * * Irvine_HDDemo_Devel/11 9/10/02 10:37a erickson * converted vchip from 16 bits in [7] to 3 bits in [5] * * Irvine_HDDemo_Devel\9 7/2/02 4:52p erickson * added some parens for the macros * * Irvine_HDDemo_Devel\8 4/17/02 1:16p erickson * Made sBcmIndexEntry public * Added timestamp * * Irvine_HDDemo_Devel\7 4/16/02 12:58p erickson * Changed header * * ***************************************************************************/ #ifndef BCMINDEXERPRIV_H #define BCMINDEXERPRIV_H /******************************* * * BNAV_Entry * ******/ /* defines and typedefs used internally by both bcmplayer and bcmindexer */ #define BNAV_set_frameType( pEntry, frameType ) \ ((pEntry)->words[0] &= 0x00fffffful, \ (pEntry)->words[0] |= ((unsigned long)(frameType) << 24)) #define BNAV_get_frameType( pEntry ) \ ((eSCType)((pEntry)->words[0] >> 24)) #define BNAV_set_seqHdrStartOffset( pEntry, seqHdrStartOffset ) \ ((pEntry)->words[0] &= 0xff000000ul, \ (pEntry)->words[0] |= ((seqHdrStartOffset) & 0x00fffffful)) #define BNAV_get_seqHdrStartOffset( pEntry ) \ ((unsigned long)((pEntry)->words[0] & 0xffffff)) #define BNAV_set_seqHdrSize( pEntry, seqHdrSize ) \ ((pEntry)->words[1] &= 0x0000fffful, \ (pEntry)->words[1] |= ((unsigned long)(seqHdrSize) << 16)) #define BNAV_get_seqHdrSize( pEntry ) \ ((unsigned short)(((pEntry)->words[1] >> 16) & 0xffff)) #define BNAV_set_refFrameOffset( pEntry, refFrameOffset ) \ ((pEntry)->words[1] &= 0xffff00fful, \ (pEntry)->words[1] |= ((unsigned long)(refFrameOffset) << 8)) #define BNAV_get_refFrameOffset( pEntry ) \ ((unsigned char)(((pEntry)->words[1] >> 8) & 0xff)) #define BNAV_set_version( pEntry, version ) \ ((pEntry)->words[1] &= 0xffffff0ful, \ (pEntry)->words[1] |= (unsigned long)(((version) & 0xf) << 4)) #define BNAV_get_version( pEntry ) \ ((unsigned char)((pEntry)->words[1] & 0xf0)>>4) /* NOTE: Lower 4 bits of [1] available */ #define BNAV_set_frameOffsetHi( pEntry, frameOffsetHi ) \ ((pEntry)->words[2] = (frameOffsetHi)) #define BNAV_get_frameOffsetHi( pEntry ) \ ((pEntry)->words[2]) #define BNAV_set_frameOffsetLo( pEntry, frameOffsetLo ) \ ((pEntry)->words[3] = (frameOffsetLo)) #define BNAV_get_frameOffsetLo( pEntry ) \ ((pEntry)->words[3]) #define BNAV_set_framePts( pEntry, framePts ) \ ((pEntry)->words[4] = (framePts)) #define BNAV_get_framePts( pEntry ) \ ((pEntry)->words[4]) /** * Maximum frameSize is 256 MB (28 bits). This should * be large enough for the largest HD I-frame possible. **/ #define BNAV_set_frameSize( pEntry, frameSize ) \ ((pEntry)->words[5] &= 0xf0000000ul, \ (pEntry)->words[5] |= ((unsigned long)(frameSize) & 0x0ffffffful)) #define BNAV_get_frameSize( pEntry ) \ ((pEntry)->words[5] & 0x0ffffffful) /* NOTE: Upper 4 bits of [5] available */ #define BNAV_set_timestamp( pEntry, timestamp) \ ((pEntry)->words[6] = (timestamp)) #define BNAV_get_timestamp( pEntry ) \ ((pEntry)->words[6]) /** * 12 bits for packed vchip information. See BNAV_pack_vchip and * BNAV_unpack_vchip. **/ #define BNAV_set_packed_vchip( pEntry, vchipdata) \ ((pEntry)->words[7] &= 0xfffff000ul, \ (pEntry)->words[7] |= (unsigned long)((vchipdata) & 0xfff)) #define BNAV_get_packed_vchip( pEntry ) \ ((unsigned short)((pEntry)->words[7] & 0xfff)) /* NOTE: Upper 20 bits of [7] available */ /******************************* * * BNAV_AVC_Entry * ******/ /* SPS is sequence parameter set. 24 bits allows 16 MB offset in stream. */ #define BNAV_set_SPS_Offset( pEntry, seqHdrStartOffset ) \ ((pEntry)->words[8] &= 0xff000000ul, \ (pEntry)->words[8] |= ((seqHdrStartOffset) & 0x00fffffful)) #define BNAV_get_SPS_Offset( pEntry ) \ ((unsigned long)((pEntry)->words[8] & 0xffffff)) /* 16 bits allows 64 KB for SPS, which is far more than enough. */ #define BNAV_set_SPS_Size( pEntry, seqHdrStartOffset ) \ ((pEntry)->words[9] &= 0xffff0000ul, \ (pEntry)->words[9] |= ((seqHdrStartOffset) & 0x0000fffful)) #define BNAV_get_SPS_Size( pEntry ) \ ((unsigned long)((pEntry)->words[9] & 0xffff)) #define BNAV_set_RandomAccessIndicator( pEntry, randomAccessIndicator) \ (((BNAV_AVC_Entry*)pEntry)->words[10] &= 0xfffffffeul, \ ((BNAV_AVC_Entry*)pEntry)->words[10] |= ((randomAccessIndicator) & 0x00000001ul)) #define BNAV_get_RandomAccessIndicator( pEntry ) \ ((unsigned long)(((BNAV_AVC_Entry*)pEntry)->words[10] & 0x1)) /* Convert eSCType to a string */ extern const char * const BNAV_frameTypeStr[]; typedef enum { eSCTypeSeqHdr, /* Sequence header */ eSCTypeIFrame, /* I-frame */ eSCTypePFrame, /* P-frame */ eSCTypeBFrame, /* B-frame */ eSCTypeGOPHdr, /* GOP header */ eSCTypeRPFrame, /* Reference picture frame */ eSCTypeUnknown /* Unknown or "don't care" frame type */ } eSCType; /** * Convert 12 bit vchip data to 16 bit vchip data. **/ unsigned short BNAV_unpack_vchip(unsigned short packed_vchip); /** * Convert 16 bit vchip data to 12 bit vchip data, checking the 16 bit * data for bits 6 and 14. If bits 6 and 14 are both 1, the vchip data * is valid and BNAV_pack_vchip returns 0 and the packed value is * written to *packed_vchip. Otherwise it returns -1 and *packed_vchip is left unchanged. */ int BNAV_pack_vchip(unsigned short unpacked_vchip, unsigned short *packed_vchip); struct BNAV_Indexer_HandleImpl { BNAV_Indexer_Settings settings; unsigned long TransRecordByteCount; /* Running counter of number of bytes recorded */ unsigned long TransRecordByteCountHi; /* Running counter of number of bytes recorded (hi word) */ unsigned long TransByteOffset; /* Running count of number of bytes processed in cur packet */ char seqHdrFlag; /* Flag indicating if MPEG2 sequence header information was found. */ char isISlice; /* Flag indicating that we found an I-slice or I-frame */ char isHits; /* Flag indicating we're dealing with a HITS-stream */ char hitFirstISlice; /* Flag indicating that we've hit the first I-slice */ unsigned long seqHdrSize; /* Number of bytes in the sequence header */ unsigned long seqHdrStartOffset; /* Sequence header offset (in bytes) relative to frame offset */ unsigned long picStart; /* Offset of start of picture */ unsigned long picEnd; /* Offset of end of picture */ unsigned fieldEncodedCount; /* count of fields in a field encoded picture */ unsigned char rfo; /* Reference frame offset counter */ BNAV_Entry curEntry; /* The current MPEG2 structure that is being populated */ BNAV_AVC_Entry avcEntry; /* The current AVC structure that is being populated. */ unsigned long next_pts; /* pts buffer for next picture frame */ bool random_access_indicator; long starttime; /* base timestamp for calculating NAV timestamp */ long lasttime; /* last timestamp written to NAV entry */ struct { unsigned frameCount; unsigned lastPts; unsigned rate; /* in 45KHz/frame units */ } ptsBasedFrameRate; unsigned prev_pc; /* previous picture code */ int prev_I_rfo; /* This contains the rfo for the previous I frame, until the next P frame is detected. This value is added to the rfo of the open gop B frames. */ unsigned short vchip; /* Current packed vchip state */ struct { #define MAX_GOP_SIZE 50 BNAV_Entry entry[MAX_GOP_SIZE]; int total_entries; } reverse; /* this information is used to report BNAV_Indexer_GetPosition consistently */ int totalEntriesWritten; BNAV_Entry lastEntryWritten; int allowOpenGopBs; /* define structures for AVC indexing */ #define TOTAL_PPS_ID 256 #define TOTAL_SPS_ID 32 struct { int current_sps, current_pps; /* if -1, then no SPS or PPS being captured */ int is_reference_picture; /* if true, then this picture has at least one slice that is referenced by another slice. this picture is not dropppable. */ struct { unsigned long offset; unsigned long size; int sps_id; } pps[TOTAL_PPS_ID]; struct { unsigned long offset; unsigned long size; } sps[TOTAL_SPS_ID]; unsigned long current_sei; bool current_sei_valid; } avc; /* instead of complicated wraparound logic, I buffer a minimum amount before processing PES payload. MIN_PES_PAYLOAD includes the startcode byte itself. */ #define MIN_PES_PAYLOAD 5 struct { unsigned char buf[MIN_PES_PAYLOAD + 2]; int bufsize; int sccount; uint64_t offset; bool vc1_interlace; uint64_t sequence_offset; int sequence_size; uint64_t entrypoint_offset; int entrypoint_size; } pes; /* bcmindexer "full packet" support allows bcmindexer to process a whole TS packet in the ITB. The whole TS packet is needed if the # of ITB's is greater than 10 per TS packet. You must #define BXPT_STARTCODE_BUFFER_WORKAROUND in XPT PI to enable this feature in the FW. */ unsigned fullPacketCount; #define BCMINDEXER_TS_PACKET_SIZE 188 uint8_t fullPacket[BCMINDEXER_TS_PACKET_SIZE]; struct { unsigned offset, offsetHi; } lastPacketOffset; }; int BNAV_P_FeedPES_VC1(BNAV_Indexer_Handle handle, uint8_t *p_bfr, unsigned size); int BNAV_Indexer_completeFrameAux(BNAV_Indexer_Handle handle, void *data, /* data points to either a BNAV_Entry or a BNAV_AVC_Entry. */ int size /* size of data */ ); #endif