📄 swdec_utils.h
字号:
/*------------------------------------------------------------------------------
-- --
-- This software is confidential and proprietary and may be used --
-- only as expressly authorized by a licensing agreement from --
-- --
-- Hantro Products Oy. --
-- --
-- In the event of publication, the following notice is applicable: --
-- --
-- (C) COPYRIGHT 2004 HANTRO PRODUCTS OY --
-- ALL RIGHTS RESERVED --
-- --
-- The entire notice above must be reproduced on all copies. --
-- --
--------------------------------------------------------------------------------
--
-- MODULE NAME: SwDec_Utils
--
-- DESCRIPTION: general utility functions and definitions of constants
--
-- PROVIDES:
-- SwDec_GetBits
-- SwDec_ShowBits
-- SwDec_ShowBits32
-- SwDec_ShowBitsAligned
-- SwDec_FlushBits
-- SwDec_UnFlushBits
-- SwDec_GetStuffing
-- SwDec_CheckStuffing
-- SwDec_FindSync
-- SwDec_GetStartCode
-- SwDec_NumBits
-- SwDec_GetOneBit
-------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
Table of contents
1. Include headers
2. Module defines
3. Data types
4. Function prototypes
------------------------------------------------------------------------------*/
#ifndef SWDEC_UTILS_H
#define SWDEC_UTILS_H
/*------------------------------------------------------------------------------
1. Include headers
------------------------------------------------------------------------------*/
#include "SwDec_Container.h"
#include "video_hantro_decoder_conf.hi"
#ifdef _ASSERT_USED
#include <assert.h>
#endif
#ifdef _UTEST
#include <stdio.h>
#endif
/*------------------------------------------------------------------------------
2. Module defines
------------------------------------------------------------------------------*/
#define HANTRO_OK 0
#define HANTRO_NOK 1
#ifndef NULL
#define NULL 0
#endif
#ifdef _UTEST
#define STATIC
#else
#define STATIC static
#endif
/* decoder states */
enum {
STATE_OK,
STATE_SYNC_LOST
};
/* start codes */
enum {
SC_VO_START = 0x00000100,
SC_VOL_START = 0x00000120,
SC_VOS_START = 0x000001B0,
SC_VOS_END = 0x000001B1,
SC_UD_START = 0x000001B2,
SC_GVOP_START = 0x000001B3,
SC_VISO_START = 0x000001B5,
SC_VOP_START = 0x000001B6,
SC_RESYNC = 0x1,
SC_SV_START = 0x20,
SC_SV_END = 0x3F,
SC_NOT_FOUND = 0xFFFE,
SC_ERROR = 0xFFFF
};
enum {
MB_INTER = 0,
MB_INTERQ = 1,
MB_INTER4V = 2,
MB_INTRA = 3,
MB_INTRAQ = 4,
MB_STUFFING= 5
};
enum {
IVOP = 0,
PVOP = 1
};
/* value to be returned by GetBits if stream buffer is empty */
#define END_OF_STREAM 0xFFFFFFFFU
enum {
MB_NOT_CODED = 0x80
};
#ifndef MP4DEC_H263_ONLY
enum {
SCAN_ZIGZAG = 0,
SCAN_HOR = 1,
SCAN_VER = 2
};
#endif
/* macro for debug printing. Note that double parenthesis has to be used, i.e.
* DEBUG(("Debug printing %d\n",%d)) */
#if 0
#ifdef _UTEST
#define DEBUG(args) printf args
#else
#define DEBUG(args)
#endif
#endif
/* macro for assertion, used only if compiler flag _ASSERT_USED is defined */
#ifdef _ASSERT_USED
#define ASSERT(expr) assert(expr)
#else
#define ASSERT(expr)
#endif
#define MB_IS_INTRA(mbNum) \
(pDecContainer->MbDesc[mbNum].flags ^ INTER_MB_MASK)
#define MB_IS_INTER(mbNum) \
(pDecContainer->MbDesc[mbNum].flags & INTER_MB_MASK)
#define MB_IS_STUFFING(mbNum) \
(pDecContainer->MbDesc[mbNum].typeOfMb == MB_STUFFING)
#define MB_HAS_DQUANT(mbNum) \
( (pDecContainer->MbDesc[mbNum].typeOfMb == MB_INTERQ) || \
(pDecContainer->MbDesc[mbNum].typeOfMb == MB_INTRAQ) )
/* macro to check if stream ends */
#define IS_END_OF_STREAM(pContainer) \
( (pContainer)->StrmDesc.strmBuffReadBits == \
(8*(pContainer)->StrmDesc.strmBuffSize) )
#ifndef _SKIP_EOS
#define CHECK_END_OF_STREAM(val) \
if ((val) == END_OF_STREAM) return(END_OF_STREAM);
#else
#define CHECK_END_OF_STREAM(val)
#endif
/* macro to saturate value to range [min,max]. Note that for unsigned value
* both min and max should be positive, otherwise result will be wrong due to
* arithmetic conversion. If min > max -> value will be equal to min. */
#define SATURATE(min,value,max) \
if ((value) < (min)) (value) = (min); \
else if ((value) > (max)) (value) = (max);
#define ABS(val) (((val) < 0) ? -(val) : (val))
#define DEQUANTIZE(val,QP) \
{ /*lint -e514 */ \
if ((val) < 0) \
{ \
(val) = (i32)(QP)*(2*(val) - 1) + !((QP)&0x1); \
if ((val) < -2048) (val) = -2048; \
} \
else if ((val) > 0) \
{ \
(val) = (i32)(QP)*(2*(val) + 1) - !((QP)&0x1); \
if ((val) > 2047) (val)=2047; \
}/*lint +e514 */ \
}
/* following four macros are used to handle temporary bit buffer of type
* tmpBuffer_t. BUFFER_SHOW 'shows' numBits bits in outVal. Bits are right
* aligned. BUFFER_FLUSH removes numBits from temporal buffer. There is no
* checking whether buffer contains enough bits -> to be used with caution.
* BUFFER_GET shows and removes bits. numBits should not be 0 in any of the
* macros. Note that BUFFER_GET indicates running out of bits kind of late
* compared to operation of corresponding functions. Additionally, BUFFER_FLUSH
* does not indicate that situation at all. */
#define BUFFER_INIT(buffer) \
{ \
(buffer).bits = 32; \
(buffer).value = SwDec_ShowBits32(pDecContainer); \
}
#define BUFFER_SHOW(buffer, outVal, numBits) \
{ \
if ((buffer).bits < (numBits)) \
{ \
if(SwDec_FlushBits(pDecContainer,32-(buffer).bits) == END_OF_STREAM) \
return(END_OF_STREAM); \
(buffer).value = SwDec_ShowBits32(pDecContainer); \
(buffer).bits = 32; \
} \
(outVal) = (buffer).value >> (32 - (numBits)); \
}
#define BUFFER_FLUSH(buffer, numBits) \
{ \
(buffer).value <<= (numBits); \
(buffer).bits -= (numBits); \
}
#define BUFFER_GET(buffer, outVal, numBits) \
{ \
if ((buffer).bits < (numBits)) \
{ \
if(SwDec_FlushBits(pDecContainer,32-(buffer).bits) == END_OF_STREAM) \
return(END_OF_STREAM); \
(buffer).value = SwDec_ShowBits32(pDecContainer); \
(buffer).bits = 32; \
} \
(outVal) = (buffer).value >> (32 - (numBits)); \
(buffer).value <<= (numBits); \
(buffer).bits -= (numBits); \
}
/*------------------------------------------------------------------------------
3. Data types
------------------------------------------------------------------------------*/
typedef struct
{
u32 value;
u32 bits;
} tmpBuffer_t;
/*------------------------------------------------------------------------------
4. Function prototypes
------------------------------------------------------------------------------*/
u32 SwDec_GetBits(decContainer_t *, u32 numBits);
u32 SwDec_ShowBits(decContainer_t *, u32 numBits);
u32 SwDec_ShowBits32(decContainer_t *);
u32 SwDec_ShowBitsAligned(decContainer_t *, u32 numBits, u32 numBytes);
u32 SwDec_FlushBits(decContainer_t *, u32 numBits);
u32 SwDec_UnFlushBits(decContainer_t *, u32 numBits);
u32 SwDec_GetOneBit(decContainer_t *pDecContainer);
u32 SwDec_SaveUserData(decContainer_t *pDecContainer, u32 mode);
#ifndef MP4DEC_H263_ONLY
u32 SwDec_GetStuffing(decContainer_t *);
u32 SwDec_CheckStuffing(decContainer_t *);
#endif
u32 SwDec_FindSync(decContainer_t *);
u32 SwDec_GetStartCode(decContainer_t *);
u32 SwDec_NumBits(u32 value);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -