From patchwork Wed Mar 30 12:17:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 35055 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp773671pzb; Wed, 30 Mar 2022 05:18:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXbin8zEEluVaVSXtcGzPzXCLOIHRvwpYrzHtxiqnbFCElCX8q3e6D5meq5y9T9AsSsZp7 X-Received: by 2002:a05:6402:60e:b0:419:d2e:bcea with SMTP id n14-20020a056402060e00b004190d2ebceamr10364891edv.326.1648642721122; Wed, 30 Mar 2022 05:18:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648642721; cv=none; d=google.com; s=arc-20160816; b=tZAKxbLV1c1kKtk8GVQCODDj019luUpn53r3p58ot0hl508WwPpXl+q63cAsDaoUDK VUEm/Uvmx20znks2E9qJOHYaq+GtJggmdeZlLWp5YeL61fKDTnHxOemz0k0IA7lOfMEa 4+M9clbZCjFxW2G1XCpHWHscdrhcNyscB2HTyN2Yeym/Ze3sNlEQ1urAT0I8NhbMjL5/ nfWxg7DqnSv/iMRxpXQvjZoUE6tgDjOQDb0mZC0FKYzYfg5DKr+1CTJt5uZC8JTDLeKI jXrhWtc5hwjk/9gxLD/BSqlY8QR+PuG4+m1pOzk7svR7tvQAkGg4AU8JjGcEToNIE7Gn nSnw== 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=ziWDb/uH8Ug+a/ifWoMZpl8hLxB1eBWnYcnziMElX/E=; b=RfZZEs9wee0iNIgjJRCJRCs7zwi0xaW1nhV/7ipZUO6KlUC2rYFzQdwycsiELkrb64 MEHnUOsL4xG7gBFuzIEgpepwHbwyc6lonA352FRppRflgW/wdP7nJPgXxjt+JDW8Q+mZ lSsgQF2GyDigEE77LC7hoOkruPxgCbVzLvUp3rg4Iyr73rvNJpAdF6W320XivJ9WRVAO +kVi7NM4sihUB+O3hdUQQuk3dJ4QOdy50faKBdcXji8Y1BP5zkIGrpSBsTrGF4YjS+cv leJzv5OWyeRcWa6T13AjGJU2SlHCkCx1t4Ru32bBJ2kJpwAamscHNzoxYIhYPbuHm4YC H4sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="ZyMx8pj/"; 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 ot5-20020a170906ccc500b006e002ecc82esi20508734ejb.45.2022.03.30.05.18.40; Wed, 30 Mar 2022 05:18:41 -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=20210112 header.b="ZyMx8pj/"; 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 1720568B1DF; Wed, 30 Mar 2022 15:18:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BA1E268B122 for ; Wed, 30 Mar 2022 15:18:27 +0300 (EEST) Received: by mail-lj1-f172.google.com with SMTP id r22so27418451ljd.4 for ; Wed, 30 Mar 2022 05:18:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hP21fZm8JfZWDp5nhsf5pz5q6K9mehCDVrmzhfKoHXQ=; b=ZyMx8pj/QBisS9glGOT/lFPf00gTeVnC5SNX2l0PFKrlJ14+mkCWQz+elzuhiZwKd6 Gs3NapuIT5mRWvxoQSed6zQROqPmGbHpXnKcSJbjmWo6ZWnfJcZD160wlhFOqYkxwENb Zpfg44z6xZJjIg8psUjzVVMTNaAorCEFuQjqrD4cV5UoSBth2VVHT5NKItv7AzrGOZvn VrLb92Ul7i1hgDfhWCwzcYOsesx8RMlMq63ct5s/1wQaq0lNaRkszbsrahpi8h4iyoI3 43Gc+5FAhDlyYhIduCh+abQQWZT8hxV9eon/eUrw7akLE3eyVaV6iz6JiquqFcliCv4E fhNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hP21fZm8JfZWDp5nhsf5pz5q6K9mehCDVrmzhfKoHXQ=; b=aY/gkvl7J/p1kaCGfBQHGsjScMHLymHUem2d0b4Ile7j7rz2lOXML6DC88xhEZlOlr cm7OZag8b8cGooZu9fWeM4gNBozIxe+qrmVQoe+0I5kUnDorekBrG+zlgAp7GeVB0dhT qSOsWG+9QY4tJdLkT3uhran0uR740KK85iaOijzUAe/g1J3kVJRltaZREhgj34zAiE1r +grfj7f230p00RHKWQYGz8wWF854KX3lhk3wd3Jl/JQN5YLkflVF+4m2PeSm1NN03jXk oj4sE3cikMyhq56d3i07R0MkGgpDnx2CJpwx//P+/vbcbNl8yfeEvDEMmNHK5fzgjoBb Bw2Q== X-Gm-Message-State: AOAM5336HtmGyT5N4UDbQLgUlIYcjQsLZyLbw47Ok+Cd6bfYRgvn9TpZ I7X0hIojzaGAyKELdah33tZJO3ZWzC4= X-Received: by 2002:a2e:97c9:0:b0:249:8404:a5b7 with SMTP id m9-20020a2e97c9000000b002498404a5b7mr6421143ljj.57.1648642706772; Wed, 30 Mar 2022 05:18:26 -0700 (PDT) Received: from localhost.localdomain (deedock.humlab.lu.se. [130.235.135.183]) by smtp.gmail.com with ESMTPSA id bj15-20020a2eaa8f000000b00246233c02a5sm2364563ljb.44.2022.03.30.05.18.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 05:18:25 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Wed, 30 Mar 2022 14:17:46 +0200 Message-Id: <20220330121806.822-2-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20220330121806.822-1-dcnieho@gmail.com> References: <20220330121806.822-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 01/21] avdevice: lock to minor version of avformat 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: B2KjeZxpzC5R As per discussion on the list ( https://ffmpeg.org/pipermail/ffmpeg-devel/2021-June/281513.html, see especially https://ffmpeg.org/pipermail/ffmpeg-devel/2021-June/281586.html), to resolve the the unholy ABI-relationship between libavdevice and libavformat and allow easier working on the part of the avdevice API that lives in avformat, lock avdevice to a specific major and minor version of avformat. Documentation of this restriction added. Signed-off-by: Diederick Niehorster --- libavdevice/avdevice.c | 13 +++++++++++++ libavdevice/avdevice.h | 10 ++++++++++ libavdevice/version.h | 13 ++++++++++++- libavformat/avformat.h | 3 +++ libavformat/utils.c | 5 +++++ libavformat/version.h | 14 ++++++++++++-- libavutil/avutil.h | 3 +++ libavutil/macros.h | 3 +++ 8 files changed, 61 insertions(+), 3 deletions(-) diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c index 833d200054..98934abfb7 100644 --- a/libavdevice/avdevice.c +++ b/libavdevice/avdevice.c @@ -19,6 +19,7 @@ #include "libavutil/avassert.h" #include "libavutil/samplefmt.h" #include "libavutil/pixfmt.h" +#include "libavformat/version.h" #include "avdevice.h" #include "internal.h" #include "config.h" @@ -39,6 +40,18 @@ unsigned avdevice_version(void) return LIBAVDEVICE_VERSION_INT; } +unsigned avdevice_version_same_minor(void) +{ + // check version of loaded lavf has same major and minor version as + // this library was compiled against + // NB: this function doesn't have to be called, dynamic linker will + // signal error when avformat of wrong major or minor version is found. + if ((avformat_version_same_minor()) & ~0xFF != (LIBAVFORMAT_VERSION_INT & ~0xFF)) + abort(); + + return avdevice_version(); +} + const char * avdevice_configuration(void) { return FFMPEG_CONFIGURATION; diff --git a/libavdevice/avdevice.h b/libavdevice/avdevice.h index 0b32e59fed..db16a2f27e 100644 --- a/libavdevice/avdevice.h +++ b/libavdevice/avdevice.h @@ -47,6 +47,16 @@ * * To use libavdevice, simply call avdevice_register_all() to register all * compiled muxers and demuxers. They all use standard libavformat API. + * + * Note that libavdevice is locked to be used with the same major and minor + * version of libavformat that it was built against. Attempting to use a + * shared build of FFmpeg or its libavdevice library with a libavformat of + * a different major or minor version will generate a dynamic linker error. + * This is achieved by the internal function check_avformat_same_minor() in + * avdevice.c. This function does not have to be called, its call to + * avformat_version_same_minor() (a macro which expands to a name with the + * specific major and minor version of avformat embedded in it) is sufficient + * to trigger link failure. * * @{ */ diff --git a/libavdevice/version.h b/libavdevice/version.h index 09c1d778dc..4efe7f8649 100644 --- a/libavdevice/version.h +++ b/libavdevice/version.h @@ -26,10 +26,11 @@ */ #include "libavutil/version.h" +#include "libavutil/macros.h" #include "version_major.h" -#define LIBAVDEVICE_VERSION_MINOR 6 +#define LIBAVDEVICE_VERSION_MINOR 7 #define LIBAVDEVICE_VERSION_MICRO 100 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \ @@ -42,4 +43,14 @@ #define LIBAVDEVICE_IDENT "Lavd" AV_STRINGIFY(LIBAVDEVICE_VERSION) +/** + * avdevice_version_same_minor() expands to a function with + * the same minor and major version it was compiled against + * encoded in it. Enables locking to the minor version of + * other libraries they were compiled against. Does not have + * to be called by user. + */ +#define avdevice_version_same_minor AV_MAKE_MAJOR_MINOR_FUNC_NAME(device,LIBAVFORMAT_VERSION_MAJOR,LIBAVFORMAT_VERSION_MINOR) +unsigned avdevice_version_same_minor(void); + #endif /* AVDEVICE_VERSION_H */ diff --git a/libavformat/avformat.h b/libavformat/avformat.h index f12fa7d904..350912e272 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -64,6 +64,9 @@ * set by user for input, always set by user for output (unless you are dealing * with an AVFMT_NOFILE format). * + * Note that libavdevice is locked to a specific major and minor version of + * libavformat, see @ref lavd "libavdevice" for more details. + * * @section lavf_options Passing options to (de)muxers * It is possible to configure lavf muxers and demuxers using the @ref avoptions * mechanism. Generic (format-independent) libavformat options are provided by diff --git a/libavformat/utils.c b/libavformat/utils.c index 3f253c2045..6d9c4e778a 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -64,6 +64,11 @@ unsigned avformat_version(void) return LIBAVFORMAT_VERSION_INT; } +unsigned avformat_version_same_minor(void) +{ + return avformat_version(); +} + const char *avformat_configuration(void) { return FFMPEG_CONFIGURATION; diff --git a/libavformat/version.h b/libavformat/version.h index f4a26c2870..bb6a7d4510 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -28,11 +28,12 @@ */ #include "libavutil/version.h" +#include "libavutil/macros.h" #include "version_major.h" -#define LIBAVFORMAT_VERSION_MINOR 20 -#define LIBAVFORMAT_VERSION_MICRO 101 +#define LIBAVFORMAT_VERSION_MINOR 21 +#define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \ @@ -44,4 +45,13 @@ #define LIBAVFORMAT_IDENT "Lavf" AV_STRINGIFY(LIBAVFORMAT_VERSION) +/** + * avformat_version_same_minor() expands to a function with + * the same minor and major version it was compiled against + * encoded in it. Enables locking to the minor version of + * other libraries they were compiled against. + */ +#define avformat_version_same_minor AV_MAKE_MAJOR_MINOR_FUNC_NAME(format,LIBAVFORMAT_VERSION_MAJOR,LIBAVFORMAT_VERSION_MINOR) +unsigned avformat_version_same_minor(void); + #endif /* AVFORMAT_VERSION_H */ diff --git a/libavutil/avutil.h b/libavutil/avutil.h index 4d633156d1..94ce472c27 100644 --- a/libavutil/avutil.h +++ b/libavutil/avutil.h @@ -76,6 +76,9 @@ * situations may change slightly (and be documented). All those are accompanied * by an entry in doc/APIchanges and incrementing either the minor or micro * version number. + * + * Note that libavdevice is locked to a specific major and minor version of + * libavformat, see @ref lavd "libavdevice" for more details. */ /** diff --git a/libavutil/macros.h b/libavutil/macros.h index 2a7567c3ea..dab530a8a0 100644 --- a/libavutil/macros.h +++ b/libavutil/macros.h @@ -73,6 +73,9 @@ * @} */ +#define AV_MAKE_MAJOR_MINOR_FUNC_NAME_IMPL(name,major,minor) av ## name ## _version_ ## major ## _ ## minor +#define AV_MAKE_MAJOR_MINOR_FUNC_NAME(name,major,minor) AV_MAKE_MAJOR_MINOR_FUNC_NAME_IMPL(name,major,minor) + #define AV_PRAGMA(s) _Pragma(#s) #define FFALIGN(x, a) (((x)+(a)-1)&~((a)-1)) From patchwork Wed Mar 30 12:17:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 35057 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp773723pzb; Wed, 30 Mar 2022 05:18:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPaDddPMf3TGu7GsH1UUBiqqOdyonqmpmOQm6YwFnXH174qsfcngQlJ1z44Do0WNfUDQKU X-Received: by 2002:a17:907:97c7:b0:6e0:defd:342d with SMTP id js7-20020a17090797c700b006e0defd342dmr24516990ejc.231.1648642730163; Wed, 30 Mar 2022 05:18:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648642730; cv=none; d=google.com; s=arc-20160816; b=sVMKNlNblLjaIZ6JFJ49hzVNYKxmtMdQnovYFWXFcDiy2RiF8/rTQ/lTF1rJvLGQDX Y3GQHNFj5AUERym80Fpa4P3feoeWb+DNPs0SoRtBJoZOOLF4RRgygD4/0yLtJPy+8Q8h 3wGl7YKc4R3YmK+ax3crhMgLCwtIsD/2dF/U0OBO1W33Yms8T3kI9Mf4ph6OHo4pQ+Df GrTrZ4b3Oi1vrMVYFN6A0P/t+hVtQyq2nDSD/gb6PsJJjpBDUIyXZVy7618RS7LElk6c IjUCv5y1JBdimBwmKQZ+Kp1q7UCh2SXN/kMPRBIaPyI0mLcHYyVr41/PkgA77fmgogOD sQ4Q== 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=WmVuaO+az511jkoe2m+hwvc87+7RjxyNxG06HLWq0hg=; b=P+zMRpvl502stGQ+M4tHDa3AFxceN8saMxJT0Gc4YQeqRO/0Tb5U50SWa74TLRnK0N hFhXunkM/ymEx5oaomm5vW9NGwcIY7EXAaBnO3Wxo54BUvQLaYCezpZREiNKQgobuGmM fR+CS7h4DIgz8VFtmGbR2CasDG1tzrGucsJV2N51d1UqL/zCTkiajXw4bNq3be6OhVvL Xs6q56tGFyMmAn6TWNOJfFgsAUS3EE345oMaJNamEjNdvJulfMRHo8mSA7lk52k5qigQ depktFU8U5R13A9bYcPK6LDpANpOJDm7PrrhPpuI8pQdC1IDgY63owbuMwxmpmYPJtOk KPVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="p//Eyz2d"; 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 qx5-20020a170906fcc500b006df76385eebsi20248204ejb.907.2022.03.30.05.18.49; Wed, 30 Mar 2022 05:18:50 -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=20210112 header.b="p//Eyz2d"; 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 1CAD568B1FA; Wed, 30 Mar 2022 15:18:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8C49368B1C7 for ; Wed, 30 Mar 2022 15:18:34 +0300 (EEST) Received: by mail-lj1-f173.google.com with SMTP id q14so27376291ljc.12 for ; Wed, 30 Mar 2022 05:18:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uBEdleHp9I6jn/h5hd+DfiHaZTDwq6y2m0kaAQSrxZU=; b=p//Eyz2dU9huA49o9opmWr6EH604ZdlHMdMJjqRCouIi8qtru46xeVtt+2exER0G6z Rdqpd8bbfi/Oy7wm2nUMNDljdA7F5D+B1fJxnHzk5F5vEC78JxKnr8KAlhMwC4H+teCl IrW3YUnc/thOo2OVH1a6zxVW1XmovUaWQ5HPUnY9EN2bqXafgy7PtZ+tjSdN0ESgHgYM 5pR4wSE+qMOadNTeqehfHunTg6k0K6Tz2+ObvsaYFS4LFvcr9uqUTBVW2QFcKVKiWgau cT9VVxuQ6pM4mKYsHBAkbq1XpwiOc4gsoWmoB9kr+N2ArVZu/9Svn0VEFVfeG3w98jB+ c2Tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uBEdleHp9I6jn/h5hd+DfiHaZTDwq6y2m0kaAQSrxZU=; b=3scz4BO8PYAna4iqKkt0amCGqXz4deS2860HmLxFyPIpv9Qb1+eCH0jKSqXUXQZbC3 zC6mPUZQBOHH7y4RR+JwTwDt7y7TnbzNGbSfKe/5oi+FiVg9mUkLpqcHRAHqfqQiWeiG 171ezVJbXoXv1T9+WgjoZ8COSQEYvYNnieYHfYQ3OB5+F+pD/NYIVvgNMgqviOYfSWRJ SImxIrbTlPgls4IawyJkwQTWAoj0drc3/6MV6QtsS+0L+7FlNiQ+hQXPIdYLQs2FUEmC ijcs9Bb+4JgTOu3KeiA+QtAlLmD7bijtec4jIAlNgqvIx4Z9VJUbN9fUINRB+X9Jvso+ RoJw== X-Gm-Message-State: AOAM533iWtGcweNJdEUWwJ4X+vkFvGhYEE8ayKfXtgv4BsHd0vTVJKwv C2oAWTrCZ1HuEnzvqGTn8rT0ebXhqS0= X-Received: by 2002:a2e:a4a8:0:b0:249:6444:d29a with SMTP id g8-20020a2ea4a8000000b002496444d29amr6461670ljm.447.1648642713616; Wed, 30 Mar 2022 05:18:33 -0700 (PDT) Received: from localhost.localdomain (deedock.humlab.lu.se. [130.235.135.183]) by smtp.gmail.com with ESMTPSA id y18-20020a056512045200b0044a35fd9945sm2319264lfk.23.2022.03.30.05.18.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 05:18:33 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Wed, 30 Mar 2022 14:17:47 +0200 Message-Id: <20220330121806.822-3-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20220330121806.822-1-dcnieho@gmail.com> References: <20220330121806.822-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 02/21] avformat: add control_message function to AVInputFormat 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: AtAYhUqYpxEv Control messages are useful for programmatic control of not only outdevs but also indevs. Bumping avformat version. Signed-off-by: Diederick Niehorster --- libavdevice/avdevice.c | 8 +++++--- libavformat/avformat.h | 6 ++++++ libavformat/version.h | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c index 98934abfb7..43d3406670 100644 --- a/libavdevice/avdevice.c +++ b/libavdevice/avdevice.c @@ -66,9 +66,11 @@ const char * avdevice_license(void) int avdevice_app_to_dev_control_message(struct AVFormatContext *s, enum AVAppToDevMessageType type, void *data, size_t data_size) { - if (!s->oformat || !s->oformat->control_message) - return AVERROR(ENOSYS); - return s->oformat->control_message(s, type, data, data_size); + if (s->oformat && s->oformat->control_message) + return s->oformat->control_message(s, type, data, data_size); + if (s->iformat && s->iformat->control_message) + return s->iformat->control_message(s, type, data, data_size); + return AVERROR(ENOSYS); } int avdevice_dev_to_app_control_message(struct AVFormatContext *s, enum AVDevToAppMessageType type, diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 350912e272..06db024559 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -785,6 +785,12 @@ typedef struct AVInputFormat { */ int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags); + /** + * Allows sending messages from application to device. + */ + int (*control_message)(struct AVFormatContext *s, int type, + void *data, size_t data_size); + /** * Returns device list with it properties. * @see avdevice_list_devices() for more details. diff --git a/libavformat/version.h b/libavformat/version.h index bb6a7d4510..d195704a31 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -32,7 +32,7 @@ #include "version_major.h" -#define LIBAVFORMAT_VERSION_MINOR 21 +#define LIBAVFORMAT_VERSION_MINOR 22 #define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ From patchwork Wed Mar 30 12:17:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 35058 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp773786pzb; Wed, 30 Mar 2022 05:18:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytEV9fnZL+xTFqVh7+bmN0TU68fOVOx1SW4uaZ9J9IAiVz9pX0KB4IEJxxlbpK1QfcZkvv X-Received: by 2002:a05:6402:42c6:b0:419:276a:dded with SMTP id i6-20020a05640242c600b00419276addedmr10323088edc.2.1648642738899; Wed, 30 Mar 2022 05:18:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648642738; cv=none; d=google.com; s=arc-20160816; b=DfVIt7kICBgK62syMG90ANszD1vi5xz5NpsGeyIfIRG5YqWFM3rWyy0bgOeJoVFSj8 2yFZv91buI8nANQeruLJ1LrhMcUPhTQXJX4N+pf6xfBi2cuxVWI8fH8T9QTMZONowjhO l4wBYpokOlyQtVYFwhJLn8ENe8Y6FAqjM+Ho4hzniYplOp55O0goB6DLWn2g6X8bQ+PM hD2cSppSek/5RQXIOyVJiyts31LL1756g4Oe1kTlQ/ICQVOUnOkXJUfUidatPq56HJjR oi3G7IECjoD4WZWueypGRrQWSfhv+apDDMttrNpI9ytQSt7tXmOPaW+uisK/TVOyPMgd 0Y7w== 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=O15lZgTMephQ9dyjkZhOHzs8gzJVfqUXZuYP9ol1BB0=; b=g1lAx67nLd97uptnY6vCfvyy6YvDrEF6FYYr6J1RNWfPRBqdSnuhqt/mpFHQxvlAEn NquQ+QvWI5HNfeZBYjQmT/ZaBuo36dCwedJ0k9JKp2e2Jpa3DbyYmfnf9tez2VTjXo8R godVOcd4glPZnarKGModwj5V4b0YO7kJTNCD5xvmhDZhWpa8qJcLrtPEl1W6uJUJZ7Ax o9sWzlvjjI5ZZkuGAO0Rea2e/6tZAuTeFNsDNBS5aCalp9Cu9lADRuTKwOO6Y0hbG0PO dX0Tx6kx6t8Id79P7Jxo3MoYXBrJOsRkatn4QUMalYvoE46E1F5+fRJdHJOuSXINc1MZ lGhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="HM/TUujx"; 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 ky3-20020a170907778300b006df76385f1fsi20434275ejc.959.2022.03.30.05.18.58; Wed, 30 Mar 2022 05:18:58 -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=20210112 header.b="HM/TUujx"; 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 2842868B1FB; Wed, 30 Mar 2022 15:18:47 +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 02D7D68B159 for ; Wed, 30 Mar 2022 15:18:41 +0300 (EEST) Received: by mail-lf1-f45.google.com with SMTP id bt26so35452608lfb.3 for ; Wed, 30 Mar 2022 05:18:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mColGxwyuFwu4Z8UoHQjQkqEwKQRklFDL2AuubPFmZ8=; b=HM/TUujx8beufeRYWRqPzLXg+7gSzLqMXyV+5L8Jd+JKfJRGb2wbr+F7iGOrFEewjM JwTJuC8z2GPNkp7G/NeZ9Qble2IKFUdu6X9GnhabNVae0Zv3hVzgIja+xuBrXdBaD45W bD8R1NJ0i/QVi2RSYCc5+7iw1IYs7JlJvJUvwiPDzQ3L/QYLxZmcLX3Zh0wVsxAIZC8y 8gHK/pEYLfNfGEpiMOEY9mlITzCUQZ9y1M4Bkcgj7ClHmDuufYD8UbEPsiEKtSHqSQKe HLxKypJ3SQQKH04SB9mPAb8fYOzN5GA0bdQEfLBnnncJKE82gNMj6A9YTrsrUeqsp+s2 HL0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mColGxwyuFwu4Z8UoHQjQkqEwKQRklFDL2AuubPFmZ8=; b=z1Ahp76Wt3HJezOcZu+TBt/jsldT5WK5F3SMp6n8X1R9izzRL219hqaacosHfFAcDm 9P8bcAwkpCZGFtzN25NBVUKUv787DLuDUKLtxAb9qh+MBoWmvtQh0N6r7Ea2XtVgY8Ds 0v1wtKeeu8UIFZuJ882I4SRZSrzpzLlPZIonkf9Xp4Whr210tK9huA8OXtTWnSD5yCy6 Dn9qOo2cFHcVOISvNI5S9c/g1+h4SQljFPwdgXns4KpmzvDd6FTN9aJ7S5NtF1eDr9C7 KPRbeALpZxcq51TTb9f8dc6tm/8gAYu/zHdk2T8JcGIFHJNA8yGcm4EzJGsLt7x3vLeI A7KA== X-Gm-Message-State: AOAM532C8jj8UgXDWh9RDM9+tpSsqT/KR0f5OrQ5oJvm7O1Up+52UMxd U4vYQ9XTwFISyNGBAkAXqUIDPxJryVI= X-Received: by 2002:a05:6512:b83:b0:44a:9fb7:784b with SMTP id b3-20020a0565120b8300b0044a9fb7784bmr6461386lfv.547.1648642720133; Wed, 30 Mar 2022 05:18:40 -0700 (PDT) Received: from localhost.localdomain (deedock.humlab.lu.se. [130.235.135.183]) by smtp.gmail.com with ESMTPSA id f14-20020a056512322e00b0044a1507b232sm2316431lfe.120.2022.03.30.05.18.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 05:18:39 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Wed, 30 Mar 2022 14:17:48 +0200 Message-Id: <20220330121806.822-4-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20220330121806.822-1-dcnieho@gmail.com> References: <20220330121806.822-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 03/21] avdevice/dshow: implement control_message interface 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: A7dYFkcroSN/ This allows programmatic users of avdevice to start and stop the DirectShow Capture graph (i.e. receive frames or not). This is important because now the buffer fills up and starts dropping samples when enqueued packets are not read out immediately after the demuxer is opened. Bumping avdevice version. Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 42 +++++++++++++++++++++++++++++++++++++ libavdevice/dshow_capture.h | 1 + libavdevice/version.h | 2 +- 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index abb8325bc3..652e093204 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -1503,6 +1503,45 @@ error: return ret; } +static int dshow_control_message(AVFormatContext *avctx, int type, void *data, size_t data_size) +{ + struct dshow_ctx *ctx = avctx->priv_data; + int run_state = ctx->is_running; + HRESULT hr; + + switch (type) { + case AV_APP_TO_DEV_PAUSE: + run_state = 0; + break; + case AV_APP_TO_DEV_PLAY: + run_state = 1; + break; + case AV_APP_TO_DEV_TOGGLE_PAUSE: + run_state = !run_state; + break; + } + + // if play state change requested, apply + if (run_state != ctx->is_running) { + if (run_state) + hr = IMediaControl_Run(ctx->control); + else + hr = IMediaControl_Pause(ctx->control); + + if (hr == S_FALSE) { + OAFilterState pfs; + hr = IMediaControl_GetState(ctx->control, 0, &pfs); + } + if (hr != S_OK) { + av_log(avctx, AV_LOG_ERROR, "Could not run/pause graph\n"); + return AVERROR(EIO); + } + ctx->is_running = run_state; + } + + return 0; +} + static enum AVCodecID waveform_codec_id(enum AVSampleFormat sample_fmt) { switch (sample_fmt) { @@ -1747,6 +1786,7 @@ static int dshow_read_header(AVFormatContext *avctx) } // don't exit yet, allow it to list crossbar options in dshow_open_device } + ctx->is_running = 0; if (ctx->device_name[VideoDevice]) { if ((r = dshow_open_device(avctx, devenum, VideoDevice, VideoSourceDevice)) < 0 || (r = dshow_add_device(avctx, VideoDevice)) < 0) { @@ -1820,6 +1860,7 @@ static int dshow_read_header(AVFormatContext *avctx) av_log(avctx, AV_LOG_ERROR, "Could not run graph (sometimes caused by a device already in use by other application)\n"); goto error; } + ctx->is_running = 1; ret = 0; @@ -1932,6 +1973,7 @@ const AVInputFormat ff_dshow_demuxer = { .read_packet = dshow_read_packet, .read_close = dshow_read_close, .get_device_list= dshow_get_device_list, + .control_message= dshow_control_message, .flags = AVFMT_NOFILE | AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK, .priv_class = &dshow_class, }; diff --git a/libavdevice/dshow_capture.h b/libavdevice/dshow_capture.h index b548cd7afc..d0dd35a670 100644 --- a/libavdevice/dshow_capture.h +++ b/libavdevice/dshow_capture.h @@ -331,6 +331,7 @@ struct dshow_ctx { IMediaControl *control; IMediaEvent *media_event; + int is_running; enum AVPixelFormat pixel_format; enum AVCodecID video_codec_id; diff --git a/libavdevice/version.h b/libavdevice/version.h index 4efe7f8649..fb1dccb6b3 100644 --- a/libavdevice/version.h +++ b/libavdevice/version.h @@ -31,7 +31,7 @@ #include "version_major.h" #define LIBAVDEVICE_VERSION_MINOR 7 -#define LIBAVDEVICE_VERSION_MICRO 100 +#define LIBAVDEVICE_VERSION_MICRO 101 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \ LIBAVDEVICE_VERSION_MINOR, \ From patchwork Wed Mar 30 12:17:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 35059 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp773884pzb; Wed, 30 Mar 2022 05:19:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtFIjCZ3Z5Nr2Xu9o8mzWRzpiVOpqGtKEDwLxG/8faPE4TQVZst/eLCszEby7i68F8l/TF X-Received: by 2002:a17:907:7f8c:b0:6e0:614f:f13e with SMTP id qk12-20020a1709077f8c00b006e0614ff13emr39629813ejc.488.1648642748544; Wed, 30 Mar 2022 05:19:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648642748; cv=none; d=google.com; s=arc-20160816; b=QAgNHRkH5D7PnEZ+ebTnH7jBTntP8UmNOm9WSEfHTuy9G3xR7I98Us68sI+vE3SKFa brKiDr6M37z8m/dmcDz7H/kFDqySRSFWHRRWJ2CgHkObOTyS+JNT/1NDYOnqVRa84Svd 5v8PULOFLLANkUV6IX/PoTzc8XDYuiF195oJ5GVmI/ruaFOlvOBE8dnyCB9ABf7Es7ms sYOaXMtskP+o8nbchNmKzyIhLRPwTPXchTgovsjdzhjSF9nZ0r7zxxt5MaR71knS1gig GJSt1K2MWztVMWijBdU7E/3+iRHMNcTGr/+YwBJhSTP6GcZQtSEf/MMSc/v77Gcwm6zQ sbTg== 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=EWPyOsXiMKAFlXGhr/BO/fZoukarMvlYpbcDalr2gtY=; b=YssF21LP9ot9DcHGfCNrKUIeMfN1Xovo5f4650NxyLwWDdiIm0dBLOo9PWIgeFOAs3 1rR/ZJuyl62ZdbyQjHAekkhZq2Cx82mvQ4Dzws45ocFziG55z3E3Qjm4pkWcP5izgsbv yTV5cMjKe08R5a7iOv6przRCcX+UIxfwTXhVRTR3nsGzcU+Yy70mdLBlBWJ5LkMw+Rn7 W7d2b7M73WKVWtYgXeULhf4yU9zPJjQUP4SnRJiU1jh2wv642GzZl63iq079a3IJkKhL qufeCcfM3ZIime0b/gR/TA9JJh6N2tIKDinLOHWw2ztcbtdGHvbYqHfOrgb9eWFGIcIc 2RQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=VwayYTbj; 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 j2-20020a170906474200b006df76385d45si20158546ejs.485.2022.03.30.05.19.08; Wed, 30 Mar 2022 05:19:08 -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=20210112 header.b=VwayYTbj; 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 2615068B210; Wed, 30 Mar 2022 15:18:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 55D8A68B1D4 for ; Wed, 30 Mar 2022 15:18:47 +0300 (EEST) Received: by mail-lj1-f179.google.com with SMTP id s13so10356820ljd.5 for ; Wed, 30 Mar 2022 05:18:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QMaDrP2eKDaJUfNBiigoWDNyVq8EvrUM+I4kIu04BHg=; b=VwayYTbjqlXSXgGS0iJaPsOvu4fsvD7GROsn+1IzzgHMrwcDzM6VuQkOUVOLx3kuPp WmsIMBly5Wu8TturqpnHZKswcaLyyWLQHAUdYx30xZWEHroEyHVlW2Qoqe3KpTgb2WhB zumHf1ihiPcsN2uq1zNO5bslPDhNuaHvWzQEdsgpTxNYL/cDKvV9MnZHalOBnsJL0DUZ bs2pwSlVuKM4kQFTwy0wxJL7m19rBEXYW87rte1tT8GXuGdexFrISHcs7hh5sRPXX74k q8b1PhjX6vDbJZnTcaCgxIpiEUFw+ebzwBB0OOjmtb3RvbUtTyxD38ntEqKzM6Z0Ls8p lqUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QMaDrP2eKDaJUfNBiigoWDNyVq8EvrUM+I4kIu04BHg=; b=Su3IDSnuZQOjOO/3uUop7rWX2EP2AvYlzq028jgVJu66pZI8Rof7KewZJt+KhpNx8O gjocS2dGvEoa1CsV+TJ7G1EW5wmubgDrc59ppgtsKFiTRrhkJU0Mfh/zOBL9dj4X8hyX MS9+SmxzY2FJIYGXB6F5GTB0VSEBhvaeLne3UJU88WeLHtgLDkoTkmeZbSsHWxDzOMoi NVVqViu3PC7kUQbbJ6ykMrcYSghQimO+XtGaesOBb0Kgzd/UnUeSlj6pF2x3AHAE3S+t 2IgZ2/JuUSbPPUf+ywlqX/idUCH52mbCIsxto5SHoW2jsy/VzVIJ9JehaOLTIKA6GPEe wPMQ== X-Gm-Message-State: AOAM533AOYVP2LeJrOv8SydphhWc0IxYO/kwZNd1p2T4SK1oLGQ8PCVD qQFUC5sM477+cM223QuKwAeOGPtQrvw= X-Received: by 2002:a2e:96d9:0:b0:249:8257:74ca with SMTP id d25-20020a2e96d9000000b00249825774camr6704206ljj.105.1648642726420; Wed, 30 Mar 2022 05:18:46 -0700 (PDT) Received: from localhost.localdomain (deedock.humlab.lu.se. [130.235.135.183]) by smtp.gmail.com with ESMTPSA id t10-20020a19910a000000b0044a8de015acsm1165095lfd.1.2022.03.30.05.18.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 05:18:46 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Wed, 30 Mar 2022 14:17:49 +0200 Message-Id: <20220330121806.822-5-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20220330121806.822-1-dcnieho@gmail.com> References: <20220330121806.822-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 04/21] avdevice: add control message requesting to show config dialog 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: IBb+vv/wqNrf This control message can be used to programmatically ask a device to show one of its configuration dialogs. Adding documentation of this message's int argument. Bumping avdevice version. Signed-off-by: Diederick Niehorster --- doc/indevs.texi | 34 ++++++++++++++++++++++++++++++++++ libavdevice/avdevice.h | 10 ++++++++++ libavdevice/version.h | 4 ++-- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/doc/indevs.texi b/doc/indevs.texi index 9d8020311a..0302859552 100644 --- a/doc/indevs.texi +++ b/doc/indevs.texi @@ -682,6 +682,40 @@ $ ffmpeg -f dshow -show_video_device_dialog true -crossbar_video_input_pin_numbe @end itemize +@subsection Libavdevice user notes + +The dshow device supports the @code{avdevice_app_to_dev_control_message} +interface. + +It understands the @code{AV_APP_TO_DEV_PAUSE}, @code{AV_APP_TO_DEV_PLAY} +and @code{AV_APP_TO_DEV_TOGGLE_PAUSE} commands, which respective stop and +start whether data is captured from the connected device, and toggle +capture state. + +It furthermore understands the @code{AV_APP_TO_DEV_CONFIG} message, which +requests the device to show a configuration dialog (if available). An +@code{int} should be passed along with this command to indicate which +configuration dialog should be shown. The bits in this @code{int} have +the following meaning: + +@itemize @bullet +@item +1st bit: If set, the dialog for the audio device will be shown. If not set +the dialog for the video device will be shown. + +@item +2nd bit: If set, show property dialog for the audio or video capture device, +allowing to change audio or video filter properties and configurations +manually. + +@item +3rd bit: If set, show property dialog where crossbar pin routings of the +audio/video device can be manually modified. + +@item +4th bit: If set, show property dialog where TV channels and frequencies can be manually modified (in case of video device), or TV audio (like mono vs. stereo, Language A, B or C) can be manually modified in case of audio device. +@end itemize + @section fbdev Linux framebuffer input device. diff --git a/libavdevice/avdevice.h b/libavdevice/avdevice.h index db16a2f27e..74e9518a8e 100644 --- a/libavdevice/avdevice.h +++ b/libavdevice/avdevice.h @@ -206,6 +206,16 @@ enum AVAppToDevMessageType { */ AV_APP_TO_DEV_GET_VOLUME = MKBETAG('G', 'V', 'O', 'L'), AV_APP_TO_DEV_GET_MUTE = MKBETAG('G', 'M', 'U', 'T'), + + /** + * Request to show configuration dialog. + * + * If device has a configuration dialog of type indicated by + * data, show it. + * + * data: int (device-specific). + */ + AV_APP_TO_DEV_CONFIG = MKBETAG('C', 'O', 'N', 'F'), }; /** diff --git a/libavdevice/version.h b/libavdevice/version.h index fb1dccb6b3..f27f9ad9bf 100644 --- a/libavdevice/version.h +++ b/libavdevice/version.h @@ -30,8 +30,8 @@ #include "version_major.h" -#define LIBAVDEVICE_VERSION_MINOR 7 -#define LIBAVDEVICE_VERSION_MICRO 101 +#define LIBAVDEVICE_VERSION_MINOR 8 +#define LIBAVDEVICE_VERSION_MICRO 100 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \ LIBAVDEVICE_VERSION_MINOR, \ From patchwork Wed Mar 30 12:17:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 35060 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp773952pzb; Wed, 30 Mar 2022 05:19:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcPylvlOuoqW/ofPyFGJqWeWpIwO0kjL+1Gkaj8J3lVpsk1cTEmtV+OTXQTamU36XtDQcA X-Received: by 2002:a50:ec96:0:b0:419:75fb:a07b with SMTP id e22-20020a50ec96000000b0041975fba07bmr10288078edr.316.1648642758929; Wed, 30 Mar 2022 05:19:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648642758; cv=none; d=google.com; s=arc-20160816; b=f1oc2fF3yn/A8l2xiqSjp5m1KYrrc+sAqHrbK0OYatAhWYAtPsFqGXDtgqiGCJaUI0 GVzeiPx79u59DwsRa1hvFSwvywcoUTZABVVGvgK9IitFXvDneBRarHdY73yRJqeSuGW8 7UIxvmpTOLQRVoN6bWFPbRfI1r5T3F3FQRqGCebos58ltCD1m43eDO26tQ49V0Np2i1r PIZLCpeuHzEQhBeluZcamqOAq3dUtv0xDAV+gnCZRmnnC1q+Do7plW3PcgpSCRFAZWrY vZCJIJsnMjIPCsMU8fW5CMQogN3v7inVLHKqyNMGtu96nz6Ro0xPyvIx2qDgu4viyeQP UofA== 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=qZBSiQQxre/XhbTpWK0HUMsyUYGYp1VWZkESF4VPI7I=; b=Jm/JN4ZJ0G/CU+dxO9+MNsBZ/CIEwPQkjec7HTyR7PakLabo0UVgPAF1tdKCV8iCZm kdqlQmfVx7lWilCIvHSSeSc7Q9C0jDO1MZoOz4gEmvtsD8tR6mJoiDQkUhM7MHbneElY rNXPbGz+4b5JrtXAXmFYgeJv6Ke0CHqmJrdmsVBfefCrG65F5T3KN8HS1CR9RCbaN1KX oxeLI1/3CxxnSOWEi859sxepuNusZOmr+gLS5ivyRyiweivLwal/sU0qZ7JXAL5mgGoB r75O9ypwH3BKDvzrLs3pJwLGgTDy+ejF41zWYDbe69nuOGpRie4XRqJ6yQIoOSqXVAWH aOKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=ClrRLseG; 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 l4-20020a170907914400b006df76385c56si15920065ejs.246.2022.03.30.05.19.18; Wed, 30 Mar 2022 05:19:18 -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=20210112 header.b=ClrRLseG; 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 1AB5868B21F; Wed, 30 Mar 2022 15:19:00 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1D99368B1D4 for ; Wed, 30 Mar 2022 15:18:54 +0300 (EEST) Received: by mail-lf1-f51.google.com with SMTP id e16so35421182lfc.13 for ; Wed, 30 Mar 2022 05:18:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gvjbBjGhD+4DTkoqUBR4omF9/1lb4OFPtJ3RkssfsRQ=; b=ClrRLseG6F1UlJV3rG/lXuh8l16hYzU6DPKEBdY+xckNvyEyRERZ44iB6imbByGHgH p//ARZIyowPyXH7c3LXIN5f5tC1gyPnZykNzmDC/I239kVvl74zaNrmJHvzvyfWRMXgv wA1A5Ip1fyyanAOcgk0LzmW2gFrinuGdt0pyR7E7T8aj/f92duNuQ6MQu2vpkOG2K/hj oDLWmb/S5l0Hsk64QQFwquxzRzjdYXKmFTXsCB3mDnPTgmCSIUQ/8cxz1XGzpAVuP99l 5fiMbb3nuW/TwfoCvrKvyYEtFlLHS1A8gcrFnm5leyXsloj3ijDA/rHCWMAgcCgM/fDb UuYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gvjbBjGhD+4DTkoqUBR4omF9/1lb4OFPtJ3RkssfsRQ=; b=OI4f79SaYVlJ1Y6b6zoh4tepxBsjxtGN/7hFQbGwogGTX7RW5jMZk1zz9W66/Sd2lb 6VVlss8fiL1RJ7e6dAPfW69I1Zfg9VGCT0tYMEkgk7eW2Dwjl2q8+yHyt/rlG+/CBBnk qjrE+YVqN3ZIzxbSYOmkPM/4Wb5XjyJbkj7AGxJNzjeJ+LPMf/8qKu3wzxu+VVEiCGCO bDgH+4t0ZYVkLnA3uE2SuXhvPvVYQblqKEO+H2UKlxoTCpfor7WwwWvu4GYCze3aQn7H zFC1sfrBAvrV0OGtDAMsP6wih7u0SackzWcfsNuoHyla3MAyybJxpmuXv9dGnALt4680 1SXA== X-Gm-Message-State: AOAM531/aYO5NrCqtK0S1fQ4VQqt1lGMQEtOSrQ6peE24ptZdG4on1i4 6zbVL5jdNo6ACkv2/Y4kSjKxuKNBCYc= X-Received: by 2002:a05:6512:b12:b0:44a:ba81:f874 with SMTP id w18-20020a0565120b1200b0044aba81f874mr3234909lfu.449.1648642733125; Wed, 30 Mar 2022 05:18:53 -0700 (PDT) Received: from localhost.localdomain (deedock.humlab.lu.se. [130.235.135.183]) by smtp.gmail.com with ESMTPSA id b35-20020a0565120ba300b0044a909dba3asm1124805lfv.266.2022.03.30.05.18.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 05:18:52 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Wed, 30 Mar 2022 14:17:50 +0200 Message-Id: <20220330121806.822-6-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20220330121806.822-1-dcnieho@gmail.com> References: <20220330121806.822-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 05/21] avdevice/dshow: accept show config dialog control message 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: 713n5E8KAhd4 DirectShow source will pop up its configuration dialog when AV_APP_TO_DEV_CONFIG is received. Implementation for several other possible configuration dialogs is more involved and will be provided in the next commit. Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 652e093204..78194406b5 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -1508,6 +1508,7 @@ static int dshow_control_message(AVFormatContext *avctx, int type, void *data, s struct dshow_ctx *ctx = avctx->priv_data; int run_state = ctx->is_running; HRESULT hr; + int ret = 0; switch (type) { case AV_APP_TO_DEV_PAUSE: @@ -1519,6 +1520,32 @@ static int dshow_control_message(AVFormatContext *avctx, int type, void *data, s case AV_APP_TO_DEV_TOGGLE_PAUSE: run_state = !run_state; break; + case AV_APP_TO_DEV_CONFIG: { + /* For documentation of dialog variable, see ffmpeg-devices.html in docs */ + int dialog; + enum dshowDeviceType devtype; + + if (!data) + av_log(avctx, AV_LOG_ERROR, "Use the data argument to indicate which dialog should be shown."); + dialog = *(int *) data; + devtype = (dialog & 1) ? AudioDevice : VideoDevice; + + if (dialog & 1<<1) { + // device_dialog + if (ctx->device_filter[devtype]) + ff_dshow_show_filter_properties(ctx->device_filter[devtype], avctx); + } else if (dialog & 1<<2) { + // crossbar_connection_dialog + // TODO + } else if (dialog & 1<<3) { + // tv_tuner_dialog + // TODO + } + break; + } + + default: + ret = AVERROR(ENOSYS); } // if play state change requested, apply @@ -1539,7 +1566,7 @@ static int dshow_control_message(AVFormatContext *avctx, int type, void *data, s ctx->is_running = run_state; } - return 0; + return ret; } static enum AVCodecID waveform_codec_id(enum AVSampleFormat sample_fmt) From patchwork Wed Mar 30 12:17:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 35061 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp774032pzb; Wed, 30 Mar 2022 05:19:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwDlWnTrEyWQUwATPBVdr9PlnYfd7qpSIZzAi0ftWEKGuSmGX00W1HjpVldy8NaFGql7ff9 X-Received: by 2002:a05:6402:183:b0:410:fde:887a with SMTP id r3-20020a056402018300b004100fde887amr10042510edv.243.1648642768776; Wed, 30 Mar 2022 05:19:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648642768; cv=none; d=google.com; s=arc-20160816; b=Hc7AIpsV3lcGsSCDSLX+C8qVFcjlgjd/T0zK0wtztecMnVb3fSCEDvcuJwbgQGMXjr IxYdPjYFq6SwDIxoA8/opLXCaX3xXtbRHhkfbclFxhSetE1j02FTUKB5qlGafQsxzxc3 0SOoHk2kKYqtw2450BrxzmGjL+47kSmkTppy0ERg6w62uTnJKT0nx6OLUO6Ohs+YOalM Qg97LRf/qgbqbOgjF1lhAkJbBfSdrVWcEl5bvRGTJD7UuTfrA45dgLypy1hllHSt2gg9 i8aEpIE0FzS0hNW5wKC4OUF5++UnQ93uSaWAuwdtHQ9rhOaH4ZA7zzvA4xYdeO7DeN3F +65Q== 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=1K879ca22CxwE+lQTZjUywVk0qtqUMeg0VOt0IcRz7s=; b=rC6KqnNI7F12xvnfr8ClP726hyeLE2vzw4p6FNftVP2ToANmaWrdYHqZRfegQdv3QC XTOGt+3N2t7RHHZbgN8vj5VOvhix/HdC7qwXs20HHQ5tC7G5iLhRA2lqlkE62PJwhpfT zgk5eGJUdinsEAEQGSVYjm42U2eHs+8Z8ggx1NPTYTaYpjiszc+ymEic7kYPWFSMF93u oTlbJoi7kmxbbpWXpCGi7B8g95wimHZrqm6JIV8XWXVVuJ/DjOdaT70bUHa/L8TyGPIC npcz1Gxy65DKDnZlG23GPFiBLsS7YwqM+vkCMgeee/Se3BwP7YZumjFPHbarmEzHqNjn LtNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=dZ7Cj3E3; 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 y9-20020a056402440900b00418c2b5bec9si1182609eda.427.2022.03.30.05.19.28; Wed, 30 Mar 2022 05:19:28 -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=20210112 header.b=dZ7Cj3E3; 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 2514D68B240; Wed, 30 Mar 2022 15:19:02 +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 9C8BE68B211 for ; Wed, 30 Mar 2022 15:19:00 +0300 (EEST) Received: by mail-lf1-f45.google.com with SMTP id z12so21681093lfu.10 for ; Wed, 30 Mar 2022 05:19:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rY5TpXorhBWUUE8+86HXbtsRyp9ZtkdEBGzNzBRY4s4=; b=dZ7Cj3E3HjRxm90FYykMmuNhRoLNwjSKZ7xHGqw4M62X76jDDaXF0Z2EmU4hZ9bZju n6TWiohat2kR4gUEF0JsPy6vOiAzEz6wtSB/lamx4Cu8Xn7JmowF77Vn9xOGNl7HQ4lz IisY4Tm26GuwmnyLq3oKj7oz32Bz0Gg2xVbFXz6MWAs2s8obY4KuDgnhp7BPa8K2oTs1 iEL7I+3eqhEKyu3yojjmO3HPP0gfRuZjIaZz9VpS/ac2VmOlH8rkmZeAiC7weMfU4NOz L/A3HP0t5M5JYutOzoyaZUHqPoB99Nrf1Hz8o5t6Uw4nBYrxFxEB2oeiasiNBlwqeXlS Yyjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rY5TpXorhBWUUE8+86HXbtsRyp9ZtkdEBGzNzBRY4s4=; b=VbIVHgQYutBZ0oYszV1aJVajfcOyXadqLf3/hcG2E+dDz68D1ecGA+DI7qXmuyGbyf NtF2BGgdz3UC2c2qxjyKC4B8THVf5SKaA9eKGfOcdATzYTcdiDuFyh5dtXbGvQQaFN6C wFZBt/854k+l0dtR8qA0FbqNOZW+ehVuZ4OBAYDZTxUEtKixwAlwBvf9+BoYMtEJR1yC ffOzYM2BQrCnUGiQiHgOxM2R2T1nJNztDQu9ZpybaBk6+ueLJg4OYupwO1fz3n90LbwV xT0MvCYGrYDb0+Hr6jEvuLjdAsFLrrYmNDBLy5R+ZbtqNTqGRJsXC1Eg0QYIRPExQl7Q URmg== X-Gm-Message-State: AOAM531Gsvy8KSNHDpqPSS1cv5cTDV1Lnn/EMONdytQ4nStUQVK/ADei COU/IsBpEVBcR0Bn+afPQBRcqaVRbuU= X-Received: by 2002:ac2:4c47:0:b0:44a:151f:a76e with SMTP id o7-20020ac24c47000000b0044a151fa76emr6716344lfk.121.1648642739654; Wed, 30 Mar 2022 05:18:59 -0700 (PDT) Received: from localhost.localdomain (deedock.humlab.lu.se. [130.235.135.183]) by smtp.gmail.com with ESMTPSA id f12-20020a05651c02cc00b002495ddc58easm2367586ljo.32.2022.03.30.05.18.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 05:18:59 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Wed, 30 Mar 2022 14:17:51 +0200 Message-Id: <20220330121806.822-7-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20220330121806.822-1-dcnieho@gmail.com> References: <20220330121806.822-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 06/21] avdevice/dshow: add config dialog command for crossbar and tv tuner 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: RYKZZ8xtiwSJ The "show config dialog" command message can now also trigger dialog boxes for the crossbar connecting pins filter the analog tuner audio / analog tuner filters. Bumping avdevice version. Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 51 ++++++++++++++++++-- libavdevice/dshow_capture.h | 10 ++++ libavdevice/dshow_crossbar.c | 91 +++++++++++++++++++++++------------- libavdevice/version.h | 2 +- 4 files changed, 115 insertions(+), 39 deletions(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 78194406b5..a780351170 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -240,6 +240,11 @@ dshow_read_close(AVFormatContext *s) struct dshow_ctx *ctx = s->priv_data; PacketListEntry *pktl; + if (ctx->graph_builder2[VideoDevice]) + ICaptureGraphBuilder2_Release(ctx->graph_builder2[VideoDevice]); + if (ctx->graph_builder2[AudioDevice]) + ICaptureGraphBuilder2_Release(ctx->graph_builder2[AudioDevice]); + if (ctx->control) { IMediaControl_Stop(ctx->control); IMediaControl_Release(ctx->control); @@ -1464,6 +1469,7 @@ dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum, av_log(avctx, AV_LOG_ERROR, "Could not create CaptureGraphBuilder2\n"); goto error; } + ctx->graph_builder2[devtype] = graph_builder2; ICaptureGraphBuilder2_SetFiltergraph(graph_builder2, graph); if (r != S_OK) { av_log(avctx, AV_LOG_ERROR, "Could not set graph for CaptureGraphBuilder2\n"); @@ -1488,9 +1494,6 @@ dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum, ret = 0; error: - if (graph_builder2 != NULL) - ICaptureGraphBuilder2_Release(graph_builder2); - if (pers_stream) IPersistStream_Release(pers_stream); @@ -1536,10 +1539,48 @@ static int dshow_control_message(AVFormatContext *avctx, int type, void *data, s ff_dshow_show_filter_properties(ctx->device_filter[devtype], avctx); } else if (dialog & 1<<2) { // crossbar_connection_dialog - // TODO + if (ctx->device_filter[devtype] && ctx->graph_builder2[devtype]) { + IAMCrossbar *cross_bar = NULL; + IBaseFilter *cross_bar_base_filter = NULL; + hr = ff_dshow_get_crossbar_and_filter(ctx->graph_builder2[devtype], ctx->device_filter[devtype], cross_bar, &cross_bar_base_filter); + + if (hr == S_OK && cross_bar_base_filter) + ff_dshow_show_filter_properties(cross_bar_base_filter, avctx); + + if (cross_bar) + IAMCrossbar_Release(cross_bar); + if (cross_bar_base_filter) + IBaseFilter_Release(cross_bar_base_filter); + } } else if (dialog & 1<<3) { // tv_tuner_dialog - // TODO + if (ctx->device_filter[devtype] && ctx->graph_builder2[devtype]) { + if (devtype == VideoDevice) { + IAMTVTuner *tv_tuner_filter = NULL; + IBaseFilter *tv_tuner_base_filter = NULL; + hr = ff_dshow_get_tvtuner_and_filter(ctx->graph_builder2[devtype], ctx->device_filter[devtype], tv_tuner_filter, tv_tuner_base_filter); + + if (hr == S_OK && tv_tuner_base_filter) + ff_dshow_show_filter_properties(tv_tuner_base_filter, avctx); + + if (tv_tuner_filter) + IAMTVTuner_Release(tv_tuner_filter); + if (tv_tuner_base_filter) + IBaseFilter_Release(tv_tuner_base_filter); + } else { + IAMAudioInputMixer *tv_audio_filter = NULL; + IBaseFilter *tv_audio_base_filter = NULL; + hr = ff_dshow_get_audiomixer_and_filter(ctx->graph_builder2[devtype], ctx->device_filter[devtype], tv_audio_filter, tv_audio_base_filter); + + if (hr == S_OK && tv_audio_base_filter) + ff_dshow_show_filter_properties(tv_audio_base_filter, avctx); + + if (tv_audio_filter) + IAMAudioInputMixer_Release(tv_audio_filter); + if (tv_audio_base_filter) + IBaseFilter_Release(tv_audio_base_filter); + } + } } break; } diff --git a/libavdevice/dshow_capture.h b/libavdevice/dshow_capture.h index d0dd35a670..94ba9896b7 100644 --- a/libavdevice/dshow_capture.h +++ b/libavdevice/dshow_capture.h @@ -318,6 +318,7 @@ struct dshow_ctx { IPin *device_pin[2]; DShowFilter *capture_filter[2]; DShowPin *capture_pin[2]; + ICaptureGraphBuilder2 *graph_builder2[2]; HANDLE mutex; HANDLE event[2]; /* event[0] is set by DirectShow @@ -352,6 +353,15 @@ struct dshow_ctx { HRESULT ff_dshow_try_setup_crossbar_options(ICaptureGraphBuilder2 *graph_builder2, IBaseFilter *device_filter, enum dshowDeviceType devtype, AVFormatContext *avctx); +HRESULT ff_dshow_get_crossbar_and_filter(ICaptureGraphBuilder2 *graph_builder2, IBaseFilter *device_filter, + IAMCrossbar *cross_bar, IBaseFilter **cross_bar_base_filter); + +HRESULT ff_dshow_get_tvtuner_and_filter(ICaptureGraphBuilder2 *graph_builder2, IBaseFilter *device_filter, + IAMTVTuner *tv_tuner_filter, IBaseFilter *tv_tuner_base_filter); + +HRESULT ff_dshow_get_audiomixer_and_filter(ICaptureGraphBuilder2 *graph_builder2, IBaseFilter *device_filter, + IAMAudioInputMixer *tv_audio_filter, IBaseFilter *tv_audio_base_filter); + void ff_dshow_show_filter_properties(IBaseFilter *pFilter, AVFormatContext *avctx); #endif /* AVDEVICE_DSHOW_CAPTURE_H */ diff --git a/libavdevice/dshow_crossbar.c b/libavdevice/dshow_crossbar.c index 961defe690..6b714e849c 100644 --- a/libavdevice/dshow_crossbar.c +++ b/libavdevice/dshow_crossbar.c @@ -133,6 +133,44 @@ setup_crossbar_options(IAMCrossbar *cross_bar, enum dshowDeviceType devtype, AVF return S_OK; } +HRESULT +ff_dshow_get_crossbar_and_filter(ICaptureGraphBuilder2 *graph_builder2, IBaseFilter *device_filter, + IAMCrossbar *cross_bar, IBaseFilter **cross_bar_base_filter) +{ + HRESULT hr = ICaptureGraphBuilder2_FindInterface(graph_builder2, &LOOK_UPSTREAM_ONLY, (const GUID *) NULL, + device_filter, &IID_IAMCrossbar, (void **) &cross_bar); + if (hr != S_OK) + /* no crossbar found */ + return hr; + + if (cross_bar_base_filter) + hr = IAMCrossbar_QueryInterface(cross_bar, &IID_IBaseFilter, (void**)cross_bar_base_filter); + + return hr; +} + +HRESULT +ff_dshow_get_tvtuner_and_filter(ICaptureGraphBuilder2 *graph_builder2, IBaseFilter *device_filter, + IAMTVTuner *tv_tuner_filter, IBaseFilter *tv_tuner_base_filter) +{ + HRESULT hr = ICaptureGraphBuilder2_FindInterface(graph_builder2, &LOOK_UPSTREAM_ONLY, NULL, + device_filter, &IID_IAMTVTuner, (void **) &tv_tuner_filter); + if (hr == S_OK) + hr = IAMCrossbar_QueryInterface(tv_tuner_filter, &IID_IBaseFilter, (void **) &tv_tuner_base_filter); + return hr; +} + +HRESULT +ff_dshow_get_audiomixer_and_filter(ICaptureGraphBuilder2 *graph_builder2, IBaseFilter *device_filter, + IAMAudioInputMixer *tv_audio_filter, IBaseFilter *tv_audio_base_filter) +{ + HRESULT hr = ICaptureGraphBuilder2_FindInterface(graph_builder2, &LOOK_UPSTREAM_ONLY, NULL, + device_filter, &IID_IAMTVAudio, (void **) &tv_audio_filter); + if (hr == S_OK) + hr = IAMCrossbar_QueryInterface(tv_audio_filter, &IID_IBaseFilter, (void **) &tv_audio_base_filter); + return hr; +} + /** * Given a fully constructed graph, check if there is a cross bar filter, and configure its pins if so. */ @@ -140,55 +178,42 @@ HRESULT ff_dshow_try_setup_crossbar_options(ICaptureGraphBuilder2 *graph_builder2, IBaseFilter *device_filter, enum dshowDeviceType devtype, AVFormatContext *avctx) { - struct dshow_ctx *ctx = avctx->priv_data; - IAMCrossbar *cross_bar = NULL; - IBaseFilter *cross_bar_base_filter = NULL; - IAMTVTuner *tv_tuner_filter = NULL; - IBaseFilter *tv_tuner_base_filter = NULL; - IAMAudioInputMixer *tv_audio_filter = NULL; - IBaseFilter *tv_audio_base_filter = NULL; + struct dshow_ctx *ctx = avctx->priv_data; + IAMCrossbar *cross_bar = NULL; + IBaseFilter *cross_bar_base_filter = NULL; + IAMTVTuner *tv_tuner_filter = NULL; + IBaseFilter *tv_tuner_base_filter = NULL; + IAMAudioInputMixer *tv_audio_filter = NULL; + IBaseFilter *tv_audio_base_filter = NULL; HRESULT hr; + int should_show_crossbar_properties = (devtype == VideoDevice) ? ctx->show_video_crossbar_connection_dialog : ctx->show_audio_crossbar_connection_dialog; - hr = ICaptureGraphBuilder2_FindInterface(graph_builder2, &LOOK_UPSTREAM_ONLY, (const GUID *) NULL, - device_filter, &IID_IAMCrossbar, (void**) &cross_bar); + hr = ff_dshow_get_crossbar_and_filter(graph_builder2, device_filter, cross_bar, should_show_crossbar_properties ? &cross_bar_base_filter : NULL); if (hr != S_OK) { - /* no crossbar found */ - hr = S_OK; + if (!cross_bar) + /* no crossbar found */ + hr = S_OK; goto end; } + /* TODO some TV tuners apparently have multiple crossbars? */ - if (devtype == VideoDevice && ctx->show_video_crossbar_connection_dialog || - devtype == AudioDevice && ctx->show_audio_crossbar_connection_dialog) { - hr = IAMCrossbar_QueryInterface(cross_bar, &IID_IBaseFilter, (void **) &cross_bar_base_filter); - if (hr != S_OK) - goto end; + if (should_show_crossbar_properties && cross_bar_base_filter) ff_dshow_show_filter_properties(cross_bar_base_filter, avctx); - } if (devtype == VideoDevice && ctx->show_analog_tv_tuner_dialog) { - hr = ICaptureGraphBuilder2_FindInterface(graph_builder2, &LOOK_UPSTREAM_ONLY, NULL, - device_filter, &IID_IAMTVTuner, (void**) &tv_tuner_filter); - if (hr == S_OK) { - hr = IAMCrossbar_QueryInterface(tv_tuner_filter, &IID_IBaseFilter, (void **) &tv_tuner_base_filter); - if (hr != S_OK) - goto end; + hr = ff_dshow_get_tvtuner_and_filter(graph_builder2, device_filter, tv_tuner_filter, tv_tuner_base_filter); + if (hr == S_OK && tv_tuner_base_filter) ff_dshow_show_filter_properties(tv_tuner_base_filter, avctx); - } else { + else av_log(avctx, AV_LOG_WARNING, "unable to find a tv tuner to display dialog for!"); - } } if (devtype == AudioDevice && ctx->show_analog_tv_tuner_audio_dialog) { - hr = ICaptureGraphBuilder2_FindInterface(graph_builder2, &LOOK_UPSTREAM_ONLY, NULL, - device_filter, &IID_IAMTVAudio, (void**) &tv_audio_filter); - if (hr == S_OK) { - hr = IAMCrossbar_QueryInterface(tv_audio_filter, &IID_IBaseFilter, (void **) &tv_audio_base_filter); - if (hr != S_OK) - goto end; + hr = ff_dshow_get_audiomixer_and_filter(graph_builder2, device_filter, tv_audio_filter, tv_audio_base_filter); + if (hr == S_OK && tv_audio_base_filter) ff_dshow_show_filter_properties(tv_audio_base_filter, avctx); - } else { + else av_log(avctx, AV_LOG_WARNING, "unable to find a tv audio tuner to display dialog for!"); - } } hr = setup_crossbar_options(cross_bar, devtype, avctx); diff --git a/libavdevice/version.h b/libavdevice/version.h index f27f9ad9bf..e2c8757b27 100644 --- a/libavdevice/version.h +++ b/libavdevice/version.h @@ -31,7 +31,7 @@ #include "version_major.h" #define LIBAVDEVICE_VERSION_MINOR 8 -#define LIBAVDEVICE_VERSION_MICRO 100 +#define LIBAVDEVICE_VERSION_MICRO 101 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \ LIBAVDEVICE_VERSION_MINOR, \ From patchwork Wed Mar 30 12:17:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 35062 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp774093pzb; Wed, 30 Mar 2022 05:19:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWZBFzTYSY2X6hpkypK1o6eBI7VEjymMsTCxS0Kp9F2til2Ky9WAgBEjydKWyFxjYm4etr X-Received: by 2002:a05:6402:1d4d:b0:419:430b:5734 with SMTP id dz13-20020a0564021d4d00b00419430b5734mr10171646edb.212.1648642779054; Wed, 30 Mar 2022 05:19:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648642779; cv=none; d=google.com; s=arc-20160816; b=isRjV6Eixop1n2rUuRgOBgfKzBQcyUylBGk1cOHcEX59HfT0+QnGtnQ8D75AA2nQaP TakzYLaAGSK4iVnJiL7OGGzPiPX/jE0E0BAAUdTZqfJGwZeeIuFqa8ugMDB+i5vTD6AB qkHofVr0AsdPNA3XyEO57wmrn3+qBqOoID5dyCG93JjVBGbaiZtsOuqN8GLVhfh3ugBY rh/u0EJsnr8voPnuDLgsGQTLsBrJgTmX2qAuu7FVD47YJTUMUqRp717tAtm/thgMp+zb yRSN/a5LjuPG7/SPJVt27u+ZSBvLSxVa5ZQ+gAUzioBZtCEh6jpmj1RNBF3isRA8bb7b B4fA== 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=n/aHuP4YuhjtRth9Ec5BNa1R09I3K9xukEsApNUYDGs=; b=i70bIoZVXcH0vHwySUTeXHX2THj0UmyLTdxLghCgyUezPk5DFbtB3ZMCQ7Ie6r3WnB CgBECNRyGoG193Gn6jOeFvk4oDX6WRKVBSMvBOMD/gnyT4CXTzqvSifw48WbdIljmws2 M8HN202UhrW5+A/8RU/q6v5QZDvv9jofgtzLivPe3t+OXUl9fuPHSl+MZkbQsAlfHJNX diorKp0PfbSOziv7Xkso9w0FuWuOuGQVoUFHxE2uMibxWxrIASkf0EgLMVrqMjiAh93I yMc9nOg8JyAttfa0gf4vr3P8h34eUwW3Z+DG9H21r6untiVkbPtrSb8gpSiA5Xme+66N 62GQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=erL33M28; 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 i16-20020a05640242d000b00418f10ac963si27775966edc.455.2022.03.30.05.19.38; Wed, 30 Mar 2022 05:19:39 -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=20210112 header.b=erL33M28; 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 11BBF68B250; Wed, 30 Mar 2022 15:19:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 85A5B68B1C7 for ; Wed, 30 Mar 2022 15:19:07 +0300 (EEST) Received: by mail-lf1-f44.google.com with SMTP id bq24so19518009lfb.5 for ; Wed, 30 Mar 2022 05:19:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OnFGvV5xb2ExfjkAeQSE/RQePA+HWBrJZj3rPD2CcE4=; b=erL33M28XERefPR8S47Ry4HO9y0fqkFdSf6zXKT+w3MZhmwMV0YY/+QrWM5KCUAfTB r0gW/hjEyaamOF9GXqbhcJxcTGX5fDXLzUKvfWIadskuyDMF+cOi5YCQRph3xNMX3esy yNU/z882x6ghJR+Nv84qRgn28a/4XdIdV5n+jfr+EkqHal2Qp0Kb84MiU+GeUb39FZ1B LAjsYmOWGRU/ExJCdJ+/FLmzpvXtfflVEjuLtgiENSoUagVTpKfeab2sUItWg05hlXQa 3mExMhVt6U8W4KZnpUzTkX2woMj1XPvX6X3KY/U0NjyxrwAJMa2yBa3s2ZY+MHSrpzsQ XQPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OnFGvV5xb2ExfjkAeQSE/RQePA+HWBrJZj3rPD2CcE4=; b=ciuujDDUOJ3CZXPRvc+5qs4hF1FKQSv5poPCQNFB2LsE+YwILMbEreQYs8AtCHtZRY idBrmnXkQoX3jddZOYqrh/THy49jP/gFyBP8kRkSS4ddifmDRFxJF1SJqMf0TyQYb+J8 NA0I4uQY21Ky4Gi8qETL2KJiSVQFqHZDSHgd6JSfCtO2jEk0tJL1HcHLgCIBq+kHRGj3 8Yqae2xvrohcuFnEkDV9wkdN2f93pYiqQ6ffdvztqAh8ubvHNH9QuGahK3oTfKt4FDUA S+6Hgn/0e9FQpcJKk2T+uMKg62F4SS+ATDtRBMc5V54nZ7jYPe2FghceNCSRhELcaJao JA7g== X-Gm-Message-State: AOAM533fGriHXKZo4OWOmDIYdsgCm+XPXk39WkYIHEHjbOo1F0YsXcIt AQzs9nZJzJPVy3j/Ii3E5QNFm3K097g= X-Received: by 2002:a05:6512:3086:b0:44a:50c3:c9dd with SMTP id z6-20020a056512308600b0044a50c3c9ddmr6658643lfd.289.1648642746131; Wed, 30 Mar 2022 05:19:06 -0700 (PDT) Received: from localhost.localdomain (deedock.humlab.lu.se. [130.235.135.183]) by smtp.gmail.com with ESMTPSA id e3-20020a196743000000b0044311216c42sm2318181lfj.307.2022.03.30.05.19.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 05:19:05 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Wed, 30 Mar 2022 14:17:52 +0200 Message-Id: <20220330121806.822-8-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20220330121806.822-1-dcnieho@gmail.com> References: <20220330121806.822-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 07/21] 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: 122dXOuaZgqh This reverts commit 4f49ca7bbc75a9db4cdf93f27f95a668c751f160. The next few patches clean up the API and implement this capability for avdevice/dshow. Bumping avformat and avdevice version. Signed-off-by: Diederick Niehorster --- libavdevice/avdevice.c | 71 ++++++++++++++++++++++++++++++++++++++---- libavdevice/avdevice.h | 5 --- libavdevice/version.h | 4 +-- libavformat/avformat.h | 21 +++++++++++++ libavformat/version.h | 2 +- 5 files changed, 89 insertions(+), 14 deletions(-) diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c index 43d3406670..d367189532 100644 --- a/libavdevice/avdevice.c +++ b/libavdevice/avdevice.c @@ -28,11 +28,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) { @@ -81,18 +109,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 74e9518a8e..9724e7edf5 100644 --- a/libavdevice/avdevice.h +++ b/libavdevice/avdevice.h @@ -347,7 +347,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). @@ -443,7 +442,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[]; /** @@ -463,7 +461,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); @@ -473,9 +470,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/libavdevice/version.h b/libavdevice/version.h index e2c8757b27..7c132f2174 100644 --- a/libavdevice/version.h +++ b/libavdevice/version.h @@ -30,8 +30,8 @@ #include "version_major.h" -#define LIBAVDEVICE_VERSION_MINOR 8 -#define LIBAVDEVICE_VERSION_MICRO 101 +#define LIBAVDEVICE_VERSION_MINOR 9 +#define LIBAVDEVICE_VERSION_MICRO 100 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \ LIBAVDEVICE_VERSION_MINOR, \ diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 06db024559..027a914e13 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -617,6 +617,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 @@ -797,6 +807,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 d195704a31..88d6f750a2 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -32,7 +32,7 @@ #include "version_major.h" -#define LIBAVFORMAT_VERSION_MINOR 22 +#define LIBAVFORMAT_VERSION_MINOR 23 #define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ From patchwork Wed Mar 30 12:17:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 35063 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp774150pzb; Wed, 30 Mar 2022 05:19:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLXjie9XaBLCAenw/Tbt0WVBAuOnHzC/jHM+TyrKLUIiFFNM1MZrOOspUFIDIww/bYUb60 X-Received: by 2002:a17:907:6296:b0:6da:64ee:1031 with SMTP id nd22-20020a170907629600b006da64ee1031mr40385190ejc.601.1648642788730; Wed, 30 Mar 2022 05:19:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648642788; cv=none; d=google.com; s=arc-20160816; b=eYEciAKlgThExXrmWphbI74/JqFdGUIxW0sTIKZuUYoSngsbncl0KgPv2tSoUe7Eq9 +SbRwAnNMe/14Q6MpjQtMnR4JDtGjFLv8Gw6sRd/j+ay7ry/b+MpHbsUWyK4qwBxumor kNP0yEDTTdBlGfdlvExtIGexU9UYf2dCBSGIicHia3yPD5f62ZpikAlBDFM5iCmhc3Vz OaiiCvicpJKQZUqaTROITjll2VIdyvfya2j8m4e9kumpQ2rga65ooJUX24ai7EEJU5hi lr6Qt+/SAYEZteEXCiDnfQhS/MkU1uplqNDsYRj+HZBhoncDc0GuPxOJH5eYyizh+HEO J7Xg== 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=ubDKRAXi6lW2gdJi65/9f21N+fjIg8+M+wjbo2KYz8w=; b=yGiK4seinNgCv+m5PHxGC0UJH/hr0jDyfDnw7mFGD2Ep6ioHye+dDXUJYcLJU0Tk/9 5gjJGEgeBMIup2zN0REDB0CrPUvl1+HD+2GKFiFzGYf3GRBqc7MS1FVYHAdAGHnP2cVU asOPPu9B9G+4iZFAP38iDWcDTQ07ma2Kb0sfhtSnf/hGOKxxuh3SUu68ZyvedHwwA6Jn ZmdIR2wAagtYmQtZN0DTsOptj2AhLsf1jWtIpEbQSyqlqHMi/HIr0s4D26x3Mi7BkMd5 soknPXJZzGNDKf5zz+HMG6ZqscWj6Tm2rcysyROluvLYXi7tN7EnsbG1rNKD1bCwpYt3 JOcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=B78T4hfw; 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 jp11-20020a170906f74b00b006df76385dcbsi19956825ejb.619.2022.03.30.05.19.48; Wed, 30 Mar 2022 05:19:48 -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=20210112 header.b=B78T4hfw; 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 9173368A896; Wed, 30 Mar 2022 15:19:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C55CB68A896 for ; Wed, 30 Mar 2022 15:19:13 +0300 (EEST) Received: by mail-lj1-f181.google.com with SMTP id c15so27387532ljr.9 for ; Wed, 30 Mar 2022 05:19:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jrXkYFjbGW+XlcDoUpFKKVfIX7B/8yEeCovCp33upOI=; b=B78T4hfwEai2gbjaYLDqeJ1h7CKad7QQ2Vr378VuLSQq1LR5n5myCTuPit5jTsQVuj JYGXDd2aT3yKcMLm5SGHLXK9AmNCReWaGRl4HSzoZ+tdug+uVsuw9SdadXqRTA0nch7r ek0jMkgpTYSVYoHSAWMrNF12bYtJDjIlhyEGi/ZkNvrrKhoN4yiWbkudI5XnscrTQBhl x24J1uWm+IOgo0oHFZMRfG/ZziE9woffMxgtypulkEdVILAem69+AlAq8AIucBqANXRD 52ao+h2IYGRi9GO42cMXwbGTrUroxjENwGKb1zZAfEpnERTVGZwmG4sd3+n3vMaGnEJA jSBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jrXkYFjbGW+XlcDoUpFKKVfIX7B/8yEeCovCp33upOI=; b=6n5Zy+kdTX46qsS5nZQ627xFIXbtq5i2De2aA9wts8lRgj4GpbqoiZTff8tngmbrnP RS1Oqmttv4GKSuhXrPA8i/yEnf/iQctitHJDdQSCjHLSOXxM/cG7Of/vi9kGpFgvufhK a4xf71PkBrAwIFRgXHy0eGb64iB8ZDfs7BOaQm3MXaMliKe5PcCWFxYIcZ3Rc9W9gA1h apg2IQ5boAWERFYhIOoO3GcgkWYtB6VWd8Qavjem2DjlbRGyKtZnAAxtPYDh2eOCy7dk r81RSDgKS+ahNivNI7LW/QyPOawZAT5uPynNVhxrPmSxQe5+gcW7X0H7GU/YPvJf3W0N F3fQ== X-Gm-Message-State: AOAM5308JAFdDXoXs9ZF+rUYLdlIVogiAUK4Guigwc9VSJU/PB9JSyp3 tv6gfCt/OHnuQ1Sp7ZCZOfrKgMSlqy4= X-Received: by 2002:a2e:9990:0:b0:249:88f6:f637 with SMTP id w16-20020a2e9990000000b0024988f6f637mr6380956lji.14.1648642752595; Wed, 30 Mar 2022 05:19:12 -0700 (PDT) Received: from localhost.localdomain (deedock.humlab.lu.se. [130.235.135.183]) by smtp.gmail.com with ESMTPSA id u11-20020a19600b000000b0044a37ab974fsm2307922lfb.51.2022.03.30.05.19.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 05:19:12 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Wed, 30 Mar 2022 14:17:53 +0200 Message-Id: <20220330121806.822-9-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20220330121806.822-1-dcnieho@gmail.com> References: <20220330121806.822-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 08/21] avdevice/avdevice: clean up avdevice_capabilities_create 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: QB+tWswY1TDd Draw implementation in line with that of avdevice_list_devices Signed-off-by: Diederick Niehorster --- libavdevice/avdevice.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c index d367189532..2e8261e0d2 100644 --- a/libavdevice/avdevice.c +++ b/libavdevice/avdevice.c @@ -113,11 +113,14 @@ int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatConte AVDictionary **device_options) { int ret; - av_assert0(s && caps); + av_assert0(s); + av_assert0(caps); av_assert0(s->iformat || s->oformat); if ((s->oformat && !s->oformat->create_device_capabilities) || - (s->iformat && !s->iformat->create_device_capabilities)) + (s->iformat && !s->iformat->create_device_capabilities)) { + *caps = NULL; return AVERROR(ENOSYS); + } *caps = av_mallocz(sizeof(**caps)); if (!(*caps)) return AVERROR(ENOMEM); From patchwork Wed Mar 30 12:17:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 35064 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp774210pzb; Wed, 30 Mar 2022 05:19:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkTB66a07sYs1/3iUQb0bN+gCH1owFdALMlcVowE1wEbQawNVzxmDxTB5iBETJVC5IDU8l X-Received: by 2002:a17:907:3d8e:b0:6e4:93c8:161c with SMTP id he14-20020a1709073d8e00b006e493c8161cmr1477700ejc.330.1648642797868; Wed, 30 Mar 2022 05:19:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648642797; cv=none; d=google.com; s=arc-20160816; b=Uwx43XFltaP313hjNAFmfWp/TPl8gnRlAe/33aq1/iDHQaCXtVH6xGtOTFxLM8A1t3 mGvRNhxAAVU4w9h6jKR1hD/OZ4kWk2PSFQMQ/duAvppOT/XOEU5edeOyAoQJFzCwn85o ZwRjvW7Umw3eIZKz8vIERG8ZH4Wwo0QPNLLlki4s9JeAOAws1VC6nB1o7k04Kf95t71p MgclEsNvPpFUm7tJ4LFOHgPIsE4zbUKKBQVTqzjMkKoTzaASlBmj7/qfTvjU2JbfQoBZ iuoyUzZSWAb6dymWES1R+9y8GBjeKwaIuu1g1Iez5i8m+y7bmGxY8jeE5YEnJt2dFzzf MJ/g== 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=Wf9I93vSS87YGOwE8vL+DkgiYzrNjcq9WncUNDYq9B8=; b=AvKOCNMFcG/z1KtaFsPplr7tYtdEl7WLu8IJOjQA4ITvgPBkLxtVncFMBrfzXlnm49 wiXss9jzyf2wUrO8qWKbxuC6zB1F5WsrJr5UKTsvDzqtZFKhjd8YIGkXHT3lsq1DUDRP F/yfRJHuRFXh+SF9YG6wDlF0k/nbLnpItRaE5lx6LoLSYdptK/ebbXZTGJmhhyKE/sZM VAmHQkbx8G/0ewY1lYgab3cb8kr3ya4KbFgA5KOeQIAvdtQYL9PdW45eDr6QbhDx4zrC 3RYP7SH0Ec2zDvZlyaVRCnBQtteb5mFew+2+TnB18NJLKoBm71ep/lw0YaOLkVCWeXuF AynQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=H4uE6r+X; 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 ky9-20020a170907778900b006df76385f3esi20973514ejc.990.2022.03.30.05.19.57; Wed, 30 Mar 2022 05:19:57 -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=20210112 header.b=H4uE6r+X; 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 A879E68B24E; Wed, 30 Mar 2022 15:19:21 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3F90668B24E for ; Wed, 30 Mar 2022 15:19:19 +0300 (EEST) Received: by mail-lj1-f174.google.com with SMTP id q14so27379062ljc.12 for ; Wed, 30 Mar 2022 05:19:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j25lCNGQZtwKoo4/1go0XJp0AHqDV+7EpB4yyI170f8=; b=H4uE6r+XJLLSiiNwVeGyTGXYxWoUn2XSjZYPgd/tJ7e+JYJCbc7iTqv0zove6015Ho XezkoFE9sjSb6YFeo7rnnbhRaLSKsSdujCuz53Q0azfbHdvyNY6aHCs/UHBNIBWp8Xev Mzs3aQHitrd9EkIB9rRWiJG8jTf8Ao5Cup66Khg4Mm7DXEt51sT6Leysvfmyw3LcIypk UvZFt42WwiB9uPcKAzBpYxBkMZ9bCgW+aj8XGrQnd3Nhnx8p62TdJRRB4Ja4cL/EBwtN XwEPa7Rqaou8axO0WT+QeR15tkcFbPwXzQD38i70MQsRtb8dwZP9TEPhQsRzv/NY+1Q8 +XFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=j25lCNGQZtwKoo4/1go0XJp0AHqDV+7EpB4yyI170f8=; b=Hhy66vl0BTWsGiOs8F1NYG56Gm7ajXz+t+eHiTvfSwIh9zUkwK+Jm1MPX49j6xIaai NupFKapgY628GNeNtwTyzKmBE1j90Gyru8KOcSdld3AuRJVaJpHeAiEt57B6cPA5hHPo RxpaZ13OzBDPk4zEaFg+SCVq2G+3A9rf3Nab5+iUU9xoY4cGaj1Qoli1EPx/DZlzSQIC cL2M5Tv7HFgiR6/9ukIxBzwiMNR/P9VjylJMlRQ3l4NZxmOIXXI2aLu9M7ZByf01h7ay /0YsXTvTFGCpEkbp39Nz63PSgiuc7nFQCvxvmhKmdaRlzvEnyIeLyybDCUkcCCuSObbu pa0A== X-Gm-Message-State: AOAM533himqAY+2zdyYbPWfAZaiEW4pAB+fIpDnxWR5REtUoToHggAyp 4rPpcP7/WQZpc5iLIY0/hcAY9D06/wk= X-Received: by 2002:a2e:551:0:b0:249:7ce6:4577 with SMTP id 78-20020a2e0551000000b002497ce64577mr6483477ljf.184.1648642758977; Wed, 30 Mar 2022 05:19:18 -0700 (PDT) Received: from localhost.localdomain (deedock.humlab.lu.se. [130.235.135.183]) by smtp.gmail.com with ESMTPSA id i15-20020ac25d2f000000b004484a530b07sm2319551lfb.143.2022.03.30.05.19.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 05:19:18 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Wed, 30 Mar 2022 14:17:54 +0200 Message-Id: <20220330121806.822-10-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20220330121806.822-1-dcnieho@gmail.com> References: <20220330121806.822-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 09/21] avdevice: capabilities API details no longer public 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: W63udL6vwJXM Bumping avdevice major version (API removed, even if it cannot have been used by anyone) Signed-off-by: Diederick Niehorster --- libavdevice/avdevice.c | 2 +- libavdevice/avdevice.h | 28 +--------------------------- libavdevice/internal.h | 33 +++++++++++++++++++++++++++++++++ libavdevice/version.h | 2 +- libavdevice/version_major.h | 2 +- 5 files changed, 37 insertions(+), 30 deletions(-) diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c index 2e8261e0d2..1cc9cd3923 100644 --- a/libavdevice/avdevice.c +++ b/libavdevice/avdevice.c @@ -34,7 +34,7 @@ const char av_device_ffversion[] = "FFmpeg version " FFMPEG_VERSION; #define V AV_OPT_FLAG_VIDEO_PARAM #define OFFSET(x) offsetof(AVDeviceCapabilitiesQuery, x) -const AVOption av_device_capabilities[] = { +const AVOption ff_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, diff --git a/libavdevice/avdevice.h b/libavdevice/avdevice.h index 9724e7edf5..6d45c74616 100644 --- a/libavdevice/avdevice.h +++ b/libavdevice/avdevice.h @@ -416,33 +416,7 @@ int avdevice_dev_to_app_control_message(struct AVFormatContext *s, * avformat_free_context(oc); * @endcode */ - -/** - * Structure describes device capabilities. - * - * It is used by devices in conjunction with av_device_capabilities AVOption table - * to implement capabilities probing API based on AVOption API. Should not be used directly. - */ -typedef struct AVDeviceCapabilitiesQuery { - const AVClass *av_class; - AVFormatContext *device_context; - enum AVCodecID codec; - enum AVSampleFormat sample_format; - enum AVPixelFormat pixel_format; - int sample_rate; - int channels; - int64_t channel_layout; - int window_width; - int window_height; - int frame_width; - int frame_height; - AVRational fps; -} AVDeviceCapabilitiesQuery; - -/** - * AVOption table used by devices to implement device capabilities API. Should not be used by a user. - */ -extern const AVOption av_device_capabilities[]; +typedef struct AVDeviceCapabilitiesQuery AVDeviceCapabilitiesQuery; /** * Initialize capabilities probing API based on AVOption API. diff --git a/libavdevice/internal.h b/libavdevice/internal.h index 67c90e1f87..bef3a4bd2d 100644 --- a/libavdevice/internal.h +++ b/libavdevice/internal.h @@ -19,10 +19,43 @@ #ifndef AVDEVICE_INTERNAL_H #define AVDEVICE_INTERNAL_H +#include "libavutil/log.h" +#include "libavutil/opt.h" +#include "libavutil/pixfmt.h" +#include "libavutil/rational.h" +#include "libavutil/samplefmt.h" +#include "libavcodec/codec_id.h" #include "libavformat/avformat.h" av_warn_unused_result int ff_alloc_input_device_context(struct AVFormatContext **avctx, const AVInputFormat *iformat, const char *format); +/** + * Structure describes device capabilities. + * + * It is used by devices in conjunction with ff_device_capabilities AVOption table + * to implement capabilities probing API based on AVOption API. + */ +struct AVDeviceCapabilitiesQuery { + const AVClass *av_class; + AVFormatContext *device_context; + enum AVCodecID codec; + enum AVSampleFormat sample_format; + enum AVPixelFormat pixel_format; + int sample_rate; + int channels; + int64_t channel_layout; + int window_width; + int window_height; + int frame_width; + int frame_height; + AVRational fps; +}; + +/** + * AVOption table used by devices to implement device capabilities API. + */ +extern const AVOption ff_device_capabilities[]; + #endif diff --git a/libavdevice/version.h b/libavdevice/version.h index 7c132f2174..09156778db 100644 --- a/libavdevice/version.h +++ b/libavdevice/version.h @@ -30,7 +30,7 @@ #include "version_major.h" -#define LIBAVDEVICE_VERSION_MINOR 9 +#define LIBAVDEVICE_VERSION_MINOR 1 #define LIBAVDEVICE_VERSION_MICRO 100 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \ diff --git a/libavdevice/version_major.h b/libavdevice/version_major.h index d255ff6992..b32de7325d 100644 --- a/libavdevice/version_major.h +++ b/libavdevice/version_major.h @@ -25,7 +25,7 @@ * Libavdevice version macros */ -#define LIBAVDEVICE_VERSION_MAJOR 59 +#define LIBAVDEVICE_VERSION_MAJOR 60 /** * FF_API_* defines may be placed below to indicate public API that will be From patchwork Wed Mar 30 12:17:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 35065 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp774272pzb; Wed, 30 Mar 2022 05:20:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOMTUuI2i/0NhQbZj1i7tuIIB/DT0efQCIg6yUce0iPgKR+gFy1xyP8CVahiTddfYP38wW X-Received: by 2002:a17:906:1411:b0:6da:f354:fb83 with SMTP id p17-20020a170906141100b006daf354fb83mr39818060ejc.539.1648642808044; Wed, 30 Mar 2022 05:20:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648642807; cv=none; d=google.com; s=arc-20160816; b=HRLY3uzmi5x0R4UOTNy9rhsEG+p4cpZPHeWUr2qMlWD2WTEE3Kmvmq6Y3CfpLbkP// oOmMAgh7X7Swj9oTKIQv3gFWLeeckdc6gjjw9FZ7TO0RezBGdVDpm0WKVVEnYf18GwzQ d83OkndGGistWPmxw2wcLWmZ4RwUoHDhCdnxJgW9zkiOsrIRvNgFnrktypsahx+g/61Q K3/glhaxwMSz+mxMS+A9v7Di/3H0olTwTTIDUWYKcefNzMSdKouk4VPQJ3hNT/zQXRBn E3ehO7BGjHjBnh5UVTwJBHDddsHbApKOT/dYFP/f0Rgq5EpS8IBvk0x2IEonsQIwinlb X9Mg== 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=2A9pYbmgm0RCt3SMzrDK2Ugo0q/WIudAQ0Sr0wkSgKo=; b=Y5sLUnXHg6So+0q3im4bmNauRcnTe7GbH4lzqh4GQ7OI7mfw3PMoanfpvZ9SVFUsQL mo7v5hTINLVEFsysdcqZcPFfn0YAk2kKHF4VrJUZhdqB6tGlpnNuP6vllob0pdQywUid 01WBMHTb1YQ8pbEGd5zDmkZUuoSU8Quesg/SZqX1cBu5Vuq/atAvYxv+yWcNlhtgDmxo oZMXuPW+caS8jNyB+3d3yKXCCSkigsAMU58sIUuWEPlm4BMg/JHGBNIZJImfxexYZOSB Xxtrz+b+wp3Fmmc1ow7QGXn84Iunq0QgeURdCwgCDuXR2hYNnvlCdxo3FfXHB6EMsBec M65Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=Km7Cav6c; 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 k27-20020a1709061c1b00b006dff4dd30f9si18703501ejg.862.2022.03.30.05.20.07; Wed, 30 Mar 2022 05:20:07 -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=20210112 header.b=Km7Cav6c; 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 537F568B267; Wed, 30 Mar 2022 15:19:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7568C68B159 for ; Wed, 30 Mar 2022 15:19:26 +0300 (EEST) Received: by mail-lj1-f178.google.com with SMTP id g24so27398982lja.7 for ; Wed, 30 Mar 2022 05:19:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=e67rJjxL3/70KyO3YUb1luBz3oVKcQTD1Fo5/Lm7BoY=; b=Km7Cav6ce7UUTTKOk+aE2AjlNZbtHPp2SeZfrUOFAqNGiAD/895AXRhffOFjF5RhLU tRdStnsp4jm8wpfVrMcWguHnldg7+fhrJNJdF3QJ8AWbtFBPctWWAuqKGlImTW/9f/fk EozN7j/C/pP5/wrt5L4AiVi4DFNhp3LQ0KDlULyIxhkAaw0AA3YGqN+x1aoRIDqigAwT pXxVVEh+gnRrJg8rjTUmZXdxCUOlLiADCNZUDvXOomLqVunU848oLEQP0kLz1/+RiiO4 y3/AXrxEJ+QxziEqNKdZEMtcwGsCCzYe16IXd+Ktip5P5/coEhau7sc/IQhZil7WGhdc rkdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=e67rJjxL3/70KyO3YUb1luBz3oVKcQTD1Fo5/Lm7BoY=; b=d/K7Ozod9FymPoI2nzyvy0AuYqoJli+w060Ozma0Zd6EQNFGs2/SlNUyzRmKXh9FGV 4Nqy0uqFPEzdluozFU4odB2nSt6D6dq0cT+jzl2JLVKNBzDTujiVWqDSNWa0Gp3QHZyM UTvEw8VAkwdlE0RKDttSucexsFXe8+hKmO809YfDGvngtMDiFcvEujFsHwNma8OVsKCP hNxb8eBbRYW3+8YDD+Wpsc7TPMiwRzllsg826a+V1rTsnX+IsJ26RfGVBE4fNgPTLgv/ EZogZQZrCD78iWazDvx1JfPEZSN7b9Qtlr3/LTax25oGRWX2ANZCDsRTpAED/3aDoQZJ wZJQ== X-Gm-Message-State: AOAM531QOcn8bsUwTowcsssmiVnStlYl2vZ3dmNuqSA2vdKV8woG/Gf1 uXsv+BdNyND575xulOjS89wGNXPLrFY= X-Received: by 2002:a2e:9cc5:0:b0:24a:c452:33a3 with SMTP id g5-20020a2e9cc5000000b0024ac45233a3mr6378550ljj.348.1648642765474; Wed, 30 Mar 2022 05:19:25 -0700 (PDT) Received: from localhost.localdomain (deedock.humlab.lu.se. [130.235.135.183]) by smtp.gmail.com with ESMTPSA id b14-20020a0565120b8e00b0044a29806f79sm2313181lfv.259.2022.03.30.05.19.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 05:19:25 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Wed, 30 Mar 2022 14:17:55 +0200 Message-Id: <20220330121806.822-11-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20220330121806.822-1-dcnieho@gmail.com> References: <20220330121806.822-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 10/21] avutil/opt: document AVOptionRange min_value > max_value 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: +8TuNo807D9H AVOptionRange needs a way to encode that an option is not set. Here i provide a documentation solution. When a range is invalid (value_min > value_max), it should be considered unset/value not available. When querying a range of formats of an avdevice, sometimes for a given format the queried option is not available. This is not an error as the user is asking for a valid capability, it just doesn't always apply to all the matching formats of the device. This cannot be communicated through a single special value (like 0 or -1) as that has the same problem asany special value solution. Documenting that an invalid range means value not available allows communicating this situation without adding a field to the AVOptionRange struct. This further documents that an AVOptionRange denotes a single value when value_min == value_max, and a range only when value_max > value_min. This makes the is_range field superfluous. Signed-off-by: Diederick Niehorster --- libavutil/opt.c | 2 +- libavutil/opt.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/libavutil/opt.c b/libavutil/opt.c index 8ffb10449b..ebffbb2f36 100644 --- a/libavutil/opt.c +++ b/libavutil/opt.c @@ -1979,9 +1979,9 @@ int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const ch ranges->range[0] = range; ranges->nb_ranges = 1; ranges->nb_components = 1; - range->is_range = 1; range->value_min = field->min; range->value_max = field->max; + range->is_range = field->max > field->min; switch (field->type) { case AV_OPT_TYPE_BOOL: diff --git a/libavutil/opt.h b/libavutil/opt.h index 461b5d3b6b..4e7d7433e9 100644 --- a/libavutil/opt.h +++ b/libavutil/opt.h @@ -316,6 +316,11 @@ typedef struct AVOptionRange { * Value range. * For string ranges this represents the min/max length. * For dimensions this represents the min/max pixel count or width/height in multi-component case. + * If value_min < value_max, the struct encodes a range. + * If value_min == value_max, the struct encodes a single value. + * If value_min > value_max, the range is empty (a value is not available). + * Good sentinel values to use when a range is empty + * are value_min=0, value_max=-1, but this is not required. */ double value_min, value_max; /** From patchwork Wed Mar 30 12:17:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 35066 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp774329pzb; Wed, 30 Mar 2022 05:20:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHZCVMKgvIagAqKU0jrkaykrDjR084omx3nz+xBYMusOiN0lxvGhnJj56rhQ1H+431MWXb X-Received: by 2002:a17:906:ae0b:b0:6df:c7d6:9235 with SMTP id le11-20020a170906ae0b00b006dfc7d69235mr40105684ejb.664.1648642818441; Wed, 30 Mar 2022 05:20:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648642818; cv=none; d=google.com; s=arc-20160816; b=MHXcZGWvavHqRegEeUlEUSLj+SAtRcMZTnR7WeB8wuD6aMLZcvaa/Svr14w6+BhqEW FiYjrB+5tZGtDXtZhKijVQrxeTWatcUWW5ntSN+aDk4H2N5U/0QoM3+g1/ev+RoEsmxU cd01vN4wSfGEGFIHHi33WXQdJT2fWjOep2pGq5Zb3z74tor4ZR1hFjjwPDDtzUJ7X2AU oJnmTzzfbJLgVPm7ZFC3IqmXfczSEYTH73ne+E+vp77E3FcmRGa4I7dcSdKvPJFn3XzV OP0Y3I8Bk1VrZosqInmkNyTFuikEkveTWTFJVZV9kg7CyXXiJLQNC2vkS+E2AUahFIKn kERg== 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=DkNgvc6y/508EGEkHrThLvAiPQqUuHElzbAfTdB5RN4=; b=tS0QwUWiWzSL0VjrucF2GGWBY1IOJKLyAO/MYc8mQ/N+6yjDUKPeHx11X3+v6NopJb iVik19hlGNwtY2NIBO0ti47lPty5nFuhCvFVjhj1Ky71wpaF4X/RTwWihRZ9BxFWIMv3 G430AQJ82roHhNd9vb9GVyAA4t1qPJQOhEmsn2jKlWOft7sEeULROuzym+uhe9FodSpa 30tyhWWb9KycZgRJ4gufjho+KpkMlF/LjuoXEfVDa0xqizKpPiLVjhGdyfXk92mwyp4k Lsm/RSu0TOpvwipUbh0JlhfmamrGwaVZei1BQXEpVZVDjaYp+oKWQLB7aHnCbomh7GKX Ldeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=HuqvorxE; 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 hx22-20020a170906847600b006df76385bbbsi20058361ejc.91.2022.03.30.05.20.18; Wed, 30 Mar 2022 05:20:18 -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=20210112 header.b=HuqvorxE; 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 0ECBC68B266; Wed, 30 Mar 2022 15:19:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3973968B1DC for ; Wed, 30 Mar 2022 15:19:32 +0300 (EEST) Received: by mail-lj1-f182.google.com with SMTP id a30so19949080ljq.13 for ; Wed, 30 Mar 2022 05:19:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7FA+octZ7Nt5nuLnopYPpV/YR8czF8Mpn25MCIj23EI=; b=HuqvorxEaqiWh+q3/GR9OX2CjJe4g8umqeFc3+lYUY19CoHROo+ST0CyFra6Qlnnkl tPlG7lDYHeVWuHNZQkCPfTMnbjwnJ9qeuLFh+D2nbkQGKHA1+I1Gm6fyQsM5x6GRaFQX 7EvcR6O7kbtfuBQw8CiCsV46eZblHhSOMnYB0gQtSqzOozbFb8ac7KjHklv2xEpIuUAH PTfzwGJ2RHh65mD3vCtqkNWHRpLUgJyHVKteQ39mGT6gYiLPFSlGvoQYJUTqdABU7uAT YYOX0a6WT2HojH1ehQkqXZec7uVslKPETV7cwywriCyBI4EGT0hk+lD9B2nivGsDPiUf C8Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7FA+octZ7Nt5nuLnopYPpV/YR8czF8Mpn25MCIj23EI=; b=wXB64zJRbak2f2y3zdcoY+GuQgCULR8SGRc28DKqyPwbJQzfFRgUZ7YAMD794Pkfsa IV26rQCnxXKIa2namkPG5ZRPlGu1OMW/6XJ4V6UmI7UdZBqxSwY8bMlWAffOjmdFY4/X lUjUr6iF3VJVilQeekhYDHgWvlmLxB4zSOjLiTEwMUiVtD8cMEplnvdIvcyaNXR+glKh nNLZD7DfynBW09SrW8A5/9Cw7TGInHJ1+myleNvwzzvKG/Bhqu5DKdWoxVrhshirFRZB 4MconE/Jr+ebjq8948Y9+wa4tKzIjwdNFoASF/RtjTfszK/vwUwSLPGGIhK7N/HJD+Nx lT8g== X-Gm-Message-State: AOAM530Twq8t8LdG+kXeyo7lJcsuv17U1DSwyrPaBz/x2ZYh0HdoKcmd m817dQEW6rQw7DK64lt8n3+SSEGR1Vk= X-Received: by 2002:a2e:90d6:0:b0:246:e44:bcf6 with SMTP id o22-20020a2e90d6000000b002460e44bcf6mr6349889ljg.501.1648642771999; Wed, 30 Mar 2022 05:19:31 -0700 (PDT) Received: from localhost.localdomain (deedock.humlab.lu.se. [130.235.135.183]) by smtp.gmail.com with ESMTPSA id bg19-20020a05651c0b9300b002497beec608sm2391145ljb.87.2022.03.30.05.19.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 05:19:31 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Wed, 30 Mar 2022 14:17:56 +0200 Message-Id: <20220330121806.822-12-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20220330121806.822-1-dcnieho@gmail.com> References: <20220330121806.822-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 11/21] avdevice: Add internal helpers for querying device capabilities 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: rgRh1/NsHYK1 Signed-off-by: Diederick Niehorster --- libavdevice/internal.h | 31 +++++++++++++++++++++++++++ libavdevice/utils.c | 48 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/libavdevice/internal.h b/libavdevice/internal.h index bef3a4bd2d..eee493a4c7 100644 --- a/libavdevice/internal.h +++ b/libavdevice/internal.h @@ -58,4 +58,35 @@ struct AVDeviceCapabilitiesQuery { */ extern const AVOption ff_device_capabilities[]; +/** + * Enumeration indicating which device capability is being queried. + */ +enum AVDeviceCapabilitiesQueryType { + AV_DEV_CAP_QUERY_NONE = 0, + // both audio and video + AV_DEV_CAP_QUERY_CODEC, + // audio + AV_DEV_CAP_QUERY_SAMPLE_FORMAT, + AV_DEV_CAP_QUERY_SAMPLE_RATE, + AV_DEV_CAP_QUERY_CHANNELS, + AV_DEV_CAP_QUERY_CHANNEL_LAYOUT, + // video + AV_DEV_CAP_QUERY_PIXEL_FORMAT, + AV_DEV_CAP_QUERY_WINDOW_SIZE, + AV_DEV_CAP_QUERY_FRAME_SIZE, + AV_DEV_CAP_QUERY_FPS +}; + +/** + * Find AVDeviceCapabilitiesQueryType enumeration by means of options name. + * Returns AV_DEV_CAP_QUERY_NONE if not found. + */ +enum AVDeviceCapabilitiesQueryType ff_device_get_query_type(const char* option_name); + +/** + * Get component name from AVDeviceCapabilitiesQueryType enumeration and component index. + * (Some options have multiple components, e.g. AV_DEV_CAP_QUERY_FRAME_SIZE). + */ +const char* ff_device_get_query_component_name(enum AVDeviceCapabilitiesQueryType query_type, int component); + #endif diff --git a/libavdevice/utils.c b/libavdevice/utils.c index d9a52c53ab..de9023f215 100644 --- a/libavdevice/utils.c +++ b/libavdevice/utils.c @@ -19,6 +19,7 @@ #include "internal.h" #include "libavutil/opt.h" #include "libavformat/avformat.h" +#include "libavutil/avassert.h" int ff_alloc_input_device_context(AVFormatContext **avctx, const AVInputFormat *iformat, const char *format) { @@ -57,3 +58,50 @@ int ff_alloc_input_device_context(AVFormatContext **avctx, const AVInputFormat * avformat_free_context(s); return ret; } + +typedef struct AVDeviceCapabilitiesQueryTypeEntry { + const char* name; + enum AVDeviceCapabilitiesQueryType query_type; +} AVDeviceCapabilitiesQueryTypeEntry; + +static const AVDeviceCapabilitiesQueryTypeEntry query_table[] = { + // both audio and video + { "codec", AV_DEV_CAP_QUERY_CODEC }, + // audio + { "sample_format", AV_DEV_CAP_QUERY_SAMPLE_FORMAT }, + { "sample_rate", AV_DEV_CAP_QUERY_SAMPLE_RATE }, + { "channels", AV_DEV_CAP_QUERY_CHANNELS }, + { "channel_layout", AV_DEV_CAP_QUERY_CHANNEL_LAYOUT }, + // video + { "pixel_format", AV_DEV_CAP_QUERY_PIXEL_FORMAT }, + { "frame_size", AV_DEV_CAP_QUERY_FRAME_SIZE }, + { "window_size", AV_DEV_CAP_QUERY_WINDOW_SIZE }, + { "fps", AV_DEV_CAP_QUERY_FPS }, +}; + +enum AVDeviceCapabilitiesQueryType ff_device_get_query_type(const char* option_name) +{ + for (int i = 0; i < FF_ARRAY_ELEMS(query_table); ++i) { + if (!strcmp(query_table[i].name, option_name)) + return query_table[i].query_type; + } + // not found + return AV_DEV_CAP_QUERY_NONE; +} + +const char* ff_device_get_query_component_name(enum AVDeviceCapabilitiesQueryType query_type, int component) +{ + if (query_type == AV_DEV_CAP_QUERY_WINDOW_SIZE || query_type == AV_DEV_CAP_QUERY_FRAME_SIZE) { + // special case: different name for each component + return component == 0 ? "pixel_count" : (component == 1 ? "width" : (component == 2 ? "height" : "")); + } + else { + av_assert0(component == 0); + for (int i = 0; i < FF_ARRAY_ELEMS(query_table); ++i) { + if (query_table[i].query_type == query_type) + return query_table[i].name; + } + } + // not found + return NULL; +} \ No newline at end of file From patchwork Wed Mar 30 12:17:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 35067 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp774400pzb; Wed, 30 Mar 2022 05:20:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0kBjPv8YPwotIMOAkY3JIMJYaqoWP3wfH9kjpabO2tpvlrrfH85kbv81P1p1PPM2CtHZs X-Received: by 2002:a17:906:c151:b0:6e0:dcff:ad6e with SMTP id dp17-20020a170906c15100b006e0dcffad6emr24517792ejc.547.1648642829297; Wed, 30 Mar 2022 05:20:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648642829; cv=none; d=google.com; s=arc-20160816; b=TR/qpuqvXblePu8n4YGukKk5KI0alw0XkHuFp3KEESq5om2WtHRymaWD1u8VT/Q0F1 3F7hGCy1TZ7p4AjODR/sNmSsLPGa8XHcSZ5Y85BbGGvt/KF7SkYMCskb8+mnVI8/Vrcw g91W2rWWDTnHMlHoIW/2GSkbQmB9g4ZoVyK/u4O5mu+i4lK9KF0RSKo/eLSfwfrLoM3U khqzw6V2l6WpG4WTdps6nvIPFs4u56Zzq28KNIymjoT2YxS75VMI7cDxBFx14ySlpU/d lo2/T3+XBS3zlEcS/6ScnERmpKKPJr+WUbalHBHUe1Y5apFsg/VBHUaJCnJ8sVoRE2hg zsmA== 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=vaOVbGlUkr0Vqod1piocTAfIcAr9yPuru0ZeNf+TUK0=; b=m7Wo+G9drsrJEIidkLihl4tcvjN62zGkvRJ0qJRskGXDqk/EVTLWTRdizfgSXiZ7SD kreePKjeM6zNghPNvQ2B+Md2fEUBu3qaJgjI48xqaOdeBTGSO6A8G5IdZ9nekMpRMvpK tzHhEPIiTwQWTpcEQ8ley30lxdKSK5VQBk8RJ58Tj1V306HdU2kfOdruTFXKioW4VhdN 4Le7Xm92TDSqxwsH563TTPBDcBzM0IdPUxyBdwf+wxj0cRXsa/1+yA4QciCjGUOK8L2b b9rg0JTxqTHhRwcvwvjEFMtWnOnk+v2EBMR4T4M1GnYGSMLkfzzlLDAguMJdI7NfVetR NlNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="YxSV/Qrv"; 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 wj8-20020a170907050800b006dfd2b1e251si19107515ejb.578.2022.03.30.05.20.28; Wed, 30 Mar 2022 05:20:29 -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=20210112 header.b="YxSV/Qrv"; 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 0BE9868B276; Wed, 30 Mar 2022 15:19:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 915BE68B1E2 for ; Wed, 30 Mar 2022 15:19:40 +0300 (EEST) Received: by mail-lf1-f49.google.com with SMTP id z12so21684249lfu.10 for ; Wed, 30 Mar 2022 05:19:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jTvhHiTlFb1Byx9ON+ugLk11hvpWzvJE2DX/dpeDuqY=; b=YxSV/QrvlT3t2Z+0wg+hcvBeoYJqve0k6SjWHbMfrks8QWIeoGNdTGOLQ5vrMIUZKC /O3daDy3vfFF8VPxk7zJMcCYppeAx3jonzMNClXbFk0we1JyncaQjHJf+gon2PEj2tv9 e3qeSw7KSZOOg3icmQdlcyKqu3hNzlMia8mr0HINC9mWhocoAMjq7EnVXs79/6bxM+Rq wiLtALUMuYWbIah5xdNOpdBWLNCVJaYT9Xpli1Bx4d9rI0yzpyDJ/8NAX0rATuv8MLA6 LKVLHWulA5nr6WtCcrQzaGWYjJuttN62ndkRFqiB/YwHk7IoSkq7TKxBYvvjgRDByTq1 HrJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jTvhHiTlFb1Byx9ON+ugLk11hvpWzvJE2DX/dpeDuqY=; b=CKzGxOVvDIAbz5rBqUFWkqNow/n5XPFHIPc8OOHUgB4b4k3QA2BCSkN0e6YMKDh1tu k0uQYtY2eLlsY3EqhW24JROQXaQhuyU7dCmucZ6Wxu1dpbIstcok/DiGK+1ny/L8EudR KURo6iH/YZ02ywLp0NGV3ZurhGgcvPx8CDNHuKez0YM/5f5aoXvDBCuv3pA5BE9n/a3g LmIg1PKA4ZmR1znD1poYJREd5LnNUgHj5aYk0fn67mcW0Qir0Tbo5oQuyOCF0HRrtRKZ 6OaIeFnuRXWgFLu+6CcEekBax99HGviTR3cBfbShr3uZW4+qZ04TS8NrClphEVVWQiO7 X3uQ== X-Gm-Message-State: AOAM533sWh0FEU/MgTeGD1xXuWpAw4LzRCWWqgIpeiCAlHBQY71dW8Yu /ggjyHOGc+AZ/2dBx4BkjumOZMJM6UQ= X-Received: by 2002:a05:6512:324b:b0:44a:8704:e8dd with SMTP id c11-20020a056512324b00b0044a8704e8ddmr6419632lfr.301.1648642779374; Wed, 30 Mar 2022 05:19:39 -0700 (PDT) Received: from localhost.localdomain (deedock.humlab.lu.se. [130.235.135.183]) by smtp.gmail.com with ESMTPSA id j6-20020a05651231c600b0044a618a23c0sm2202021lfe.267.2022.03.30.05.19.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 05:19:38 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Wed, 30 Mar 2022 14:17:57 +0200 Message-Id: <20220330121806.822-13-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20220330121806.822-1-dcnieho@gmail.com> References: <20220330121806.822-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 12/21] avdevice: change device capabilities option type 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: xf2yRY9bkE9b Changes fps option from AVRational to double. This since any device capability query results are returned in AVOptionRanges, which hold the value as doubles, which can't contain AVRationals. Also updated documentation of other capabilities, some had the wrong option type listed. micro version bump as this capabilities API is unused for now. Signed-off-by: Diederick Niehorster --- libavdevice/avdevice.c | 4 ++-- libavdevice/avdevice.h | 6 +++--- libavdevice/internal.h | 4 +++- libavdevice/version.h | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c index 1cc9cd3923..863f8df477 100644 --- a/libavdevice/avdevice.c +++ b/libavdevice/avdevice.c @@ -51,8 +51,8 @@ const AVOption ff_device_capabilities[] = { {.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 }, + { "fps", "fps", OFFSET(fps), AV_OPT_TYPE_DOUBLE, + {.dbl = NAN}, 0, INT_MAX, E|D|V }, { NULL } }; diff --git a/libavdevice/avdevice.h b/libavdevice/avdevice.h index 6d45c74616..a815d65f12 100644 --- a/libavdevice/avdevice.h +++ b/libavdevice/avdevice.h @@ -360,7 +360,7 @@ int avdevice_dev_to_app_control_message(struct AVFormatContext *s, * type: AV_OPT_TYPE_INT (AVCodecID value) * - Capabilities valid for audio devices: * - sample_format: supported sample formats. - * type: AV_OPT_TYPE_INT (AVSampleFormat value) + * type: AV_OPT_TYPE_SAMPLE_FMT * - sample_rate: supported sample rates. * type: AV_OPT_TYPE_INT * - channels: supported number of channels. @@ -369,13 +369,13 @@ int avdevice_dev_to_app_control_message(struct AVFormatContext *s, * type: AV_OPT_TYPE_INT64 * - Capabilities valid for video devices: * - pixel_format: supported pixel formats. - * type: AV_OPT_TYPE_INT (AVPixelFormat value) + * type: AV_OPT_TYPE_PIXEL_FMT * - window_size: supported window sizes (describes size of the window size presented to the user). * type: AV_OPT_TYPE_IMAGE_SIZE * - frame_size: supported frame sizes (describes size of provided video frames). * type: AV_OPT_TYPE_IMAGE_SIZE * - fps: supported fps values - * type: AV_OPT_TYPE_RATIONAL + * type: AV_OPT_TYPE_DOUBLE * * Value of the capability may be set by user using av_opt_set() function * and AVDeviceCapabilitiesQuery object. Following queries will diff --git a/libavdevice/internal.h b/libavdevice/internal.h index eee493a4c7..5f0bd403dd 100644 --- a/libavdevice/internal.h +++ b/libavdevice/internal.h @@ -50,7 +50,9 @@ struct AVDeviceCapabilitiesQuery { int window_height; int frame_width; int frame_height; - AVRational fps; + // NB: an AVRational cannot be represented in the AVOptionRange + // output of av_opt_query_ranges, so we store fps as double instead + double fps; }; /** diff --git a/libavdevice/version.h b/libavdevice/version.h index 09156778db..181987d287 100644 --- a/libavdevice/version.h +++ b/libavdevice/version.h @@ -31,7 +31,7 @@ #include "version_major.h" #define LIBAVDEVICE_VERSION_MINOR 1 -#define LIBAVDEVICE_VERSION_MICRO 100 +#define LIBAVDEVICE_VERSION_MICRO 101 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \ LIBAVDEVICE_VERSION_MINOR, \ From patchwork Wed Mar 30 12:17:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 35068 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp774458pzb; Wed, 30 Mar 2022 05:20:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZCoE2G45YwzoIyYChMPOSfBBBzRyzIY9WfntrlKYYraBlN8Usilr+KrPROdG2y78e42Mo X-Received: by 2002:a17:907:3f29:b0:6df:7eac:7fa4 with SMTP id hq41-20020a1709073f2900b006df7eac7fa4mr39958877ejc.391.1648642838451; Wed, 30 Mar 2022 05:20:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648642838; cv=none; d=google.com; s=arc-20160816; b=vpCj3Q2NYIdwn4sbyFzZt2ZlZoM0g9wF+gIqchFtV1y/HOCJ7bvjcXYU/GUA/fpjd6 o7ZklmCG8qro/vTUEQz7G+ZeX5jHnpjlUW9KgjqjVeNiF0PPC8RpUQScks3XBxfrc03Y mA3ALui5iuF44jqcooDWBVcA0M8BfL0Vgc52aFMx2VFQ6cS4OcHiEdmzGhHMBw6MLroh ncDGAciPiBhM7/cv4NLCwDc4g/KXM/eW1rrPaKRgHZEe/vcwAxH1iz22tK+wGEt+3DbQ srIzyuI4dyLxfHDkIm8/83mrFB9YBrXWAR4xhkjBHyu69CBTLNu4xnasPSPgrbTPgx0m eUCw== 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=JEX+rZlj5vLUpd3byo6DdH+zMZqIoHib5p1zfmVA+FE=; b=Krr+A70HG/lQ5rsvXcHzrDWoyeG0JPy/s0vKwKtJwcCgF524Q2g/Q9pPpr9z6lmCRN 5zJn0iIEYI3mKdlYvdcL1b9wxyBul0R3tYBrycVlQWSzmCZjQTB74vQIz9w54ZNuBWsu C5sG6GIuUM+ka4Od5dWwMYG9UvXZMzM7LQLw0l3PGXWYa52HEtKYENJzurGfZOwDDZnB Yi0kiECPhQFdEOVa9B5F2z3tXsBabpvgvp/PuMKsrgW/4/fhdeeYR5ykbKkgNsirTgHp kXObXc7+Qk45lArPLDclr/q+R1hJgPv9V7fss5v5R+9GHpXFUBSbeQnMwksN7L6cks5G 3NnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=AjlRWquj; 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 l16-20020a170906a41000b006df76385f2bsi20721886ejz.971.2022.03.30.05.20.38; Wed, 30 Mar 2022 05:20:38 -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=20210112 header.b=AjlRWquj; 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 2D3A168B210; Wed, 30 Mar 2022 15:19:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BE62068B13C for ; Wed, 30 Mar 2022 15:19:46 +0300 (EEST) Received: by mail-lf1-f48.google.com with SMTP id h7so35493301lfl.2 for ; Wed, 30 Mar 2022 05:19:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DQ07VCqpbGLDnLFVQQHhti6Awh5ysPUT1zIJ+naNLuE=; b=AjlRWquj5MHrAIj5wO+cjZtU3LvxHHsG+IPFF95NGnzIJt7gWwpZIvXq9GroOlDhHx qACMgR+cwkVf9ySotf+Hqc7CQg7wu43ivGAgbxvLmqrHA7tJHIHv56Pn3XjWb1c5pCgb L+HtXbFDeO2xUakZuAAjm+QLx8uyUqEBqpkbk6WDG8Y7/fuQVg9zGM77uxu2Y+umHhkx cjRF5Nmjfz1mBRx0pLQK/BC/ZWCMkiOsyQ3jWcrEXbubCfFpsP7dNGUzIhxCiJUJsu5x CrLxLtHdwG54STzoI2Hm3uNUDEyI+eVPXJEJcQBxDwGZT4nQ5z/FwPTLoqoOVJe0A3Gj j+Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DQ07VCqpbGLDnLFVQQHhti6Awh5ysPUT1zIJ+naNLuE=; b=D2FklSjKqnzrYtJmXRz4Xw886/q031CLIut3Q+DjTWliDsHbxmHtobl+Tyuh0Fr6x/ W3tyGucCqiAEtgbdHspEiOk9v3pCa6N48ej6Ejp4ImcOZ+0FsUUT/xaAmIU7bk7sYuHB XSoIjGINllLQBnEhNKBr2SFeD3ftiksn19P+jE2Js1tY5z8U1Lm1UuAjfZdUR0ZHec6w zqPQre48CxV5YrXWNfPUEWNV0rkoSPPZpF+tuAoKFxvFxLUPuyAuBEoRr4ftrX4sf9vJ x6VORQzbmMVNoPefBpYzgEJX7us3HaDGB1+3r1PdXqYeZ0ZKJqiRy/zXj2gB49Oq2oOH x05Q== X-Gm-Message-State: AOAM533gjyCzuw/XZ4NmdSXXi2ysgtFRNzQVtgSkGmTTcQKINEs6zDjh n4I8LtKRulqboRl4gd91NDmrjSVfmJg= X-Received: by 2002:ac2:4241:0:b0:448:4b83:8372 with SMTP id m1-20020ac24241000000b004484b838372mr6740548lfl.463.1648642785820; Wed, 30 Mar 2022 05:19:45 -0700 (PDT) Received: from localhost.localdomain (deedock.humlab.lu.se. [130.235.135.183]) by smtp.gmail.com with ESMTPSA id f18-20020ac25cd2000000b0044a34937c16sm2318126lfq.173.2022.03.30.05.19.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 05:19:45 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Wed, 30 Mar 2022 14:17:58 +0200 Message-Id: <20220330121806.822-14-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20220330121806.822-1-dcnieho@gmail.com> References: <20220330121806.822-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 13/21] avdevice: improve capabilities' option 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: KsMtbWkf22+m This adds avdevice_capabilities_get_class() to allow examining the capabilities that can be queried/set through the capabilities API, and avdevice_capabilities_bprint_num() which allows printing the value returned when querying a capability. These values (min_value and max_value of an AVOptionRange) are doubles and this function formats them properly, e.g. 1. for a AV_OPT_TYPE_PIXEL_FMT -> yuyv422. bump minor version. Signed-off-by: Diederick Niehorster --- libavdevice/avdevice.c | 80 ++++++++++++++++++++++++++++++++++++++++++ libavdevice/avdevice.h | 27 ++++++++++++++ libavdevice/version.h | 4 +-- 3 files changed, 109 insertions(+), 2 deletions(-) diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c index 863f8df477..e2c60618d3 100644 --- a/libavdevice/avdevice.c +++ b/libavdevice/avdevice.c @@ -19,6 +19,9 @@ #include "libavutil/avassert.h" #include "libavutil/samplefmt.h" #include "libavutil/pixfmt.h" +#include "libavutil/pixdesc.h" +#include "libavutil/avutil.h" +#include "libavcodec/codec_id.h" #include "libavformat/version.h" #include "avdevice.h" #include "internal.h" @@ -141,6 +144,83 @@ int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatConte return ret; } +static const AVClass avdevice_capabilities_context_class = { + .class_name = "AVDeviceCapabilitiesQuery", + .item_name = av_default_item_name, + .option = ff_device_capabilities, + .version = LIBAVUTIL_VERSION_INT +}; + +const AVClass *avdevice_capabilities_get_class(void) +{ + return &avdevice_capabilities_context_class; +} + +int avdevice_capabilities_bprint_num(AVBPrint *bp, const char *name, double val) +{ + int opt_type_set = 0, is_codec = 0; + enum AVOptionType type; // will be set below, opt_type_set tracks if has been set + const AVClass *cap_class = avdevice_capabilities_get_class(); + + // may fail, e.g. if name of a component of a multi-component option was provided as input + const AVOption *field = av_opt_find(&cap_class, name, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ); + if (field) { + type = field->type; + opt_type_set = 1; + } + + // based on name, a type override or other extra info may be needed + if (opt_type_set && type==AV_OPT_TYPE_INT && strcmp(name, "codec")==0) + is_codec = 1; + // next three are for the three components of a AV_OPT_TYPE_IMAGE_SIZE + // NB: these wont be found by av_opt_find above + else if ( + strcmp(name, ff_device_get_query_component_name(AV_DEV_CAP_QUERY_WINDOW_SIZE, 0))==0 || + strcmp(name, ff_device_get_query_component_name(AV_DEV_CAP_QUERY_WINDOW_SIZE, 1))==0 || + strcmp(name, ff_device_get_query_component_name(AV_DEV_CAP_QUERY_WINDOW_SIZE, 2))==0 + ) { + type = AV_OPT_TYPE_INT; + opt_type_set = 1; + } + + // now, format if type set, else error + if (!opt_type_set) { + av_log(NULL, AV_LOG_ERROR, "A device capability with the name '%s' is not known\n", name); + return AVERROR_OPTION_NOT_FOUND; + } + + switch (type) + { + case AV_OPT_TYPE_INT: + { + int temp = lrint(val); + if (is_codec) + av_bprintf(bp, "%s", (char *)avcodec_get_name((enum AVCodecID)lrint(val))); + else + av_bprintf(bp, "%d", temp); + break; + } + case AV_OPT_TYPE_PIXEL_FMT: + av_bprintf(bp, "%s", (char *)av_x_if_null(av_get_pix_fmt_name((enum AVPixelFormat)lrint(val)), "none")); + break; + case AV_OPT_TYPE_SAMPLE_FMT: + av_bprintf(bp, "%s", (char *)av_x_if_null(av_get_sample_fmt_name((enum AVSampleFormat)lrint(val)), "none")); + break; + case AV_OPT_TYPE_DOUBLE: + av_bprintf(bp, "%f", val); + break; + case AV_OPT_TYPE_CHANNEL_LAYOUT: + av_bprintf(bp, "0x%"PRIx64, llrint(val)); + break; + + default: + av_log(NULL, AV_LOG_ERROR, "avdevice_capabilities_bprint_num is not implemented for this option type\n", name); + return AVERROR_PATCHWELCOME; + } + + return 0; +} + void avdevice_capabilities_free(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s) { if (!s || !caps || !(*caps)) diff --git a/libavdevice/avdevice.h b/libavdevice/avdevice.h index a815d65f12..5f9dfccc34 100644 --- a/libavdevice/avdevice.h +++ b/libavdevice/avdevice.h @@ -64,6 +64,7 @@ #include "libavutil/log.h" #include "libavutil/opt.h" #include "libavutil/dict.h" +#include "libavutil/bprint.h" #include "libavformat/avformat.h" /** @@ -418,6 +419,16 @@ int avdevice_dev_to_app_control_message(struct AVFormatContext *s, */ typedef struct AVDeviceCapabilitiesQuery AVDeviceCapabilitiesQuery; +/** + * Get the AVClass for AVDeviceCapabilitiesQuery. It can be used + * in combination with AV_OPT_SEARCH_FAKE_OBJ for examining + * which capabilities can be queried through the + * AVDeviceCapabilitiesQuery API. + * + * @see av_opt_find(), av_opt_next(). + */ +const AVClass *avdevice_capabilities_get_class(void); + /** * Initialize capabilities probing API based on AVOption API. * @@ -438,6 +449,22 @@ typedef struct AVDeviceCapabilitiesQuery AVDeviceCapabilitiesQuery; int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s, AVDictionary **device_options); +/** + * Format a capabilities value as string and append to a bprint buffer. + * @param bp A buffer to which the output string will be + * appended. + * @param name Name of the option to print (provide + * AVOptionRange.str). + * @param val An capabilities value represented as a + * double (e.g. min_value or max_value of + * AVOptionRange) + * @return 0 on success, a negative error code otherwise. Even if + * return value indicates success, the state of the bp variable + * should also be checked, as it may have experienced memory allocation + * trouble. + */ +int avdevice_capabilities_bprint_num(AVBPrint *bp, const char *name, double val); + /** * Free resources created by avdevice_capabilities_create() * diff --git a/libavdevice/version.h b/libavdevice/version.h index 181987d287..764aceccb5 100644 --- a/libavdevice/version.h +++ b/libavdevice/version.h @@ -30,8 +30,8 @@ #include "version_major.h" -#define LIBAVDEVICE_VERSION_MINOR 1 -#define LIBAVDEVICE_VERSION_MICRO 101 +#define LIBAVDEVICE_VERSION_MINOR 2 +#define LIBAVDEVICE_VERSION_MICRO 100 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \ LIBAVDEVICE_VERSION_MINOR, \ From patchwork Wed Mar 30 12:17:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 35056 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp774508pzb; Wed, 30 Mar 2022 05:20:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyihUO+ANUZlqbVHfj0xjl0N/IFjMP/pt//ITWLN46TNGazOoVdFFeAGsbkimcKbjBU/HZe X-Received: by 2002:a17:907:3d01:b0:6e0:c63b:1992 with SMTP id gm1-20020a1709073d0100b006e0c63b1992mr27033782ejc.422.1648642848388; Wed, 30 Mar 2022 05:20:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648642848; cv=none; d=google.com; s=arc-20160816; b=XqXpuu22XUllhEklkwH8ZbJwhdP50CEQAKFur2m5TBNZn3irLF34XvTMwotUXqCIdZ 2uG0ejmvOP1fy+c3t5RoLr1CpfTZ0uHtjCyUpTGb2Nu7vrApcJq/0BpohyBs74hqxY+D izPNZKs5k+Odh1knz5izseGcIkVQ5VIL2V14L84psBjY6FocDnRgtoVVoVWNkEf/HNlG ro9pze/PZ8IYTIAYCb5CIz6vLAVEaq/fAAm1GwTC1Fm+MpRCWAHbeDOaFqZqZc2UwGvL 98jhABAywh30alh/SSQyMJti7Oe89ax7ctbPbR7laRY3Ukn7YgMMxnImv+FJs1ALSEuO CiRQ== 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=oJwKKqTxhp5hCx8kUXi8h9mEgSTCo7lslq3HjbT7OCA=; b=uRSCCBbVVwFm0Dd1iSZrN71AaeMG46GNnEk/XslofhNhFH9tP+jSjael5Ll5dXfySH LKlwaKO34IashpQqHE2toZI0Hkc+CcOleZ0Nai2AJqsBQO3EzO/G+QBlT/9lq/AZlgxD PaRpaxLprO7rd7LoKG85E3sbyktN4uugeqXutygUkvmbCfAsqws+OS3OGW0wHybYt6eZ pi4MZ8ZdXBOXf6fmtCLZNX5Gah7gWijNie0xN6UC+cJV3MoEBbLoNFSfax4rypHcEZ5e lXHcgO+aF5GgYXb4j/YhsmvgKQa9AkhJu9QuQa9Bl+p/I0B3RkmNY7rdfxXIXKxwlkCa Ak9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="Ypz/uDZ2"; 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 go11-20020a1709070d8b00b006e08c4b10fesi28776662ejc.772.2022.03.30.05.20.48; Wed, 30 Mar 2022 05:20:48 -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=20210112 header.b="Ypz/uDZ2"; 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 1FB3968B21F; Wed, 30 Mar 2022 15:20:00 +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 19E8468B1EB for ; Wed, 30 Mar 2022 15:19:53 +0300 (EEST) Received: by mail-lf1-f45.google.com with SMTP id h7so35493789lfl.2 for ; Wed, 30 Mar 2022 05:19:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=X9tilHYFSR8oj/oR0fxEXcXNQjGVqHXRBOg/E6sKVkg=; b=Ypz/uDZ2E9xpezKplFNTDuIq5JlAfEdKY4l6VAQyGarenxjY8c81rc3rhlHr6EroYW rPCMNC2Sl66BOGEsNYxo1sgEeuWvGC7CnPLteHvMY0nziQRUAO+KRzsHjG5KFBVJvwEZ ksm9wRf1TEpW40d2QeWON9WVlRA/7ifCV1u9H3wBa9it3yodVuECsw1kM5YtZZABhXu/ HwCbc92QjdF7jJKIzAQH2y12+5vd0q9ljbk9AkTYfQlZcVMzNxnGavg2StgSD6y3rj1w +DScg5aDi6l8/yMl/JqbsyXvApnhnPYvDx3ipvUuAenjUxz+6szL+iLQyA3wwOmQUnqa RGyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=X9tilHYFSR8oj/oR0fxEXcXNQjGVqHXRBOg/E6sKVkg=; b=Hl1CAZnmHQuOtgeuqRR3QxFZl+sm6UmdOHQ3CdXoSN2If6slTkOqxI9xv6yHw53idw M0hL+vtVONKGEgPKUj2WelFgsMH/DuOFPuv9+fgjNMaJZbUgLGlr9/lx84u5DaLgL4QL NC1Hdz2Q/rPRKgVLwJWL9ZsG/popYoFQRcHZFEGtLpNDytVVYyziflfo6/hmDWCFMfTH lQ8nwNk7o7t+ZR1ZJW8Ge9dTKdSyBesQtCaDGj4xOR91nQX6xbPMw4FAn/5jiX3iAy08 pvzGYf82o1ZWiqF5t7JQUX+RF5l9OMlvBbJXMdsKepi0SYmNmj8srzF0AqxvO9RT+REg VPEw== X-Gm-Message-State: AOAM533h9oRAWnzdlrbQ4GAhcZJO8BzpBU7PEEfmwPQpf5iLLrPiCCFq dPqMhKkqqwTdN+tky1iogaxIZ+1CJr8= X-Received: by 2002:a05:6512:3f0a:b0:44a:e3f:2862 with SMTP id y10-20020a0565123f0a00b0044a0e3f2862mr6597721lfa.397.1648642792273; Wed, 30 Mar 2022 05:19:52 -0700 (PDT) Received: from localhost.localdomain (deedock.humlab.lu.se. [130.235.135.183]) by smtp.gmail.com with ESMTPSA id r20-20020a2e5754000000b002480655267dsm2283128ljd.67.2022.03.30.05.19.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 05:19:51 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Wed, 30 Mar 2022 14:17:59 +0200 Message-Id: <20220330121806.822-15-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20220330121806.822-1-dcnieho@gmail.com> References: <20220330121806.822-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 14/21] avdevice/dshow: move audio format helpers 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: g9XS0Pl2cbJM Needs to be moved up in file for upcoming implementation of avdevice_capabilities_create. Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index a780351170..d35224beb5 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -79,6 +79,26 @@ static enum AVPixelFormat dshow_pixfmt(DWORD biCompression, WORD biBitCount) return avpriv_pix_fmt_find(PIX_FMT_LIST_RAW, biCompression); // all others } +static enum AVCodecID waveform_codec_id(enum AVSampleFormat sample_fmt) +{ + switch (sample_fmt) { + case AV_SAMPLE_FMT_U8: return AV_CODEC_ID_PCM_U8; + case AV_SAMPLE_FMT_S16: return AV_CODEC_ID_PCM_S16LE; + case AV_SAMPLE_FMT_S32: return AV_CODEC_ID_PCM_S32LE; + default: return AV_CODEC_ID_NONE; /* Should never happen. */ + } +} + +static enum AVSampleFormat sample_fmt_bits_per_sample(int bits) +{ + switch (bits) { + case 8: return AV_SAMPLE_FMT_U8; + case 16: return AV_SAMPLE_FMT_S16; + case 32: return AV_SAMPLE_FMT_S32; + default: return AV_SAMPLE_FMT_NONE; /* Should never happen. */ + } +} + static enum AVColorRange dshow_color_range(DXVA2_ExtendedFormat *fmt_info) { switch (fmt_info->NominalRange) @@ -1610,26 +1630,6 @@ static int dshow_control_message(AVFormatContext *avctx, int type, void *data, s return ret; } -static enum AVCodecID waveform_codec_id(enum AVSampleFormat sample_fmt) -{ - switch (sample_fmt) { - case AV_SAMPLE_FMT_U8: return AV_CODEC_ID_PCM_U8; - case AV_SAMPLE_FMT_S16: return AV_CODEC_ID_PCM_S16LE; - case AV_SAMPLE_FMT_S32: return AV_CODEC_ID_PCM_S32LE; - default: return AV_CODEC_ID_NONE; /* Should never happen. */ - } -} - -static enum AVSampleFormat sample_fmt_bits_per_sample(int bits) -{ - switch (bits) { - case 8: return AV_SAMPLE_FMT_U8; - case 16: return AV_SAMPLE_FMT_S16; - case 32: return AV_SAMPLE_FMT_S32; - default: return AV_SAMPLE_FMT_NONE; /* Should never happen. */ - } -} - static int dshow_add_device(AVFormatContext *avctx, enum dshowDeviceType devtype) From patchwork Wed Mar 30 12:18:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 35069 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp774582pzb; Wed, 30 Mar 2022 05:20:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrkf8cWl+mhWJNC29GF6a+lgpAJ8lATVVGCzFMXu+VW9vwj3fhZj1Gj6vbJbWkHXNHooPc X-Received: by 2002:a05:6402:1385:b0:413:2bc6:4400 with SMTP id b5-20020a056402138500b004132bc64400mr10583659edv.94.1648642858683; Wed, 30 Mar 2022 05:20:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648642858; cv=none; d=google.com; s=arc-20160816; b=Apv4WQfDJOh/D3wU6APLIAbcuZSz0pKmX58sdJxPDQqbbOq08cPsDT4bRLzbIpOjeu EIYIBIFFrSQrjIj2zUYOQDal49729KxBuLM8KEwl3rJYlOiUSDdQE9GRHkFkqV/Z9PGT QHAEVsCX4NzXEU5nSN7rZ9xvRjj5PBkUHAG0HmFQUVNpcP9tTwkMxMAL+M5E3F70PVuk md3xEx+ghN/Sq19vFYPAdFGWEXAkP4fOEWW2UxfbG+Pva9U+JOn7O4p7ZYqydqQIcD/H qIDosg42lUROODNgberCf2IYX2TEAUY2QhbKzWXG9IHbWeo7mChKPURNiWRNo+jc2Fiz OleA== 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=CClGl678/vkJZEzh0zBJsqU/ddMSJj3H8A68MKwD7ho=; b=q4IJCFRDkXonxnH0fkJjESgX+2YQO/Gfjin4xTBcXGMGW8Qy7fPsg4AYpeBCnRTf5A T9+dscj+CI+vbjgCarBFfMDttK9WRhXl114d3QI+p8CdKeEaOZ6fm2QYpqAzQxVDgynC 7MJGQdFF3Wfo/8l2QpYb3vg9njNFGMBL0vHueKAw9zpOfEVBy1Vjt1QkxIQk8EuA4UGR GztZsVavqRvVBcllLa9Xx6ZJ0dQZA/gaPnrx4ISgr9vg5tWHYbCl2fMnV/NMByDO7WqB W12jQTOSy+EC6F11LOG+vkd2q6+qHp+yh+024yeLmdkbBUyOGdD35aOhwPsfTovPVjqt lRnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=NXrAkBxW; 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 t17-20020a170906065100b006dfa8b9bc20si20910404ejb.894.2022.03.30.05.20.57; Wed, 30 Mar 2022 05:20:58 -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=20210112 header.b=NXrAkBxW; 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 01BBC68B1EB; Wed, 30 Mar 2022 15:20:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6709B68B280 for ; Wed, 30 Mar 2022 15:20:00 +0300 (EEST) Received: by mail-lf1-f42.google.com with SMTP id bq24so19522266lfb.5 for ; Wed, 30 Mar 2022 05:20:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NK/QrJEeth1MSuzhPObWDUazu7iR/OBn1N+cSzfeM/U=; b=NXrAkBxWGY5TrlVzdjwnIB6LUAWzaS/kf01BrfZeLSwOdF/zd3Dz/3wxWOtAoJxJHa dhJBxTvhXIu38AfTi4bGE+0ElKJkXK4Gg8QIJcQ5bBDderTLpdXdTxvpHJfDHgGS/tub ON67nwhWKTDFP4KbTjJWXBcfY78t+piWerVxEjHmuOLJR/fGuXbkZcqkNHpg3fluw/LJ sZL97lzaKlLzYl9tLpos29Uwa2dIrMZHU60MO//MbFlk51+j4tqy5oKHTfFd2Ii+rkxl 4il/1tirNw06nnp1l2J1cOUTMi5lXFDLYx/4Y1KR9kuVDYZIRiU3CNnK7dQFdXFKbsKH wYlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NK/QrJEeth1MSuzhPObWDUazu7iR/OBn1N+cSzfeM/U=; b=n8hVslHkkXBawOAlhn2O+s9v6i2VftRt1DZ3qEwOR2g9uyU0OkbzEHWPF7g7HwJPgD +r8bkedMRng/C81fO0qvtgrrgz1LMB0yNldw7gJjzFPcTW9rfHime6W6cpQTFS8/coGg dxr52FO3qeNF2VHlRaGnwZD1oEGVOJV8Wd440sDeUGQLnYWkMd0BLBKSyU6IWVbvshv+ lviggFb8XYp+adeU+NPkzkvZ6Vp5Dh8qfFB8wUBHBD1DyBk3yeQcL+JAflYNmX3Jr06o CiwdkBWwBCPGxZADJZlLZ1Oy4dzu3pkaJjwUrHAAGxyJ3+YVFaWetmBZKImbXjMTGfrj oNEQ== X-Gm-Message-State: AOAM532TldLAVhxRelhGeV58cm3srts2iOlxuUGwkFI5I++qRCbDHjpx spOvSP7SU8FH96ZW7RQO4J1rIyhqpyY= X-Received: by 2002:a05:6512:555:b0:44a:a75c:885c with SMTP id h21-20020a056512055500b0044aa75c885cmr6508200lfl.80.1648642798721; Wed, 30 Mar 2022 05:19:58 -0700 (PDT) Received: from localhost.localdomain (deedock.humlab.lu.se. [130.235.135.183]) by smtp.gmail.com with ESMTPSA id g36-20020a0565123ba400b0044a2a1ccd99sm2319993lfv.20.2022.03.30.05.19.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 05:19:58 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Wed, 30 Mar 2022 14:18:00 +0200 Message-Id: <20220330121806.822-16-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20220330121806.822-1-dcnieho@gmail.com> References: <20220330121806.822-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 15/21] avdevice/dshow: when closing, set context fields back to zero 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: ZJz+lNp3I7kS After the avdevice capabilities API is implemented, the format context may be reused after querying device capabilities in a later avformat_open_input call. To enable this reuse, after releasing resources, make sure to also set the corresponding pointers back to NULL. This correctly indicates their state after cleanup. Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index d35224beb5..0d5f731030 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -264,14 +264,18 @@ dshow_read_close(AVFormatContext *s) ICaptureGraphBuilder2_Release(ctx->graph_builder2[VideoDevice]); if (ctx->graph_builder2[AudioDevice]) ICaptureGraphBuilder2_Release(ctx->graph_builder2[AudioDevice]); + ctx->graph_builder2[0] = NULL; + ctx->graph_builder2[1] = NULL; if (ctx->control) { IMediaControl_Stop(ctx->control); IMediaControl_Release(ctx->control); } + ctx->control = NULL; if (ctx->media_event) IMediaEvent_Release(ctx->media_event); + ctx->media_event = NULL; if (ctx->graph) { IEnumFilters *fenum; @@ -289,25 +293,34 @@ dshow_read_close(AVFormatContext *s) IEnumFilters_Release(fenum); } IGraphBuilder_Release(ctx->graph); + ctx->graph = NULL; } if (ctx->capture_pin[VideoDevice]) ff_dshow_pin_Release(ctx->capture_pin[VideoDevice]); if (ctx->capture_pin[AudioDevice]) ff_dshow_pin_Release(ctx->capture_pin[AudioDevice]); + ctx->capture_pin[0] = NULL; + ctx->capture_pin[1] = NULL; if (ctx->capture_filter[VideoDevice]) ff_dshow_filter_Release(ctx->capture_filter[VideoDevice]); if (ctx->capture_filter[AudioDevice]) ff_dshow_filter_Release(ctx->capture_filter[AudioDevice]); + ctx->capture_filter[0] = NULL; + ctx->capture_filter[1] = NULL; if (ctx->device_pin[VideoDevice]) IPin_Release(ctx->device_pin[VideoDevice]); if (ctx->device_pin[AudioDevice]) IPin_Release(ctx->device_pin[AudioDevice]); + ctx->device_pin[0] = NULL; + ctx->device_pin[1] = NULL; if (ctx->device_filter[VideoDevice]) IBaseFilter_Release(ctx->device_filter[VideoDevice]); if (ctx->device_filter[AudioDevice]) IBaseFilter_Release(ctx->device_filter[AudioDevice]); + ctx->device_filter[0] = NULL; + ctx->device_filter[1] = NULL; av_freep(&ctx->device_name[0]); av_freep(&ctx->device_name[1]); @@ -316,10 +329,13 @@ dshow_read_close(AVFormatContext *s) if(ctx->mutex) CloseHandle(ctx->mutex); + ctx->mutex = NULL; if(ctx->event[0]) CloseHandle(ctx->event[0]); if(ctx->event[1]) CloseHandle(ctx->event[1]); + ctx->event[0] = NULL; + ctx->event[1] = NULL; pktl = ctx->pktl; while (pktl) { @@ -328,6 +344,7 @@ dshow_read_close(AVFormatContext *s) av_free(pktl); pktl = next; } + ctx->pktl = NULL; CoUninitialize(); From patchwork Wed Mar 30 12:18:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 35070 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp774653pzb; Wed, 30 Mar 2022 05:21:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDz4tULRy7s+yK9Y/LLUL1WvXySO7/kzQfG8DY+ujndVv9lOa6pkaBo6xNpppGHKStTIYC X-Received: by 2002:a17:906:478b:b0:6db:8b6e:d5de with SMTP id cw11-20020a170906478b00b006db8b6ed5demr40933390ejc.161.1648642867680; Wed, 30 Mar 2022 05:21:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648642867; cv=none; d=google.com; s=arc-20160816; b=E4oLWp6Lg0yrTP1d+CozB2g4gudl95mH0xUD4xjgoJUMB7oExfhyPfXBWRqW4BFf9g xKJsICZvb9yxFvBygPaZ01YI2KDMnrVzaW5fcVJol8Z0tE/c4XsOsVtckkBQuXAPLNIu KiBLOOVcdS51py173ICBH7bstw9qgHFGDR905xVVpMdaFiCZ+92oPNXLiHcTBnzVLNAw Si64gHqu201k1UJ48L4fvjqkYXe3Z+bWgKmPpm/XyYbTPC1tzYUoHehCps7Pl+5QLj55 ZAKB2REXs/UBnj4+ZbtZkQO//dCpFHEc4b5B5viU6j9xR1Nba0l1xkOUmeuJvJdoUwlf TFYw== 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=U2m4Q8Jp1yqUCsUlzegkCbAzIqy2lOneAs7zUiF6ZaM=; b=ZhIEEG7JmydWFqNFABp5Q6dmZQUxIpPk++WyurL85VREI0ra4dxYYNL1r3P5QF91yl AsLjZjQpXwb+QyeijFWwpapY8jopzvVdhvpE2ftoCEZl4Z7I38+jVF+jliwjeLEXXS2l i83t/LujoMV2DvnjOH8KvVRbPWzDmveZ0GnOcdEbxPBfxeZva0e/R0tT/o5OHmuUUc/U mJpeueXnwmqPYYwSvSOHnEiI3K/y2xqHP5inXs+K14l6Utj3WBFMlRYNoTdK2gxv/o4P l2DQP0E2B+9Xo/u7PCindS5PYIPfmhqjAZSgcxOwaUDGdISXIS5SFwA4b4cb1pbB2KcF 1jKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=faIBOfxx; 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 s12-20020a1709067b8c00b006df76385ee7si21729679ejo.903.2022.03.30.05.21.07; Wed, 30 Mar 2022 05:21:07 -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=20210112 header.b=faIBOfxx; 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 1646468B297; Wed, 30 Mar 2022 15:20:08 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B642568B289 for ; Wed, 30 Mar 2022 15:20:06 +0300 (EEST) Received: by mail-lf1-f47.google.com with SMTP id bu29so35585407lfb.0 for ; Wed, 30 Mar 2022 05:20:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=m0aVniDB6Sz31bLyiPjfYMpMkT6AWQ3czrPjZpd+tGk=; b=faIBOfxxIqhUQ9PnSKGV8sjD47VbxaOMgInDrYIwrRapr9aWCm1tk40Zc2w4KgX2xL tXZmlPDCUkjVAwZjoFNH5n3Op7oeT/GFyBZPbtQ8opbfJxu0jrHVLMzX9sWLa1uqTHHK ysws3dFZu3M45TROhwCUpoUj0RjjAdhKq2s0XXoQ0Vh2JBLxbBhq6VEShfE8K8mqs7zv bcWbQWNgxitmu6J/ZuDhdfySn3OEP3teC2ZLGtXwhI9Wcwrxm7vWwjkvmYuuPB3yuLOl IpkvpFnvjiM6pNsDCNyIX6QioNk4MCY47VuHhJSMlz1Jq60vKDGvb+Oi+mvC2uG1WHg1 BtRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=m0aVniDB6Sz31bLyiPjfYMpMkT6AWQ3czrPjZpd+tGk=; b=63tOzoSHjZuYOjw2RQ8vuT66pD2Gnpgq1aA3Rnt0/Sn92n3gbBP1UKPb74Im8D5Fxd ImH2ypx3gGVtN0vAwxcytwk4PdY6QutxcmzqaFxrpWm/o8qEoegt6lyJzKwoUbWD79oJ DOvOPzMEb4g3IvRDYEarcr52XIaHT4TFsnP3nX4oS2fNGxE/4WFoW4Y4jmhPO7yY1J/m xCQdmuTE2Tv/9qsifcz9Bh+jpV/y30TEnCREtOj2NdTIjs98ZrkL7spE8KSRgJNSXJWP qZXlOK+u1bMwOkVk5u3jbWClF/2+nrLkCLtz9Q2k2j9ZgxJAPiV5KrKHfm5F9uw1om1R 7NFw== X-Gm-Message-State: AOAM531ZHoEYXO5WFt/SV4+3A0/aFtplhZ4wmlkbPkT7zFEsyyvDOMDJ FugG3XOeARLP01cjCVT0ThqHuv9UCtk= X-Received: by 2002:ac2:4c42:0:b0:448:622e:5e81 with SMTP id o2-20020ac24c42000000b00448622e5e81mr6629183lfk.425.1648642805234; Wed, 30 Mar 2022 05:20:05 -0700 (PDT) Received: from localhost.localdomain (deedock.humlab.lu.se. [130.235.135.183]) by smtp.gmail.com with ESMTPSA id r23-20020a2e94d7000000b002498622f241sm2412564ljh.12.2022.03.30.05.20.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 05:20:04 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Wed, 30 Mar 2022 14:18:01 +0200 Message-Id: <20220330121806.822-17-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20220330121806.822-1-dcnieho@gmail.com> References: <20220330121806.822-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 16/21] avdevice/dshow: implement 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: BSpGAeCFMC+I This implements avdevice_capabilities_create and avdevice_capabilities_free for the dshow device. This enables 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 device's capabilities through the list_options option with an FFmpeg tool, and listing what they want to configure in dumb text boxes. Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 430 ++++++++++++++++++++++++++++++++++++++++-- libavdevice/version.h | 2 +- 2 files changed, 412 insertions(+), 20 deletions(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 0d5f731030..58476a0f40 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -27,6 +27,7 @@ #include "libavformat/internal.h" #include "libavformat/riff.h" #include "avdevice.h" +#include "internal.h" #include "libavcodec/raw.h" #include "objidl.h" #include "shlwapi.h" @@ -830,11 +831,15 @@ static void dshow_get_default_format(IPin *pin, IAMStreamConfig *config, enum ds * try to set parameters specified through AVOptions, or the pin's * default format if no such parameters were set. If successful, * return 1 in *pformat_set. - * If pformat_set is NULL, list all pin capabilities. + * If pformat_set is NULL or the ranges input is not NULL, list all + * pin capabilities. + * When listing pin capabilities, if ranges is NULL, output to log, + * else store capabilities in ranges. */ static void dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, - IPin *pin, int *pformat_set) + IPin *pin, int *pformat_set, + AVOptionRanges *ranges, enum AVDeviceCapabilitiesQueryType query_type) { struct dshow_ctx *ctx = avctx->priv_data; IAMStreamConfig *config = NULL; @@ -878,7 +883,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, * one, with most info exposed (see comment below). */ use_default = !dshow_should_set_format(avctx, devtype); - if (use_default && pformat_set) + if (use_default && pformat_set && !ranges) { // get default dshow_get_default_format(pin, config, devtype, &type); @@ -924,7 +929,9 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, // exposes contains a VIDEOINFOHEADER2. Fall back to the VIDEOINFOHEADER // format if no corresponding VIDEOINFOHEADER2 is found when we finish // iterating. - for (i = 0; i < n && !format_set; i++) { + for (i = 0; i < n && (!format_set || ranges); i++) { + AVOptionRange *new_range[3] = { NULL }; + int nb_range = 0; struct dshow_format_info *fmt_info = NULL; r = IAMStreamConfig_GetStreamCaps(config, i, &type, (void *) caps); if (r != S_OK) @@ -960,7 +967,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, wait_for_better = 0; } - if (!pformat_set) { + if (!pformat_set && !ranges) { const char *chroma = av_chroma_location_name(fmt_info->chroma_loc); if (fmt_info->pix_fmt == AV_PIX_FMT_NONE) { const AVCodec *codec = avcodec_find_decoder(fmt_info->codec_id); @@ -1024,6 +1031,60 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, bih->biWidth = requested_width; bih->biHeight = requested_height; } + + if (ranges) { + for (int j = 0; j < ranges->nb_components; j++) { + new_range[j] = av_mallocz(sizeof(**new_range)); + if (!new_range[j]) + goto next; + new_range[j]->value_max = -1.; // init (min:0, max:-1 means value not set) + ++nb_range; + + switch (query_type) + { + case AV_DEV_CAP_QUERY_CODEC: + if (dshow_pixfmt(bih->biCompression, bih->biBitCount) == AV_PIX_FMT_NONE) { + const AVCodecTag *const tags[] = { avformat_get_riff_video_tags(), NULL }; + new_range[j]->value_min = av_codec_get_id(tags, bih->biCompression); + } + else + new_range[j]->value_min = AV_CODEC_ID_RAWVIDEO; + new_range[j]->value_max = new_range[j]->value_min; + break; + case AV_DEV_CAP_QUERY_PIXEL_FORMAT: + new_range[j]->value_min = new_range[j]->value_max = dshow_pixfmt(bih->biCompression, bih->biBitCount); + new_range[j]->value_min; + break; + case AV_DEV_CAP_QUERY_FRAME_SIZE: + { + switch (j) + { + case 0: + new_range[j]->value_min = vcaps->MinOutputSize.cx * vcaps->MinOutputSize.cy; + new_range[j]->value_max = vcaps->MaxOutputSize.cx * vcaps->MaxOutputSize.cy; + break; + case 1: + new_range[j]->value_min = vcaps->MinOutputSize.cx; + new_range[j]->value_max = vcaps->MaxOutputSize.cx; + break; + case 2: + new_range[j]->value_min = vcaps->MinOutputSize.cy; + new_range[j]->value_max = vcaps->MaxOutputSize.cy; + break; + } + break; + } + case AV_DEV_CAP_QUERY_FPS: + new_range[j]->value_min = 1e7 / vcaps->MaxFrameInterval; + new_range[j]->value_max = 1e7 / vcaps->MinFrameInterval; + break; + + // default: + // an audio property is being queried, output all fields 0 (mallocz above) is fine + } + } + } + } else { WAVEFORMATEX *fx; AUDIO_STREAM_CONFIG_CAPS *acaps = caps; @@ -1035,7 +1096,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, } else { goto next; } - if (!pformat_set) { + if (!pformat_set && !ranges) { av_log( avctx, AV_LOG_INFO, @@ -1051,15 +1112,69 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, ) { goto next; } + + if (ranges) { + for (int j = 0; j < ranges->nb_components; j++) { + new_range[j] = av_mallocz(sizeof(**new_range)); + if (!new_range[j]) + goto next; + new_range[j]->value_max = -1.; // init (min:0, max:-1 means value not set) + ++nb_range; + + switch (query_type) + { + case AV_DEV_CAP_QUERY_SAMPLE_FORMAT: + new_range[j]->value_min = sample_fmt_bits_per_sample(acaps->MinimumBitsPerSample); + new_range[j]->value_max = sample_fmt_bits_per_sample(acaps->MaximumBitsPerSample); + break; + case AV_DEV_CAP_QUERY_SAMPLE_RATE: + new_range[j]->value_min = acaps->MinimumSampleFrequency; + new_range[j]->value_max = acaps->MaximumSampleFrequency; + break; + case AV_DEV_CAP_QUERY_CHANNELS: + new_range[j]->value_min = acaps->MinimumChannels; + new_range[j]->value_max = acaps->MaximumChannels; + break; + + // default: + // a video property is being queried, output all fields 0 (mallocz above) is fine + // NB: this is a for-loop since some of the video queries are multi-component + // and all components should be set + } + } + } } // found a matching format. Either apply or store // for safekeeping if we might maybe find a better // format with more info attached to it (see comment - // above loop) - if (!wait_for_better) { + // above loop). If storing all capabilities of device + // in ranges, try to apply in all cases, and store + // caps if successfully applied + if (!wait_for_better || ranges) { if (IAMStreamConfig_SetFormat(config, type) != S_OK) goto next; + else if (ranges) { + // format matched and could be set successfully. + // fill in some fields for each capability + for (int j = 0; j < nb_range; j++) { + new_range[j]->str = av_strdup(ff_device_get_query_component_name(query_type, j)); + if (!new_range[j]->str) + goto next; + new_range[j]->is_range = new_range[j]->value_min < new_range[j]->value_max; + } + + // store to ranges output + if (av_reallocp_array(&ranges->range, + ranges->nb_ranges * ranges->nb_components + nb_range * ranges->nb_components, + sizeof(*ranges->range)) < 0) + goto next; + for (int j = 0; j < nb_range; ++j) { + ranges->range[ranges->nb_ranges] = new_range[j]; + ranges->nb_ranges++; + new_range[j] = NULL; // copied into array, make sure not freed below + } + } format_set = 1; } else if (!previous_match_type) { @@ -1070,6 +1185,12 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, } next: av_freep(&fmt_info); + for (int j = 0; j < nb_range; ++j) { + if (new_range[j]) { + av_freep(&new_range[j]->str); + av_freep(&new_range[j]); + } + } if (type && type->pbFormat) CoTaskMemFree(type->pbFormat); CoTaskMemFree(type); @@ -1209,10 +1330,13 @@ end: * devtype, retrieve the first output pin and return the pointer to the * object found in *ppin. * If ppin is NULL, cycle through all pins listing audio/video capabilities. + * If ppin is not NULL and ranges is also not null, enumerate all formats + * supported by the selected pin. */ static int dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype, - enum dshowSourceFilterType sourcetype, IBaseFilter *device_filter, IPin **ppin) + enum dshowSourceFilterType sourcetype, IBaseFilter *device_filter, + IPin **ppin, AVOptionRanges *ranges, enum AVDeviceCapabilitiesQueryType query_type) { struct dshow_ctx *ctx = avctx->priv_data; IEnumPins *pins = 0; @@ -1250,6 +1374,7 @@ dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype, wchar_t *pin_id = NULL; char *pin_buf = NULL; char *desired_pin_name = devtype == VideoDevice ? ctx->video_pin_name : ctx->audio_pin_name; + int nb_ranges = ranges ? ranges->nb_ranges : 0; IPin_QueryPinInfo(pin, &info); IBaseFilter_Release(info.pFilter); @@ -1274,7 +1399,7 @@ dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype, if (!ppin) { av_log(avctx, AV_LOG_INFO, " Pin \"%s\" (alternative pin name \"%s\")\n", name_buf, pin_buf); - dshow_cycle_formats(avctx, devtype, pin, NULL); + dshow_cycle_formats(avctx, devtype, pin, NULL, NULL, AV_DEV_CAP_QUERY_NONE); goto next; } @@ -1288,12 +1413,15 @@ dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype, // will either try to find format matching options supplied by user // or try to open default format. Successful if returns with format_set==1 - dshow_cycle_formats(avctx, devtype, pin, &format_set); + // if ranges is non-NULL, will iterate over all formats and return info + // about all the valid ones. If any valid found, format_set==1, else + // format_set will be 0 + dshow_cycle_formats(avctx, devtype, pin, &format_set, ranges, query_type); if (!format_set) { goto next; } - if (devtype == AudioDevice && ctx->audio_buffer_size) { + if (devtype == AudioDevice && ctx->audio_buffer_size && !ranges) { if (dshow_set_audio_buffer_size(avctx, pin) < 0) { av_log(avctx, AV_LOG_ERROR, "unable to set audio buffer size %d to pin, using pin anyway...", ctx->audio_buffer_size); } @@ -1306,8 +1434,25 @@ dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype, next: if (p) IKsPropertySet_Release(p); - if (device_pin != pin) + if (device_pin != pin) { IPin_Release(pin); + // remove any option ranges info we just added, wrong pin + if (ranges && nb_ranges>0) { + int nb_original_entries = nb_ranges * ranges->nb_components; + for (int i = nb_original_entries; i < ranges->nb_ranges * ranges->nb_components; i++) { + AVOptionRange *range = ranges->range[i]; + if (range) { + av_freep(&range->str); + av_freep(&ranges->range[i]); + } + } + if (av_reallocp_array(&ranges->range, nb_original_entries, sizeof(*ranges->range)) < 0) + ranges->nb_ranges = 0; + else + ranges->nb_ranges = nb_ranges; + } + device_pin = NULL; + } av_free(name_buf); av_free(pin_buf); if (pin_id) @@ -1339,10 +1484,12 @@ next: */ static int dshow_list_device_options(AVFormatContext *avctx, ICreateDevEnum *devenum, - enum dshowDeviceType devtype, enum dshowSourceFilterType sourcetype) + enum dshowDeviceType devtype, enum dshowSourceFilterType sourcetype, + AVOptionRanges *ranges, enum AVDeviceCapabilitiesQueryType query_type) { struct dshow_ctx *ctx = avctx->priv_data; IBaseFilter *device_filter = NULL; + IPin *device_pin = NULL; char *device_unique_name = NULL; int r; @@ -1350,7 +1497,7 @@ dshow_list_device_options(AVFormatContext *avctx, ICreateDevEnum *devenum, return r; ctx->device_filter[devtype] = device_filter; ctx->device_unique_name[devtype] = device_unique_name; - if ((r = dshow_cycle_pins(avctx, devtype, sourcetype, device_filter, NULL)) < 0) + if ((r = dshow_cycle_pins(avctx, devtype, sourcetype, device_filter, ranges ? &device_pin : NULL, ranges, query_type)) < 0) return r; return 0; } @@ -1433,7 +1580,7 @@ dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum, goto error; } - if ((r = dshow_cycle_pins(avctx, devtype, sourcetype, device_filter, &device_pin)) < 0) { + if ((r = dshow_cycle_pins(avctx, devtype, sourcetype, device_filter, &device_pin, NULL, AV_DEV_CAP_QUERY_NONE)) < 0) { ret = r; goto error; } @@ -1856,14 +2003,14 @@ static int dshow_read_header(AVFormatContext *avctx) } if (ctx->list_options) { if (ctx->device_name[VideoDevice]) - if ((r = dshow_list_device_options(avctx, devenum, VideoDevice, VideoSourceDevice))) { + if ((r = dshow_list_device_options(avctx, devenum, VideoDevice, VideoSourceDevice, NULL, AV_DEV_CAP_QUERY_NONE))) { ret = r; goto error; } if (ctx->device_name[AudioDevice]) { - if (dshow_list_device_options(avctx, devenum, AudioDevice, AudioSourceDevice)) { + if (dshow_list_device_options(avctx, devenum, AudioDevice, AudioSourceDevice, NULL, AV_DEV_CAP_QUERY_NONE)) { /* show audio options from combined video+audio sources as fallback */ - if ((r = dshow_list_device_options(avctx, devenum, AudioDevice, VideoSourceDevice))) { + if ((r = dshow_list_device_options(avctx, devenum, AudioDevice, VideoSourceDevice, NULL, AV_DEV_CAP_QUERY_NONE))) { ret = r; goto error; } @@ -2010,6 +2157,249 @@ static int dshow_read_packet(AVFormatContext *s, AVPacket *pkt) return ctx->eof ? AVERROR(EIO) : pkt->size; } +// TODO: consider if and how to expose extra info we have about formats, such as color_range +static int dshow_query_ranges(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags) +{ + AVDeviceCapabilitiesQuery *caps = obj; + const AVFormatContext *avctx = caps->device_context; + struct dshow_ctx *ctx = avctx->priv_data; + + int backup_sample_size; + int backup_sample_rate; + int backup_channels; + enum AVCodecID backup_video_codec_id; + enum AVPixelFormat backup_pixel_format; + int backup_requested_width; + int backup_requested_height; + char* backup_framerate = NULL; + + enum AVDeviceCapabilitiesQueryType query_type = AV_DEV_CAP_QUERY_NONE; + + AVOptionRanges *ranges = av_mallocz(sizeof(**ranges_arg)); + const AVOption *field = av_opt_find(obj, key, NULL, 0, flags); + int ret; + + ICreateDevEnum *devenum = NULL; + + *ranges_arg = NULL; + + if (!ranges) { + ret = AVERROR(ENOMEM); + goto fail1; + } + + if (!field) { + ret = AVERROR_OPTION_NOT_FOUND; + goto fail1; + } + + // turn option name into cap query + query_type = ff_device_get_query_type(field->name); + + if (query_type == AV_DEV_CAP_QUERY_CHANNEL_LAYOUT || query_type == AV_DEV_CAP_QUERY_WINDOW_SIZE) { + av_log(avctx, AV_LOG_ERROR, "Querying the option %s is not supported for a dshow device\n", field->name); + ret = AVERROR(EINVAL); + goto fail1; + } + + // take backup of dshow parameters/options + // audio + backup_sample_size = ctx->sample_size; + backup_sample_rate = ctx->sample_rate; + backup_channels = ctx->channels; + // video + backup_video_codec_id = ctx->video_codec_id; + backup_pixel_format = ctx->pixel_format; + backup_requested_width = ctx->requested_width; + backup_requested_height= ctx->requested_height; + backup_framerate = ctx->framerate; + + + // set format constraints set in AVDeviceCapabilitiesQuery + // audio (NB: channel_layout not used) + ctx->sample_size = av_get_bytes_per_sample(caps->sample_format) << 3; + ctx->sample_rate = (caps->sample_rate == -1) ? 0 : caps->sample_rate; + ctx->channels = (caps->channels == -1) ? 0 : caps->channels; + // video (NB: window_width and window_height not used) + ctx->video_codec_id = caps->codec; + ctx->pixel_format = caps->pixel_format; + ctx->requested_width = caps->frame_width; + ctx->requested_height = caps->frame_height; + // dshow checks whether requested framerate is set by means of !ctx->framerate. + // fill with something + if (!isnan(caps->fps)) { + ctx->requested_framerate = av_d2q(caps->fps, INT_MAX); + ctx->framerate = av_strdup("dummy"); // just make sure its non-zero + if (!ctx->framerate) { + ret = AVERROR(ENOMEM); + goto fail2; + } + } + else + ctx->framerate = NULL; // make sure its NULL (if it wasn't, we already have a backup of the pointer to restore later) + + // now iterate matching format of pin that would be selected when device + // is opened with options currently in effect. + // for each matching format, output its parameter range, also if that same + // range already returned for another format. That way, user can reconstruct + // possible valid combinations by av_opt_query_ranges() for each of the + // format options and matching returned values by sequence number. + if (CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, + &IID_ICreateDevEnum, (void **) &devenum)) { + av_log(avctx, AV_LOG_ERROR, "Could not enumerate system devices.\n"); + ret = AVERROR(EIO); + goto fail2; + } + + ctx->video_codec_id = ctx->video_codec_id ? ctx->video_codec_id + : AV_CODEC_ID_RAWVIDEO; + + ranges->nb_components = (field->type == AV_OPT_TYPE_IMAGE_SIZE && (flags & AV_OPT_MULTI_COMPONENT_RANGE)) ? 3 : 1; + if (ctx->device_name[VideoDevice]) + if ((ret = dshow_list_device_options(avctx, devenum, VideoDevice, VideoSourceDevice, ranges, query_type)) < 0) + goto fail2; + if (ctx->device_name[AudioDevice]) { + if (dshow_list_device_options(avctx, devenum, AudioDevice, AudioSourceDevice, ranges, query_type) < 0) { + /* show audio options from combined video+audio sources as fallback */ + if ((ret = dshow_list_device_options(avctx, devenum, AudioDevice, VideoSourceDevice, ranges, query_type)) < 0) + goto fail2; + } + } + ret = ranges->nb_ranges ? ranges->nb_components : 0; + + // when dealing with a multi-component item (regardless of whether + // AV_OPT_MULTI_COMPONENT_RANGE is set or not), we need to reorganize the + // output range array from [r1_c1 r1_c2 r1_c3 r2_c1 r2_c2 r2_c3 ...] to + // [r1_c1 r2_c1 ... r1_c2 r2_c2 ... r1_c3 r2_c3 ...] to be consistent with + // documentation of AVOptionRanges in libavutil/opt.h + if (ranges->nb_ranges && ranges->nb_components > 1) { + AVOptionRange **new_range = av_malloc_array(ranges->nb_components * ranges->nb_ranges, sizeof(*ranges->range)); + AVOptionRange **old_range = ranges->range; + if (!new_range) { + ret = AVERROR(ENOMEM); + goto fail2; + } + ranges->nb_ranges /= ranges->nb_components; + for (int n = 0; n < ranges->nb_components * ranges->nb_ranges; n++) { + int i = n / ranges->nb_components; + int j = n % ranges->nb_components; + new_range[ranges->nb_ranges * j + i] = old_range[n]; + } + ranges->range = new_range; + av_freep(&old_range); + } + + // success, set output + *ranges_arg = ranges; + +fail2: + // set dshow parameters/options back to original values + // audio + ctx->sample_size = backup_sample_size; + ctx->sample_rate = backup_sample_rate; + ctx->channels = backup_channels; + // video + ctx->video_codec_id = backup_video_codec_id; + ctx->pixel_format = backup_pixel_format; + ctx->requested_width = backup_requested_width; + ctx->requested_height = backup_requested_height; + if (ctx->framerate) + av_free(ctx->framerate); + ctx->framerate = backup_framerate; + + if (devenum) + ICreateDevEnum_Release(devenum); + +fail1: + if (ret < 0) + av_opt_freep_ranges(&ranges); + + return ret; +} + +// fake class to point av_opt_query_ranges to our query_ranges function +static const AVClass dshow_dev_caps_class = { + .class_name = "", + .item_name = av_default_item_name, + .option = ff_device_capabilities, + .version = LIBAVUTIL_VERSION_INT, + .query_ranges = dshow_query_ranges, +}; + +static int dshow_create_device_capabilities(struct AVFormatContext *avctx, AVDeviceCapabilitiesQuery *caps) +{ + struct dshow_ctx *ctx = avctx->priv_data; + int ret = 0; + ICreateDevEnum *devenum = NULL; + + // set class so queries work + caps->av_class = &dshow_dev_caps_class; + + if (ctx->device_name[0] || ctx->device_name[1]) { + av_log(avctx, AV_LOG_ERROR, "You cannot query device capabilities on an opened device\n"); + ret = AVERROR(EIO); + goto fail; + } + + if (!parse_device_name(avctx)) { + av_log(avctx, AV_LOG_ERROR, "You must set a device name (AVFormatContext url) to specify which device to query capabilities from\n"); + ret = AVERROR(EINVAL); + goto fail; + } + + CoInitialize(0); + if (CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, + &IID_ICreateDevEnum, (void **) &devenum)) { + av_log(avctx, AV_LOG_ERROR, "Could not enumerate system devices.\n"); + ret = AVERROR(EIO); + goto fail; + } + + // check devices can be found + if (ctx->device_name[VideoDevice]) { + IBaseFilter *device_filter = NULL; + char *device_unique_name = NULL; + if ((ret = dshow_cycle_devices(avctx, devenum, VideoDevice, VideoSourceDevice, &device_filter, &device_unique_name, NULL)) < 0) + return ret; + + if (ret >= 0) { + ctx->device_filter[VideoDevice] = device_filter; + ctx->device_unique_name[VideoDevice] = device_unique_name; + } + } + if (ctx->device_name[AudioDevice]) { + IBaseFilter *device_filter = NULL; + char *device_unique_name = NULL; + if (dshow_cycle_devices(avctx, devenum, AudioDevice, AudioSourceDevice, &device_filter, &device_unique_name, NULL) < 0) { + /* try to access audio from combined video+audio sources as fallback */ + if ((ret = dshow_cycle_devices(avctx, devenum, AudioDevice, VideoSourceDevice, &device_filter, &device_unique_name, NULL)) < 0) + goto fail; + } + if (ret >= 0) { + ctx->device_filter[AudioDevice] = device_filter; + ctx->device_unique_name[AudioDevice] = device_unique_name; + } + } + +fail: + if (devenum) + ICreateDevEnum_Release(devenum); + + if (ret < 0) + return ret; + else + return 0; +} + +static int dshow_free_device_capabilities(struct AVFormatContext *avctx, AVDeviceCapabilitiesQuery *caps) +{ + // clear state variables that may have been set during the querying process + // (e.g. frees device names, removes device_filters, etc) + dshow_read_close(avctx); + + return 0; +} + #define OFFSET(x) offsetof(struct dshow_ctx, x) #define DEC AV_OPT_FLAG_DECODING_PARAM static const AVOption options[] = { @@ -2059,6 +2449,8 @@ const AVInputFormat ff_dshow_demuxer = { .read_close = dshow_read_close, .get_device_list= dshow_get_device_list, .control_message= dshow_control_message, + .create_device_capabilities = dshow_create_device_capabilities, + .free_device_capabilities = dshow_free_device_capabilities, .flags = AVFMT_NOFILE | AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK, .priv_class = &dshow_class, }; diff --git a/libavdevice/version.h b/libavdevice/version.h index 764aceccb5..5f8f371bea 100644 --- a/libavdevice/version.h +++ b/libavdevice/version.h @@ -31,7 +31,7 @@ #include "version_major.h" #define LIBAVDEVICE_VERSION_MINOR 2 -#define LIBAVDEVICE_VERSION_MICRO 100 +#define LIBAVDEVICE_VERSION_MICRO 101 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \ LIBAVDEVICE_VERSION_MINOR, \ From patchwork Wed Mar 30 12:18:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 35071 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp774806pzb; Wed, 30 Mar 2022 05:21:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRlHjoUM+dqk1UXRIBzT/uZloSJXkWGRGVrn1VkEBlSY92iOSXw7iMY/lELG21OL3RDQTU X-Received: by 2002:a05:6402:3554:b0:419:402f:f632 with SMTP id f20-20020a056402355400b00419402ff632mr10054443edd.1.1648642887885; Wed, 30 Mar 2022 05:21:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648642887; cv=none; d=google.com; s=arc-20160816; b=bXuGBcHjgLx4kFi9Gl3xNPOvtuC4oM59ARQH9hBKJQbh114fSRavQg4jgNI+C+B7za xLr78bFhTiCuJCgfaw6gbPlwOpSSoNdOLezumdq64rVsdChenyJr5SNKyaOdo4KzNBkt GEo8fbrOYpDhmGhH8euU0uZMcIGdhZPXEyUAFk9eH+NQiLGcwBe5ufaly9CcojHQ/x3P ZGvUBIQAsBdly2fLbEJwXAw1BVITBUk0BcZaCErwaL1pwMNSvw6aUP4qidE4k3vutBQv lDxq53Ug7l3yUlCzEntJPowRU22qcDjH5ZmMpog5W5wYxeu7VCw5hL17kGSnyN5aBVWQ hz8A== 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=9q0K6xCH1EMWG9qZSqurzxouXJYIegfeqFJvhzIAUqY=; b=sejMuAAFE+gIiq/FThrOTTGEzjebrOAjfU+9KhqFd8QXp5RujQyJBKbc6EQBVv+3+u l7lN/53VV3j2Sg36L8T4u2hjVDYppnvKHaOLXAjZ+JhXtx4neN9ZYv6f2S3XSR+1QTwN zdETofFfkhwFTjCajEVQDX+oLHMCOJsLC94pdxAqjGXwJCqKtacHdgYmJfAnDv0F6s7+ FQYqsrjgTHupnoqXFdKQetbXFGH0YUgyjft/a19MHJmNo+SSlI2CTSsDsVzMqFL1RdKf EngNw/aDJFtWqdQjH4HJHfuQQwGPBUNE8fsnPGYduvTUQiR3wdcIcSzxv7JtlmG34H8i e5Jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=ho6A+SWX; 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 p23-20020a1709061b5700b006df76385ef3si21216625ejg.915.2022.03.30.05.21.27; Wed, 30 Mar 2022 05:21:27 -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=20210112 header.b=ho6A+SWX; 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 1C7DE68B2A9; Wed, 30 Mar 2022 15:20:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0D2D068B223 for ; Wed, 30 Mar 2022 15:20:12 +0300 (EEST) Received: by mail-lj1-f178.google.com with SMTP id h11so27409115ljb.2 for ; Wed, 30 Mar 2022 05:20:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ioa9BeZmT/y7hHfyDoKcG7T9Jmai5VFmSaZcjXM/uLY=; b=ho6A+SWXq11yKYfrYLiyQb71apg+QW8o858yPnTwmlamZ8Kcb7WqLRrjLsv7YQrejf sYoJmAQjkA174q1ay/mcKCIDVClveEBMzlh+O4QBbpbRbD9s9wc8DcJ1+zstWbwy6/Du YvzZHShJ9sGgbjm1SK7Mc1050DdVXr8/v/HAUfIF7/rWqmcSasHSpbUMZ1UYKujI/r8V ymp+geBTNDjj9iRnpXRfgTtNckqvUZ/xWYxyDMcRF0ipL/siSxKmT202pOAVX35X5XAY aOscvirXBIou0c4+Z8B+nIzxP5KdWOoTtFHfv4GvqIK1GyKa4BJTDR6Dd4vjc48uWitb lANQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ioa9BeZmT/y7hHfyDoKcG7T9Jmai5VFmSaZcjXM/uLY=; b=LFoat2WZOlge+fKvwgyGe21dKCwHVAA5TXhS2mTn2SBVBjXpYPjgPnVyZwiEaL5Igd u8ui7FVPFunSXZRslNvUYKQUG6djdPRgAhp0KDskOaSsI+eSu7UrYCJoUqnzRWE9/lEE Zn10I4bIdskFC/HnlVzUtqhTl05aXluD9cldVUiUMGfcueYk6x0GMNFZMyreaNlzj0Yw zFvFrpYfOJfIwPb67oMk5LYgCzNpK1ir0w04Npi4NDMfEqgLhpm+YxQODeTE5c2bbuaw vH2kDWG8kf29dq2EAM4hdXuoSY2Qiy4Y7WzoLfEWWTSVh5MJvUX3EGLhUlDVfnFBVdTP vyDw== X-Gm-Message-State: AOAM5312GxNQt88q/NtnzrpI7e+w1Yrc5iEcTPtd0nXtdFG+tdFhW0nM 3n2dT2kF+WNl47l0R+5FfCP1sZHxbr4= X-Received: by 2002:a2e:8851:0:b0:249:9504:d19e with SMTP id z17-20020a2e8851000000b002499504d19emr6275210ljj.153.1648642811868; Wed, 30 Mar 2022 05:20:11 -0700 (PDT) Received: from localhost.localdomain (deedock.humlab.lu.se. [130.235.135.183]) by smtp.gmail.com with ESMTPSA id h16-20020a19ca50000000b0044a25081cf9sm2313065lfj.133.2022.03.30.05.20.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 05:20:11 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Wed, 30 Mar 2022 14:18:02 +0200 Message-Id: <20220330121806.822-18-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20220330121806.822-1-dcnieho@gmail.com> References: <20220330121806.822-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 17/21] avdevice/dshow: cosmetics 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: /WZlBHAgJG6C Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 58476a0f40..3cae7d265e 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -933,6 +933,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, AVOptionRange *new_range[3] = { NULL }; int nb_range = 0; struct dshow_format_info *fmt_info = NULL; + r = IAMStreamConfig_GetStreamCaps(config, i, &type, (void *) caps); if (r != S_OK) goto next; @@ -1558,7 +1559,8 @@ dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum, goto error; } } - if (ctx->device_filter[otherDevType]) { + + if (ctx->device_filter[otherDevType]) { // avoid adding add two instances of the same device to the graph, one for video, one for audio // a few devices don't support this (could also do this check earlier to avoid double crossbars, etc. but they seem OK) if (strcmp(device_filter_unique_name, ctx->device_unique_name[otherDevType]) == 0) { @@ -2441,16 +2443,16 @@ static const AVClass dshow_class = { }; const AVInputFormat ff_dshow_demuxer = { - .name = "dshow", - .long_name = NULL_IF_CONFIG_SMALL("DirectShow capture"), - .priv_data_size = sizeof(struct dshow_ctx), - .read_header = dshow_read_header, - .read_packet = dshow_read_packet, - .read_close = dshow_read_close, - .get_device_list= dshow_get_device_list, - .control_message= dshow_control_message, + .name = "dshow", + .long_name = NULL_IF_CONFIG_SMALL("DirectShow capture"), + .priv_data_size = sizeof(struct dshow_ctx), + .read_header = dshow_read_header, + .read_packet = dshow_read_packet, + .read_close = dshow_read_close, + .get_device_list = dshow_get_device_list, + .control_message = dshow_control_message, .create_device_capabilities = dshow_create_device_capabilities, - .free_device_capabilities = dshow_free_device_capabilities, - .flags = AVFMT_NOFILE | AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK, - .priv_class = &dshow_class, + .free_device_capabilities = dshow_free_device_capabilities, + .flags = AVFMT_NOFILE | AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK, + .priv_class = &dshow_class, }; From patchwork Wed Mar 30 12:18:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 35072 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp774878pzb; Wed, 30 Mar 2022 05:21:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7jJtoJiuPJFPbxxbR/vq3y/IvgCGgAAzAV8RjGijJ716qCPy4Upize9q7h6YEJgfe1aaS X-Received: by 2002:a17:907:a089:b0:6df:ee65:1aa4 with SMTP id hu9-20020a170907a08900b006dfee651aa4mr40581036ejc.294.1648642897675; Wed, 30 Mar 2022 05:21:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648642897; cv=none; d=google.com; s=arc-20160816; b=pzVZPAeUMuL9+z6+Y3GVgBbfnepL0v1zrqPkxFbUlb6x+4dQq3Qp+EbRLRzf0WSG7M KrdytVB2l8xlLKcghHwnEIq7m6cKyjHJr5pjfd9p/Eg6J+671PzGzhYJgW/bNowA2lR3 EwW8BJshz1kHO+XZi2/nn4Nk740RvyRR7EuaL9zFKCg1b2DltQZbfyhRaNLaclutvpgl q6vI6/50bDGeiQ7b6uNiuV3j9fUtc12sgjc1IOSMm0fYHuLQimUm3ER9GGkNpX+7LmDn QmyaRJCs4zj/PhTxgAIIVx0lz7nuZJ9J5JS68L49jdGBBJMw2bJ1AUlDOh17FZyoIG2r 289A== 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=zMUNnKrNIG1z8jTbq6/AExdXnfW5LL+x/ZjjGaXwIUo=; b=aimKw1tF4bIWps6XdEgBPkS0Sp9LYdC+05e37bP+KcVv8J5jHX+H5VIn3D61FL4PSp Nn5GxX8DAP3u6/bwhTXLKKtuiRH4whR5Us4g8Q5aV++G/mC5ylgp19K7nXHTIarfh0pc qg+jWMmK04kirwPak5ov/gvEHWCZOWfX2HGMkKldj8raLDsm39EFwz2FXOo0BILxgdHH nr5tSlXqVSWvUJiHq0TlQOz3Sh5pHoqg91tE6b5x43lhpH2UX5pUqDv5zSGHO1dD5/Kh 7EdI7hJfDoYqf9sBVINxHnWEG0uDvucIK7vsk14Xs8vNpJq0WWMD0dbY68wtiPT/oI/m A1/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=d6WHtgSt; 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 s1-20020a056402036100b00419014273b3si15818687edw.354.2022.03.30.05.21.37; Wed, 30 Mar 2022 05:21:37 -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=20210112 header.b=d6WHtgSt; 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 2624D68B2AD; Wed, 30 Mar 2022 15:20:21 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BB32068B240 for ; Wed, 30 Mar 2022 15:20:19 +0300 (EEST) Received: by mail-lf1-f54.google.com with SMTP id z12so21687292lfu.10 for ; Wed, 30 Mar 2022 05:20:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CkpEGxcejScS9D4Hm7xVGgijLix5CJGbSatbgtgFHBc=; b=d6WHtgStD2t6oMCWCVK7raJuulLtU2vzL3Lrz42lsgH8rgkXSOp84x4qXhVbtjw5BS WsI6Bz1RKcnfL4KGAIxymxZmJPlYWNzhGWcCd4BoY+qfEoKLZ5dHLRh8yYqcht6Ka/WO text8Fs5rjgImXWWg87DBiWPsxKLpRnqyX4OApnXp6u29QWCTkXyo1kz0pcQjMb0E8f7 J6NuVFrxTR9+7N8BRrdZpZAPzurD3oQg9V4ViSr7VF5wEJV4CszgRun8PcePmmFADQHy F7jvQzvNakgizPPclOtjA2V2vEYl9XQVFBVdj43RvEH7txpt4opaw+E/9uij4po10UVo vzRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CkpEGxcejScS9D4Hm7xVGgijLix5CJGbSatbgtgFHBc=; b=DAW+MtfzPDMCH3V7MLzlaPDth5MV1njbftHDXwbn7lZXhLIP2KDcXzEubLuiYna8Te alp3Te4lddZGu/EMEMUxiWAGom152HH2rfjMw1e1fKO74nMcVFRJDc/j/tqY6TcMI33N XwX4IlmXcap8/1G0USFnTIZlSiZzZ7gcNw1+cMYN8yuYKZ/Dcb1FOUUSihYJIeyGybBY sTOrQZW5q5IvfIWbDSeCR+Ye4p12yqAg3thWv4GpRSpNO1F6UuQh26a1MykulL+aR1Uy UfObh4k6Snr9NgLrypelwURoGWYzSPQ6sIW+1ilvDkHPlO8Wn4KY0laeO5NuHYCvFe+V pzmg== X-Gm-Message-State: AOAM531f2F10zEWDMFdHoPGURvdwNjlOD6KWnUVftOuu5DFHn+8Wyl4L kDN6enqKlLVni6D8AFFb9BoI/IyUtlc= X-Received: by 2002:a05:6512:128e:b0:44a:4067:9ffe with SMTP id u14-20020a056512128e00b0044a40679ffemr6612210lfs.64.1648642818438; Wed, 30 Mar 2022 05:20:18 -0700 (PDT) Received: from localhost.localdomain (deedock.humlab.lu.se. [130.235.135.183]) by smtp.gmail.com with ESMTPSA id o19-20020a2e9b53000000b00249b8cbdd70sm1843569ljj.103.2022.03.30.05.20.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 05:20:17 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Wed, 30 Mar 2022 14:18:03 +0200 Message-Id: <20220330121806.822-19-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20220330121806.822-1-dcnieho@gmail.com> References: <20220330121806.822-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 18/21] avformat: add avformat_alloc_input_context() 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: SDxzoSm8HE9m avformat_alloc_input_context function analogous to avformat_alloc_output_context2, except that it does not take a filename argument as guessing the format by just the filename does not make sense. avformat_alloc_input_context can be used e.g. with the avdevice capabilities API, which needs an allocated input format with priv_data (and default options) set, but device should not be opened. Added some checks to avformat_open_input, for the case that a AVFormatContext* allocated by avformat_alloc_input_context is provided: 1. if avformat_open_input's AVInputFormat *fmt argument is not NULL, clean up any already set s->iformat 2. if s->url is already set and avformat_open_input's filename argument is not NULL, free current url and replace by provided filename 3. if s->url is already set and avformat_open_input's filename argument is NULL, do not set s->url to "", but keep current url 4. if s->priv_data has already been allocated, do not do so again. 4b. do reset options to default and apply provided options (if any) 5. add 4b to docs of avformat_open_input Bump libavformat version. Signed-off-by: Diederick Niehorster --- libavformat/avformat.h | 29 +++++++++++++++-- libavformat/demux.c | 74 ++++++++++++++++++++++++++++++++++++++---- libavformat/version.h | 2 +- 3 files changed, 95 insertions(+), 10 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 027a914e13..004d81640f 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -2024,6 +2024,26 @@ AVProgram *av_new_program(AVFormatContext *s, int id); * @} */ + /** + * Allocate an AVFormatContext for an input format. + * avformat_free_context() can be used to free the context and + * everything allocated by the framework within it. NB: in general + * the correct format cannot be known (unless the user has extra + * information) until the file is opened. If forcing a format by + * this method, but it turns out not to match the file's format + * upon avformat_open_input(), the latter will throw an error. + * + * @param *ctx is set to the created format context, or to NULL in + * case of failure + * @param iformat format to use for allocating the context, if NULL + * format_name is used instead + * @param format_name the name of input format to use for allocating the + * context + * @return >= 0 in case of success, a negative AVERROR code in case of + * failure + */ +int avformat_alloc_input_context(AVFormatContext **ctx, const AVInputFormat *iformat, + const char *format_name); /** * Allocate an AVFormatContext for an output format. @@ -2119,9 +2139,9 @@ int av_probe_input_buffer(AVIOContext *pb, const AVInputFormat **fmt, * Open an input stream and read the header. The codecs are not opened. * The stream must be closed with avformat_close_input(). * - * @param ps Pointer to user-supplied AVFormatContext (allocated by avformat_alloc_context). - * May be a pointer to NULL, in which case an AVFormatContext is allocated by this - * function and written into ps. + * @param ps Pointer to user-supplied AVFormatContext (allocated by avformat_alloc_context, or + * avformat_alloc_input_context). May be a pointer to NULL, in which case an + * AVFormatContext is allocated by this function and written into ps. * Note that a user-supplied AVFormatContext will be freed on failure. * @param url URL of the stream to open. * @param fmt If non-NULL, this parameter forces a specific input format. @@ -2129,6 +2149,9 @@ int av_probe_input_buffer(AVIOContext *pb, const AVInputFormat **fmt, * @param options A dictionary filled with AVFormatContext and demuxer-private options. * On return this parameter will be destroyed and replaced with a dict containing * options that were not found. May be NULL. + * Note that if a AVFormatContext allocated by avformat_alloc_input_context + * is provided, any demuxer-private options will be overwritten by their defaults + * before applying this new set of demuxer-private options, if any. * * @return 0 on success, a negative AVERROR on failure. * diff --git a/libavformat/demux.c b/libavformat/demux.c index ef189d9d8e..52442b2e55 100644 --- a/libavformat/demux.c +++ b/libavformat/demux.c @@ -217,6 +217,56 @@ FF_ENABLE_DEPRECATION_WARNINGS return 0; } + +int avformat_alloc_input_context(AVFormatContext** avctx, const AVInputFormat* iformat, + const char* format) +{ + AVFormatContext* s = avformat_alloc_context(); + int ret = 0; + + *avctx = NULL; + if (!s) + goto nomem; + + if (!iformat) { + if (format) { + iformat = av_find_input_format(format); + if (!iformat) { + av_log(s, AV_LOG_ERROR, "Requested input format '%s' not found\n", format); + ret = AVERROR(EINVAL); + goto error; + } + } + else { + av_log(s, AV_LOG_ERROR, "You should provide an input format or the name of an input format when calling this function\n"); + ret = AVERROR(EINVAL); + goto error; + } + } + + s->iformat = iformat; + if (s->iformat->priv_data_size > 0) { + s->priv_data = av_mallocz(s->iformat->priv_data_size); + if (!s->priv_data) + goto nomem; + if (s->iformat->priv_class) { + *(const AVClass**)s->priv_data = s->iformat->priv_class; + av_opt_set_defaults(s->priv_data); + } + } + else + s->priv_data = NULL; + + *avctx = s; + return 0; +nomem: + av_log(s, AV_LOG_ERROR, "Out of memory\n"); + ret = AVERROR(ENOMEM); +error: + avformat_free_context(s); + return ret; +} + int avformat_open_input(AVFormatContext **ps, const char *filename, const AVInputFormat *fmt, AVDictionary **options) { @@ -233,8 +283,14 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, av_log(NULL, AV_LOG_ERROR, "Input context has not been properly allocated by avformat_alloc_context() and is not NULL either\n"); return AVERROR(EINVAL); } - if (fmt) + if (fmt) { + if (s->iformat) { + if (s->iformat->priv_class && s->priv_data) + av_opt_free(s->priv_data); + av_freep(&s->priv_data); + } s->iformat = fmt; + } if (options) av_dict_copy(&tmp, *options, 0); @@ -245,7 +301,9 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, if ((ret = av_opt_set_dict(s, &tmp)) < 0) goto fail; - if (!(s->url = av_strdup(filename ? filename : ""))) { + if (filename && s->url) + av_freep(&s->url); + if (!s->url && !(s->url = av_strdup(filename ? filename : ""))) { ret = AVERROR(ENOMEM); goto fail; } @@ -288,12 +346,16 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, s->duration = s->start_time = AV_NOPTS_VALUE; - /* Allocate private data. */ + /* Allocate private data and set options. */ if (s->iformat->priv_data_size > 0) { - if (!(s->priv_data = av_mallocz(s->iformat->priv_data_size))) { - ret = AVERROR(ENOMEM); - goto fail; + /* allocate if not already allocated */ + if (!s->priv_data) { + if (!(s->priv_data = av_mallocz(s->iformat->priv_data_size))) { + ret = AVERROR(ENOMEM); + goto fail; + } } + /* Overwrite any options already set (1: back to defaults, 2: apply options, if any) */ if (s->iformat->priv_class) { *(const AVClass **) s->priv_data = s->iformat->priv_class; av_opt_set_defaults(s->priv_data); diff --git a/libavformat/version.h b/libavformat/version.h index 88d6f750a2..4a7d2f441c 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -32,7 +32,7 @@ #include "version_major.h" -#define LIBAVFORMAT_VERSION_MINOR 23 +#define LIBAVFORMAT_VERSION_MINOR 24 #define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ From patchwork Wed Mar 30 12:18:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 35073 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp774948pzb; Wed, 30 Mar 2022 05:21:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7OdXBNGM4YfAFzKAIQxuHzcXMEbWov4UoBMYig5Q5CLyUZLPucUc+YiXVE/dq9seDd8yb X-Received: by 2002:aa7:c759:0:b0:419:896:271b with SMTP id c25-20020aa7c759000000b004190896271bmr10194783eds.98.1648642907292; Wed, 30 Mar 2022 05:21:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648642907; cv=none; d=google.com; s=arc-20160816; b=pjMpJxX/oeHqQNm6p+FRvefX0zAbt3Z6TDr48XOYbl7b2t8wWB7ZLK/vbHOZP2uN7+ Rb2N1bE0K8rBT82VOdiAY/dSNXfLf/PdEAwCIY3wPjCyff74StCWC+32BstbcyEKFyEa R0cDGO5gdQS9NbK1pR1g06uXLHIIWlQ1KleO/cr/gyAt00qGx5h8+jVSybYoZsAbwQdv wzhXMcDhKFDct4bQf31ERk5i03spk3mQsvj5Uj8f+8Tu1MSGNZFp8F+ATRUJXY9lAUW0 VctNYlV/MiTMWXnj76rEnpDdhBrsgj388CQYNRTTRibcRGxWvZVP+QER0IYfH/YB6G3K a3vw== 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=dNv3vsHS6Oav+cR5WaqweaFBwvvmKr6e9gBCMaIUXuI=; b=dLwhPSkrdnMLOc6plKCxunERH10nSijkq7AuAMg+GLdLeiz66EMA7hnHvgKEqvMvt7 aEeRRt1QNIXloZvOrfTZlHdn7YUBxMHu9aARGeIqVYS3n1eQ1uwpxNeqrJUPMPL0a+6K xFpcv8l1QXm8l4vy6Z05XyMFoqJ4mGptBNY2tfD3/5VmvawfuIy5cq1ZDn5p/ed5FpVF OlNOh2TqBSnINFeUibAYvYJnO0U/ub0KdgFu8XcO5sBWSc34Yk1Is1JndL9+jtsFyn/O NcyRs8KmtBKvWdSYGMXhR4oXjqktvZKV3lNXL907TbJVEMkKAeHpv2Az2IAnf+h2Y6ri O1ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=fdHh12EX; 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 c1-20020a170906924100b006df76385e5bsi19482054ejx.763.2022.03.30.05.21.46; Wed, 30 Mar 2022 05:21:47 -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=20210112 header.b=fdHh12EX; 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 404DF68B21A; Wed, 30 Mar 2022 15:20:28 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EFFC468B1E2 for ; Wed, 30 Mar 2022 15:20:25 +0300 (EEST) Received: by mail-lj1-f182.google.com with SMTP id c15so27391757ljr.9 for ; Wed, 30 Mar 2022 05:20:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ruk9BoVt3V2PXiF0fWjSKbmWOBG+NGE61kG4/Yh7IXg=; b=fdHh12EXUzFr7d7P+Wn04sK2thSyUnr4RJKFU0GrXkvJ/kq9Xre1iHKS2XhKQkYQtI 6pvxg49fZZsqOYVdf/NWmOTmMKoJzktG17zJRl/WlAH2KnOToNKk+DI0p4uw7elCn2A3 QPYawTHnKxIhQFiWPNmRKBiqRF/RaWFP/S84HbbTkK/GzzfgUK5JU+/2fOk+08nWaxyN ecllBymPDFgcyDiS2PPssAq924pm5MbJDq/VcydeR0c+6HYHAm1spI2zw55n4kOVp7rB RKTrVmpbJABG6V/TUUv77/ijSvjck40xIZm/RQkJjKLASxmxkM82mXuF+tt+kUjo45Nw bL9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ruk9BoVt3V2PXiF0fWjSKbmWOBG+NGE61kG4/Yh7IXg=; b=XaeRTkxWOLOkftphSTl9quYfIKkkbeuVS6aYPMjotf+15ckqMqXKNpjR07EZthMLUU RwyqGbTxTsGMtJeDOagNITnZmYe6PlqYVHvOgx8ibnDZa8VB5Cm+KqLy2p+ov17nqWFd 5bX38SldE70yeMFdMvuNy4R7XxM1y++Kxp9vGIe+BI9vU5b4lq/GEYYgOFVD5nWLWm3d sw7Y+psNCzdn7bNUTYmomR/r8ZZCpEYO9sDPuoanVzLYGvMlAvXmtwS6xvTDsWk91Vcx vEXVpQWec6kSNPKo0IIV8isCLKMdMeEIo8AmvjqavDdoIwOcWabxJlpuJstmkiK9bo5E dD4Q== X-Gm-Message-State: AOAM531BjhqGN0JPh5WYvtIhkW8YSdH5KaVWp7IIwwVvsutISiBZmb4r ds35Hz95VVwAf6v3l1jW5GeD/W2U2JU= X-Received: by 2002:a2e:a0c3:0:b0:247:eba1:366b with SMTP id f3-20020a2ea0c3000000b00247eba1366bmr6198787ljm.190.1648642824951; Wed, 30 Mar 2022 05:20:24 -0700 (PDT) Received: from localhost.localdomain (deedock.humlab.lu.se. [130.235.135.183]) by smtp.gmail.com with ESMTPSA id i8-20020a0565123e0800b0044a74e0954dsm1804515lfv.66.2022.03.30.05.20.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 05:20:24 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Wed, 30 Mar 2022 14:18:04 +0200 Message-Id: <20220330121806.822-20-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20220330121806.822-1-dcnieho@gmail.com> References: <20220330121806.822-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 19/21] doc/examples: adding device_get_capabilities example 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: uRSknAy9m2Ok This example also shows use of get_device_list API. Also improve capability API doc in avdevice.h: now point to this example instead of rough example code given in the header. Signed-off-by: Diederick Niehorster --- configure | 2 + doc/examples/.gitignore | 1 + doc/examples/Makefile | 1 + doc/examples/Makefile.example | 1 + doc/examples/device_get_capabilities.c | 243 +++++++++++++++++++++++++ libavdevice/avdevice.h | 33 +--- 6 files changed, 249 insertions(+), 32 deletions(-) create mode 100644 doc/examples/device_get_capabilities.c diff --git a/configure b/configure index e4d36aa639..be78a2119e 100755 --- a/configure +++ b/configure @@ -1726,6 +1726,7 @@ EXAMPLE_LIST=" decode_audio_example decode_video_example demuxing_decoding_example + device_get_capabilities_example encode_audio_example encode_video_example extract_mvs_example @@ -3751,6 +3752,7 @@ avio_reading_deps="avformat avcodec avutil" decode_audio_example_deps="avcodec avutil" decode_video_example_deps="avcodec avutil" demuxing_decoding_example_deps="avcodec avformat avutil" +device_get_capabilities_example_deps="avdevice avformat avutil" encode_audio_example_deps="avcodec avutil" encode_video_example_deps="avcodec avutil" extract_mvs_example_deps="avcodec avformat avutil" diff --git a/doc/examples/.gitignore b/doc/examples/.gitignore index 44960e1de7..256f33a600 100644 --- a/doc/examples/.gitignore +++ b/doc/examples/.gitignore @@ -3,6 +3,7 @@ /decode_audio /decode_video /demuxing_decoding +/device_get_capabilities /encode_audio /encode_video /extract_mvs diff --git a/doc/examples/Makefile b/doc/examples/Makefile index 81bfd34d5d..de707bb3ca 100644 --- a/doc/examples/Makefile +++ b/doc/examples/Makefile @@ -3,6 +3,7 @@ EXAMPLES-$(CONFIG_AVIO_READING_EXAMPLE) += avio_reading EXAMPLES-$(CONFIG_DECODE_AUDIO_EXAMPLE) += decode_audio EXAMPLES-$(CONFIG_DECODE_VIDEO_EXAMPLE) += decode_video EXAMPLES-$(CONFIG_DEMUXING_DECODING_EXAMPLE) += demuxing_decoding +EXAMPLES-$(CONFIG_DEVICE_GET_CAPABILITIES_EXAMPLE) += device_get_capabilities EXAMPLES-$(CONFIG_ENCODE_AUDIO_EXAMPLE) += encode_audio EXAMPLES-$(CONFIG_ENCODE_VIDEO_EXAMPLE) += encode_video EXAMPLES-$(CONFIG_EXTRACT_MVS_EXAMPLE) += extract_mvs diff --git a/doc/examples/Makefile.example b/doc/examples/Makefile.example index a232d97f98..b861b9cc74 100644 --- a/doc/examples/Makefile.example +++ b/doc/examples/Makefile.example @@ -16,6 +16,7 @@ EXAMPLES= avio_list_dir \ decode_audio \ decode_video \ demuxing_decoding \ + device_get_capabilities \ encode_audio \ encode_video \ extract_mvs \ diff --git a/doc/examples/device_get_capabilities.c b/doc/examples/device_get_capabilities.c new file mode 100644 index 0000000000..1cfbca64eb --- /dev/null +++ b/doc/examples/device_get_capabilities.c @@ -0,0 +1,243 @@ +/* + * Copyright (c) 2021 Diederick Niehorster + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/** + * @file + * avdevice getting capabilities example. + * + * Shows how to use the avdevice capabilities API to probe + * device capabilities (supported codecs, pixel formats, sample + * formats, resolutions, channel counts, etc) + * @example device_get_capabilities.c + */ + +#include +#include +#include +#include +#include + +static int print_option_ranges(enum AVOptionType type, AVOptionRanges *ranges) +{ + for (int range_index = 0; range_index < ranges->nb_ranges; range_index++) { + int ret; + char *out_val = NULL; + AVBPrint bp; + av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED); + for (int component_index = 0; component_index < ranges->nb_components; component_index++) + { + AVOptionRange* range = ranges->range[ranges->nb_ranges * component_index + range_index]; + if (component_index > 0) + av_bprintf(&bp, ", "); + av_bprintf(&bp, "%s: ", range->str); + if (range->value_min > range->value_max) + av_bprintf(&bp, ""); + else { + avdevice_capabilities_bprint_num(&bp, range->str, range->value_min); + if (range->is_range) { + av_bprintf(&bp, " -- "); + avdevice_capabilities_bprint_num(&bp, range->str, range->value_max); + } + } + } + if (!av_bprint_is_complete(&bp)) + return AVERROR(ENOMEM); + if ((ret = av_bprint_finalize(&bp, &out_val)) < 0) + return ret; + printf("%s\n", out_val); + av_freep(&out_val); + } + + return 0; +} + +static void list_queries(void) +{ + const AVOption *opt = NULL; + const AVClass *class = avdevice_capabilities_get_class(); + while (opt = av_opt_next(&class, opt)) + fprintf(stderr, " %s\n", opt->name); +} + +static void list_device_sources(const AVInputFormat *fmt) +{ + int ret; + AVDeviceInfoList *device_list = NULL; + + if (!fmt || !fmt->priv_class || !AV_IS_INPUT_DEVICE(fmt->priv_class->category)) + return; + + if (!fmt->get_device_list) { + ret = AVERROR(ENOSYS); + fprintf(stderr, " Cannot list sources. Not implemented.\n"); + return; + } + + if ((ret = avdevice_list_input_sources(fmt, NULL, NULL, &device_list)) < 0) { + fprintf(stderr, " Cannot list sources.\n"); + return; + } + + for (int i = 0; i < device_list->nb_devices; i++) { + const AVDeviceInfo *device = device_list->devices[i]; + fprintf(stderr, " %s %s (", device_list->default_device == i ? "*" : " ", device->device_name); + if (device->nb_media_types > 0 && device->media_types) { + for (int j = 0; j < device->nb_media_types; ++j) { + const char* media_type = av_get_media_type_string(device->media_types[j]); + if (j > 0) + fprintf(stderr, ", "); + fprintf(stderr, "%s", media_type ? media_type : "unknown"); + } + } + else { + fprintf(stderr, "none"); + } + fprintf(stderr, ")\n"); + } + + avdevice_free_list_devices(&device_list); +} + + + +int main (int argc, char **argv) +{ + int ret = 0; + const char *device_name = NULL; + const char *input_name = NULL; + const char *query_cap = NULL; + const char *set_cap_name = NULL; + const char *set_cap_value = NULL; + + const AVInputFormat *fmt = NULL; + AVFormatContext *fmt_ctx = NULL; + AVDeviceCapabilitiesQuery *caps = NULL; + AVOptionRanges *ranges = NULL; + const AVOption *opt = NULL; + + if (argc != 6) { + fprintf(stderr, "usage: %s device_name input_name query_cap set_cap_name set_cap_value\n" + "API example program to show how to use the avdevice\n" + "capabilities API to probe device capabilities \n" + "(supported codecs, pixel formats, sample formats,\n" + "resolutions, channel counts, etc).\n\n" + "example invocation: " + "%s dshow video=\"Integrated Webcam\" frame_size pixel_format yuyv422", + argv[0], argv[0]); + exit(1); + } + device_name = argv[1]; + input_name = argv[2]; + query_cap = argv[3]; + set_cap_name = argv[4]; + set_cap_value = argv[5]; + + // make sure avdevices can be found among input and output formats + avdevice_register_all(); + // find specified device + fmt = av_find_input_format(device_name); + if (!fmt) { + fprintf(stderr, "Could not find the device '%s'\n",device_name); + ret = AVERROR(EINVAL); + goto end; + } + + // prepare device format context, and set device to query, + ret = avformat_alloc_input_context(&fmt_ctx, fmt, NULL); + if (ret < 0) { + fprintf(stderr, "Cannot allocate input format context\n"); + goto end; + } + fmt_ctx->url = av_strdup(input_name); + + // prepare query object, setting device options + ret = avdevice_capabilities_create(&caps, fmt_ctx, NULL); + if (ret < 0) { + fprintf(stderr, "avdevice_capabilities_create() failed. Possibly the input name you specified ('%s') is not available for this device ('%s').\n%s can access the following sources:\n", input_name, device_name, device_name); + list_device_sources(fmt); + goto end; + } + + // check capability to query, and get info about the return type + opt = av_opt_find(caps, query_cap, NULL, 0, 0); + if (!opt) { + fprintf(stderr, "Capability '%s' you wish to query is not available.\nYou can query the following capabilities:\n", query_cap); + list_queries(); + ret = AVERROR_OPTION_NOT_FOUND; + goto end; + } + + // query the capability without any filter set + ret = av_opt_query_ranges(&ranges, caps, opt->name, AV_OPT_MULTI_COMPONENT_RANGE); + if (ret < 0) { + fprintf(stderr, "av_opt_query_ranges() failed\n"); + goto end; + } + + // print results + ret = print_option_ranges(opt->type, ranges); + if (ret < 0) { + fprintf(stderr, "printing the AVOptionRanges failed\n"); + goto end; + } + av_opt_freep_ranges(&ranges); + + printf("=============\n"); + + // set one capability, which may filter out some returned capabilities + // (or all, if set to an invalid value) + ret = av_opt_set(caps, set_cap_name, set_cap_value, 0); + if (ret < 0) { + fprintf(stderr, "av_opt_set() failed when trying to set the capability '%s'. Possibly it is not available.\nYou can set the following capabilities:\n", set_cap_name); + list_queries(); + goto end; + } + + // query again + ret = av_opt_query_ranges(&ranges, caps, opt->name, AV_OPT_MULTI_COMPONENT_RANGE); + if (ret < 0) { + fprintf(stderr, "av_opt_query_ranges() failed\n"); + goto end; + } + + // print results + print_option_ranges(opt->type, ranges); + + +end: + if (ranges) + av_opt_freep_ranges(&ranges); + if (caps) + avdevice_capabilities_free(&caps, fmt_ctx); + + if (fmt_ctx) + avformat_free_context(fmt_ctx); + + if (ret < 0) { + char a[AV_ERROR_MAX_STRING_SIZE] = { 0 }; + av_make_error_string(a, AV_ERROR_MAX_STRING_SIZE, ret); + + printf("Error: %s\n", a); + } + + return ret < 0; +} diff --git a/libavdevice/avdevice.h b/libavdevice/avdevice.h index 5f9dfccc34..c29d8940a5 100644 --- a/libavdevice/avdevice.h +++ b/libavdevice/avdevice.h @@ -384,38 +384,7 @@ int avdevice_dev_to_app_control_message(struct AVFormatContext *s, * For example, setting a codec may impact number of formats or fps values * returned during next query. Setting invalid value may limit results to zero. * - * Example of the usage basing on opengl output device: - * - * @code - * AVFormatContext *oc = NULL; - * AVDeviceCapabilitiesQuery *caps = NULL; - * AVOptionRanges *ranges; - * int ret; - * - * if ((ret = avformat_alloc_output_context2(&oc, NULL, "opengl", NULL)) < 0) - * goto fail; - * if (avdevice_capabilities_create(&caps, oc, NULL) < 0) - * goto fail; - * - * //query codecs - * if (av_opt_query_ranges(&ranges, caps, "codec", AV_OPT_MULTI_COMPONENT_RANGE)) < 0) - * goto fail; - * //pick codec here and set it - * av_opt_set(caps, "codec", AV_CODEC_ID_RAWVIDEO, 0); - * - * //query format - * if (av_opt_query_ranges(&ranges, caps, "pixel_format", AV_OPT_MULTI_COMPONENT_RANGE)) < 0) - * goto fail; - * //pick format here and set it - * av_opt_set(caps, "pixel_format", AV_PIX_FMT_YUV420P, 0); - * - * //query and set more capabilities - * - * fail: - * //clean up code - * avdevice_capabilities_free(&query, oc); - * avformat_free_context(oc); - * @endcode + * @see examples/device_get_capabilities.c */ typedef struct AVDeviceCapabilitiesQuery AVDeviceCapabilitiesQuery; From patchwork Wed Mar 30 12:18:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 35074 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp775018pzb; Wed, 30 Mar 2022 05:21:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqZRG60YizQ5Fxp0q/VgapQEihlpIdLToyBTnjLyNyvvv/bMUUdj7BdEMV5/6416DQWhBR X-Received: by 2002:a50:ab16:0:b0:414:39b0:7fc1 with SMTP id s22-20020a50ab16000000b0041439b07fc1mr10133651edc.214.1648642917401; Wed, 30 Mar 2022 05:21:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648642917; cv=none; d=google.com; s=arc-20160816; b=ojBhPJo4PDkv2eBCDY6VoDq1ga333vynIUr+yGycZuG89O2Mk0v+Rcqe9QMtejoUEi v3WqtsKEO33MgY1gTWkbncmwQcCqVXav/5qV3CF3p01GxwCKEJVF6Rjo1gA5NNsqnqtO Q6tPTIGnFu2lS3oaIOZ/44fI1Aj0apxnzxcrzYDywjm57NGZxYylGEAGNOctHFi7+w8C n71iY4ZOtI1t+HHXTvDnagEKxhvh9lp55JJs3T/fYrjHAhYjQ/B4hySnHP1vt7KWRPC/ haTHKV6wj/8dtm1coNebTDK5LxhOMI3xTCcmUXFbOiiFAFCXwBU+HBBdoVUpGODqFU/B zpfA== 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=IrDst6eY/FmevbXjerxXr42ZZQbWVKkW3PHdSFdvq54=; b=SInyKXWIv8NR2l4PGf+VvoFd6EGNHggzt2LhVyFSGSpXUlQoJWo3z4GbLMjzmLwkCf Ffc58RRpuGhmalWXVaQyKjT33kcw1/H8fkHh3AaXIKeyDaY2WJomXLWO/amSQAEHF9b/ tQJ4Obos7YjSTnLY2NIq6DhpKS4u8dQrqRJxaYhgTml6t/8zExMFH/4//oCLINujSBI0 t3Kv/C4u7kdcezU/x/2MUIkF54cQI1hwP9z3+n3OWanVZk+6TfmTtZMpTlBhZr9aingP KFLk80Sjfvq0LvO34yjuTl03n3DoBgijrIVrb3tZBmCqvfXaheuq/feM/ZIXQYjBiS+h szUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=PXL8MI8K; 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 i5-20020a170906850500b006dffb2d6bdcsi20493817ejx.83.2022.03.30.05.21.56; Wed, 30 Mar 2022 05:21:57 -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=20210112 header.b=PXL8MI8K; 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 D10AF68B2BB; Wed, 30 Mar 2022 15:20:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7C62568B24C for ; Wed, 30 Mar 2022 15:20:32 +0300 (EEST) Received: by mail-lf1-f41.google.com with SMTP id bu29so35587503lfb.0 for ; Wed, 30 Mar 2022 05:20:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qRgAhwEaIAPRZtmx9B1/sp/bKAQK+XSNSi8QFTYYZ28=; b=PXL8MI8KCpsmGf0/NZq1iudjLy2RZPTEXXT+Jzegjem8uRZkpDNrCQzwHWN3tLAqcT rtxQLyVXC4l8/VK0w4FuHuKSp+ctjw7RzZuJh+zIMQ+goZl3OK07R7dBNqQ4gZg06IUh fXk9RlBZ/YWWXVUJY/6vv4PqRVSKctMtJjatu0Og0OCKtN/JitQylUpW+6ncnsAsHwrH es+Jf9t3Ttl2TyZ+981RpBeFlYQbasBPYI1/KZB9YohuHh3xEKHqXfBPgICT+kx+6JqO KE3wykMwiraILN0FPAPHXMvMcdF3cILb5cpQPwMdW3CwCWU10FY7YQdcsv5dSfDjHbrw hRaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qRgAhwEaIAPRZtmx9B1/sp/bKAQK+XSNSi8QFTYYZ28=; b=7/r7y+wVrIx3UDzgFtxpPuucC42GY8vWPxLsXmZCSVrHWwpoHrmAAwFvisZl373Syv TAvlxaKdTnm+v0g95Ho3RMf6TCZGUVQKSDrKWmRbvNMnHvQbNhDpjpGIyZyL/3Z6+Zkc RFCeboXuDH0C64ZXA84AM9xXGRBV1NfrhrfDuhtky9AyMYd1tEFRD+KC5m1KAveYFHa4 JcS18kyv/SCa1s356YZb3py2SVcXmGYb5KU8l/RcWtK/xLZBNxKHmrAzeczPTlQ8nalr ZjePsEyl9ZwlpyVxOoKlEcRAWLd2aaMG4SeBr1XrGMqrW8lwxrIKMe8PHArmNI70PZVU P/2w== X-Gm-Message-State: AOAM532rex1Fw8hyO6nGHjo9+cObWaxE5TPmNkoe+I9QGOe9rhjfKsQ5 +Hhr+ghHqF3RxUfmGjSWTxLKtmo6UT4= X-Received: by 2002:a05:6512:150f:b0:448:244c:e96e with SMTP id bq15-20020a056512150f00b00448244ce96emr6496597lfb.653.1648642831315; Wed, 30 Mar 2022 05:20:31 -0700 (PDT) Received: from localhost.localdomain (deedock.humlab.lu.se. [130.235.135.183]) by smtp.gmail.com with ESMTPSA id q17-20020a2e8751000000b00244beaacef1sm2378488ljj.18.2022.03.30.05.20.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 05:20:30 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Wed, 30 Mar 2022 14:18:05 +0200 Message-Id: <20220330121806.822-21-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20220330121806.822-1-dcnieho@gmail.com> References: <20220330121806.822-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 20/21] Makefile/examples: cosmetics 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: jGTP7vF7Lzwr Signed-off-by: Diederick Niehorster --- doc/examples/Makefile | 48 +++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/doc/examples/Makefile b/doc/examples/Makefile index de707bb3ca..7988ed4226 100644 --- a/doc/examples/Makefile +++ b/doc/examples/Makefile @@ -1,27 +1,27 @@ -EXAMPLES-$(CONFIG_AVIO_LIST_DIR_EXAMPLE) += avio_list_dir -EXAMPLES-$(CONFIG_AVIO_READING_EXAMPLE) += avio_reading -EXAMPLES-$(CONFIG_DECODE_AUDIO_EXAMPLE) += decode_audio -EXAMPLES-$(CONFIG_DECODE_VIDEO_EXAMPLE) += decode_video -EXAMPLES-$(CONFIG_DEMUXING_DECODING_EXAMPLE) += demuxing_decoding -EXAMPLES-$(CONFIG_DEVICE_GET_CAPABILITIES_EXAMPLE) += device_get_capabilities -EXAMPLES-$(CONFIG_ENCODE_AUDIO_EXAMPLE) += encode_audio -EXAMPLES-$(CONFIG_ENCODE_VIDEO_EXAMPLE) += encode_video -EXAMPLES-$(CONFIG_EXTRACT_MVS_EXAMPLE) += extract_mvs -EXAMPLES-$(CONFIG_FILTER_AUDIO_EXAMPLE) += filter_audio -EXAMPLES-$(CONFIG_FILTERING_AUDIO_EXAMPLE) += filtering_audio -EXAMPLES-$(CONFIG_FILTERING_VIDEO_EXAMPLE) += filtering_video -EXAMPLES-$(CONFIG_HTTP_MULTICLIENT_EXAMPLE) += http_multiclient -EXAMPLES-$(CONFIG_HW_DECODE_EXAMPLE) += hw_decode -EXAMPLES-$(CONFIG_METADATA_EXAMPLE) += metadata -EXAMPLES-$(CONFIG_MUXING_EXAMPLE) += muxing -EXAMPLES-$(CONFIG_QSVDEC_EXAMPLE) += qsvdec -EXAMPLES-$(CONFIG_REMUXING_EXAMPLE) += remuxing -EXAMPLES-$(CONFIG_RESAMPLING_AUDIO_EXAMPLE) += resampling_audio -EXAMPLES-$(CONFIG_SCALING_VIDEO_EXAMPLE) += scaling_video -EXAMPLES-$(CONFIG_TRANSCODE_AAC_EXAMPLE) += transcode_aac -EXAMPLES-$(CONFIG_TRANSCODING_EXAMPLE) += transcoding -EXAMPLES-$(CONFIG_VAAPI_ENCODE_EXAMPLE) += vaapi_encode -EXAMPLES-$(CONFIG_VAAPI_TRANSCODE_EXAMPLE) += vaapi_transcode +EXAMPLES-$(CONFIG_AVIO_LIST_DIR_EXAMPLE) += avio_list_dir +EXAMPLES-$(CONFIG_AVIO_READING_EXAMPLE) += avio_reading +EXAMPLES-$(CONFIG_DECODE_AUDIO_EXAMPLE) += decode_audio +EXAMPLES-$(CONFIG_DECODE_VIDEO_EXAMPLE) += decode_video +EXAMPLES-$(CONFIG_DEMUXING_DECODING_EXAMPLE) += demuxing_decoding +EXAMPLES-$(CONFIG_DEVICE_GET_CAPABILITIES_EXAMPLE) += device_get_capabilities +EXAMPLES-$(CONFIG_ENCODE_AUDIO_EXAMPLE) += encode_audio +EXAMPLES-$(CONFIG_ENCODE_VIDEO_EXAMPLE) += encode_video +EXAMPLES-$(CONFIG_EXTRACT_MVS_EXAMPLE) += extract_mvs +EXAMPLES-$(CONFIG_FILTER_AUDIO_EXAMPLE) += filter_audio +EXAMPLES-$(CONFIG_FILTERING_AUDIO_EXAMPLE) += filtering_audio +EXAMPLES-$(CONFIG_FILTERING_VIDEO_EXAMPLE) += filtering_video +EXAMPLES-$(CONFIG_HTTP_MULTICLIENT_EXAMPLE) += http_multiclient +EXAMPLES-$(CONFIG_HW_DECODE_EXAMPLE) += hw_decode +EXAMPLES-$(CONFIG_METADATA_EXAMPLE) += metadata +EXAMPLES-$(CONFIG_MUXING_EXAMPLE) += muxing +EXAMPLES-$(CONFIG_QSVDEC_EXAMPLE) += qsvdec +EXAMPLES-$(CONFIG_REMUXING_EXAMPLE) += remuxing +EXAMPLES-$(CONFIG_RESAMPLING_AUDIO_EXAMPLE) += resampling_audio +EXAMPLES-$(CONFIG_SCALING_VIDEO_EXAMPLE) += scaling_video +EXAMPLES-$(CONFIG_TRANSCODE_AAC_EXAMPLE) += transcode_aac +EXAMPLES-$(CONFIG_TRANSCODING_EXAMPLE) += transcoding +EXAMPLES-$(CONFIG_VAAPI_ENCODE_EXAMPLE) += vaapi_encode +EXAMPLES-$(CONFIG_VAAPI_TRANSCODE_EXAMPLE) += vaapi_transcode EXAMPLES := $(EXAMPLES-yes:%=doc/examples/%$(PROGSSUF)$(EXESUF)) EXAMPLES_G := $(EXAMPLES-yes:%=doc/examples/%$(PROGSSUF)_g$(EXESUF)) From patchwork Wed Mar 30 12:18:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 35075 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp775082pzb; Wed, 30 Mar 2022 05:22:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBJwxC5+tUTUgb5DE0cq6nBQ+oZULU+LHKYP+a4wU39Hhrlfc3Szd3aXEhHkHTT3Z+JABB X-Received: by 2002:a17:906:58d2:b0:6da:b635:fbf3 with SMTP id e18-20020a17090658d200b006dab635fbf3mr38642187ejs.40.1648642925731; Wed, 30 Mar 2022 05:22:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648642925; cv=none; d=google.com; s=arc-20160816; b=vj6ZoNX789XmLMQkH+Mlz9hr+XQQSTS+P8sFST755kuX4CVWJnUnYBAt1/IGM7YuY8 yURpFu6ffHZ5oVFZ0yTru9wWgdwOBmxfVooYrRKMHShxL4b8CTa0sZZ5AHUgCFkd9DPR 2BEKgJ1Z6ny/z0b8di93qQmD4TvfiG7WjOnL/KHaeI0fpbt8JSYaFJaSE0CtbJp74TSf HYbPnoMz9smcsZkv1AyomIhWLF6PijpbM0Yum18Dpdw8H+kW21J/sqxMyIVPo00BNToE LfqpWM38YB1Dq3evAX6wVu5xxgjWKuPFeo/5KIhQqNozUC0iL7GVhPkzw7qMYiBbETy5 tmNw== 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=AaJnY39oP3AkeCTAKkoV1wcqehCaeIsYJMEPtnbpqDg=; b=ABE3wa6jdBnAzNcWU+ptzOmBZyBMYIlIYNbW308giLLvTdWSUnpvd40w678KihPy8d XzhxQgyDHH4/5Op/HLQhoFc5ePiSiHLJHlUDo0A1Q0qOAD1CJAUdIgv0JnTc+lITVKx7 yNa2CvFY2cyeMgJTsuEF9TBjRRUaAEa6yb/oHWO8dt0qYS8gAqHEJtoH7SGTlIao9XxL FLYCYzcmaCBqxcL38UTf8Sdncteiglta8nU+m81dCSKEMIBrvHDK+Geb/jlUqyTnipdz b1hHO0G7tC4VeReKf9Qh+/tVb7nlwEktH7P1zQqZfMRS02O2wu8h4THuYe0BiQq+b5Gp 12EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=AMQSzhmi; 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 e20-20020a17090658d400b006df91581f50si26420845ejs.983.2022.03.30.05.22.05; Wed, 30 Mar 2022 05:22:05 -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=20210112 header.b=AMQSzhmi; 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 A2CF468B2BD; Wed, 30 Mar 2022 15:20:44 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C83C368B24E for ; Wed, 30 Mar 2022 15:20:38 +0300 (EEST) Received: by mail-lf1-f44.google.com with SMTP id bq24so19525458lfb.5 for ; Wed, 30 Mar 2022 05:20:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=D07bVlKiIkA2SzzUiC6GaF15DcgQb3Fp+hz3VGzc3Z8=; b=AMQSzhmiuWyl8LE7aHiHQQkAVy40xgLNO8ZyJ0C1mAUqg7tZh5nGxIvuv0khbqrihA 4PPTGHHRB2XK3U2yk3E1+Ur93NtKfpeibprPzwNczh7vzEN5Mm37Pilti1v/m+2pTcON NM6Lr9yi0ExrII6cBLQkmp4mLH0j20afLNnnnl8GCDOY08kxpa07UgySf+EzY+xEr1OO 4kHnWq1QFDjKO8lDS4V97TpL7tKfiOGfybhiTVLHk+p8QmFrNohFbYN39a/22nOfZx+3 uFREXm3+0B1XvdVJOCrBv6Neth3QHx4fRXJnE95IMGRLQtRwhvH1kli11dB/1nm6htzE j9sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=D07bVlKiIkA2SzzUiC6GaF15DcgQb3Fp+hz3VGzc3Z8=; b=WV11SdAeJ4yWUk0Ej1UwQ5GRZ27qECNHcNfjUQuoRK1adS+nbzXpGNUM3oRhTlLFtc WVJBBrnnGhwu0ROq2zeDLNQKuVB+6W003YqYv5GRgQ1jcpJdy6IJbc805quT1jTtk31x lBc+u6KW6S+A/anl+sxxfgj1Z/ZBOZIeY/MivwlGZn8nS5RhiBfOqkYXB3HJdT6f+4Bf IStNSJrNG5CVsnm1YUSGZtrLHI9EAJu6RxHFi8c6SNxNy3RblVChV5v3Q7CAyNW9aDtc ma3a4dsxce1FqPiq1LjH3dARXwh/W4ZlEU6KBuba6X4ZEkLFxq3KTH2bShgJ38XvgFu5 Efjw== X-Gm-Message-State: AOAM5313BzASiaTanTzNXie9G+4Gqe176Fn6gXfya06UxjyYYz973HOB kk3PfSWERSLcdjxfyOI0YPcGLDJuVys= X-Received: by 2002:a05:6512:400e:b0:447:5d84:c40 with SMTP id br14-20020a056512400e00b004475d840c40mr6221092lfb.591.1648642837904; Wed, 30 Mar 2022 05:20:37 -0700 (PDT) Received: from localhost.localdomain (deedock.humlab.lu.se. [130.235.135.183]) by smtp.gmail.com with ESMTPSA id a21-20020a2eb555000000b00247ea2fa530sm2324070ljn.20.2022.03.30.05.20.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 05:20:37 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Wed, 30 Mar 2022 14:18:06 +0200 Message-Id: <20220330121806.822-22-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20220330121806.822-1-dcnieho@gmail.com> References: <20220330121806.822-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 21/21] avdevice/dshow: capabilities query also works on opened device 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: YXD9dpMOPKdB While the capabilities API is in principle meant to be used with an allocated format context belonging to an unopened device, small changes make it work for an opened dshow device as well. So hereby done. Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 110 +++++++++++++++++++++--------------- libavdevice/dshow_capture.h | 3 + 2 files changed, 66 insertions(+), 47 deletions(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 3cae7d265e..1e4025983a 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -849,7 +849,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, void *caps = NULL; int i, n, size, r; int wait_for_better = 0; - int use_default; + int use_default, already_opened; // format parameters requested by user // if none are requested by user, the values will below be set to @@ -875,6 +875,9 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, if (!caps) goto end; + // get if device is already opened + already_opened = ctx->device_name[0] || ctx->device_name[1]; + /** * If we should open the device with the default format, * then: @@ -1153,7 +1156,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, // in ranges, try to apply in all cases, and store // caps if successfully applied if (!wait_for_better || ranges) { - if (IAMStreamConfig_SetFormat(config, type) != S_OK) + if (!already_opened && IAMStreamConfig_SetFormat(config, type) != S_OK) // skip if device already opened goto next; else if (ranges) { // format matched and could be set successfully. @@ -1494,12 +1497,19 @@ dshow_list_device_options(AVFormatContext *avctx, ICreateDevEnum *devenum, char *device_unique_name = NULL; int r; - if ((r = dshow_cycle_devices(avctx, devenum, devtype, sourcetype, &device_filter, &device_unique_name, NULL)) < 0) - return r; - ctx->device_filter[devtype] = device_filter; - ctx->device_unique_name[devtype] = device_unique_name; + if (!ctx->device_filter[devtype]) { + if ((r = dshow_cycle_devices(avctx, devenum, devtype, sourcetype, &device_filter, &device_unique_name, NULL)) < 0) + return r; + + // put them in context so they'll be cleaned up again + ctx->device_filter[devtype] = device_filter; + ctx->device_unique_name[devtype] = device_unique_name; + } else + device_filter = ctx->device_filter[devtype]; + if ((r = dshow_cycle_pins(avctx, devtype, sourcetype, device_filter, ranges ? &device_pin : NULL, ranges, query_type)) < 0) return r; + return 0; } @@ -2319,7 +2329,8 @@ fail1: return ret; } -// fake class to point av_opt_query_ranges to our query_ranges function +// fake class to point av_opt functions to capabilities that can be queried, +// and av_opt_query_ranges to our query_ranges function static const AVClass dshow_dev_caps_class = { .class_name = "", .item_name = av_default_item_name, @@ -2337,49 +2348,51 @@ static int dshow_create_device_capabilities(struct AVFormatContext *avctx, AVDev // set class so queries work caps->av_class = &dshow_dev_caps_class; - if (ctx->device_name[0] || ctx->device_name[1]) { - av_log(avctx, AV_LOG_ERROR, "You cannot query device capabilities on an opened device\n"); - ret = AVERROR(EIO); - goto fail; - } + // check if device setup is needed or we will be querying capabilities of an already opened device + ctx->cap_query_already_opened = ctx->device_name[0] || ctx->device_name[1]; + if (ctx->cap_query_already_opened) + av_log(avctx, AV_LOG_WARNING, "Querying device capabilities on an opened device: may yield false positives\n"); - if (!parse_device_name(avctx)) { - av_log(avctx, AV_LOG_ERROR, "You must set a device name (AVFormatContext url) to specify which device to query capabilities from\n"); - ret = AVERROR(EINVAL); - goto fail; - } - - CoInitialize(0); - if (CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, - &IID_ICreateDevEnum, (void **) &devenum)) { - av_log(avctx, AV_LOG_ERROR, "Could not enumerate system devices.\n"); - ret = AVERROR(EIO); - goto fail; - } + // if device not already opened, check that what user specified can be opened + if (!ctx->cap_query_already_opened) { + if (!parse_device_name(avctx)) { + av_log(avctx, AV_LOG_ERROR, "You must set a device name (AVFormatContext url) to specify which device to query capabilities from\n"); + ret = AVERROR(EINVAL); + goto fail; + } - // check devices can be found - if (ctx->device_name[VideoDevice]) { - IBaseFilter *device_filter = NULL; - char *device_unique_name = NULL; - if ((ret = dshow_cycle_devices(avctx, devenum, VideoDevice, VideoSourceDevice, &device_filter, &device_unique_name, NULL)) < 0) - return ret; - - if (ret >= 0) { - ctx->device_filter[VideoDevice] = device_filter; - ctx->device_unique_name[VideoDevice] = device_unique_name; + CoInitialize(0); + if (CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, + &IID_ICreateDevEnum, (void **) &devenum)) { + av_log(avctx, AV_LOG_ERROR, "Could not enumerate system devices.\n"); + ret = AVERROR(EIO); + goto fail; } - } - if (ctx->device_name[AudioDevice]) { - IBaseFilter *device_filter = NULL; - char *device_unique_name = NULL; - if (dshow_cycle_devices(avctx, devenum, AudioDevice, AudioSourceDevice, &device_filter, &device_unique_name, NULL) < 0) { - /* try to access audio from combined video+audio sources as fallback */ - if ((ret = dshow_cycle_devices(avctx, devenum, AudioDevice, VideoSourceDevice, &device_filter, &device_unique_name, NULL)) < 0) - goto fail; + + // check devices can be found + if (ctx->device_name[VideoDevice]) { + IBaseFilter *device_filter = NULL; + char *device_unique_name = NULL; + if ((ret = dshow_cycle_devices(avctx, devenum, VideoDevice, VideoSourceDevice, &device_filter, &device_unique_name, NULL)) < 0) + return ret; + + if (ret >= 0) { + ctx->device_filter[VideoDevice] = device_filter; + ctx->device_unique_name[VideoDevice] = device_unique_name; + } } - if (ret >= 0) { - ctx->device_filter[AudioDevice] = device_filter; - ctx->device_unique_name[AudioDevice] = device_unique_name; + if (ctx->device_name[AudioDevice]) { + IBaseFilter *device_filter = NULL; + char *device_unique_name = NULL; + if (dshow_cycle_devices(avctx, devenum, AudioDevice, AudioSourceDevice, &device_filter, &device_unique_name, NULL) < 0) { + /* try to access audio from combined video+audio sources as fallback */ + if ((ret = dshow_cycle_devices(avctx, devenum, AudioDevice, VideoSourceDevice, &device_filter, &device_unique_name, NULL)) < 0) + goto fail; + } + if (ret >= 0) { + ctx->device_filter[AudioDevice] = device_filter; + ctx->device_unique_name[AudioDevice] = device_unique_name; + } } } @@ -2395,9 +2408,12 @@ fail: static int dshow_free_device_capabilities(struct AVFormatContext *avctx, AVDeviceCapabilitiesQuery *caps) { + struct dshow_ctx *ctx = avctx->priv_data; + // clear state variables that may have been set during the querying process // (e.g. frees device names, removes device_filters, etc) - dshow_read_close(avctx); + if (!ctx->cap_query_already_opened) + dshow_read_close(avctx); return 0; } diff --git a/libavdevice/dshow_capture.h b/libavdevice/dshow_capture.h index 94ba9896b7..a2c107b19c 100644 --- a/libavdevice/dshow_capture.h +++ b/libavdevice/dshow_capture.h @@ -345,6 +345,9 @@ struct dshow_ctx { int sample_rate; int sample_size; int channels; + + // for capabilities query + int cap_query_already_opened; }; /*****************************************************************************