From patchwork Tue Jul 6 09:20:11 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: 28816 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5d:965a:0:0:0:0:0 with SMTP id d26csp4922237ios; Tue, 6 Jul 2021 02:25:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKzuNEdCV+MmtdtuTzrA4siCjnY51YLcdRc3b2P20SnljohBQXK6l4yfxmJlLVqH07NQon X-Received: by 2002:aa7:ce1a:: with SMTP id d26mr8303330edv.209.1625563555259; Tue, 06 Jul 2021 02:25:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625563555; cv=none; d=google.com; s=arc-20160816; b=FEmnklQc++pgOVe7REv/clC/Br7lRA7X74R10rPYbJA3F1MGzPeB2C2MthVSb95aao TxMvRWsX5P1XgtHjr84ESz9RDafAye0+T/7hGUnu24871ddd8O/1jmQ0LFcrxiZ3qlil p8PIoj2nUsaNVzY+CZZOZjR4VEuiEvRmtAOdLthQbNAxTVOdkHJgS+y3+LkIqKSDQVJT xoOeA6XJWmQv1s2gFPixcuLSTH5P1nyGlzWvUMpVk062P6s7Ion4cHtBEYD1siEtsv74 Y3SF6RLmELEvRKsJ3FQG1A5VyzIdeoVbFNvWacCC3mvpmGooeI9xvMcgRpvZHMoB+W7K M+gg== 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=2fZpiNoUpmsTDuUOhj969Do7VmPhJly0CZXpsB7JOsY=; b=s6tlho6h340fRdbYnULYWIyQwwrIWa5bKpflbUe1FVwG43vl7fadU9N3rwZBZYBg31 mjELOKOi9vnWD79jsJqUp/d3D3Y2o8SpCknO10fn693MxXmlUhJVxHCew1uu/WjNsvaN ddnoxjUk3Bey6yU82WtVNOHMy9HQNaknGlMb7nePcwXB4atEbMDG5aFfhqqxPvIF6RCf 1Z3PD+W5Q7GLF3tuoW3U7MsPNXs5PViKzhZ4PacYdea3oC3OHtZ3dGFOC/GcWp7SJcF2 VyEcxA2MMt+jZcMIDCIdxKNFTeu5sKP8ZL7WM90V9aXa/tX0pCha+EsAQh9fvNbzyaEg yIYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=TY2tPnEs; 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 c9si15733309ejj.120.2021.07.06.02.25.54; Tue, 06 Jul 2021 02:25:55 -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=TY2tPnEs; 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 59BB668A89C; Tue, 6 Jul 2021 12:25:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 696E468A888 for ; Tue, 6 Jul 2021 12:25:43 +0300 (EEST) Received: by mail-lj1-f170.google.com with SMTP id u25so28207911ljj.11 for ; Tue, 06 Jul 2021 02:25:43 -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=ytZLCOr8PZ7Z4aJDakweiepJwndMNK9+FhHZpkFI0gw=; b=TY2tPnEsywSZPWhQv40CPG9eD9xgCgNt/DGnrp1Q7Jw1Qy8MEuhTNE7ROy3GSF12rs De7ClsvhNNhBzGA4m0Vl2iEw/IVVL9RnuYvd+9T2eSWOb0aR0x2exvUlp17snok5Fief qkFjw8gZRUogw9SAPY+A6fcOLujAcM2nqwCot1or2kK7fxYtFEAqGYrYHc+jty2vawSq Ckd9kL62WXDHhngFl/nEb/X+uMSY4Ypi1FytHrTdvuUC0gO/B57z/CF12xxzczPf33QH hvr9He6KyOjBv3ph38J/2nn4LhHlNp9ei6IcrItRSuD/BGjBmtD65UPSmFuRlHvPAy4n hjrg== 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=ytZLCOr8PZ7Z4aJDakweiepJwndMNK9+FhHZpkFI0gw=; b=hEUBkTTyh4pMJ0goUkPrs1a3Jd3ZEaEtC06ReFle5blHdVd1jslWonKCEL5rASo8sQ I6cqOjg0cQsusrFsOoTD6NVFAjT6jpC49gAMeLPvL3VAEd8coULbQpjamJQACbpii+Yn WKRrfIrxQG0EYlEJwzZcdOPzONiDToMfg9BifS63nnI5FWu2toNlOebM71HdtEqgz2VJ KV88ytCbSmNk35BdHQHgAPDNmMaQpEpMBTdMDQ0+NPUeY4c7uGzLEzVgByhHWAb8txMS S341X+5H1rjUossBpyQqzrWPnEXnCc2/OeDu0kAYzx3qXNbeiyGuzREgwFvRgQhxtQuu X2UQ== X-Gm-Message-State: AOAM531eM0zcahzN5/nJEr4GYMjcLdntor+RwWUZPcDR8Y2VS/sU07ON BCcq26th5SbKf/03Yp3/rm9kHJu8Gew= X-Received: by 2002:a2e:9d1a:: with SMTP id t26mr14584724lji.10.1625563542223; Tue, 06 Jul 2021 02:25:42 -0700 (PDT) Received: from localhost.localdomain (deedock.humlab.lu.se. [130.235.135.183]) by smtp.gmail.com with ESMTPSA id c5sm1348409lff.86.2021.07.06.02.25.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 02:25:41 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 6 Jul 2021 11:20:11 +0200 Message-Id: <20210706092020.1057-26-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210706092020.1057-1-dcnieho@gmail.com> References: <20210706092020.1057-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 25/34] 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: i1y/dhCZcsBM 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 | 79 ++++++++++++++++++++++++++++++++++++++++++ libavdevice/avdevice.h | 27 +++++++++++++++ libavdevice/version.h | 4 +-- 3 files changed, 108 insertions(+), 2 deletions(-) diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c index 73c6738383..181ce04188 100644 --- a/libavdevice/avdevice.c +++ b/libavdevice/avdevice.c @@ -19,6 +19,8 @@ #include "libavutil/avassert.h" #include "libavutil/samplefmt.h" #include "libavutil/pixfmt.h" +#include "libavutil/pixdesc.h" +#include "libavutil/avutil.h" #include "libavcodec/avcodec.h" #include "avdevice.h" #include "internal.h" @@ -128,6 +130,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 758c650636..11d1a6ae12 100644 --- a/libavdevice/avdevice.h +++ b/libavdevice/avdevice.h @@ -48,6 +48,7 @@ #include "libavutil/log.h" #include "libavutil/opt.h" #include "libavutil/dict.h" +#include "libavutil/bprint.h" #include "libavformat/avformat.h" /** @@ -402,6 +403,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. * @@ -422,6 +433,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 0df40ef4c7..8f92c3b85b 100644 --- a/libavdevice/version.h +++ b/libavdevice/version.h @@ -28,8 +28,8 @@ #include "libavutil/version.h" #define LIBAVDEVICE_VERSION_MAJOR 59 -#define LIBAVDEVICE_VERSION_MINOR 3 -#define LIBAVDEVICE_VERSION_MICRO 102 +#define LIBAVDEVICE_VERSION_MINOR 4 +#define LIBAVDEVICE_VERSION_MICRO 100 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \ LIBAVDEVICE_VERSION_MINOR, \