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