int hw_device_setup_for_decode(InputStream *ist)
{
    enum AVHWDeviceType type;
    HWDevice *dev;
    const char *type_name;
    int err;
    if (ist->hwaccel_device) {
        dev = hw_device_get_by_name(ist->hwaccel_device);
        if (!dev) {
            char *tmp;
            size_t len;
            type = hw_device_match_type_by_hwaccel(ist->hwaccel_id);
            if (type == AV_HWDEVICE_TYPE_NONE) {
                return 0;
            }
            type_name = av_hwdevice_get_type_name(type);
            len = strlen(type_name) + 1 +
                  strlen(ist->hwaccel_device) + 1;
            tmp = av_malloc(len);
            if (!tmp)
                return AVERROR(ENOMEM);
            snprintf(tmp, len, "%s:%s", type_name, ist->hwaccel_device);
            err = hw_device_init_from_string(tmp, &dev);
            av_free(tmp);
            if (err < 0)
                return err;
        }
    } else {
        if (ist->hwaccel_id != HWACCEL_NONE)
            type = hw_device_match_type_by_hwaccel(ist->hwaccel_id);
        else
            type = hw_device_match_type_in_name(ist->dec->name);
        if (type != AV_HWDEVICE_TYPE_NONE) {
            dev = hw_device_get_by_type(type);
            if (!dev) {
                hw_device_init_from_string(av_hwdevice_get_type_name(type),
                                           &dev);
            }
        } else {
            return 0;
        }
    }
    if (!dev) {
        av_log(ist->dec_ctx, AV_LOG_WARNING, "No device available "
               "for decoder (device type %s for codec %s).\n",
               av_hwdevice_get_type_name(type), ist->dec->name);
        return 0;
    }
    ist->dec_ctx->hw_device_ctx = av_buffer_ref(dev->device_ref);
    if (!ist->dec_ctx->hw_device_ctx)
        return AVERROR(ENOMEM);
    return 0;
}
['int hw_device_setup_for_decode(InputStream *ist)\n{\n    enum AVHWDeviceType type;\n    HWDevice *dev;\n    const char *type_name;\n    int err;\n    if (ist->hwaccel_device) {\n        dev = hw_device_get_by_name(ist->hwaccel_device);\n        if (!dev) {\n            char *tmp;\n            size_t len;\n            type = hw_device_match_type_by_hwaccel(ist->hwaccel_id);\n            if (type == AV_HWDEVICE_TYPE_NONE) {\n                return 0;\n            }\n            type_name = av_hwdevice_get_type_name(type);\n            len = strlen(type_name) + 1 +\n                  strlen(ist->hwaccel_device) + 1;\n            tmp = av_malloc(len);\n            if (!tmp)\n                return AVERROR(ENOMEM);\n            snprintf(tmp, len, "%s:%s", type_name, ist->hwaccel_device);\n            err = hw_device_init_from_string(tmp, &dev);\n            av_free(tmp);\n            if (err < 0)\n                return err;\n        }\n    } else {\n        if (ist->hwaccel_id != HWACCEL_NONE)\n            type = hw_device_match_type_by_hwaccel(ist->hwaccel_id);\n        else\n            type = hw_device_match_type_in_name(ist->dec->name);\n        if (type != AV_HWDEVICE_TYPE_NONE) {\n            dev = hw_device_get_by_type(type);\n            if (!dev) {\n                hw_device_init_from_string(av_hwdevice_get_type_name(type),\n                                           &dev);\n            }\n        } else {\n            return 0;\n        }\n    }\n    if (!dev) {\n        av_log(ist->dec_ctx, AV_LOG_WARNING, "No device available "\n               "for decoder (device type %s for codec %s).\\n",\n               av_hwdevice_get_type_name(type), ist->dec->name);\n        return 0;\n    }\n    ist->dec_ctx->hw_device_ctx = av_buffer_ref(dev->device_ref);\n    if (!ist->dec_ctx->hw_device_ctx)\n        return AVERROR(ENOMEM);\n    return 0;\n}', 'HWDevice *hw_device_get_by_name(const char *name)\n{\n    int i;\n    for (i = 0; i < nb_hw_devices; i++) {\n        if (!strcmp(hw_devices[i]->name, name))\n            return hw_devices[i];\n    }\n    return NULL;\n}', 'static enum AVHWDeviceType hw_device_match_type_by_hwaccel(enum HWAccelID hwaccel_id)\n{\n    int i;\n    if (hwaccel_id == HWACCEL_NONE)\n        return AV_HWDEVICE_TYPE_NONE;\n    for (i = 0; hwaccels[i].name; i++) {\n        if (hwaccels[i].id == hwaccel_id)\n            return hwaccels[i].device_type;\n    }\n    return AV_HWDEVICE_TYPE_NONE;\n}', 'const char *av_hwdevice_get_type_name(enum AVHWDeviceType type)\n{\n    if (type > AV_HWDEVICE_TYPE_NONE &&\n        type < FF_ARRAY_ELEMS(hw_type_names))\n        return hw_type_names[type];\n    else\n        return NULL;\n}']