rv_utils.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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: rv_utils.h,v $
  23. -- $Date: 2009/03/11 14:00:12 $
  24. -- $Revision: 1.1 $
  25. --
  26. ------------------------------------------------------------------------------*/
  27. #ifndef RV_UTILS_H
  28. #define RV_UTILS_H
  29. /*------------------------------------------------------------------------------
  30. 1. Include headers
  31. ------------------------------------------------------------------------------*/
  32. #include "rv_container.h"
  33. #ifdef _ASSERT_USED
  34. #include <assert.h>
  35. #endif
  36. #ifdef _UTEST
  37. #include <stdio.h>
  38. #endif
  39. /*------------------------------------------------------------------------------
  40. 2. Module defines
  41. ------------------------------------------------------------------------------*/
  42. /* constant definitions */
  43. #ifndef OK
  44. #define OK 0
  45. #endif
  46. #ifndef NOK
  47. #define NOK 1
  48. #endif
  49. #ifndef FALSE
  50. #define FALSE 0
  51. #endif
  52. #ifndef TRUE
  53. #define TRUE 1
  54. #endif
  55. #ifndef NULL
  56. #define NULL 0
  57. #endif
  58. /* decoder states */
  59. enum
  60. {
  61. STATE_OK,
  62. STATE_NOT_READY,
  63. STATE_SYNC_LOST
  64. };
  65. #define HANTRO_OK 0
  66. #define HANTRO_NOK 1
  67. #ifndef NULL
  68. #define NULL 0
  69. #endif
  70. /* Error concealment */
  71. #define FREEZED_PIC_RDY 1
  72. enum
  73. {
  74. RV_I_PIC = 0,
  75. RV_FI_PIC = 1,
  76. RV_P_PIC = 2,
  77. RV_B_PIC = 3
  78. };
  79. enum
  80. {
  81. RV_SLICE
  82. };
  83. /* value to be returned by GetBits if stream buffer is empty */
  84. #define END_OF_STREAM 0xFFFFFFFFU
  85. /* macro for debug printing. Note that double parenthesis has to be used, i.e.
  86. * DEBUG(("Debug printing %d\n",%d)) */
  87. #ifdef _UTEST
  88. #define DEBUG(args) printf args
  89. #else
  90. #define DEBUG(args)
  91. #endif
  92. /* macro for assertion, used only if compiler flag _ASSERT_USED is defined */
  93. #ifdef _ASSERT_USED
  94. #define ASSERT(expr) assert(expr)
  95. #else
  96. #define ASSERT(expr)
  97. #endif
  98. /* macro to check if stream ends */
  99. #define IS_END_OF_STREAM(pContainer) \
  100. ( (pContainer)->StrmDesc.strmBuffReadBits == \
  101. (8*(pContainer)->StrmDesc.strmBuffSize) )
  102. /* macro to saturate value to range [min,max]. Note that for unsigned value
  103. * both min and max should be positive, otherwise result will be wrong due to
  104. * arithmetic conversion. If min > max -> value will be equal to min. */
  105. #define SATURATE(min,value,max) \
  106. if ((value) < (min)) (value) = (min); \
  107. else if ((value) > (max)) (value) = (max);
  108. #define ABS(val) (((val) < 0) ? -(val) : (val))
  109. /*------------------------------------------------------------------------------
  110. 3. Data types
  111. ------------------------------------------------------------------------------*/
  112. typedef struct
  113. {
  114. u8 *pStrmBuffStart; /* pointer to start of stream buffer */
  115. u8 *pStrmCurrPos; /* current read address in stream buffer */
  116. u32 bitPosInWord; /* bit position in stream buffer byte */
  117. u32 strmBuffSize; /* size of stream buffer (bytes) */
  118. u32 strmBuffReadBits; /* number of bits read from stream buffer */
  119. } strmData_t;
  120. /*------------------------------------------------------------------------------
  121. 4. Function prototypes
  122. ------------------------------------------------------------------------------*/
  123. u32 rv_GetBits(DecContainer *, u32 numBits);
  124. u32 rv_ShowBits(DecContainer *, u32 numBits);
  125. u32 rv_ShowBits32(DecContainer *);
  126. u32 rv_FlushBits(DecContainer *, u32 numBits);
  127. u32 rv_CheckStuffing(DecContainer *);
  128. u32 rv_NumBits(u32 value);
  129. #endif /* RV_UTILS_H */