From patchwork Fri Jun 11 20:30:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 28226 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp766155iol; Fri, 11 Jun 2021 13:38:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHO9eoglYkexUAwkwyG1MpYROddimp+j5zDBGwhf95HRACif5G4eiolNgkwNooGolCSURe X-Received: by 2002:aa7:c450:: with SMTP id n16mr5498735edr.386.1623443911278; Fri, 11 Jun 2021 13:38:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443911; cv=none; d=google.com; s=arc-20160816; b=G3cjliHBkRCP12ucxNCZr6qqxTLteNuvcB9REt7l2gkss2Lg2lDFduERGF29y46MlA +dIQKdmwj+mc5sXxB598ln61hFdsrUbVGJsyjahgRUMbk2V86CB+fIUA3QOoric41c3W CsAGEvLNUvoMRrGsE4lLSlEqmSa6fIIgGCd01M8EpuimHrbWEZXVDDMgVjXX8Y/uUaAh LLLhSqv9YtUEkIIyLn8cyNjAmi3G6RvpdLtvL2D0gkXwfX+hjN3+QBITdppAgwAzQAnM nY35dSwWtvf9pxd/gis0ZOLJ3UkjEThyHld46ZaImI2l5Zqx/uD0innBhM1cLTnwJRzU FSQA== 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=kQAA2fHQyl2mGLlRrnd72W0PldqKyCYw7DSY47bbOng=; b=Zkfw76QPJFHCoWoPGZ8dWbit0osl1iOHmNEmh8tXmgauci0v8kqxsuvkEKzfRSPGtm 5ypoKqbsY8ciY4CA5YgpHm/yIgDG2v9T9R50THGkz4j0QAKYoOsRL81aVPBWEfdrgyk9 755ZxFI6IRSaA9wsXf0M2HjvleHYm96FwJAkCuuM+3e5uEyi5sII0Y75eQ3kYqod5E20 YYnm6p+RjIBf0PkLzhzI6HX4q1qnQkc7wzcTlqTOQUD2SYwbqDIAOKnfXf4MvVyBpkuJ hQLo1ZqdsTkhKYMLJV2MW0x9okTlObCHqrPuU2VSxrHLEG6rn0lzi3yf1Qi86LXHF9uw 2Zjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=DYIt2YF2; 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 r15si5446270edo.442.2021.06.11.13.38.30; Fri, 11 Jun 2021 13:38:31 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=DYIt2YF2; 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 D008C6808CC; Fri, 11 Jun 2021 23:38:27 +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 B7DF6689815 for ; Fri, 11 Jun 2021 23:38:25 +0300 (EEST) Received: by mail-lf1-f47.google.com with SMTP id m21so10346021lfg.13 for ; Fri, 11 Jun 2021 13:38:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ji5OwGis+lTZN5i+0WIlbAnoYmZK9arobLG3ykad+II=; b=DYIt2YF24T3/pE8jIXO27SuQFocyWczQNZ3hn7fXVfDA4sCIZAJ5iidxEZd5TgjUCl in3GP791JwarZ8nRNXljq1T06MDn8LpIBKBnjVUS2SS8KPZ4jYhEPnJv2FGmOC+hBm07 D0ZCVXTjOjIgXq6HAuA7NVJShq9HG61MkvRYSMDd5FeZuBz806+FZEvrtYkJnDDiPCmo OR6WdUzipw0vfbzm1wch5JO68ShGQPNDLxK87pioiO4RGzTnTE1FztZEO/QIhuZRRifw PYUzdBqmji+VDMd/Kt6SMxZUPngqyC57FzND4PeiS+ejWhraoHAhiBKovFmR3SYOkpxv nn6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ji5OwGis+lTZN5i+0WIlbAnoYmZK9arobLG3ykad+II=; b=I3I/Bxi9qG84D5Fgrao3kH2ux79/NbKucNAoj2mGtQOUn79mN0tlcTaPv7s9uTvStg k0WFuHdB+I61ox3htP6x2lzuq9TFlu77vLy+KsYhM/zYaCKPXHwzZfg8v4Q34j2E8WDx gdqDFejbIVerZrHMs81MbOq4wQS+ghGbT0qaP7fNg4ns5scXcQo4WzBKCeWjUCVBQvEA ioie616I1cwj7xshiWkpC5+5hRlGD/5xr/JuX7Ax9w6goWxHcN3+BiBHoIb9f8OHm7FC unmoIG6pV7YuD1c/bt34h14GQqjonTtek7u3ZXhGYsfSapI0wGgBvojF5HBUpZPDWstS G1mg== X-Gm-Message-State: AOAM531SecoyVMMpvqmkaUo4A0blx7HXxsQh+z+uuV4RFK4mNNyEPi76 sjKgJW1l76l5VT9K37eCSGDc/KS6aQ6rbw== X-Received: by 2002:ac2:596a:: with SMTP id h10mr3566021lfp.360.1623443904847; Fri, 11 Jun 2021 13:38:24 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id bi2sm530374lfb.190.2021.06.11.13.38.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:38:24 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:55 +0200 Message-Id: <20210611203104.1692-25-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 24/33] 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: UKc2hAGxRejT Signed-off-by: Diederick Niehorster --- libavdevice/internal.h | 31 +++++++++++++++++++++++++++ libavdevice/utils.c | 48 ++++++++++++++++++++++++++++++++++++++++++ libavdevice/version.h | 2 +- 3 files changed, 80 insertions(+), 1 deletion(-) diff --git a/libavdevice/internal.h b/libavdevice/internal.h index e7a72d008d..ce316082be 100644 --- a/libavdevice/internal.h +++ b/libavdevice/internal.h @@ -58,4 +58,35 @@ typedef 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 diff --git a/libavdevice/version.h b/libavdevice/version.h index 53af6fa0d0..e0361aebc1 100644 --- a/libavdevice/version.h +++ b/libavdevice/version.h @@ -29,7 +29,7 @@ #define LIBAVDEVICE_VERSION_MAJOR 59 #define LIBAVDEVICE_VERSION_MINOR 3 -#define LIBAVDEVICE_VERSION_MICRO 100 +#define LIBAVDEVICE_VERSION_MICRO 101 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \ LIBAVDEVICE_VERSION_MINOR, \