From 798707fd3823238cf6c388d82e623be583e2c252 Mon Sep 17 00:00:00 2001 From: "Sergey Semyonov (Serge)" Date: Thu, 4 Feb 2016 14:44:22 +0000 Subject: [PATCH] Fplay: reorder decoded frames when needed git-svn-id: svn://kolibrios.org@6135 a494cfbc-eb01-0410-851d-a64ba20cac60 --- contrib/media/fplay/fplay.h | 6 ++- contrib/media/fplay/vaapi.c | 4 +- contrib/media/fplay/video.c | 99 ++++++++++++++++++++----------------- 3 files changed, 59 insertions(+), 50 deletions(-) diff --git a/contrib/media/fplay/fplay.h b/contrib/media/fplay/fplay.h index e6d9098111..f1aa7e6556 100644 --- a/contrib/media/fplay/fplay.h +++ b/contrib/media/fplay/fplay.h @@ -135,7 +135,11 @@ struct vstate vframe_t *decoder_frame; 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; }; diff --git a/contrib/media/fplay/vaapi.c b/contrib/media/fplay/vaapi.c index 3e21b89b18..7b5541d68b 100644 --- a/contrib/media/fplay/vaapi.c +++ b/contrib/media/fplay/vaapi.c @@ -608,8 +608,6 @@ void va_create_planar(vst_t *vst, vframe_t *vframe) if(vframe->format != AV_PIX_FMT_NONE) return; -ENTER(); - status = vaDeriveImage(vaapi->display,v_surface_id[vframe->index],&vaimage); if (!vaapi_check_status(status, "vaDeriveImage()")) { @@ -653,5 +651,5 @@ ENTER(); vaReleaseBufferHandle(vaapi->display, vaimage.buf); vaDestroyImage(vaapi->display, vaimage.image_id); -LEAVE(); + } diff --git a/contrib/media/fplay/video.c b/contrib/media/fplay/video.c index c34607341e..09308a76f0 100644 --- a/contrib/media/fplay/video.c +++ b/contrib/media/fplay/video.c @@ -76,6 +76,48 @@ int init_video(vst_t *vst) 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) { AVPacket pkt; @@ -83,24 +125,13 @@ int decode_video(vst_t* vst) int frameFinished; if(vst->decoder_frame == NULL) - { - 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); + vst->decoder_frame = get_input_frame(vst); - vframe_t *vframe = vst->decoder_frame; - }; + if(vst->decoder_frame == NULL) + return 0; if( get_packet(&vst->q_video, &pkt) == 0 ) - { return 0; - }; frameFinished = 0; if(dts == 0) @@ -113,13 +144,16 @@ int decode_video(vst_t* vst) if(frameFinished) { - vframe_t *vframe; + vframe_t *vframe = vst->decoder_frame;; AVPicture *dst_pic; - pts = av_frame_get_best_effort_timestamp(Frame); - pts *= av_q2d(video_time_base); + if(vst->hwdec) + pts = pkt.pts; + else + pts = av_frame_get_best_effort_timestamp(Frame); + + pts*= av_q2d(video_time_base); - vframe = vst->decoder_frame; dst_pic = &vframe->picture; 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->ready = 1; - - 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); - + put_output_frame(vst, vframe); // printf("decoded index: %d pts: %f pkt_pts %f pkt_dts %f\n", // vst->dfx, vst->vframe[vst->dfx].pts,