Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

video: hwdec: fallback to hw_ingmtfmt match if no hw_device matches #15586

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions video/decode/vd_lavc.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ struct hwdec_info {
enum AVPixelFormat pix_fmt; // if not NONE, select in get_format
bool use_hw_frames; // set AVCodecContext.hw_frames_ctx
bool use_hw_device; // set AVCodecContext.hw_device_ctx
bool use_hw_internal; // set AVCodecContext.hw_device_ctx
unsigned int flags; // HWDEC_FLAG_*

// for internal sorting
Expand Down Expand Up @@ -340,7 +341,8 @@ static void add_all_hwdec_methods(struct hwdec_info **infos, int *num_infos)
break;

if ((cfg->methods & AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX) ||
(cfg->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX))
(cfg->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX) ||
(cfg->methods & AV_CODEC_HW_CONFIG_METHOD_INTERNAL))
{
struct hwdec_info info = info_template;
info.lavc_device = cfg->device_type;
Expand All @@ -361,6 +363,8 @@ static void add_all_hwdec_methods(struct hwdec_info **infos, int *num_infos)
// those, so always use hw_frames_ctx if offered.
if (cfg->methods & AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX) {
info.use_hw_frames = true;
} else if (cfg->methods & AV_CODEC_HW_CONFIG_METHOD_INTERNAL) {
info.use_hw_internal = true;
} else {
info.use_hw_device = true;
}
Expand Down Expand Up @@ -458,7 +462,7 @@ static AVBufferRef *hwdec_create_dev(struct mp_filter *vd,

const struct mp_hwdec_ctx *hw_ctx =
hwdec_devices_get_by_imgfmt_and_type(ctx->hwdec_devs, imgfmt,
hwdec->lavc_device);
hwdec->use_hw_internal ? AV_HWDEVICE_TYPE_NONE : hwdec->lavc_device);

if (hw_ctx && hw_ctx->av_device_ref)
return av_buffer_ref(hw_ctx->av_device_ref);
Expand Down
12 changes: 10 additions & 2 deletions video/hwdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,16 @@ struct mp_hwdec_ctx *hwdec_devices_get_by_imgfmt_and_type(struct mp_hwdec_device
struct mp_hwdec_ctx *dev = devs->hwctxs[n];
AVHWDeviceContext *hw_device_ctx =
dev->av_device_ref ? (AVHWDeviceContext *)dev->av_device_ref->data : NULL;
if (dev->hw_imgfmt == hw_imgfmt &&
(!hw_device_ctx || hw_device_ctx->type == device_type)) {

if (dev->hw_imgfmt != hw_imgfmt)
continue;

// ignore device_type if requested device is AV_HWDEVICE_TYPE_NONE
if (device_type == AV_HWDEVICE_TYPE_NONE){
res = dev;
break;
}
if (!hw_device_ctx || hw_device_ctx->type == device_type) {
res = dev;
break;
}
Expand Down
Loading