From patchwork Sat Apr 13 10:19:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: der richter X-Patchwork-Id: 12718 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id AEAD444779F for ; Sat, 13 Apr 2019 13:25:25 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9093B68AA89; Sat, 13 Apr 2019 13:25:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D774868A9D9 for ; Sat, 13 Apr 2019 13:25:18 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1555151118; bh=KMCDyHueAGvWDdxSQzIzTce0TbB7TKK2H8EXbXKGFdQ=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=egkJKIbE8CmJuS//AFsszg8VZDQB6AaOBMJImykkRZ0sBZbrcFNjCXUoyCPybj2D2 iCPFV91/BbIWHaBDBUGyUcmWnj3xBhK2jE3oz0WxbWcQppomcPAD7MvKkYB/ydei+m bZ9YI137ZH14AsmW72ee0Wgm29n6Fbj/qiolNdlY= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Akemis-iMac.speedport.ip ([79.222.69.43]) by mail.gmx.com (mrgmx101 [212.227.17.168]) with ESMTPSA (Nemesis) id 0MgoiC-1hSVHy29oW-00M5av; Sat, 13 Apr 2019 12:20:06 +0200 From: der richter To: ffmpeg-devel@ffmpeg.org Date: Sat, 13 Apr 2019 12:19:58 +0200 Message-Id: <20190413101959.43275-1-der.richter@gmx.de> X-Mailer: git-send-email 2.21.0 In-Reply-To: <97109285-8762-4B44-8ABD-91C7BA7A86D7@gmx.de> References: <97109285-8762-4B44-8ABD-91C7BA7A86D7@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:7TNR2YoS6f1gcQEGHTDNXKcBlbiz1WB4XP4Yz/BF51JclVOD+v/ 3OLMcP87YiIpdJc3elOGDh95l4MwLZPL8IEQHhm7njlmN+G5HXTF8+H+l6VY3ZBCl1Q9JiM C7c8vp7obgL9xHA6BKTF4YYNdGG2N5w3lxsSnmlCena8o/z9aAPJ/QzMdSR6repYz0ze9wJ aUMbUroRkA3WDSmCAV0dQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:/POCiCAv+Wo=:y2afzzBrlQHA/fJTzjlwzn T/iJ7+5jCYkjRa0QRkIfmMCpk8WUYZlEF91oG3A+qtwDREL35sv4gMCiQE4KGHOmAZd9BjJSc LQSRXZ3QBOTH0WPZV+Hh61emfWRuy+wg2MZnmKtsXjjwp8JW+8KVIxgd6qRp0y9bgOlSc/AoT Pq1janTpSGhpJJNV/pphV/LKgUDEatdk5g24sjnPfFHOt5wf555E8opd5Mq6Zif7Ne2DUxG+0 Fz/F387OIIpJd9Tx5++CwMAkGo9jQGcGTGJ+33HTXqs0t7o2wJYX8kYKOVfsoKsKuOuhTQALD sIHIYDW0D0N483fVKHTIb1iypgCbro/CPg7EP/VVCu5GGLsGCYmHmZ2QpzhpjLgUcoMrrahA4 WBj9Soqyq1EhfIujTvREn2XITP956dQ7y0zoS8aGb2n+e4e9jjdrp+/5jDrNHtUMCuAFumXNF dqoqSpM2f+T6sRZx+hpuNhnHrTcZbrpJWF3NyNTk8XaVVIuDM6VmAxJFVZ6JScPIOmSh4nSRR d+AGsIBxoAe+zi+ezFjotiQ7xda3j32naKsKQ3SCIWpY/Ruj1QoHb2RZ+Bpm0LUPbh809U3X0 ZtV2//FlA+8ZCpCJhEtvKkHyYbyulwHU1oJOkMTDw7En11NnZ1MGFDEnvmhNBnF3qDdwpVUs0 7MR7yrscPWZykv3wX0h/fFLSOFOUzY3lGTqRes7mEMww8qPoEikRHm5JzlanfDXP6NXjgFIVP xK069Jtrh2tyq2IHuw+IZfhDOC6dVbLAM3xHZ/MIJfa2uSr/NZIwQgh8tNMf8s7Ya+xc+ZToA rO2FaDEPSqMtNGTmbWHSphw61ROihZ2at19OvgiiT9D2tMOgyHVScB35hvFJFtc7ZKW4zk18Z jbNk/bBiz6qh5BzHx5WDqAokrXcjfW7gKe4KzCk9uEcEz4MuTaefbalAM/Zj/r Subject: [FFmpeg-devel] [PATCH v2 1/2] avcodec/videotoolbox: add support for 10bit pixel format X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: fumoboy007 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: fumoboy007 this patch was originally posted on issue #7704 and was slightly adjusted to check for the availability of the pixel format. --- configure | 2 ++ fftools/ffmpeg_videotoolbox.c | 3 +++ libavcodec/videotoolbox.c | 32 +++++++++++++++++++++++++----- libavutil/hwcontext_videotoolbox.c | 3 +++ 4 files changed, 35 insertions(+), 5 deletions(-) -- 2.21.0 diff --git a/configure b/configure index 331393f8d5..a89da70aab 100755 --- a/configure +++ b/configure @@ -2253,6 +2253,7 @@ TOOLCHAIN_FEATURES=" TYPES_LIST=" kCMVideoCodecType_HEVC + kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange socklen_t struct_addrinfo struct_group_source_req @@ -6012,6 +6013,7 @@ enabled avfoundation && { enabled videotoolbox && { check_lib coreservices CoreServices/CoreServices.h UTGetOSTypeFromString "-framework CoreServices" check_func_headers CoreMedia/CMFormatDescription.h kCMVideoCodecType_HEVC "-framework CoreMedia" + check_func_headers CoreVideo/CVPixelBuffer.h kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange "-framework CoreVideo" } check_struct "sys/time.h sys/resource.h" "struct rusage" ru_maxrss diff --git a/fftools/ffmpeg_videotoolbox.c b/fftools/ffmpeg_videotoolbox.c index b820aec017..ad6174d3c7 100644 --- a/fftools/ffmpeg_videotoolbox.c +++ b/fftools/ffmpeg_videotoolbox.c @@ -52,6 +52,9 @@ static int videotoolbox_retrieve_data(AVCodecContext *s, AVFrame *frame) case kCVPixelFormatType_32BGRA: vt->tmp_frame->format = AV_PIX_FMT_BGRA; break; #ifdef kCFCoreFoundationVersionNumber10_7 case kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange: vt->tmp_frame->format = AV_PIX_FMT_NV12; break; +#endif +#if HAVE_KCVPIXELFORMATTYPE_420YPCBCR10BIPLANARVIDEORANGE + case kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange: vt->tmp_frame->format = AV_PIX_FMT_P010; break; #endif default: av_log(NULL, AV_LOG_ERROR, diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c index fb3501f413..021afd411b 100644 --- a/libavcodec/videotoolbox.c +++ b/libavcodec/videotoolbox.c @@ -26,6 +26,7 @@ #include "vt_internal.h" #include "libavutil/avutil.h" #include "libavutil/hwcontext.h" +#include "libavutil/pixdesc.h" #include "bytestream.h" #include "decode.h" #include "h264dec.h" @@ -1020,6 +1021,17 @@ static int videotoolbox_uninit(AVCodecContext *avctx) return 0; } +static enum AVPixelFormat videotoolbox_best_pixel_format(AVCodecContext *avctx) { + const AVPixFmtDescriptor *descriptor = av_pix_fmt_desc_get(avctx->pix_fmt); + if (!descriptor) + return AV_PIX_FMT_NV12; // same as av_videotoolbox_alloc_context() + + int depth = descriptor->comp[0].depth; + if (depth > 8) { + return AV_PIX_FMT_P010; + } +} + static int videotoolbox_common_init(AVCodecContext *avctx) { VTContext *vtctx = avctx->internal->hwaccel_priv_data; @@ -1053,7 +1065,7 @@ static int videotoolbox_common_init(AVCodecContext *avctx) hw_frames = (AVHWFramesContext*)avctx->hw_frames_ctx->data; hw_frames->format = AV_PIX_FMT_VIDEOTOOLBOX; - hw_frames->sw_format = AV_PIX_FMT_NV12; // same as av_videotoolbox_alloc_context() + hw_frames->sw_format = videotoolbox_best_pixel_format(avctx); hw_frames->width = avctx->width; hw_frames->height = avctx->height; @@ -1097,7 +1109,7 @@ static int videotoolbox_frame_params(AVCodecContext *avctx, frames_ctx->format = AV_PIX_FMT_VIDEOTOOLBOX; frames_ctx->width = avctx->coded_width; frames_ctx->height = avctx->coded_height; - frames_ctx->sw_format = AV_PIX_FMT_NV12; + frames_ctx->sw_format = videotoolbox_best_pixel_format(avctx); return 0; } @@ -1194,18 +1206,28 @@ const AVHWAccel ff_mpeg4_videotoolbox_hwaccel = { .priv_data_size = sizeof(VTContext), }; -AVVideotoolboxContext *av_videotoolbox_alloc_context(void) +static AVVideotoolboxContext *av_videotoolbox_alloc_context_with_pix_fmt(enum AVPixelFormat pix_fmt) { AVVideotoolboxContext *ret = av_mallocz(sizeof(*ret)); if (ret) { ret->output_callback = videotoolbox_decoder_callback; - ret->cv_pix_fmt_type = kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange; + + OSType cv_pix_fmt_type = av_map_videotoolbox_format_from_pixfmt(pix_fmt); + if (cv_pix_fmt_type == 0) { + cv_pix_fmt_type = kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange; + } + ret->cv_pix_fmt_type = cv_pix_fmt_type; } return ret; } +AVVideotoolboxContext *av_videotoolbox_alloc_context(void) +{ + return av_videotoolbox_alloc_context_with_pix_fmt(AV_PIX_FMT_NONE); +} + int av_videotoolbox_default_init(AVCodecContext *avctx) { return av_videotoolbox_default_init2(avctx, NULL); @@ -1213,7 +1235,7 @@ int av_videotoolbox_default_init(AVCodecContext *avctx) int av_videotoolbox_default_init2(AVCodecContext *avctx, AVVideotoolboxContext *vtctx) { - avctx->hwaccel_context = vtctx ?: av_videotoolbox_alloc_context(); + avctx->hwaccel_context = vtctx ?: av_videotoolbox_alloc_context_with_pix_fmt(videotoolbox_best_pixel_format(avctx)); if (!avctx->hwaccel_context) return AVERROR(ENOMEM); return videotoolbox_start(avctx); diff --git a/libavutil/hwcontext_videotoolbox.c b/libavutil/hwcontext_videotoolbox.c index cc00f1f2f2..6eac2c0774 100644 --- a/libavutil/hwcontext_videotoolbox.c +++ b/libavutil/hwcontext_videotoolbox.c @@ -42,6 +42,9 @@ static const struct { #ifdef kCFCoreFoundationVersionNumber10_7 { kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange, AV_PIX_FMT_NV12 }, #endif +#if HAVE_KCVPIXELFORMATTYPE_420YPCBCR10BIPLANARVIDEORANGE + { kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange, AV_PIX_FMT_P010 }, +#endif }; enum AVPixelFormat av_map_videotoolbox_format_to_pixfmt(uint32_t cv_fmt)