From patchwork Mon Jun 7 23:03:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 28147 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp3886092iof; Mon, 7 Jun 2021 16:05:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHBjXqgG9VKOIMmzwYFmfRfLl4UZPaIO02YD9gsHb6kzh3vzvdxlEe8+SNSqKOxuNaTSNC X-Received: by 2002:a50:bf0f:: with SMTP id f15mr21965498edk.205.1623107111206; Mon, 07 Jun 2021 16:05:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623107111; cv=none; d=google.com; s=arc-20160816; b=OwQ+2ou2h2EqT//ObcZApX3Kj4J8H4lj79YTYs11mxTdnfToxY4I+duG/EZyrnghK9 D57XmbcAOrwuZe/SjUvRB7Zz64aejEe+S3z1MtVAMynejEfB6ccHrOFKWZeXj0khWeRS OdfuTloyD7+kLNUhm8AdkgWNsmvqdu8yNq8KhPO089H06w4kT7EmcaoG/rgnnehw1JKT d821a0qQLHC7+2hYz5eVWV1UDWe76vueNtPAkLhTXNlpHKw6hnKnaFBpIDkNkVgKqwiP YqZ/1tv6yh1XTWcDfUoMwf3Q08rdMzhQqXIs00pXtygLW/SQT8HC8Ji8ezrqmOjNs0TW jrvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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=dd488VGOg1orfwWdrC6UGUF/hEok2dsWQSkkSpWvR/8=; b=e/F53yKXI+BrmCXFqCNGkRs5d7BO8bL82zv2rHbV0bwBWX8/Bz/5DvnZjBa1pfKFjv sSyXPZM82QEZcIZplnS2bIBbt/naS1E3pLU3oSAIinM74OgWYMlXNeGpkekLa8S3aiDr 2yjoBnlqSa/tarFhbbmyAwHSP1IUxLt0RC98rO+ONzBOgFCm1Lkq0kCEKS96kiWn8zv/ II+uFTcIB1/H/WtqJ8Y4GZD3KcUc/qdfeRrdz4jKslRr7O/YIc5pknzslZoxZK8Lz/o+ QDE80ZxI2Jd5SIW5kh+3kKyFTpe2bzddOcVYP8GcC3/oh3VqZUMU1NMOPxZA+/sSJnq5 xySw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=lY1KP9et; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id de12si13652180ejc.296.2021.06.07.16.05.10; Mon, 07 Jun 2021 16:05:11 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b=lY1KP9et; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9AC916809A6; Tue, 8 Jun 2021 02:04:49 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 32B216808F5 for ; Tue, 8 Jun 2021 02:04:45 +0300 (EEST) Received: by mail-lf1-f45.google.com with SMTP id m21so13271673lfg.13 for ; Mon, 07 Jun 2021 16:04:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nIH6cDoD/RROiyfeOFQZIRrAU1jjsbsOmKPvhX1etiQ=; b=lY1KP9et+WHCb4A7FDIHZcZOHJNJKAdrKk8j7Z8d7t3e6WHghyEV22qUNJAHkJ+VYW RRuHEM+esAdvxDUHzYPbkrv/5cILa0rDmFrPHTXbMHXqLWOwmTmlwd/+jCx4EmKtJgiF zjIUQIYcap6STD26VKEVv466mBdnkKsMMpz+4OSg18asslCByGL3hIc9wRjzghqp97AH af0ffOsTp7nlRUTBW22Pnj4lx4bYoOP5Fqqus4Fx0NblZKOe/XrNSPVo09fPQL5WoHco dvzJVSAsIk2FbTg9HoSC1+E8EgKu/JTF6GDTbvPK1nhPgEf6L4HdUHk2b2GSf5UL+8Wz dBOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nIH6cDoD/RROiyfeOFQZIRrAU1jjsbsOmKPvhX1etiQ=; b=Ih9+C5tfTMYvvNc08aF9hXt0ZanddFIXWoGThXFx9tA6X9HUJN+NT1aOzC57Zi4Oxh ED1HlPoTccsJAaPv9C6X6pdqHoSUMaGk6RrB+m3XO3M5NcfoPl2cmVOpMnPFLVn93AJo KmGAB7S5KGnvJSVVMJzhjKKpX9DdkZ3RbbjnQzuHFycFsPvFEOJOZTbQIFKujHIoiG/x 9uhw56ws3doxqeoy1oZCDOg3noeNmcm8S551g7vI9U27K3hF1qK1RW1IJ8fmjXWUkai8 YEk9joQkph50ryr92cCtdZmoudYRc1uBKZ8VBIDWrXtT4Gl7iGbOV1HgtKL2IP0ifUoW 6qHg== X-Gm-Message-State: AOAM531i+RX0iYiBheIsB0K/1s7iNJwwaGFWij4iG40tfB6HbNmMCDbC eJdic8fOtYEDTKOFH7Wau24dgIeW/hR/BA== X-Received: by 2002:ac2:58c3:: with SMTP id u3mr9840205lfo.371.1623107084893; Mon, 07 Jun 2021 16:04:44 -0700 (PDT) Received: from localhost.localdomain (84-217-56-54.customers.ownit.se. [84.217.56.54]) by smtp.gmail.com with ESMTPSA id v9sm1999563ljv.131.2021.06.07.16.04.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jun 2021 16:04:44 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Jun 2021 01:03:58 +0200 Message-Id: <20210607230414.612-20-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210607230414.612-1-dcnieho@gmail.com> References: <20210607230414.612-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 19/35] avdevice/avdevice: Revert "Deprecate AVDevice Capabilities API" 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 Cc: Diederick Niehorster Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: TnCDjN/O1d5b This reverts commit 4f49ca7bbc75a9db4cdf93f27f95a668c751f160. This patch series will implement this capability for avdevice/dshow, enabling configuration discovery of DirectShow devices through the API, which is important for my use case. It enables making proper GUIs presenting users with options, instead of asking them to discover a dshow devices capabilities through the list_options option with an ffmpeg tool, and listing what they want to configure in text boxes. Signed-off-by: Diederick Niehorster --- libavdevice/avdevice.c | 71 ++++++++++++++++++++++++++++++++++++++---- libavdevice/avdevice.h | 5 --- libavformat/avformat.h | 21 +++++++++++++ libavformat/version.h | 2 +- 4 files changed, 87 insertions(+), 12 deletions(-) diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c index e339cebf2d..695b9143af 100644 --- a/libavdevice/avdevice.c +++ b/libavdevice/avdevice.c @@ -27,11 +27,39 @@ #include "libavutil/ffversion.h" const char av_device_ffversion[] = "FFmpeg version " FFMPEG_VERSION; -#if FF_API_DEVICE_CAPABILITIES +#define E AV_OPT_FLAG_ENCODING_PARAM +#define D AV_OPT_FLAG_DECODING_PARAM +#define A AV_OPT_FLAG_AUDIO_PARAM +#define V AV_OPT_FLAG_VIDEO_PARAM +#define OFFSET(x) offsetof(AVDeviceCapabilitiesQuery, x) + const AVOption av_device_capabilities[] = { + { "codec", "codec", OFFSET(codec), AV_OPT_TYPE_INT, + {.i64 = AV_CODEC_ID_NONE}, AV_CODEC_ID_NONE, INT_MAX, E|D|A|V }, + { "sample_format", "sample format", OFFSET(sample_format), AV_OPT_TYPE_SAMPLE_FMT, + {.i64 = AV_SAMPLE_FMT_NONE}, AV_SAMPLE_FMT_NONE, INT_MAX, E|D|A }, + { "sample_rate", "sample rate", OFFSET(sample_rate), AV_OPT_TYPE_INT, + {.i64 = -1}, -1, INT_MAX, E|D|A }, + { "channels", "channels", OFFSET(channels), AV_OPT_TYPE_INT, + {.i64 = -1}, -1, INT_MAX, E|D|A }, + { "channel_layout", "channel layout", OFFSET(channel_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, + {.i64 = -1}, -1, INT_MAX, E|D|A }, + { "pixel_format", "pixel format", OFFSET(pixel_format), AV_OPT_TYPE_PIXEL_FMT, + {.i64 = AV_PIX_FMT_NONE}, AV_PIX_FMT_NONE, INT_MAX, E|D|V }, + { "window_size", "window size", OFFSET(window_width), AV_OPT_TYPE_IMAGE_SIZE, + {.str = NULL}, -1, INT_MAX, E|D|V }, + { "frame_size", "frame size", OFFSET(frame_width), AV_OPT_TYPE_IMAGE_SIZE, + {.str = NULL}, -1, INT_MAX, E|D|V }, + { "fps", "fps", OFFSET(fps), AV_OPT_TYPE_RATIONAL, + {.dbl = -1}, -1, INT_MAX, E|D|V }, { NULL } }; -#endif + +#undef E +#undef D +#undef A +#undef V +#undef OFFSET unsigned avdevice_version(void) { @@ -68,18 +96,49 @@ int avdevice_dev_to_app_control_message(struct AVFormatContext *s, enum AVDevToA return s->control_message_cb(s, type, data, data_size); } -#if FF_API_DEVICE_CAPABILITIES int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s, AVDictionary **device_options) { - return AVERROR(ENOSYS); + int ret; + av_assert0(s && caps); + av_assert0(s->iformat || s->oformat); + if ((s->oformat && !s->oformat->create_device_capabilities) || + (s->iformat && !s->iformat->create_device_capabilities)) + return AVERROR(ENOSYS); + *caps = av_mallocz(sizeof(**caps)); + if (!(*caps)) + return AVERROR(ENOMEM); + (*caps)->device_context = s; + if (((ret = av_opt_set_dict(s->priv_data, device_options)) < 0)) + goto fail; + if (s->iformat) { + if ((ret = s->iformat->create_device_capabilities(s, *caps)) < 0) + goto fail; + } else { + if ((ret = s->oformat->create_device_capabilities(s, *caps)) < 0) + goto fail; + } + av_opt_set_defaults(*caps); + return 0; + fail: + av_freep(caps); + return ret; } void avdevice_capabilities_free(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s) { - return; + if (!s || !caps || !(*caps)) + return; + av_assert0(s->iformat || s->oformat); + if (s->iformat) { + if (s->iformat->free_device_capabilities) + s->iformat->free_device_capabilities(s, *caps); + } else { + if (s->oformat->free_device_capabilities) + s->oformat->free_device_capabilities(s, *caps); + } + av_freep(caps); } -#endif int avdevice_list_devices(AVFormatContext *s, AVDeviceInfoList **device_list) { diff --git a/libavdevice/avdevice.h b/libavdevice/avdevice.h index 4fbdf6aabc..7c5e77df00 100644 --- a/libavdevice/avdevice.h +++ b/libavdevice/avdevice.h @@ -331,7 +331,6 @@ int avdevice_dev_to_app_control_message(struct AVFormatContext *s, enum AVDevToAppMessageType type, void *data, size_t data_size); -#if FF_API_DEVICE_CAPABILITIES /** * Following API allows user to probe device capabilities (supported codecs, * pixel formats, sample formats, resolutions, channel counts, etc). @@ -427,7 +426,6 @@ typedef struct AVDeviceCapabilitiesQuery { /** * AVOption table used by devices to implement device capabilities API. Should not be used by a user. */ -attribute_deprecated extern const AVOption av_device_capabilities[]; /** @@ -447,7 +445,6 @@ extern const AVOption av_device_capabilities[]; * * @return >= 0 on success, negative otherwise. */ -attribute_deprecated int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s, AVDictionary **device_options); @@ -457,9 +454,7 @@ int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatConte * @param caps Device capabilities data to be freed. * @param s Context of the device. */ -attribute_deprecated void avdevice_capabilities_free(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s); -#endif /** * Structure describes basic parameters of the device. diff --git a/libavformat/avformat.h b/libavformat/avformat.h index adbdd712a7..6fd09f52cb 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -578,6 +578,16 @@ typedef struct AVOutputFormat { * @see avdevice_list_devices() for more details. */ int (*get_device_list)(struct AVFormatContext *s, struct AVDeviceInfoList *device_list); + /** + * Initialize device capabilities submodule. + * @see avdevice_capabilities_create() for more details. + */ + int (*create_device_capabilities)(struct AVFormatContext *s, struct AVDeviceCapabilitiesQuery *caps); + /** + * Free device capabilities submodule. + * @see avdevice_capabilities_free() for more details. + */ + int (*free_device_capabilities)(struct AVFormatContext *s, struct AVDeviceCapabilitiesQuery *caps); enum AVCodecID data_codec; /**< default data codec */ /** * Initialize format. May allocate data here, and set any AVFormatContext or @@ -749,6 +759,17 @@ typedef struct AVInputFormat { */ int (*get_device_list)(struct AVFormatContext *s, struct AVDeviceInfoList *device_list); + /** + * Initialize device capabilities submodule. + * @see avdevice_capabilities_create() for more details. + */ + int (*create_device_capabilities)(struct AVFormatContext *s, struct AVDeviceCapabilitiesQuery *caps); + + /** + * Free device capabilities submodule. + * @see avdevice_capabilities_free() for more details. + */ + int (*free_device_capabilities)(struct AVFormatContext *s, struct AVDeviceCapabilitiesQuery *caps); } AVInputFormat; /** * @} diff --git a/libavformat/version.h b/libavformat/version.h index 7f02e18f24..6519bba101 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -32,7 +32,7 @@ // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium) // Also please add any ticket numbers that you believe might be affected here #define LIBAVFORMAT_VERSION_MAJOR 59 -#define LIBAVFORMAT_VERSION_MINOR 3 +#define LIBAVFORMAT_VERSION_MINOR 4 #define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \