Skip to content

UsageExampleForDecoder

Sijia Chen edited this page Feb 2, 2015 · 6 revisions

This page is about the example of decoder usage

Decoder usage example

  • An example for using the decoder for Decoding only or Parsing only

Step 1:decoder declaration

//decoder declaration
ISVCDecoder *pSvcDecoder;
//input: encoded bitstream start position; should include start code prefix
unsigned char *pBuf =...;
//input: encoded bit stream length; should include the size of start code prefix
int iSize =...;
//output: [0~2] for Y,U,V buffer for Decoding only
unsigned char *pData[3] =...;
//in-out: for Decoding only: declare and initialize the output buffer info, this should never co-exist with Parsing only
SBufferInfo sDstBufInfo;
memset(&sDstBufInfo, 0, sizeof(SBufferInfo));
//in-out: for Parsing only: declare and initialize the output bitstream buffer info for parse only, this should never co-exist with Decoding only
SParserBsInfo sDstParseInfo;
    memset(&sDstParseInfo, 0, sizeof(SParserBsInfo));
    sDstParseInfo.pDstBuff = new unsigned char[PARSE_SIZE]; //In Parsing only, allocate enough buffer to save transcoded bitstream for a frame

Step 2:decoder creation

CreateDecoder(pSvcDecoder);

Step 3:declare required parameter, used to differentiate Decoding only and Parsing only

SDecodingParam sDecParam = {0};
sDecParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_AVC;
//for Parsing only, the assignment is mandatory
sDecParam.bParseOnly = true;

Step 4:initialize the parameter and decoder context, allocate memory

Initialize(&sDecParam);

Step 5:do actual decoding process in slice level; this can be done in a loop until data ends

 //for Decoding only
 iRet = DecodeFrameNoDelay(pBuf, iSize, pData, &sDstBufInfo);
 //or
 iRet = DecodeFrame2(pBuf, iSize, pData, &sDstBufInfo);
 //for Parsing only
 iRet = DecodeParser(pBuf, iSize, &sDstParseInfo);
 //decode failed
 If (iRet != 0){
     RequestIDR or something like that.
 }
 //for Decoding only, pData can be used for render.
 if (sDstBufInfo.iBufferStatus==1){
     output pData[0], pData[1], pData[2];
 }
//for Parsing only, sDstParseInfo can be used for, e.g., HW decoding
 if (sDstBufInfo.iNalNum > 0){
     Hardware decoding sDstParseInfo;
 }
 //no-delay decoding can be realized by directly calling DecodeFrameNoDelay(), which is the recommended usage.
 //no-delay decoding can also be realized by directly calling DecodeFrame2() again with NULL input, as in the following. In this case, decoder would immediately reconstruct the input data. This can also be used similarly for Parsing only. Consequent decoding error and output indication should also be considered as above.
 iRet = DecodeFrame2(NULL, 0, pData, &sDstBufInfo);
 judge iRet, sDstBufInfo.iBufferStatus ...

Step 6:uninitialize the decoder and memory free

Uninitialize();

Step 7:destroy the decoder

DestroyDecoder();
Clone this wiki locally