int hw_device_setup_for_decode(InputStream *ist)

{

    enum AVHWDeviceType type;

    HWDevice *dev;

    int err;



    if (ist->hwaccel_device) {

        dev = hw_device_get_by_name(ist->hwaccel_device);

        if (!dev) {

            char *tmp;

            type = hw_device_match_type_by_hwaccel(ist->hwaccel_id);

            if (type == AV_HWDEVICE_TYPE_NONE) {

                // No match - this isn't necessarily invalid, though,

                // because an explicit device might not be needed or

                // the hwaccel setup could be handled elsewhere.

                return 0;

            }

            tmp = av_asprintf("%s:%s", av_hwdevice_get_type_name(type),

                              ist->hwaccel_device);

            if (!tmp)

                return AVERROR(ENOMEM);

            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 {

            // No device required.

            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)

{

    enum AVHWDeviceType type;

    HWDevice *dev;

    int err;



    if (ist->hwaccel_device) {

        dev = hw_device_get_by_name(ist->hwaccel_device);

        if (!dev) {

            char *tmp;

            type = hw_device_match_type_by_hwaccel(ist->hwaccel_id);

            if (type == AV_HWDEVICE_TYPE_NONE) {

                

                

                

                return 0;

            }

            tmp = av_asprintf("%s:%s", av_hwdevice_get_type_name(type),

                              ist->hwaccel_device);

            if (!tmp)

                return AVERROR(ENOMEM);

            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 FUNC_0(InputStream *VAR_0)

{

    enum AVHWDeviceType VAR_1;

    HWDevice *dev;

    int VAR_2;



    if (VAR_0->hwaccel_device) {

        dev = hw_device_get_by_name(VAR_0->hwaccel_device);

        if (!dev) {

            char *VAR_3;

            VAR_1 = hw_device_match_type_by_hwaccel(VAR_0->hwaccel_id);

            if (VAR_1 == AV_HWDEVICE_TYPE_NONE) {

                

                

                

                return 0;

            }

            VAR_3 = av_asprintf("%s:%s", av_hwdevice_get_type_name(VAR_1),

                              VAR_0->hwaccel_device);

            if (!VAR_3)

                return AVERROR(ENOMEM);

            VAR_2 = hw_device_init_from_string(VAR_3, &dev);

            av_free(VAR_3);

            if (VAR_2 < 0)

                return VAR_2;

        }

    } else {

        if (VAR_0->hwaccel_id != HWACCEL_NONE)

            VAR_1 = hw_device_match_type_by_hwaccel(VAR_0->hwaccel_id);

        else

            VAR_1 = hw_device_match_type_in_name(VAR_0->dec->name);

        if (VAR_1 != AV_HWDEVICE_TYPE_NONE) {

            dev = hw_device_get_by_type(VAR_1);

            if (!dev) {

                hw_device_init_from_string(av_hwdevice_get_type_name(VAR_1),

                                           &dev);

            }

        } else {

            

            return 0;

        }

    }



    if (!dev) {

        av_log(VAR_0->dec_ctx, AV_LOG_WARNING, "No device available "

               "for decoder (device VAR_1 %s for codec %s).\n",

               av_hwdevice_get_type_name(VAR_1), VAR_0->dec->name);

        return 0;

    }



    VAR_0->dec_ctx->hw_device_ctx = av_buffer_ref(dev->device_ref);

    if (!VAR_0->dec_ctx->hw_device_ctx)

        return AVERROR(ENOMEM);



    return 0;

}

int FUNC_0(InputStream *VAR_0)
{ enum AVHWDeviceType VAR_1; HWDevice *dev; int VAR_2; if (VAR_0->hwaccel_device) { dev = hw_device_get_by_name(VAR_0->hwaccel_device); if (!dev) { char *VAR_3; VAR_1 = hw_device_match_type_by_hwaccel(VAR_0->hwaccel_id); if (VAR_1 == AV_HWDEVICE_TYPE_NONE) { return 0; } VAR_3 = av_asprintf("%s:%s", av_hwdevice_get_type_name(VAR_1),
VAR_0->hwaccel_device); if (!VAR_3)
return AVERROR(ENOMEM); VAR_2 = hw_device_init_from_string(VAR_3, &dev); av_free(VAR_3); if (VAR_2 < 0)
return VAR_2; } } else { if (VAR_0->hwaccel_id != HWACCEL_NONE)
VAR_1 = hw_device_match_type_by_hwaccel(VAR_0->hwaccel_id); else
VAR_1 = hw_device_match_type_in_name(VAR_0->dec->name); if (VAR_1 != AV_HWDEVICE_TYPE_NONE) { dev = hw_device_get_by_type(VAR_1); if (!dev) { hw_device_init_from_string(av_hwdevice_get_type_name(VAR_1),
&dev); } } else { return 0; } } if (!dev) { av_log(VAR_0->dec_ctx, AV_LOG_WARNING, "No device available "
"for decoder (device VAR_1 %s for codec %s).\n",
av_hwdevice_get_type_name(VAR_1), VAR_0->dec->name); return 0; } VAR_0->dec_ctx->hw_device_ctx = av_buffer_ref(dev->device_ref); if (!VAR_0->dec_ctx->hw_device_ctx)
return AVERROR(ENOMEM); return 0; }