Ticket #7704: VideoToolbox_10bit.patch

File VideoToolbox_10bit.patch, 4.5 KB (added by fumoboy007, 4 months ago)
  • fftools/ffmpeg_videotoolbox.c

    diff --git a/fftools/ffmpeg_videotoolbox.c b/fftools/ffmpeg_videotoolbox.c
    index b820aec017..e13592caeb 100644
    a b static int videotoolbox_retrieve_data(AVCodecContext *s, AVFrame *frame) 
    5353#ifdef kCFCoreFoundationVersionNumber10_7
    5454    case kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange: vt->tmp_frame->format = AV_PIX_FMT_NV12; break;
    5555#endif
     56    case kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange: vt->tmp_frame->format = AV_PIX_FMT_P010; break;
    5657    default:
    5758        av_log(NULL, AV_LOG_ERROR,
    5859               "%s: Unsupported pixel format: %s\n",
  • libavcodec/videotoolbox.c

    diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
    index da7236f100..df22786532 100644
    a b  
    2626#include "vt_internal.h"
    2727#include "libavutil/avutil.h"
    2828#include "libavutil/hwcontext.h"
     29#include "libavutil/pixdesc.h"
    2930#include "bytestream.h"
    3031#include "decode.h"
    3132#include "h264dec.h"
    static int videotoolbox_uninit(AVCodecContext *avctx) 
    10261027    return 0;
    10271028}
    10281029
     1030static enum AVPixelFormat videotoolbox_best_pixel_format(AVCodecContext *avctx) {
     1031    const AVPixFmtDescriptor *descriptor = av_pix_fmt_desc_get(avctx->pix_fmt);
     1032    if (descriptor != NULL) {
     1033        int depth = descriptor->comp[0].depth;
     1034        if (depth > 8) {
     1035            return AV_PIX_FMT_P010;
     1036        }
     1037    }
     1038
     1039    return AV_PIX_FMT_NV12; // same as av_videotoolbox_alloc_context()
     1040}
     1041
    10291042static int videotoolbox_common_init(AVCodecContext *avctx)
    10301043{
    10311044    VTContext *vtctx = avctx->internal->hwaccel_priv_data;
    static int videotoolbox_common_init(AVCodecContext *avctx) 
    10591072
    10601073        hw_frames = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
    10611074        hw_frames->format = AV_PIX_FMT_VIDEOTOOLBOX;
    1062         hw_frames->sw_format = AV_PIX_FMT_NV12; // same as av_videotoolbox_alloc_context()
     1075        hw_frames->sw_format = videotoolbox_best_pixel_format(avctx);
    10631076        hw_frames->width = avctx->width;
    10641077        hw_frames->height = avctx->height;
    10651078
    static int videotoolbox_frame_params(AVCodecContext *avctx, 
    11031116    frames_ctx->format            = AV_PIX_FMT_VIDEOTOOLBOX;
    11041117    frames_ctx->width             = avctx->coded_width;
    11051118    frames_ctx->height            = avctx->coded_height;
    1106     frames_ctx->sw_format         = AV_PIX_FMT_NV12;
     1119    frames_ctx->sw_format         = videotoolbox_best_pixel_format(avctx);
    11071120
    11081121    return 0;
    11091122}
    const AVHWAccel ff_mpeg4_videotoolbox_hwaccel = { 
    12001213    .priv_data_size = sizeof(VTContext),
    12011214};
    12021215
    1203 AVVideotoolboxContext *av_videotoolbox_alloc_context(void)
     1216static AVVideotoolboxContext *av_videotoolbox_alloc_context_with_pix_fmt(enum AVPixelFormat pix_fmt)
    12041217{
    12051218    AVVideotoolboxContext *ret = av_mallocz(sizeof(*ret));
    12061219
    12071220    if (ret) {
    12081221        ret->output_callback = videotoolbox_decoder_callback;
    1209         ret->cv_pix_fmt_type = kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange;
     1222
     1223        OSType cv_pix_fmt_type = av_map_videotoolbox_format_from_pixfmt(pix_fmt);
     1224        if (cv_pix_fmt_type == 0) {
     1225            cv_pix_fmt_type = kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange;
     1226        }
     1227        ret->cv_pix_fmt_type = cv_pix_fmt_type;
    12101228    }
    12111229
    12121230    return ret;
    12131231}
    12141232
     1233AVVideotoolboxContext *av_videotoolbox_alloc_context(void)
     1234{
     1235    return av_videotoolbox_alloc_context_with_pix_fmt(AV_PIX_FMT_NONE);
     1236}
     1237
    12151238int av_videotoolbox_default_init(AVCodecContext *avctx)
    12161239{
    12171240    return av_videotoolbox_default_init2(avctx, NULL);
    int av_videotoolbox_default_init(AVCodecContext *avctx) 
    12191242
    12201243int av_videotoolbox_default_init2(AVCodecContext *avctx, AVVideotoolboxContext *vtctx)
    12211244{
    1222     avctx->hwaccel_context = vtctx ?: av_videotoolbox_alloc_context();
     1245    avctx->hwaccel_context = vtctx ?: av_videotoolbox_alloc_context_with_pix_fmt(videotoolbox_best_pixel_format(avctx));
    12231246    if (!avctx->hwaccel_context)
    12241247        return AVERROR(ENOMEM);
    12251248    return videotoolbox_start(avctx);
  • libavutil/hwcontext_videotoolbox.c

    diff --git a/libavutil/hwcontext_videotoolbox.c b/libavutil/hwcontext_videotoolbox.c
    index cc00f1f2f2..5da8b91016 100644
    a b static const struct { 
    4242#ifdef kCFCoreFoundationVersionNumber10_7
    4343    { kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange,  AV_PIX_FMT_NV12 },
    4444#endif
     45    { kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange, AV_PIX_FMT_P010 },
    4546};
    4647
    4748enum AVPixelFormat av_map_videotoolbox_format_to_pixfmt(uint32_t cv_fmt)