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 /*------------------------------------------------------------------------------ 18 19 Table of contents 20 21 1. Include headers 22 2. Module defines 23 3. Data types 24 4. Function prototypes 25 26 ------------------------------------------------------------------------------*/ 27 28 #ifndef H264SWDEC_UTIL_H 29 #define H264SWDEC_UTIL_H 30 31 /*------------------------------------------------------------------------------ 32 1. Include headers 33 ------------------------------------------------------------------------------*/ 34 35 #ifdef _ASSERT_USED 36 #include <assert.h> 37 #endif 38 39 #include "H264SwDecApi.h" 40 41 #if defined(_RANGE_CHECK) || defined(_DEBUG_PRINT) || defined(_ERROR_PRINT) 42 #include <stdio.h> 43 #endif 44 45 #include <stdint.h> 46 #include "basetype.h" 47 #include "h264bsd_stream.h" 48 #include "h264bsd_image.h" 49 50 /*------------------------------------------------------------------------------ 51 2. Module defines 52 ------------------------------------------------------------------------------*/ 53 54 #define HANTRO_OK 0 55 #define HANTRO_NOK 1 56 57 #define HANTRO_TRUE (1) 58 #define HANTRO_FALSE (0) 59 60 #ifndef NULL 61 #define NULL 0 62 #endif 63 64 #define MEMORY_ALLOCATION_ERROR 0xFFFF 65 #define PARAM_SET_ERROR 0xFFF0 66 67 /* value to be returned by GetBits if stream buffer is empty */ 68 #define END_OF_STREAM 0xFFFFFFFFU 69 70 #define EMPTY_RESIDUAL_INDICATOR 0xFFFFFF 71 72 /* macro to mark a residual block empty, i.e. contain zero coefficients */ 73 #define MARK_RESIDUAL_EMPTY(residual) ((residual)[0] = EMPTY_RESIDUAL_INDICATOR) 74 /* macro to check if residual block is empty */ 75 #define IS_RESIDUAL_EMPTY(residual) ((residual)[0] == EMPTY_RESIDUAL_INDICATOR) 76 77 /* macro for assertion, used only if compiler flag _ASSERT_USED is defined */ 78 #ifdef _ASSERT_USED 79 #define ASSERT(expr) assert(expr) 80 #else 81 #define ASSERT(expr) 82 #endif 83 84 /* macro for range checking an value, used only if compiler flag _RANGE_CHECK 85 * is defined */ 86 #ifdef _RANGE_CHECK 87 #define RANGE_CHECK(value, minBound, maxBound) \ 88 { \ 89 if ((value) < (minBound) || (value) > (maxBound)) \ 90 fprintf(stderr, "Warning: Value exceeds given limit(s)!\n"); \ 91 } 92 #else 93 #define RANGE_CHECK(value, minBound, maxBound) 94 #endif 95 96 /* macro for range checking an array, used only if compiler flag _RANGE_CHECK 97 * is defined */ 98 #ifdef _RANGE_CHECK 99 #define RANGE_CHECK_ARRAY(array, minBound, maxBound, length) \ 100 { \ 101 i32 i; \ 102 for (i = 0; i < (length); i++) \ 103 if ((array)[i] < (minBound) || (array)[i] > (maxBound)) \ 104 fprintf(stderr,"Warning: Value [%d] exceeds given limit(s)!\n",i); \ 105 } 106 #else 107 #define RANGE_CHECK_ARRAY(array, minBound, maxBound, length) 108 #endif 109 110 /* macro for debug printing, used only if compiler flag _DEBUG_PRINT is 111 * defined */ 112 #ifdef _DEBUG_PRINT 113 #define DEBUG(args) printf args 114 #else 115 #define DEBUG(args) 116 #endif 117 118 /* macro for error printing, used only if compiler flag _ERROR_PRINT is 119 * defined */ 120 #ifdef _ERROR_PRINT 121 #define EPRINT(msg) fprintf(stderr,"ERROR: %s\n",msg) 122 #else 123 #define EPRINT(msg) 124 #endif 125 126 /* macro to get smaller of two values */ 127 #define MIN(a, b) (((a) < (b)) ? (a) : (b)) 128 129 /* macro to get greater of two values */ 130 #define MAX(a, b) (((a) > (b)) ? (a) : (b)) 131 132 /* macro to get absolute value */ 133 #define ABS(a) (((a) < 0) ? -(a) : (a)) 134 135 /* macro to clip a value z, so that x <= z =< y */ 136 #define CLIP3(x,y,z) (((z) < (x)) ? (x) : (((z) > (y)) ? (y) : (z))) 137 138 /* macro to clip a value z, so that 0 <= z =< 255 */ 139 #define CLIP1(z) (((z) < 0) ? 0 : (((z) > 255) ? 255 : (z))) 140 141 /* macro to allocate memory */ 142 #define ALLOCATE(ptr, count, type) \ 143 { \ 144 (ptr) = H264SwDecMalloc(sizeof(type), (count)); \ 145 } 146 147 /* macro to free allocated memory */ 148 #define FREE(ptr) \ 149 { \ 150 H264SwDecFree((ptr)); (ptr) = NULL; \ 151 } 152 153 #define ALIGN(ptr, bytePos) \ 154 (ptr + ( ((bytePos - (uintptr_t)ptr) & (bytePos - 1)) / sizeof(*ptr) )) 155 156 extern const u32 h264bsdQpC[52]; 157 158 /*------------------------------------------------------------------------------ 159 3. Data types 160 ------------------------------------------------------------------------------*/ 161 162 /*------------------------------------------------------------------------------ 163 4. Function prototypes 164 ------------------------------------------------------------------------------*/ 165 #ifndef H264DEC_NEON 166 u32 h264bsdCountLeadingZeros(u32 value, u32 length); 167 #else 168 u32 h264bsdCountLeadingZeros(u32 value); 169 #endif 170 u32 h264bsdRbspTrailingBits(strmData_t *strmData); 171 172 u32 h264bsdMoreRbspData(strmData_t *strmData); 173 174 u32 h264bsdNextMbAddress(u32 *pSliceGroupMap, u32 picSizeInMbs, u32 currMbAddr); 175 176 void h264bsdSetCurrImageMbPointers(image_t *image, u32 mbNum); 177 178 #endif /* #ifdef H264SWDEC_UTIL_H */ 179 180