+ VDPAUHWContext *hwctx = avctx->hwaccel_context;
+ VDPAUContext *vdctx = avctx->internal->hwaccel_priv_data;
+ VdpVideoSurfaceQueryCapabilities *surface_query_caps;
+ VdpDecoderQueryCapabilities *decoder_query_caps;
+ VdpDecoderCreate *create;
+ void *func;
+ VdpStatus status;
+ VdpBool supported;
+ uint32_t max_level, max_mb, max_width, max_height;
+ VdpChromaType type;
+ uint32_t width;
+ uint32_t height;
+
+ vdctx->width = UINT32_MAX;
+ vdctx->height = UINT32_MAX;
+ hwctx->reset = 0;
+
+ if (hwctx->context.decoder != VDP_INVALID_HANDLE) {
+ vdctx->decoder = hwctx->context.decoder;
+ vdctx->render = hwctx->context.render;
+ vdctx->device = VDP_INVALID_HANDLE;
+ return 0; /* Decoder created by user */
+ }
+
+ vdctx->device = hwctx->device;
+ vdctx->get_proc_address = hwctx->get_proc_address;
+
+ if (hwctx->flags & AV_HWACCEL_FLAG_IGNORE_LEVEL)
+ level = 0;
+ else if (level < 0)
+ return AVERROR(ENOTSUP);
+
+ if (av_vdpau_get_surface_parameters(avctx, &type, &width, &height))
+ return AVERROR(ENOSYS);
+
+ if (!(hwctx->flags & AV_HWACCEL_FLAG_ALLOW_HIGH_DEPTH) &&
+ type != VDP_CHROMA_TYPE_420)
+ return AVERROR(ENOSYS);
+
+ status = vdctx->get_proc_address(vdctx->device,
+ VDP_FUNC_ID_VIDEO_SURFACE_QUERY_CAPABILITIES,
+ &func);
+ if (status != VDP_STATUS_OK)
+ return vdpau_error(status);
+ else
+ surface_query_caps = func;
+
+ status = surface_query_caps(vdctx->device, type, &supported,
+ &max_width, &max_height);
+ if (status != VDP_STATUS_OK)
+ return vdpau_error(status);
+ if (supported != VDP_TRUE ||
+ max_width < width || max_height < height)
+ return AVERROR(ENOTSUP);
+
+ status = vdctx->get_proc_address(vdctx->device,
+ VDP_FUNC_ID_DECODER_QUERY_CAPABILITIES,
+ &func);
+ if (status != VDP_STATUS_OK)
+ return vdpau_error(status);
+ else
+ decoder_query_caps = func;
+
+ status = decoder_query_caps(vdctx->device, profile, &supported, &max_level,
+ &max_mb, &max_width, &max_height);
+#ifdef VDP_DECODER_PROFILE_H264_CONSTRAINED_BASELINE
+ if (status != VDP_STATUS_OK && profile == VDP_DECODER_PROFILE_H264_CONSTRAINED_BASELINE) {
+ /* Run-time backward compatibility for libvdpau 0.8 and earlier */
+ profile = VDP_DECODER_PROFILE_H264_MAIN;
+ status = decoder_query_caps(vdctx->device, profile, &supported,
+ &max_level, &max_mb,
+ &max_width, &max_height);
+ }
+#endif
+ if (status != VDP_STATUS_OK)
+ return vdpau_error(status);
+
+ if (supported != VDP_TRUE || max_level < level ||
+ max_width < width || max_height < height)
+ return AVERROR(ENOTSUP);
+
+ status = vdctx->get_proc_address(vdctx->device, VDP_FUNC_ID_DECODER_CREATE,
+ &func);
+ if (status != VDP_STATUS_OK)
+ return vdpau_error(status);
+ else
+ create = func;