cancel
Showing results for 
Search instead for 
Did you mean: 

JPEG Codec Decoding Stock!

Charlie CHEN
Associate II

Hi all,

I`m trying to decode jpg with JPEG Codec, and I reference the sample code from CubMX Official code { JPEG_DecodingUsingFs_DMA }, then inserted to my code.

And now it stocks in this function:

do 
 {
      JpegProcessing_End = JPEG_OutputHandler(&JPEG_Handle);
  }while(JpegProcessing_End == 0);

I have checked the SDRAM & HAL_JPEG_MSP setting, and nothing wrong .

By the way, it`s a little similar from :https://community.st.com/s/question/0D50X0000BBqYgrSQF/jpeg-codec-decoding-does-not-endcomplete

, but I use this { JPEG_DecodingUsingFs_DMA } project with SDMMC.

Can anyone help with this?

Thanks!

1 REPLY 1
Charlie CHEN
Associate II

Hi,

I find some problem, if there are someone can help,please remain your suggestions!

Just like what I post on topic, the function { JPEG_OutputHandler } in down below.

When it goes in this function, it always get Jpeg_HWDecodingEnd = 0 , so it will keep doing the do..while function never ending.

uint32_t JPEG_InputHandler(JPEG_HandleTypeDef *hjpeg)
{
  if(Jpeg_HWDecodingEnd == 0)
  {
    if(Jpeg_IN_BufferTab[JPEG_IN_Write_BufferIndex].State == JPEG_BUFFER_EMPTY)
    {
      if(f_read (pFile, Jpeg_IN_BufferTab[JPEG_IN_Write_BufferIndex].DataBuffer , CHUNK_SIZE_IN, (UINT*)(&Jpeg_IN_BufferTab[JPEG_IN_Write_BufferIndex].DataBufferSize)) == FR_OK)
      {  
        Jpeg_IN_BufferTab[JPEG_IN_Write_BufferIndex].State = JPEG_BUFFER_FULL;
      }
      else
      {
        Error_Handler();
      }
      
      if((Input_Is_Paused == 1) && (JPEG_IN_Write_BufferIndex == JPEG_IN_Read_BufferIndex))
      {
        Input_Is_Paused = 0;
        HAL_JPEG_ConfigInputBuffer(hjpeg,Jpeg_IN_BufferTab[JPEG_IN_Read_BufferIndex].DataBuffer, Jpeg_IN_BufferTab[JPEG_IN_Read_BufferIndex].DataBufferSize);    
        
        HAL_JPEG_Resume(hjpeg, JPEG_PAUSE_RESUME_INPUT); 
      }
      
      JPEG_IN_Write_BufferIndex++;
      if(JPEG_IN_Write_BufferIndex >= NB_INPUT_DATA_BUFFERS)
      {
        JPEG_IN_Write_BufferIndex = 0;
      }            
    }
    return 0;
  }
  else
  {
    return 1;
  }
}

​Then I check detail of the project, it can leave this function by :

void HAL_JPEG_DecodeCpltCallback(JPEG_HandleTypeDef *hjpeg)
{    
  Jpeg_HWDecodingEnd = 1; 
}

But it`s something strange, I search HAL_JPEG_DecodeCpltCallback which is called by HAL_JPEG_Init ,there are called by other too but this most associate.

And HAL_JPEG_Init didn`t open that, so how should us use it?

If USE_HAL_JPEG_REGISTER_CALLBACKS == 1 is true, then HAL_JPEG_MspInit won`t be executed and it is wrong method for this project.

#if (USE_HAL_JPEG_REGISTER_CALLBACKS == 1)    --> It didn`t open
  if (hjpeg->State == HAL_JPEG_STATE_RESET)
  {
    /* Allocate lock resource and initialize it */
    hjpeg->Lock = HAL_UNLOCKED;
 
    hjpeg->InfoReadyCallback  = HAL_JPEG_InfoReadyCallback;  /* Legacy weak InfoReadyCallback  */
    hjpeg->EncodeCpltCallback = HAL_JPEG_EncodeCpltCallback; /* Legacy weak EncodeCpltCallback */
    hjpeg->DecodeCpltCallback = HAL_JPEG_DecodeCpltCallback; /* Legacy weak DecodeCpltCallback */
    hjpeg->ErrorCallback      = HAL_JPEG_ErrorCallback;      /* Legacy weak ErrorCallback      */
    hjpeg->GetDataCallback    = HAL_JPEG_GetDataCallback;    /* Legacy weak GetDataCallback    */
    hjpeg->DataReadyCallback  = HAL_JPEG_DataReadyCallback;  /* Legacy weak DataReadyCallback  */
 
    if (hjpeg->MspInitCallback == NULL)
    {
      hjpeg->MspInitCallback = HAL_JPEG_MspInit; /* Legacy weak MspInit  */
    }
 
    /* Init the low level hardware */
    hjpeg->MspInitCallback(hjpeg);
  }
#else
  if (hjpeg->State == HAL_JPEG_STATE_RESET)
  {
    /* Allocate lock resource and initialize it */
    hjpeg->Lock = HAL_UNLOCKED;
 
    /* Init the low level hardware : GPIO, CLOCK */
    HAL_JPEG_MspInit(hjpeg);
  }
#endif /* USE_HAL_JPEG_REGISTER_CALLBACKS */

​It is what I want to share my question, and I`ll keep research it.

Hope someone can really help!

Thanks!