📄 video_editor.c
字号:
return MP4_PARSER_ERROR;
}
/*Video decorder initialize*/
ASSERT(g_video_dec_status.running == KAL_FALSE);
ASSERT(g_video_enc_status.running == KAL_FALSE);
/*Decode initialize*/
video_dec_input.pstMp4Parser = veditor_struct->pstVIDParser;
video_dec_input.pstFSAL = veditor_struct->pstVIDFSAL;
video_dec_input.start_frame_no = 0xff; /*Don't care*/
video_dec_input.video_dec_callback = veditor_struct->call_back;
result = video_decoder_initialize(&video_dec_input, VIDEO_EDITOR_MAX_FRAME_WIDTH, VIDEO_EDITOR_MAX_FRAME_HEIGHT);
if (result != MEDIA_STATUS_OK)
{
VIDEO_ASSERT(0);
return result;
}
VIDEO_EDITOR_DATA.decode_frame_width = g_video_dec_info_ptr->width;
VIDEO_EDITOR_DATA.decode_frame_height = g_video_dec_info_ptr->height;
VIDEO_EDITOR_DATA.encode_frame_width = veditor_struct->encode_frame_width;
VIDEO_EDITOR_DATA.encode_frame_height = veditor_struct->encode_frame_height;
VIDEO_EDITOR_DATA.bit_rate = veditor_struct->bit_rate;
VIDEO_EDITOR_DATA.short_header = veditor_struct->short_header;
video_enc_input.short_header = veditor_struct->short_header;
video_enc_input.bit_rate = veditor_struct->bit_rate;
video_enc_input.frame_width = veditor_struct->encode_frame_width;
video_enc_input.frame_height = veditor_struct->encode_frame_height;
video_enc_input.call_back = veditor_struct->call_back;
/*Encode initialize*/
result = video_encode_comm_setup(&video_enc_input);
if (result != MEDIA_STATUS_OK)
{
VIDEO_ASSERT(0);
return result;
}
/*Obtain AV sync info*/
result = video_editor_avsync_info(veditor_struct->need_avsync,
veditor_struct->video_start_time,
veditor_struct->audio_start_time,
veditor_struct->av_duration,
audio_avsync,
current_video_frame_no);
if (result != MEDIA_STATUS_OK)
{
VIDEO_ASSERT(0);
return result;
}
VIDEO_EDITOR_DATA.veditor_state = VIEDO_EDITOR_STATE_OPEN;
g_video_enc_info_ptr->total_frames = 0;
g_video_enc_info_ptr->hisr_total_frames = 0;
return MEDIA_STATUS_OK;
}
MEDIA_STATUS_CODE video_editor_open_next(VIDEO_EDITOR_OPEN_NEXT_STRUCT *veditor_struct, VEDITOR_AVSYNC_AUDIO_STRUCT *audio_avsync, kal_uint32 *current_video_frame_no)
{
MEDIA_STATUS_CODE result;
MP4ENC_SETUP_STRUCT video_enc_input;
MP4DEC_INIT_STRUCT video_dec_input;
ASSERT(VIDEO_EDITOR_DATA.veditor_state == VIEDO_EDITOR_STATE_IDLE);
g_video_dec_status.scenario = VIDEO_SCENARIO_EDITOR;
g_video_enc_status.scenario = VIDEO_SCENARIO_EDITOR;
VIDEO_EDITOR_DATA.pstVIDParser = veditor_struct->pstVIDParser;
VIDEO_EDITOR_DATA.pstVIDFSAL = veditor_struct->pstVIDFSAL;
VIDEO_EDITOR_DATA.pstAUDParser = veditor_struct->pstAUDParser;
VIDEO_EDITOR_DATA.pstAUDFSAL = veditor_struct->pstAUDFSAL;
VIDEO_EDITOR_DATA.call_by_next = KAL_TRUE;
VIDEO_EDITOR_DATA.call_back = veditor_struct->call_back;
VIDEO_EDITOR_DATA.need_avsync = veditor_struct->need_avsync;
VIDEO_EDITOR_DATA.video_start_time = veditor_struct->video_start_time;
VIDEO_EDITOR_DATA.audio_start_time = veditor_struct->audio_start_time;
VIDEO_EDITOR_DATA.av_duration = veditor_struct->av_duration;
VIDEO_EDITOR_DATA.check_end_call_back = video_editor_check_end;
VIDEO_EDITOR_DATA.video_decode_end = KAL_FALSE;
/*Decode initialize*/
video_dec_input.pstMp4Parser = veditor_struct->pstVIDParser;
video_dec_input.pstFSAL = veditor_struct->pstVIDFSAL;
video_dec_input.start_frame_no = 0xff; /*Don't care*/
video_dec_input.video_dec_callback = veditor_struct->call_back;
result = video_decoder_initialize(&video_dec_input, VIDEO_EDITOR_MAX_FRAME_WIDTH, VIDEO_EDITOR_MAX_FRAME_HEIGHT);
if (result != MEDIA_STATUS_OK)
{
VIDEO_ASSERT(0);
return result;
}
VIDEO_EDITOR_DATA.decode_frame_width = g_video_dec_info_ptr->width;
VIDEO_EDITOR_DATA.decode_frame_height = g_video_dec_info_ptr->height;
/*Encode initialize*/
video_enc_input.short_header = VIDEO_EDITOR_DATA.short_header;
video_enc_input.bit_rate = VIDEO_EDITOR_DATA.bit_rate;
video_enc_input.frame_width = VIDEO_EDITOR_DATA.encode_frame_width;
video_enc_input.frame_height = VIDEO_EDITOR_DATA.encode_frame_height;
video_enc_input.call_back = veditor_struct->call_back;
result = video_encode_comm_setup(&video_enc_input);
if (result != MEDIA_STATUS_OK)
{
VIDEO_ASSERT(0);
return result;
}
/*Obtain AV sync info*/
result = video_editor_avsync_info(veditor_struct->need_avsync,
veditor_struct->video_start_time,
veditor_struct->audio_start_time,
veditor_struct->av_duration,
audio_avsync,
current_video_frame_no);
if (result != MEDIA_STATUS_OK)
{
VIDEO_ASSERT(0);
return result;
}
VIDEO_EDITOR_DATA.veditor_state = VIEDO_EDITOR_STATE_OPEN_NEXT;
return MEDIA_STATUS_OK;
}
MEDIA_STATUS_CODE video_editor_seek_by_frame(kal_uint32 frame, void (*callback)(kal_uint8 event))
{
MEDIA_STATUS_CODE result;
ASSERT( (VIDEO_EDITOR_DATA.veditor_state == VIEDO_EDITOR_STATE_OPEN) ||
(VIDEO_EDITOR_DATA.veditor_state == VIEDO_EDITOR_STATE_OPEN_NEXT) );
result = video_dec_seek_by_frame(frame, callback, KAL_FALSE);
if (result != MEDIA_STATUS_OK)
{
VIDEO_ASSERT(0);
return result;
}
VIDEO_EDITOR_DATA.veditor_state = VIEDO_EDITOR_STATE_SEEK;
return MEDIA_STATUS_OK;
}
void video_editor_set_seek_lisr(void)
{
kal_uint32 savedMask;
savedMask = SaveAndSetIRQMask();
g_video_dec_info_ptr->dec_state = VIDEO_DEC_STATE_SEEK;
VISUAL_Register_HISR(VISUAL_MP4_SEEK_HISR_ID,mpeg4_dec_seek_HISR);
#if ( defined(MT6219) || defined(MT6226) || defined(MT6227) || defined(MT6226M) )
IRQ_Register_LISR(IRQ_MPEG4_CODE, MPEG4_EDITOR_LISR,"MPEG4Seek");
IRQSensitivity(IRQ_MPEG4_CODE,LEVEL_SENSITIVE);
IRQUnmask(IRQ_MPEG4_CODE);
#else /*!(MT6219, MT6226, MT6227, MT6226M)*/
IRQ_Register_LISR(IRQ_MPEG4_DEC_CODE, MPEG4_EDITOR_LISR,"MPEG4Seek");
IRQSensitivity(IRQ_MPEG4_DEC_CODE,LEVEL_SENSITIVE);
IRQUnmask(IRQ_MPEG4_DEC_CODE);
#endif /*(MT6219, MT6226, MT6227, MT6226M)*/
RestoreIRQMask(savedMask);
}
void video_editor_start(void)
{
kal_uint32 time_stamp;
ASSERT(VIDEO_EDITOR_DATA.veditor_state == VIEDO_EDITOR_STATE_SEEK);
//display, encode, then decode, encode, decode
/*Encoder*/
time_stamp = VIDEO_EDITOR_DATA.glb_time_stamp;
VIDEO_EDITOR_DATA.glb_time_stamp = video_editor_avsync_first_frame(VIDEO_EDITOR_DATA.glb_time_stamp);
g_video_enc_info_ptr->force_I_frame = KAL_TRUE;
video_enc_lisr_process(DRV_Reg32(MP4_DEC_REC_ADDR), time_stamp, 0);
/*Decoder*/
video_dec_clr_buffer(g_video_dec_info_ptr->seek_frame_number, (VIDEO_EDITOR_DATA.video_avsync.end_frame_number+1));
video_dec_set_seek_frame((VIDEO_EDITOR_DATA.video_avsync.end_frame_number+1));
video_dec_put_frame_to_buffer();
video_editor_set_seek_lisr();
visual_active_hisr(VISUAL_MP4_SEEK_HISR_ID);
VIDEO_EDITOR_DATA.veditor_state = VIEDO_EDITOR_STATE_START;
}
void video_editor_close(void)
{
ASSERT(VIDEO_EDITOR_DATA.veditor_state == VIEDO_EDITOR_STATE_START);
VIDEO_EDITOR_DATA.call_by_next = KAL_FALSE;
video_dec_close();
video_enc_close();
VIDEO_EDITOR_DATA.veditor_state = VIEDO_EDITOR_STATE_IDLE;
}
void video_editor_seek_action(void)
{
video_seek_action();
}
void MPEG4_EDITOR_LISR(void)
{
kal_uint32 status;
kal_uint32 time_stamp;
status = DRV_Reg32(MP4_DEC_IRQ_STS);
if (status & MP4_DEC_IRQ_STS_DEC)
{
//Enable image data path copy memory to display
video_display_to_LCD(DRV_Reg32(MP4_DEC_REC_ADDR));
//Execute the encode process
time_stamp = VIDEO_EDITOR_DATA.glb_time_stamp;
VIDEO_EDITOR_DATA.glb_time_stamp += video_dec_get_curr_frame_duration();
ASSERT(VIDEO_EDITOR_DATA.glb_time_stamp >= time_stamp);
video_enc_lisr_process(DRV_Reg32(MP4_DEC_REC_ADDR), time_stamp, 0);
}
mpeg4_dec_seek_lisr_process(status);
}
void VIDEO_EDITOR_DEC_DONE_HISR(void)
{ //NULL function.
VIDEO_EDITOR_DATA.video_decode_end = KAL_TRUE;
}
#else /*!__VIDEO_EDITOR__*/
#include "drv_comm.h"
#endif /*__VIDEO_EDITOR__*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -