📄 encuserdata.c
字号:
/*------------------------------------------------------------------------------
-- --
-- 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. --
-- --
--------------------------------------------------------------------------------
--
-- Description : Encoder internal
--
-------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
Table of context
1. Include headers
2. External compiler flags
3. Module defines
4. Local function prototypes
5. Functions
5.1 EncUserData
------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
1. Include headers
------------------------------------------------------------------------------*/
#include "encmemory.h"
#include "EncUserData.h"
#include "EncStartCode.h"
#include "EncTrace.h"
/*------------------------------------------------------------------------------
2. External compiler flags
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
3. Module defines
------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
4. Local function prototypes
------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
EncUserDataAlloc
Perform memory allocation needed by user data.
Input userData_s Pointer to userData_s structure.
data Poiter to user data source.
byteCnt User data size of source.
Return OK Memory allocation OK.
NOK Memory allocation fail.
------------------------------------------------------------------------------*/
bool_e EncUserDataAlloc(userData_s *userData, const u8 *data, u32 byteCnt)
{
bool_e status = OK;
ASSERT(userData != NULL);
ASSERT(data != NULL);
ASSERT(byteCnt > 0);
/* Free unused user data */
if (userData->header == YES) {
EncUserDataFree(userData);
}
if ((userData->data = (u8 *) hantro_malloc(byteCnt)) == NULL) {
userData->byteCnt = 0;
userData->header = NO;
status = NOK;
} else {
hantro_memcpy(userData->data, data, byteCnt);
userData->byteCnt = byteCnt;
userData->header = YES;
}
return status;
}
/*------------------------------------------------------------------------------
EncUserDataFree
Input userData Pointer to userData_s structure.
------------------------------------------------------------------------------*/
void EncUserDataFree(userData_s *userData)
{
ASSERT(userData != NULL);
hantro_free(userData->data);
userData->data = NULL;
userData->header = NO;
userData->byteCnt = 0;
return;
}
/*------------------------------------------------------------------------------
EncUserData
------------------------------------------------------------------------------*/
void EncUserData(stream_s *stream, userData_s *userData)
{
u8 *data;
u8 next;
u32 byteCnt;
u32 zeroCnt = 0;
u32 zeroIn = 0;
u32 i;
if (userData->header == NO) {
return;
}
byteCnt = userData->byteCnt;
data = userData->data;
/* start code */
EncPutBits(stream, START_CODE_PREFIX_VAL, START_CODE_PREFIX_NUM);
EncPutBits(stream, START_CODE_USER_DATA_VAL, START_CODE_USER_DATA_NUM);
COMMENT("User Data");
while (byteCnt > 0) {
next = data[0];
/* Incoming zeros */
i = 0;
while (((next>>i) & 0xFF) > 0) {
i++;
}
zeroIn = 8 - i;
/* Consecutive zeros shall not be a string of 23 or more zeros
* */
if (zeroCnt + zeroIn > 22) {
EncPutBits(stream, START_CODE_PREFIX_VAL,
START_CODE_PREFIX_NUM);
EncPutBits(stream, START_CODE_USER_DATA_VAL,
START_CODE_USER_DATA_NUM);
COMMENT("User Data -Break header-");
zeroCnt = 0;
zeroIn = 0;
} else {
if (zeroIn == 8) {
zeroCnt += 8;
} else {
i = 0;
while (((next<<i) & 0xFF) > 0) {
i++;
}
zeroCnt = 8 - i;
}
EncPutBits(stream, next, 8);
data++;
byteCnt--;
}
}
EncUserDataFree(userData);
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -