diff options
Diffstat (limited to 'video/decode')
-rw-r--r-- | video/decode/videotoolbox.c | 32 |
1 files changed, 15 insertions, 17 deletions
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; } |