[jpegd]: handle special stream and eos in parser_prepare and format source code with mpp_astyle.sh in Linux Server.

git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@1102 6e48237b-75ef-9749-8fc9-41990f28c85a
This commit is contained in:
HuangTingjin
2016-07-27 02:57:06 +00:00
parent 16b22667c6
commit 448771db51
7 changed files with 4466 additions and 4418 deletions

View File

@@ -991,6 +991,72 @@ JpegDecRet jpegd_default_huffman_tables(JpegParserContext *ctx)
return MPP_OK;
}
MPP_RET jpegd_parser_split_frame(RK_U8 *src, RK_U32 src_size, RK_U8 *dst, RK_U32 *dst_size)
{
FUN_TEST("Enter");
MPP_RET ret = MPP_OK;
if (NULL == src || NULL == dst || src_size <= 0) {
JPEGD_ERROR_LOG("NULL pointer or wrong src_size(%d)", src_size);
return MPP_ERR_NULL_PTR;
}
RK_U8 *end;
RK_U8 *tmp;
RK_U32 str_size = (src_size + 255) & (~255);
end = dst + src_size;
if (src[6] == 0x41 && src[7] == 0x56 && src[8] == 0x49 && src[9] == 0x31) {
//distinguish 310 from 210 camera
RK_U32 i;
RK_U32 copy_len = 0;
tmp = src;
JPEGD_INFO_LOG("distinguish 310 from 210 camera");
for (i = 0; i < src_size - 4; i++) {
if (tmp[i] == 0xff) {
if (tmp[i + 1] == 0x00 && tmp[i + 2] == 0xff && ((tmp[i + 3] & 0xf0) == 0xd0))
i += 2;
}
*dst++ = tmp[i];
copy_len++;
}
for (; i < src_size; i++) {
*dst++ = tmp[i];
copy_len++;
}
if (copy_len < src_size)
memset(dst, 0, src_size - copy_len);
*dst_size = copy_len;
} else {
memcpy(dst, src, src_size);
memset(dst + src_size, 0, str_size - src_size);
*dst_size = src_size;
}
/* NOTE: hardware bug, need to remove tailing FF 00 before FF D9 end flag */
if (end[-1] == 0xD9 && end[-2] == 0xFF) {
end -= 2;
do {
if (end[-1] == 0xFF) {
end--;
continue;
}
if (end[-1] == 0x00 && end [-2] == 0xFF) {
end -= 2;
continue;
}
break;
} while (1);
JPEGD_INFO_LOG("remove tailing FF 00 before FF D9 end flag.");
end[0] = 0xff;
end[1] = 0xD9;
}
FUN_TEST("Exit");
return ret;
}
MPP_RET jpegd_prepare(void *ctx, MppPacket pkt, HalDecTask *task)
{
FUN_TEST("Enter");
@@ -998,21 +1064,34 @@ MPP_RET jpegd_prepare(void *ctx, MppPacket pkt, HalDecTask *task)
JpegParserContext *JpegParserCtx = (JpegParserContext *)ctx;
MppPacket input_packet = JpegParserCtx->input_packet;
RK_U32 pkt_length = 0;
RK_U32 copy_length = 0;
void *pPacket = NULL;
void *pPos = NULL;
task->valid = 0;
JpegParserCtx->pts = mpp_packet_get_pts(pkt);
JpegParserCtx->eos = mpp_packet_get_eos(pkt);
pkt_length = mpp_packet_get_length(pkt);
pPacket = pPos = mpp_packet_get_pos(pkt);
memcpy(JpegParserCtx->recv_buffer, pPacket, pkt_length);
if (JpegParserCtx->eos) {
JPEGD_INFO_LOG("it is end of stream.");
task->flags.eos = 1;
return ret;
}
jpegd_parser_split_frame(pPacket, pkt_length, JpegParserCtx->recv_buffer, &copy_length);
pPos += pkt_length;
mpp_packet_set_pos(pkt, pPos);
if (copy_length != pkt_length) {
JPEGD_INFO_LOG("there seems to be something wrong with split_frame. pkt_length:%d, copy_length:%d", pkt_length, copy_length);
}
/* debug information */
if(JpegParserCtx->parser_debug_enable && JpegParserCtx->input_jpeg_count < 3)
{
if (JpegParserCtx->parser_debug_enable && JpegParserCtx->input_jpeg_count < 3) {
static FILE *jpg_file;
static char name[32];
@@ -1072,16 +1151,14 @@ MPP_RET jpegd_read_decode_parameters(JpegParserContext *ctx, StreamStorage *pStr
}
/* Read decoding parameters */
for (pStream->readBits = 0; (pStream->readBits / 8) < pStream->streamLength; pStream->readBits++)
{
for (pStream->readBits = 0; (pStream->readBits / 8) < pStream->streamLength; pStream->readBits++) {
/* Look for marker prefix byte from stream */
if ((currentByte == 0xFF) || jpegd_get_byte(pStream) == 0xFF) {
currentByte = jpegd_get_byte(pStream);
switch (currentByte) { /* switch to certain header decoding */
case SOF0: /* baseline marker */
case SOF2: /* progresive marker */
{
case SOF2: { /* progresive marker */
JPEGD_VERBOSE_LOG("SOF, currentByte:0x%x", currentByte);
if (currentByte == SOF0) {
pImageInfo->codingMode = pSyntax->info.operationType = JPEGDEC_BASELINE;
@@ -1228,8 +1305,7 @@ MPP_RET jpegd_read_decode_parameters(JpegParserContext *ctx, StreamStorage *pStr
pSyntax->info.yCbCrMode = pSyntax->info.getInfoYCbCrMode = pImageInfo->outputFormat;
break;
}
case SOS:
{
case SOS: {
JPEGD_VERBOSE_LOG("SOS, currentByte:0x%x", currentByte);
/* SOS length */
headerLength = jpegd_get_two_bytes(pStream);
@@ -1263,8 +1339,7 @@ MPP_RET jpegd_read_decode_parameters(JpegParserContext *ctx, StreamStorage *pStr
}
break;
}
case DQT:
{
case DQT: {
JPEGD_VERBOSE_LOG("DQT, currentByte:0x%x", currentByte);
/* DQT length */
headerLength = jpegd_get_two_bytes(pStream);
@@ -1283,8 +1358,7 @@ MPP_RET jpegd_read_decode_parameters(JpegParserContext *ctx, StreamStorage *pStr
}
break;
}
case DHT:
{
case DHT: {
JPEGD_VERBOSE_LOG("DHT, currentByte:0x%x", currentByte);
/* DHT length */
headerLength = jpegd_get_two_bytes(pStream);
@@ -1302,8 +1376,7 @@ MPP_RET jpegd_read_decode_parameters(JpegParserContext *ctx, StreamStorage *pStr
}
break;
}
case DRI:
{
case DRI: {
JPEGD_VERBOSE_LOG("DRI, currentByte:0x%x", currentByte);
/* DRI length */
headerLength = jpegd_get_two_bytes(pStream);
@@ -1332,8 +1405,7 @@ MPP_RET jpegd_read_decode_parameters(JpegParserContext *ctx, StreamStorage *pStr
pSyntax->frame.Ri = headerLength;
break;
}
case APP0: /* application segments */
{
case APP0: { /* application segments */
JPEGD_VERBOSE_LOG("APP0, currentByte:0x%x", currentByte);
/* reset */
appBits = 0;
@@ -1431,8 +1503,7 @@ MPP_RET jpegd_read_decode_parameters(JpegParserContext *ctx, StreamStorage *pStr
currentByte = jpegd_get_byte(pStream);
switch (currentByte) { /* switch to certain header decoding */
case SOF0: /* baseline marker */
case SOF2: /* progresive marker */
{
case SOF2: { /* progresive marker */
if (currentByte == SOF0)
pImageInfo->codingModeThumb = pSyntax->info.operationTypeThumb = JPEGDEC_BASELINE;
else
@@ -1551,8 +1622,7 @@ MPP_RET jpegd_read_decode_parameters(JpegParserContext *ctx, StreamStorage *pStr
initThumb = 1;
break;
}
case SOS:
{
case SOS: {
/* SOS length */
headerLength = jpegd_get_two_bytes(pStream);
if (headerLength == STRM_ERROR ||
@@ -1584,8 +1654,7 @@ MPP_RET jpegd_read_decode_parameters(JpegParserContext *ctx, StreamStorage *pStr
}
break;
}
case DQT:
{
case DQT: {
/* DQT length */
headerLength = jpegd_get_two_bytes(pStream);
if (headerLength == STRM_ERROR) {
@@ -1600,8 +1669,7 @@ MPP_RET jpegd_read_decode_parameters(JpegParserContext *ctx, StreamStorage *pStr
appBits += (headerLength * 8);
break;
}
case DHT:
{
case DHT: {
/* DHT length */
headerLength = jpegd_get_two_bytes(pStream);
if (headerLength == STRM_ERROR) {
@@ -1616,8 +1684,7 @@ MPP_RET jpegd_read_decode_parameters(JpegParserContext *ctx, StreamStorage *pStr
appBits += (headerLength * 8);
break;
}
case DRI:
{
case DRI: {
/* DRI length */
headerLength = jpegd_get_two_bytes(pStream);
if (headerLength == STRM_ERROR) {
@@ -1647,8 +1714,7 @@ MPP_RET jpegd_read_decode_parameters(JpegParserContext *ctx, StreamStorage *pStr
case APP12:
case APP13:
case APP14:
case APP15:
{
case APP15: {
/* APPn length */
headerLength = jpegd_get_two_bytes(pStream);
if (headerLength == STRM_ERROR) {
@@ -1663,8 +1729,7 @@ MPP_RET jpegd_read_decode_parameters(JpegParserContext *ctx, StreamStorage *pStr
appBits += (headerLength * 8);
break;
}
case DNL:
{
case DNL: {
/* DNL length */
headerLength = jpegd_get_two_bytes(pStream);
if (headerLength == STRM_ERROR) {
@@ -1679,8 +1744,7 @@ MPP_RET jpegd_read_decode_parameters(JpegParserContext *ctx, StreamStorage *pStr
appBits += (headerLength * 8);
break;
}
case COM:
{
case COM: {
/* COM length */
headerLength = jpegd_get_two_bytes(pStream);
if (headerLength == STRM_ERROR) {
@@ -1707,8 +1771,7 @@ MPP_RET jpegd_read_decode_parameters(JpegParserContext *ctx, StreamStorage *pStr
case SOF14:
case SOF15:
case DAC:
case DHP:
{
case DHP: {
JPEGD_ERROR_LOG("Unsupported coding styles");
return (JPEGDEC_UNSUPPORTED);
}
@@ -1793,8 +1856,7 @@ MPP_RET jpegd_read_decode_parameters(JpegParserContext *ctx, StreamStorage *pStr
case APP12:
case APP13:
case APP14:
case APP15:
{
case APP15: {
JPEGD_VERBOSE_LOG("APPn, currentByte:0x%x", currentByte);
/* APPn length */
headerLength = jpegd_get_two_bytes(pStream);
@@ -1812,8 +1874,7 @@ MPP_RET jpegd_read_decode_parameters(JpegParserContext *ctx, StreamStorage *pStr
}
break;
}
case DNL:
{
case DNL: {
JPEGD_VERBOSE_LOG("DNL, currentByte:0x%x", currentByte);
/* DNL length */
headerLength = jpegd_get_two_bytes(pStream);
@@ -1831,8 +1892,7 @@ MPP_RET jpegd_read_decode_parameters(JpegParserContext *ctx, StreamStorage *pStr
}
break;
}
case COM:
{
case COM: {
JPEGD_VERBOSE_LOG("COM, currentByte:0x%x", currentByte);
headerLength = jpegd_get_two_bytes(pStream);
JPEGD_VERBOSE_LOG("COM, headerLength:%x", headerLength);
@@ -1861,8 +1921,7 @@ MPP_RET jpegd_read_decode_parameters(JpegParserContext *ctx, StreamStorage *pStr
case SOF14:
case SOF15:
case DAC:
case DHP:
{
case DHP: {
JPEGD_ERROR_LOG("SOF, currentByte:0x%x", currentByte);
JPEGD_ERROR_LOG("Unsupported coding styles");
return (JPEGDEC_UNSUPPORTED);
@@ -2069,14 +2128,12 @@ MPP_RET jpegd_decode_frame_impl(JpegParserContext *ctx)
/* switch to certain header decoding */
switch (currentByte) {
case 0x00:
{
case 0x00: {
JPEGD_VERBOSE_LOG("currentByte:0x00");
break;
}
case SOF0:
case SOF2:
{
case SOF2: {
JPEGD_VERBOSE_LOG("SOF, currentByte:0x%x", currentByte);
/* Baseline/Progressive */
pSyntax->frame.codingType = currentByte;
@@ -2098,8 +2155,7 @@ MPP_RET jpegd_decode_frame_impl(JpegParserContext *ctx)
}
break;
}
case SOS: /* Start of Scan */
{
case SOS: { /* Start of Scan */
JPEGD_VERBOSE_LOG("SOS, currentByte:0x%x", currentByte);
/* reset image ready */
pSyntax->image.imageReady = 0;
@@ -2141,8 +2197,7 @@ MPP_RET jpegd_decode_frame_impl(JpegParserContext *ctx)
}
break;
}
case DHT: /* Start of Huffman tables */
{
case DHT: { /* Start of Huffman tables */
JPEGD_VERBOSE_LOG("DHT, currentByte:0x%x", currentByte);
retCode = jpegd_decode_huffman_tables(pCtx);
if (retCode != JPEGDEC_OK) {
@@ -2157,8 +2212,7 @@ MPP_RET jpegd_decode_frame_impl(JpegParserContext *ctx)
findhufftable = 1;
break;
}
case DQT: /* start of Quantisation Tables */
{
case DQT: { /* start of Quantisation Tables */
JPEGD_VERBOSE_LOG("DQT, currentByte:0x%x", currentByte);
retCode = jpegd_decode_quant_tables(pCtx);
if (retCode != JPEGDEC_OK) {
@@ -2172,13 +2226,11 @@ MPP_RET jpegd_decode_frame_impl(JpegParserContext *ctx)
}
break;
}
case SOI: /* Start of Image */
{
case SOI: { /* Start of Image */
/* no actions needed, continue */
break;
}
case EOI: /* End of Image */
{
case EOI: { /* End of Image */
JPEGD_VERBOSE_LOG("EOI, currentByte:0x%x", currentByte);
if (pSyntax->image.imageReady) {
JPEGD_ERROR_LOG("EOI: OK\n");
@@ -2188,8 +2240,7 @@ MPP_RET jpegd_decode_frame_impl(JpegParserContext *ctx)
return (JPEGDEC_ERROR);
}
}
case DRI: /* Define Restart Interval */
{
case DRI: { /* Define Restart Interval */
JPEGD_VERBOSE_LOG("DRI, currentByte:0x%x", currentByte);
currentBytes = jpegd_get_two_bytes(pStream);
if (currentBytes == STRM_ERROR) {
@@ -2207,8 +2258,7 @@ MPP_RET jpegd_decode_frame_impl(JpegParserContext *ctx)
case RST4:
case RST5:
case RST6:
case RST7:
{
case RST7: {
JPEGD_VERBOSE_LOG("RST, currentByte:0x%x", currentByte);
/* initialisation of DC predictors to zero value !!! */
for (i = 0; i < MAX_NUMBER_OF_COMPONENTS; i++) {
@@ -2230,13 +2280,11 @@ MPP_RET jpegd_decode_frame_impl(JpegParserContext *ctx)
case SOF15:
case DAC:
case DHP:
case TEM:
{
case TEM: {
JPEGD_ERROR_LOG("Unsupported Features, currentByte:0x%x", currentByte);
return (JPEGDEC_UNSUPPORTED);
}
case APP0: /* application data & comments */
{
case APP0: { /* application data & comments */
JPEGD_VERBOSE_LOG("APP0, currentByte:0x%x", currentByte);
/* APP0 Extended Thumbnail */
if (pCtx->decImageType == JPEGDEC_THUMBNAIL) {
@@ -2324,8 +2372,7 @@ MPP_RET jpegd_decode_frame_impl(JpegParserContext *ctx)
case APP13:
case APP14:
case APP15:
case COM:
{
case COM: {
JPEGD_VERBOSE_LOG("APPn, currentByte:0x%x", currentByte);
currentBytes = jpegd_get_two_bytes(pStream);
if (currentBytes == STRM_ERROR) {
@@ -2614,6 +2661,7 @@ MPP_RET jpegd_deinit(void *ctx)
}
JpegParserCtx->pts = 0;
JpegParserCtx->eos = 0;
JpegParserCtx->parser_debug_enable = 0;
JpegParserCtx->input_jpeg_count = 0;
@@ -2708,7 +2756,8 @@ MPP_RET jpegd_init(void *ctx, ParserCfg *parser_cfg)
JpegParserCtx->extensionsSupported = 1;
JpegParserCtx->pts = 0;
JpegParserCtx->parser_debug_enable = 1;
JpegParserCtx->eos = 0;
JpegParserCtx->parser_debug_enable = 0;
JpegParserCtx->input_jpeg_count = 0;
FUN_TEST("Exit");

View File

@@ -195,7 +195,7 @@ typedef struct JpegParserContext {
RK_U32 extensionsSupported;
RK_S64 pts;
RK_U32 eos;
RK_U32 parser_debug_enable;
RK_U32 input_jpeg_count;
} JpegParserContext;

View File

@@ -1873,7 +1873,7 @@ MPP_RET hal_jpegd_init(void *hal, MppHalCfg *cfg)
}
//init dbg stuff
JpegHalCtx->hal_debug_enable = 1;
JpegHalCtx->hal_debug_enable = 0;
JpegHalCtx->frame_count = 0;
JpegHalCtx->output_yuv_count = 0;
@@ -2024,8 +2024,7 @@ MPP_RET hal_jpegd_wait(void *hal, HalTaskInfo *task)
}
/* debug information */
if(JpegHalCtx->hal_debug_enable && JpegHalCtx->output_yuv_count < 3)
{
if (JpegHalCtx->hal_debug_enable && JpegHalCtx->output_yuv_count < 3) {
static FILE *jpg_file;
static char name[32];
MppBuffer outputBuf = NULL;