6410硬解码示例

    技术2026-06-08  2

    1 ring_buf模式:

     

    static char outfilename[512];int decoder_test(char *filename, int dec_type){  void *handle;  SSBSIP_MFC_STREAM_INFO stream_info;  FILE *fp_in,*fp_out;  int nLoop, nFrames;  void *pStrmBuf;  int nStrmSize, nReadLeng;  unsigned char *pYUVBuf;  int nYUVLeng;    // Opening Input File //    fp_in = fopen(filename, "rb");  if (fp_in == NULL) {  RETAILMSG(1,(L"File not found/n"));  return 0;  }/* /  // Opening Output File //  /  sprintf(outfilename, "//Storage Card//output.yuv");  fp_out = fopen(outfilename,"wb");  if (fp_out == NULL) {  RETAILMSG(1,(L"Cannot open the output file./n"));  return 0;  }*/  RETAILMSG(1,(L"### Start Decoding/n"));  /  /// 1. Create new instance ///  /// (SsbSipMfcDecodeInit) ///  /  handle = SsbSipMfcDecodeInit(dec_type);  if (handle == NULL) {  RETAILMSG(1,(L"SsbSipMfcDecodeInit Failed./n"));  return 0;  }    /// 2. Obtaining the Input Buffer ///  /// (SsbSipMfcDecodeGetInBuf) ///    pStrmBuf = SsbSipMfcDecodeGetInBuf(handle, &nStrmSize);  if (pStrmBuf == NULL) {  RETAILMSG(1,(L"SsbSipMfcDecodeGetInBuf Failed./n"));  SsbSipMfcDecodeDeInit(handle);  return 0;  }  RETAILMSG(1,(L"/nXXXX pStrmBuf =0x%X. GetCurrentProcessId()=0x%X, nStreamSize = %d/n", pStrmBuf, GetCurrentProcessId(), nStrmSize));  /  // Read Video Stream from File //  // (Size of reading is returned //  // by SsbSipMfcDecodeGetInBuf() call) //  /  nReadLeng = fread(pStrmBuf, 1, nStrmSize, fp_in);    /// 3. Configuring the instance with the config stream ///  /// (SsbSipMfcDecodeExe) ///    if (SsbSipMfcDecodeExe(handle, nReadLeng) != SSBSIP_MFC_DEC_RET_OK) {  RETAILMSG(1,(L"MFC Decoder(RING_BUF mode) Configuration Failed./n"));  return 0;  }  /  /// 4. Get stream information ///  /  SsbSipMfcDecodeGetConfig(handle, MFC_DEC_GETCONF_STREAMINFO, &stream_info);  RETAILMSG(1,(L"/t<STREAMINFO> width=%d height=%d./n", stream_info.width, stream_info.height));  nFrames = 0;  for (nLoop=0; nLoop < 10000; nLoop++) {    /// 5. Obtaining the Input Buffer ///  /// (SsbSipMfcDecodeGetInBuf) ///    pStrmBuf = SsbSipMfcDecodeGetInBuf(handle, &nStrmSize);  RETAILMSG(1,(L"/t/t---nStrmSize = [%d]/n", nStrmSize));  //  /// Fill the Input Buffer only if required. ///  //  if (nStrmSize > 0) {  RETAILMSG(1,(L"/n *** 1 *** "));  if (feof(fp_in)) {  RETAILMSG(1, (L"/n###############################"));  RETAILMSG(1, (L"/n## END OF FILE ##/n"));  RETAILMSG(1, (L"/n###############################"));  break;  }  RETAILMSG(1,(L"/n *** 2 *** "));  // Read data from file  nReadLeng = fread(pStrmBuf, 1, nStrmSize, fp_in);  RETAILMSG(1,(L"/n *** 3 *** "));  if (nReadLeng == nStrmSize) {// RETAILMSG(1, (L"/n##################################"));// RETAILMSG(1, (L"/n# READING ONE UNIT FROM FILE #"));// RETAILMSG(1, (L"/n##################################/n"));  }  else if (nReadLeng < nStrmSize) {  RETAILMSG(1, (L"/n##########################################"));  RETAILMSG(1, (L"/n## READING THE LAST BLOCK OF FILE ##"));  RETAILMSG(1, (L"/n##########################################"));  }  }  else  nReadLeng = 0;  /  /// 6. DECODE ///  /// (SsbSipMfcDecodeExe) ///  /  if (SsbSipMfcDecodeExe(handle, nReadLeng) != SSBSIP_MFC_DEC_RET_OK)  break;  /  /// 7. Obtaining the Output Buffer ///  /// (SsbSipMfcDecodeGetOutBuf) ///  /  pYUVBuf = SsbSipMfcDecodeGetOutBuf(handle, &nYUVLeng);// if (nLoop > 0 && nLoop < 80)// fwrite(pYUVBuf, 1, (stream_info.width * stream_info.height * 3) >> 1, fp_out);  RETAILMSG(1,(L"/t [%d] decoded./n", nLoop));  }  //  /// 8. SsbSipMfcDecodeDeInit ///  //  SsbSipMfcDecodeDeInit(handle);  RETAILMSG(1,(L"/n/n@@@ Program ends./n"));  fclose(fp_in);// fclose(fp_out);  return 0;}

     

    2 line_buf模式: h264dec_test

     

    int h264dec_test(char *filename){  void *handle;  SSBSIP_H264_STREAM_INFO stream_info;  FILE *fp_in,*fp_out;  int nLoop, nFrames;  void *pStrmBuf;  int nFrameLeng;  unsigned char *pYUVBuf;  int nYUVLeng;  int phy_add_buf_vals[2];  unsigned int post_rotate;  int fram_need_count;  FRAMEX_CTX *pFrameExCtx;    // Opening Input File //    //fp_in = fopen(filename, "rb");fp_in = fopen("//Storage Card//ultraviolet-640x480.264", "rb");//fp_in = fopen("//Storage Card//test.264", "rb");  if (fp_in == NULL) {  RETAILMSG(1,(L"File not found/n"));  return 0;  }  /  // Opening Output File //  /  fp_out = fopen("//My Documents//Video_Channle25TS.yuv","wb");  if (fp_out == NULL) {  RETAILMSG(1,(L"Cannot open the output file./n"));  return 0;  }  ///  // FrameExtractor Initialization //  ///  pFrameExCtx = FrameExtractorInit(FRAMEX_IN_TYPE_FILE, delimiter_h264, sizeof(delimiter_h264), 1);  FrameExtractorFirst(pFrameExCtx, fp_in);  //  /// 1. Create new instance ///  /// (SsbSipH264DecodeInit) ///  //  handle = SsbSipH264DecodeInit();  if (handle == NULL) {  RETAILMSG(1,(L"H264_Dec_Init Failed./n"));  return 0;  }  /  /// 2. Obtaining the Input Buffer ///  /// (SsbSipH264DecodeGetInBuf) ///  /  pStrmBuf = SsbSipH264DecodeGetInBuf(handle, 204800);  if (pStrmBuf == NULL) {  RETAILMSG(1,(L"SsbSipH264DecodeGetInBuf Failed./n"));  SsbSipH264DecodeDeInit(handle);  return 0;  }    // H264 CONFIG stream extraction //    nFrameLeng = ExtractConfigStreamH264(pFrameExCtx, fp_in, pStrmBuf, INPUT_BUFFER_SIZE, NULL);  RETAILMSG(1,(L"n(1) FrameLeng = %d/n", nFrameLeng));/*  post_rotate = 0x0015;  if (SsbSipH264DecodeSetConfig(handle, H264_DEC_SETCONF_POST_ROTATE, &post_rotate) != SSBSIP_H264_DEC_RET_OK) {  RETAILMSG(1,(L"H.264 Decoder SetConfig failed./n"));  return 0;  }  RETAILMSG(1,(L"/n*** H264_DEC_SETCONF_POST_ROTATE succeeds./n"));*/    /// 3. Configuring the instance with the config stream ///  /// (SsbSipH264DecodeExe) ///    if (SsbSipH264DecodeExe(handle, nFrameLeng) != SSBSIP_H264_DEC_RET_OK) {  RETAILMSG(1,(L"H.264 Decoder Configuration Failed./n"));  return 0;  }  /  /// 4. Get stream information ///  /  SsbSipH264DecodeGetConfig(handle, H264_DEC_GETCONF_STREAMINFO, &stream_info);  RETAILMSG(1,(L"/t<STREAMINFO> width=%d height=%d./n", stream_info.width, stream_info.height));// SsbSipH264DecodeGetConfig(handle, H264_DEC_GETCONF_FRAM_NEED_COUNT, &fram_need_count);// RETAILMSG(1,(L"/t<FRAM_NEED_COUNT> %d./n", fram_need_count));  nFrames = 0;  for (nLoop=0; nLoop < 2000; nLoop++)  {  //  /// 5. DECODE ///  /// (SsbSipH264DecodeExe) ///  //  if (SsbSipH264DecodeExe(handle, nFrameLeng) != SSBSIP_H264_DEC_RET_OK) {  RETAILMSG(1,(L"/t Decode fail./n"));  break;  }  //  /// 6. Obtaining the Output Buffer ///  /// (SsbSipH264DecodeGetOutBuf) ///  //  pYUVBuf = SsbSipH264DecodeGetOutBuf(handle, (long*) &nYUVLeng);  if (pYUVBuf)  printf("pYUVBUF=[0x%08x]/n", pYUVBuf);  else {  printf("pYUVBuf is NULL. nYUVLeng=%d/n", nYUVLeng);  return 0;  }    // if (nLoop < 400)// fwrite(pYUVBuf, 1, (stream_info.width * stream_info.height * 3) >> 1, fp_out);  RETAILMSG(1,(L"/t [%d] decoded./n", nLoop));  /  // Next H.264 VIDEO stream //  /  nFrameLeng = NextFrameH264(pFrameExCtx, fp_in, pStrmBuf, INPUT_BUFFER_SIZE, NULL);  if (nFrameLeng < 4)  break;  *((unsigned int *) pStrmBuf) = 0x32a047b9;  memset((void *) ((unsigned char *)pStrmBuf + nFrameLeng - 10), 0, 20);SsbSipH264DecodeGetConfig(handle, H264_DEC_GETCONF_PHYADDR_FRAM_BUF, phy_add_buf_vals);// RETAILMSG(1, (L"BUF = 0x%X, length = %d, Virtual Addr = 0x%x", phy_add_buf_vals[0], phy_add_buf_vals[1], (unsigned int) pYUVBuf));  }  ///  /// 7. SsbSipH264DecodeDeInit ///  ///  SsbSipH264DecodeDeInit(handle);  RETAILMSG(1,(L"/n/n@@@ Program ends./n"));  fclose(fp_in);  fclose(fp_out);  return 0;}

     

    3 h263dec_test

     

     

    int h263dec_test(char *filename){  void *handle;  SSBSIP_MPEG4_STREAM_INFO stream_info;  FILE *fp_in,*fp_out;  int nLoop, nFrames;  void *pStrmBuf;  int nFrameLeng;  unsigned char *pYUVBuf;  int nYUVLeng;    // Opening Input File //    fp_in = fopen(filename, "rb");  if (fp_in == NULL) {  RETAILMSG(1,(L"File not found/n"));  return 0;  }  /  // Opening Output File //  /  fp_out = fopen("//My Documents//output.yuv","wb");  if (fp_out == NULL) {  RETAILMSG(1,(L"Cannot open the output file./n"));  return 0;  }  //  /// 1. Create new instance ///  /// (SsbSipMPEG4DecodeInit) ///  //  handle = SsbSipMPEG4DecodeInit();  if (handle == NULL) {  RETAILMSG(1,(L"SsbSipMPEG4DecodeInit Failed./n"));  return 0;  }  /  /// 2. Obtaining the Input Buffer ///  /// (SsbSipMPEG4DecodeGetInBuf) ///  /  pStrmBuf = SsbSipMPEG4DecodeGetInBuf(handle, 200000);  if (pStrmBuf == NULL) {  RETAILMSG(1,(L"SsbSipMPEG4DecodeGetInBuf Failed./n"));  SsbSipMPEG4DecodeDeInit(handle);  return 0;  }    // MPEG4 CONFIG stream extraction //    nFrameLeng = ExtractConfigStreamH263(fp_in, pStrmBuf, INPUT_BUFFER_SIZE, NULL);    /// 3. Configuring the instance with the config stream ///  /// (SsbSipMPEG4DecodeExe) ///    if (SsbSipMPEG4DecodeExe(handle, nFrameLeng) != SSBSIP_MPEG4_DEC_RET_OK) {  RETAILMSG(1,(L"MPEG4 Decoder Configuration Failed./n"));  return 0;  }  /  /// 4. Get stream information ///  /  if (SsbSipMPEG4DecodeGetConfig(handle, MPEG4_DEC_GETCONF_STREAMINFO, &stream_info) != SSBSIP_MPEG4_DEC_RET_OK)  return 0;  RETAILMSG(1,(L"/t<STREAMINFO> width=%d height=%d./n", stream_info.width, stream_info.height));  nFrames = 0;  for (nLoop=0; nLoop < 800; nLoop++)  {  ///  /// 5. DECODE ///  /// (SsbSipMPEG4DecodeExe) ///  ///  if (SsbSipMPEG4DecodeExe(handle, nFrameLeng) != SSBSIP_MPEG4_DEC_RET_OK)  break;  //  /// 6. Obtaining the Output Buffer ///  /// (SsbSipMPEG4DecodeGetInBuf) ///  //  pYUVBuf = SsbSipMPEG4DecodeGetOutBuf(handle, &nYUVLeng);  if (pYUVBuf)  printf("pYUVBUF=[0x%08x]/n", pYUVBuf);  else {  printf("pYUVBuf is NULL/n");  return 0;  }// if (nLoop > 10 && nLoop < 30)// fwrite(pYUVBuf, 1, nYUVLeng, fp_out);  RETAILMSG(1,(L"/t [%d] decoded./n", nLoop));  ///  // Next MPEG4 VOP stream //  ///  nFrameLeng = NextFrameH263(fp_in, pStrmBuf, INPUT_BUFFER_SIZE, NULL);  if (nFrameLeng < 4)  break;  }    /// 7. SsbSipMPEG4DecodeDeInit ///    SsbSipMPEG4DecodeDeInit(handle);  RETAILMSG(1,(L"/n/n@@@ Program ends./n"));  fclose(fp_in);  fclose(fp_out);  return 0;}

    最新回复(0)