📄 video_dec_api.c
字号:
}
else
#endif /*__VIDEO_EDITOR__*/
{
video_dec_complete();
}
/* audio interrupt should count (in order to get time information) */
video_dec_set_enable_av_callback(NULL);
return MEDIA_STATUS_OK;
}
else /* g_video_dec_info_ptr->seek_time < g_video_dec_info_ptr->audio_duration */
{
/* seek time is longer than both video duration and audio duration */
#if defined(__VIDEO_EDITOR__)
if (g_video_dec_status.scenario != VIDEO_SCENARIO_EDITOR)
{
ASSERT(0);
}
else
#endif /*__VIDEO_EDITOR__*/
{
video_dec_complete();
}
g_video_dec_status.VIDEO_STATUS = VIDEO_DEC_SEEK_AUDIO_END;
return VIDEO_ERROR;
}
}
if (g_video_dec_info_ptr->stage == VIDEO_DEC_STAGE_STOP)
{
/* Do not act seek before this play action, and not clip play, but when ??? */
if (g_video_dec_info_ptr->seek_result_frame_number < g_video_dec_info_ptr->total_frames_in_file)
{
g_video_dec_info_ptr->seek_frame_number = g_video_dec_info_ptr->dec_frames_no;
g_video_dec_info_ptr->seek_result_frame_number = g_video_dec_info_ptr->dec_frames_no;
/* get seek time from video frame number */
g_video_dec_status.PARSE_STATUS = MP4_GetDecodeTime(g_video_dec_info_ptr->pMp4Parser,
(g_video_dec_info_ptr->seek_result_frame_number - 1), //id = 1~, reviewed
&g_video_dec_info_ptr->seek_time,
MP4_TRACK_VIDEO);
if (g_video_dec_status.PARSE_STATUS != MP4_PARSER_OK)
{
VIDEO_ASSERT(0);
return MP4_PARSER_ERROR;
}
/* set play back time base, if audio enable, play time is got from this time base */
MP4_SetPlaybackTimerBase(vid_get_audio_parser(),
(kal_uint32)VIDEO_ANYBASE_TO_MS(g_video_dec_info_ptr->seek_time,
g_video_dec_info_ptr->video_time_scale),
KAL_TRUE);
/*obtain Video play_time, if audio is not enable, play time is got from this time base */
result = video_dec_translate_av_time(g_video_dec_info_ptr->seek_time,
&g_video_dec_info_ptr->play_time);
if (result != MEDIA_STATUS_OK)
{
VIDEO_ASSERT(0);
return result;
}
/* translate seek time to common base */
g_video_dec_info_ptr->seek_time = VIDEO_ANYBASE_TO_COMMBASE(g_video_dec_info_ptr->seek_time,
g_video_dec_info_ptr->video_time_scale);
if (g_video_dec_info_ptr->seek_result_frame_number < g_video_dec_info_ptr->total_frames_in_file - 1)
{
/* still has next frame, not the last frame */
g_video_dec_status.PARSE_STATUS =
MP4_GetDecodeTime_Next(g_video_dec_info_ptr->pMp4Parser,
&g_video_dec_info_ptr->seek_next_frame_time,
MP4_TRACK_VIDEO);
if (g_video_dec_status.PARSE_STATUS != MP4_PARSER_OK)
{
VIDEO_ASSERT(0);
return MP4_PARSER_ERROR;
}
/* also translate seek_next_frame_time to common base */
g_video_dec_info_ptr->seek_next_frame_time =
VIDEO_ANYBASE_TO_COMMBASE(g_video_dec_info_ptr->seek_next_frame_time,
g_video_dec_info_ptr->video_time_scale);
}
else
{
/* the last frame */
g_video_dec_info_ptr->seek_next_frame_time = g_video_dec_info_ptr->seek_time;
}
}
else /* g_video_dec_info_ptr->seek_result_frame_number < g_video_dec_info_ptr->total_frames_in_file */
{
video_play = KAL_FALSE;
}
}
else if (g_video_dec_info_ptr->stage == VIDEO_DEC_STAGE_CLOSE)
{
return MEDIA_STATUS_OK;
}
else
{
if (g_video_dec_info_ptr->stage != VIDEO_DEC_STAGE_SEEK)
{
VIDEO_ASSERT(0);
g_video_dec_status.VIDEO_STATUS = VIDEO_DEC_FUNC_STATE_ERROR;
return VIDEO_ERROR;
}
}
/* Rita, move to video_image_path_open */
#if 0
#if ( (!defined(MT6219)) && (!defined(MT6226)) && (!defined(MT6227)) && (!defined(MT6226M)) )
/* under construction !*/
#endif /*MT6228, MT6229, MT6230*/
#endif
if (g_video_dec_info_ptr->seek_result_frame_number < g_video_dec_info_ptr->total_frames_in_file)
{
/* reset other parameters also */
video_dec_struct_init(g_video_dec_info_ptr, g_video_dec_info_ptr->decode_type,
g_video_dec_info_ptr->VOS, g_video_dec_info_ptr->total_frames_in_file);
if (g_video_dec_info_ptr->video_avg_frame_duration < VIDEO_ANYBASE_TO_COMMBASE(3000, 1000))
{
g_video_dec_info_ptr->prepare_frames_no = g_video_dec_info_ptr->seek_result_frame_number;
g_video_dec_info_ptr->dec_frames_no = g_video_dec_info_ptr->seek_result_frame_number;
g_video_dec_info_ptr->hdr_parse_frames_no = g_video_dec_info_ptr->seek_result_frame_number;
}
else
{ /*temp for long video duration, must solve by med ??? */
g_video_dec_info_ptr->prepare_frames_no = g_video_dec_info_ptr->seek_result_frame_number;
g_video_dec_info_ptr->dec_frames_no = g_video_dec_info_ptr->seek_result_frame_number - 1;
g_video_dec_info_ptr->hdr_parse_frames_no = g_video_dec_info_ptr->seek_result_frame_number - 1;
}
/* prepare bitstream buffer */
video_dec_clr_buffer(g_video_dec_info_ptr->prepare_frames_no, g_video_dec_info_ptr->total_frames_in_file);
result = video_dec_put_frame_to_buffer();
if (result != MEDIA_STATUS_OK)
{
VIDEO_ASSERT(0);
return result;
}
//Prepare the HW register and bistream of current frame
if (g_video_dec_info_ptr->hdr_parse_frames_no < g_video_dec_info_ptr->total_frames_in_file)
{
for (recheck_count = 0; recheck_count < 50; recheck_count++)
{
/* try to parse one success frame */
result = video_dec_get_next_frame(&frame_addr, &frame_length, &prev_frame_duration);
frame_duration = prev_frame_duration;
if (result != MEDIA_STATUS_OK)
{
VIDEO_ASSERT(0);
return result;
}
result = mpeg4_decode_main(frame_addr, frame_length, prev_frame_duration);
if (result == MEDIA_STATUS_OK)
{
break;
}
else
{
/* parse next frame */
VIDEO_ASSERT(0);
}
}
if (result != MEDIA_STATUS_OK)
{
/* all recheck fail */
VIDEO_ASSERT(0);
return result;
}
g_video_dec_info_ptr->dec_frames_no += recheck_count;
if (recheck_count != 0)
{
/* Get real next frame time */
g_video_dec_status.PARSE_STATUS =
MP4_GetDecodeTime(g_video_dec_info_ptr->pMp4Parser,
g_video_dec_info_ptr->dec_frames_no, //id = 1~, reviewed
&g_video_dec_info_ptr->seek_next_frame_time,
MP4_TRACK_VIDEO);
if (g_video_dec_status.PARSE_STATUS != MP4_PARSER_OK)
{
VIDEO_ASSERT(0);
return MP4_PARSER_ERROR;
}
/* also translate seek_next_frame_time to common base */
g_video_dec_info_ptr->seek_next_frame_time =
VIDEO_ANYBASE_TO_COMMBASE(g_video_dec_info_ptr->seek_next_frame_time,
g_video_dec_info_ptr->video_time_scale);
}
/* write register to decode the parsed frame */
mpeg4_decode_write_register();
}
/* Pre-parse the next frame */
if (g_video_dec_info_ptr->hdr_parse_frames_no < g_video_dec_info_ptr->total_frames_in_file)
{
/* Not the last frame */
result = video_dec_get_next_frame(&frame_addr, &frame_length, &prev_frame_duration);
if (result != MEDIA_STATUS_OK)
{
VIDEO_ASSERT(0);
return result;
}
/* pre-parse the next frame */
result = mpeg4_decode_main(frame_addr, frame_length, prev_frame_duration);
if (result != MEDIA_STATUS_OK)
{
/* treat the error frame as non-coded */
VIDEO_ASSERT(0);
g_video_dec_info_ptr->is_non_coded = KAL_TRUE;
}
}
else
{
/* previous decode one is the last frame. Treat this case as play done */
video_play = KAL_FALSE;
ASSERT(g_video_dec_info_ptr->video_dec_callback != NULL);
g_video_dec_info_ptr->video_end = KAL_TRUE;
#if defined(__VIDEO_EDITOR__)
if (g_video_dec_status.scenario == VIDEO_SCENARIO_EDITOR)
{
ASSERT(0);
}
else
#endif /*__VIDEO_EDITOR__*/
{
video_dec_complete();
}
}
}
else /*(g_video_dec_info_ptr->seek_frame_number < g_video_dec_info_ptr->total_frames_in_file)*/
{
video_dbg_trace(MP4_DEC_SEEK_END_FRAME, video_get_current_time());
video_play = KAL_FALSE;
/*send complete message!! */
ASSERT(g_video_dec_info_ptr->video_dec_callback != NULL);
g_video_dec_info_ptr->video_end = KAL_TRUE;
#if defined(__VIDEO_EDITOR__)
if (g_video_dec_status.scenario == VIDEO_SCENARIO_EDITOR)
{
ASSERT(0);
}
else
#endif /*__VIDEO_EDITOR__*/
{
video_dec_complete();
}
}
if (g_video_dec_info_ptr->audio_enable == KAL_TRUE)
{
/* should align time to audio frame number */
if (g_video_dec_info_ptr->dec_frames_no < g_video_dec_info_ptr->total_frames_in_file)
{
if ((g_video_dec_info_ptr->stage == VIDEO_DEC_STAGE_STOP)
&& (current_play_time < g_video_dec_info_ptr->seek_next_frame_time)
&& (g_video_dec_info_ptr->seek_next_frame_time > VIDEO_ANYBASE_TO_COMMBASE(
current_play_time, 1000)))
{
/*For long video duratoin??*/
seek_time_video_scale_based = VIDEO_ANYBASE_TO_ANYBASE(current_play_time, 1000,
g_video_dec_info_ptr->video_time_scale);
}
else
{
seek_time_video_scale_based = VIDEO_COMMBASE_TO_ANYBASE(g_video_dec_info_ptr->seek_time,
g_video_dec_info_ptr->video_time_scale);
}
/* video not end. use video time to seek to audio frame no */
g_video_dec_status.PARSE_STATUS =
MP4_Audio_Seek_To_Video(g_video_dec_info_ptr->pMp4Parser, seek_time_video_scale_based,
&audio_frame_number);
}
else
{
/* video end, use seek time to seek audio frame directly */
kal_uint64 seek_time_ms;
seek_time_ms = VIDEO_ANYBASE_TO_MS(g_video_dec_info_ptr->seek_time, VIDEO_COMMON_TIME_BASE);
g_video_dec_status.PARSE_STATUS =
MP4_Audio_TimeToSampleNo(g_video_dec_info_ptr->pMp4Parser, seek_time_ms, &audio_frame_number);
}
if (g_video_dec_status.PARSE_STATUS == MP4_PARSER_NO_SUCH_TRACK)
{
/*No audio track*/
audio_frame_number = 0;
*audio_frame_no = 0;
audio_decode_time = 0;
audio_exist = KAL_FALSE;
}
else if (g_video_dec_status.PARSE_STATUS == MP4_PARSER_NO_SUCH_SAMPLE)
{
/* audio end */
audio_frame_number = 0;
*audio_frame_no = 0;
audio_decode_time = 0;
audio_end = KAL_TRUE;
g_video_dec_status.VIDEO_STATUS = VIDEO_DEC_SEEK_AUDIO_END;
}
else
{
*audio_frame_no = audio_frame_number;
if (g_video_dec_status.PARSE_STATUS != MP4_PARSER_OK)
{
VIDEO_ASSERT(0);
return MP4_PARSER_ERROR;
}
/*Get Audio duration from the seeked audio frame no */
g_video_dec_status.PARSE_STATUS =
MP4_GetDecodeTime(g_video_dec_info_ptr->pMp4Parser, audio_frame_number, &audio_decode_time,
MP4_TRACK_AUDIO);
if (g_video_dec_status.PARSE_STATUS != MP4_PARSER_OK)
{
VIDEO_ASSERT(0);
return MP4_PARSER_ERROR;
}
audio_decode_time = VIDEO_ANYBASE_TO_COMMBASE(audio_decode_time,
g_video_dec_info_ptr->audio_time_scale);
}
//Get (Next Video - audio time) duration
if ((audio_exist) && (audio_end == KAL_FALSE) && (video_play == KAL_TRUE))
{
/* with audio */
ASSERT(g_video_dec_info_ptr->seek_next_frame_time >= audio_decode_time);
/* translate time to av ticks */
decode_time = VIDEO_COMMBASE_TO_ANYBASE(
(g_video_dec_info_ptr->seek_next_frame_time - audio_decode_time),
g_video_dec_info_ptr->video_time_scale);
video_dec_translate_av_time(decode_time, &decode_time);
/* Rita add,
1. audio frame and seek time may be not the same
2. seek and play may re-check several frames */
MP4_SetPlaybackTimerBase(vid_get_audio_parser(),
(kal_uint32)VIDEO_COMMBASE_TO_ANYBASE(audio_decode_time, 1000),
KAL_TRUE);
}
else if (video_play == KAL_TRUE)
{
/* with no audio. audio duration < video duration. and play beyond audio duration */
decode_time = VIDEO_COMMBASE_TO_ANYBASE(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -