mp4dechwd_utils.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /*------------------------------------------------------------------------------
  2. -- --
  3. -- This software is confidential and proprietary and may be used --
  4. -- only as expressly authorized by a licensing agreement from --
  5. -- --
  6. -- Hantro Products Oy. --
  7. -- --
  8. -- (C) COPYRIGHT 2006 HANTRO PRODUCTS OY --
  9. -- ALL RIGHTS RESERVED --
  10. -- --
  11. -- The entire notice above must be reproduced --
  12. -- on all copies and should not be removed. --
  13. -- --
  14. --------------------------------------------------------------------------------
  15. --
  16. -- Abstract : Header file for stream decoding utilities
  17. --
  18. --------------------------------------------------------------------------------
  19. --
  20. -- Version control information, please leave untouched.
  21. --
  22. -- $RCSfile: mp4dechwd_utils.h,v $
  23. -- $Date: 2008/01/14 14:36:24 $
  24. -- $Revision: 1.3 $
  25. --
  26. ------------------------------------------------------------------------------*/
  27. #ifndef STRMDEC_UTILS_H_DEFINED
  28. #define STRMDEC_UTILS_H_DEFINED
  29. #include "mp4dechwd_container.h"
  30. /* constant definitions */
  31. #ifndef HANTRO_OK
  32. #define HANTRO_OK 0
  33. #endif
  34. #ifndef HANTRO_NOK
  35. #define HANTRO_NOK 1
  36. #endif
  37. #ifndef HANTRO_FALSE
  38. #define HANTRO_FALSE 0
  39. #endif
  40. #ifndef HANTRO_TRUE
  41. #define HANTRO_TRUE 1
  42. #endif
  43. #define AMBIGUOUS 2
  44. #ifndef NULL
  45. #define NULL 0
  46. #endif
  47. /* decoder states */
  48. enum
  49. {
  50. STATE_OK,
  51. STATE_NOT_READY,
  52. STATE_SYNC_LOST
  53. };
  54. /* start codes */
  55. enum
  56. {
  57. SC_VO_START = 0x00000100,
  58. SC_VOL_START = 0x00000120,
  59. SC_VOS_START = 0x000001B0,
  60. SC_VOS_END = 0x000001B1,
  61. SC_UD_START = 0x000001B2,
  62. SC_GVOP_START = 0x000001B3,
  63. SC_VISO_START = 0x000001B5,
  64. SC_VOP_START = 0x000001B6,
  65. SC_RESYNC = 0x1,
  66. SC_SV_START = 0x20,
  67. SC_SORENSON_START = 0x10,
  68. SC_SV_END = 0x3F,
  69. SC_NOT_FOUND = 0xFFFE,
  70. SC_ERROR = 0xFFFF
  71. };
  72. enum
  73. {
  74. MB_INTER = 0,
  75. MB_INTERQ = 1,
  76. MB_INTER4V = 2,
  77. MB_INTRA = 3,
  78. MB_INTRAQ = 4,
  79. MB_STUFFING = 5
  80. };
  81. enum
  82. {
  83. IVOP = 0,
  84. PVOP = 1,
  85. BVOP = 2,
  86. NOT_SET
  87. };
  88. /*enum {
  89. DEC = 0,
  90. HEX = 1,
  91. BIN = 2
  92. };*/
  93. /* value to be returned by StrmDec_GetBits if stream buffer is empty */
  94. #define END_OF_STREAM 0xFFFFFFFFU
  95. /* How many control words(32bit) does one mb take */
  96. #define NBR_OF_WORDS_MB 1
  97. /* how many motion vector data words for mb */
  98. #define NBR_MV_WORDS_MB 4
  99. /* how many DC VLC data words for mb */
  100. #define NBR_DC_WORDS_MB 2
  101. enum
  102. {
  103. OUT_OF_BUFFER = 0xFF
  104. };
  105. /* Bit positions in Asic CtrlBits memory ( specified in top level spec ) */
  106. enum
  107. {
  108. ASICPOS_MBTYPE = 31,
  109. ASICPOS_4MV = 30,
  110. ASICPOS_USEINTRADCVLC = 30,
  111. ASICPOS_VPBI = 29,
  112. ASICPOS_ACPREDFLAG = 28,
  113. ASICPOS_QP = 16,
  114. ASICPOS_CONCEAL = 15,
  115. ASICPOS_MBNOTCODED = 14
  116. };
  117. /* Boundary strenght positions in ctrlBits */
  118. enum
  119. {
  120. BS_VER_00 = 13,
  121. BS_HOR_00 = 10,
  122. BS_VER_02 = 7,
  123. BS_HOR_01 = 4,
  124. BS_VER_04 = 1,
  125. BS_HOR_02_MSB = 0,
  126. BS_HOR_02_LSB = 30,
  127. BS_VER_06 = 27,
  128. BS_HOR_03 = 24,
  129. BS_VER_08 = 21,
  130. BS_HOR_08 = 18,
  131. BS_VER_10 = 15,
  132. BS_HOR_09 = 12,
  133. BS_VER_12 = 9,
  134. BS_HOR_10 = 6,
  135. BS_VER_14 = 3,
  136. BS_HOR_11 = 0
  137. };
  138. enum
  139. {
  140. ASIC_ZERO_MOTION_VECTORS_LUM = 0,
  141. ASIC_ZERO_MOTION_VECTORS_CHR = 0
  142. };
  143. enum
  144. {
  145. MB_NOT_CODED = 0x80
  146. };
  147. #define MB_IS_INTRA(mbNumber) \
  148. ( (pDecContainer->MBDesc[mbNumber].typeOfMB == MB_INTRA) || \
  149. (pDecContainer->MBDesc[mbNumber].typeOfMB == MB_INTRAQ) )
  150. #define MB_IS_INTER(mbNumber) \
  151. (pDecContainer->MBDesc[mbNumber].typeOfMB <= MB_INTER4V)
  152. #define MB_IS_INTER4V(mbNumber) \
  153. (pDecContainer->MBDesc[mbNumber].typeOfMB == MB_INTER4V)
  154. #define MB_IS_STUFFING(mbNumber) \
  155. (pDecContainer->MBDesc[mbNumber].typeOfMB == MB_STUFFING)
  156. #define MB_HAS_DQUANT(mbNumber) \
  157. ( (pDecContainer->MBDesc[mbNumber].typeOfMB == MB_INTERQ) || \
  158. (pDecContainer->MBDesc[mbNumber].typeOfMB == MB_INTRAQ) )
  159. /* macro to check if stream ends */
  160. #define IS_END_OF_STREAM(pContainer) \
  161. ( (pContainer)->StrmDesc.strmBuffReadBits == \
  162. (8*(pContainer)->StrmDesc.strmBuffSize) )
  163. #define SATURATE(min,value,max) \
  164. if ((value) < (min)) (value) = (min); \
  165. else if ((value) > (max)) (value) = (max);
  166. #define SHOWBITS32(tmp) \
  167. { \
  168. i32 bits, shift; \
  169. const u8 *pstrm = pDecContainer->StrmDesc.pStrmCurrPos; \
  170. bits = (i32)pDecContainer->StrmDesc.strmBuffSize*8 - \
  171. (i32)pDecContainer->StrmDesc.strmBuffReadBits; \
  172. if (bits >= 32) \
  173. { \
  174. tmp = ((u32)pstrm[0] << 24) | ((u32)pstrm[1] << 16) | \
  175. ((u32)pstrm[2] << 8) | ((u32)pstrm[3]); \
  176. if (pDecContainer->StrmDesc.bitPosInWord) \
  177. { \
  178. tmp <<= pDecContainer->StrmDesc.bitPosInWord; \
  179. tmp |= \
  180. (u32)pstrm[4]>>(8-pDecContainer->StrmDesc.bitPosInWord); \
  181. } \
  182. } \
  183. else if (bits) \
  184. { \
  185. shift = 24 + pDecContainer->StrmDesc.bitPosInWord; \
  186. tmp = (u32)(*pstrm++) << shift; \
  187. bits -= 8 - pDecContainer->StrmDesc.bitPosInWord; \
  188. while (bits > 0) \
  189. { \
  190. shift -= 8; \
  191. tmp |= (u32)(*pstrm++) << shift; \
  192. bits -= 8; \
  193. } \
  194. } \
  195. else \
  196. tmp = 0; \
  197. }
  198. #define FLUSHBITS(bits) \
  199. { \
  200. u32 FBtmp;\
  201. if ( (pDecContainer->StrmDesc.strmBuffReadBits + bits) > \
  202. (8*pDecContainer->StrmDesc.strmBuffSize) ) \
  203. { \
  204. pDecContainer->StrmDesc.strmBuffReadBits = \
  205. 8 * pDecContainer->StrmDesc.strmBuffSize; \
  206. pDecContainer->StrmDesc.bitPosInWord = 0; \
  207. pDecContainer->StrmDesc.pStrmCurrPos = \
  208. pDecContainer->StrmDesc.pStrmBuffStart + \
  209. pDecContainer->StrmDesc.strmBuffSize;\
  210. return(END_OF_STREAM);\
  211. }\
  212. else\
  213. {\
  214. pDecContainer->StrmDesc.strmBuffReadBits += bits;\
  215. FBtmp = pDecContainer->StrmDesc.bitPosInWord + bits;\
  216. pDecContainer->StrmDesc.pStrmCurrPos += FBtmp >> 3;\
  217. pDecContainer->StrmDesc.bitPosInWord = FBtmp & 0x7;\
  218. }\
  219. }
  220. /* function prototypes */
  221. u32 StrmDec_GetBits(DecContainer *, u32 numBits);
  222. u32 StrmDec_ShowBits(DecContainer *, u32 numBits);
  223. u32 StrmDec_ShowBitsAligned(DecContainer *, u32 numBits, u32 numBytes);
  224. u32 StrmDec_FlushBits(DecContainer *, u32 numBits);
  225. u32 StrmDec_UnFlushBits(DecContainer *, u32 numBits);
  226. void StrmDec_ProcessPacketFooter( DecContainer * );
  227. u32 StrmDec_GetStuffing(DecContainer *);
  228. u32 StrmDec_CheckStuffing(DecContainer *);
  229. u32 StrmDec_FindSync(DecContainer *);
  230. u32 StrmDec_GetStartCode(DecContainer *);
  231. u32 StrmDec_ProcessBvopExtraResync(DecContainer *);
  232. u32 StrmDec_NumBits(u32 value);
  233. #endif