| @@ -40,6 +40,11 @@ · 39 unmodified lines |
| 40 | 40 | |
| 41 | 41 | static const AVRational default_tb = { 1, 90000 }; |
| 42 | 42 | |
| 43 | +typedef struct QSVAsyncFrame { |
| 44 | + mfxSyncPoint sync; |
| 45 | + QSVFrame *frame; |
| 46 | +} QSVAsyncFrame; |
| 47 | + |
| 43 | 48 | static const struct { |
| 44 | 49 | int mfx_iopattern; |
| 45 | 50 | const char *desc; |
| @@ -642,16 +647,6 @@ static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s) · 596 unmodified lines |
| 642 | 647 | return 0; |
| 643 | 648 | } |
| 644 | 649 | |
| 645 | | −static unsigned int qsv_fifo_item_size(void) |
| 646 | | −{ |
| 647 | | − return sizeof(mfxSyncPoint) + sizeof(QSVFrame*); |
| 648 | | −} |
| 649 | | − |
| 650 | | −static unsigned int qsv_fifo_size(const AVFifoBuffer* fifo) |
| 651 | | −{ |
| 652 | | − return av_fifo_size(fifo)/qsv_fifo_item_size(); |
| 653 | | −} |
| 654 | | − |
| 655 | 650 | int ff_qsvvpp_create(AVFilterContext *avctx, QSVVPPContext **vpp, QSVVPPParam *param) |
| 656 | 651 | { |
| 657 | 652 | int i; |
| @@ -727,7 +722,7 @@ int ff_qsvvpp_create(AVFilterContext *avctx, QSVVPPContext **vpp, QSVVPPParam *p · 69 unmodified lines |
| 727 | 722 | s->got_frame = 0; |
| 728 | 723 | |
| 729 | 724 | /** keep fifo size at least 1. Even when async_depth is 0, fifo is used. */ |
| 730 | | − s->async_fifo = av_fifo_alloc((param->async_depth + 1) * qsv_fifo_item_size()); |
| 725 | + s->async_fifo = av_fifo_alloc2(param->async_depth + 1, sizeof(QSVAsyncFrame), 0); |
| 731 | 726 | s->async_depth = param->async_depth; |
| 732 | 727 | if (!s->async_fifo) { |
| 733 | 728 | ret = AVERROR(ENOMEM); |
| @@ -789,7 +784,7 @@ int ff_qsvvpp_free(QSVVPPContext **vpp) · 55 unmodified lines |
| 789 | 784 | av_freep(&s->surface_ptrs_out); |
| 790 | 785 | av_freep(&s->ext_buffers); |
| 791 | 786 | av_freep(&s->frame_infos); |
| 792 | | − av_fifo_free(s->async_fifo); |
| 787 | + av_fifo_freep2(&s->async_fifo); |
| 793 | 788 | av_freep(vpp); |
| 794 | 789 | |
| 795 | 790 | return 0; |
| @@ -799,24 +794,23 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picr · 3 unmodified lines |
| 799 | 794 | { |
| 800 | 795 | AVFilterContext *ctx = inlink->dst; |
| 801 | 796 | AVFilterLink *outlink = ctx->outputs[0]; |
| 797 | + QSVAsyncFrame aframe; |
| 802 | 798 | mfxSyncPoint sync; |
| 803 | 799 | QSVFrame *in_frame, *out_frame, *tmp; |
| 804 | 800 | int ret, filter_ret; |
| 805 | 801 | |
| 806 | | − while (s->eof && qsv_fifo_size(s->async_fifo)) { |
| 807 | | − av_fifo_generic_read(s->async_fifo, &tmp, sizeof(tmp), NULL); |
| 808 | | − av_fifo_generic_read(s->async_fifo, &sync, sizeof(sync), NULL); |
| 809 | | − if (MFXVideoCORE_SyncOperation(s->session, sync, 1000) < 0) |
| 802 | + while (s->eof && av_fifo_read(s->async_fifo, &aframe, 1) >= 0) { |
| 803 | + if (MFXVideoCORE_SyncOperation(s->session, aframe.sync, 1000) < 0) |
| 810 | 804 | av_log(ctx, AV_LOG_WARNING, "Sync failed.\n"); |
| 811 | 805 | |
| 812 | | − filter_ret = s->filter_frame(outlink, tmp->frame); |
| 806 | + filter_ret = s->filter_frame(outlink, aframe.frame->frame); |
| 813 | 807 | if (filter_ret < 0) { |
| 814 | | − av_frame_free(&tmp->frame); |
| 808 | + av_frame_free(&aframe.frame->frame); |
| 815 | 809 | return filter_ret; |
| 816 | 810 | } |
| 817 | | − tmp->queued--; |
| 811 | + aframe.frame->queued--; |
| 818 | 812 | s->got_frame = 1; |
| 819 | | − tmp->frame = NULL; |
| 813 | + aframe.frame->frame = NULL; |
| 820 | 814 | }; |
| 821 | 815 | |
| 822 | 816 | if (!picref) |
| @@ -853,16 +847,14 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picr · 30 unmodified lines |
| 853 | 847 | default_tb, outlink->time_base); |
| 854 | 848 | |
| 855 | 849 | out_frame->queued++; |
| 856 | | − av_fifo_generic_write(s->async_fifo, &out_frame, sizeof(out_frame), NULL); |
| 857 | | − av_fifo_generic_write(s->async_fifo, &sync, sizeof(sync), NULL); |
| 858 | | − |
| 850 | + aframe = (QSVAsyncFrame){ sync, out_frame }; |
| 851 | + av_fifo_write(s->async_fifo, &aframe, 1); |
| 859 | 852 | |
| 860 | | − if (qsv_fifo_size(s->async_fifo) > s->async_depth) { |
| 861 | | − av_fifo_generic_read(s->async_fifo, &tmp, sizeof(tmp), NULL); |
| 862 | | − av_fifo_generic_read(s->async_fifo, &sync, sizeof(sync), NULL); |
| 853 | + if (av_fifo_can_read(s->async_fifo) > s->async_depth) { |
| 854 | + av_fifo_read(s->async_fifo, &aframe, 1); |
| 863 | 855 | |
| 864 | 856 | do { |
| 865 | | − ret = MFXVideoCORE_SyncOperation(s->session, sync, 1000); |
| 857 | + ret = MFXVideoCORE_SyncOperation(s->session, aframe.sync, 1000); |
| 866 | 858 | } while (ret == MFX_WRN_IN_EXECUTION); |
| 867 | 859 | |
| 868 | 860 | filter_ret = s->filter_frame(outlink, tmp->frame); |