Skip to content

Commit

Permalink
qsv: enable 10bit for hw scale/resize filters
Browse files Browse the repository at this point in the history
  • Loading branch information
galinart authored and sr55 committed Nov 29, 2020
1 parent 552f957 commit 938484b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 17 deletions.
2 changes: 1 addition & 1 deletion libhb/cropscale.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static int crop_scale_init(hb_filter_object_t * filter, hb_filter_init_t * init)
hb_dict_set_int(avsettings, "w", width);
hb_dict_set_int(avsettings, "h", height);
hb_dict_set(avfilter, "scale_qsv", avsettings);
int result = hb_create_ffmpeg_pool(init->job, width, height, AV_PIX_FMT_NV12, HB_QSV_POOL_SURFACE_SIZE, 0, &init->job->qsv.ctx->hb_vpp_qsv_frames_ctx->hw_frames_ctx);
int result = hb_create_ffmpeg_pool(init->job, width, height, init->pix_fmt, HB_QSV_POOL_SURFACE_SIZE, 0, &init->job->qsv.ctx->hb_vpp_qsv_frames_ctx->hw_frames_ctx);
if (result < 0)
{
hb_error("hb_create_ffmpeg_pool vpp allocation failed");
Expand Down
6 changes: 3 additions & 3 deletions libhb/hbavfilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,17 @@ hb_avfilter_graph_init(hb_value_t * settings, hb_filter_init_t * init)
if (hb_qsv_hw_filters_are_enabled(graph->job))
{
par = av_buffersrc_parameters_alloc();
init->pix_fmt = AV_PIX_FMT_QSV;
filter_args = hb_strdup_printf(
"video_size=%dx%d:pix_fmt=%d:sar=%d/%d:"
"time_base=%d/%d:frame_rate=%d/%d",
init->geometry.width, init->geometry.height, init->pix_fmt,
init->geometry.width, init->geometry.height, AV_PIX_FMT_QSV,
init->geometry.par.num, init->geometry.par.den,
init->time_base.num, init->time_base.den,
init->vrate.num, init->vrate.den);

AVBufferRef *hb_hw_frames_ctx = NULL;
result = hb_create_ffmpeg_pool(graph->job, init->geometry.width, init->geometry.height, AV_PIX_FMT_NV12, 32, 0, &hb_hw_frames_ctx);

result = hb_create_ffmpeg_pool(graph->job, init->geometry.width, init->geometry.height, init->pix_fmt, 32, 0, &hb_hw_frames_ctx);
if (result < 0)
{
hb_error("hb_create_ffmpeg_pool failed");
Expand Down
5 changes: 4 additions & 1 deletion libhb/qsv_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,7 @@ int hb_qsv_full_path_is_enabled(hb_job_t *job)
{
static int device_check_completed = 0;
static int device_check_succeded = 0;
int codecs_exceptions = 0;
int qsv_full_path_is_enabled = 0;

if(!device_check_completed)
Expand All @@ -1070,9 +1071,11 @@ int hb_qsv_full_path_is_enabled(hb_job_t *job)
device_check_completed = 1;
}

codecs_exceptions = (job->title->pix_fmt == AV_PIX_FMT_YUV420P10 && job->vcodec == HB_VCODEC_QSV_H264);

qsv_full_path_is_enabled = (hb_qsv_decode_is_enabled(job) &&
hb_qsv_info_get(job->vcodec) &&
device_check_succeded && !job->qsv.ctx->num_cpu_filters);
device_check_succeded && !job->qsv.ctx->num_cpu_filters) && !codecs_exceptions;
return qsv_full_path_is_enabled;
}

Expand Down
51 changes: 39 additions & 12 deletions libhb/work.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ void hb_display_job_info(hb_job_t *job)
#if HB_PROJECT_FEATURE_QSV
if (hb_qsv_decode_is_enabled(job))
{
hb_log(" + decoder: %s",
hb_qsv_decode_get_codec_name(title->video_codec_param));
hb_log(" + decoder: %s %d-bit",
hb_qsv_decode_get_codec_name(title->video_codec_param), hb_get_bit_depth(job->pix_fmt));
}
else
#endif
Expand Down Expand Up @@ -804,7 +804,27 @@ static int bit_depth_is_supported(hb_job_t * job, int bit_depth)
static int get_best_pix_ftm(hb_job_t * job)
{
int bit_depth = hb_get_bit_depth(job->title->pix_fmt);

#if HB_PROJECT_FEATURE_QSV && (defined( _WIN32 ) || defined( __MINGW32__ ))
if (hb_qsv_info_get(job->vcodec))
{
if (hb_qsv_full_path_is_enabled(job))
{
if (job->title->pix_fmt == AV_PIX_FMT_YUV420P10 && job->vcodec == HB_VCODEC_QSV_H265_10BIT)
{
return AV_PIX_FMT_P010LE;
}
else
{
return AV_PIX_FMT_NV12;
}
}
else
{
// system memory usage: QSV encoder only or QSV decoder + SW filters + QSV encoder
return AV_PIX_FMT_YUV420P;
}
}
#endif
if (bit_depth >= 12 && bit_depth_is_supported(job, 12))
{
return AV_PIX_FMT_YUV420P12;
Expand Down Expand Up @@ -1365,7 +1385,22 @@ static void do_job(hb_job_t *job)
memset(interjob, 0, sizeof(*interjob));
interjob->sequence_id = job->sequence_id;
}

#if HB_PROJECT_FEATURE_QSV
if (hb_qsv_is_enabled(job))
{
job->qsv.ctx = hb_qsv_context_init();
#if HB_PROJECT_FEATURE_QSV && (defined( _WIN32 ) || defined( __MINGW32__ ))
if (hb_qsv_full_path_is_enabled(job))
{
// Temporary workaround for the driver in case when low_power mode is disabled, should be removed later
if (job->title->pix_fmt == AV_PIX_FMT_YUV420P10 && job->vcodec == HB_VCODEC_QSV_H265)
{
job->vcodec = HB_VCODEC_QSV_H265_10BIT;
}
}
#endif
}
#endif
job->list_work = hb_list_init();
w = hb_get_work(job->h, WORK_READER);
hb_list_add(job->list_work, w);
Expand All @@ -1392,14 +1427,6 @@ static void do_job(hb_job_t *job)
*job->die = 1;
goto cleanup;
}

#if HB_PROJECT_FEATURE_QSV
if (hb_qsv_is_enabled(job))
{
job->qsv.ctx = hb_qsv_context_init();
}
#endif

// Filters have an effect on settings.
// So initialize the filters and update the job.
if (job->list_filter && hb_list_count(job->list_filter))
Expand Down

0 comments on commit 938484b

Please sign in to comment.