From 592abf7851424f49277499dd9beb8ec129da5011 Mon Sep 17 00:00:00 2001 From: HuangTingjin Date: Wed, 10 Aug 2016 06:37:14 +0000 Subject: [PATCH] [jpegd]: move set_output_format function from jpegd_parser.c to hal_jpegd_reg.c. git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@1184 6e48237b-75ef-9749-8fc9-41990f28c85a --- mpp/codec/dec/jpeg/jpegd_parser.c | 133 ++++-------------------------- mpp/codec/dec/jpeg/jpegd_parser.h | 1 - mpp/hal/vpu/jpegd/hal_jpegd_reg.c | 96 ++++++++++++++++++++- 3 files changed, 111 insertions(+), 119 deletions(-) diff --git a/mpp/codec/dec/jpeg/jpegd_parser.c b/mpp/codec/dec/jpeg/jpegd_parser.c index 4e7d981e..6e0950c4 100644 --- a/mpp/codec/dec/jpeg/jpegd_parser.c +++ b/mpp/codec/dec/jpeg/jpegd_parser.c @@ -812,12 +812,12 @@ JpegDecRet jpegd_decode_huffman_tables(JpegParserContext *ctx) while (len < pSyntax->vlc.Lh) { tmp = jpegd_get_byte(pStream); len++; - Tc = tmp >> 4; /* Table class */ + Tc = tmp >> 4; /* Table class: DC or AC */ if (Tc != 0 && Tc != 1) { JPEGD_ERROR_LOG("Tc(%d) is unsupported", Tc); return (JPEGDEC_UNSUPPORTED); } - Th = tmp & 0xF; /* Huffman table identifier */ + Th = tmp & 0xF; /* Huffman table identifier: 0 or 1 .(Baseline)*/ /* only two tables in baseline allowed */ if ((pSyntax->frame.codingType == SOF0) && (Th > 1)) { JPEGD_ERROR_LOG("Th(%d) is unsupported", Th); @@ -831,7 +831,7 @@ JpegDecRet jpegd_decode_huffman_tables(JpegParserContext *ctx) /* set the table pointer */ if (Tc) { - /* Ac table */ + /* AC table */ switch (Th) { case 0: JPEGD_VERBOSE_LOG("ac0\n"); @@ -854,7 +854,7 @@ JpegDecRet jpegd_decode_huffman_tables(JpegParserContext *ctx) return (JPEGDEC_UNSUPPORTED); } } else { - /* Dc table */ + /* DC table */ switch (Th) { case 0: JPEGD_VERBOSE_LOG("dc0\n"); @@ -1267,7 +1267,7 @@ MPP_RET jpegd_read_decode_parameters(JpegParserContext *ctx, StreamStorage *pStr } JpegParserContext *pCtx = ctx; - JpegDecImageInfo *pImageInfo = (JpegDecImageInfo *) & (pCtx->imageInfo); + JpegDecImageInfo *pImageInfo = (JpegDecImageInfo *) & (pCtx->pSyntax->imageInfo); JpegSyntaxParam *pSyntax = pCtx->pSyntax; RK_U32 Nf = 0, Ns = 0, NsThumb = 0; RK_U32 i, j = 0, init = 0, initThumb = 0; @@ -1447,7 +1447,7 @@ MPP_RET jpegd_read_decode_parameters(JpegParserContext *ctx, StreamStorage *pStr JPEGD_VERBOSE_LOG("SOS, currentByte:0x%x", currentByte); /* SOS length */ headerLength = jpegd_get_two_bytes(pStream); - JPEGD_VERBOSE_LOG("SOS, headerLength:%d", headerLength); + JPEGD_VERBOSE_LOG("Length of is %d", headerLength); if (headerLength == STRM_ERROR || ((pStream->readBits + ((headerLength * 8) - 16)) > (8 * pStream->streamLength))) { JPEGD_ERROR_LOG("readBits:%d, headerLength:%d, streamLength:%d", pStream->readBits, headerLength, pStream->streamLength); @@ -1481,7 +1481,7 @@ MPP_RET jpegd_read_decode_parameters(JpegParserContext *ctx, StreamStorage *pStr JPEGD_VERBOSE_LOG("DQT, currentByte:0x%x", currentByte); /* DQT length */ headerLength = jpegd_get_two_bytes(pStream); - JPEGD_VERBOSE_LOG("headerLength:%d", headerLength); + JPEGD_VERBOSE_LOG("Length of Define Quantization Table is %d", headerLength); if (headerLength == STRM_ERROR || ((pStream->readBits + ((headerLength * 8) - 16)) > (8 * pStream->streamLength))) { JPEGD_ERROR_LOG("readBits:%d, headerLength:%d, streamLength:%d", pStream->readBits, headerLength, pStream->streamLength); @@ -1500,7 +1500,7 @@ MPP_RET jpegd_read_decode_parameters(JpegParserContext *ctx, StreamStorage *pStr JPEGD_VERBOSE_LOG("DHT, currentByte:0x%x", currentByte); /* DHT length */ headerLength = jpegd_get_two_bytes(pStream); - JPEGD_VERBOSE_LOG("headerLength:%d", headerLength); + JPEGD_VERBOSE_LOG("Length of Define Huffman Table is %d", headerLength); if (headerLength == STRM_ERROR || ((pStream->readBits + ((headerLength * 8) - 16)) > (8 * pStream->streamLength))) { JPEGD_ERROR_LOG("readBits:%d, headerLength:%d, streamLength:%d", pStream->readBits, headerLength, pStream->streamLength); @@ -1518,24 +1518,19 @@ MPP_RET jpegd_read_decode_parameters(JpegParserContext *ctx, StreamStorage *pStr JPEGD_VERBOSE_LOG("DRI, currentByte:0x%x", currentByte); /* DRI length */ headerLength = jpegd_get_two_bytes(pStream); - JPEGD_VERBOSE_LOG("headerLength:%d", headerLength); + JPEGD_VERBOSE_LOG("Length of Define Restart Interval(must be 4 Bytes) is %d", headerLength); if (headerLength == STRM_ERROR || ((pStream->readBits + ((headerLength * 8) - 16)) > (8 * pStream->streamLength))) { JPEGD_ERROR_LOG("readBits:%d, headerLength:%d, streamLength:%d", pStream->readBits, headerLength, pStream->streamLength); errorCode = 1; break; } -#if 0 - /* jump over DRI header */ - if (headerLength != 0) { - pStream->readBits += ((headerLength * 8) - 16); - pStream->pCurrPos += (((headerLength * 8) - 16) / 8); - } -#endif + headerLength = jpegd_get_two_bytes(pStream); - JPEGD_VERBOSE_LOG("headerLength:%d", headerLength); + JPEGD_VERBOSE_LOG("Restart Interval:%d", headerLength); if (headerLength == STRM_ERROR || ((pStream->readBits + ((headerLength * 8) - 16)) > (8 * pStream->streamLength))) { + /* may optimize one day */ JPEGD_ERROR_LOG("readBits:%d, headerLength:%d, streamLength:%d", pStream->readBits, headerLength, pStream->streamLength); errorCode = 1; break; @@ -2096,18 +2091,14 @@ MPP_RET jpegd_get_image_info(JpegParserContext *ctx) { FUN_TEST("Enter"); JpegParserContext *pCtx = ctx; - MPP_RET ret = MPP_OK; - PostProcessInfo ppInfo; - RK_U32 ppInputFomart = 0; - RK_U32 ppScaleW = 640, ppScaleH = 480; - RK_U32 pic_size = 0; - StreamStorage stream; - if (NULL == pCtx) { JPEGD_ERROR_LOG("NULL pointer"); return MPP_ERR_NULL_PTR; } + + MPP_RET ret = MPP_OK; JpegSyntaxParam *pSyntax = pCtx->pSyntax; + StreamStorage stream; if (pCtx->streamLength < 1) { JPEGD_ERROR_LOG("streamLength:%d", pCtx->streamLength); @@ -2126,8 +2117,7 @@ MPP_RET jpegd_get_image_info(JpegParserContext *ctx) return MPP_ERR_VALUE; } - memset(&(pCtx->imageInfo), 0, sizeof(JpegDecImageInfo)); - pCtx->imageInfo.thumbnailType = JPEGDEC_NO_THUMBNAIL; + pSyntax->imageInfo.thumbnailType = JPEGDEC_NO_THUMBNAIL; /* utils initialization */ stream.bitPosInByte = 0; @@ -2143,94 +2133,6 @@ MPP_RET jpegd_get_image_info(JpegParserContext *ctx) return ret; } - if (pCtx->color_conv) { - /* Using pp to convert all format to yuv420sp */ - switch (pCtx->imageInfo.outputFormat) { - case JPEGDEC_YCbCr400: - ppInputFomart = PP_IN_FORMAT_YUV400; - break; - case JPEGDEC_YCbCr420_SEMIPLANAR: - ppInputFomart = PP_IN_FORMAT_YUV420SEMI; - break; - case JPEGDEC_YCbCr422_SEMIPLANAR: - ppInputFomart = PP_IN_FORMAT_YUV422SEMI; - break; - case JPEGDEC_YCbCr440: - ppInputFomart = PP_IN_FORMAT_YUV440SEMI; - break; - case JPEGDEC_YCbCr411_SEMIPLANAR: - ppInputFomart = PP_IN_FORMAT_YUV411_SEMI; - break; - case JPEGDEC_YCbCr444_SEMIPLANAR: - ppInputFomart = PP_IN_FORMAT_YUV444_SEMI; - break; - } - - // set pp info - memset(&ppInfo, 0, sizeof(ppInfo)); - ppInfo.enable = 1; - ppInfo.outFomart = 5; //PP_OUT_FORMAT_YUV420INTERLAVE - ppScaleW = pCtx->imageInfo.outputWidth; - ppScaleH = pCtx->imageInfo.outputHeight; - if (ppScaleW > 1920) { // || ppScaleH > 1920) { - ppScaleW = (ppScaleW + 15) & (~15); //(ppScaleW + 15)/16*16; - ppScaleH = (ppScaleH + 15) & (~15); - } else { - ppScaleW = (ppScaleW + 7) & (~7); // pp dest width must be dividable by 8 - ppScaleH = (ppScaleH + 1) & (~1); // must be dividable by 2.in pp downscaling ,the output lines always equal (desire lines - 1); - } - - JPEGD_INFO_LOG("Post Process! ppScaleW:%d, ppScaleH:%d", ppScaleW, ppScaleH); - - pic_size = ppScaleW * ppScaleH * 2; - pSyntax->ppInstance = (void *)1; - } else { - /* keep original output format */ - memset(&ppInfo, 0, sizeof(ppInfo)); - ppInfo.outFomart = 5; //PP_OUT_FORMAT_YUV420INTERLAVE - ppScaleW = pCtx->imageInfo.outputWidth; - ppScaleH = pCtx->imageInfo.outputHeight; - - ppScaleW = (ppScaleW + 15) & (~15); - ppScaleH = (ppScaleH + 15) & (~15); - - switch (pCtx->imageInfo.outputFormat) { - case JPEGDEC_YCbCr400: - ppInputFomart = PP_IN_FORMAT_YUV400; - pic_size = ppScaleW * ppScaleH; - break; - case JPEGDEC_YCbCr420_SEMIPLANAR: - ppInputFomart = PP_IN_FORMAT_YUV420SEMI; - pic_size = ppScaleW * ppScaleH * 3 / 2; - break; - case JPEGDEC_YCbCr422_SEMIPLANAR: - ppInputFomart = PP_IN_FORMAT_YUV422SEMI; - pic_size = ppScaleW * ppScaleH * 2; - break; - case JPEGDEC_YCbCr440: - ppInputFomart = PP_IN_FORMAT_YUV440SEMI; - pic_size = ppScaleW * ppScaleH * 2; - break; - case JPEGDEC_YCbCr411_SEMIPLANAR: - ppInputFomart = PP_IN_FORMAT_YUV411_SEMI; - pic_size = ppScaleW * ppScaleH * 2; - break; - case JPEGDEC_YCbCr444_SEMIPLANAR: - ppInputFomart = PP_IN_FORMAT_YUV444_SEMI; - pic_size = ppScaleW * ppScaleH * 3; - break; - } - - pSyntax->ppInstance = (void *)0; - } - - (void)pic_size; - memcpy(&(pSyntax->imageInfo), &(pCtx->imageInfo), sizeof(JpegDecImageInfo)); - memcpy(&(pSyntax->ppInfo), &(ppInfo), sizeof(PostProcessInfo)); - pSyntax->ppScaleW = ppScaleW; - pSyntax->ppScaleH = ppScaleH; - pSyntax->ppInputFomart = ppInputFomart; - FUN_TEST("Exit"); return ret; } @@ -2856,7 +2758,6 @@ MPP_RET jpegd_init(void *ctx, ParserCfg *parser_cfg) memset(JpegParserCtx->pSyntax, 0, sizeof(JpegSyntaxParam)); JpegParserCtx->pSyntax->ppInstance = (void *)0; /* will be changed when need pp */ - memset(&(JpegParserCtx->imageInfo), 0, sizeof(JpegDecImageInfo)); JpegParserCtx->decImageType = JPEGDEC_IMAGE; /* FULL MODEs */ JpegParserCtx->sliceMbSet = 0; /* will be changed when over 16MB*/ JpegParserCtx->color_conv = 0; @@ -2906,7 +2807,6 @@ MPP_RET jpegd_reset(void *ctx) MPP_RET jpegd_control(void *ctx, RK_S32 cmd, void *param) { FUN_TEST("Enter"); - MPP_RET ret = MPP_OK; JpegParserContext *JpegParserCtx = (JpegParserContext *)ctx; if (NULL == JpegParserCtx) { @@ -2922,7 +2822,6 @@ MPP_RET jpegd_control(void *ctx, RK_S32 cmd, void *param) default : ret = MPP_NOK; } - FUN_TEST("Exit"); return ret; } diff --git a/mpp/codec/dec/jpeg/jpegd_parser.h b/mpp/codec/dec/jpeg/jpegd_parser.h index 4048c8a2..e625a972 100644 --- a/mpp/codec/dec/jpeg/jpegd_parser.h +++ b/mpp/codec/dec/jpeg/jpegd_parser.h @@ -165,7 +165,6 @@ typedef struct JpegParserContext { RK_S32 frame_slot_index; /* slot index for output */ RK_U8 *recv_buffer; JpegSyntaxParam *pSyntax; - JpegDecImageInfo imageInfo; RK_U32 streamLength; /* input stream length or buffer size */ RK_U32 bufferSize; /* input stream buffer size */ diff --git a/mpp/hal/vpu/jpegd/hal_jpegd_reg.c b/mpp/hal/vpu/jpegd/hal_jpegd_reg.c index e5b012fa..7a2ed56a 100644 --- a/mpp/hal/vpu/jpegd/hal_jpegd_reg.c +++ b/mpp/hal/vpu/jpegd/hal_jpegd_reg.c @@ -347,6 +347,99 @@ static void jpegd_select_chroma_table(JpegSyntaxParam *pSyntax, JpegHalContext * return; } +MPP_RET jpegd_set_output_format(JpegSyntaxParam *pSyntax) +{ + FUN_TEST("Enter"); + MPP_RET ret = MPP_OK; + if (NULL == pSyntax) { + JPEGD_ERROR_LOG("NULL pointer"); + return MPP_ERR_NULL_PTR; + } + PostProcessInfo ppInfo; + RK_U32 ppInputFomart = 0; + RK_U32 ppScaleW = 640, ppScaleH = 480; + + if (0/*pCtx->color_conv*/) { + /* Using pp to convert all format to yuv420sp */ + switch (pSyntax->imageInfo.outputFormat) { + case JPEGDEC_YCbCr400: + ppInputFomart = PP_IN_FORMAT_YUV400; + break; + case JPEGDEC_YCbCr420_SEMIPLANAR: + ppInputFomart = PP_IN_FORMAT_YUV420SEMI; + break; + case JPEGDEC_YCbCr422_SEMIPLANAR: + ppInputFomart = PP_IN_FORMAT_YUV422SEMI; + break; + case JPEGDEC_YCbCr440: + ppInputFomart = PP_IN_FORMAT_YUV440SEMI; + break; + case JPEGDEC_YCbCr411_SEMIPLANAR: + ppInputFomart = PP_IN_FORMAT_YUV411_SEMI; + break; + case JPEGDEC_YCbCr444_SEMIPLANAR: + ppInputFomart = PP_IN_FORMAT_YUV444_SEMI; + break; + } + + // set pp info + memset(&ppInfo, 0, sizeof(ppInfo)); + ppInfo.enable = 1; + ppInfo.outFomart = 5; //PP_OUT_FORMAT_YUV420INTERLAVE + ppScaleW = pSyntax->imageInfo.outputWidth; + ppScaleH = pSyntax->imageInfo.outputHeight; + if (ppScaleW > 1920) { // || ppScaleH > 1920) { + ppScaleW = (ppScaleW + 15) & (~15); //(ppScaleW + 15)/16*16; + ppScaleH = (ppScaleH + 15) & (~15); + } else { + ppScaleW = (ppScaleW + 7) & (~7); // pp dest width must be dividable by 8 + ppScaleH = (ppScaleH + 1) & (~1); // must be dividable by 2.in pp downscaling ,the output lines always equal (desire lines - 1); + } + + JPEGD_INFO_LOG("Post Process! ppScaleW:%d, ppScaleH:%d", ppScaleW, ppScaleH); + pSyntax->ppInstance = (void *)1; + } else { + /* keep original output format */ + memset(&ppInfo, 0, sizeof(ppInfo)); + ppInfo.outFomart = 5; //PP_OUT_FORMAT_YUV420INTERLAVE + ppScaleW = pSyntax->imageInfo.outputWidth; + ppScaleH = pSyntax->imageInfo.outputHeight; + + ppScaleW = (ppScaleW + 15) & (~15); + ppScaleH = (ppScaleH + 15) & (~15); + + switch (pSyntax->imageInfo.outputFormat) { + case JPEGDEC_YCbCr400: + ppInputFomart = PP_IN_FORMAT_YUV400; + break; + case JPEGDEC_YCbCr420_SEMIPLANAR: + ppInputFomart = PP_IN_FORMAT_YUV420SEMI; + break; + case JPEGDEC_YCbCr422_SEMIPLANAR: + ppInputFomart = PP_IN_FORMAT_YUV422SEMI; + break; + case JPEGDEC_YCbCr440: + ppInputFomart = PP_IN_FORMAT_YUV440SEMI; + break; + case JPEGDEC_YCbCr411_SEMIPLANAR: + ppInputFomart = PP_IN_FORMAT_YUV411_SEMI; + break; + case JPEGDEC_YCbCr444_SEMIPLANAR: + ppInputFomart = PP_IN_FORMAT_YUV444_SEMI; + break; + } + + pSyntax->ppInstance = (void *)0; + } + + memcpy(&(pSyntax->ppInfo), &(ppInfo), sizeof(PostProcessInfo)); + pSyntax->ppScaleW = ppScaleW; + pSyntax->ppScaleH = ppScaleH; + pSyntax->ppInputFomart = ppInputFomart; + + FUN_TEST("Exit"); + return ret; +} static void jpegd_write_tables(JpegSyntaxParam *pSyntax, JpegHalContext *pCtx) { @@ -1831,7 +1924,7 @@ MPP_RET hal_jpegd_init(void *hal, MppHalCfg *cfg) //get vpu socket #ifdef RKPLATFORM if (JpegHalCtx->vpu_socket <= 0) { - JpegHalCtx->vpu_socket = VPUClientInit(VPU_DEC_PP/*VPU_DEC*/); + JpegHalCtx->vpu_socket = VPUClientInit(/*VPU_DEC_PP*/VPU_DEC); if (JpegHalCtx->vpu_socket <= 0) { JPEGD_ERROR_LOG("get vpu_socket(%d) <= 0, failed. \n", JpegHalCtx->vpu_socket); return MPP_ERR_UNKNOW; @@ -1943,6 +2036,7 @@ MPP_RET hal_jpegd_gen_regs(void *hal, HalTaskInfo *syn) if (syn->dec.valid) { syn->dec.valid = 0; + jpegd_set_output_format(pSyntax); #ifdef RKPLATFORM mpp_buf_slot_get_prop(JpegHalCtx->packet_slots, syn->dec.input, SLOT_BUFFER, &streambuf);