Skip to content

Commit

Permalink
video: hwdec: introduce AV_CODEC_HW_CONFIG_METHOD_INTERNAL
Browse files Browse the repository at this point in the history
  • Loading branch information
boogieeeee committed Dec 31, 2024
1 parent 7562a79 commit d845c5c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
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

0 comments on commit d845c5c

Please sign in to comment.