From patchwork Fri Jun 11 20:31:04 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: 28232 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp767564iol; Fri, 11 Jun 2021 13:41:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxfIqFxndi8DIMRRtsu7nb7DFMhlxUxxfnTnQN2TW7ZqzovkX/FX03w7shEdcUVlXk18nl X-Received: by 2002:a17:906:d0c9:: with SMTP id bq9mr5161686ejb.313.1623444064839; Fri, 11 Jun 2021 13:41:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623444064; cv=none; d=google.com; s=arc-20160816; b=XwagRn3mxdtxvJdUgWn37/wqijAlE7nUhgK0AeKBKB6gpdEhuBgUG9hl6b/6e7SK87 pyLHaM2XKU4C1mKe+2NQd0whJYEk9JXYwMW6J4JZ6emO8eSHYKQ5dGbjJVALuidmjVpb QGLxm0yqTB/P65SrsObTu33a+Xxw30+bcnP2Rek8l/o92XDNJygud/CjQf3fUfSaHBCt xHEosXp7lQYsIFYDaJIFW3bKNOjmSxfVkyLMgnrIHcouDb2FIalBOT4ueMBfccyHcImb Q2LhU03OHBS/RV0ia4NjSEqQOkz9jQoIfKx2RU6tvpHKk+hXL8yjwsPiXA31OkWl8bfH uNag== 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=e/47X675pQoa84E5wTliarzUsXZmDc6HwrBOBdhBxOw=; b=PaTvKO2M2yOMKOeXQxabXnhkFcQxj13jf6c/2bLKP5wunItywK2f4jTqfVrnQpoGxh E3/In98nogtHJvJ1MTdCkBOralw8i1bTQdhg21IDSL4yS+gyzfQg0hKkD9e4u8GkxgXd 4GArLPDXFfmq3Yuss7zSSwJnA9r+r2ym1N9AXhFg8KuZbPfARONCLebHgcCugy4ljtrx jJ/MyhWvc/9rM0CLyEvHQxCyKcuBQyjMEQivBYpdhsPYYW2oDy4yzUKVYafQ5rgJJLLJ tWJzkYpDRfef78l8lHuroQUf1VcfEZwj0PuRRHj6b+DenzaCTZqDCkLQ1hhRBX4IT/sx 56AQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b="cV/whrbO"; 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 i16si5672938ejo.417.2021.06.11.13.41.04; Fri, 11 Jun 2021 13:41:04 -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="cV/whrbO"; 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 D0E55689B7F; Fri, 11 Jun 2021 23:40:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3B6136891F1 for ; Fri, 11 Jun 2021 23:40:57 +0300 (EEST) Received: by mail-lf1-f45.google.com with SMTP id p7so10401746lfg.4 for ; Fri, 11 Jun 2021 13:40:57 -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=44o2W9uZemXMa+mDxhh0Dbo3YYfEl238oBpq5Oxh56M=; b=cV/whrbOVFxNGF5MTCArc1xIbtUKVZlfmj8XCwoeMn7qQEMz0WTJri9sCxjglAh9AN 1TVJH5PaPAni+Yv6YuuuRCYibSbBaMv+8tsMNIQGO1rUOS+6VPTvJzRXQxhwn6C2Ns5M SFuRRjgGmegXwm3qppQKDkJ5XLL/3A39WADKOfy2W6lA+KTdvKndeeIEoqD78N6aWys+ 14clYnOG1RbYm4HlegYY1ObStB0NBB4RQddEygnewJRMzCH727T02tGlSFZj+bFfAZxy RWzw3aaESHPJTKv//kMUyKwrQpQkEZj+ipZm9eRfvFI/neCUZM4mZ4fDh+beuCgOj6VK DB4g== 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=44o2W9uZemXMa+mDxhh0Dbo3YYfEl238oBpq5Oxh56M=; b=UXqBO89mKiMnQXqDRhMlMfDbRGCpPBX+9XF10YSVsQNy/QubbrqIqSRakBrZAnwwcn nLHNqXesvMa0NqBNhVLwm3ctqHqNUxNjxtjKaYMiSgnN/nf4G+im/N16dQ4cheC8FPyq dtRCLqRlEQKPS5nVq7YRawdY0ZvMvgN/ZQV9vGdbQL5z8oLIKBjO41JN4FaSb7O2DU0P vE4hZVydCLm1cejr5iEyRFgC+HwjQaMjS1PRNoIqW9xHYBJE0/bNAs1kQNynZ5wGhP/g T/XxHcX5OFQYHK9EyzyqtMiXhuObwg7wcWJH+AMKC0Yo3SytNkcukSsAUey4ucZsRXwj S6kQ== X-Gm-Message-State: AOAM530PK/+CDb+LWkUtneiCXplBld2nLvHIEsPDj8ysmejNJETQ23T1 7bVSiJBn+jibeVjuPbZNNucrTubfxlaz2A== X-Received: by 2002:a05:6512:3a85:: with SMTP id q5mr3673243lfu.404.1623444057165; Fri, 11 Jun 2021 13:40:57 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id u8sm846782lja.77.2021.06.11.13.40.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:40:56 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:31:04 +0200 Message-Id: <20210611203104.1692-34-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 33/33] 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: Kbtq+Qb9wxIy 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 d3937df41a..11fa71db13 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -853,7 +853,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 @@ -879,6 +879,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: @@ -1187,7 +1190,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. @@ -1513,12 +1516,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; } @@ -2188,6 +2198,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; @@ -2227,13 +2238,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; @@ -2349,7 +2358,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)