static int dxva2_get_decoder_configuration(AVCodecContext *s, const GUID *device_guid,

                                           const DXVA2_VideoDesc *desc,

                                           DXVA2_ConfigPictureDecode *config)

{

    InputStream  *ist = s->opaque;

    int loglevel = (ist->hwaccel_id == HWACCEL_AUTO) ? AV_LOG_VERBOSE : AV_LOG_ERROR;

    DXVA2Context *ctx = ist->hwaccel_ctx;

    unsigned cfg_count = 0, best_score = 0;

    DXVA2_ConfigPictureDecode *cfg_list = NULL;

    DXVA2_ConfigPictureDecode best_cfg = {{0}};

    HRESULT hr;

    int i;



    hr = IDirectXVideoDecoderService_GetDecoderConfigurations(ctx->decoder_service, device_guid, desc, NULL, &cfg_count, &cfg_list);

    if (FAILED(hr)) {

        av_log(NULL, loglevel, "Unable to retrieve decoder configurations\n");

        return AVERROR(EINVAL);

    }



    for (i = 0; i < cfg_count; i++) {

        DXVA2_ConfigPictureDecode *cfg = &cfg_list[i];



        unsigned score;

        if (cfg->ConfigBitstreamRaw == 1)

            score = 1;

        else if (s->codec_id == AV_CODEC_ID_H264 && cfg->ConfigBitstreamRaw == 2)

            score = 2;

        else

            continue;

        if (IsEqualGUID(&cfg->guidConfigBitstreamEncryption, &DXVA2_NoEncrypt))

            score += 16;

        if (score > best_score) {

            best_score = score;

            best_cfg   = *cfg;

        }

    }

    CoTaskMemFree(cfg_list);



    if (!best_score) {

        av_log(NULL, loglevel, "No valid decoder configuration available\n");

        return AVERROR(EINVAL);

    }



    *config = best_cfg;

    return 0;

}

static int dxva2_get_decoder_configuration(AVCodecContext *s, const GUID *device_guid,

                                           const DXVA2_VideoDesc *desc,

                                           DXVA2_ConfigPictureDecode *config)

{

    InputStream  *ist = s->opaque;

    int loglevel = (ist->hwaccel_id == HWACCEL_AUTO) ? AV_LOG_VERBOSE : AV_LOG_ERROR;

    DXVA2Context *ctx = ist->hwaccel_ctx;

    unsigned cfg_count = 0, best_score = 0;

    DXVA2_ConfigPictureDecode *cfg_list = NULL;

    DXVA2_ConfigPictureDecode best_cfg = {{0}};

    HRESULT hr;

    int i;



    hr = IDirectXVideoDecoderService_GetDecoderConfigurations(ctx->decoder_service, device_guid, desc, NULL, &cfg_count, &cfg_list);

    if (FAILED(hr)) {

        av_log(NULL, loglevel, "Unable to retrieve decoder configurations\n");

        return AVERROR(EINVAL);

    }



    for (i = 0; i < cfg_count; i++) {

        DXVA2_ConfigPictureDecode *cfg = &cfg_list[i];



        unsigned score;

        if (cfg->ConfigBitstreamRaw == 1)

            score = 1;

        else if (s->codec_id == AV_CODEC_ID_H264 && cfg->ConfigBitstreamRaw == 2)

            score = 2;

        else

            continue;

        if (IsEqualGUID(&cfg->guidConfigBitstreamEncryption, &DXVA2_NoEncrypt))

            score += 16;

        if (score > best_score) {

            best_score = score;

            best_cfg   = *cfg;

        }

    }

    CoTaskMemFree(cfg_list);



    if (!best_score) {

        av_log(NULL, loglevel, "No valid decoder configuration available\n");

        return AVERROR(EINVAL);

    }



    *config = best_cfg;

    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, const GUID *VAR_1,

                                           const DXVA2_VideoDesc *VAR_2,

                                           DXVA2_ConfigPictureDecode *VAR_3)

{

    InputStream  *ist = VAR_0->opaque;

    int VAR_4 = (ist->hwaccel_id == HWACCEL_AUTO) ? AV_LOG_VERBOSE : AV_LOG_ERROR;

    DXVA2Context *ctx = ist->hwaccel_ctx;

    unsigned VAR_5 = 0, VAR_6 = 0;

    DXVA2_ConfigPictureDecode *cfg_list = NULL;

    DXVA2_ConfigPictureDecode best_cfg = {{0}};

    HRESULT hr;

    int VAR_7;



    hr = IDirectXVideoDecoderService_GetDecoderConfigurations(ctx->decoder_service, VAR_1, VAR_2, NULL, &VAR_5, &cfg_list);

    if (FAILED(hr)) {

        av_log(NULL, VAR_4, "Unable to retrieve decoder configurations\n");

        return AVERROR(EINVAL);

    }



    for (VAR_7 = 0; VAR_7 < VAR_5; VAR_7++) {

        DXVA2_ConfigPictureDecode *cfg = &cfg_list[VAR_7];



        unsigned VAR_8;

        if (cfg->ConfigBitstreamRaw == 1)

            VAR_8 = 1;

        else if (VAR_0->codec_id == AV_CODEC_ID_H264 && cfg->ConfigBitstreamRaw == 2)

            VAR_8 = 2;

        else

            continue;

        if (IsEqualGUID(&cfg->guidConfigBitstreamEncryption, &DXVA2_NoEncrypt))

            VAR_8 += 16;

        if (VAR_8 > VAR_6) {

            VAR_6 = VAR_8;

            best_cfg   = *cfg;

        }

    }

    CoTaskMemFree(cfg_list);



    if (!VAR_6) {

        av_log(NULL, VAR_4, "No valid decoder configuration available\n");

        return AVERROR(EINVAL);

    }



    *VAR_3 = best_cfg;

    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, const GUID *VAR_1,
const DXVA2_VideoDesc *VAR_2,
DXVA2_ConfigPictureDecode *VAR_3)
{ InputStream  *ist = VAR_0->opaque; int VAR_4 = (ist->hwaccel_id == HWACCEL_AUTO) ? AV_LOG_VERBOSE : AV_LOG_ERROR; DXVA2Context *ctx = ist->hwaccel_ctx; unsigned VAR_5 = 0, VAR_6 = 0; DXVA2_ConfigPictureDecode *cfg_list = NULL; DXVA2_ConfigPictureDecode best_cfg = {{0}}; HRESULT hr; int VAR_7; hr = IDirectXVideoDecoderService_GetDecoderConfigurations(ctx->decoder_service, VAR_1, VAR_2, NULL, &VAR_5, &cfg_list); if (FAILED(hr)) { av_log(NULL, VAR_4, "Unable to retrieve decoder configurations\n"); return AVERROR(EINVAL); } for (VAR_7 = 0; VAR_7 < VAR_5; VAR_7++) { DXVA2_ConfigPictureDecode *cfg = &cfg_list[VAR_7]; unsigned VAR_8; if (cfg->ConfigBitstreamRaw == 1)
VAR_8 = 1; else if (VAR_0->codec_id == AV_CODEC_ID_H264 && cfg->ConfigBitstreamRaw == 2)
VAR_8 = 2; else
continue; if (IsEqualGUID(&cfg->guidConfigBitstreamEncryption, &DXVA2_NoEncrypt))
VAR_8 += 16; if (VAR_8 > VAR_6) { VAR_6 = VAR_8; best_cfg   = *cfg; } } CoTaskMemFree(cfg_list); if (!VAR_6) { av_log(NULL, VAR_4, "No valid decoder configuration available\n"); return AVERROR(EINVAL); } *VAR_3 = best_cfg; return 0; }