X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fvdpau.c;h=475a56c73caa9d0010f4f54f92e3ab974517777e;hb=4f664d8aae8ccca33f39c2515484bd03e9d3f80d;hp=ea239bb311a7c209f6b48736ee19e352b19427fd;hpb=ff4f2036defbadc60081ba252e093abda5897d6d;p=ffmpeg diff --git a/libavcodec/vdpau.c b/libavcodec/vdpau.c index ea239bb311a..475a56c73ca 100644 --- a/libavcodec/vdpau.c +++ b/libavcodec/vdpau.c @@ -71,6 +71,46 @@ AVVDPAUContext *av_alloc_vdpaucontext(void) MAKE_ACCESSORS(AVVDPAUContext, vdpau_hwaccel, AVVDPAU_Render2, render2) +int av_vdpau_get_surface_parameters(AVCodecContext *avctx, + VdpChromaType *type, + uint32_t *width, uint32_t *height) +{ + VdpChromaType t; + uint32_t w = avctx->coded_width; + uint32_t h = avctx->coded_height; + + /* See for per-type alignment constraints. */ + switch (avctx->sw_pix_fmt) { + case AV_PIX_FMT_YUV420P: + case AV_PIX_FMT_YUVJ420P: + t = VDP_CHROMA_TYPE_420; + w = (w + 1) & ~1; + h = (h + 3) & ~3; + break; + case AV_PIX_FMT_YUV422P: + case AV_PIX_FMT_YUVJ422P: + t = VDP_CHROMA_TYPE_422; + w = (w + 1) & ~1; + h = (h + 1) & ~1; + break; + case AV_PIX_FMT_YUV444P: + case AV_PIX_FMT_YUVJ444P: + t = VDP_CHROMA_TYPE_444; + h = (h + 1) & ~1; + break; + default: + return AVERROR(ENOSYS); + } + + if (type) + *type = t; + if (width) + *width = w; + if (height) + *height = h; + return 0; +} + int ff_vdpau_common_init(AVCodecContext *avctx, VdpDecoderProfile profile, int level) { @@ -83,9 +123,9 @@ int ff_vdpau_common_init(AVCodecContext *avctx, VdpDecoderProfile profile, VdpStatus status; VdpBool supported; uint32_t max_level, max_mb, max_width, max_height; - /* See vdpau/vdpau.h for alignment constraints. */ - uint32_t width = (avctx->coded_width + 1) & ~1; - uint32_t height = (avctx->coded_height + 3) & ~3; + VdpChromaType type; + uint32_t width; + uint32_t height; vdctx->width = UINT32_MAX; vdctx->height = UINT32_MAX; @@ -112,6 +152,13 @@ int ff_vdpau_common_init(AVCodecContext *avctx, VdpDecoderProfile profile, 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); @@ -120,7 +167,7 @@ int ff_vdpau_common_init(AVCodecContext *avctx, VdpDecoderProfile profile, else surface_query_caps = func; - status = surface_query_caps(vdctx->device, VDP_CHROMA_TYPE_420, &supported, + status = surface_query_caps(vdctx->device, type, &supported, &max_width, &max_height); if (status != VDP_STATUS_OK) return vdpau_error(status); @@ -241,7 +288,8 @@ int ff_vdpau_common_end_frame(AVCodecContext *avctx, AVFrame *frame, #if FF_API_BUFS_VDPAU FF_DISABLE_DEPRECATION_WARNINGS - hwctx->info = pic_ctx->info; + av_assert0(sizeof(hwctx->info) <= sizeof(pic_ctx->info)); + memcpy(&hwctx->info, &pic_ctx->info, sizeof(hwctx->info)); hwctx->bitstream_buffers = pic_ctx->bitstream_buffers; hwctx->bitstream_buffers_used = pic_ctx->bitstream_buffers_used; hwctx->bitstream_buffers_allocated = pic_ctx->bitstream_buffers_allocated; @@ -701,7 +749,7 @@ int av_vdpau_bind_context(AVCodecContext *avctx, VdpDevice device, { VDPAUHWContext *hwctx; - if (flags & ~AV_HWACCEL_FLAG_IGNORE_LEVEL) + if (flags & ~(AV_HWACCEL_FLAG_IGNORE_LEVEL|AV_HWACCEL_FLAG_ALLOW_HIGH_DEPTH)) return AVERROR(EINVAL); if (av_reallocp(&avctx->hwaccel_context, sizeof(*hwctx)))