/H264Dec/source/h264bsd_util.h

http://github.com/mbebenita/Broadway · C Header · 178 lines · 86 code · 36 blank · 56 comment · 8 complexity · 5f1adbe1c6732a7c538c0f4b415b39f9 MD5 · raw file

  1. /*
  2. * Copyright (C) 2009 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*------------------------------------------------------------------------------
  17. Table of contents
  18. 1. Include headers
  19. 2. Module defines
  20. 3. Data types
  21. 4. Function prototypes
  22. ------------------------------------------------------------------------------*/
  23. #ifndef H264SWDEC_UTIL_H
  24. #define H264SWDEC_UTIL_H
  25. /*------------------------------------------------------------------------------
  26. 1. Include headers
  27. ------------------------------------------------------------------------------*/
  28. #ifdef _ASSERT_USED
  29. #include <assert.h>
  30. #endif
  31. #include "H264SwDecApi.h"
  32. #if defined(_RANGE_CHECK) || defined(_DEBUG_PRINT) || defined(_ERROR_PRINT)
  33. #include <stdio.h>
  34. #endif
  35. #include "basetype.h"
  36. #include "h264bsd_stream.h"
  37. #include "h264bsd_image.h"
  38. /*------------------------------------------------------------------------------
  39. 2. Module defines
  40. ------------------------------------------------------------------------------*/
  41. #define HANTRO_OK 0
  42. #define HANTRO_NOK 1
  43. #define HANTRO_TRUE (1)
  44. #define HANTRO_FALSE (0)
  45. #ifndef NULL
  46. #define NULL 0
  47. #endif
  48. #define MEMORY_ALLOCATION_ERROR 0xFFFF
  49. #define PARAM_SET_ERROR 0xFFF0
  50. /* value to be returned by GetBits if stream buffer is empty */
  51. #define END_OF_STREAM 0xFFFFFFFFU
  52. #define EMPTY_RESIDUAL_INDICATOR 0xFFFFFF
  53. /* macro to mark a residual block empty, i.e. contain zero coefficients */
  54. #define MARK_RESIDUAL_EMPTY(residual) ((residual)[0] = EMPTY_RESIDUAL_INDICATOR)
  55. /* macro to check if residual block is empty */
  56. #define IS_RESIDUAL_EMPTY(residual) ((residual)[0] == EMPTY_RESIDUAL_INDICATOR)
  57. /* macro for assertion, used only if compiler flag _ASSERT_USED is defined */
  58. #ifdef _ASSERT_USED
  59. #define ASSERT(expr) assert(expr)
  60. #else
  61. #define ASSERT(expr)
  62. #endif
  63. /* macro for range checking an value, used only if compiler flag _RANGE_CHECK
  64. * is defined */
  65. #ifdef _RANGE_CHECK
  66. #define RANGE_CHECK(value, minBound, maxBound) \
  67. { \
  68. if ((value) < (minBound) || (value) > (maxBound)) \
  69. fprintf(stderr, "Warning: Value exceeds given limit(s)!\n"); \
  70. }
  71. #else
  72. #define RANGE_CHECK(value, minBound, maxBound)
  73. #endif
  74. /* macro for range checking an array, used only if compiler flag _RANGE_CHECK
  75. * is defined */
  76. #ifdef _RANGE_CHECK
  77. #define RANGE_CHECK_ARRAY(array, minBound, maxBound, length) \
  78. { \
  79. i32 i; \
  80. for (i = 0; i < (length); i++) \
  81. if ((array)[i] < (minBound) || (array)[i] > (maxBound)) \
  82. fprintf(stderr,"Warning: Value [%d] exceeds given limit(s)!\n",i); \
  83. }
  84. #else
  85. #define RANGE_CHECK_ARRAY(array, minBound, maxBound, length)
  86. #endif
  87. /* macro for debug printing, used only if compiler flag _DEBUG_PRINT is
  88. * defined */
  89. #ifdef _DEBUG_PRINT
  90. #define DEBUG(args) printf args
  91. #else
  92. #define DEBUG(args)
  93. #endif
  94. /* macro for error printing, used only if compiler flag _ERROR_PRINT is
  95. * defined */
  96. #ifdef _ERROR_PRINT
  97. #define EPRINT(msg) fprintf(stderr,"ERROR: %s\n",msg)
  98. #else
  99. #define EPRINT(msg)
  100. #endif
  101. /* macro to get smaller of two values */
  102. #define MIN(a, b) (((a) < (b)) ? (a) : (b))
  103. /* macro to get greater of two values */
  104. #define MAX(a, b) (((a) > (b)) ? (a) : (b))
  105. /* macro to get absolute value */
  106. #define ABS(a) (((a) < 0) ? -(a) : (a))
  107. /* macro to clip a value z, so that x <= z =< y */
  108. #define CLIP3(x,y,z) (((z) < (x)) ? (x) : (((z) > (y)) ? (y) : (z)))
  109. /* macro to clip a value z, so that 0 <= z =< 255 */
  110. #define CLIP1(z) (((z) < 0) ? 0 : (((z) > 255) ? 255 : (z)))
  111. /* macro to allocate memory */
  112. #define ALLOCATE(ptr, count, type) \
  113. { \
  114. (ptr) = H264SwDecMalloc((count) * sizeof(type)); \
  115. }
  116. /* macro to free allocated memory */
  117. #define FREE(ptr) \
  118. { \
  119. H264SwDecFree((ptr)); (ptr) = NULL; \
  120. }
  121. #define ALIGN(ptr, bytePos) \
  122. (ptr + ( ((bytePos - (int)ptr) & (bytePos - 1)) / sizeof(*ptr) ))
  123. extern const u32 h264bsdQpC[52];
  124. /*------------------------------------------------------------------------------
  125. 3. Data types
  126. ------------------------------------------------------------------------------*/
  127. /*------------------------------------------------------------------------------
  128. 4. Function prototypes
  129. ------------------------------------------------------------------------------*/
  130. #ifndef H264DEC_NEON
  131. u32 h264bsdCountLeadingZeros(u32 value, u32 length);
  132. #else
  133. u32 h264bsdCountLeadingZeros(u32 value);
  134. #endif
  135. u32 h264bsdRbspTrailingBits(strmData_t *strmData);
  136. u32 h264bsdMoreRbspData(strmData_t *strmData);
  137. u32 h264bsdNextMbAddress(u32 *pSliceGroupMap, u32 picSizeInMbs, u32 currMbAddr);
  138. void h264bsdSetCurrImageMbPointers(image_t *image, u32 mbNum);
  139. #endif /* #ifdef H264SWDEC_UTIL_H */