From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id DA12642762 for ; Wed, 30 Mar 2022 12:20:15 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C794968B25A; Wed, 30 Mar 2022 15:19:33 +0300 (EEST) 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-Google-Smtp-Source: ABdhPJwp+DX88/qA0AYMEVG8BqFClJLvt9oRiABEYLFcOrQhhTF2/+ztDFslBFCmv5+O2X309dQ7oQ== 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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 -- 2.28.0.windows.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".