Fplay: reorder decoded frames when needed

git-svn-id: svn://kolibrios.org@6135 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2016-02-04 14:44:22 +00:00
parent 5398730057
commit 798707fd38
3 changed files with 59 additions and 50 deletions

View File

@ -135,7 +135,11 @@ struct vstate
vframe_t *decoder_frame; vframe_t *decoder_frame;
void *hwCtx; /* hardware context */ void *hwCtx; /* hardware context */
int hwdec; /* hardware decoder */ int hwdec:1; /* hardware decoder */
int blit_bitmap:1; /* hardware RGBA blitter */
int blit_texture:1; /* hardware RGBA blit and scale */
int blit_planar:1; /* hardbare YUV blit and scale */
int frame_reorder:1;
}; };

View File

@ -608,8 +608,6 @@ void va_create_planar(vst_t *vst, vframe_t *vframe)
if(vframe->format != AV_PIX_FMT_NONE) if(vframe->format != AV_PIX_FMT_NONE)
return; return;
ENTER();
status = vaDeriveImage(vaapi->display,v_surface_id[vframe->index],&vaimage); status = vaDeriveImage(vaapi->display,v_surface_id[vframe->index],&vaimage);
if (!vaapi_check_status(status, "vaDeriveImage()")) if (!vaapi_check_status(status, "vaDeriveImage()"))
{ {
@ -653,5 +651,5 @@ ENTER();
vaReleaseBufferHandle(vaapi->display, vaimage.buf); vaReleaseBufferHandle(vaapi->display, vaimage.buf);
vaDestroyImage(vaapi->display, vaimage.image_id); vaDestroyImage(vaapi->display, vaimage.image_id);
LEAVE();
} }

View File

@ -76,6 +76,48 @@ int init_video(vst_t *vst)
static double dts = 0.0; static double dts = 0.0;
static vframe_t *get_input_frame(vst_t *vst)
{
vframe_t *vframe = NULL;
mutex_lock(&vst->input_lock);
if(!list_empty(&vst->input_list))
{
vframe = list_first_entry(&vst->input_list, vframe_t, list);
list_del(&vframe->list);
}
mutex_unlock(&vst->input_lock);
return vframe;
}
static void put_output_frame(vst_t *vst, vframe_t *vframe)
{
mutex_lock(&vst->output_lock);
if(list_empty(&vst->output_list))
list_add_tail(&vframe->list, &vst->output_list);
else
{
vframe_t *cur;
cur = list_first_entry(&vst->output_list,vframe_t,list);
if(vframe->pts < cur->pts)
list_add_tail(&vframe->list, &vst->output_list);
else
{
list_for_each_entry_reverse(cur,&vst->output_list,list)
{
if(vframe->pts > cur->pts)
{
list_add(&vframe->list, &cur->list);
break;
};
};
};
};
mutex_unlock(&vst->output_lock);
};
int decode_video(vst_t* vst) int decode_video(vst_t* vst)
{ {
AVPacket pkt; AVPacket pkt;
@ -83,24 +125,13 @@ int decode_video(vst_t* vst)
int frameFinished; int frameFinished;
if(vst->decoder_frame == NULL) if(vst->decoder_frame == NULL)
{ vst->decoder_frame = get_input_frame(vst);
mutex_lock(&vst->input_lock);
if(list_empty(&vst->input_list))
{
mutex_unlock(&vst->input_lock);
return -1;
}
vst->decoder_frame = list_first_entry(&vst->input_list, vframe_t, list);
list_del(&vst->decoder_frame->list);
mutex_unlock(&vst->input_lock);
vframe_t *vframe = vst->decoder_frame; if(vst->decoder_frame == NULL)
}; return 0;
if( get_packet(&vst->q_video, &pkt) == 0 ) if( get_packet(&vst->q_video, &pkt) == 0 )
{
return 0; return 0;
};
frameFinished = 0; frameFinished = 0;
if(dts == 0) if(dts == 0)
@ -113,13 +144,16 @@ int decode_video(vst_t* vst)
if(frameFinished) if(frameFinished)
{ {
vframe_t *vframe; vframe_t *vframe = vst->decoder_frame;;
AVPicture *dst_pic; AVPicture *dst_pic;
if(vst->hwdec)
pts = pkt.pts;
else
pts = av_frame_get_best_effort_timestamp(Frame); pts = av_frame_get_best_effort_timestamp(Frame);
pts*= av_q2d(video_time_base); pts*= av_q2d(video_time_base);
vframe = vst->decoder_frame;
dst_pic = &vframe->picture; dst_pic = &vframe->picture;
if(vframe->is_hw_pic == 0) if(vframe->is_hw_pic == 0)
@ -134,34 +168,7 @@ int decode_video(vst_t* vst)
vframe->pkt_dts = dts*av_q2d(video_time_base)*1000.0; vframe->pkt_dts = dts*av_q2d(video_time_base)*1000.0;
vframe->ready = 1; vframe->ready = 1;
put_output_frame(vst, vframe);
mutex_lock(&vst->output_lock);
if(list_empty(&vst->output_list))
list_add_tail(&vframe->list, &vst->output_list);
else
{
vframe_t *cur;
cur = list_first_entry(&vst->output_list,vframe_t,list);
if(vframe->pkt_pts < cur->pkt_pts)
{
list_add_tail(&vframe->list, &vst->output_list);
}
else
{
list_for_each_entry_reverse(cur,&vst->output_list,list)
{
if(vframe->pkt_pts > cur->pkt_pts)
{
list_add(&vframe->list, &cur->list);
break;
};
};
};
};
mutex_unlock(&vst->output_lock);
// printf("decoded index: %d pts: %f pkt_pts %f pkt_dts %f\n", // printf("decoded index: %d pts: %f pkt_pts %f pkt_dts %f\n",
// vst->dfx, vst->vframe[vst->dfx].pts, // vst->dfx, vst->vframe[vst->dfx].pts,