[jpegd]: modify jpegd parser

scan the stream just for one time in jpegd parser and
remove redundant codes.

Change-Id: I72920b15fc4ed15cfa1de55d9ed249d50cceebb2
Signed-off-by: timkingh.huang <timkingh.huang@rock-chips.com>
This commit is contained in:
timkingh.huang 2017-03-28 09:18:27 +08:00
parent 353d839b61
commit 93aa8a0c8a
12 changed files with 3576 additions and 6370 deletions

View file

@ -150,9 +150,9 @@ typedef enum {
*mpp color format define
*/
typedef enum {
MPP_FMT_YUV420SP = MPP_FRAME_FMT_YUV, /* YYYY... UVUVUV... */
MPP_FMT_YUV420SP = MPP_FRAME_FMT_YUV, /* YYYY... UV... */
MPP_FMT_YUV420SP_10BIT,
MPP_FMT_YUV422SP, /* YYYY... UVUVUV... */
MPP_FMT_YUV422SP, /* YYYY... UVUV... */
MPP_FMT_YUV422SP_10BIT, ///< Not part of ABI
MPP_FMT_YUV420P, /* YYYY... UUUU... VVVV */
MPP_FMT_YUV420SP_VU, /* YYYY... VUVUVU... */
@ -160,6 +160,10 @@ typedef enum {
MPP_FMT_YUV422SP_VU, /* YYYY... VUVUVU... */
MPP_FMT_YUV422_YUYV, /* YUYVYUYV... */
MPP_FMT_YUV422_UYVY, /* UYVYUYVY... */
MPP_FMT_YUV400SP, /* YYYY... */
MPP_FMT_YUV440SP, /* YYYY... UVUV... */
MPP_FMT_YUV411SP, /* YYYY... UV... */
MPP_FMT_YUV444SP, /* YYYY... UVUVUVUV... */
MPP_FMT_YUV_BUTT,
MPP_FMT_RGB565 = MPP_FRAME_FMT_RGB, /* 16-bit RGB */
MPP_FMT_BGR565, /* 16-bit RGB */

File diff suppressed because it is too large Load diff

View file

@ -27,150 +27,131 @@
#include "mpp_dec.h"
#include "mpp_buf_slot.h"
#include "mpp_packet.h"
#include "mpp_bitread.h"
#include "jpegd_syntax.h"
/* Max amount of stream: 16777216 = 16*1024*1024 = 4K*4K */
#define DEC_MAX_STREAM ((1<<24)-1)
#define JPEGDEC_MIN_BUFFER (256)
#define JPEGDEC_MAX_BUFFER (16776960)
#define JPEGDEC_MIN_WIDTH (48)
#define JPEGDEC_MIN_HEIGHT (48)
#define JPEGDEC_MAX_PIXEL_AMOUNT (16370688)
#define JPEGDEC_MAX_WIDTH_8190 (8176)
#define JPEGDEC_MAX_HEIGHT_8190 (8176)
#define JPEGDEC_MAX_PIXEL_AMOUNT_8190 (66846976)
#define JPEGDEC_MAX_SLICE_SIZE_8190 (8100)
#define JPEGDEC_MAX_WIDTH_TN (256)
#define JPEGDEC_MAX_HEIGHT_TN (256)
#define JPEG_IDENTIFIER(a, b, c, d) \
((RK_U32)(d) | ((RK_U32)(c) << 8) | \
((RK_U32)(b) << 16) | ((RK_U32)(a) << 24))
#define PP_IN_FORMAT_YUV422INTERLAVE (0)
#define PP_IN_FORMAT_YUV420SEMI (1)
#define PP_IN_FORMAT_YUV420PLANAR (2)
#define PP_IN_FORMAT_YUV400 (3)
#define PP_IN_FORMAT_YUV422SEMI (4)
#define PP_IN_FORMAT_YUV420SEMITIELED (5)
#define PP_IN_FORMAT_YUV440SEMI (6)
#define PP_IN_FORMAT_YUV444_SEMI (7)
#define PP_IN_FORMAT_YUV411_SEMI (8)
#define PP_OUT_FORMAT_RGB565 (0)
#define PP_OUT_FORMAT_ARGB (1)
#define PP_OUT_FORMAT_YUV422INTERLAVE (3)
#define PP_OUT_FORMAT_YUV420INTERLAVE (5)
/* JPEG marker codes */
enum JpegMarker {
/* start of frame */
SOF0 = 0xc0, /* baseline */
SOF1 = 0xc1, /* extended sequential, huffman */
SOF2 = 0xc2, /* progressive, huffman */
SOF3 = 0xc3, /* lossless, huffman */
enum {
JPEGDEC_NO_UNITS = 0, /* No units, X and Y specify
* the pixel aspect ratio */
JPEGDEC_DOTS_PER_INCH = 1, /* X and Y are dots per inch */
JPEGDEC_DOTS_PER_CM = 2 /* X and Y are dots per cm */
SOF5 = 0xc5, /* differential sequential, huffman */
SOF6 = 0xc6, /* differential progressive, huffman */
SOF7 = 0xc7, /* differential lossless, huffman */
JPG = 0xc8, /* reserved for JPEG extension */
SOF9 = 0xc9, /* extended sequential, arithmetic */
SOF10 = 0xca, /* progressive, arithmetic */
SOF11 = 0xcb, /* lossless, arithmetic */
SOF13 = 0xcd, /* differential sequential, arithmetic */
SOF14 = 0xce, /* differential progressive, arithmetic */
SOF15 = 0xcf, /* differential lossless, arithmetic */
DHT = 0xc4, /* define huffman tables */
DAC = 0xcc, /* define arithmetic-coding conditioning */
/* restart with modulo 8 count "m" */
RST0 = 0xd0,
RST1 = 0xd1,
RST2 = 0xd2,
RST3 = 0xd3,
RST4 = 0xd4,
RST5 = 0xd5,
RST6 = 0xd6,
RST7 = 0xd7,
SOI = 0xd8, /* start of image */
EOI = 0xd9, /* end of image */
SOS = 0xda, /* start of scan */
DQT = 0xdb, /* define quantization tables */
DNL = 0xdc, /* define number of lines */
DRI = 0xdd, /* define restart interval */
DHP = 0xde, /* define hierarchical progression */
EXP = 0xdf, /* expand reference components */
APP0 = 0xe0,
APP1 = 0xe1,
APP2 = 0xe2,
APP3 = 0xe3,
APP4 = 0xe4,
APP5 = 0xe5,
APP6 = 0xe6,
APP7 = 0xe7,
APP8 = 0xe8,
APP9 = 0xe9,
APP10 = 0xea,
APP11 = 0xeb,
APP12 = 0xec,
APP13 = 0xed,
APP14 = 0xee,
APP15 = 0xef,
JPG0 = 0xf0,
JPG1 = 0xf1,
JPG2 = 0xf2,
JPG3 = 0xf3,
JPG4 = 0xf4,
JPG5 = 0xf5,
JPG6 = 0xf6,
SOF48 = 0xf7, ///< JPEG-LS
LSE = 0xf8, ///< JPEG-LS extension parameters
JPG9 = 0xf9,
JPG10 = 0xfa,
JPG11 = 0xfb,
JPG12 = 0xfc,
JPG13 = 0xfd,
COM = 0xfe, /* comment */
TEM = 0x01, /* temporary private use for arithmetic coding */
/* 0x02 -> 0xbf reserved */
};
enum {
JPEGDEC_THUMBNAIL_JPEG = 0x10,
JPEGDEC_THUMBNAIL_NOT_SUPPORTED_FORMAT = 0x11,
JPEGDEC_NO_THUMBNAIL = 0x12
};
enum {
JPEGDEC_IMAGE = 0,
JPEGDEC_THUMBNAIL = 1
};
enum {
SOF0 = 0xC0,
SOF1 = 0xC1,
SOF2 = 0xC2,
SOF3 = 0xC3,
SOF5 = 0xC5,
SOF6 = 0xC6,
SOF7 = 0xC7,
SOF9 = 0xC8,
SOF10 = 0xCA,
SOF11 = 0xCB,
SOF13 = 0xCD,
SOF14 = 0xCE,
SOF15 = 0xCF,
JPG = 0xC8,
DHT = 0xC4,
DAC = 0xCC,
SOI = 0xD8,
EOI = 0xD9,
SOS = 0xDA,
DQT = 0xDB,
DNL = 0xDC,
DRI = 0xDD,
DHP = 0xDE,
EXP = 0xDF,
APP0 = 0xE0,
APP1 = 0xE1,
APP2 = 0xE2,
APP3 = 0xE3,
APP4 = 0xE4,
APP5 = 0xE5,
APP6 = 0xE6,
APP7 = 0xE7,
APP8 = 0xE8,
APP9 = 0xE9,
APP10 = 0xEA,
APP11 = 0xEB,
APP12 = 0xEC,
APP13 = 0xED,
APP14 = 0xEE,
APP15 = 0xEF,
JPG0 = 0xF0,
JPG1 = 0xF1,
JPG2 = 0xF2,
JPG3 = 0xF3,
JPG4 = 0xF4,
JPG5 = 0xF5,
JPG6 = 0xF6,
JPG7 = 0xF7,
JPG8 = 0xF8,
JPG9 = 0xF9,
JPG10 = 0xFA,
JPG11 = 0xFB,
JPG12 = 0xFC,
JPG13 = 0xFD,
COM = 0xFE,
TEM = 0x01,
RST0 = 0xD0,
RST1 = 0xD1,
RST2 = 0xD2,
RST3 = 0xD3,
RST4 = 0xD4,
RST5 = 0xD5,
RST6 = 0xD6,
RST7 = 0xD7
};
typedef struct JpegParserContext {
typedef struct JpegdCtx {
MppBufSlots packet_slots;
MppBufSlots frame_slots;
RK_S32 frame_slot_index; /* slot index for output */
RK_U8 *recv_buffer;
JpegSyntaxParam *pSyntax;
RK_U32 streamLength; /* input stream length or buffer size */
RK_U32 bufferSize; /* input stream buffer size */
RK_U32 decImageType; /* Full image or Thumbnail to be decoded */
/* slot index for output */
RK_S32 frame_slot_index;
RK_U8 *recv_buffer;
/* input stream length or buffer size */
RK_U32 streamLength;
/* input stream buffer size */
RK_U32 bufferSize;
MppFrameFormat output_fmt;
MppPacket input_packet;
MppFrame output_frame;
RK_U32 minSupportedWidth;
RK_U32 minSupportedHeight;
RK_U32 maxSupportedWidth;
RK_U32 maxSupportedHeight;
RK_U32 maxSupportedPixelAmount;
RK_U32 maxSupportedSliceSize;
RK_U32 extensionsSupported;
RK_S64 pts;
RK_U32 eos;
RK_U32 parser_debug_enable;
RK_U32 input_jpeg_count;
RK_S32 copy_flag; /* 0 - no need to copy stream; 1 - need to copy */
} JpegParserContext;
/* 0 - no need to copy stream; 1 - need to copy */
RK_S32 copy_flag;
RK_U8 *buffer;
RK_U32 buf_size;
/* current start code */
RK_S32 start_code;
/* bit read context */
BitReadCtx_t *bit_ctx;
JpegdSyntax *syntax;
} JpegdCtx;
#endif /* __JPEGD_PARSER_H__ */

View file

@ -24,69 +24,6 @@ extern "C" {
extern const ParserApi api_jpegd_parser;
extern RK_U32 jpegd_log;
#define JPEGD_VBE_LOG (0x01)
#define JPEGD_DBG_LOG (0x02)
#define JPEGD_INF_LOG (0x04)
#define JPEGD_ERR_LOG (0x08)
#define JPEGD_DBG_ASSERT (1)
#define FUN_TEST(tag) \
do {\
if (JPEGD_VBE_LOG & jpegd_log)\
{ mpp_log("[Verbose] %s: line(%d), func(%s)", tag, __LINE__, __FUNCTION__); }\
} while (0)
#define JPEGD_ASSERT(val)\
do {\
if (JPEGD_DBG_ASSERT)\
{ mpp_assert(val); }\
} while (0)
//check function return
#define CHECK_FUN(val) \
do{ \
if((val) < 0) { \
ret = (val); \
mpp_log("func return error(Line %d), ret:%d\n", __LINE__, ret); \
goto __FAILED; \
} \
} while (0)
//memory malloc check
#define CHECK_MEM(val, ...)\
do{ if(!(val)) {\
ret = MPP_ERR_MALLOC;\
mpp_log("malloc buffer error(Line %d), pointer:%p\n", __LINE__, val);\
goto __FAILED;\
} } while (0)
#define JPEGD_VERBOSE_LOG(fmt, ...) \
do {\
if (JPEGD_VBE_LOG & jpegd_log)\
{ mpp_log("[Verbose] func(%s), line(%d), "fmt"", __FUNCTION__, __LINE__, ##__VA_ARGS__); }\
} while (0)
#define JPEGD_DEBUG_LOG(fmt, ...) \
do {\
if (JPEGD_DBG_LOG & jpegd_log)\
{ mpp_log("[Debug] func(%s), line(%d), "fmt"", __FUNCTION__, __LINE__, ##__VA_ARGS__); }\
} while (0)
#define JPEGD_INFO_LOG(fmt, ...) \
do {\
if (JPEGD_INF_LOG & jpegd_log)\
{ mpp_log("[Info] func(%s), line(%d), "fmt"", __FUNCTION__, __LINE__, ##__VA_ARGS__); }\
} while (0)
#define JPEGD_ERROR_LOG(fmt, ...) \
do {\
if (JPEGD_ERR_LOG & jpegd_log)\
{ mpp_log("[Error] func(%s), line(%d), "fmt"", __FUNCTION__, __LINE__, ##__VA_ARGS__); }\
} while (0)
MPP_RET jpegd_prepare(void *ctx, MppPacket pkt, HalDecTask *task);
MPP_RET jpegd_init(void *ctx, ParserCfg *parser_cfg);

View file

@ -18,334 +18,171 @@
#ifndef __JPEGD_SYNTAX__
#define __JPEGD_SYNTAX__
#include "vpu_api.h"
#define JPEGDEC_YUV400 (0)
#define JPEGDEC_YUV420 (2)
#define JPEGDEC_YUV422 (3)
#define JPEGDEC_YUV444 (4)
#define JPEGDEC_YUV440 (5)
#define JPEGDEC_YUV411 (6)
#define MIN_NUMBER_OF_COMPONENTS (1)
#define MAX_NUMBER_OF_COMPONENTS (3)
#define JPEGD_STREAM_BUFF_SIZE (512*1024)
#define MAX_COMPONENTS (3) /* for JFIF: YCbCr */
#define DRI_MARKER_LENGTH (4) /* must be 4 bytes */
#define QUANTIZE_TABLE_LENGTH (64)
#define MAX_AC_HUFFMAN_TABLE_LENGTH (162) /* for baseline */
#define MAX_DC_HUFFMAN_TABLE_LENGTH (12) /* for baseline */
#define MAX_HUFFMAN_CODE_BIT_LENGTH (16) /* The longest code word is 16 bits */
#define MIN_WIDTH (48) /* 48 Bytes */
#define MIN_HEIGHT (48) /* 48 Bytes */
#define MAX_WIDTH (4*1024) /* 4K Bytes */
#define MAX_HEIGHT (4*1024) /* 4K Bytes */
#define MAX_STREAM_LENGTH (MAX_WIDTH * MAX_HEIGHT) /* 16M Bytes */
#define ZERO_PADDING_LENGTH (4) /* 4 Bytes */
#define JPEGD_BASELINE_TABLE_SIZE (QUANTIZE_TABLE_LENGTH * 3 \
+ MAX_AC_HUFFMAN_TABLE_LENGTH * 2 \
+ MAX_DC_HUFFMAN_TABLE_LENGTH * 2 \
+ ZERO_PADDING_LENGTH) /* 544 Bytes */
#define JPEGDEC_YCbCr400 (0x080000U)
#define JPEGDEC_YCbCr440 (0x010004U)
#define JPEGDEC_YCbCr411_SEMIPLANAR (0x100000U)
#define JPEGDEC_YCbCr444_SEMIPLANAR (0x200000U)
#define JPEGD_DBG_FUNCTION (0x00000001)
#define JPEGD_DBG_STARTCODE (0x00000002)
#define JPEGD_DBG_TABLE (0x00000004)
#define JPEGD_DBG_RESULT (0x00000008)
#define JPEGD_DBG_IO (0x00000010) /* input and output write file */
#define JPEGD_DBG_PARSER_INFO (0x00000020) /* parser information */
#define JPEGD_DBG_SYNTAX_ERR (0x00000040) /* syntax error */
#define JPEGD_DBG_HAL_INFO (0x00000080) /* hal information */
#define JPEGDEC_BASELINE (0x0)
#define JPEGDEC_PROGRESSIVE (0x1)
#define JPEGDEC_NONINTERLEAVED (0x2)
extern RK_U32 jpegd_debug;
#define JPEGDEC_YUV400 (0)
#define JPEGDEC_YUV420 (2)
#define JPEGDEC_YUV422 (3)
#define JPEGDEC_YUV444 (4)
#define JPEGDEC_YUV440 (5)
#define JPEGDEC_YUV411 (6)
#define jpegd_dbg(flag, fmt, ...) _mpp_dbg(jpegd_debug, flag, fmt, ## __VA_ARGS__)
#define jpegd_dbg_f(flag, fmt, ...) _mpp_dbg_f(jpegd_debug, flag, fmt, ## __VA_ARGS__)
#define JPEGD_STREAM_BUFF_SIZE (512*1024)
#define JPEGDEC_BASELINE_TABLE_SIZE (544)
#define jpegd_dbg_func(fmt, ...) jpegd_dbg_f(JPEGD_DBG_FUNCTION, fmt, ## __VA_ARGS__)
#define jpegd_dbg_marker(fmt, ...) jpegd_dbg(JPEGD_DBG_STARTCODE, fmt, ## __VA_ARGS__)
#define jpegd_dbg_table(fmt, ...) jpegd_dbg(JPEGD_DBG_TABLE, fmt, ## __VA_ARGS__)
#define jpegd_dbg_result(fmt, ...) jpegd_dbg(JPEGD_DBG_RESULT, fmt, ## __VA_ARGS__)
#define jpegd_dbg_io(fmt, ...) jpegd_dbg(JPEGD_DBG_IO, fmt, ## __VA_ARGS__)
#define jpegd_dbg_parser(fmt, ...) jpegd_dbg(JPEGD_DBG_PARSER_INFO, fmt, ## __VA_ARGS__)
#define jpegd_dbg_syntax(fmt, ...) jpegd_dbg(JPEGD_DBG_SYNTAX_ERR, fmt, ## __VA_ARGS__)
#define jpegd_dbg_hal(fmt, ...) jpegd_dbg(JPEGD_DBG_HAL_INFO, fmt, ## __VA_ARGS__)
typedef enum {
JPEGDEC_SLICE_READY = 2,
JPEGDEC_FRAME_READY = 1,
JPEGDEC_STRM_PROCESSED = 3,
JPEGDEC_SCAN_PROCESSED = 4,
JPEGDEC_OK = 0,
JPEGDEC_ERROR = -1,
JPEGDEC_UNSUPPORTED = -2,
JPEGDEC_PARAM_ERROR = -3,
JPEGDEC_MEMFAIL = -4,
JPEGDEC_INITFAIL = -5,
JPEGDEC_INVALID_STREAM_LENGTH = -6,
JPEGDEC_STRM_ERROR = -7,
JPEGDEC_INVALID_INPUT_BUFFER_SIZE = -8,
JPEGDEC_HW_RESERVED = -9,
JPEGDEC_INCREASE_INPUT_BUFFER = -10,
JPEGDEC_SLICE_MODE_UNSUPPORTED = -11,
JPEGDEC_DWL_HW_TIMEOUT = -253,
JPEGDEC_DWL_ERROR = -254,
JPEGDEC_HW_BUS_ERROR = -255,
JPEGDEC_SYSTEM_ERROR = -256,
JPEGDEC_FORMAT_NOT_SUPPORTED = -1000
} JpegDecRet;
enum huffman_table_type {
HUFFMAN_TABLE_TYPE_DC = 0,
HUFFMAN_TABLE_TYPE_AC = 1,
HUFFMAN_TABLE_TYPE_BUTT = 2,
};
enum huffman_table_id {
HUFFMAN_TABLE_ID_ZERO = 0,
HUFFMAN_TABLE_ID_ONE = 1,
HUFFMAN_TABLE_ID_TWO = 2,
HUFFMAN_TABLE_ID_THREE = 3,
HUFFMAN_TABLE_ID_BUTT = 4,
};
enum quantize_table_id {
QUANTIZE_TABLE_ID_ZERO = 0,
QUANTIZE_TABLE_ID_ONE = 1,
QUANTIZE_TABLE_ID_TWO = 2,
QUANTIZE_TABLE_ID_THREE = 3,
QUANTIZE_TABLE_ID_BUTT = 4,
};
/* Alternating Current Table */
typedef struct {
RK_U32 C; /* Component id */
RK_U32 H; /* Horizontal sampling factor */
RK_U32 V; /* Vertical sampling factor */
RK_U32 Tq; /* Quantization table destination selector */
} Components;
RK_U32 bits[MAX_HUFFMAN_CODE_BIT_LENGTH];
RK_U32 vals[MAX_AC_HUFFMAN_TABLE_LENGTH];
RK_U32 actual_length; /* calculate based on actual stream */
} AcTable;
/* Direct Current Table */
typedef struct {
RK_U8 *pStartOfStream;
RK_U8 *pCurrPos;
RK_U32 streamBus; /* physical address */
RK_U32 bitPosInByte;
RK_U32 streamLength;
RK_U32 readBits;
RK_U32 appnFlag;
RK_U32 thumbnail;
RK_U32 returnSosMarker;
} StreamStorage;
RK_U32 bits[MAX_HUFFMAN_CODE_BIT_LENGTH];
RK_U32 vals[MAX_DC_HUFFMAN_TABLE_LENGTH];
RK_U32 actual_length; /* calculate based on actual stream */
} DcTable;
typedef struct {
RK_U8 *pStartOfImage;
RK_U8 *pLum;
RK_U8 *pCr;
RK_U8 *pCb;
RK_U32 imageReady;
RK_U32 headerReady;
RK_U32 size;
RK_U32 sizeLuma;
RK_U32 sizeChroma;
RK_U32 ready;
RK_U32 columns[MAX_NUMBER_OF_COMPONENTS];
RK_U32 pixelsPerRow[MAX_NUMBER_OF_COMPONENTS];
} ImageData;
typedef struct JpegdSyntax {
/* just 16 bits because quantization parameters are much less than 2^16 */
RK_U16 quant_matrixes[4][QUANTIZE_TABLE_LENGTH];
typedef struct {
RK_U32 Lf;
RK_U32 P;
RK_U32 Y;
RK_U32 hwY;
RK_U32 X;
RK_U32 hwX;
RK_U32 Nf; /* Number of components in frame */
RK_U32 codingType;
RK_U32 numMcuInFrame;
RK_U32 numMcuInRow;
RK_U32 mcuNumber;
RK_U32 nextRstNumber;
RK_U32 Ri;
RK_U32 driPeriod;
RK_U32 block;
RK_U32 row;
RK_U32 col;
RK_U32 cIndex;
RK_U32 *pBuffer;
RK_U32 bufferBus;
RK_S32 *pBufferCb;
RK_S32 *pBufferCr;
VPUMemLinear_t pTableBase;
RK_U32 numBlocks[MAX_NUMBER_OF_COMPONENTS];
RK_U32 blocksPerRow[MAX_NUMBER_OF_COMPONENTS];
RK_U32 useAcOffset[MAX_NUMBER_OF_COMPONENTS];
Components component[MAX_NUMBER_OF_COMPONENTS];
} FrameInfo;
/* only two ac table for baseline */
AcTable ac_table[2];
typedef struct {
RK_U32 Ls;
RK_U32 Ns;
RK_U32 Cs[MAX_NUMBER_OF_COMPONENTS]; /* Scan component selector */
RK_U32 Td[MAX_NUMBER_OF_COMPONENTS]; /* Selects table for DC */
RK_U32 Ta[MAX_NUMBER_OF_COMPONENTS]; /* Selects table for AC */
RK_U32 Ss;
RK_U32 Se;
RK_U32 Ah;
RK_U32 Al;
RK_U32 index;
RK_S32 numIdctRows;
RK_S32 pred[MAX_NUMBER_OF_COMPONENTS];
} ScanInfo;
/* only two dc table for baseline */
DcTable dc_table[2];
typedef struct {
RK_U32 sliceHeight;
RK_U32 amountOfQTables;
RK_U32 yCbCrMode;
RK_U32 yCbCr422;
RK_U32 column;
RK_U32 X; /* width */
RK_U32 Y; /* height */
RK_U32 memSize;
RK_U32 SliceCount;
RK_U32 SliceReadyForPause;
RK_U32 SliceMBCutValue;
RK_U32 pipeline;
RK_U32 userAllocMem;
RK_U32 sliceMbSetValue;
RK_U32 timeout;
RK_U32 rlcMode;
RK_U32 lumaPos;
RK_U32 chromaPos;
RK_U32 sliceStartCount;
RK_U32 amountOfSlices;
RK_U32 noSliceIrqForUser;
RK_U32 sliceLimitReached;
RK_U32 inputBufferEmpty;
RK_U32 fillRight;
RK_U32 fillBottom;
RK_U32 streamEnd;
RK_U32 streamEndFlag;
RK_U32 inputBufferLen;
RK_U32 inputStreaming;
RK_U32 decodedStreamLen;
RK_U32 init;
RK_U32 initThumb;
RK_U32 initBufferSize;
RK_S32 dcRes[MAX_NUMBER_OF_COMPONENTS];
VPUMemLinear_t outLuma;
VPUMemLinear_t outChroma;
VPUMemLinear_t outChroma2;
VPUMemLinear_t givenOutLuma;
VPUMemLinear_t givenOutChroma;
VPUMemLinear_t givenOutChroma2;
RK_S32 pred[MAX_NUMBER_OF_COMPONENTS];
/* progressive parameters */
RK_U32 nonInterleaved;
RK_U32 componentId;
RK_U32 operationType;
RK_U32 operationTypeThumb;
RK_U32 progressiveScanReady;
RK_U32 nonInterleavedScanReady;
RK_U32 allocated;
RK_U32 yCbCrModeOrig;
RK_U32 getInfoYCbCrMode;
RK_U32 components[MAX_NUMBER_OF_COMPONENTS];
VPUMemLinear_t pCoeffBase;
/* quantizer scale calculated from quant_matrixes */
RK_U32 qscale[4];
RK_U32 fillX;
RK_U32 fillY;
/* output format */
MppFrameFormat output_fmt;
RK_U32 progressiveFinish;
RK_U32 pfCompId;
RK_U32 pfNeeded[MAX_NUMBER_OF_COMPONENTS];
VPUMemLinear_t tmpStrm;
} DecInfo;
/* especially for jpeg */
RK_U32 yuv_mode;
RK_U8 fill_bottom;
RK_U8 fill_right;
typedef struct {
VPUMemLinear_t outLumaBuffer;
VPUMemLinear_t outChromaBuffer;
VPUMemLinear_t outChromaBuffer2;
} JpegAsicBuffers;
/* syntax in SOS */
RK_U8 scan_start;
RK_U8 scan_end;
RK_U8 prev_shift; /* Ah */
RK_U8 point_transform; /* Al */
typedef struct {
RK_U32 bits[16];
RK_U32 *vals;
RK_U32 tableLength;
RK_U32 start;
RK_U32 last;
} VlcTable;
/* 0 - not found; 1 - found */
RK_U8 dht_found;
RK_U8 eoi_found;
typedef struct {
RK_U32 Lh;
VlcTable acTable0;
VlcTable acTable1;
VlcTable acTable2;
VlcTable acTable3;
VlcTable dcTable0;
VlcTable dcTable1;
VlcTable dcTable2;
VlcTable dcTable3;
VlcTable *table;
} HuffmanTables;
/* amount of quantize tables: 1 or 3 */
RK_U8 qtable_cnt;
typedef struct {
RK_U32 Lq; /* Quantization table definition length */
RK_U32 table0[64];
RK_U32 table1[64];
RK_U32 table2[64];
RK_U32 table3[64];
RK_U32 *table;
} QuantTables;
/* length of sos segment */
RK_U32 sos_len;
/* Control interface between decoder and pp */
/* decoder writes, pp read-only */
typedef struct DecPpInterface_ {
enum {
DECPP_IDLE = 0,
DECPP_RUNNING, /* PP was started */
DECPP_PIC_READY, /* PP has finished a picture */
DECPP_PIC_NOT_FINISHED /* PP still processing a picture */
} ppStatus; /* Decoder keeps track of what it asked the pp to do */
/* decoded bytes by software */
RK_U32 strm_offset;
enum {
MULTIBUFFER_UNINIT = 0, /* buffering mode not yet decided */
MULTIBUFFER_DISABLED, /* Single buffer legacy mode */
MULTIBUFFER_SEMIMODE, /* enabled but full pipel cannot be used */
MULTIBUFFER_FULLMODE /* enabled and full pipeline successful */
} multiBufStat;
/* hardware decode start address */
RK_U8 *cur_pos;
RK_U32 inputBusLuma;
RK_U32 inputBusChroma;
RK_U32 bottomBusLuma;
RK_U32 bottomBusChroma;
RK_U32 picStruct; /* structure of input picture */
RK_U32 topField;
RK_U32 inwidth;
RK_U32 inheight;
RK_U32 usePipeline; /* only this variance be used */
RK_U32 littleEndian;
RK_U32 wordSwap;
RK_U32 croppedW;
RK_U32 croppedH;
/* length of a jpeg packet */
RK_U32 pkt_len;
RK_U32 bufferIndex; /* multibuffer, where to put PP output */
RK_U32 displayIndex; /* multibuffer, next picture in display order */
RK_U32 prevAnchorDisplayIndex;
/* Horizontal pixel density */
RK_U16 hor_density;
/* VC-1 */
RK_U32 rangeRed;
RK_U32 rangeMapYEnable;
RK_U32 rangeMapYCoeff;
RK_U32 rangeMapCEnable;
RK_U32 rangeMapCCoeff;
} DecPpInterface;
/* Vertical pixel density */
RK_U16 ver_density;
typedef struct {
int enable;
int outFomart; /* =0,RGB565;=1,ARGB 8888 */
int scale_denom;
int shouldDither;
int cropX;
int cropY;
int cropW;
int cropH;
} PostProcessInfo;
RK_U32 width, height;
RK_U32 hor_stride, ver_stride;
/* Image information */
typedef struct {
RK_U32 displayWidth;
RK_U32 displayHeight;
RK_U32 outputWidth; /* Number of pixels/line in the image */
RK_U32 outputHeight; /* Number of lines in in the image */
RK_U32 version;
RK_U32 units;
RK_U32 xDensity;
RK_U32 yDensity;
RK_U32 outputFormat;
RK_U32 codingMode; /* JPEGDEC_BASELINE
* JPEGDEC_PROGRESSIVE
* JPEGDEC_NONINTERLEAVED
*/
/* Number of components in frame */
RK_U32 nb_components;
RK_U32 thumbnailType; /* Thumbnail exist or not or not supported */
RK_U32 displayWidthThumb;
RK_U32 displayHeightThumb;
RK_U32 outputWidthThumb; /* Number of pixels/line in the image */
RK_U32 outputHeightThumb; /* Number of lines in in the image */
RK_U32 outputFormatThumb; /* JPEGDEC_YCbCr400
* JPEGDEC_YCbCr420
* JPEGDEC_YCbCr422
*/
RK_U32 codingModeThumb; /* JPEGDEC_BASELINE
* JPEGDEC_PROGRESSIVE
* JPEGDEC_NONINTERLEAVED
*/
} JpegDecImageInfo;
/* Component id */
RK_U32 component_id[MAX_COMPONENTS];
typedef struct JpegSyntaxParam {
StreamStorage stream;
FrameInfo frame;
ImageData image;
ScanInfo scan;
DecInfo info;
HuffmanTables vlc;
QuantTables quant;
JpegDecImageInfo imageInfo;
RK_U32 ppInputFomart;
PostProcessInfo ppInfo;
RK_U32 ppScaleW;
RK_U32 ppScaleH;
JpegAsicBuffers asicBuff;
DecPpInterface ppControl;
const void *ppInstance;
} JpegSyntaxParam;
/* Horizontal sampling factor */
RK_U32 h_count[MAX_COMPONENTS];
/* Vertical sampling factor */
RK_U32 v_count[MAX_COMPONENTS];
/* Huffman Table ID used by DC */
RK_U32 dc_index[MAX_COMPONENTS];
/* Huffman Table ID used by AC */
RK_U32 ac_index[MAX_COMPONENTS];
/* maximum h and v counts */
RK_U32 h_max, v_max;
/* quant table index for each component */
RK_U32 quant_index[MAX_COMPONENTS];
RK_U32 restart_interval;
} JpegdSyntax;
#endif /*__JPEGD_SYNTAX__*/

View file

@ -27,56 +27,56 @@
static MPP_RET hal_jpegd_reg_gen (void *hal, HalTaskInfo *task)
{
JpegHalContext *self = (JpegHalContext *)hal;
JpegdHalCtx *self = (JpegdHalCtx *)hal;
return self->hal_api.reg_gen (hal, task);
}
static MPP_RET hal_jpegd_start (void *hal, HalTaskInfo *task)
{
JpegHalContext *self = (JpegHalContext *)hal;
JpegdHalCtx *self = (JpegdHalCtx *)hal;
return self->hal_api.start (hal, task);
}
static MPP_RET hal_jpegd_wait (void *hal, HalTaskInfo *task)
{
JpegHalContext *self = (JpegHalContext *)hal;
JpegdHalCtx *self = (JpegdHalCtx *)hal;
return self->hal_api.wait (hal, task);
}
static MPP_RET hal_jpegd_reset (void *hal)
{
JpegHalContext *self = (JpegHalContext *)hal;
JpegdHalCtx *self = (JpegdHalCtx *)hal;
return self->hal_api.reset (hal);
}
static MPP_RET hal_jpegd_flush (void *hal)
{
JpegHalContext *self = (JpegHalContext *)hal;
JpegdHalCtx *self = (JpegdHalCtx *)hal;
return self->hal_api.flush (hal);
}
static MPP_RET hal_jpegd_control (void *hal, RK_S32 cmd_type, void *param)
{
JpegHalContext *self = (JpegHalContext *)hal;
JpegdHalCtx *self = (JpegdHalCtx *)hal;
return self->hal_api.control (hal, cmd_type, param);
}
static MPP_RET hal_jpegd_deinit (void *hal)
{
JpegHalContext *self = (JpegHalContext *)hal;
JpegdHalCtx *self = (JpegdHalCtx *)hal;
return self->hal_api.deinit (hal);
}
static MPP_RET hal_jpegd_init (void *hal, MppHalCfg *cfg)
{
JpegHalContext *self = (JpegHalContext *)hal;
JpegdHalCtx *self = (JpegdHalCtx *)hal;
MppHalApi *p_api = NULL;
VpuHardMode hard_mode = MODE_NULL;
RK_U32 hw_flag = 0;
if (NULL == self)
return MPP_ERR_VALUE;
memset(self, 0, sizeof(JpegHalContext));
memset(self, 0, sizeof(JpegdHalCtx));
p_api = &self->hal_api;
@ -119,7 +119,7 @@ const MppHalApi hal_api_jpegd = {
.name = "jpegd",
.type = MPP_CTX_DEC,
.coding = MPP_VIDEO_CodingMJPEG,
.ctx_size = sizeof(JpegHalContext),
.ctx_size = sizeof(JpegdHalCtx),
.flag = 0,
.init = hal_jpegd_init,
.deinit = hal_jpegd_deinit,

View file

@ -35,7 +35,19 @@ typedef struct JpegdIocExtInfo_t {
JpegdIocExtInfoSlot slots[5];
} JpegdIocExtInfo;
typedef struct JpegHalContext {
typedef struct PPInfo_t {
/* PP parameters */
RK_U8 pp_enable; /* 0 - disable; 1 - enable */
RK_U8 pp_in_fmt; /* PP input format */
RK_U8 pp_out_fmt;/* PP output format */
RK_U8 dither_enable; /* for PP output RGB565 */
RK_U32 crop_width;
RK_U32 crop_height;
RK_U32 crop_x;
RK_U32 crop_y;
} PPInfo;
typedef struct JpegdHalCtx {
MppBufSlots packet_slots;
MppBufSlots frame_slots;
RK_S32 vpu_socket;
@ -51,8 +63,13 @@ typedef struct JpegHalContext {
RK_U32 frame_count;
RK_U32 output_yuv_count;
RK_S32 pkt_fd; /* input stream's physical address(fd) */
RK_S32 frame_fd; /* output picture's physical address(fd) */
PPInfo pp_info;
FILE *fp_reg_in;
FILE *fp_reg_out;
} JpegHalContext;
} JpegdHalCtx;
#endif /* __HAL_JPEGD_COMMON_H__ */

File diff suppressed because it is too large Load diff

View file

@ -43,8 +43,9 @@ static const RK_U8 zzOrder[64] = {
58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63
};
MPP_RET jpegd_allocate_chroma_out_buffer(JpegSyntaxParam *pSyntax);
void jpegd_write_tables(JpegSyntaxParam *pSyntax, JpegHalContext *pCtx);
MPP_RET
jpegd_set_output_format(JpegHalContext *pCtx, JpegSyntaxParam *pSyntax);
void jpegd_write_qp_ac_dc_table(JpegdHalCtx *ctx,
JpegdSyntax*syntax);
void jpegd_setup_output_fmt(JpegdHalCtx *ctx, JpegdSyntax *syntax);
#endif /* __HAL_JPEGD_COMMON_H__ */

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -241,7 +241,6 @@ PARSE_OPINIONS_OUT:
MPP_RET jpegd_test_deinit(jpegdDemoCtx *ctx)
{
FUN_TEST("Enter");
MppDec *pApi = &(ctx->api);
if (pApi->parser) {
parser_deinit(pApi->parser);
@ -281,13 +280,11 @@ MPP_RET jpegd_test_deinit(jpegdDemoCtx *ctx)
ctx->pOutFile = NULL;
}
FUN_TEST("Exit");
return MPP_OK;
}
MPP_RET jpegd_test_init(parserDemoCmdCtx *cmd, jpegdDemoCtx *ctx)
{
FUN_TEST("Enter");
MPP_RET ret = MPP_OK;
MppDec *pMppDec = NULL;
ParserCfg parser_cfg;
@ -299,11 +296,11 @@ MPP_RET jpegd_test_init(parserDemoCmdCtx *cmd, jpegdDemoCtx *ctx)
//demo configure
ctx->pOutFile = fopen("/data/spurs.yuv", "wb+");
if (NULL == ctx->pOutFile) {
JPEGD_ERROR_LOG("create spurs.yuv failed");
mpp_err_f("create spurs.yuv failed");
}
//malloc buffers for software
CHECK_MEM(ctx->strmbuf = mpp_malloc_size(RK_U8, JPEGD_STREAM_BUFF_SIZE));
ctx->strmbuf = mpp_malloc_size(RK_U8, JPEGD_STREAM_BUFF_SIZE);
//malloc buffers for hardware
if (ctx->frmbuf_grp == NULL) {
@ -325,12 +322,10 @@ MPP_RET jpegd_test_init(parserDemoCmdCtx *cmd, jpegdDemoCtx *ctx)
pMppDec = &ctx->api;
pMppDec->coding = MPP_VIDEO_CodingMJPEG;
CHECK_FUN(mpp_buf_slot_init(&pMppDec->frame_slots));
CHECK_MEM(pMppDec->frame_slots);
mpp_buf_slot_init(&pMppDec->frame_slots);
mpp_buf_slot_setup(pMppDec->frame_slots, 2);
CHECK_FUN(mpp_buf_slot_init(&pMppDec->packet_slots));
CHECK_MEM(pMppDec->packet_slots);
mpp_buf_slot_init(&pMppDec->packet_slots);
mpp_buf_slot_setup(pMppDec->packet_slots, 2);
//parser config
@ -340,7 +335,7 @@ MPP_RET jpegd_test_init(parserDemoCmdCtx *cmd, jpegdDemoCtx *ctx)
parser_cfg.packet_slots = pMppDec->packet_slots;
parser_cfg.task_count = 2;
parser_cfg.need_split = 0;
CHECK_FUN(parser_init(&pMppDec->parser, &parser_cfg));
parser_init(&pMppDec->parser, &parser_cfg);
//hal config
memset(&hal_cfg, 0, sizeof(hal_cfg));
@ -360,23 +355,20 @@ MPP_RET jpegd_test_init(parserDemoCmdCtx *cmd, jpegdDemoCtx *ctx)
hal_cfg.frame_slots = pMppDec->frame_slots;
hal_cfg.packet_slots = pMppDec->packet_slots;
hal_cfg.task_count = parser_cfg.task_count;
CHECK_FUN(mpp_hal_init(&pMppDec->hal, &hal_cfg));
mpp_hal_init(&pMppDec->hal, &hal_cfg);
pMppDec->tasks = hal_cfg.tasks;
memset(&ctx->task, 0, sizeof(ctx->task));
memset(ctx->task.refer, -1, sizeof(ctx->task.refer));
ctx->task.input = -1;
FUN_TEST("Exit");
return MPP_OK;
__FAILED:
FUN_TEST("Exit");
return ret;
}
MPP_RET jpegd_parser_test(parserDemoCmdCtx *cmd)
{
FUN_TEST("Enter");
MPP_RET ret = MPP_OK;
MppDec *pMppDec = NULL;
HalDecTask *curtask = NULL;
@ -420,7 +412,7 @@ MPP_RET jpegd_parser_test(parserDemoCmdCtx *cmd)
mpp_packet_init(&DemoCtx.pkt, DemoCtx.strmbuf, fileSize);
// 3.parser_prepare
CHECK_FUN(parser_prepare(pMppDec->parser, DemoCtx.pkt, curtask)); // jpegd_parser_prepare
parser_prepare(pMppDec->parser, DemoCtx.pkt, curtask); // jpegd_parser_prepare
if (-1 == curtask->input) {
if (MPP_OK == mpp_buf_slot_get_unused(pMppDec->packet_slots, &slot_idx) ) {
@ -455,7 +447,7 @@ MPP_RET jpegd_parser_test(parserDemoCmdCtx *cmd)
}
}
CHECK_FUN(parser_parse(pMppDec->parser, curtask)); // jpegd_parser_parse
parser_parse(pMppDec->parser, curtask); // jpegd_parser_parse
if (curtask->valid) {
HalTaskInfo task_info;
@ -492,12 +484,11 @@ MPP_RET jpegd_parser_test(parserDemoCmdCtx *cmd)
void* pOutYUV = NULL;
pOutYUV = mpp_buffer_get_ptr(DemoCtx.pic_buf);
if (pOutYUV) {
JPEGD_INFO_LOG("pOutYUV:%p", pOutYUV);
JpegSyntaxParam *pTmpSyn = (JpegSyntaxParam *)curtask->syntax.data;
RK_U32 width = pTmpSyn->frame.hwX;
RK_U32 height = pTmpSyn->frame.hwY;
JpegdSyntax *syntax = (JpegdSyntax *)curtask->syntax.data;
RK_U32 width = syntax->hor_stride;
RK_U32 height = syntax->ver_stride;
JPEGD_INFO_LOG("Output Image: %d*%d", width, height);
mpp_log_f("Output Image: %d*%d", width, height);
if (DemoCtx.pOutFile) {
fwrite(pOutYUV, 1, width * height * 3 / 2, DemoCtx.pOutFile);
fflush(DemoCtx.pOutFile);
@ -523,7 +514,7 @@ MPP_RET jpegd_parser_test(parserDemoCmdCtx *cmd)
DemoCtx.dec_frm_num ++;
} while (0);
CHECK_FUN(mpp_dec_flush(pMppDec));
mpp_dec_flush(pMppDec);
__FAILED:
if (pInFile) {
@ -532,14 +523,11 @@ __FAILED:
}
jpegd_test_deinit(&DemoCtx);
FUN_TEST("Exit");
return MPP_OK;
}
int main(int argc, char **argv)
{
FUN_TEST("Enter");
RK_S32 ret = 0;
parserDemoCmdCtx demoCmdCtx;
parserDemoCmdCtx* cmd = NULL;
@ -565,6 +553,5 @@ int main(int argc, char **argv)
}
jpegd_parser_test(cmd);
FUN_TEST("Exit");
return MPP_OK;
}