📄 video_enc_isr.c
字号:
void video_enc_fr_evalutaion_init(void)
{
FR_STRUCT *fs_rate = (FR_STRUCT *)&g_video_enc_info_ptr->rc_data.fr_rate;
if ( (video_is_start_record == VIDEO_ENC_START_RECORD_STATE_START) ||
(video_is_start_record == VIDEO_ENC_START_RECORD_STATE_RESUME_START) )
{
fs_rate->time_stamp_index = 0;
fs_rate->buffer_frame_num = 0;
fs_rate->avg_frame_duration = 0;
fs_rate->time_stamp[fs_rate->time_stamp_index] = video_get_current_time();
fs_rate->time_stamp_index = (fs_rate->time_stamp_index+1)&3;
fs_rate->frame_rate = 15;
fs_rate->run_done = KAL_TRUE;
}
}
void video_enc_fr_evalutaion(void)
{
FR_STRUCT *fs_rate = (FR_STRUCT *)&g_video_enc_info_ptr->rc_data.fr_rate;
kal_uint32 time_duration_temp;
if ((video_is_start_record == VIDEO_ENC_START_RECORD_STATE_START)
|| (video_is_start_record == VIDEO_ENC_START_RECORD_STATE_RESUME_START))
{
fs_rate->time_stamp_index = 0;
fs_rate->buffer_frame_num = 0;
fs_rate->avg_frame_duration = 0;
fs_rate->time_stamp[fs_rate->time_stamp_index] = video_get_current_time();
fs_rate->time_stamp_index = (fs_rate->time_stamp_index + 1) & 3;
fs_rate->frame_rate = 15;
}
else
{
if (fs_rate->run_done == KAL_FALSE)
{
fs_rate->time_stamp[fs_rate->time_stamp_index] = video_get_current_time();
time_duration_temp = video_get_duration_tick(fs_rate->time_stamp[(fs_rate->time_stamp_index - 1) & 3],
fs_rate->time_stamp[fs_rate->time_stamp_index]);
if (video_assert_check)
{
ASSERT(time_duration_temp < 32000);
}
fs_rate->time_stamp_index = (fs_rate->time_stamp_index + 1) & 3;
fs_rate->avg_frame_duration = (fs_rate->avg_frame_duration * fs_rate->buffer_frame_num + time_duration_temp)
/ (fs_rate->buffer_frame_num + 1);
if (fs_rate->buffer_frame_num < 7)
fs_rate->buffer_frame_num++;
fs_rate->frame_rate = 32768 / fs_rate->avg_frame_duration;
if ((32768 % fs_rate->avg_frame_duration) > (fs_rate->avg_frame_duration / 2))
{
fs_rate->frame_rate = fs_rate->frame_rate + 1;
}
}
else
{
fs_rate->run_done = KAL_FALSE;
}
}
}
kal_bool video_enc_check_buffer(void)
{
if (g_video_enc_info_ptr->is_need_to_check_buffer)
{
g_video_enc_info_ptr->lost_frames++;
if (video_enc_get_buffer_status(g_video_enc_info_ptr))
{
g_video_enc_info_ptr->is_need_to_check_buffer = KAL_FALSE;
g_video_enc_info_ptr->force_I_frame = KAL_TRUE;
g_video_enc_info_ptr->chk_buffer_status_count = 0;
if (g_video_enc_info_ptr->switch_buffer_callback)
g_video_enc_info_ptr->switch_buffer_callback();
}
else
{
g_video_enc_info_ptr->chk_buffer_status_count++;
if (g_video_enc_info_ptr->chk_buffer_status_count > 50)
{
VIDEO_ASSERT(0);
g_video_enc_info_ptr->encode_stop = KAL_TRUE;
g_video_enc_status.VIDEO_STATUS = VIDEO_ENC_FATAL_ERROR;
#if ( defined(MT6219) || defined(MT6226) || defined(MT6227) || defined(MT6226M) )
IRQMask(IRQ_MPEG4_CODE);
#else /*!(MT6219, MT6226, MT6227, MT6226M)*/
IRQMask(IRQ_MPEG4_ENC_CODE);
#endif /*(MT6219, MT6226, MT6227, MT6226M)*/
VISUAL_Register_HISR(VISUAL_MPEG4_ENC_HISR_ID, MPEG4_ENC_ERROR_REPORT_HISR);
visual_active_hisr(VISUAL_MPEG4_ENC_HISR_ID);
return KAL_FALSE;
}
}
return KAL_FALSE;
}
return KAL_TRUE;
}
kal_bool video_enc_check_frame_with_cam_video(void)
{
if (g_video_enc_info_ptr->total_frames != g_video_enc_info_ptr->hisr_total_frames)
{
video_dbg_trace(MP4_ENC_DMA_LISR_FRAMEQUICK, video_get_current_time());
g_video_enc_info_ptr->safty_check_count++;
if (g_video_enc_info_ptr->safty_check_count >= 3)
{
VIDEO_ASSERT(0);
g_video_enc_info_ptr->encode_stop = KAL_TRUE;
g_video_enc_status.VIDEO_STATUS = VIDEO_ENC_FATAL_ERROR;
#if ( defined(MT6219) || defined(MT6226) || defined(MT6227) || defined(MT6226M) )
IRQMask(IRQ_MPEG4_CODE);
#else /*!(MT6219, MT6226, MT6227, MT6226M)*/
IRQMask(IRQ_MPEG4_ENC_CODE);
#endif /*(MT6219, MT6226, MT6227, MT6226M)*/
VISUAL_Register_HISR(VISUAL_MPEG4_ENC_HISR_ID, MPEG4_ENC_ERROR_REPORT_HISR);
visual_active_hisr(VISUAL_MPEG4_ENC_HISR_ID);
return KAL_FALSE;
}
// g_video_enc_info_ptr->lost_frames++;
return KAL_FALSE;
}
g_video_enc_info_ptr->safty_check_count = 0;
return KAL_TRUE;
}
kal_bool video_enc_check_encode_state(void)
{
if (g_video_enc_info_ptr->encode_stop == KAL_TRUE)
return KAL_FALSE;
#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
if (g_video_enc_info_ptr->large_quant_count != 0)
{
g_video_enc_info_ptr->large_quant_count = 0;
return KAL_FALSE;
}
return KAL_TRUE;
}
void video_enc_lisr_process(kal_uint32 encode_work_yuv, kal_uint32 time_stamp, kal_uint32 delay_offset)
{
kal_uint32 length;
MEDIA_STATUS_CODE result;
MP4ENC_PROC_STRUCT mp4enc_proc_input;
video_dbg_trace(MP4_ENC_DMA_LISR_ENTRY1, video_get_current_time());
if (video_enc_check_encode_state() == KAL_FALSE)
return;
if (video_enc_check_buffer() == KAL_FALSE)
return;
if (video_enc_check_frame_with_cam_video() == KAL_FALSE)
return;
#if defined(__VIDEO_EDITOR__)
if ((video_is_start_record != VIDEO_ENC_START_RECORD_STATE_RESUME_START)
|| (g_video_enc_status.scenario == VIDEO_SCENARIO_EDITOR))
#else /*!__VIDEO_EDITOR__*/
if (video_is_start_record != VIDEO_ENC_START_RECORD_STATE_RESUME_START)
#endif /*__VIDEO_EDITOR__*/
{
video_is_start_record = VIDEO_ENC_START_RECORD_STATE_RUNING;
if (g_video_enc_info_ptr->total_frames != 0)
{
VIDEO_ASSERT(time_stamp >= delay_offset);
g_video_enc_info_ptr->time_stamp = time_stamp - delay_offset;
}
else
{
#ifdef __VIDEO_EDITOR__
if (g_video_enc_status.scenario == VIDEO_SCENARIO_EDITOR)
{
VIDEO_ASSERT(time_stamp >= delay_offset);
g_video_enc_info_ptr->time_stamp = time_stamp - delay_offset;
}
else
#endif /*__VIDEO_EDITOR__*/
{
g_video_enc_info_ptr->time_stamp = 0;
g_video_enc_info_ptr->const_delay = Media_A2V_GetAudioRecordDelay(video_enc_audio_format);
}
}
}
else
{
video_is_start_record = VIDEO_ENC_START_RECORD_STATE_START;
return;
}
video_dbg_trace(MP4_ENC_DMA_LISR_ENTRY, video_get_current_time());
#ifdef __L1_STANDALONE__
#ifndef __VIDEO_EDITOR__
if (((g_video_enc_info_ptr->total_frames != TOTAL_frame_num) && (video_next == KAL_FALSE))
|| ((video_next == KAL_TRUE) && (g_video_enc_info_ptr->total_frames != (TOTAL_frame_num * 2)))) //Jensen
#endif /*__VIDEO_EDITOR__*/
#endif /*__L1_STANDALONE__*/
{
g_video_enc_info_ptr->current_bitstream_addr = video_enc_buffer_get_memaddr(g_video_enc_info_ptr);
length = video_enc_buffer_get_roomleft(g_video_enc_info_ptr);
if (length == 0)
{
if (video_enc_switch_buffer(g_video_enc_info_ptr))
{
ASSERT(g_video_enc_info_ptr->video_enc_callback != NULL);
if (g_video_enc_info_ptr->is_task_prepare_video_data == KAL_FALSE)
{
video_enc_isr_send_avail_ilm();
}
g_video_enc_info_ptr->current_bitstream_addr = video_enc_buffer_get_memaddr(g_video_enc_info_ptr);
length = video_enc_buffer_get_roomleft(g_video_enc_info_ptr);
}
else
{
g_video_enc_info_ptr->is_need_to_check_buffer = KAL_TRUE;
g_video_enc_info_ptr->switch_buffer_callback = NULL;
g_video_enc_info_ptr->lost_frames++;
return;
}
}
#if defined(__VIDEO_EDITOR__)
if (g_video_dec_status.scenario != VIDEO_SCENARIO_EDITOR)
#endif /*__VIDEO_EDITOR__*/
{
video_enc_fr_evalutaion();
}
mp4enc_proc_input.frame = g_video_enc_info_ptr->total_frames;
mp4enc_proc_input.input_yuv_data = (kal_uint8 *)encode_work_yuv;
mp4enc_proc_input.bitstreams_ptr = (kal_uint8 *)g_video_enc_info_ptr->current_bitstream_addr;
mp4enc_proc_input.buffer_length = length;
mp4enc_proc_input.im = &g_video_enc_info_ptr->im;
result = video_enc_proc(&mp4enc_proc_input);
if (result != MEDIA_STATUS_OK)
{
VIDEO_ASSERT(0);
g_video_enc_info_ptr->encode_stop = KAL_TRUE;
g_video_enc_status.VIDEO_STATUS = VIDEO_ENC_FATAL_ERROR;
#if ( defined(MT6219) || defined(MT6226) || defined(MT6227) || defined(MT6226M) )
IRQMask(IRQ_MPEG4_CODE);
#else /*!(MT6219, MT6226, MT6227, MT6226M)*/
IRQMask(IRQ_MPEG4_ENC_CODE);
#endif /*(MT6219, MT6226, MT6227, MT6226M)*/
VISUAL_Register_HISR(VISUAL_MPEG4_ENC_HISR_ID, MPEG4_ENC_ERROR_REPORT_HISR);
visual_active_hisr(VISUAL_MPEG4_ENC_HISR_ID);
return;
}
g_video_enc_info_ptr->total_frames++;
video_dbg_trace(MP4_ENC_DMA_LISR_END, video_get_current_time());
}
}
void video_enc_dma_lisr(kal_uint32 encode_work_yuv)
{
kal_uint32 time_stamp;
kal_uint32 delay_offset;
if (g_video_enc_info_ptr->encode_stop == KAL_TRUE)
return;
#ifdef __VIDEO_GET_YUV_DATA__
if ((((video_yuv.write_index + 1) & 7) != video_yuv.read_index) && (video_yuv.enable_log == KAL_TRUE))
{
if (video_yuv.cif_size == 1)
{
kal_mem_cpy(video_yuv.yuvdata.yuvCIF[video_yuv.write_index], (void *)encode_work_yuv,
(g_video_enc_info_ptr->im.width * g_video_enc_info_ptr->im.height * 3 / 2));
}
else
{
kal_mem_cpy(video_yuv.yuvdata.yuvQCIF[video_yuv.write_index], (void *)encode_work_yuv,
(g_video_enc_info_ptr->im.width * g_video_enc_info_ptr->im.height * 3 / 2));
}
video_yuv.write_index++;
video_yuv.write_index = video_yuv.write_index % video_yuv.yuv_max_buffer_count;
visual_active_hisr(VISUAL_MPEG4_ENC_HISR_ID);
}
else
{
video_yuv.enable_log = KAL_FALSE;
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -