From patchwork Sat Nov 13 21:09:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: rcombs X-Patchwork-Id: 31411 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp3679836iob; Sat, 13 Nov 2021 13:12:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJysA+tawxQJ1Wg1OCd4Kypv1fHbtUYinsS0m2JxU/xrtc6/LifdZjtQ4z0P8EG0OsCh+Gdn X-Received: by 2002:a17:907:d9f:: with SMTP id go31mr34723750ejc.412.1636837923222; Sat, 13 Nov 2021 13:12:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636837923; cv=none; d=google.com; s=arc-20160816; b=Ev8R4DtTtCUI7/GaEBFnFDtmI94meISVErca/3sFHb8qLqvIAUoyOzAli6T+dV+REy Ny+iOj03w+XYLqdH/+kpGGQ1XSTKAvsOVaQTuRPrP2+gaJBAe8ttWgKHGXmesXaiWn1o 30/7VFomUHaVgRVmMmtkIVn6d+4CUZbbNMe9g8/RvB7hGuG2uRTMFnAA9LsLnHxktF5x R76+SyY1Su8tdWtwRG4AevnTsjt4LyWpOXErJwG1aT8BoDwqQdVHZY90Me/CwuXUclaI xin+RTwFyTG15GnXMVS3HEj34hPM2l9qlqZG7v475+dxMdIuCHX9QWcbUMrsLANBEJ1p M+mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=xeXlrhfnhaA5IVpSfYTEXjQqgrK+0YdQyhFmkWVehY8=; b=LEtGTAWg19DeKbhSwWnVM1KzYq38t1+O/frgTZ9KDqn6xqffM1P+OSbnmAZZCB7Kmn h3sWkZ4nSPHFvYwcDqqdsmk3f7tv7c/9fkm7GOJiSFZBHU6J1ku7ovXKs9I8qbhO59Wf nz2VjTf30l7HQ8ZiE4qNeAtu90P8GcADCdv64nIhO94TmlBIyTcZA09/BgpWLnsb8xMe rXKKX/u0BdSq03aBgKxIoWfVZG8ES59FsCVDoS3c+6g8kRpdI8k7kYkhmXPmCyIEqUoh DOYHCFXELgJoxcb0Uyrlbo+Y/tdjLN4ZHy7bQoNQAJbYMy1dUFWE5w4s4PZsF7dmNiU+ mOYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@rcombs.me header.s=google header.b=jDppPxSm; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=rcombs.me Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id da6si7706318edb.67.2021.11.13.13.12.02; Sat, 13 Nov 2021 13:12:03 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@rcombs.me header.s=google header.b=jDppPxSm; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=rcombs.me Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2C12A68AEA9; Sat, 13 Nov 2021 23:09:44 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-il1-f177.google.com (mail-il1-f177.google.com [209.85.166.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 90B3568AE78 for ; Sat, 13 Nov 2021 23:09:30 +0200 (EET) Received: by mail-il1-f177.google.com with SMTP id l19so12476104ilk.0 for ; Sat, 13 Nov 2021 13:09:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rcombs.me; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=LjdDPARjurln+Oczbb8HHEhcv3F9MHzkkMHZXgDGc1U=; b=jDppPxSm66saBojAMb/b2f106VEQwjRKbrMif60GpIfBgpK48fqL7oBKR5ujLYxQJW RkpOIX5EOXIW/8IadI1wkXhoS1OGAelfquJrmpbJ7Z1Qz46p/4D5FiDtW8ZA15L7zA6j JeeD7L1c4AxAuYx/d0bxRxrldXWjkY5vGooAWf1msx1Q5oaFxshtfJkt5039cyCaAZJ0 t31KtFZmHEhemmoT+EM8AgZASbfGPrTUgUa3nJeSjRn0Tn/JPr9ZPPjDFMMxwioK6Wo3 iDZta7ncs56PqaMXkuNHSQOM/0TISwxGYh3o6qVjpdtUIB6cGitadGzsSOtfFjWsNCw6 y5Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LjdDPARjurln+Oczbb8HHEhcv3F9MHzkkMHZXgDGc1U=; b=zDs61oRUwkyd9uLZjVWgsUNNDG3XidtnMeZgoGiJiSTkPX4lAoihkAAhsKVpbmJWLU c5hLoY3yG6NZq03YiOeIhX8f9Ij2zPacb1F/16WmOZkKPD9T8f6dfZz9N82f+/Wo2Pea 15UPxK7czxJ8VAEdlULiwmzvmnzQNSBZy+iyI7aSzDddEaRko6YW6132HJvnGZE+GMIT fuqN+s1LWnbw/9AwMRAo+bQrjHyLbX95wQJ95e5Z8c1w9C37NSBRpkOH2zrPBzStxlcr FLJBG4Bxjrk7+56QmBBFAgH7O8UaAVMRkHmNesz01Q/OqDc4IbonPWwGjsPCT8+GOep5 QpHw== X-Gm-Message-State: AOAM530WwMRtN3M/tvEt9DAVHHHLjyYzN22QwA65VeKzzQh4ZUbR9BXu 0oiRHPKzSwyd7lg+5s4ZR7Jok3QW5bZBP6s= X-Received: by 2002:a92:c261:: with SMTP id h1mr13989978ild.291.1636837768920; Sat, 13 Nov 2021 13:09:28 -0800 (PST) Received: from rcombs-mbp.localdomain ([2601:243:2000:5ac:516:f322:7db9:ae0a]) by smtp.gmail.com with ESMTPSA id j23sm5243896iog.53.2021.11.13.13.09.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 13 Nov 2021 13:09:28 -0800 (PST) From: rcombs To: ffmpeg-devel@ffmpeg.org Date: Sat, 13 Nov 2021 15:09:11 -0600 Message-Id: <20211113210916.49167-10-rcombs@rcombs.me> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211113210916.49167-1-rcombs@rcombs.me> References: <20211113210916.49167-1-rcombs@rcombs.me> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/15] lavc/videotoolbox: expose some functions as lavc-internal X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Qqb9wqiL7qpc --- libavcodec/videotoolbox.c | 146 ++++++++++++++++++-------------------- libavcodec/vt_internal.h | 10 +++ 2 files changed, 78 insertions(+), 78 deletions(-) diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c index 764021586b..18cc589d2a 100644 --- a/libavcodec/videotoolbox.c +++ b/libavcodec/videotoolbox.c @@ -61,9 +61,9 @@ static void videotoolbox_buffer_release(void *opaque, uint8_t *data) av_free(data); } -static int videotoolbox_buffer_copy(VTContext *vtctx, - const uint8_t *buffer, - uint32_t size) +int ff_videotoolbox_buffer_copy(VTContext *vtctx, + const uint8_t *buffer, + uint32_t size) { void *tmp; @@ -374,7 +374,7 @@ int ff_videotoolbox_h264_start_frame(AVCodecContext *avctx, H264Context *h = avctx->priv_data; if (h->is_avc == 1) { - return videotoolbox_buffer_copy(vtctx, buffer, size); + return ff_videotoolbox_buffer_copy(vtctx, buffer, size); } return 0; @@ -438,18 +438,6 @@ int ff_videotoolbox_h264_decode_slice(AVCodecContext *avctx, return videotoolbox_common_decode_slice(avctx, buffer, size); } -int ff_videotoolbox_uninit(AVCodecContext *avctx) -{ - VTContext *vtctx = avctx->internal->hwaccel_priv_data; - if (vtctx) { - av_freep(&vtctx->bitstream); - if (vtctx->frame) - CVPixelBufferRelease(vtctx->frame); - } - - return 0; -} - #if CONFIG_VIDEOTOOLBOX // Return the AVVideotoolboxContext that matters currently. Where it comes from // depends on the API used. @@ -465,6 +453,43 @@ static AVVideotoolboxContext *videotoolbox_get_context(AVCodecContext *avctx) return avctx->hwaccel_context; } +static void videotoolbox_stop(AVCodecContext *avctx) +{ + AVVideotoolboxContext *videotoolbox = videotoolbox_get_context(avctx); + if (!videotoolbox) + return; + + if (videotoolbox->cm_fmt_desc) { + CFRelease(videotoolbox->cm_fmt_desc); + videotoolbox->cm_fmt_desc = NULL; + } + + if (videotoolbox->session) { + VTDecompressionSessionInvalidate(videotoolbox->session); + CFRelease(videotoolbox->session); + videotoolbox->session = NULL; + } +} + +int ff_videotoolbox_uninit(AVCodecContext *avctx) +{ + VTContext *vtctx = avctx->internal->hwaccel_priv_data; + if (!vtctx) + return 0; + + av_freep(&vtctx->bitstream); + if (vtctx->frame) + CVPixelBufferRelease(vtctx->frame); + + if (vtctx->vt_ctx) + videotoolbox_stop(avctx); + + av_buffer_unref(&vtctx->cached_hw_frames_ctx); + av_freep(&vtctx->vt_ctx); + + return 0; +} + static int videotoolbox_buffer_create(AVCodecContext *avctx, AVFrame *frame) { VTContext *vtctx = avctx->internal->hwaccel_priv_data; @@ -901,24 +926,6 @@ static int videotoolbox_start(AVCodecContext *avctx) } } -static void videotoolbox_stop(AVCodecContext *avctx) -{ - AVVideotoolboxContext *videotoolbox = videotoolbox_get_context(avctx); - if (!videotoolbox) - return; - - if (videotoolbox->cm_fmt_desc) { - CFRelease(videotoolbox->cm_fmt_desc); - videotoolbox->cm_fmt_desc = NULL; - } - - if (videotoolbox->session) { - VTDecompressionSessionInvalidate(videotoolbox->session); - CFRelease(videotoolbox->session); - videotoolbox->session = NULL; - } -} - static const char *videotoolbox_error_string(OSStatus status) { switch (status) { @@ -932,7 +939,7 @@ static const char *videotoolbox_error_string(OSStatus status) return "unknown"; } -static int videotoolbox_common_end_frame(AVCodecContext *avctx, AVFrame *frame) +int ff_videotoolbox_common_end_frame(AVCodecContext *avctx, AVFrame *frame) { OSStatus status; AVVideotoolboxContext *videotoolbox = videotoolbox_get_context(avctx); @@ -971,7 +978,7 @@ static int videotoolbox_h264_end_frame(AVCodecContext *avctx) H264Context *h = avctx->priv_data; AVFrame *frame = h->cur_pic_ptr->f; VTContext *vtctx = avctx->internal->hwaccel_priv_data; - int ret = videotoolbox_common_end_frame(avctx, frame); + int ret = ff_videotoolbox_common_end_frame(avctx, frame); vtctx->bitstream_size = 0; return ret; } @@ -1010,7 +1017,7 @@ static int videotoolbox_hevc_end_frame(AVCodecContext *avctx) h->output_frame->crop_top = 0; h->output_frame->crop_bottom = 0; - int ret = videotoolbox_common_end_frame(avctx, frame); + int ret = ff_videotoolbox_common_end_frame(avctx, frame); vtctx->bitstream_size = 0; return ret; } @@ -1021,7 +1028,7 @@ static int videotoolbox_mpeg_start_frame(AVCodecContext *avctx, { VTContext *vtctx = avctx->internal->hwaccel_priv_data; - return videotoolbox_buffer_copy(vtctx, buffer, size); + return ff_videotoolbox_buffer_copy(vtctx, buffer, size); } static int videotoolbox_mpeg_decode_slice(AVCodecContext *avctx, @@ -1036,24 +1043,7 @@ static int videotoolbox_mpeg_end_frame(AVCodecContext *avctx) MpegEncContext *s = avctx->priv_data; AVFrame *frame = s->current_picture_ptr->f; - return videotoolbox_common_end_frame(avctx, frame); -} - -static int videotoolbox_uninit(AVCodecContext *avctx) -{ - VTContext *vtctx = avctx->internal->hwaccel_priv_data; - if (!vtctx) - return 0; - - ff_videotoolbox_uninit(avctx); - - if (vtctx->vt_ctx) - videotoolbox_stop(avctx); - - av_buffer_unref(&vtctx->cached_hw_frames_ctx); - av_freep(&vtctx->vt_ctx); - - return 0; + return ff_videotoolbox_common_end_frame(avctx, frame); } static enum AVPixelFormat videotoolbox_best_pixel_format(AVCodecContext *avctx) { @@ -1095,7 +1085,7 @@ static enum AVPixelFormat videotoolbox_best_pixel_format(AVCodecContext *avctx) return AV_PIX_FMT_NV12; } -static int videotoolbox_common_init(AVCodecContext *avctx) +int ff_videotoolbox_common_init(AVCodecContext *avctx) { VTContext *vtctx = avctx->internal->hwaccel_priv_data; AVHWFramesContext *hw_frames; @@ -1167,12 +1157,12 @@ static int videotoolbox_common_init(AVCodecContext *avctx) return 0; fail: - videotoolbox_uninit(avctx); + ff_videotoolbox_uninit(avctx); return err; } -static int videotoolbox_frame_params(AVCodecContext *avctx, - AVBufferRef *hw_frames_ctx) +int ff_videotoolbox_frame_params(AVCodecContext *avctx, + AVBufferRef *hw_frames_ctx) { AVHWFramesContext *frames_ctx = (AVHWFramesContext*)hw_frames_ctx->data; @@ -1193,9 +1183,9 @@ const AVHWAccel ff_h263_videotoolbox_hwaccel = { .start_frame = videotoolbox_mpeg_start_frame, .decode_slice = videotoolbox_mpeg_decode_slice, .end_frame = videotoolbox_mpeg_end_frame, - .frame_params = videotoolbox_frame_params, - .init = videotoolbox_common_init, - .uninit = videotoolbox_uninit, + .frame_params = ff_videotoolbox_frame_params, + .init = ff_videotoolbox_common_init, + .uninit = ff_videotoolbox_uninit, .priv_data_size = sizeof(VTContext), }; @@ -1209,9 +1199,9 @@ const AVHWAccel ff_hevc_videotoolbox_hwaccel = { .decode_slice = videotoolbox_hevc_decode_slice, .decode_params = videotoolbox_hevc_decode_params, .end_frame = videotoolbox_hevc_end_frame, - .frame_params = videotoolbox_frame_params, - .init = videotoolbox_common_init, - .uninit = videotoolbox_uninit, + .frame_params = ff_videotoolbox_frame_params, + .init = ff_videotoolbox_common_init, + .uninit = ff_videotoolbox_uninit, .priv_data_size = sizeof(VTContext), }; @@ -1225,9 +1215,9 @@ const AVHWAccel ff_h264_videotoolbox_hwaccel = { .decode_slice = ff_videotoolbox_h264_decode_slice, .decode_params = videotoolbox_h264_decode_params, .end_frame = videotoolbox_h264_end_frame, - .frame_params = videotoolbox_frame_params, - .init = videotoolbox_common_init, - .uninit = videotoolbox_uninit, + .frame_params = ff_videotoolbox_frame_params, + .init = ff_videotoolbox_common_init, + .uninit = ff_videotoolbox_uninit, .priv_data_size = sizeof(VTContext), }; @@ -1240,9 +1230,9 @@ const AVHWAccel ff_mpeg1_videotoolbox_hwaccel = { .start_frame = videotoolbox_mpeg_start_frame, .decode_slice = videotoolbox_mpeg_decode_slice, .end_frame = videotoolbox_mpeg_end_frame, - .frame_params = videotoolbox_frame_params, - .init = videotoolbox_common_init, - .uninit = videotoolbox_uninit, + .frame_params = ff_videotoolbox_frame_params, + .init = ff_videotoolbox_common_init, + .uninit = ff_videotoolbox_uninit, .priv_data_size = sizeof(VTContext), }; @@ -1255,9 +1245,9 @@ const AVHWAccel ff_mpeg2_videotoolbox_hwaccel = { .start_frame = videotoolbox_mpeg_start_frame, .decode_slice = videotoolbox_mpeg_decode_slice, .end_frame = videotoolbox_mpeg_end_frame, - .frame_params = videotoolbox_frame_params, - .init = videotoolbox_common_init, - .uninit = videotoolbox_uninit, + .frame_params = ff_videotoolbox_frame_params, + .init = ff_videotoolbox_common_init, + .uninit = ff_videotoolbox_uninit, .priv_data_size = sizeof(VTContext), }; @@ -1270,9 +1260,9 @@ const AVHWAccel ff_mpeg4_videotoolbox_hwaccel = { .start_frame = videotoolbox_mpeg_start_frame, .decode_slice = videotoolbox_mpeg_decode_slice, .end_frame = videotoolbox_mpeg_end_frame, - .frame_params = videotoolbox_frame_params, - .init = videotoolbox_common_init, - .uninit = videotoolbox_uninit, + .frame_params = ff_videotoolbox_frame_params, + .init = ff_videotoolbox_common_init, + .uninit = ff_videotoolbox_uninit, .priv_data_size = sizeof(VTContext), }; diff --git a/libavcodec/vt_internal.h b/libavcodec/vt_internal.h index fb64735b8c..e2f279d0fc 100644 --- a/libavcodec/vt_internal.h +++ b/libavcodec/vt_internal.h @@ -19,6 +19,9 @@ #ifndef AVCODEC_VT_INTERNAL_H #define AVCODEC_VT_INTERNAL_H +#include "avcodec.h" +#include "videotoolbox.h" + typedef struct VTContext { // The current bitstream buffer. uint8_t *bitstream; @@ -45,6 +48,12 @@ typedef struct VTContext { } VTContext; int ff_videotoolbox_alloc_frame(AVCodecContext *avctx, AVFrame *frame); +int ff_videotoolbox_common_init(AVCodecContext *avctx); +int ff_videotoolbox_frame_params(AVCodecContext *avctx, + AVBufferRef *hw_frames_ctx); +int ff_videotoolbox_buffer_copy(VTContext *vtctx, + const uint8_t *buffer, + uint32_t size); int ff_videotoolbox_uninit(AVCodecContext *avctx); int ff_videotoolbox_h264_start_frame(AVCodecContext *avctx, const uint8_t *buffer, @@ -52,6 +61,7 @@ int ff_videotoolbox_h264_start_frame(AVCodecContext *avctx, int ff_videotoolbox_h264_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size); +int ff_videotoolbox_common_end_frame(AVCodecContext *avctx, AVFrame *frame); CFDataRef ff_videotoolbox_avcc_extradata_create(AVCodecContext *avctx); CFDataRef ff_videotoolbox_hvcc_extradata_create(AVCodecContext *avctx);