summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtem Galin <[email protected]>2020-07-16 12:31:40 +0100
committerScott <[email protected]>2020-07-20 16:56:43 +0100
commit990654edba2cd1fd1c81b28fe60e126ee3ee8ef9 (patch)
tree583cf44c73a1458adaff10ea4271f5ba2e77131b
parentcf4c834504cdaf23c845d164e0b61237e4159e41 (diff)
qsv: move hw filters flag check into function
-rw-r--r--libhb/avfilter.c6
-rw-r--r--libhb/cropscale.c5
-rw-r--r--libhb/decavcodec.c2
-rw-r--r--libhb/enc_qsv.c6
-rw-r--r--libhb/fifo.c2
-rw-r--r--libhb/handbrake/qsv_common.h1
-rw-r--r--libhb/hbavfilter.c9
-rw-r--r--libhb/qsv_common.c9
8 files changed, 21 insertions, 19 deletions
diff --git a/libhb/avfilter.c b/libhb/avfilter.c
index dd2fb7b02..4fb45de2a 100644
--- a/libhb/avfilter.c
+++ b/libhb/avfilter.c
@@ -240,9 +240,7 @@ static hb_buffer_t* filterFrame( hb_filter_private_t * pv, hb_buffer_t * in )
#if HB_PROJECT_FEATURE_QSV
mfxFrameSurface1 *surface = NULL;
// We need to keep surface pointer because hb_avfilter_add_buf set it to 0 after in ffmpeg call
- int use_qsv_filters = (pv->input.job && pv->input.job->qsv.ctx &&
- pv->input.job->qsv.ctx->qsv_filters_are_enabled && in && in->qsv_details.frame) ? 1 : 0;
- if (use_qsv_filters)
+ if (hb_qsv_hw_filters_are_enabled(pv->input.job) && in && in->qsv_details.frame)
{
surface = (mfxFrameSurface1 *)in->qsv_details.frame->data[3];
}
@@ -262,7 +260,7 @@ static hb_buffer_t* filterFrame( hb_filter_private_t * pv, hb_buffer_t * in )
buf = hb_avfilter_get_buf(pv->graph);
}
#if HB_PROJECT_FEATURE_QSV
- if (use_qsv_filters && surface)
+ if (hb_qsv_hw_filters_are_enabled(pv->input.job) && surface)
{
hb_qsv_release_surface_from_pool_by_surface_pointer(pv->input.job->qsv.ctx->hb_dec_qsv_frames_ctx, surface);
}
diff --git a/libhb/cropscale.c b/libhb/cropscale.c
index c2beab9b4..15ed199a4 100644
--- a/libhb/cropscale.c
+++ b/libhb/cropscale.c
@@ -92,8 +92,7 @@ static int crop_scale_init(hb_filter_object_t * filter, hb_filter_init_t * init)
hb_dict_t * avsettings = hb_dict_init();
#if HB_PROJECT_FEATURE_QSV
- int use_qsv_filters = (init->job && init->job->qsv.ctx && init->job->qsv.ctx->qsv_filters_are_enabled) ? 1 : 0;
- if (use_qsv_filters)
+ if (hb_qsv_hw_filters_are_enabled(init->job))
{
hb_dict_set_int(avsettings, "w", width);
hb_dict_set_int(avsettings, "h", height);
@@ -169,7 +168,7 @@ static int crop_scale_init(hb_filter_object_t * filter, hb_filter_init_t * init)
avsettings = hb_dict_init();
#if HB_PROJECT_FEATURE_QSV
- if (!use_qsv_filters)
+ if (!hb_qsv_hw_filters_are_enabled(init->job))
#endif
{
// TODO: Support other pix formats
diff --git a/libhb/decavcodec.c b/libhb/decavcodec.c
index 60c213584..0e120f763 100644
--- a/libhb/decavcodec.c
+++ b/libhb/decavcodec.c
@@ -1176,7 +1176,7 @@ int reinit_video_filters(hb_work_private_t * pv)
{
settings = hb_dict_init();
#if HB_PROJECT_FEATURE_QSV
- if (pv->job && pv->job->qsv.ctx && pv->job->qsv.ctx->qsv_filters_are_enabled)
+ if (hb_qsv_hw_filters_are_enabled(pv->job))
{
hb_dict_set(settings, "w", hb_value_int(orig_width));
hb_dict_set(settings, "h", hb_value_int(orig_height));
diff --git a/libhb/enc_qsv.c b/libhb/enc_qsv.c
index 45e6e8f15..2b5346d54 100644
--- a/libhb/enc_qsv.c
+++ b/libhb/enc_qsv.c
@@ -802,7 +802,7 @@ int qsv_enc_init(hb_work_private_t *pv)
.Free = hb_qsv_frame_free,
};
- if (pv->job->qsv.ctx->qsv_filters_are_enabled)
+ if (hb_qsv_hw_filters_are_enabled(pv->job))
{
frame_allocator.pthis = pv->job->qsv.ctx->hb_vpp_qsv_frames_ctx;
}
@@ -2159,7 +2159,7 @@ static int qsv_enc_work(hb_work_private_t *pv,
mfxFrameSurface1 *surface = task->stage->in.p_surface;
if(!pv->is_sys_mem && surface)
{
- if (pv->job->qsv.ctx->qsv_filters_are_enabled)
+ if (hb_qsv_hw_filters_are_enabled(pv->job))
{
hb_qsv_release_surface_from_pool(pv->job->qsv.ctx->hb_vpp_qsv_frames_ctx, surface->Data.MemId);
}
@@ -2264,7 +2264,7 @@ int encqsvWork(hb_work_object_t *w, hb_buffer_t **buf_in, hb_buffer_t **buf_out)
hb_qsv_get_free_surface_from_pool_with_range(pv->job->qsv.ctx->hb_dec_qsv_frames_ctx, HB_POOL_SURFACE_SIZE - HB_POOL_ENCODER_SIZE, HB_POOL_SURFACE_SIZE, &mid, &surface);
}
- if (pv->job->qsv.ctx->qsv_filters_are_enabled)
+ if (hb_qsv_hw_filters_are_enabled(pv->job))
{
hb_qsv_replace_surface_mid(pv->job->qsv.ctx->hb_vpp_qsv_frames_ctx, mid, surface);
}
diff --git a/libhb/fifo.c b/libhb/fifo.c
index 4a75d06bb..14da3a9f2 100644
--- a/libhb/fifo.c
+++ b/libhb/fifo.c
@@ -728,7 +728,7 @@ void hb_buffer_close( hb_buffer_t ** _b )
if(b->qsv_details.frame)
{
mfxFrameSurface1 *surface = (mfxFrameSurface1*)b->qsv_details.frame->data[3];
- if(surface)
+ if(surface && b->qsv_details.ctx)
{
if(b->qsv_details.ctx->qsv_filters_are_enabled)
{
diff --git a/libhb/handbrake/qsv_common.h b/libhb/handbrake/qsv_common.h
index 1e437831b..c70c0c53f 100644
--- a/libhb/handbrake/qsv_common.h
+++ b/libhb/handbrake/qsv_common.h
@@ -267,6 +267,7 @@ typedef struct HBQSVFramesContext {
/* Full QSV pipeline helpers */
int hb_qsv_init(int coded_width, int coded_height, enum AVPixelFormat sw_pix_fmt, int extra_hw_frames, AVBufferRef **out_hw_frames_ctx);
int hb_create_ffmpeg_pool(int coded_width, int coded_height, enum AVPixelFormat sw_pix_fmt, int pool_size, int extra_hw_frames, AVBufferRef **out_hw_frames_ctx);
+int hb_qsv_hw_filters_are_enabled(hb_job_t *job);
void hb_qsv_update_frames_context(hb_job_t *job);
int hb_qsv_full_path_is_enabled(hb_job_t *job);
AVBufferRef *hb_qsv_create_mids(AVBufferRef *hw_frames_ref);
diff --git a/libhb/hbavfilter.c b/libhb/hbavfilter.c
index d3364a6a1..80ec654e0 100644
--- a/libhb/hbavfilter.c
+++ b/libhb/hbavfilter.c
@@ -99,8 +99,7 @@ hb_avfilter_graph_init(hb_value_t * settings, hb_filter_init_t * init)
goto fail;
}
#if HB_PROJECT_FEATURE_QSV
- int use_qsv_filters = (graph->job && graph->job->qsv.ctx && graph->job->qsv.ctx->qsv_filters_are_enabled) ? 1 : 0;
- if (!use_qsv_filters)
+ if (!hb_qsv_hw_filters_are_enabled(graph->job))
#endif
{
av_opt_set(graph->avgraph, "scale_sws_opts", "lanczos+accurate_rnd", 0);
@@ -116,7 +115,7 @@ hb_avfilter_graph_init(hb_value_t * settings, hb_filter_init_t * init)
AVBufferSrcParameters *par = 0;
// Build filter input
#if HB_PROJECT_FEATURE_QSV
- if (use_qsv_filters)
+ if (hb_qsv_hw_filters_are_enabled(graph->job))
{
par = av_buffersrc_parameters_alloc();
init->pix_fmt = AV_PIX_FMT_QSV;
@@ -271,7 +270,7 @@ int hb_avfilter_add_buf(hb_avfilter_graph_t * graph, hb_buffer_t * in)
if (in != NULL)
{
#if HB_PROJECT_FEATURE_QSV
- if (graph->job && graph->job->qsv.ctx && graph->job->qsv.ctx->qsv_filters_are_enabled)
+ if (hb_qsv_hw_filters_are_enabled(graph->job))
{
hb_video_buffer_to_avframe(in->qsv_details.frame, in);
return hb_avfilter_add_frame(graph, in->qsv_details.frame);
@@ -298,7 +297,7 @@ hb_buffer_t * hb_avfilter_get_buf(hb_avfilter_graph_t * graph)
{
hb_buffer_t * buf;
#if HB_PROJECT_FEATURE_QSV
- if (graph->job && graph->job->qsv.ctx && graph->job->qsv.ctx->qsv_filters_are_enabled)
+ if (hb_qsv_hw_filters_are_enabled(graph->job))
{
buf = hb_qsv_copy_frame(graph->job, graph->frame, 1);
hb_avframe_set_video_buffer_flags(buf, graph->frame, graph->out_time_base);
diff --git a/libhb/qsv_common.c b/libhb/qsv_common.c
index e3971a02e..215a2e2cd 100644
--- a/libhb/qsv_common.c
+++ b/libhb/qsv_common.c
@@ -991,6 +991,11 @@ int hb_qsv_decode_is_enabled(hb_job_t *job)
static int hb_dxva2_device_check();
static int hb_d3d11va_device_check();
+int hb_qsv_hw_filters_are_enabled(hb_job_t *job)
+{
+ return job && job->qsv.ctx && job->qsv.ctx->qsv_filters_are_enabled;
+}
+
void hb_qsv_update_frames_context(hb_job_t *job)
{
qsv_filters_are_enabled = job->qsv.ctx->qsv_filters_are_enabled;
@@ -2851,7 +2856,7 @@ hb_buffer_t* hb_qsv_copy_frame(hb_job_t *job, AVFrame *frame, int is_vpp)
hb_qsv_frames_ctx = job->qsv.ctx->hb_dec_qsv_frames_ctx;
}
- if (!is_vpp && job->qsv.ctx->qsv_filters_are_enabled)
+ if (!is_vpp && hb_qsv_hw_filters_are_enabled(job))
{
ret = hb_qsv_get_free_surface_from_pool(hb_qsv_frames_ctx, out->qsv_details.frame, &mid);
if (ret < 0)
@@ -2867,7 +2872,7 @@ hb_buffer_t* hb_qsv_copy_frame(hb_job_t *job, AVFrame *frame, int is_vpp)
{
mfxFrameSurface1* input_surface = (mfxFrameSurface1*)frame->data[3];
// copy all surface fields
- if (job->qsv.ctx->qsv_filters_are_enabled)
+ if (hb_qsv_hw_filters_are_enabled(job))
{
mfxMemId mem = output_surface->Data.MemId;
*output_surface = *input_surface;