From patchwork Mon Jun 7 23:04:14 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: 28146 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp3887832iof; Mon, 7 Jun 2021 16:07:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzc66o2g0dVGhPa74q/In5pd7ZEyn0zdbNHkBvGJIf9vRk4hlELUDe7vbrWG2/6A/LoDx1A X-Received: by 2002:a05:6402:4cf:: with SMTP id n15mr23150597edw.162.1623107262553; Mon, 07 Jun 2021 16:07:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623107262; cv=none; d=google.com; s=arc-20160816; b=s38y/uHOHKcZbXm7q3XWQCXH9DKA5AuzwBCTYTQEcvFNii4K5rJsrnG80TSAt6Qs+X XdLdF8VonBw01rxBdCHOrAf19s1Y3Y630zX1KcCDEDtLS9CIMJI4IqOst9PF8UoxMcMq IQGsoRpDf4AeNAvLux1tG99HsWYU5aVixTIgeIKO/BHogGin6byvvt/USFFafhOExSam yu8jYboAHfPdrhl7r+uzlVhKerU4LgvAo1mjHlJJuUUqOcTcOZpjo7mDb/+QMEkfHKaO m3XqNBZTTgoPQwopoG4068JCHvc3VBT/SAYCsZF75Z7t6u0uneBBiaYEFgTIP3PmFxkD d3+A== 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=jB1asXvWTMLxoiPz1jBKx8yPEGKhUsdRRwAuYYlTl1A=; b=wf9fap5zyM5UfxK9hI9KUWVB6BqaYe4dz9GTdPyUEzYu/dQfIlePqCdfLKoyRSTAGd SgaFMOVQmau9meHWZfIQLbvsBkMLsMv67Hcva8s5zQaIdHtbKa3c4dCfqSJgZp2VDAeS e89cSwgNqUUiuq1Z311bxa61dy1wwdL+XaOBkfLcQGcz3ghXKc1h4mZnS9DBbFrcbEG0 NyzpfDUCINC68dFC/VwF4iLqWNPEHMW7CldD4vz8Vbx7G6nxjD/A8XxguJUcJCg5Tftm e0tYBzE6USDU8G1adS7NsFiHamnRFoX7pa1c0iH6Xu+PZOmc3Z4C+55ZohHYigJdzJYi 9I9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=AifXht6C; 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 g12si12023968ejd.330.2021.06.07.16.07.42; Mon, 07 Jun 2021 16:07:42 -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=AifXht6C; 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 4FBF868812C; Tue, 8 Jun 2021 02:05:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 52328687FFA for ; Tue, 8 Jun 2021 02:05:00 +0300 (EEST) Received: by mail-lf1-f46.google.com with SMTP id v22so27648299lfa.3 for ; Mon, 07 Jun 2021 16:05:00 -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=yZCvqiRgMx+ONd84mxjHmzy71zdHHJS5NHJfKjDaIF4=; b=AifXht6ClStZ0wUnAvrYCXc1vgLfd9KwtWQdGbS/qyNmueuR/cYaIs5JixZC8/Iphm AL6+TkWv+HJmxsUJxZLcoUyyUxzspA66VywddRwI7ea/4jykjGUhSli6u23q5CTA+LBC V1OE1jIYxDY5wXpufLfQRp8jVzzxqGqhl1nQiAyQxvxTEkZUfOEBJ7W2Ay4omylmWGnD yhE+e+xmm1cKD0ZU4HKFAYCqCklib4W3/A6nPbQHlomyS4QXlJ+VJy/3d1/wq2ihvrKS 8eHcFKmjwV9pRpXBirb/8DsXwHsc45gwu83N3wS2eHPey3MVceXSW4PQdrcEI5PBnDhI c6Ig== 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=yZCvqiRgMx+ONd84mxjHmzy71zdHHJS5NHJfKjDaIF4=; b=VXguqO//d5KnALPbQ87oOWJTkKUzDjiYSCuM8YS3S48Uz5X6pM7msQ8C4JJDl5j8iF 8/BFR9Q11jJ6TdAQFgMnOE4Ekz+8/6R+cOOx4jmrPlcMUyZy7BCFHz4L+eBJ8XmT5mf6 9SJSKusO5PNmPoXj+nxVZM3YAqEl2VZni/jGNoiDNOmqtANroBGqCTxSTmUHKJz1ZqNx wSVU4BwKao1M+SIwPDoJOiyHnHW8UM0rR4n1IEqGJH4qAydxTwK4/SJIs+7NwSd8CyAA Obz1vUjlAD+t26K+gLG+GIgYmFeVjDsKWgRCkqKnTvJ4Xr8yP8QVqxCQ5qj1J21oI1Aa g+bw== X-Gm-Message-State: AOAM5333DJvFYXUeN7SNCHv6tg/Yh9SoB+iMB+p3RkR2tJX+7BzTucRM +N4VN+hPmsM7I0PqPrFk7nio2U2m+pQEag== X-Received: by 2002:a05:6512:3882:: with SMTP id n2mr13257213lft.193.1623107099367; Mon, 07 Jun 2021 16:04:59 -0700 (PDT) Received: from localhost.localdomain (84-217-56-54.customers.ownit.se. [84.217.56.54]) by smtp.gmail.com with ESMTPSA id v9sm1999563ljv.131.2021.06.07.16.04.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jun 2021 16:04:58 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Jun 2021 01:04:14 +0200 Message-Id: <20210607230414.612-36-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210607230414.612-1-dcnieho@gmail.com> References: <20210607230414.612-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 35/35] 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: odGassCG9c2F 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 | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 9af3360317..c0032ae726 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -834,7 +834,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 @@ -860,6 +860,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: @@ -1173,7 +1176,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. @@ -1500,12 +1503,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; + } 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; + + if (!ctx->device_filter[devtype]) { + // 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; + } return 0; } @@ -2175,6 +2185,7 @@ static int dshow_query_ranges(AVOptionRanges** ranges_arg, void* obj, const char AVDeviceCapabilitiesQuery *caps = obj; const AVFormatContext *avctx = caps->device_context; struct dshow_ctx *ctx = avctx->priv_data; + int already_opened; int backup_sample_size; int backup_sample_rate; @@ -2214,13 +2225,11 @@ static int dshow_query_ranges(AVOptionRanges** ranges_arg, void* obj, const char goto fail1; } - if (ctx->device_name[0]) { - av_log(avctx, AV_LOG_ERROR, "You cannot query device capabilities on an opened device\n"); - ret = AVERROR(EIO); - goto fail1; - } + already_opened = ctx->device_name[0] || ctx->device_name[1]; + if (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)) { + if (!already_opened && !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 fail1; @@ -2336,7 +2345,8 @@ fail2: // clear state variables that may have been set during the above process // (e.g. frees device names, removes device_filters, etc) - dshow_read_close(avctx); + if (!already_opened) + dshow_read_close(avctx); fail1: if (ret < 0)