From patchwork Mon Nov 22 21:58:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: rcombs X-Patchwork-Id: 31543 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp7665503iob; Mon, 22 Nov 2021 13:58:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJx3DTqLYY4aVI7ONNizI7FSXZUOkSZs9JVv3HmOgBKMUAKeTK6uunsgRI8c/lbrf5JC8vl9 X-Received: by 2002:a17:906:b884:: with SMTP id hb4mr715403ejb.376.1637618321331; Mon, 22 Nov 2021 13:58:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637618321; cv=none; d=google.com; s=arc-20160816; b=q6zWnt1aH51pyNPJpJMEyoCqpv8TT59hFZryCSPH0SVn7p4qJoLVqoU4uDfBg/TLXe ib0PghyW81JcW5/9blLBqAzB4HAFRlmDu2K9UmPmr1u+Cw+HGHtLkNgBElE+t9Ygu7rv fEf7ie500N0v6QKdvNGF17+po5u4adSWLXC+ZQuLTUW6t71M7VcwLfh6n4PFIsuTOdGo IFMchNVTr+kq4nhF26XD8ta8vwAnMOHOI6eOeruTarl3WFMu4jpKf33eke43NWoRpYgK mg/KiPO2PsQyGeuKCvIHoayoqwGLzRgeZTNh84nS0dhI2LPKXvu+m2nBhyZQqEOcWJUk uu8w== 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:message-id:date:to:from :dkim-signature:delivered-to; bh=63t6TLW7th4TPt6dkSBUPz2PkfLc3yLMGaDR++Ceenk=; b=FW0VPfZGAq6iBxuUrIkocGxQyb57pDDwPiMvUUpwoka6K6/mWu5XprkN0b4HnLH8XO 3XBsmJfrxT0H7HWiOwJq6F2251mRWuaWeA4wL9rD/i1YAHFaZqjidPZ4AarjEZ/Ii44I dd/V+XbHU/9IjYGmI0p9xHaixCFPfOexpOo2J2gwRKexXCYkcVOhZbSCaXWZ/VkfdoD/ nQlsbqKCqfXkZ2Gfx/Ia4K8ASbcnR+3Y6NYMaC6BeYuvsNtBFTxvbM26WvJjB18axujv AOikHs03dl6d/VW8GePvUscFUh0OC491YlRlI3uBYrsKagkmDxXkHnk8JT4hq09vvf71 sDgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@rcombs.me header.s=google header.b=UpUDWKBN; 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 r6si1747256edv.7.2021.11.22.13.58.39; Mon, 22 Nov 2021 13:58:41 -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=UpUDWKBN; 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 ADF4B688324; Mon, 22 Nov 2021 23:58:35 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io1-f51.google.com (mail-io1-f51.google.com [209.85.166.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C84B9689B6B for ; Mon, 22 Nov 2021 23:58:29 +0200 (EET) Received: by mail-io1-f51.google.com with SMTP id y16so25297318ioc.8 for ; Mon, 22 Nov 2021 13:58:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rcombs.me; s=google; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=WbJA7/NUFCQfQREc5BExWSRa4f9eL/VySokDsUX1AMg=; b=UpUDWKBNFT+eTD+x4TzogTBM/1tSjpZwFn5LAWclZ2xqhpULkgkMpgczSIG32AcyXr GrXlRxFDH6awKp1iLO1XixP+epeibl0cuttjOIhycfYqiutoAzPrWF/M/b5mcgiC6xdi Hto8roAtnCuLbX0gLv1pipsvkPFi1w2Y8sbIPAE+PvwKGsQW6ocLlK36Lez7MN8+ksci MOLPrd6Yzc3rMAaARMLFoEVJxnd1qnnMy9YzosdfAMUJV9/Kr6JElPgVqgsquAYrc+6m Itjn8XTcVUnfnCBG7jACnXdEmfomvWaoFDAK8/26llz4k8ynkYTJ3S0h9K5/n7ohhVbp GA/Q== 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:mime-version :content-transfer-encoding; bh=WbJA7/NUFCQfQREc5BExWSRa4f9eL/VySokDsUX1AMg=; b=Ci1k2IdE0dMI6nExigtN1FsZG2mhIZCS/3e+fwNOfipA2bO0gXm6voGZk0Cv1WgTnR MdDtG3s0gOuce7KZm2SgdGuaAA4A4z0spcuZET/aOnt0vR1jtTvwQQLEfxlA05FHPdVL WqLJYesAIdB//noQT9Yg2Tc4ToJEajf9TwHQeNJ3DYYahq0f02Iks96WmG7+hHY2BB3+ sPUq6YTEN4KcG/G6oDaiCL3px9yrWPLviT0HSvGo3xPu2wcxP7KiI7J+lR2jBLABhkH6 wCgG0j/2loLVyQeZT0pAr3eeO+WiZe8c/53t+unDote+8BPFd6R0s+4k7Uqq5yT6yxCb I8Mg== X-Gm-Message-State: AOAM532717iHsJbDGfR/Fqg+nw5CasL8w/NxKiQh6zR5en4VGSdrVISx ibVz8UbNV9s6fFTjSn/yKIrHO9QmQ4+JVzk= X-Received: by 2002:a05:6638:2055:: with SMTP id t21mr343748jaj.90.1637618307962; Mon, 22 Nov 2021 13:58:27 -0800 (PST) Received: from rcombs-mbp.localdomain ([2601:243:2000:5ac:edf5:499:2479:42a8]) by smtp.gmail.com with ESMTPSA id o1sm5668802ilj.41.2021.11.22.13.58.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Nov 2021 13:58:27 -0800 (PST) From: rcombs To: ffmpeg-devel@ffmpeg.org Date: Mon, 22 Nov 2021 15:58:06 -0600 Message-Id: <20211122215821.9849-1-rcombs@rcombs.me> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/16] ffmpeg: remove ffmpeg_videotoolbox 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: GhWaVbt+gnvV This was almost completely redundant. The only functionality that's no longer available after this removal is the videotoolbox_pixfmt arg, which has been obsolete for several years. --- fftools/Makefile | 4 - fftools/ffmpeg.c | 37 +------ fftools/ffmpeg.h | 10 -- fftools/ffmpeg_opt.c | 28 +----- fftools/ffmpeg_videotoolbox.c | 177 ---------------------------------- 5 files changed, 7 insertions(+), 249 deletions(-) delete mode 100644 fftools/ffmpeg_videotoolbox.c diff --git a/fftools/Makefile b/fftools/Makefile index 5234932ab0..da420786eb 100644 --- a/fftools/Makefile +++ b/fftools/Makefile @@ -10,10 +10,6 @@ ALLAVPROGS = $(AVBASENAMES:%=%$(PROGSSUF)$(EXESUF)) ALLAVPROGS_G = $(AVBASENAMES:%=%$(PROGSSUF)_g$(EXESUF)) OBJS-ffmpeg += fftools/ffmpeg_opt.o fftools/ffmpeg_filter.o fftools/ffmpeg_hw.o -ifndef CONFIG_VIDEOTOOLBOX -OBJS-ffmpeg-$(CONFIG_VDA) += fftools/ffmpeg_videotoolbox.o -endif -OBJS-ffmpeg-$(CONFIG_VIDEOTOOLBOX) += fftools/ffmpeg_videotoolbox.o define DOFFTOOL OBJS-$(1) += fftools/cmdutils.o fftools/$(1).o $(OBJS-$(1)-yes) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index c9a9cdfcd6..589d2efed3 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2859,12 +2859,7 @@ static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat break; } } - if (config) { - if (config->device_type != ist->hwaccel_device_type) { - // Different hwaccel offered, ignore. - continue; - } - + if (config && config->device_type == ist->hwaccel_device_type) { ret = hwaccel_decode_init(s); if (ret < 0) { if (ist->hwaccel_id == HWACCEL_GENERIC) { @@ -2877,36 +2872,10 @@ static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat } continue; } - } else { - const HWAccel *hwaccel = NULL; - int i; - for (i = 0; hwaccels[i].name; i++) { - if (hwaccels[i].pix_fmt == *p) { - hwaccel = &hwaccels[i]; - break; - } - } - if (!hwaccel) { - // No hwaccel supporting this pixfmt. - continue; - } - if (hwaccel->id != ist->hwaccel_id) { - // Does not match requested hwaccel. - continue; - } - ret = hwaccel->init(s); - if (ret < 0) { - av_log(NULL, AV_LOG_FATAL, - "%s hwaccel requested for input stream #%d:%d, " - "but cannot be initialized.\n", hwaccel->name, - ist->file_index, ist->st->index); - return AV_PIX_FMT_NONE; - } + ist->hwaccel_pix_fmt = *p; + break; } - - ist->hwaccel_pix_fmt = *p; - break; } return *p; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 1728010f56..21c63415d6 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -60,16 +60,8 @@ enum HWAccelID { HWACCEL_NONE = 0, HWACCEL_AUTO, HWACCEL_GENERIC, - HWACCEL_VIDEOTOOLBOX, }; -typedef struct HWAccel { - const char *name; - int (*init)(AVCodecContext *s); - enum HWAccelID id; - enum AVPixelFormat pix_fmt; -} HWAccel; - typedef struct HWDevice { const char *name; enum AVHWDeviceType type; @@ -626,7 +618,6 @@ extern int stdin_interaction; extern int frame_bits_per_raw_sample; extern AVIOContext *progress_avio; extern float max_error_rate; -extern char *videotoolbox_pixfmt; extern char *filter_nbthreads; extern int filter_complex_nbthreads; @@ -636,7 +627,6 @@ extern int auto_conversion_filters; extern const AVIOInterruptCB int_cb; extern const OptionDef options[]; -extern const HWAccel hwaccels[]; #if CONFIG_QSV extern char *qsv_device; #endif diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 6732a29625..f59986a648 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -134,12 +134,6 @@ static const char *const opt_name_enc_time_bases[] = {"enc_time_base" }\ } -const HWAccel hwaccels[] = { -#if CONFIG_VIDEOTOOLBOX - { "videotoolbox", videotoolbox_init, HWACCEL_VIDEOTOOLBOX, AV_PIX_FMT_VIDEOTOOLBOX }, -#endif - { 0 }, -}; HWDevice *filter_hw_device; char *vstats_filename; @@ -955,21 +949,10 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) else if (!strcmp(hwaccel, "auto")) ist->hwaccel_id = HWACCEL_AUTO; else { - enum AVHWDeviceType type; - int i; - for (i = 0; hwaccels[i].name; i++) { - if (!strcmp(hwaccels[i].name, hwaccel)) { - ist->hwaccel_id = hwaccels[i].id; - break; - } - } - - if (!ist->hwaccel_id) { - type = av_hwdevice_find_type_by_name(hwaccel); - if (type != AV_HWDEVICE_TYPE_NONE) { - ist->hwaccel_id = HWACCEL_GENERIC; - ist->hwaccel_device_type = type; - } + enum AVHWDeviceType type = av_hwdevice_find_type_by_name(hwaccel); + if (type != AV_HWDEVICE_TYPE_NONE) { + ist->hwaccel_id = HWACCEL_GENERIC; + ist->hwaccel_device_type = type; } if (!ist->hwaccel_id) { @@ -3844,9 +3827,6 @@ const OptionDef options[] = { { "hwaccel_output_format", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT | OPT_SPEC | OPT_INPUT, { .off = OFFSET(hwaccel_output_formats) }, "select output format used with HW accelerated decoding", "format" }, -#if CONFIG_VIDEOTOOLBOX - { "videotoolbox_pixfmt", HAS_ARG | OPT_STRING | OPT_EXPERT, { &videotoolbox_pixfmt}, "" }, -#endif { "hwaccels", OPT_EXIT, { .func_arg = show_hwaccels }, "show available HW acceleration methods" }, { "autorotate", HAS_ARG | OPT_BOOL | OPT_SPEC | diff --git a/fftools/ffmpeg_videotoolbox.c b/fftools/ffmpeg_videotoolbox.c deleted file mode 100644 index 4ba8618539..0000000000 --- a/fftools/ffmpeg_videotoolbox.c +++ /dev/null @@ -1,177 +0,0 @@ -/* - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "config.h" - -#if HAVE_UTGETOSTYPEFROMSTRING -#include -#endif - -#include "libavcodec/avcodec.h" -#include "libavcodec/videotoolbox.h" -#include "libavutil/imgutils.h" -#include "ffmpeg.h" - -typedef struct VTContext { - AVFrame *tmp_frame; - int log_once; -} VTContext; - -char *videotoolbox_pixfmt; - -static int videotoolbox_retrieve_data(AVCodecContext *s, AVFrame *frame) -{ - InputStream *ist = s->opaque; - VTContext *vt = ist->hwaccel_ctx; - CVPixelBufferRef pixbuf = (CVPixelBufferRef)frame->data[3]; - OSType pixel_format = CVPixelBufferGetPixelFormatType(pixbuf); - CVReturn err; - uint8_t *data[4] = { 0 }; - int linesize[4] = { 0 }; - int planes, ret, i; - - if (frame->format == ist->hwaccel_output_format) { - av_log_once(s, AV_LOG_INFO, AV_LOG_TRACE, &vt->log_once, - "There is no video filter for videotoolbox pix_fmt now, remove the " - "-hwaccel_output_format option if video filter doesn't work\n"); - return 0; - } - - av_frame_unref(vt->tmp_frame); - - switch (pixel_format) { - case kCVPixelFormatType_420YpCbCr8Planar: vt->tmp_frame->format = AV_PIX_FMT_YUV420P; break; - case kCVPixelFormatType_422YpCbCr8: vt->tmp_frame->format = AV_PIX_FMT_UYVY422; break; - case kCVPixelFormatType_32BGRA: vt->tmp_frame->format = AV_PIX_FMT_BGRA; break; -#ifdef kCFCoreFoundationVersionNumber10_7 - case kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange: - case kCVPixelFormatType_420YpCbCr8BiPlanarFullRange: vt->tmp_frame->format = AV_PIX_FMT_NV12; break; -#endif -#if HAVE_KCVPIXELFORMATTYPE_420YPCBCR10BIPLANARVIDEORANGE - case kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange: - case kCVPixelFormatType_420YpCbCr10BiPlanarFullRange: vt->tmp_frame->format = AV_PIX_FMT_P010; break; -#endif - default: - av_log(NULL, AV_LOG_ERROR, - "%s: Unsupported pixel format: %s\n", - av_fourcc2str(s->codec_tag), videotoolbox_pixfmt); - return AVERROR(ENOSYS); - } - - vt->tmp_frame->width = frame->width; - vt->tmp_frame->height = frame->height; - ret = av_frame_get_buffer(vt->tmp_frame, 0); - if (ret < 0) - return ret; - - err = CVPixelBufferLockBaseAddress(pixbuf, kCVPixelBufferLock_ReadOnly); - if (err != kCVReturnSuccess) { - av_log(NULL, AV_LOG_ERROR, "Error locking the pixel buffer.\n"); - return AVERROR_UNKNOWN; - } - - if (CVPixelBufferIsPlanar(pixbuf)) { - - planes = CVPixelBufferGetPlaneCount(pixbuf); - for (i = 0; i < planes; i++) { - data[i] = CVPixelBufferGetBaseAddressOfPlane(pixbuf, i); - linesize[i] = CVPixelBufferGetBytesPerRowOfPlane(pixbuf, i); - } - } else { - data[0] = CVPixelBufferGetBaseAddress(pixbuf); - linesize[0] = CVPixelBufferGetBytesPerRow(pixbuf); - } - - av_image_copy(vt->tmp_frame->data, vt->tmp_frame->linesize, - (const uint8_t **)data, linesize, vt->tmp_frame->format, - frame->width, frame->height); - - ret = av_frame_copy_props(vt->tmp_frame, frame); - CVPixelBufferUnlockBaseAddress(pixbuf, kCVPixelBufferLock_ReadOnly); - if (ret < 0) - return ret; - - av_frame_unref(frame); - av_frame_move_ref(frame, vt->tmp_frame); - - return 0; -} - -static void videotoolbox_uninit(AVCodecContext *s) -{ - InputStream *ist = s->opaque; - VTContext *vt = ist->hwaccel_ctx; - - ist->hwaccel_uninit = NULL; - ist->hwaccel_retrieve_data = NULL; - - av_frame_free(&vt->tmp_frame); - - av_videotoolbox_default_free(s); - av_freep(&ist->hwaccel_ctx); -} - -int videotoolbox_init(AVCodecContext *s) -{ - InputStream *ist = s->opaque; - int loglevel = (ist->hwaccel_id == HWACCEL_AUTO) ? AV_LOG_VERBOSE : AV_LOG_ERROR; - int ret = 0; - VTContext *vt; - - vt = av_mallocz(sizeof(*vt)); - if (!vt) - return AVERROR(ENOMEM); - - ist->hwaccel_ctx = vt; - ist->hwaccel_uninit = videotoolbox_uninit; - ist->hwaccel_retrieve_data = videotoolbox_retrieve_data; - - vt->tmp_frame = av_frame_alloc(); - if (!vt->tmp_frame) { - ret = AVERROR(ENOMEM); - goto fail; - } - - // TODO: reindent - if (!videotoolbox_pixfmt) { - ret = av_videotoolbox_default_init(s); - } else { - AVVideotoolboxContext *vtctx = av_videotoolbox_alloc_context(); - CFStringRef pixfmt_str = CFStringCreateWithCString(kCFAllocatorDefault, - videotoolbox_pixfmt, - kCFStringEncodingUTF8); -#if HAVE_UTGETOSTYPEFROMSTRING - vtctx->cv_pix_fmt_type = UTGetOSTypeFromString(pixfmt_str); -#else - av_log(s, loglevel, "UTGetOSTypeFromString() is not available " - "on this platform, %s pixel format can not be honored from " - "the command line\n", videotoolbox_pixfmt); -#endif - ret = av_videotoolbox_default_init2(s, vtctx); - CFRelease(pixfmt_str); - } - if (ret < 0) { - av_log(NULL, loglevel, "Error creating Videotoolbox decoder.\n"); - goto fail; - } - - return 0; -fail: - videotoolbox_uninit(s); - return ret; -}