📄 img_msg_handler.c
字号:
if (dec_ret == JPEG_DECODE_DECODING)
{
img_context_p->processing = KAL_TRUE;
med_start_timer(IMAGE_CODEC_RETRY_TIMER, waiting_time, img_codec_retry_handler, 0);
}
else
{
img_context_p->file_buffer_address = NULL;
img_release_memory();
result = img_get_decode_res(dec_ret);
if (!img_context_p->blocking)
{
img_send_decode_finish_ind(result, img_context_p->seq_num);
}
else
{
img_set_result(result);
IMG_SET_EVENT(IMG_EVT_DECODE);
}
IMG_ENTER_STATE(IMG_IDLE);
}
}
else
#endif /* JPG_DECODE */
{
img_context_p->file_buffer_address = NULL;
img_release_memory();
if (!img_context_p->blocking)
{
img_send_decode_finish_ind(MED_RES_INVALID_FORMAT, img_context_p->seq_num);
}
else
{
img_set_result(MED_RES_INVALID_FORMAT);
IMG_SET_EVENT(IMG_EVT_DECODE);
}
IMG_ENTER_STATE(IMG_IDLE);
}
}
else /* MED_MODE_STREAM */
{
ASSERT(img_context_p->media_mode != MED_MODE_STREAM);
}
}
/*****************************************************************************
* FUNCTION
* img_codec_retry_handler
* DESCRIPTION
* This function is to handle image codec timeout.
* PARAMETERS
* arg [?]
* kal_uint8 cause(?)
* RETURNS
* void
*****************************************************************************/
void img_codec_retry_handler(void *arg)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (IMG_IN_STATE(IMG_JPG_DECODE))
{
#ifdef JPG_DECODE
if (img_context_p->has_retried == TRUE || (img_context_p->jpeg_retry_thumbnail==FALSE))
{
if (!img_context_p->processing)
{
return; /* means the call back happened but ind msg is in queue */
}
kal_prompt_trace(MOD_MED, "[MED_IMG] stop_jpeg_decode_process:1");
stop_jpeg_decode_process();
img_context_p->processing = KAL_FALSE;
/* decode fail, hardware issue */
if (img_context_p->media_mode == MED_MODE_ARRAY)
{
img_context_p->file_buffer_address = NULL;
}
img_release_memory();
if (!img_context_p->blocking)
{
img_send_decode_finish_ind(MED_RES_INVALID_FORMAT, img_context_p->seq_num);
}
else
{
img_set_result(MED_RES_IMG_DECODE_TIME_OUT);
IMG_SET_EVENT(IMG_EVT_DECODE);
}
IMG_ENTER_STATE(IMG_IDLE);
}
else
{
/* timeout, then try to decode thumbnail */
kal_uint8 dec_ret = JPEG_DECODE_UNSUPPORT_FORMAT;
kal_uint32 waiting_time;
img_context_p->has_retried = TRUE;
jpg_decode.jpeg_decode_retry_flag = JPEG_DECODER_RETRY_THUMBNAIL;
#ifdef BEREMOVED
img_context_p->image_buffer_address1 = (kal_uint32) med_alloc_ext_mem(img_context_p->image_buffer_size);
#endif
kal_prompt_trace(MOD_MED, "[MED_IMG] stop_jpeg_decode_process:2");
/* stop jpeg decode process */
stop_jpeg_decode_process();
/* allocate another buffer for thumbnail */
#ifdef BEREMOVED
if (img_context_p->image_buffer_address1 == NULL)
{
img_context_p->processing = KAL_FALSE;
/* decode fail, hardware issue */
if (img_context_p->media_mode == MED_MODE_ARRAY)
{
img_context_p->file_buffer_address = NULL;
}
img_release_memory();
if (!img_context_p->blocking)
{
img_send_decode_finish_ind(MED_RES_INVALID_FORMAT, img_context_p->seq_num);
}
else
{
img_set_result(MED_RES_IMG_DECODE_TIME_OUT);
IMG_SET_EVENT(IMG_EVT_DECODE);
}
IMG_ENTER_STATE(IMG_IDLE);
}
else
#endif
{
/* if there is enough memory to decode thumbnail */
img_context_p->prev_result = MED_RES_IMG_DECODE_TIME_OUT;
img_context_p->has_retried = TRUE;
if (img_context_p->blocking)
{
waiting_time = IMG_CODEC_BLOCK_WAITING_TIME;
}
else
{
waiting_time = IMG_CODEC_RETRY_TIME * ((img_context_p->file_size >> IMG_DECODE_FILE_UNIT) + 1);
}
#ifdef __MTK_TARGET__
dec_ret = jpeg_decode_process(&jpg_decode);
#endif
if (dec_ret == JPEG_DECODE_DECODING)
{
img_context_p->processing = KAL_TRUE;
img_context_p->retry_conut = 0;
med_start_timer(IMAGE_CODEC_RETRY_TIMER, waiting_time, img_codec_retry_handler, 0);
IMG_ENTER_STATE(IMG_JPG_DECODE);
}
else
{
if (dec_ret == JPEG_DECODE_SUCCESS)
{
/* copy to the destination buffer */
//memcpy((kal_uint8 *)img_context_p->image_buffer_address,
// (kal_uint8 *)img_context_p->image_buffer_address1,
// img_context_p->image_buffer_size);
img_set_result(MED_RES_OK);
}
else
{
img_set_result(MED_RES_IMG_DECODE_TIME_OUT);
}
if (img_context_p->media_mode == MED_MODE_ARRAY)
{
img_context_p->file_buffer_address = NULL;
}
img_release_memory();
img_set_decoded_width(img_context_p->image_width);
IMG_SET_EVENT(IMG_EVT_DECODE);
IMG_ENTER_STATE(IMG_IDLE);
}
}
}
#endif /* JPG_DECODE */
}
}
/*****************************************************************************
* FUNCTION
* img_decode_event_ind_hdlr
* DESCRIPTION
* This function is the event handler for decoding.
* PARAMETERS
* ilm_ptr [?]
* RETURNS
* void
*****************************************************************************/
void img_decode_event_ind_hdlr(ilm_struct *ilm_ptr)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
media_img_decode_event_ind_struct *ind_p;
kal_int16 result = MED_RES_FAIL;
kal_bool is_finish = KAL_FALSE;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
ind_p = (media_img_decode_event_ind_struct*) ilm_ptr->local_para_ptr;
kal_prompt_trace(MOD_MED, "[MED_IMG] decode event ind: %d", ind_p->cause);
if (IMG_IN_STATE(IMG_JPG_DECODE))
{
#ifdef JPG_DECODE
if ((kal_uint8) ind_p->cause == JPEG_DECODE_DECODING)
{
img_context_p->processing = KAL_TRUE;
decode_jpeg_next_block();
}
else if ((kal_uint8) ind_p->cause == JPEG_DECODE_DECODER_OVERFLOW_FAIL && img_context_p->has_retried == FALSE)
{
kal_uint8 dec_ret = JPEG_DECODE_UNSUPPORT_FORMAT;
kal_uint32 waiting_time;
kal_prompt_trace(MOD_MED, "[MED_IMG] HW issue, retry ");
med_stop_timer(IMAGE_CODEC_RETRY_TIMER);
/* HW issues: retry to decode thumbnail */
jpg_decode.jpeg_decode_retry_flag = JPEG_DECODER_RETRY_THUMBNAIL;
#ifdef BEREMOVED
img_context_p->image_buffer_address1 = (kal_uint32) med_alloc_ext_mem(img_context_p->image_buffer_size);
#endif
kal_prompt_trace(MOD_MED, "[MED_IMG] stop_jpeg_decode_process:3");
stop_jpeg_decode_process();
#ifdef BEREMOVED
if (img_context_p->image_buffer_address1 == NULL)
{
kal_prompt_trace(MOD_MED, "[MED_IMG] HW issue, do not retry");
IMG_ENTER_STATE(IMG_IDLE);
if (img_context_p->media_mode == MED_MODE_ARRAY)
{
img_context_p->file_buffer_address = NULL;
}
img_release_memory();
result = img_get_decode_res((kal_uint8) ind_p->cause);
img_set_decoded_width(img_context_p->image_width);
is_finish = KAL_TRUE;
}
else
#endif
{
/* if there is enough memory to decode thumbnail */
img_context_p->prev_result = img_get_decode_res((kal_uint8) ind_p->cause);
img_context_p->has_retried = TRUE;
if (img_context_p->blocking)
{
waiting_time = IMG_CODEC_BLOCK_WAITING_TIME;
}
else
{
waiting_time = IMG_CODEC_RETRY_TIME * ((img_context_p->file_size >> IMG_DECODE_FILE_UNIT) + 1);
}
#ifdef __MTK_TARGET__
dec_ret = jpeg_decode_process(&jpg_decode);
#endif
if (dec_ret == JPEG_DECODE_DECODING)
{
img_context_p->processing = KAL_TRUE;
img_context_p->retry_conut = 0;
med_start_timer(IMAGE_CODEC_RETRY_TIMER, waiting_time, img_codec_retry_handler, 0);
IMG_ENTER_STATE(IMG_JPG_DECODE);
}
else
{
if (dec_ret == JPEG_DECODE_SUCCESS)
{
result = img_get_decode_res(dec_ret);
/* copy to the destination buffer */
//memcpy((kal_uint8 *)img_context_p->image_buffer_address,
// (kal_uint8 *)img_context_p->image_buffer_address1,
// img_context_p->image_buffer_size);
}
else
{
result = img_context_p->prev_result;
}
if (img_context_p->media_mode == MED_MODE_ARRAY)
{
img_context_p->file_buffer_address = NULL;
}
IMG_ENTER_STATE(IMG_IDLE);
img_release_memory();
img_set_decoded_width(img_context_p->image_width);
is_finish = KAL_TRUE;
}
}
}
else
{
med_stop_timer(IMAGE_CODEC_RETRY_TIMER);
kal_prompt_trace(MOD_MED, "[MED_IMG] stop_jpeg_decode_process:4");
stop_jpeg_decode_process();
IMG_ENTER_STATE(IMG_IDLE);
if (img_context_p->media_mode == MED_MODE_ARRAY)
{
img_context_p->file_buffer_address = NULL;
}
img_release_memory();
result = img_get_decode_res((kal_uint8) ind_p->cause);
img_set_decoded_width(img_context_p->image_width);
is_finish = KAL_TRUE;
}
#endif /* JPG_DECODE */
}
#if defined(USE_HW_GIF_DECODER_V2)
else if (IMG_IN_STATE(IMG_GIF_V2_DECODE))
{
if (ind_p->cause == GIF_STATUS_INEMPTY)
{
gif_report_status_enum status;
status = gif_decode_resume(&img_context_gif_config, img_context_gif_info);
if (status != GIF_DECODING)
{
result = MED_RES_FAIL;
is_finish = KAL_TRUE;
}
}
else if (ind_p->cause == GIF_STATUS_COMPLETE)
{
if (img_context_gif_config.frame_number > ind_p->arg0) /* still need decode next frame */
{
if (gif_decode_resume(&img_context_gif_config, img_context_gif_info) != GIF_DECODING)
{
result = MED_RES_FAIL;
is_finish = KAL_TRUE;
}
}
else /* reach target frame */
{
result = MED_RES_OK;
is_finish = KAL_TRUE;
}
}
else /* decode fail */
{
gif_decode_stop();
result = MED_RES_FAIL;
is_finish = KAL_TRUE;
}
if (is_finish) /* gif finializer */
{
S32 resz_w = (S32) img_context_gif_info->resz_w;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -