This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

after snap some jpeg files, ALG_vidEncRun will be blocked

We need to snap video data to jpeg not YUV format,  and save it to storage。

we have change ALG_vidEncRun as below:

int ALG_vidEncRun(void *hndl, ALG_VidEncRunPrm *prm, ALG_VidEncRunStatus *runStatus)
{
  ALG_VidEncObj *pObj = (ALG_VidEncObj*)hndl;
  IVIDEO1_BufDescIn  inBufDesc;
  XDM_BufDesc        outBufDesc;
  XDAS_Int32         status;
  VIDENC1_InArgs     inArgs;
  VIDENC1_OutArgs    outArgs;
  IH264VENC_InArgs   h264InArgs;
  IH264VENC_OutArgs  h264OutArgs;
  XDAS_Int32         offset;
  XDAS_Int32         outBufSizeArray[2];
  XDAS_UInt8         *dst[2],i=0;
  static unsigned long h264Timestamp = 0;

  runStatus->bytesGenerated = 0;
  runStatus->isKeyFrame     = FALSE;
  runStatus->numMB          = 0;

  if(pObj==NULL)
    return OSA_EFAIL;

  if(pObj->createPrm.codec==ALG_VID_CODEC_MJPEG)
  {
    ALG_JpgEncRunPrm jpgRun;
    ALG_JpgEncRunStatus jpgStatus;

    jpgRun.inStartX = prm->inStartX;
    jpgRun.inStartY = prm->inStartY;
    jpgRun.inAddr   = prm->inAddr;
    jpgRun.outAddr  = prm->outAddr;
    jpgRun.outDataMaxSize = prm->outDataMaxSize;

    jpgRun.snapEnable = prm->snapEnable;
 strcpy(jpgRun.snapFilename, prm->snapFilename);

 OSA_mutexLock(&vnf_imcop_lock);
 OSA_mutexLock(&vicp_imcop_lock);

    status = ALG_jpgEncRun(pObj->hJpgEncode, &jpgRun, &jpgStatus);

 OSA_mutexUnlock(&vnf_imcop_lock);
 OSA_mutexUnlock(&vicp_imcop_lock);

    runStatus->isKeyFrame     = TRUE;

    if(status!=OSA_SOK) {

      return OSA_EFAIL;
    }

    runStatus->bytesGenerated = jpgStatus.bytesGenerated;

    return OSA_SOK;
  }

  offset = pObj->createPrm.offsetH * pObj->createPrm.offsetV;

  if(prm->outDataMaxSize==0)
    prm->outDataMaxSize = pObj->createPrm.width*pObj->createPrm.height*2;

  outBufSizeArray[0] = prm->outDataMaxSize;

  prm->inStartY = OSA_floor(prm->inStartY, 2);
  prm->inStartX = OSA_floor(prm->inStartX, 2);

  inBufDesc.numBufs       = 2;
  inBufDesc.frameWidth    = OSA_align(pObj->createPrm.width, 16);
  inBufDesc.frameHeight   = OSA_align(pObj->createPrm.height, 16);
  inBufDesc.framePitch    = pObj->createPrm.offsetH;

  inBufDesc.bufDesc[0].bufSize = pObj->createPrm.offsetH*inBufDesc.frameHeight ;
  inBufDesc.bufDesc[0].buf     = (XDAS_Int8*)(prm->inAddr + prm->inStartY*pObj->createPrm.offsetH + prm->inStartX);
  inBufDesc.bufDesc[0].accessMask = 0;

  inBufDesc.bufDesc[1].bufSize = pObj->createPrm.offsetH*inBufDesc.frameHeight/2;
  inBufDesc.bufDesc[1].buf     = (XDAS_Int8*)(prm->inAddr + offset + prm->inStartY*pObj->createPrm.offsetH/2 + prm->inStartX);
  inBufDesc.bufDesc[1].accessMask = 0;

#if 0
  if(prm->snapEnable) {
   OSA_fileWriteVideoData(prm->snapFilename, (Uint8 *)inBufDesc.bufDesc[0].buf, (Uint8 *)inBufDesc.bufDesc[1].buf,
    inBufDesc.frameWidth, inBufDesc.frameHeight, inBufDesc.framePitch);
  }
#else //added by jonnyling 20110315
 if(prm->snapEnable)
 {
  ALG_JpgEncCreate jpgCreatePram;
  
  jpgCreatePram.dataFormat  = pObj->createPrm.dataFormat;
  //jpgCreatePram.encDataFormat = ALG_VID_DATA_FORMAT_YUV422;
  jpgCreatePram.encDataFormat = ALG_VID_DATA_FORMAT_YUV420;
  jpgCreatePram.width   = pObj->createPrm.width;
  jpgCreatePram.height   = pObj->createPrm.height;
  jpgCreatePram.offsetH   = pObj->createPrm.offsetH;
  jpgCreatePram.offsetV   = pObj->createPrm.offsetV;
  jpgCreatePram.qValue  = 90;
  
  void *pJpgEnc = ALG_jpgEncCreate(&jpgCreatePram);
  if(pJpgEnc == NULL)
  {
   OSA_printf("ALG_jpgEncCreate for snap FAILED!\n");
  }
  else
  {
   ALG_JpgEncRunPrm  jpgRun;
   ALG_JpgEncRunStatus jpgStatus;
   
   jpgRun.inStartX = prm->inStartX;
   jpgRun.inStartY = prm->inStartY;
   jpgRun.inAddr = prm->inAddr;
   jpgRun.outAddr = prm->outAddr;
   jpgRun.outDataMaxSize = prm->outDataMaxSize;
   
   jpgRun.snapEnable = FALSE;;
   strcpy(jpgRun.snapFilename, "");
   
   OSA_mutexLock(&vnf_imcop_lock);
   OSA_mutexLock(&vicp_imcop_lock);
   
   status = ALG_jpgEncRun(pJpgEnc, &jpgRun, &jpgStatus);
   
   OSA_mutexUnlock(&vnf_imcop_lock);
   OSA_mutexUnlock(&vicp_imcop_lock);

     if(status == OSA_SOK)
   {
    OSA_printf("snap jpeg file ok, file: %s, size: %d\n",
     prm->snapFilename,jpgStatus.bytesGenerated);
    
    OSA_fileWriteFile(prm->snapFilename,
     jpgRun.outAddr, jpgStatus.bytesGenerated);
     }
   else
   {
    OSA_printf("snap jpeg file failed, file: %s\n",
     prm->snapFilename);
   }

   ALG_jpgEncDelete(pJpgEnc);
  }
 } 
#endif

...

We also have set h264 paramters like below:

 pObj->params_h264.enableARM926Tcm  = 1;//h264 does not use VICP resource at all
 pObj->params_h264.enableDDRbuff    = 1;//h264 does not use VICP resource at all

Can anybody help?

DVSDK component version:

/mnt/sda5/opt/dvsdk_2_10_01_18/framework_components_2_25_00_04

/mnt/sda5/opt/dvsdk_2_10_01_18/linuxutils_2_24_03

/mnt/sda5/opt/dvsdk_2_10_01_18/xdctools_3_15_01_59

Codec version:

H264ENC.version.02.10.00.06.wizardversion.0.5.2

JPEGENC.version.01.00.00.09.wizardversion.0.5.2

 

 

  • Jonny,

    What is the problem here ? It is not clear. Seems you are trying to do something with Jpeg and H.264.

    regards

    Yashwant

  • Hi Yashwant,

    We need to capture video to jpg file while h264enc running.

    The capture is triggered by some other signals  the frequency is very low, for example, capture one jpg picture every 3 seconds.

    the original ALG_vidEnc supports snapping  YUV data to file, but we need to encode YUV data to jpg file, that is what we need to do, so we change the code as you can see.

    the changed code works fine, that is, we can get the jpg files we needed, but some time later it will be blocked, and ALG_vidEncRun will not return, we think this is a resource problem,  such as edma we guess.

    you can try our code for your test, and check if this happen or not.

    we have coutered another problem before when we use DMAI interface to handle video dat, if we use FrameCopy by using edma to move data, it will be blocked after some uncertain time, we have work around this by using memcpy instead of FrameCopy, but we guess the edma driver may have some problem of DM365 platform.

    thank you.

    regards,

    Johnny

  • Jonny,

    Can you try the below at your end and let is know -

    1. After how much time the lock up happens ?

    1. Does the Jpeg hang if you run it for every frame ?(along with H.264)

    2. Have you tried creating the jpeg only once and then calling only the encode call at the given periodiicty.

     

    In our application(TI IPNC ref design), we run Jpeg and H.264 together at varying frame rate, and it works fine for long.

    regards

    Yashwant