From patchwork Fri Jun 11 20:30:50 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: 28221 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp765303iol; Fri, 11 Jun 2021 13:37:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9YTXSE2C1mlqvc572fXa9Be3XIU9eH5l1hBJycfMkbrlQrLaQIW3u07gW6yx2NkiJeO7v X-Received: by 2002:a17:906:a294:: with SMTP id i20mr5276060ejz.330.1623443828321; Fri, 11 Jun 2021 13:37:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443828; cv=none; d=google.com; s=arc-20160816; b=PPMPnzCFwtaqQfxvJgBa2oIkBOcBMdsSm5puM249mAnQlarjBDFL8/rZ/cbXaF6CnN +7EbRuuER5KmkRsDSMOcaQmfRWUG+ch8jix1bZyiMfQkP2NHLLqMuGfF/xcENf1gE5Nf UpUf4VSRyuaejO8sYDEEPqvlvYlBzPIk/uCk0MEbkOycE73o2HyypuFTgsmcqumtmdIu RfIeGfzkCos052ABuDTCOmP6qukM2KcDLosdJog8n5fFQiVK44I3/w6/u3wlLsG4sZWd ZZLE38yitReqEgYJ16pf7dwDpy+Krg8OiQtSvSSf9LkU3KIJAHJ1VA6HNzgtw6z4B/gP ULlQ== 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=8mu2Nsq5ufSmfGyj6YKVBXfqYJ5IMvy8MGTzRw7+Dyk=; b=HNf+J2DMmTtN93K7hVgzlghCY2/GleHNpo2uCGCO3x9RolJ/zzACmI7jw3B3zgZ4HH arydTSP5X7Z8EzLfSrwa+Uumoi/p/lorB5h9dc6qgp+1xPcN+VNDXtEeSfVhlyF1oMd1 2ESkt6oJ/ROYZKO/uq3pAWPmq5ETyZL1IXoKRi3NG+1GDsJpW5kEf+ZFEDLcNiqZX+3H UdFXi98aEhC7Z9h51lfERsoYHeWv4yIeU4X/hnMgsGsXd43cFsU0Li86/UnldkKGLxTA 5TSPylQd6/quNWv0YHbjDFG4psR0yie6Rf38iSAvX3JbB05F7Z1oCKT9q0ubvLAx76o5 7zkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=SfYtdUc9; 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 u23si5863685edi.175.2021.06.11.13.37.07; Fri, 11 Jun 2021 13:37: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=20161025 header.b=SfYtdUc9; 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 637BF6808CC; Fri, 11 Jun 2021 23:37:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DCFE76808CC for ; Fri, 11 Jun 2021 23:37:01 +0300 (EEST) Received: by mail-lf1-f52.google.com with SMTP id p7so10387952lfg.4 for ; Fri, 11 Jun 2021 13:37:01 -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=l1eLY/v/V4skxYZ7ZTRZY0QUE3Et6Oq3M/DuBR/5lZc=; b=SfYtdUc9W5kCKLIkEBDqMvRN7jI6RX0ndwfsa+FNnnxIqGMO8iYdJkPgK4QUcpK/Ta 6phlk5+E5qRG3BLs+F1Ypmml1Th63BMOoJvMLarh0iXJ5IgVfJkPzoD4u7l00cBEwkF5 OqkJ91vCIMqo5hoAeAWELVk1opnOl48ziqSKKSusCYzAT7XH/btDYuR+QWqcnl2GjiME IrcqWxoAgd/qS2uJT1Ct60LOrE2H7YG1H9PpVWpWtPUoRuk1bIgbWDDm8fZWEOPKOjQ2 rop638EdlJP4K1mhRWxFR2gkqWaYBze3i5iIVGRoS1TzSs3N/3yQfeu3nQXpXIcbaLBR 61FA== 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=l1eLY/v/V4skxYZ7ZTRZY0QUE3Et6Oq3M/DuBR/5lZc=; b=Ak/4IXIvtwQhC30WNuC0SeqOWDN89JGo7UubIR7rP2n1a0iCXiB0zBMWIKSKy6t/Wp epI8rAk2ogIvfuMMhH82M+YlnhsdjdcYz6wG10YIU7xxpoR/5UHRO5v/Vja16ocdpGMc goTrvunzYQEent9koZLQRedh/muyP8CQpGt60J1oJ94MhKL/dKgtM47UoFkdhox7qfe8 lH3+HqRi9Qg8lPcW4B8vHKO2JNhRMOO1LwyOSBv7/CJqxFwG/x5S+IuEdsgXmTXxxMpB RVeBJu6wFay3FSue+KwXxaBuchq1nomH9/dU+P2BR2mCoIiPloVYI6dDmtMEAvaXKK7I IhJQ== X-Gm-Message-State: AOAM533qwWBqa+Su+T0B/17sxYgmE3eKiH8mkg8gdaxhrcCt6rtOiq1p vYmiIm9ccu7TW7T6MotvuAWggKaIb7rF1w== X-Received: by 2002:a05:6512:39ca:: with SMTP id k10mr3789381lfu.473.1623443820690; Fri, 11 Jun 2021 13:37:00 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id o6sm685129lfg.212.2021.06.11.13.36.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:37:00 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:50 +0200 Message-Id: <20210611203104.1692-20-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 19/33] 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: nAiXQriKMKG0 This reverts commit 4f49ca7bbc75a9db4cdf93f27f95a668c751f160. The next few patches clean up the API and implement this capability for avdevice/dshow. Signed-off-by: Diederick Niehorster --- libavdevice/avdevice.c | 71 ++++++++++++++++++++++++++++++++++++++---- libavdevice/avdevice.h | 5 --- libavformat/avformat.h | 21 +++++++++++++ 3 files changed, 86 insertions(+), 11 deletions(-) diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c index e339cebf2d..695b9143af 100644 --- a/libavdevice/avdevice.c +++ b/libavdevice/avdevice.c @@ -27,11 +27,39 @@ #include "libavutil/ffversion.h" const char av_device_ffversion[] = "FFmpeg version " FFMPEG_VERSION; -#if FF_API_DEVICE_CAPABILITIES +#define E AV_OPT_FLAG_ENCODING_PARAM +#define D AV_OPT_FLAG_DECODING_PARAM +#define A AV_OPT_FLAG_AUDIO_PARAM +#define V AV_OPT_FLAG_VIDEO_PARAM +#define OFFSET(x) offsetof(AVDeviceCapabilitiesQuery, x) + const AVOption av_device_capabilities[] = { + { "codec", "codec", OFFSET(codec), AV_OPT_TYPE_INT, + {.i64 = AV_CODEC_ID_NONE}, AV_CODEC_ID_NONE, INT_MAX, E|D|A|V }, + { "sample_format", "sample format", OFFSET(sample_format), AV_OPT_TYPE_SAMPLE_FMT, + {.i64 = AV_SAMPLE_FMT_NONE}, AV_SAMPLE_FMT_NONE, INT_MAX, E|D|A }, + { "sample_rate", "sample rate", OFFSET(sample_rate), AV_OPT_TYPE_INT, + {.i64 = -1}, -1, INT_MAX, E|D|A }, + { "channels", "channels", OFFSET(channels), AV_OPT_TYPE_INT, + {.i64 = -1}, -1, INT_MAX, E|D|A }, + { "channel_layout", "channel layout", OFFSET(channel_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, + {.i64 = -1}, -1, INT_MAX, E|D|A }, + { "pixel_format", "pixel format", OFFSET(pixel_format), AV_OPT_TYPE_PIXEL_FMT, + {.i64 = AV_PIX_FMT_NONE}, AV_PIX_FMT_NONE, INT_MAX, E|D|V }, + { "window_size", "window size", OFFSET(window_width), AV_OPT_TYPE_IMAGE_SIZE, + {.str = NULL}, -1, INT_MAX, E|D|V }, + { "frame_size", "frame size", OFFSET(frame_width), AV_OPT_TYPE_IMAGE_SIZE, + {.str = NULL}, -1, INT_MAX, E|D|V }, + { "fps", "fps", OFFSET(fps), AV_OPT_TYPE_RATIONAL, + {.dbl = -1}, -1, INT_MAX, E|D|V }, { NULL } }; -#endif + +#undef E +#undef D +#undef A +#undef V +#undef OFFSET unsigned avdevice_version(void) { @@ -68,18 +96,49 @@ int avdevice_dev_to_app_control_message(struct AVFormatContext *s, enum AVDevToA return s->control_message_cb(s, type, data, data_size); } -#if FF_API_DEVICE_CAPABILITIES int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s, AVDictionary **device_options) { - return AVERROR(ENOSYS); + int ret; + av_assert0(s && caps); + av_assert0(s->iformat || s->oformat); + if ((s->oformat && !s->oformat->create_device_capabilities) || + (s->iformat && !s->iformat->create_device_capabilities)) + return AVERROR(ENOSYS); + *caps = av_mallocz(sizeof(**caps)); + if (!(*caps)) + return AVERROR(ENOMEM); + (*caps)->device_context = s; + if (((ret = av_opt_set_dict(s->priv_data, device_options)) < 0)) + goto fail; + if (s->iformat) { + if ((ret = s->iformat->create_device_capabilities(s, *caps)) < 0) + goto fail; + } else { + if ((ret = s->oformat->create_device_capabilities(s, *caps)) < 0) + goto fail; + } + av_opt_set_defaults(*caps); + return 0; + fail: + av_freep(caps); + return ret; } void avdevice_capabilities_free(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s) { - return; + if (!s || !caps || !(*caps)) + return; + av_assert0(s->iformat || s->oformat); + if (s->iformat) { + if (s->iformat->free_device_capabilities) + s->iformat->free_device_capabilities(s, *caps); + } else { + if (s->oformat->free_device_capabilities) + s->oformat->free_device_capabilities(s, *caps); + } + av_freep(caps); } -#endif int avdevice_list_devices(AVFormatContext *s, AVDeviceInfoList **device_list) { diff --git a/libavdevice/avdevice.h b/libavdevice/avdevice.h index bbeb1ae21b..6443f865d5 100644 --- a/libavdevice/avdevice.h +++ b/libavdevice/avdevice.h @@ -331,7 +331,6 @@ int avdevice_dev_to_app_control_message(struct AVFormatContext *s, enum AVDevToAppMessageType type, void *data, size_t data_size); -#if FF_API_DEVICE_CAPABILITIES /** * Following API allows user to probe device capabilities (supported codecs, * pixel formats, sample formats, resolutions, channel counts, etc). @@ -427,7 +426,6 @@ typedef struct AVDeviceCapabilitiesQuery { /** * AVOption table used by devices to implement device capabilities API. Should not be used by a user. */ -attribute_deprecated extern const AVOption av_device_capabilities[]; /** @@ -447,7 +445,6 @@ extern const AVOption av_device_capabilities[]; * * @return >= 0 on success, negative otherwise. */ -attribute_deprecated int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s, AVDictionary **device_options); @@ -457,9 +454,7 @@ int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatConte * @param caps Device capabilities data to be freed. * @param s Context of the device. */ -attribute_deprecated void avdevice_capabilities_free(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s); -#endif /** * Structure describes basic parameters of the device. diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 7e9db81d26..54457572b1 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -583,6 +583,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 @@ -754,6 +764,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; /** * @}