History

lavfi/qsvvpp: switch to new FIFO API

Anton Khirnov committed 4 years ago

Commit 85c938f1 parent 90eef1c2 files · +20 −28Browse files

Unified · Split

2 files
  1. libavfilter/qsvvpp.c +19 −27
  2. libavfilter/qsvvpp.h +1 −1
libavfilter/qsvvpp.c+19−27
@@ -40,6 +40,11 @@ · 39 unmodified lines
4040
4141 static const AVRational default_tb = { 1, 90000 };
4242
43+typedef struct QSVAsyncFrame {
44+ mfxSyncPoint sync;
45+ QSVFrame *frame;
46+} QSVAsyncFrame;
47+
4348 static const struct {
4449 int mfx_iopattern;
4550 const char *desc;
@@ -642,16 +647,6 @@ static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s) · 596 unmodified lines
642647 return 0;
643648 }
644649
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−
655650 int ff_qsvvpp_create(AVFilterContext *avctx, QSVVPPContext **vpp, QSVVPPParam *param)
656651 {
657652 int i;
@@ -727,7 +722,7 @@ int ff_qsvvpp_create(AVFilterContext *avctx, QSVVPPContext **vpp, QSVVPPParam *p · 69 unmodified lines
727722 s->got_frame = 0;
728723
729724 /** 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);
731726 s->async_depth = param->async_depth;
732727 if (!s->async_fifo) {
733728 ret = AVERROR(ENOMEM);
@@ -789,7 +784,7 @@ int ff_qsvvpp_free(QSVVPPContext **vpp) · 55 unmodified lines
789784 av_freep(&s->surface_ptrs_out);
790785 av_freep(&s->ext_buffers);
791786 av_freep(&s->frame_infos);
792− av_fifo_free(s->async_fifo);
787+ av_fifo_freep2(&s->async_fifo);
793788 av_freep(vpp);
794789
795790 return 0;
@@ -799,24 +794,23 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picr · 3 unmodified lines
799794 {
800795 AVFilterContext *ctx = inlink->dst;
801796 AVFilterLink *outlink = ctx->outputs[0];
797+ QSVAsyncFrame aframe;
802798 mfxSyncPoint sync;
803799 QSVFrame *in_frame, *out_frame, *tmp;
804800 int ret, filter_ret;
805801
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)
810804 av_log(ctx, AV_LOG_WARNING, "Sync failed.\n");
811805
812− filter_ret = s->filter_frame(outlink, tmp->frame);
806+ filter_ret = s->filter_frame(outlink, aframe.frame->frame);
813807 if (filter_ret < 0) {
814− av_frame_free(&tmp->frame);
808+ av_frame_free(&aframe.frame->frame);
815809 return filter_ret;
816810 }
817− tmp->queued--;
811+ aframe.frame->queued--;
818812 s->got_frame = 1;
819− tmp->frame = NULL;
813+ aframe.frame->frame = NULL;
820814 };
821815
822816 if (!picref)
@@ -853,16 +847,14 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picr · 30 unmodified lines
853847 default_tb, outlink->time_base);
854848
855849 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);
859852
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);
863855
864856 do {
865− ret = MFXVideoCORE_SyncOperation(s->session, sync, 1000);
857+ ret = MFXVideoCORE_SyncOperation(s->session, aframe.sync, 1000);
866858 } while (ret == MFX_WRN_IN_EXECUTION);
867859
868860 filter_ret = s->filter_frame(outlink, tmp->frame);
libavfilter/qsvvpp.h+1−1
@@ -73,7 +73,7 @@ typedef struct QSVVPPContext { · 72 unmodified lines
7373 int async_depth;
7474 int eof;
7575 /** order with frame_out, sync */
76− AVFifoBuffer *async_fifo;
76+ AVFifo *async_fifo;
7777 } QSVVPPContext;
7878
7979 typedef struct QSVVPPCrop {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t