From 85488f68928ed40020e545b736118e0273e06cd1 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 15 Jul 2016 11:54:44 +0200 Subject: video: change hw_subfmt meaning The hw_subfmt field roughly corresponds to the field AVHWFramesContext.sw_format in ffmpeg. The ffmpeg one is of the type AVPixelFormat (instead of the underlying hardware format), so it's a good idea to switch to this too for preparation. Now the hw_subfmt field is an mp_imgfmt instead of an opaque/API- specific number. VDPAU and Direct3D11 already used mp_imgfmt, but Videotoolbox and VAAPI had to be switched. One somewhat user-visible change is that the verbose log will now always show the hw_subfmt as image format, instead of as nonsensical number. (In the end it would be good if we could switch to AVHWFramesContext completely, but the upstream API is incomplete and doesn't cover Direct3D11 and Videotoolbox.) --- video/decode/videotoolbox.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'video/decode') diff --git a/video/decode/videotoolbox.c b/video/decode/videotoolbox.c index 355017ffd4..c6f1a472bf 100644 --- a/video/decode/videotoolbox.c +++ b/video/decode/videotoolbox.c @@ -138,6 +138,17 @@ static void uninit(struct lavc_ctx *ctx) ctx->hwdec_priv = NULL; } +static int mp_imgfmt_from_cvpixelformat(uint32_t cvpixfmt) +{ + switch (cvpixfmt) { + case kCVPixelFormatType_420YpCbCr8Planar: return IMGFMT_420P; + case kCVPixelFormatType_422YpCbCr8: return IMGFMT_UYVY; + case kCVPixelFormatType_32BGRA: return IMGFMT_RGB0; + case kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange: return IMGFMT_NV12; + } + return 0; +} + static struct mp_image *copy_image(struct lavc_ctx *ctx, struct mp_image *hw_image) { if (hw_image->imgfmt != IMGFMT_VIDEOTOOLBOX) @@ -150,23 +161,9 @@ static struct mp_image *copy_image(struct lavc_ctx *ctx, struct mp_image *hw_ima size_t width = CVPixelBufferGetWidth(pbuf); size_t height = CVPixelBufferGetHeight(pbuf); uint32_t cvpixfmt = CVPixelBufferGetPixelFormatType(pbuf); - int pixfmt = 0; - switch (cvpixfmt) { - case kCVPixelFormatType_420YpCbCr8Planar: - pixfmt = IMGFMT_420P; - break; - case kCVPixelFormatType_422YpCbCr8: - pixfmt = IMGFMT_UYVY; - break; - case kCVPixelFormatType_32BGRA: - pixfmt = IMGFMT_RGB0; - break; - case kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange: - pixfmt = IMGFMT_NV12; - break; - default: + int pixfmt = mp_imgfmt_from_cvpixelformat(cvpixfmt); + if (!pixfmt) goto unlock; - } struct mp_image img = {0}; mp_image_setfmt(&img, pixfmt); @@ -202,7 +199,8 @@ static struct mp_image *process_image(struct lavc_ctx *ctx, struct mp_image *img { if (img->imgfmt == IMGFMT_VIDEOTOOLBOX) { CVPixelBufferRef pbuf = (CVPixelBufferRef)img->planes[3]; - img->params.hw_subfmt = CVPixelBufferGetPixelFormatType(pbuf); + uint32_t cvpixfmt = CVPixelBufferGetPixelFormatType(pbuf); + img->params.hw_subfmt = mp_imgfmt_from_cvpixelformat(cvpixfmt); } return img; } -- cgit v1.2.3