History

lavfi/qsvvpp: support async depth

Async depth will allow qsv filter cache few frames, and avoid force switch and end filter task frame by frame. This change will improve performance for some multi-task case, for example 1:N transcode( decode + vpp + encode) with all QSV plugins. Performance data test on my Coffee Lake Desktop(i7-8700K) by using the following 1:8 transcode test case improvement: 1. Fps improved from 55 to 130. 2. Render/Video usage improved from ~61%/~38% to ~100%/~70%.(Data get from intel_gpu_top) test CMD: ffmpeg -v verbose -init_hw_device qsv=hw:/dev/dri/renderD128 -filter_hw_device \ hw -hwaccel qsv -hwaccel_output_format qsv -c:v h264_qsv -i 1920x1080.264 \ -vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30 -preset 7 -g 33 -refs 2 -bf 3 -q 24 -f null - \ -vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30 -preset 7 -g 33 -refs 2 -bf 3 -q 24 -f null - \ -vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30 -preset 7 -g 33 -refs 2 -bf 3 -q 24 -f null - \ -vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30 -preset 7 -g 33 -refs 2 -bf 3 -q 24 -f null - \ -vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30 -preset 7 -g 33 -refs 2 -bf 3 -q 24 -f null - \ -vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30 -preset 7 -g 33 -refs 2 -bf 3 -q 24 -f null - \ -vf 'vpp_qsv=w=1280:h=720:async_depth=4' -c:v h264_qsv -r:v 30 -preset 7 -g 33 -refs 2 -bf 3 -q 24 -f null -

Fei Wang committed 5 years ago

Commit 89ffcd11 parent 309e3cc4 files · +191 −90Browse files

Showing the changes to libavfilter (4 of 4 files). Show all

Unified · Split

4 files
  1. libavfilter/qsvvpp.c +89 −64
  2. libavfilter/qsvvpp.h +38 −1
  3. libavfilter/vf_deinterlace_qsv.c +3 −11
  4. libavfilter/vf_vpp_qsv.c +61 −14
libavfilter/qsvvpp.c+89−64
@@ -37,37 +37,6 @@ · 36 unmodified lines
37#define IS_OPAQUE_MEMORY(mode) (mode & MFX_MEMTYPE_OPAQUE_FRAME)37#define IS_OPAQUE_MEMORY(mode) (mode & MFX_MEMTYPE_OPAQUE_FRAME)
38#define IS_SYSTEM_MEMORY(mode) (mode & MFX_MEMTYPE_SYSTEM_MEMORY)38#define IS_SYSTEM_MEMORY(mode) (mode & MFX_MEMTYPE_SYSTEM_MEMORY)
39 39
40typedef struct QSVFrame {
41 AVFrame *frame;
42 mfxFrameSurface1 *surface;
43 mfxFrameSurface1 surface_internal; /* for system memory */
44 struct QSVFrame *next;
45} QSVFrame;
46
47/* abstract struct for all QSV filters */
48struct QSVVPPContext {
49 mfxSession session;
50 int (*filter_frame) (AVFilterLink *outlink, AVFrame *frame);/* callback */
51 enum AVPixelFormat out_sw_format; /* Real output format */
52 mfxVideoParam vpp_param;
53 mfxFrameInfo *frame_infos; /* frame info for each input */
54
55 /* members related to the input/output surface */
56 int in_mem_mode;
57 int out_mem_mode;
58 QSVFrame *in_frame_list;
59 QSVFrame *out_frame_list;
60 int nb_surface_ptrs_in;
61 int nb_surface_ptrs_out;
62 mfxFrameSurface1 **surface_ptrs_in;
63 mfxFrameSurface1 **surface_ptrs_out;
64
65 /* MFXVPP extern parameters */
66 mfxExtOpaqueSurfaceAlloc opaque_alloc;
67 mfxExtBuffer **ext_buffers;
68 int nb_ext_buffers;
69};
70
71static const mfxHandleType handle_types[] = {40static const mfxHandleType handle_types[] = {
72 MFX_HANDLE_VA_DISPLAY,41 MFX_HANDLE_VA_DISPLAY,
73 MFX_HANDLE_D3D9_DEVICE_MANAGER,42 MFX_HANDLE_D3D9_DEVICE_MANAGER,
@@ -336,9 +305,11 @@ static int fill_frameinfo_by_link(mfxFrameInfo *frameinfo, AVFilterLink *link) · 262 unmodified lines
336static void clear_unused_frames(QSVFrame *list)305static void clear_unused_frames(QSVFrame *list)
337{306{
338 while (list) {307 while (list) {
339 if (list->surface && !list->surface->Data.Locked) {308 /* list->queued==1 means the frame is not cached in VPP
340 list->surface = NULL;309 * process any more, it can be released to pool. */
310 if ((list->queued == 1) && !list->surface.Data.Locked) {
341 av_frame_free(&list->frame);311 av_frame_free(&list->frame);
312 list->queued = 0;
342 }313 }
343 list = list->next;314 list = list->next;
344 }315 }
@@ -361,8 +332,10 @@ static QSVFrame *get_free_frame(QSVFrame **list) · 16 unmodified lines
361 QSVFrame *out = *list;332 QSVFrame *out = *list;
362 333
363 for (; out; out = out->next) {334 for (; out; out = out->next) {
364 if (!out->surface)335 if (!out->queued) {
336 out->queued = 1;
365 break;337 break;
338 }
366 }339 }
367 340
368 if (!out) {341 if (!out) {
@@ -371,8 +344,9 @@ static QSVFrame *get_free_frame(QSVFrame **list) · 2 unmodified lines
371 av_log(NULL, AV_LOG_ERROR, "Can't alloc new output frame.\n");344 av_log(NULL, AV_LOG_ERROR, "Can't alloc new output frame.\n");
372 return NULL;345 return NULL;
373 }346 }
374 out->next = *list;347 out->queued = 1;
375 *list = out;348 out->next = *list;
349 *list = out;
376 }350 }
377 351
378 return out;352 return out;
@@ -402,7 +376,7 @@ static QSVFrame *submit_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *p · 23 unmodified lines
402 return NULL;376 return NULL;
403 }377 }
404 qsv_frame->frame = av_frame_clone(picref);378 qsv_frame->frame = av_frame_clone(picref);
405 qsv_frame->surface = (mfxFrameSurface1 *)qsv_frame->frame->data[3];379 qsv_frame->surface = *(mfxFrameSurface1 *)qsv_frame->frame->data[3];
406 } else {380 } else {
407 /* make a copy if the input is not padded as libmfx requires */381 /* make a copy if the input is not padded as libmfx requires */
408 if (picref->height & 31 || picref->linesize[0] & 31) {382 if (picref->height & 31 || picref->linesize[0] & 31) {
@@ -425,27 +399,26 @@ static QSVFrame *submit_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *p · 16 unmodified lines
425 qsv_frame->frame = av_frame_clone(picref);399 qsv_frame->frame = av_frame_clone(picref);
426 400
427 if (map_frame_to_surface(qsv_frame->frame,401 if (map_frame_to_surface(qsv_frame->frame,
428 &qsv_frame->surface_internal) < 0) {402 &qsv_frame->surface) < 0) {
429 av_log(ctx, AV_LOG_ERROR, "Unsupported frame.\n");403 av_log(ctx, AV_LOG_ERROR, "Unsupported frame.\n");
430 return NULL;404 return NULL;
431 }405 }
432 qsv_frame->surface = &qsv_frame->surface_internal;
433 }406 }
434 407
435 qsv_frame->surface->Info = s->frame_infos[FF_INLINK_IDX(inlink)];408 qsv_frame->surface.Info = s->frame_infos[FF_INLINK_IDX(inlink)];
436 qsv_frame->surface->Data.TimeStamp = av_rescale_q(qsv_frame->frame->pts,409 qsv_frame->surface.Data.TimeStamp = av_rescale_q(qsv_frame->frame->pts,
437 inlink->time_base, default_tb);410 inlink->time_base, default_tb);
438 411
439 qsv_frame->surface->Info.PicStruct =412 qsv_frame->surface.Info.PicStruct =
440 !qsv_frame->frame->interlaced_frame ? MFX_PICSTRUCT_PROGRESSIVE :413 !qsv_frame->frame->interlaced_frame ? MFX_PICSTRUCT_PROGRESSIVE :
441 (qsv_frame->frame->top_field_first ? MFX_PICSTRUCT_FIELD_TFF :414 (qsv_frame->frame->top_field_first ? MFX_PICSTRUCT_FIELD_TFF :
442 MFX_PICSTRUCT_FIELD_BFF);415 MFX_PICSTRUCT_FIELD_BFF);
443 if (qsv_frame->frame->repeat_pict == 1)416 if (qsv_frame->frame->repeat_pict == 1)
444 qsv_frame->surface->Info.PicStruct |= MFX_PICSTRUCT_FIELD_REPEATED;417 qsv_frame->surface.Info.PicStruct |= MFX_PICSTRUCT_FIELD_REPEATED;
445 else if (qsv_frame->frame->repeat_pict == 2)418 else if (qsv_frame->frame->repeat_pict == 2)
446 qsv_frame->surface->Info.PicStruct |= MFX_PICSTRUCT_FRAME_DOUBLING;419 qsv_frame->surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_DOUBLING;
447 else if (qsv_frame->frame->repeat_pict == 4)420 else if (qsv_frame->frame->repeat_pict == 4)
448 qsv_frame->surface->Info.PicStruct |= MFX_PICSTRUCT_FRAME_TRIPLING;421 qsv_frame->surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_TRIPLING;
449 422
450 return qsv_frame;423 return qsv_frame;
451}424}
@@ -476,7 +449,7 @@ static QSVFrame *query_frame(QSVVPPContext *s, AVFilterLink *outlink) · 24 unmodified lines
476 return NULL;449 return NULL;
477 }450 }
478 451
479 out_frame->surface = (mfxFrameSurface1 *)out_frame->frame->data[3];452 out_frame->surface = *(mfxFrameSurface1 *)out_frame->frame->data[3];
480 } else {453 } else {
481 /* Get a frame with aligned dimensions.454 /* Get a frame with aligned dimensions.
482 * Libmfx need system memory being 128x64 aligned */455 * Libmfx need system memory being 128x64 aligned */
@@ -490,14 +463,12 @@ static QSVFrame *query_frame(QSVVPPContext *s, AVFilterLink *outlink) · 7 unmodified lines
490 out_frame->frame->height = outlink->h;463 out_frame->frame->height = outlink->h;
491 464
492 ret = map_frame_to_surface(out_frame->frame,465 ret = map_frame_to_surface(out_frame->frame,
493 &out_frame->surface_internal);466 &out_frame->surface);
494 if (ret < 0)467 if (ret < 0)
495 return NULL;468 return NULL;
496
497 out_frame->surface = &out_frame->surface_internal;
498 }469 }
499 470
500 out_frame->surface->Info = s->vpp_param.vpp.Out;471 out_frame->surface.Info = s->vpp_param.vpp.Out;
501 472
502 return out_frame;473 return out_frame;
503}474}
@@ -666,6 +637,16 @@ static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s) · 162 unmodified lines
666 return 0;637 return 0;
667}638}
668 639
640static unsigned int qsv_fifo_item_size(void)
641{
642 return sizeof(mfxSyncPoint) + sizeof(QSVFrame*);
643}
644
645static unsigned int qsv_fifo_size(const AVFifoBuffer* fifo)
646{
647 return av_fifo_size(fifo)/qsv_fifo_item_size();
648}
649
669int ff_qsvvpp_create(AVFilterContext *avctx, QSVVPPContext **vpp, QSVVPPParam *param)650int ff_qsvvpp_create(AVFilterContext *avctx, QSVVPPContext **vpp, QSVVPPParam *param)
670{651{
671 int i;652 int i;
@@ -738,7 +719,17 @@ int ff_qsvvpp_create(AVFilterContext *avctx, QSVVPPContext **vpp, QSVVPPParam *p · 66 unmodified lines
738 s->vpp_param.ExtParam = param->ext_buf;719 s->vpp_param.ExtParam = param->ext_buf;
739 }720 }
740 721
741 s->vpp_param.AsyncDepth = 1;722 s->got_frame = 0;
723
724 /** keep fifo size at least 1. Even when async_depth is 0, fifo is used. */
725 s->async_fifo = av_fifo_alloc((param->async_depth + 1) * qsv_fifo_item_size());
726 s->async_depth = param->async_depth;
727 if (!s->async_fifo) {
728 ret = AVERROR(ENOMEM);
729 goto failed;
730 }
731
732 s->vpp_param.AsyncDepth = param->async_depth;
742 733
743 if (IS_SYSTEM_MEMORY(s->in_mem_mode))734 if (IS_SYSTEM_MEMORY(s->in_mem_mode))
744 s->vpp_param.IOPattern |= MFX_IOPATTERN_IN_SYSTEM_MEMORY;735 s->vpp_param.IOPattern |= MFX_IOPATTERN_IN_SYSTEM_MEMORY;
@@ -793,6 +784,7 @@ int ff_qsvvpp_free(QSVVPPContext **vpp) · 48 unmodified lines
793 av_freep(&s->surface_ptrs_out);784 av_freep(&s->surface_ptrs_out);
794 av_freep(&s->ext_buffers);785 av_freep(&s->ext_buffers);
795 av_freep(&s->frame_infos);786 av_freep(&s->frame_infos);
787 av_fifo_free(s->async_fifo);
796 av_freep(vpp);788 av_freep(vpp);
797 789
798 return 0;790 return 0;
@@ -803,9 +795,29 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picr · 4 unmodified lines
803 AVFilterContext *ctx = inlink->dst;795 AVFilterContext *ctx = inlink->dst;
804 AVFilterLink *outlink = ctx->outputs[0];796 AVFilterLink *outlink = ctx->outputs[0];
805 mfxSyncPoint sync;797 mfxSyncPoint sync;
806 QSVFrame *in_frame, *out_frame;798 QSVFrame *in_frame, *out_frame, *tmp;
807 int ret, filter_ret;799 int ret, filter_ret;
808 800
801 while (s->eof && qsv_fifo_size(s->async_fifo)) {
802 av_fifo_generic_read(s->async_fifo, &tmp, sizeof(tmp), NULL);
803 av_fifo_generic_read(s->async_fifo, &sync, sizeof(sync), NULL);
804 if (MFXVideoCORE_SyncOperation(s->session, sync, 1000) < 0)
805 av_log(ctx, AV_LOG_WARNING, "Sync failed.\n");
806
807 filter_ret = s->filter_frame(outlink, tmp->frame);
808 if (filter_ret < 0) {
809 av_frame_free(&tmp->frame);
810 ret = filter_ret;
811 break;
812 }
813 tmp->queued--;
814 s->got_frame = 1;
815 tmp->frame = NULL;
816 };
817
818 if (!picref)
819 return 0;
820
809 in_frame = submit_frame(s, inlink, picref);821 in_frame = submit_frame(s, inlink, picref);
810 if (!in_frame) {822 if (!in_frame) {
811 av_log(ctx, AV_LOG_ERROR, "Failed to submit frame on input[%d]\n",823 av_log(ctx, AV_LOG_ERROR, "Failed to submit frame on input[%d]\n",
@@ -821,8 +833,8 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picr · 9 unmodified lines
821 }833 }
822 834
823 do {835 do {
824 ret = MFXVideoVPP_RunFrameVPPAsync(s->session, in_frame->surface,836 ret = MFXVideoVPP_RunFrameVPPAsync(s->session, &in_frame->surface,
825 out_frame->surface, NULL, &sync);837 &out_frame->surface, NULL, &sync);
826 if (ret == MFX_WRN_DEVICE_BUSY)838 if (ret == MFX_WRN_DEVICE_BUSY)
827 av_usleep(500);839 av_usleep(500);
828 } while (ret == MFX_WRN_DEVICE_BUSY);840 } while (ret == MFX_WRN_DEVICE_BUSY);
@@ -833,20 +845,33 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picr · 4 unmodified lines
833 ret = AVERROR(EAGAIN);845 ret = AVERROR(EAGAIN);
834 break;846 break;
835 }847 }
848 out_frame->frame->pts = av_rescale_q(out_frame->surface.Data.TimeStamp,
849 default_tb, outlink->time_base);
836 850
837 if (MFXVideoCORE_SyncOperation(s->session, sync, 1000) < 0)851 out_frame->queued++;
838 av_log(ctx, AV_LOG_WARNING, "Sync failed.\n");852 av_fifo_generic_write(s->async_fifo, &out_frame, sizeof(out_frame), NULL);
853 av_fifo_generic_write(s->async_fifo, &sync, sizeof(sync), NULL);
839 854
840 out_frame->frame->pts = av_rescale_q(out_frame->surface->Data.TimeStamp,
841 default_tb, outlink->time_base);
842 855
843 filter_ret = s->filter_frame(outlink, out_frame->frame);856 if (qsv_fifo_size(s->async_fifo) > s->async_depth) {
844 if (filter_ret < 0) {857 av_fifo_generic_read(s->async_fifo, &tmp, sizeof(tmp), NULL);
845 av_frame_free(&out_frame->frame);858 av_fifo_generic_read(s->async_fifo, &sync, sizeof(sync), NULL);
846 ret = filter_ret;859
847 break;860 do {
861 ret = MFXVideoCORE_SyncOperation(s->session, sync, 1000);
862 } while (ret == MFX_WRN_IN_EXECUTION);
863
864 filter_ret = s->filter_frame(outlink, tmp->frame);
865 if (filter_ret < 0) {
866 av_frame_free(&tmp->frame);
867 ret = filter_ret;
868 break;
869 }
870
871 tmp->queued--;
872 s->got_frame = 1;
873 tmp->frame = NULL;
848 }874 }
849 out_frame->frame = NULL;
850 } while(ret == MFX_ERR_MORE_SURFACE);875 } while(ret == MFX_ERR_MORE_SURFACE);
851 876
852 return ret;877 return ret;
libavfilter/qsvvpp.h+38−1
@@ -27,6 +27,7 @@ · 26 unmodified lines
27#include <mfx/mfxvideo.h>27#include <mfx/mfxvideo.h>
28 28
29#include "avfilter.h"29#include "avfilter.h"
30#include "libavutil/fifo.h"
30 31
31#define FF_INLINK_IDX(link) ((int)((link)->dstpad - (link)->dst->input_pads))32#define FF_INLINK_IDX(link) ((int)((link)->dstpad - (link)->dst->input_pads))
32#define FF_OUTLINK_IDX(link) ((int)((link)->srcpad - (link)->src->output_pads))33#define FF_OUTLINK_IDX(link) ((int)((link)->srcpad - (link)->src->output_pads))
@@ -39,7 +40,41 @@ · 6 unmodified lines
39 ((MFX_VERSION.Major > (MAJOR)) || \40 ((MFX_VERSION.Major > (MAJOR)) || \
40 (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))41 (MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
41 42
42typedef struct QSVVPPContext QSVVPPContext;43typedef struct QSVFrame {
44 AVFrame *frame;
45 mfxFrameSurface1 surface;
46 struct QSVFrame *next;
47 int queued;
48} QSVFrame;
49
50typedef struct QSVVPPContext {
51 mfxSession session;
52 int (*filter_frame) (AVFilterLink *outlink, AVFrame *frame); /**< callback */
53 enum AVPixelFormat out_sw_format; /**< Real output format */
54 mfxVideoParam vpp_param;
55 mfxFrameInfo *frame_infos; /**< frame info for each input */
56
57 /** members related to the input/output surface */
58 int in_mem_mode;
59 int out_mem_mode;
60 QSVFrame *in_frame_list;
61 QSVFrame *out_frame_list;
62 int nb_surface_ptrs_in;
63 int nb_surface_ptrs_out;
64 mfxFrameSurface1 **surface_ptrs_in;
65 mfxFrameSurface1 **surface_ptrs_out;
66
67 /** MFXVPP extern parameters */
68 mfxExtOpaqueSurfaceAlloc opaque_alloc;
69 mfxExtBuffer **ext_buffers;
70 int nb_ext_buffers;
71
72 int got_frame;
73 int async_depth;
74 int eof;
75 /** order with frame_out, sync */
76 AVFifoBuffer *async_fifo;
77} QSVVPPContext;
43 78
44typedef struct QSVVPPCrop {79typedef struct QSVVPPCrop {
45 int in_idx; ///< Input index80 int in_idx; ///< Input index
@@ -60,6 +95,8 @@ typedef struct QSVVPPParam { · 14 unmodified lines
60 /* Crop information for each input, if needed */95 /* Crop information for each input, if needed */
61 int num_crop;96 int num_crop;
62 QSVVPPCrop *crop;97 QSVVPPCrop *crop;
98
99 int async_depth;
63} QSVVPPParam;100} QSVVPPParam;
64 101
65/* create and initialize the QSV session */102/* create and initialize the QSV session */
libavfilter/vf_deinterlace_qsv.c+3−11
@@ -47,14 +47,6 @@ enum { · 46 unmodified lines
47 QSVDEINT_MORE_INPUT,47 QSVDEINT_MORE_INPUT,
48};48};
49 49
50typedef struct QSVFrame {
51 AVFrame *frame;
52 mfxFrameSurface1 surface;
53 int used;
54
55 struct QSVFrame *next;
56} QSVFrame;
57
58typedef struct QSVDeintContext {50typedef struct QSVDeintContext {
59 const AVClass *class;51 const AVClass *class;
60 52
@@ -376,7 +368,7 @@ static void clear_unused_frames(QSVDeintContext *s) · 315 unmodified lines
376 while (cur) {368 while (cur) {
377 if (!cur->surface.Data.Locked) {369 if (!cur->surface.Data.Locked) {
378 av_frame_free(&cur->frame);370 av_frame_free(&cur->frame);
379 cur->used = 0;371 cur->queued = 0;
380 }372 }
381 cur = cur->next;373 cur = cur->next;
382 }374 }
@@ -391,7 +383,7 @@ static int get_free_frame(QSVDeintContext *s, QSVFrame **f) · 8 unmodified lines
391 frame = s->work_frames;383 frame = s->work_frames;
392 last = &s->work_frames;384 last = &s->work_frames;
393 while (frame) {385 while (frame) {
394 if (!frame->used) {386 if (!frame->queued) {
395 *f = frame;387 *f = frame;
396 return 0;388 return 0;
397 }389 }
@@ -453,7 +445,7 @@ static int submit_frame(AVFilterContext *ctx, AVFrame *frame, · 55 unmodified lines
453 (AVRational){1, 90000});445 (AVRational){1, 90000});
454 446
455 *surface = &qf->surface;447 *surface = &qf->surface;
456 qf->used = 1;448 qf->queued = 1;
457 449
458 return 0;450 return 0;
459}451}
libavfilter/vf_vpp_qsv.c+61−14
@@ -32,6 +32,7 @@ · 31 unmodified lines
32#include "formats.h"32#include "formats.h"
33#include "internal.h"33#include "internal.h"
34#include "avfilter.h"34#include "avfilter.h"
35#include "filters.h"
35#include "libavcodec/avcodec.h"36#include "libavcodec/avcodec.h"
36#include "libavformat/avformat.h"37#include "libavformat/avformat.h"
37 38
@@ -93,6 +94,9 @@ typedef struct VPPContext{ · 55 unmodified lines
93 char *cx, *cy, *cw, *ch;94 char *cx, *cy, *cw, *ch;
94 char *ow, *oh;95 char *ow, *oh;
95 char *output_format_str;96 char *output_format_str;
97
98 int async_depth;
99 int eof;
96} VPPContext;100} VPPContext;
97 101
98static const AVOption options[] = {102static const AVOption options[] = {
@@ -128,6 +132,7 @@ static const AVOption options[] = { · 29 unmodified lines
128 { "h", "Output video height", OFFSET(oh), AV_OPT_TYPE_STRING, { .str="w*ch/cw" }, 0, 255, .flags = FLAGS },132 { "h", "Output video height", OFFSET(oh), AV_OPT_TYPE_STRING, { .str="w*ch/cw" }, 0, 255, .flags = FLAGS },
129 { "height", "Output video height", OFFSET(oh), AV_OPT_TYPE_STRING, { .str="w*ch/cw" }, 0, 255, .flags = FLAGS },133 { "height", "Output video height", OFFSET(oh), AV_OPT_TYPE_STRING, { .str="w*ch/cw" }, 0, 255, .flags = FLAGS },
130 { "format", "Output pixel format", OFFSET(output_format_str), AV_OPT_TYPE_STRING, { .str = "same" }, .flags = FLAGS },134 { "format", "Output pixel format", OFFSET(output_format_str), AV_OPT_TYPE_STRING, { .str = "same" }, .flags = FLAGS },
135 { "async_depth", "Internal parallelization depth, the higher the value the higher the latency.", OFFSET(async_depth), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, .flags = FLAGS },
131 136
132 { NULL }137 { NULL }
133};138};
@@ -303,6 +308,7 @@ static int config_output(AVFilterLink *outlink) · 169 unmodified lines
303 param.filter_frame = NULL;308 param.filter_frame = NULL;
304 param.num_ext_buf = 0;309 param.num_ext_buf = 0;
305 param.ext_buf = ext_buf;310 param.ext_buf = ext_buf;
311 param.async_depth = vpp->async_depth;
306 312
307 if (inlink->format == AV_PIX_FMT_QSV) {313 if (inlink->format == AV_PIX_FMT_QSV) {
308 if (!inlink->hw_frames_ctx || !inlink->hw_frames_ctx->data)314 if (!inlink->hw_frames_ctx || !inlink->hw_frames_ctx->data)
@@ -467,23 +473,64 @@ static int config_output(AVFilterLink *outlink) · 158 unmodified lines
467 return 0;473 return 0;
468}474}
469 475
470static int filter_frame(AVFilterLink *inlink, AVFrame *picref)476static int activate(AVFilterContext *ctx)
471{477{
472 int ret = 0;478 AVFilterLink *inlink = ctx->inputs[0];
473 AVFilterContext *ctx = inlink->dst;479 AVFilterLink *outlink = ctx->outputs[0];
474 VPPContext *vpp = inlink->dst->priv;480 VPPContext *s =ctx->priv;
475 AVFilterLink *outlink = ctx->outputs[0];481 QSVVPPContext *qsv = s->qsv;
476 482 AVFrame *in = NULL;
477 if (vpp->qsv) {483 int ret, status;
478 ret = ff_qsvvpp_filter_frame(vpp->qsv, inlink, picref);484 int64_t pts;
479 av_frame_free(&picref);485
486 FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
487
488 if (!s->eof) {
489 ret = ff_inlink_consume_frame(inlink, &in);
490 if (ret < 0)
491 return ret;
492
493 if (ff_inlink_acknowledge_status(inlink, &status, &pts)) {
494 if (status == AVERROR_EOF) {
495 s->eof = 1;
496 }
497 }
498 }
499
500 if (qsv) {
501 if (in || s->eof) {
502 qsv->eof = s->eof;
503 ret = ff_qsvvpp_filter_frame(qsv, inlink, in);
504 av_frame_free(&in);
505
506 if (s->eof) {
507 ff_outlink_set_status(outlink, status, pts);
508 return 0;
509 }
510
511 if (qsv->got_frame) {
512 qsv->got_frame = 0;
513 return ret;
514 }
515 }
480 } else {516 } else {
481 if (picref->pts != AV_NOPTS_VALUE)517 if (in) {
482 picref->pts = av_rescale_q(picref->pts, inlink->time_base, outlink->time_base);518 if (in->pts != AV_NOPTS_VALUE)
483 ret = ff_filter_frame(outlink, picref);519 in->pts = av_rescale_q(in->pts, inlink->time_base, outlink->time_base);
520
521 ret = ff_filter_frame(outlink, in);
522 return ret;
523 }
484 }524 }
485 525
486 return ret;526 if (s->eof) {
527 ff_outlink_set_status(outlink, status, pts);
528 return 0;
529 } else {
530 FF_FILTER_FORWARD_WANTED(outlink, inlink);
531 }
532
533 return FFERROR_NOT_READY;
487}534}
488 535
489static int query_formats(AVFilterContext *ctx)536static int query_formats(AVFilterContext *ctx)
@@ -531,7 +578,6 @@ static const AVFilterPad vpp_inputs[] = { · 41 unmodified lines
531 .name = "default",578 .name = "default",
532 .type = AVMEDIA_TYPE_VIDEO,579 .type = AVMEDIA_TYPE_VIDEO,
533 .config_props = config_input,580 .config_props = config_input,
534 .filter_frame = filter_frame,
535 },581 },
536 { NULL }582 { NULL }
537};583};
@@ -554,6 +600,7 @@ AVFilter ff_vf_vpp_qsv = { · 16 unmodified lines
554 .uninit = vpp_uninit,600 .uninit = vpp_uninit,
555 .inputs = vpp_inputs,601 .inputs = vpp_inputs,
556 .outputs = vpp_outputs,602 .outputs = vpp_outputs,
603 .activate = activate,
557 .priv_class = &vpp_class,604 .priv_class = &vpp_class,
558 .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,605 .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
559};606};

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