From patchwork Tue Dec 21 12:12:28 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: 32778 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5360316iog; Tue, 21 Dec 2021 04:13:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJxQbqVDZ+Q7h9Tffm3gddIC7SU4I5DDb4HvYOUh1LC6F9taX5WDSld41sAcrhZkFMwS8EgU X-Received: by 2002:a05:6402:5106:: with SMTP id m6mr1378707edd.169.1640088797140; Tue, 21 Dec 2021 04:13:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640088797; cv=none; d=google.com; s=arc-20160816; b=ciBHmrw5wRuNzsIgvteO8RPYKvaefhkt0iclg2Mw0mpJAo6HZSGDaqZ+N5DQpQ25Zy pBRvAvp0rvkxXQHGnRW19MP1k+N7GMybcyLQSsYvedn2UyfDedatlI3gzxGsKzXGMAvg ZQCyZRluc93NCrG5rAk7tTJqhw70n4naOVazok1VsNAHJm54iNWMXhMvYh3JcrPTfsLs vFgqADHLKqg7kH0O6Qvw0/4IrY5x1xSF4hhL+ojB583i5Q/DBv/ltMKX6a+9bAtsx2qV z3x5pm+LiIWyji7VuhKYDyV/EJs5QsRkb9rxT6UO3XeBcBzSqbNWlbaaW4C83LXLDT62 LQhA== 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=m/s5EPvZLYo4YA+rc8/KGNmrJHguYkJqkJTYyTZicHs=; b=QW1NdeKTdJmjPjL5jGg2Rlwibr+AWQfuV9gdvj1qW33x9odTJEaYrB/w+loY28lv+T tEx3nKJrTpzSfjzCxMgfGBzBMm75PSGfdvOt3xdPMj0c/oir+KFQlcrUUChRpN93F1xO Z5wy9FnSMYHFtrKB+LF5PjcZE/9zRXNH5zM0eOlPmXsCRl5tbBVCarQlp6V0tdBlpZt0 mBc8uZVlynDkBhbc0tLn686brSRobfumzW+hQxE6MiWMKFOos6FsaRuEZFl9+pBRelxH 2iOKVJ/mmhQx6GBcjqT0w59nZZR67W5YW+95gDq7SApp3yTubmucbRZFe74qAubpe6yI 7qCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=AvnK3ci6; 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 o1si3340167edc.214.2021.12.21.04.13.16; Tue, 21 Dec 2021 04:13:17 -0800 (PST) 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=20210112 header.b=AvnK3ci6; 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 A660C68AEDD; Tue, 21 Dec 2021 14:13:08 +0200 (EET) 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 9800268AE95 for ; Tue, 21 Dec 2021 14:13:01 +0200 (EET) Received: by mail-lf1-f46.google.com with SMTP id g26so13050993lfv.11 for ; Tue, 21 Dec 2021 04:13:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=n4ECdPBbt8xqX/bDaPPPd4LEZ+alPN7BkD4xWH+ML2s=; b=AvnK3ci6hNOhWxThDfN2Bhrpawvtfpcgh/HNlvO+Xt/Fk+UYY/b9ikIdU2nH0sxXfc AU1ghM9neafM3XruwpCLhXqvUbnO6Fv1dKAV2DviA9E/JMPkfdQvNp/5v4FpgqU77GEY NBj1y3IgALLjNZTSr3EBeUPkUQDAXFRhbLtxUl7BwmXy+DQJJ0mYsLMAavSg6MpMeGXo DEijy14XJctx4Fuw4sDptQivoaLeC3jVfDaG3c0aGPiSrAAvhN0C7NkLwk5W7SNCqLzJ htZ4OZbQu+RIwnMBqJA2pMDnZCRM+STEUkkhARYowzcTqnoVV61pLMST5vaan9CKdDvn GgcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=n4ECdPBbt8xqX/bDaPPPd4LEZ+alPN7BkD4xWH+ML2s=; b=ogZLCaVcAzJ7cuVx1CgmzlH5V7LvCpiQbwQBFKN2BzR7YO0A8Eu+lmeJceWKYVFl5n qpXi+kSbaxrP5T0ffyMNofXnR1HDQokAtULmlG4NpO/C3v0t4exr0TZb48FYNsnYrKS7 BhcO5JxCkL4UwZjsgGLVr9rWLpy4c3jqfbfiMfqTQgl95rB+x8DXN6rPdxcloCFe1VcL BvE1q1clo7Y9+cFcJhN7KeAvbhoooOHVxQg10sTq8F7q+KTW7Y63ctmTqOrPdD9icJQ8 /pEsRZ3OecANSiTdRpmqvveQ0oiktJoNEHq9sZNRjfNaNnthyqIGw5/of6ikHAe/n3fa M1JQ== X-Gm-Message-State: AOAM530ht/1IHEAHSDjDYYYR5HA/fJKBRPZaYlpfAwOSkUuUXVo36gBH 7ulhU5NcqHKusOIEDJefKZ39YFCo4qBRYg== X-Received: by 2002:a05:6512:3b13:: with SMTP id f19mr2763696lfv.305.1640088780761; Tue, 21 Dec 2021 04:13:00 -0800 (PST) Received: from localhost.localdomain ([196.244.192.13]) by smtp.gmail.com with ESMTPSA id p4sm245760lfo.9.2021.12.21.04.13.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 04:13:00 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 13:12:28 +0100 Message-Id: <20211221121239.1201-2-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211221121239.1201-1-dcnieho@gmail.com> References: <20211221121239.1201-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 01/12] avdevice/dshow: prevent NULL access 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: EMX0RGycGn/y list_options true would crash when both a video and an audio device were specified as input. Crash would occur on line 784 because ctx->device_unique_name[otherDevType] would be NULL Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index ef78781865..cc0bef0474 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -708,9 +708,9 @@ dshow_list_device_options(AVFormatContext *avctx, ICreateDevEnum *devenum, if ((r = dshow_cycle_devices(avctx, devenum, devtype, sourcetype, &device_filter, &device_unique_name)) < 0) return r; ctx->device_filter[devtype] = device_filter; + ctx->device_unique_name[devtype] = device_unique_name; if ((r = dshow_cycle_pins(avctx, devtype, sourcetype, device_filter, NULL)) < 0) return r; - av_freep(&device_unique_name); return 0; } @@ -1143,6 +1143,7 @@ static int dshow_read_header(AVFormatContext *avctx) } } } + // don't exit yet, allow it to list crossbar options in dshow_open_device } if (ctx->device_name[VideoDevice]) { if ((r = dshow_open_device(avctx, devenum, VideoDevice, VideoSourceDevice)) < 0 || From patchwork Tue Dec 21 12:12:29 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: 32780 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5360594iog; Tue, 21 Dec 2021 04:13:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJzIIPVlGFKshSHpwt0cTb/U6gNznLHki2DooEx5eELvvmVB7DvDbVqEzirshA2AmT82f+91 X-Received: by 2002:aa7:d957:: with SMTP id l23mr2958032eds.116.1640088820375; Tue, 21 Dec 2021 04:13:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640088820; cv=none; d=google.com; s=arc-20160816; b=keunslx7mBvidNPcQYl1FPoVELK3UPkZwBSWcuiudYSF2F7M7XNnHWot/KFMvNn6Sv cZGZRBG2f0JLOrjBKfLHKgkavmFBi7mKHTTMYfRw0DoFa57W1TY8pIgWIRR/OyrPseA/ w2g7UZ3FzWsj7kyATf5dGOe5zJ1UHNHRV75D/FN56Ql595WDdeL6C8aQoRAe2tDEsabI odcxphfIOku0eaZgMG5XcihZBDCpDO5O40H7lzMYhJVuIvE5mmmOf3ipos8GOVbswr6K J9MadZVExs7xIYr/Qkv/KsaeRFzYOcd3D4T/hyPMZolhqOPnAuvX1QRXlb7Hs7nOl/K7 L9Lg== 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=FvjjeTXn/ZrJRmlwOsosC8ne9WQHJ1SgG/qOy+hTado=; b=p74bRG1SHsOxdhLS7NFN2D/zqsM+kyEiodis5dbtIiTdNfcshcIR8lu1sHW6F2mAg4 s2I2uIGs1IQMcKzNEHc90vbOAWLfHaoFlynwwafsi9JcbGCmEUEvaBF3U0U+RxHeFDF+ wpOoeQQ2VteoYgo7bM/dsJmqRgMOzpLCOC1YXQ+/ey20OHhd1wGVvbViFgFAAyIsTSgg NN3BWKDOZeot6w+QtsuUs/4D4QxpzYMIxLY4Uj0ocAwTJ0uoE2/WukQucZzdm3a3FzBL 1plhDaEm8xUZgJia7X099JnBMI0St/E8+rahlkAZ1vD1a89QRou/Fu1ckdXoWHxGUc1w L+zQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=DUl+NLMb; 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 nb7si14314936ejc.685.2021.12.21.04.13.27; Tue, 21 Dec 2021 04:13:40 -0800 (PST) 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=20210112 header.b=DUl+NLMb; 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 A0A8068AEFD; Tue, 21 Dec 2021 14:13:14 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3C8E468AEE9 for ; Tue, 21 Dec 2021 14:13:08 +0200 (EET) Received: by mail-lf1-f50.google.com with SMTP id bq20so27810031lfb.4 for ; Tue, 21 Dec 2021 04:13:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4bcGWxKvvhbdpCAlfdAHzJCUilMj1GVE3tthIhcqlAk=; b=DUl+NLMbMBfFhX8tdl9Se6LwgczjPVNaRxt/uUX2B9xEF+9c+cYXX3c5zhzLPOf1t+ 34c3s0R6aiVLDUoyL1n3LzlrkyTj0AxDSFK+8G/TLfIff3R7WiLh32kNCkUOCZrKJqxW vR8Y3al7ehtZZ5TOd0vNtvIsZ/gRdUp2GFujsfVY2ZYJTEovQ72vh7qaqyiIB5WV+olo IguhV2AMVHTsW0NvIc3ld02FOsCoBrvbRTH+hjzduY3H0r7d7MEF/gNqty2qlA0kYXW8 0LxU4uqVHOWaSriL3pF2l7whJCzn1hHqAaMpB0It8/elJV3+hsLHVIv8VuKqSxysZRge 4jxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4bcGWxKvvhbdpCAlfdAHzJCUilMj1GVE3tthIhcqlAk=; b=lWeoMBbgcfUGypylEH4FvvlrMd7r/0tXcpn+K6p6mCxp6qHlEXKuCyWhaw9U8M7ojA j/SKjwghUk9yqnMXbnijXy2WGVHEVRldl3/wYBem3BfQ2iGZDrQ/BXlSUISK39YRBv/X rMgaHwCCVtM2rx1A6bd8xkmwAbN0vVl0hA5Qaa0oCBq7+1Qs5HXvULTNDDPkb+RrwgCY JMJ1LmMuu1JAYfX0jPazuBIOU7BVo/VCgfR3FeEv9W0HUS9wnPokWBMny0eTfrgbADee LKxF3n+galjNIrGo5+con1J2SHnnxWSEGhnG8euAWIsZJweXjBGlIhkgXZCVY0nblyMc qfbQ== X-Gm-Message-State: AOAM530Ys5p1+IyLJHH+stFkbiLsH7wWqLyfkK77z/JEGwoWjUmqn1dY F2H8Rsb/x8+kcWmpsnArsb+FbpsymVRRzw== X-Received: by 2002:ac2:59c8:: with SMTP id x8mr2772632lfn.573.1640088787255; Tue, 21 Dec 2021 04:13:07 -0800 (PST) Received: from localhost.localdomain ([196.244.192.13]) by smtp.gmail.com with ESMTPSA id c20sm2724671ljf.37.2021.12.21.04.13.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 04:13:06 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 13:12:29 +0100 Message-Id: <20211221121239.1201-3-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211221121239.1201-1-dcnieho@gmail.com> References: <20211221121239.1201-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 02/12] avdevice/dshow: implement option to use device video timestamps 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: F3RXxYWyf0qt The dshow avdevice ignores timestamps for video frames provided by the DirectShow device, instead using wallclock time, apparently because the implementer of this code had a device that provided unreliable timestamps. Me (and others) would like to use the device's timestamps. The new use_video_device_timestamps option for dshow device enables them to do so. Since the majority of video devices out there probably provide fine timestamps, this patch sets the default to using the device timestamps, which means best fidelity timestamps are used by default. Using the new option, the user can switch this off and revert to the old behavior, so a fall back remains available in case the device provides broken timestamps. add use_video_device_timestamps to docs. Closes: #8620 Signed-off-by: Diederick Niehorster --- doc/indevs.texi | 6 ++++++ libavdevice/dshow.c | 1 + libavdevice/dshow_capture.h | 1 + libavdevice/dshow_pin.c | 11 ++++++----- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/doc/indevs.texi b/doc/indevs.texi index 5be647f70a..9d8020311a 100644 --- a/doc/indevs.texi +++ b/doc/indevs.texi @@ -625,6 +625,12 @@ Save the currently used video capture filter device and its parameters (if the filter supports it) to a file. If a file with the same name exists it will be overwritten. +@item use_video_device_timestamps +If set to @option{false}, the timestamp for video frames will be +derived from the wallclock instead of the timestamp provided by +the capture device. This allows working around devices that +provide unreliable timestamps. + @end table @subsection Examples diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index cc0bef0474..5e6eb9c85d 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -1310,6 +1310,7 @@ static const AVOption options[] = { { "audio_device_save", "save audio capture filter device (and properties) to file", OFFSET(audio_filter_save_file), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, { "video_device_load", "load video capture filter device (and properties) from file", OFFSET(video_filter_load_file), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, { "video_device_save", "save video capture filter device (and properties) to file", OFFSET(video_filter_save_file), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, + { "use_video_device_timestamps", "use device instead of wallclock timestamps for video frames", OFFSET(use_video_device_timestamps), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DEC }, { NULL }, }; diff --git a/libavdevice/dshow_capture.h b/libavdevice/dshow_capture.h index 06ded2ba96..5a2691518c 100644 --- a/libavdevice/dshow_capture.h +++ b/libavdevice/dshow_capture.h @@ -312,6 +312,7 @@ struct dshow_ctx { char *audio_filter_save_file; char *video_filter_load_file; char *video_filter_save_file; + int use_video_device_timestamps; IBaseFilter *device_filter[2]; IPin *device_pin[2]; diff --git a/libavdevice/dshow_pin.c b/libavdevice/dshow_pin.c index 3dae405e65..8e56dccbfe 100644 --- a/libavdevice/dshow_pin.c +++ b/libavdevice/dshow_pin.c @@ -309,10 +309,14 @@ long ff_dshow_meminputpin_Receive(DShowMemInputPin *this, IMediaSample *sample) if (!sample) return E_POINTER; + priv_data = pin->filter->priv_data; + s = priv_data; + ctx = s->priv_data; + IMediaSample_GetTime(sample, &orig_curtime, &dummy); orig_curtime += pin->filter->start_time; IReferenceClock_GetTime(clock, &graphtime); - if (devtype == VideoDevice) { + if (devtype == VideoDevice && !ctx->use_video_device_timestamps) { /* PTS from video devices is unreliable. */ IReferenceClock_GetTime(clock, &curtime); } else { @@ -322,7 +326,7 @@ long ff_dshow_meminputpin_Receive(DShowMemInputPin *this, IMediaSample *sample) like 437650244077016960 which FFmpeg doesn't like. TODO figure out math. For now just drop them. */ av_log(NULL, AV_LOG_DEBUG, - "dshow dropping initial (or ending) audio frame with odd PTS too high %"PRId64"\n", curtime); + "dshow dropping initial (or ending) frame with odd PTS too high %"PRId64"\n", curtime); return S_OK; } curtime += pin->filter->start_time; @@ -330,9 +334,6 @@ long ff_dshow_meminputpin_Receive(DShowMemInputPin *this, IMediaSample *sample) buf_size = IMediaSample_GetActualDataLength(sample); IMediaSample_GetPointer(sample, &buf); - priv_data = pin->filter->priv_data; - s = priv_data; - ctx = s->priv_data; index = pin->filter->stream_index; av_log(NULL, AV_LOG_VERBOSE, "dshow passing through packet of type %s size %8d " From patchwork Tue Dec 21 12:12:30 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: 32779 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5360564iog; Tue, 21 Dec 2021 04:13:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJwYybd/A4vp3DFQW5kh4e7bwtJAeR/CyQUkht5uCx8rtGnV4sODpV+XmeoVNhM7tPL27+qv X-Received: by 2002:a50:c38c:: with SMTP id h12mr2983798edf.72.1640088818104; Tue, 21 Dec 2021 04:13:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640088818; cv=none; d=google.com; s=arc-20160816; b=rnae1eKdUCDWjj913WdODikvP68xBg2YoODNhPbLr29+y0q1d3k1OH6fEhDb2khLhC uYvnQmGU/rlh7NELL++UQ9aOUud45gev281dPrpil3yQn975wIVp4fEpofqNVLW1f+iE N/Hjp3JBhh/YrSye7PcvC1KFnbie/ahSwPnbIJJTMiIxuNFwQk6aEDQjbbi4bAa4a2W1 VE5PvAvqqxw4CCjnqP0v8o7MnR7AtABAq5wzPGVirBMt/09Y5d+R04RFow9mkwRrtcqv GpfyIQ1InswTGLnAMFrQ+BwPB24VL1JrtzeXcDvzDpTB7XrEkXf7c64itKB8KsTI+vrn /ZOA== 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=pa/7AoG/Tn1IKWdkErCmAui2uj/lRNPvOKfWL9u3LsY=; b=Lze6Y7dY7Y3kbn0Na3ee1B8/pJnkhV6ikBxsKItto8SSzd9zrf4cPVxmjPoFMlh/Ov gKJL52GTlAhY7RcpGIASMvvUpHB08uyEVOmbnMD8YQGnnIUFVp0ec6GhhcP79+PU3keO EA6u5eVVHuLDjn2uVRa+j3S9ghsh/KIZ3TPed0st46RgnXUzmbilQHm8h3mlq84tq4ug fGRbOEDrzOe6u7Kbqj8rPJ2TAvy6bJ3/YptrKqFo5+RwyG7hkTEU7cZqOVBpqKYMi7FY tCnie39xm3B/P/FJhmM/qfcmi0qlO9f8Z+QmKmuMbP2ZeXhZzK0cb9vNIqnVbu1m1UDp 6hmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=ZCAODhnJ; 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 dz9si6080953edb.335.2021.12.21.04.13.37; Tue, 21 Dec 2021 04:13:38 -0800 (PST) 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=20210112 header.b=ZCAODhnJ; 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 9B91A68AF3B; Tue, 21 Dec 2021 14:13:21 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 141F368AEEA for ; Tue, 21 Dec 2021 14:13:15 +0200 (EET) Received: by mail-lj1-f178.google.com with SMTP id a37so21050760ljq.13 for ; Tue, 21 Dec 2021 04:13:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tLBGkU73btm2UY8VXqRWlX4bo6pvicPCF5lFX+SbDcM=; b=ZCAODhnJ0GTL3pPftF3YNiiIyZ0tIRUOSkKcKh+nlGQoNEAUyA46G2J2oVu89yfCBs cuTEjfwntkymRy4kMXccX3ZBlkWhAMgIXxpyyJd8j/u8Wp1xiAv2R0mVMD55QzjEpZxK sY8km9Zzi+ohjmc2fVMw3Enimr65z/o8sbeOlQsMEbrYMKSTqg7rJqaX2nLcGPDY/cGH P9AqvFP6Uzag5kRAee0PmmA45vBv2LUtrCwcUExfOkxt8nNCR3SfAlSKSxptykCZdrqf IDnbcBEih1WFJ1ZDtOdsGXj4U/PoYUn/nRTMgnyv+PQMa2CNqnl2laHCnJool9IJhiIO qOrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tLBGkU73btm2UY8VXqRWlX4bo6pvicPCF5lFX+SbDcM=; b=wxMn5SPfPCDTLKqfiLM1R4wsPQV8efs086v26nayx09pbr0b67k45FYKLtUqtwayzl AlX4O2zzRH7QOdj3yZW0zBgONe4Ba76KLxUOBwwY0GaeukJZ/GzYTBZZUrmHcqBB3NgC wyGQao+r2uF71Y7Cz0r31A3AYXKO+PoXUd8QotujwNFoqat6LgPimQGMapD8uGU5tQ/f /YrkULUB7FIoZLeNDHqVUg6xUnYUJhRPP1oEIW04Mgl5J44nRRGXcoG0jkDxr3SoM8Wf QMgQtme9qUP4r/IuiNWlA/w+YlhfdWvU3oNdAFg64GFX27mWgkye2hcm57m/Y9D/ucE8 Ln4A== X-Gm-Message-State: AOAM531CAgaa6u6FtJj0/w1VXo3q2GEbcTTGj0NCUyYmWjN6mPHYc0My xWpth7TfOpA2kD2U0HfpLwzd13h/kWzpIA== X-Received: by 2002:a2e:9617:: with SMTP id v23mr2277938ljh.363.1640088793693; Tue, 21 Dec 2021 04:13:13 -0800 (PST) Received: from localhost.localdomain ([196.244.192.13]) by smtp.gmail.com with ESMTPSA id d5sm554482lfv.83.2021.12.21.04.13.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 04:13:13 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 13:12:30 +0100 Message-Id: <20211221121239.1201-4-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211221121239.1201-1-dcnieho@gmail.com> References: <20211221121239.1201-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 03/12] avdevice/dshow: query graph and sample time only once 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: UqEVnUbcL/B4 No need to query twice, use value we've already unconditionally got. Improve variable names Signed-off-by: Diederick Niehorster --- libavdevice/dshow_pin.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/libavdevice/dshow_pin.c b/libavdevice/dshow_pin.c index 8e56dccbfe..1d0e880480 100644 --- a/libavdevice/dshow_pin.c +++ b/libavdevice/dshow_pin.c @@ -295,9 +295,10 @@ long ff_dshow_meminputpin_Receive(DShowMemInputPin *this, IMediaSample *sample) uint8_t *buf; int buf_size; /* todo should be a long? */ int index; - int64_t curtime; - int64_t orig_curtime; + int64_t chosentime; + int64_t sampletime; int64_t graphtime; + int use_sample_time = 1; const char *devtypename = (devtype == VideoDevice) ? "video" : "audio"; IReferenceClock *clock = pin->filter->clock; int64_t dummy; @@ -313,24 +314,27 @@ long ff_dshow_meminputpin_Receive(DShowMemInputPin *this, IMediaSample *sample) s = priv_data; ctx = s->priv_data; - IMediaSample_GetTime(sample, &orig_curtime, &dummy); - orig_curtime += pin->filter->start_time; + IMediaSample_GetTime(sample, &sampletime, &dummy); IReferenceClock_GetTime(clock, &graphtime); if (devtype == VideoDevice && !ctx->use_video_device_timestamps) { /* PTS from video devices is unreliable. */ - IReferenceClock_GetTime(clock, &curtime); + chosentime = graphtime; + use_sample_time = 0; } else { - IMediaSample_GetTime(sample, &curtime, &dummy); - if(curtime > 400000000000000000LL) { + if (sampletime > 400000000000000000LL) { /* initial frames sometimes start < 0 (shown as a very large number here, - like 437650244077016960 which FFmpeg doesn't like. + like 437650244077016960 which FFmpeg doesn't like). TODO figure out math. For now just drop them. */ av_log(NULL, AV_LOG_DEBUG, - "dshow dropping initial (or ending) frame with odd PTS too high %"PRId64"\n", curtime); + "dshow dropping initial (or ending) frame with odd PTS too high %"PRId64"\n", sampletime); return S_OK; } - curtime += pin->filter->start_time; + chosentime = sampletime; } + // media sample time is relative to graph start time + sampletime += pin->filter->start_time; + if (use_sample_time) + chosentime += pin->filter->start_time; buf_size = IMediaSample_GetActualDataLength(sample); IMediaSample_GetPointer(sample, &buf); @@ -338,8 +342,8 @@ long ff_dshow_meminputpin_Receive(DShowMemInputPin *this, IMediaSample *sample) av_log(NULL, AV_LOG_VERBOSE, "dshow passing through packet of type %s size %8d " "timestamp %"PRId64" orig timestamp %"PRId64" graph timestamp %"PRId64" diff %"PRId64" %s\n", - devtypename, buf_size, curtime, orig_curtime, graphtime, graphtime - orig_curtime, ctx->device_name[devtype]); - pin->filter->callback(priv_data, index, buf, buf_size, curtime, devtype); + devtypename, buf_size, chosentime, sampletime, graphtime, graphtime - sampletime, ctx->device_name[devtype]); + pin->filter->callback(priv_data, index, buf, buf_size, chosentime, devtype); return S_OK; } From patchwork Tue Dec 21 12:12:31 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: 32781 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5360721iog; Tue, 21 Dec 2021 04:13:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJzHE+by6UqOF0Ehkxn2U9yqU7u7gf7RLWKYvJpDk79iGLb/TC82vBr+/s0rNnJzxIvbdjaY X-Received: by 2002:a17:907:7fa4:: with SMTP id qk36mr2378620ejc.308.1640088830874; Tue, 21 Dec 2021 04:13:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640088830; cv=none; d=google.com; s=arc-20160816; b=sj+CwWTW3Xa+2txLKEAr1DGZoz0eN85S50QFMcTNNKtaxXJrqTFdIOIg9F310u8A2x ZRyf4CI1PBd7vANBOrTrDz1Kbu1AoSoaKjg/3koduwhpXPRtCfAE52eAGTR5egdrrrrM i6HnuuEbLKAGqlCDxfP/bkThD7NikSS2PxPNRUyPaK70YRDfOxp0Ztk0XSH7KhVSKT0D UNh0dfBDuR3H1I0jdnifg2qKbLOR9b7QzZpotaT1F8BxI8EHgF8n+SX6ELBH2CPH6VgN TeUknNClinR/AHSvUuYQLmsF6yDMUR68+QEzryxF/jVjrc8lguN9sVnv8SgDZAAufmx0 byCA== 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=bvagzn3t9ZMTbvWzqNQ6CQDKu2uFNdHK7+XCxBMIVPs=; b=mrwBOfVNRlT0TajnJnWbAVI2b/IXGCDgP5Fy2xlyI0mTRTEfLSnWDY0MLZQNj/0QSU qyG0LRI7rCL4aFRL3mMltRt7R6O/Q+ryi0uKAcIf4n0eWeRlS4Bn5Vg2+njoNk8WkfQn iq2hEJ7qvajESxTaW9swlwOGJm1ZQskefxxZH0IVWAhwWBrYWhf5mTdYDNFAvvXJob2R hsmncQ4vS6B2eKE7PmfY8Znp5SYh0uf9s181HWzUX5ItEgMl17huuk6JLPuqqZT3w8IP O+58am7wFiVL5gmAWd94mA7jMLO1X4Pk88dTdL1SWuRxqwHpDSO/iBuGbwh8v6xQlW3U rYgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=iG7y3Kb2; 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 p20si11643683ejl.775.2021.12.21.04.13.49; Tue, 21 Dec 2021 04:13:50 -0800 (PST) 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=20210112 header.b=iG7y3Kb2; 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 84A5068AF69; Tue, 21 Dec 2021 14:13:23 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 02A0668AEEA for ; Tue, 21 Dec 2021 14:13:21 +0200 (EET) Received: by mail-lj1-f179.google.com with SMTP id v15so21175463ljc.0 for ; Tue, 21 Dec 2021 04:13:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DA8hT6RJYqezw3uqiFxtsp6o5kao2G6PRwqIa6ifWcI=; b=iG7y3Kb2LT+5YNXmZYn4PptR00pD/jTjtIpfNc6aEvk3uAx/N4mCS58rEG0gVYe49L 2jYVBfGOr/X4C+0HXCyip4Z/O2yDNnXiX7FClYn4VD0CbuzJ0uLpte0sdAD3wm1kAqTv VovXx5Ud8d8hVyXf+YAUF1UrYmhovX2XDPRcyqV7gYYE/VAbketsnjq5dEy/0YJp1Sz9 eolDXcbg7gp8QsT0GKfXykE0Q4E3hYfv9NzSP8zf5GffZkSYPQZMw78PVzo74bzUlehw OUVWirBxb6QWvWxu3KkBMA1IHj+zjTySqvg3S12UDuXgywdIIlrsU6trO7gVIxHV2ZHj r1yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DA8hT6RJYqezw3uqiFxtsp6o5kao2G6PRwqIa6ifWcI=; b=YbJ4UHbebPwJFBq9XGUbXJLYKNXIaolSsrRRDyETy8MErWlObR0T2nUreaXx6A4Uk8 kvxa8zn5loOIJvT8++2rL+tPyQqa7la0qxSHHQsdZu4T3BlpUAYMkVm4f3c2d8j0tch2 5hD/wBOzshY6RAKia235Ou4U4ZWg+LlOC0mtIobdaLIGwPF6imdjykJ3+npJmfqv/GKu YS1gbmYWWj0FCIp0c9fpxN6AXwPChRnIn6RYijcj6aHi8LssHDrt9Eu6xemB/Mjtb+e8 ZKKdbWa36DTpfD9U0i67jWWWin8ecZeHGoWOW/7wmFREJphSNffaU+ymJmWse9ZLHP1+ plBg== X-Gm-Message-State: AOAM532LTotUSSMlQj9AMhVWioThpzK9xgxoOB/pq8VEDudbJhyuigF+ 57l4yrAkhHXrqRBbiRwQvnwQLeA63dVkyg== X-Received: by 2002:a05:651c:17a6:: with SMTP id bn38mr2363920ljb.413.1640088800150; Tue, 21 Dec 2021 04:13:20 -0800 (PST) Received: from localhost.localdomain ([196.244.192.13]) by smtp.gmail.com with ESMTPSA id x5sm2099035lfu.145.2021.12.21.04.13.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 04:13:19 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 13:12:31 +0100 Message-Id: <20211221121239.1201-5-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211221121239.1201-1-dcnieho@gmail.com> References: <20211221121239.1201-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 04/12] avdevice/dshow: handle unknown sample time 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: oK6GofBOGED0 GetTime may return an error indication that the sample has not timestamps, or may return a NULL start time. In those cases, fall back to graph time. Emit log when that happens. Improve logging in the frame receive function: now logged against correct avclass instead of NULL. Better debug message in case sample dropped: could now be audio or video frame. Signed-off-by: Diederick Niehorster --- libavdevice/dshow_pin.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/libavdevice/dshow_pin.c b/libavdevice/dshow_pin.c index 1d0e880480..2d1fa0e882 100644 --- a/libavdevice/dshow_pin.c +++ b/libavdevice/dshow_pin.c @@ -295,14 +295,15 @@ long ff_dshow_meminputpin_Receive(DShowMemInputPin *this, IMediaSample *sample) uint8_t *buf; int buf_size; /* todo should be a long? */ int index; - int64_t chosentime; - int64_t sampletime; - int64_t graphtime; + int64_t chosentime = 0; + int64_t sampletime = 0; + int64_t graphtime = 0; int use_sample_time = 1; const char *devtypename = (devtype == VideoDevice) ? "video" : "audio"; IReferenceClock *clock = pin->filter->clock; int64_t dummy; struct dshow_ctx *ctx; + HRESULT hr; dshowdebug("ff_dshow_meminputpin_Receive(%p)\n", this); @@ -314,22 +315,28 @@ long ff_dshow_meminputpin_Receive(DShowMemInputPin *this, IMediaSample *sample) s = priv_data; ctx = s->priv_data; - IMediaSample_GetTime(sample, &sampletime, &dummy); + hr = IMediaSample_GetTime(sample, &sampletime, &dummy); IReferenceClock_GetTime(clock, &graphtime); if (devtype == VideoDevice && !ctx->use_video_device_timestamps) { /* PTS from video devices is unreliable. */ chosentime = graphtime; use_sample_time = 0; } else { - if (sampletime > 400000000000000000LL) { + if (hr == VFW_E_SAMPLE_TIME_NOT_SET || sampletime == 0) { + chosentime = graphtime; + use_sample_time = 0; + av_log(s, AV_LOG_DEBUG, + "frame with missing sample timestamp encountered, falling back to graph timestamp\n"); + } + else if (sampletime > 400000000000000000LL) { /* initial frames sometimes start < 0 (shown as a very large number here, like 437650244077016960 which FFmpeg doesn't like). TODO figure out math. For now just drop them. */ - av_log(NULL, AV_LOG_DEBUG, - "dshow dropping initial (or ending) frame with odd PTS too high %"PRId64"\n", sampletime); + av_log(s, AV_LOG_DEBUG, + "dropping initial (or ending) sample with odd PTS too high %"PRId64"\n", sampletime); return S_OK; - } - chosentime = sampletime; + } else + chosentime = sampletime; } // media sample time is relative to graph start time sampletime += pin->filter->start_time; @@ -340,7 +347,7 @@ long ff_dshow_meminputpin_Receive(DShowMemInputPin *this, IMediaSample *sample) IMediaSample_GetPointer(sample, &buf); index = pin->filter->stream_index; - av_log(NULL, AV_LOG_VERBOSE, "dshow passing through packet of type %s size %8d " + av_log(s, AV_LOG_VERBOSE, "passing through packet of type %s size %8d " "timestamp %"PRId64" orig timestamp %"PRId64" graph timestamp %"PRId64" diff %"PRId64" %s\n", devtypename, buf_size, chosentime, sampletime, graphtime, graphtime - sampletime, ctx->device_name[devtype]); pin->filter->callback(priv_data, index, buf, buf_size, chosentime, devtype); From patchwork Tue Dec 21 12:12:32 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: 32782 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5360912iog; Tue, 21 Dec 2021 04:14:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJxsWlD0QYLT7KYQgBdHqalyZ4AI92UpnvKXwb4edW0sLvUkIvaw0uLvGv9rC8xryXTYWpS+ X-Received: by 2002:a17:906:fc9:: with SMTP id c9mr2358419ejk.728.1640088848083; Tue, 21 Dec 2021 04:14:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640088848; cv=none; d=google.com; s=arc-20160816; b=TTvWmsiZ0cY7FAfEqI9GpHfblIikzvtein3U1BVYuRyxBEu1T4YCKBryPa6Jle/ORD rF2qDQ4/OFIuqMA1NbvsCJqTR9oy1ikGIRIFHpi1WSLB99yN6UhgnCD0hNOIOuf21v3P KAx59VqaTfzwBJ9zDaJdl1dtx7B2NChuty4IT2Nm+RZFTz4JwFYOBUvSut7vGF4U4jL5 +HSAUc07Wo8XrXgxx2Ryq4Egq6n6KpzzfZbjfHnTJmQN1/zQjWPKyk5Jem0ko2NqnCUb MXuEgLO9W5CPKT9tOvHWx600qHq/Z92qpIiWNuQ0szyLHObcfg4WbZWxkWuoLpkeSfUe nODg== 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=3j0QrtQQHAeI1Zzn+f4NBkwbXDFahor9ccyTUmhV678=; b=AHAHcTS3ZjbPFBQQocOwRQ4apkd8XewL5BtodomqpsieJ6UP63F4xKESP0mvctm0Y7 0AwK5giLGqtrXxTFaPUMPx0++HRGwBtnlf7p2gwGgdPWxV80riMJF8Muqdpool5kT5Yq hnGm5oKMjI/idiWbscbJkiVR0xo+gz+WP3XW/LOcYKMJ3Q4YtdQTqXuA/MLlZZ3K/Fj3 agCbwjdHXuaW1RFnq11c5dGNdUEpaX1qGyZ4/HffCT8mGN5uzwxtCuvV0+1PNwr3sDYy F/H0dJO1MX/1qhy8fLJmVNBEvX9EljoXyaTxjjATwToXMd4URfTSlk4oZ4YUjqLG6uMa qtXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=jTebabOm; 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 eg28si7678903edb.197.2021.12.21.04.14.01; Tue, 21 Dec 2021 04:14:08 -0800 (PST) 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=20210112 header.b=jTebabOm; 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 C14FE68AF7E; Tue, 21 Dec 2021 14:13:29 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0C2BD68AF6F for ; Tue, 21 Dec 2021 14:13:27 +0200 (EET) Received: by mail-lf1-f42.google.com with SMTP id bu9so7327578lfb.7 for ; Tue, 21 Dec 2021 04:13:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PRQUajDDzo0yckQUc1NGOreX/fguC3LwegFuv42BzkQ=; b=jTebabOmlfgB8TgDf25Lj5HuT1G0bSzEeeDJ5IYPptdYNM7E/wILjn429Pysi+4cXM HXtUITRF5LPzecYVr8LNKLb7EMLwx7k2Wm9F88PoZC/XcPvrwM72LpjX92qS8v7/Cxj7 Qp4gY2yKytlx4XZXjBEQVga5wNpf5UJ6UP+61mzaqJZfmmG1Cfe5NcZG1q/FjIx+QbID WroaCrig2wyHIEosrpWAsMyPKrH0JjjhL/WsePV1vhHFUDs7T3fR+ZRCpGtrVeaMpxWC vhylrwJYZSSXTm3l/lnoifIFFP+etzhZfle7vd/XzaaRg0E7qmhyl0aTythBVZ3eMVqT 8ojw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PRQUajDDzo0yckQUc1NGOreX/fguC3LwegFuv42BzkQ=; b=8EdIRD1y4R83otuW+z45feEDO4ABt2SGuuWVyzP+RNQQwT+ZCi+hWRhZvofL9fAKq/ BMsSZJfdvoUAM2t69Tsacd6kLQ9Tqd39NeyewC5/5avDuNJ1AK6x3ZP230WpphW3gzpz VK5hDTn3WZswYArgTAdh/GM1xQvbB/7lJXDfRSVYYHQZjz/u0rYJirdFqyxVUVpYcsVP ulFesL2U1xA4v+Bj0odLoBfv9EgGOB9OVeWuZJRt7aMsokGM2uQr55eq52ggtc0vQov7 +GvFqp1rJ+R1YP1LOMfCZ/3jbRl4YEe8DJQhoQK4/T57xJVzfoPneTFqeFPjbzrJcs/z tFdw== X-Gm-Message-State: AOAM530/Rpi5Zd2+cMrJ6F2WLtRjL5vn2w6i7SWAYH4qqBp1DmpWkZHh Dh/W+YbBjvkS+sb5tLJWIn+Lhjqzii+a+w== X-Received: by 2002:a05:6512:2111:: with SMTP id q17mr2816037lfr.285.1640088806691; Tue, 21 Dec 2021 04:13:26 -0800 (PST) Received: from localhost.localdomain ([196.244.192.13]) by smtp.gmail.com with ESMTPSA id b43sm2618823ljr.64.2021.12.21.04.13.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 04:13:26 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 13:12:32 +0100 Message-Id: <20211221121239.1201-6-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211221121239.1201-1-dcnieho@gmail.com> References: <20211221121239.1201-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 05/12] avdevice/dshow: set no-seek flags 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: a+0VmJSs4DCE avdevice/dshow is a realtime device and as such does not support seeking. Therefore, its demuxer format should define the AVFMT_NOBINSEARCH, AVFMT_NOGENSEARCH and AVFMT_NO_BYTE_SEEK flags. With these flags set, attempting to seek (with, e.g., avformat_seek_file()) correctly yields -1 (operation not permitted) instead of -22 (invalid argument). This actually seems to apply to many other devices, at least the gdigrab, v4l2, vfwcap, x11grab, fbdev, kmsgrab and android_camera devices, from reading the source. Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 5e6eb9c85d..0ef3b3d13e 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -1329,6 +1329,6 @@ const AVInputFormat ff_dshow_demuxer = { .read_header = dshow_read_header, .read_packet = dshow_read_packet, .read_close = dshow_read_close, - .flags = AVFMT_NOFILE, + .flags = AVFMT_NOFILE | AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK, .priv_class = &dshow_class, }; From patchwork Tue Dec 21 12:12:33 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: 32783 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5360993iog; Tue, 21 Dec 2021 04:14:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJzBmCUev3Vm+LXYEQv90ueMrYvqoBb2ir2GaQSnbu8eBIfKEC5nb2p8WF3pdskHpNWSRVhr X-Received: by 2002:a17:906:c444:: with SMTP id ck4mr2372839ejb.89.1640088852787; Tue, 21 Dec 2021 04:14:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640088852; cv=none; d=google.com; s=arc-20160816; b=ZIBOT5ZvNlpCki1TCclzaplZUJUw0p7rBRj66e0ld+2OG3YczkdwCZN7TJRmX2mUgH 9aJm2BFXd7On5p0GkA+PAyT8ud0l9EJVWfa6ICjnKCdUU2LzEPNdmRNsULC1cRrFIOl6 wyFPQx69jOS6PkFGGX4JcvTHr9n759rVJq3qRopssgSakZMi4nbD2tlRdp+ICIW0yuT5 F8skxd2neRxZ4gnWIY0SRCYvrOZugUc1hUdpiMVyKlAL5Km4DYROLVJMq/4czHgyk8S4 +jkdvBxSD1oUgubngTcEUuG6r9S0xwQSFQMbRZGv7X4UA7ptvwgbKTIMlVU1OE7rC17l 2jjg== 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=gwKU17KTV55I+hU7pJgZxuNPujnv+pcgLbvC+EZEKA8=; b=OIwL/GefXkJuMu+vz8u6KxponM73wSODsCaIc+IFrQfWmKoSNOjorrJebayUC8YsJr ILJcBy6ygMxJJ+SNkVosK3S1tLWiyZR7ONespf2n1JCqs0aQ9f0XD57IVdOfAVDivoLl fqRn4Ll+aVR5roBOoWkUudkajgAUtsEVpS1vd06FHzzYFJ0tNgc/SfOYfEln0eje7PK6 eAWPXJ/aLhJmMOi6lG5K78hVZf+GT7tLKQ0ba1ge9/rpJGxJw9Df2LMCEsI7KR+ndeeC HhqjSAxbwqL7gWTMzsDLF6WBqOMPDYqeYmJpA9R7ljQez+jmkewzKQEbbWuQEIQqENjS 8i4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=lH9NcQnW; 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 bm25si9998731edb.145.2021.12.21.04.14.12; Tue, 21 Dec 2021 04:14:12 -0800 (PST) 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=20210112 header.b=lH9NcQnW; 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 E7FCC68AF9C; Tue, 21 Dec 2021 14:13:35 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 275A868AF87 for ; Tue, 21 Dec 2021 14:13:34 +0200 (EET) Received: by mail-lf1-f50.google.com with SMTP id k21so10725553lfu.0 for ; Tue, 21 Dec 2021 04:13:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tpWG988i7SyyWgEvuHi9I7+W8WU7xI2kxgYCv90LkdI=; b=lH9NcQnWhFJ/FvqbQYwP3NcinIR0GfY89wMPlbndCde47BdAup3cdNrxB0YymO7/wn acf3wOLrjJsyf3Mob0p51UKEmUT8Qr1w/+hgAzkqHSIcg2gjgURAxZYpzRhomb8x/+Vx xRcQYIGbp5bgFW7fYjlqR8oUCLdBl9DPhP7D1KNfhHbdhoiMfGWzNp2HBZA+MZdLPXcT DaGD4/QAvor+N5zpJ/O/PxLd+xw0b6hPm7TqYuGXfoqAcM0Xc2NwWoFz+1ceUwlCjQHr Q8lqEsPS4hoD518OPIh3FDtq6+9WQx2d+fVnobQr33byqYct58PvDpY3L6yLs9JtwPUx G/6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tpWG988i7SyyWgEvuHi9I7+W8WU7xI2kxgYCv90LkdI=; b=ri0f8pYnoyHN6oIYZ0S0tyZRw9359mHRhvKaW9+u5ArmpU6LTi7DR0CCJaqgd5zyJe /MBiCFFtbfTUgIHRksdBZvGRZHXtlAGsEo50jLOJBTa/JCCDqUwEleT8EaoiQ2/KYuq9 v98W9fv1vynss0o6V5+PmKDOaHoflXnRNZjJH1MAN1snqVejv3iMSuwoNeqMMc5/ceD+ a62cBXZWQoyHuyO5jV+r1Bm9HGZGjQrjWbPQtxCeOztSYiknDR1FRNdbgTOrVfyD5MtV urNsqIFtd2gRXmxEvboPk74H8xCwvZsP4BchEo6l0+5R0sVQBoahg1dRK9X5J8HrUdNH VdRg== X-Gm-Message-State: AOAM531T2jq/+uGojRMJQ7z3OHZvBF4FRFxCN+A5aUFn5z5Rosn+6en6 SLpCuYVGBk/j5CIr+lj7fuzervWYoStgVA== X-Received: by 2002:a05:6512:238f:: with SMTP id c15mr2871796lfv.166.1640088813206; Tue, 21 Dec 2021 04:13:33 -0800 (PST) Received: from localhost.localdomain ([196.244.192.13]) by smtp.gmail.com with ESMTPSA id h9sm147165lft.5.2021.12.21.04.13.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 04:13:32 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 13:12:33 +0100 Message-Id: <20211221121239.1201-7-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211221121239.1201-1-dcnieho@gmail.com> References: <20211221121239.1201-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 06/12] avdevice/dshow: implement get_device_list 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: jM9k/wHQA6bU Needed to enable programmatic discovery of DirectShow devices Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 96 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 81 insertions(+), 15 deletions(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 0ef3b3d13e..e1702c8519 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -202,11 +202,14 @@ fail: * retrieve the device with type specified by devtype and return the * pointer to the object found in *pfilter. * If pfilter is NULL, list all device names. + * If device_list is not NULL, populate it with found devices instead of + * outputting device names to log */ static int dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum, enum dshowDeviceType devtype, enum dshowSourceFilterType sourcetype, - IBaseFilter **pfilter, char **device_unique_name) + IBaseFilter **pfilter, char **device_unique_name, + AVDeviceInfoList **device_list) { struct dshow_ctx *ctx = avctx->priv_data; IBaseFilter *device_filter = NULL; @@ -238,18 +241,19 @@ dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum, IBindCtx *bind_ctx = NULL; LPOLESTR olestr = NULL; LPMALLOC co_malloc = NULL; + AVDeviceInfo *device = NULL; int i; r = CoGetMalloc(1, &co_malloc); if (r != S_OK) - goto fail1; + goto fail; r = CreateBindCtx(0, &bind_ctx); if (r != S_OK) - goto fail1; + goto fail; /* GetDisplayname works for both video and audio, DevicePath doesn't */ r = IMoniker_GetDisplayName(m, bind_ctx, NULL, &olestr); if (r != S_OK) - goto fail1; + goto fail; unique_name = dup_wchar_to_utf8(olestr); /* replace ':' with '_' since we use : to delineate between sources */ for (i = 0; i < strlen(unique_name); i++) { @@ -259,34 +263,62 @@ dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum, r = IMoniker_BindToStorage(m, 0, 0, &IID_IPropertyBag, (void *) &bag); if (r != S_OK) - goto fail1; + goto fail; var.vt = VT_BSTR; r = IPropertyBag_Read(bag, L"FriendlyName", &var, NULL); if (r != S_OK) - goto fail1; + goto fail; friendly_name = dup_wchar_to_utf8(var.bstrVal); if (pfilter) { if (strcmp(device_name, friendly_name) && strcmp(device_name, unique_name)) - goto fail1; + goto fail; if (!skip--) { r = IMoniker_BindToObject(m, 0, 0, &IID_IBaseFilter, (void *) &device_filter); if (r != S_OK) { av_log(avctx, AV_LOG_ERROR, "Unable to BindToObject for %s\n", device_name); - goto fail1; + goto fail; } *device_unique_name = unique_name; unique_name = NULL; // success, loop will end now } } else { - av_log(avctx, AV_LOG_INFO, " \"%s\"\n", friendly_name); - av_log(avctx, AV_LOG_INFO, " Alternative name \"%s\"\n", unique_name); + if (device_list) { + device = av_mallocz(sizeof(AVDeviceInfo)); + if (!device) + goto fail; + + device->device_name = av_strdup(friendly_name); + device->device_description = av_strdup(unique_name); + if (!device->device_name || !device->device_description) + goto fail; + + // make space in device_list for this new device + if (av_reallocp_array(&(*device_list)->devices, + (*device_list)->nb_devices + 1, + sizeof(*(*device_list)->devices)) < 0) + goto fail; + + // store device in list + (*device_list)->devices[(*device_list)->nb_devices] = device; + (*device_list)->nb_devices++; + device = NULL; // copied into array, make sure not freed below + } + else { + av_log(avctx, AV_LOG_INFO, " \"%s\"\n", friendly_name); + av_log(avctx, AV_LOG_INFO, " Alternative name \"%s\"\n", unique_name); + } } -fail1: +fail: + if (device) { + av_freep(&device->device_name); + av_freep(&device->device_description); + av_free(device); + } if (olestr && co_malloc) IMalloc_Free(co_malloc, olestr); if (bind_ctx) @@ -312,6 +344,39 @@ fail1: return 0; } +static int dshow_get_device_list(AVFormatContext *avctx, AVDeviceInfoList *device_list) +{ + struct dshow_ctx *ctx = avctx->priv_data; + ICreateDevEnum *devenum = NULL; + int r; + int ret = AVERROR(EIO); + + if (!device_list) + return AVERROR(EINVAL); + + CoInitialize(0); + + r = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, + &IID_ICreateDevEnum, (void**)&devenum); + if (r != S_OK) { + av_log(avctx, AV_LOG_ERROR, "Could not enumerate system devices.\n"); + goto error; + } + + ret = dshow_cycle_devices(avctx, devenum, VideoDevice, VideoSourceDevice, NULL, NULL, &device_list); + if (ret < S_OK) + goto error; + ret = dshow_cycle_devices(avctx, devenum, AudioDevice, AudioSourceDevice, NULL, NULL, &device_list); + +error: + if (devenum) + ICreateDevEnum_Release(devenum); + + CoUninitialize(); + + return ret; +} + /** * Cycle through available formats using the specified pin, * try to set parameters specified through AVOptions and if successful @@ -705,7 +770,7 @@ 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)) < 0) + 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; @@ -765,7 +830,7 @@ dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum, av_log(avctx, AV_LOG_INFO, "Capture filter loaded successfully from file \"%s\".\n", filename); } else { - if ((r = dshow_cycle_devices(avctx, devenum, devtype, sourcetype, &device_filter, &device_filter_unique_name)) < 0) { + if ((r = dshow_cycle_devices(avctx, devenum, devtype, sourcetype, &device_filter, &device_filter_unique_name, NULL)) < 0) { ret = r; goto error; } @@ -1122,9 +1187,9 @@ static int dshow_read_header(AVFormatContext *avctx) if (ctx->list_devices) { av_log(avctx, AV_LOG_INFO, "DirectShow video devices (some may be both video and audio devices)\n"); - dshow_cycle_devices(avctx, devenum, VideoDevice, VideoSourceDevice, NULL, NULL); + dshow_cycle_devices(avctx, devenum, VideoDevice, VideoSourceDevice, NULL, NULL, NULL); av_log(avctx, AV_LOG_INFO, "DirectShow audio devices\n"); - dshow_cycle_devices(avctx, devenum, AudioDevice, AudioSourceDevice, NULL, NULL); + dshow_cycle_devices(avctx, devenum, AudioDevice, AudioSourceDevice, NULL, NULL, NULL); ret = AVERROR_EXIT; goto error; } @@ -1329,6 +1394,7 @@ const AVInputFormat ff_dshow_demuxer = { .read_header = dshow_read_header, .read_packet = dshow_read_packet, .read_close = dshow_read_close, + .get_device_list= dshow_get_device_list, .flags = AVFMT_NOFILE | AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK, .priv_class = &dshow_class, }; From patchwork Tue Dec 21 12:12:34 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: 32784 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5361177iog; Tue, 21 Dec 2021 04:14:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJypFxk3bYAZK4sap0nlxgFrJ9hhuJ3JQ9GPeSWN4dNW/FE6AD4OWaX1H+cp+bbgZUv3+XB9 X-Received: by 2002:a05:6402:1e8a:: with SMTP id f10mr3043793edf.52.1640088865088; Tue, 21 Dec 2021 04:14:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640088865; cv=none; d=google.com; s=arc-20160816; b=p6Z6JZvJ7xnwFhEOgW9z9rJGgzw+uxpw8tzElIfJ40/lLjHVnT6x5UwnlagxYKJw3j 8jXiExQI6Hhx39hIXGa7oFsYFbKzo8GyKziJLMoz8vW+pkUslEluVkR95I3PzzozL/wj PDFY5r1rbqwIHthpdAJNMmueTNplQ9xwBWc26jxPmakjcCuSgfqzRpvCFDgIffj6ZHQu 8bgWgGO5I8/MrefahbQf/+fp9oUr84O+/dMpFGrRUfzgPiPTwlI0lheV+ur32WAAKSSw tQiqWggMGARVdZcGNn7aE9Z82GlOJkTqkbxJBvGlHroOnniMMAEJJBYWmaVu0xwU1RlF w6dA== 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=ckchGMdpEiP1zFYFdME8cEHxrtpNiMzR+wSs5u6/avo=; b=lInIlEmBwq6Rw7IuEcFpxtL954BhcxcLZV+nJtO9sIUNTK6EfjYLj86WgYJ2HLWj2w LnNt64kJDPnF844zuf06jyip5I6onmgxZJ6tkEq8yWQfLcn3zPBLMXOOaI2ESDjyZf/k FzeDFlHjuWLeqoxMKQE00NNVOfxA0nQVDde5HmZDDTBJDpygaNcHveNDZ6zenPJM3E3x 2C5AQfC2/7ly9ylzZyOYq31FM7M2JzxwbkiGPyHajcCCAiLG7DRpM5RSLfVtYkmjYfdz bMQ0jOEDLOA5/wNEOWLtpu0AamMF7NjwiavK7KxOcK/apC+1p9W9e7xE7dlAk1e9gZRk b4Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="X7Oi3/1S"; 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 y9si155447edv.384.2021.12.21.04.14.24; Tue, 21 Dec 2021 04:14:25 -0800 (PST) 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=20210112 header.b="X7Oi3/1S"; 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 E44C268AFD2; Tue, 21 Dec 2021 14:13:46 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9864168AFB3 for ; Tue, 21 Dec 2021 14:13:40 +0200 (EET) Received: by mail-lf1-f41.google.com with SMTP id o12so9630024lfk.1 for ; Tue, 21 Dec 2021 04:13:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LtqzHYGVuzjBr2UxmIJX18AIY5hVdJD9RAAMd5KqA0c=; b=X7Oi3/1SmRbMyz+RuHX3JvIJW/hhFKq99VVD1DnenSCboKc6c4ZUsucAEV3lQl7cUW 64CbeReeh/3ix/miPRBSuYl904wE9/LL80UEj+dfVM4GHZuna7Sxi3Wvff+wO5++OCLf KlrpACKdAFPoKk6Iuk6dgTwohi/93FXUYIylglOPf6UWpfyMYUzMxruZ/nvupOPjvQG/ 2R8wL6IGBDShqbfcXTB0AqLaJmPjl9pIDHaRhK40oszS20oWxPwsDILyDbR44LQBCxZZ gqdqWWD0RyRponlqLEaFmAie3ZYC9Y9JgNk9lDFvDSRBbicOfX3+msMX+g6Xo+ECltx4 vZjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LtqzHYGVuzjBr2UxmIJX18AIY5hVdJD9RAAMd5KqA0c=; b=WMgcOatVXOsfdWsPXOUZwCI+DEygMMvH+6Ai9G3kdeD73ZMhlnHYtmaLs7xbTDBwNx Okc6GAYdNy1a/fhzX3PFAEPFfJh9qHCZ0Aj7UWr4dFegtJfWiTZ5uqdLZtF2D30H0tUT cuN28cgCLoeBW/mUZzCohBpRsQpQphMeFxV70waMedmRudmJrjtbuDBrRr4zTVlrPLD5 RZ/pl6Y7nclTQq3o9RUtrbGu4maNQrgOoCO6DDVPO2KrOojrUwknQZTP7z7HZiVfj5F4 ASrzERT7bIfW4zPu/MCGjNXOiVYzg/RH0S/p0ozftz3yltdraPF+MuGyTq6Gl22obyK6 HQwA== X-Gm-Message-State: AOAM532LXh9+9SlTegxIABE7Kmf8k/cD6WrKPL0EmqNWlOnHUd/Z2bNr 4fr3jnbTea5wgl9NatVWCXjzs/LKuis+0w== X-Received: by 2002:a05:6512:3e13:: with SMTP id i19mr2867567lfv.508.1640088819683; Tue, 21 Dec 2021 04:13:39 -0800 (PST) Received: from localhost.localdomain ([196.244.192.13]) by smtp.gmail.com with ESMTPSA id m13sm2692142lfl.131.2021.12.21.04.13.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 04:13:39 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 13:12:34 +0100 Message-Id: <20211221121239.1201-8-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211221121239.1201-1-dcnieho@gmail.com> References: <20211221121239.1201-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 07/12] avdevice/dshow: list_devices: show media type(s) per 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: SHbYHvjAQq89 the list_devices option of dshow didn't indicate whether a specific device provides audio or video output. This patch iterates through all media formats of all pins exposed by the device to see what types it provides for capture, and prints this to the console for each device. Importantly, this now allows to find devices that provide both audio and video, and devices that provide neither. Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 103 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 98 insertions(+), 5 deletions(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index e1702c8519..8dba04a787 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -197,6 +197,80 @@ fail: return; } +static void +dshow_get_device_media_types(AVFormatContext *avctx, enum dshowDeviceType devtype, + enum dshowSourceFilterType sourcetype, IBaseFilter *device_filter, + enum AVMediaType **media_types, int *nb_media_types) +{ + struct dshow_ctx *ctx = avctx->priv_data; + IEnumPins *pins = 0; + IPin *pin; + int has_audio = 0, has_video = 0; + + if (IBaseFilter_EnumPins(device_filter, &pins) != S_OK) + return; + + while (IEnumPins_Next(pins, 1, &pin, NULL) == S_OK) { + IKsPropertySet *p = NULL; + PIN_INFO info = { 0 }; + GUID category; + DWORD r2; + IEnumMediaTypes *types = NULL; + AM_MEDIA_TYPE *type; + + if (IPin_QueryPinInfo(pin, &info) != S_OK) + goto next; + IBaseFilter_Release(info.pFilter); + + if (info.dir != PINDIR_OUTPUT) + goto next; + if (IPin_QueryInterface(pin, &IID_IKsPropertySet, (void **) &p) != S_OK) + goto next; + if (IKsPropertySet_Get(p, &ROPSETID_Pin, AMPROPERTY_PIN_CATEGORY, + NULL, 0, &category, sizeof(GUID), &r2) != S_OK) + goto next; + if (!IsEqualGUID(&category, &PIN_CATEGORY_CAPTURE)) + goto next; + + if (IPin_EnumMediaTypes(pin, &types) != S_OK) + goto next; + + // enumerate media types exposed by pin + // NB: don't know if a pin can expose both audio and video, check 'm all to be safe + IEnumMediaTypes_Reset(types); + while (IEnumMediaTypes_Next(types, 1, &type, NULL) == S_OK) { + if (IsEqualGUID(&type->majortype, &MEDIATYPE_Video)) { + has_video = 1; + } else if (IsEqualGUID(&type->majortype, &MEDIATYPE_Audio)) { + has_audio = 1; + } + CoTaskMemFree(type); + } + + next: + if (types) + IEnumMediaTypes_Release(types); + if (p) + IKsPropertySet_Release(p); + if (pin) + IPin_Release(pin); + } + + IEnumPins_Release(pins); + + if (has_audio || has_video) { + int nb_types = has_audio + has_video; + *media_types = av_malloc_array(nb_types, sizeof(enum AVMediaType)); + if (*media_types) { + if (has_audio) + (*media_types)[0] = AVMEDIA_TYPE_AUDIO; + if (has_video) + (*media_types)[0 + has_audio] = AVMEDIA_TYPE_VIDEO; + *nb_media_types = nb_types; + } + } +} + /** * Cycle through available devices using the device enumerator devenum, * retrieve the device with type specified by devtype and return the @@ -242,6 +316,8 @@ dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum, LPOLESTR olestr = NULL; LPMALLOC co_malloc = NULL; AVDeviceInfo *device = NULL; + enum AVMediaType *media_types = NULL; + int nb_media_types = 0; int i; r = CoGetMalloc(1, &co_malloc); @@ -286,6 +362,12 @@ dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum, // success, loop will end now } } else { + // get media types exposed by pins of device + if (IMoniker_BindToObject(m, 0, 0, &IID_IBaseFilter, (void* ) &device_filter) == S_OK) { + dshow_get_device_media_types(avctx, devtype, sourcetype, device_filter, &media_types, &nb_media_types); + IBaseFilter_Release(device_filter); + device_filter = NULL; + } if (device_list) { device = av_mallocz(sizeof(AVDeviceInfo)); if (!device) @@ -308,12 +390,25 @@ dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum, device = NULL; // copied into array, make sure not freed below } else { - av_log(avctx, AV_LOG_INFO, " \"%s\"\n", friendly_name); - av_log(avctx, AV_LOG_INFO, " Alternative name \"%s\"\n", unique_name); + av_log(avctx, AV_LOG_INFO, "\"%s\"", friendly_name); + if (nb_media_types > 0) { + const char* media_type = av_get_media_type_string(media_types[0]); + av_log(avctx, AV_LOG_INFO, " (%s", media_type ? media_type : "unknown"); + for (int i = 1; i < nb_media_types; ++i) { + media_type = av_get_media_type_string(media_types[i]); + av_log(avctx, AV_LOG_INFO, ", %s", media_type ? media_type : "unknown"); + } + av_log(avctx, AV_LOG_INFO, ")"); + } else { + av_log(avctx, AV_LOG_INFO, " (none)"); + } + av_log(avctx, AV_LOG_INFO, "\n"); + av_log(avctx, AV_LOG_INFO, " Alternative name \"%s\"\n", unique_name); } } -fail: + fail: + av_freep(&media_types); if (device) { av_freep(&device->device_name); av_freep(&device->device_description); @@ -1186,9 +1281,7 @@ static int dshow_read_header(AVFormatContext *avctx) } if (ctx->list_devices) { - av_log(avctx, AV_LOG_INFO, "DirectShow video devices (some may be both video and audio devices)\n"); dshow_cycle_devices(avctx, devenum, VideoDevice, VideoSourceDevice, NULL, NULL, NULL); - av_log(avctx, AV_LOG_INFO, "DirectShow audio devices\n"); dshow_cycle_devices(avctx, devenum, AudioDevice, AudioSourceDevice, NULL, NULL, NULL); ret = AVERROR_EXIT; goto error; From patchwork Tue Dec 21 12:12:35 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: 32785 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5361364iog; Tue, 21 Dec 2021 04:14:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJwxUNLZl7ogp37jEjUM3nJmbK2gNEINepIkqKu1LSGmNT254Y1DdXiMSNNDMK9cpJ3OoTry X-Received: by 2002:a17:906:a20e:: with SMTP id r14mr2403186ejy.376.1640088877054; Tue, 21 Dec 2021 04:14:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640088877; cv=none; d=google.com; s=arc-20160816; b=aHSfTKUVou2xyEBlvYnieyr6Q5kqDcuZg77Q7WmpEqhg2b5u0b4JCKfQnkeaT/kO4a ivPmDLjL3ieJkHwbX2276O3f2C3/8ywmiHySPZxNxgxtHmRv01BpN4UtXAL79vY1Tu4X 1cspFsq1s75dKseMNqqADwvd/GeR08+VCz+1VIGgOlW9mQIcI9gciQzzSKpzfr+xfE6W fpMZfR5HV+rn+DXdsxGDAlsnH21opWm3xC5YBm3aZuW1K8rCg66UOSzBo+aysqWHMPGb H3cZXoB/FTrP9dlC7U3vQXFY1nNeaNaDn6De2VFF78GcrlIyrSs49PtR/Vz8qKjJO+Jb Tovw== 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=T4HROmvL/8xJlef5VNQzAihljd4G6k3+CBmmzbKNMZc=; b=nS4zgrUzitXOM21neFKHzzJEX8NDe+KQrpyFOqz6oH81rx1j2lmGnfuIpnU8q0/hvY 8nm5Ny7q16H/j3wW5dTj5mTUdVai3U26LCD2LQCQJqj4vkJK/zNAghkBX7BaRd+11SZy wkzihX2Ei/GXU/MK4YiK1FzhZ3iJjhTjZJ3gUf7z403Pl5ZBjiYfV5AU1mnB5GL1hNY+ MHBn0Nfa2jzf+vuxkMGRaRq4dDaGAMKW5GqmrdVfGzVUbS1jIYmaW6ofsC7RkF+uTCH5 s45GD9Q3uQyeGnk+6cOw78PkEFFmh8h66UtiDL2VX4JBgP0FQzBu4Mq35cdKiP327ouG U74w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=eknp3wqI; 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 hb9si9450672ejb.574.2021.12.21.04.14.36; Tue, 21 Dec 2021 04:14:37 -0800 (PST) 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=20210112 header.b=eknp3wqI; 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 01C2668AE95; Tue, 21 Dec 2021 14:13:49 +0200 (EET) 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 4C28468AFB3 for ; Tue, 21 Dec 2021 14:13:47 +0200 (EET) Received: by mail-lf1-f45.google.com with SMTP id g26so13055398lfv.11 for ; Tue, 21 Dec 2021 04:13:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4axSseDA+cc32lWcTsH+1ta6Ma+i8aKWlLXmXGb90K8=; b=eknp3wqIbbuGNVTK1pUxaX5j7YrXyBPhTLBAgj18quMkh2SbV1YsolMtn1PkXoT1DU tdqDtDH/ysZAVPzgpq99oCMV0csd0yRTEo2S2u4idK10YgpNEzTEaPw7veJlsPxH+4n5 jXODYFg6BR7xBIwTh83I4/7uCFCDOzFozi0XsX8KPBVvsEWbcdPpAyNBfV4zt3il5n9O tYZLf/qh2cpVESpdwgiYlFsPmCOLiWaT16je5HaLwPO3trXZuiurF7gMCJVaSLnouCwc vYl5keh1SmJT6Oa2z+UYkrX1RK3lzbqQJm/WpPrbQIfQn+sTje8mZ6UqVLzmP2OeqCEi 0ubQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4axSseDA+cc32lWcTsH+1ta6Ma+i8aKWlLXmXGb90K8=; b=MsW+Af8JB6z6nvXjlfCOItnHpRHZFjC/FhqC+bqxkBpfBhVMvQdIJZJnKR2VhS7gD2 nBRuwkZgbdfEVS+bXcGikXnn5qfJl37nuPCezgHplagVTDoTe49uToIDOhpfhsdWQR2D vQgAFWPH1segEAefzkIvJ4uA9DKGHDz9ws/6+ALK4yPzQ8a6Mf5t1c30TY72SuCbauVC l/ZZXAQkS4+Z4i7utmX6FhqBQc7l9ajZEWY04iQstkm8GEIUTa9qeuUSOHtDqae/zT5m Fzj40BkGXam9UrkyJFJWaV2NFCyXPztIVGeqBmzJMF0tS8niWwkDT9l++N/gySG4ET5N ORzw== X-Gm-Message-State: AOAM531i52dJjBWRd0i8TDgTq1Ymuflw7tTYRzxf1MuEV25OmX4kEaKT 10SN0gghauh2owEIBkY5puBZG2wyRPCJZg== X-Received: by 2002:a19:e308:: with SMTP id a8mr2796040lfh.220.1640088826157; Tue, 21 Dec 2021 04:13:46 -0800 (PST) Received: from localhost.localdomain ([196.244.192.13]) by smtp.gmail.com with ESMTPSA id l5sm1267493lfk.167.2021.12.21.04.13.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 04:13:45 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 13:12:35 +0100 Message-Id: <20211221121239.1201-9-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211221121239.1201-1-dcnieho@gmail.com> References: <20211221121239.1201-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 08/12] avdevice: add info about media types(s) to AVDeviceInfo 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: +R6mE/8/zdWP An avdevice, regardless of whether its category says its an audio or video device, may provide access to devices providing different media types, or even single devices providing multiple media types. Also, some devices may provide no media types. dshow is an example encompassing all of these cases. Users should be provided with this information, so AVDeviceInfo is extended to provide it. Bump avdevice version Signed-off-by: Diederick Niehorster --- libavdevice/avdevice.c | 1 + libavdevice/avdevice.h | 2 ++ libavdevice/version.h | 4 ++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c index 2ae26ab8e3..8f460c7564 100644 --- a/libavdevice/avdevice.c +++ b/libavdevice/avdevice.c @@ -157,6 +157,7 @@ void avdevice_free_list_devices(AVDeviceInfoList **device_list) if (dev) { av_freep(&dev->device_name); av_freep(&dev->device_description); + av_freep(&dev->media_types); av_free(dev); } } diff --git a/libavdevice/avdevice.h b/libavdevice/avdevice.h index 8370bbc7f2..6f24976dcc 100644 --- a/libavdevice/avdevice.h +++ b/libavdevice/avdevice.h @@ -457,6 +457,8 @@ void avdevice_capabilities_free(AVDeviceCapabilitiesQuery **caps, AVFormatContex typedef struct AVDeviceInfo { char *device_name; /**< device name, format depends on device */ char *device_description; /**< human friendly name */ + enum AVMediaType *media_types; /**< array indicating what media types(s), if any, a device can provide. If null, cannot provide any */ + int nb_media_types; /**< length of media_types array, 0 if device cannot provide any media types */ } AVDeviceInfo; /** diff --git a/libavdevice/version.h b/libavdevice/version.h index 914e156ec7..41f568d6b0 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 0 -#define LIBAVDEVICE_VERSION_MICRO 101 +#define LIBAVDEVICE_VERSION_MINOR 1 +#define LIBAVDEVICE_VERSION_MICRO 100 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \ LIBAVDEVICE_VERSION_MINOR, \ From patchwork Tue Dec 21 12:12:36 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: 32786 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5361554iog; Tue, 21 Dec 2021 04:14:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJyyPx6n6B5uhgSvF7ALGIRcVbxbX1LjqwfvKcJeCIBar0dCuSObpSmWCx2R4fqhcalRKx9+ X-Received: by 2002:a05:6402:516a:: with SMTP id d10mr3018586ede.131.1640088892332; Tue, 21 Dec 2021 04:14:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640088892; cv=none; d=google.com; s=arc-20160816; b=idZq6riZC0INWR0HKKW2fL16t33YcF/LcWNGAdQlbAEpizKexKoeWUXFsbQsH6s6dP yWo56lk9uKdb0NzW9f5LBsTy6YuPCcDeSpD4+EWlttJrscPquHQBrIdNDxq+euf6iiPa J1n2KrFaUCapy8xi7HiMigACOi8qrNE2AtLAshVL09YjRFH4J/LCTYkqrdsr8zMWSo1E +Y806i0y5OS6VL3lG33EmyNQyubXpB+ceFznbOndvYikrgI9RVMsZ/YLsnxttwY2H7tZ QAcapJr5OHUOoa9QYGfr0728+C5K0qFMs+Fw/nhWAMacQwn4TNVkIQghg3rK6kOjBNe6 KBJw== 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=T1p4dXjdoOorQzbEjoxluW0EMmVJ1gI9e2DuNfkkNvg=; b=tL++PCwjVvu1JjMkgO7dWQIwqW59xaLg4POUxbecNRTBngQVGgwdM1+BtyS0498WPU 0yc9b9XiCeyZcVjuCweYVgX1jL73dElGk93bCTdPMn2BB9H3QLjlaBjq9oEireVQPmfk tfdiU+ZI/aMkGKzj/92vpSU6vwsL6M+3zL36B4KvP8rUxXWBzdGGIIHCxrKJP0deklMQ WYKiAixA2/Vvum24EEhtYuXMAc6D+Hi3g2qRxBlso5s0FYwx1hg+6uYRaVns3Bizxq0k OL/M49j49m4ELFxKVTHcshSTrwWFGtKffb+YtNQaVWe+GlFDlAilrvkLtx0ISctChh7S nc8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=boDRaBTU; 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 w14si4309041edc.474.2021.12.21.04.14.48; Tue, 21 Dec 2021 04:14:52 -0800 (PST) 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=20210112 header.b=boDRaBTU; 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 13BF368AFEB; Tue, 21 Dec 2021 14:13:55 +0200 (EET) 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 C305268AFDD for ; Tue, 21 Dec 2021 14:13:53 +0200 (EET) Received: by mail-lf1-f47.google.com with SMTP id x7so4345593lfu.8 for ; Tue, 21 Dec 2021 04:13:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=v2kXJOQXp1FSsiOyRIGlHOZj4JiIWVkJ1nszCAPlQyM=; b=boDRaBTUcmRXyz/txcZJIyTJMcGyGX47/tDb0pfZQhvW0SPnKf8JOfM4f8zgqd0nio mFGGyiPqdS7a1CHCs3Wd1Nl6qt4SIj+V8wOAn4QNHBPHerYB4aZCrZphbuJlgYIra+zr LyQGRdlc9NabvnnDvjv65S0BHjaIJszeVOLrTq9BdNy9puJEwSkJDmRIAOXv3PxbntyY kAd97oAohV5JOVglFE9O8RL35eSnbUcCNz5/VU9XM2WMgZNOsfjzfVa7Hiv3py03Ssim /+s5FEk9H+nDNJjKxdxHtRP0n7JQKNGuIxC4YJGrvVtcyotPMZPDyeHF8MuQXLpjUKgj nuyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=v2kXJOQXp1FSsiOyRIGlHOZj4JiIWVkJ1nszCAPlQyM=; b=FKpHaadx2LWJmM6mH4u/ZZnyR0gf96e+H9aWUIh9EuhGej1lNRVuRzqJGYqvK4iUc3 vn2wW5qJGUhq2I5MMrgh1l2EE36578OaBuaDXX5g2uAz2WDpLYex59/QS3hylrlwfk51 fW3Z9CdVbHae3dXb8s+CZ/+lz6E1YgEwimi8nlK9ZjjWpEC079cMt7Umzf8AT1gbhe48 3bUzsQ3v95Z2Wtx6NPeHejcaJRAn5vCkHCUUgF/QKbZ44swaUVp4aowjSe4zmfYXzIHK ZMD3S3zWFdwzArd7CHzAkmfM5ADCzqv03cYv+ru7+KvSWr+x3nfYSQFp7L0fXar8bJTw S2JQ== X-Gm-Message-State: AOAM533W+moHbm/DlNFrgtnkl59LhC71udAjNfUlry/wbSyvfdyo0My1 97SSsbC1S52KbZ6xYhRRptZkupb8lw2i6A== X-Received: by 2002:a05:6512:388d:: with SMTP id n13mr2691207lft.109.1640088832617; Tue, 21 Dec 2021 04:13:52 -0800 (PST) Received: from localhost.localdomain ([196.244.192.13]) by smtp.gmail.com with ESMTPSA id p6sm28403ljg.69.2021.12.21.04.13.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 04:13:52 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 13:12:36 +0100 Message-Id: <20211221121239.1201-10-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211221121239.1201-1-dcnieho@gmail.com> References: <20211221121239.1201-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 09/12] avdevice/dshow: add media type info to get_device_list 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: ieG0h/PFnGNp The list returned by get_device_list now contains info about what media type(s), if any, can be provided by each device. Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 8dba04a787..4b1e942c7a 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -384,6 +384,12 @@ dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum, sizeof(*(*device_list)->devices)) < 0) goto fail; + // attach media_types to device + device->nb_media_types = nb_media_types; + device->media_types = media_types; + nb_media_types = 0; + media_types = NULL; + // store device in list (*device_list)->devices[(*device_list)->nb_devices] = device; (*device_list)->nb_devices++; @@ -412,6 +418,7 @@ dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum, if (device) { av_freep(&device->device_name); av_freep(&device->device_description); + // NB: no need to av_freep(&device->media_types), its only moved to device once nothing can fail anymore av_free(device); } if (olestr && co_malloc) From patchwork Tue Dec 21 12:12:37 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: 32787 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5361820iog; Tue, 21 Dec 2021 04:15:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJxE9WCt/10g2LeMazv64gBGGuht7ucn9tfEOpsnm536jgifovkVDg8Nmghs3vh3aTYdXJmc X-Received: by 2002:a17:907:1c13:: with SMTP id nc19mr2380881ejc.436.1640088911122; Tue, 21 Dec 2021 04:15:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640088911; cv=none; d=google.com; s=arc-20160816; b=Wev8Ppmnvxm6ov4sbJQaPUT/0qeqCafnAAbZmbsj6cGkyM1utpDTN8Q0QE5R/nlMas 5VXcxy8HHMTgqNYQt9JNaSozufNxk5jzJ1w358XtNfUDAZpg0IpPF+XAaFv8DVVAuU0L yNO0eNG5YP6WLOHv1tbAcnMkIZWmsUYHwBzvE6gSJxtDbfYKHh0hjHanVyet9TCcMg7A Jln/QNMdTSMqej1Nxul6BqA+jVEyeRlIf/ujNQg+Qt0UpxANwm1daHcdEmj+bh3mz42F lHYrNKDXynWZoRLLN/Vl3/xcr6uB25yUegRHvWJJRgoOzMcT/+a46kWnYHsIkQVd8hBC wpqQ== 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=VVZDiHHiulmLZ2DUouAOoRd6xOr1m6VopPl7GpLCVxI=; b=jQzEsihQz38Mbhm4iSqlS5x23gkP/ws7BmZBKFS3vZ9X8E7joKGZJrQkbWaykA1MdD e9thybDBSWl+0Uj6pJnOma/gnXfttf0xM06f7DDe5nrQSnc7cYI6nn7noJFI9JS2/jlf 6AkdWgL2N2pNJEMrJWcE9wUocMbGxsz+/ziRBQMCRK2F25c5f0L2ZsPCM7X/waJWr9lk n2kYFAN94IBF7gwNOTlbc2i2KY/pdv+FvQEGDEUF+nRZs9zroadktFlbHp/GQJkYw5bB ElXgA/JsVIZ6gwqXlfvUHgcXYglJUHdEDpLLPasTwPd2zQhLTt1pExgLOnTbWLNRylqe 9bPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=TkJmsZIQ; 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 l7si4633582edr.32.2021.12.21.04.15.01; Tue, 21 Dec 2021 04:15:11 -0800 (PST) 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=20210112 header.b=TkJmsZIQ; 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 20D8668AFF7; Tue, 21 Dec 2021 14:14:06 +0200 (EET) 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 C54DD68AEFF for ; Tue, 21 Dec 2021 14:13:59 +0200 (EET) Received: by mail-lf1-f45.google.com with SMTP id x7so4346318lfu.8 for ; Tue, 21 Dec 2021 04:13:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kMsh/cjRaeHZRA9EESMdY3i4MzhjOve1+S0jXjzgehM=; b=TkJmsZIQSyQDg5ZXiynoveVnMgue9YA/1alb9TOaCtpHzkl8yRVXUhoY0S42b63jbs dCLx6gjrEUGCVhzxdpW+lH+ztQtOUMJmYJ1VavfRoqaiKQPFsoKOCbk0ISQ6Uy7qKya3 750ta8bVT997kbLB9zVqzwBgdqK1yPgZ66kDiKpB6y5w9p18hOpkEMBdkl80Tvy0qboj 1VSuu7/9O3dDUfrNKf7LaH5IjYdHlrojKTRDLRyaaFmT+G7yh/FoVD2XzAugfMmsFT2N HIVxUZi39srcq83tr/L85BFHqhGxTg/xzt7jSrz1TDDZUzcx4go7TwLN2SOmhZeFvOvG VWAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kMsh/cjRaeHZRA9EESMdY3i4MzhjOve1+S0jXjzgehM=; b=sYC3L/A97MIUDSr7XSDg3jX1Bbd174keL1dMbY8SDYRicdtCYXFgLNiGgYoRjGmX/P Zni3W4J0BmekiFxyGBoJYM7CQcZ3shBkLfDa5kSFDmhGlnT0HowipSoNWGdt7VVtCFFw j1XSdVtPqeSpi/cJqrCZldSGJ58fTVP2JJn/Vrn6HCOju+vvqe/jopOw+Sxovld8J0kR K0Y4vf6dFrXiHfOuK3kyIXqteHMyeoGlnWyX+80GSJ04zZHHfIKTEpKAqKt3rfjRoCNB zPSXUF5XHIQuFb5O/u3FWc4uWlYFA+ziQXIY91AdA9CcOMn7cbaxOGWkg8f8ZLZADaqM FiHw== X-Gm-Message-State: AOAM531Bx7eDprnBTdHMAOU+6soFlED728YYAjkzBZPZ4zUx+N0cIX3T x4PQ0QF5eVppqBS/5thVVlRuJckjSOBPng== X-Received: by 2002:ac2:4883:: with SMTP id x3mr2930063lfc.620.1640088839032; Tue, 21 Dec 2021 04:13:59 -0800 (PST) Received: from localhost.localdomain ([196.244.192.13]) by smtp.gmail.com with ESMTPSA id y4sm2728707ljp.16.2021.12.21.04.13.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 04:13:58 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 13:12:37 +0100 Message-Id: <20211221121239.1201-11-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211221121239.1201-1-dcnieho@gmail.com> References: <20211221121239.1201-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 10/12] fftools: provide media type info for devices 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: Ltve/Nq96heC fftools now print info about what media type(s), if any, are provided by sink and source avdevices. Signed-off-by: Diederick Niehorster --- fftools/cmdutils.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 3c8e5a82cd..8b2dc030bc 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -2244,9 +2244,29 @@ double get_rotation(int32_t *displaymatrix) } #if CONFIG_AVDEVICE +static void print_device_list(const AVDeviceInfoList *device_list) +{ + // print devices + for (int i = 0; i < device_list->nb_devices; i++) { + const AVDeviceInfo *device = device_list->devices[i]; + printf("%c %s [%s] (", device_list->default_device == i ? '*' : ' ', + device->device_name, device->device_description); + if (device->nb_media_types > 0) { + for (int j = 0; j < device->nb_media_types; ++j) { + const char* media_type = av_get_media_type_string(device->media_types[j]); + if (j > 0) + printf(", "); + printf("%s", media_type ? media_type : "unknown"); + } + } else { + printf("none"); + } + printf(")\n"); + } +} static int print_device_sources(const AVInputFormat *fmt, AVDictionary *opts) { - int ret, i; + int ret; AVDeviceInfoList *device_list = NULL; if (!fmt || !fmt->priv_class || !AV_IS_INPUT_DEVICE(fmt->priv_class->category)) @@ -2258,10 +2278,7 @@ static int print_device_sources(const AVInputFormat *fmt, AVDictionary *opts) goto fail; } - for (i = 0; i < device_list->nb_devices; i++) { - printf("%c %s [%s]\n", device_list->default_device == i ? '*' : ' ', - device_list->devices[i]->device_name, device_list->devices[i]->device_description); - } + print_device_list(device_list); fail: avdevice_free_list_devices(&device_list); @@ -2270,7 +2287,7 @@ static int print_device_sources(const AVInputFormat *fmt, AVDictionary *opts) static int print_device_sinks(const AVOutputFormat *fmt, AVDictionary *opts) { - int ret, i; + int ret; AVDeviceInfoList *device_list = NULL; if (!fmt || !fmt->priv_class || !AV_IS_OUTPUT_DEVICE(fmt->priv_class->category)) @@ -2282,10 +2299,7 @@ static int print_device_sinks(const AVOutputFormat *fmt, AVDictionary *opts) goto fail; } - for (i = 0; i < device_list->nb_devices; i++) { - printf("%c %s [%s]\n", device_list->default_device == i ? '*' : ' ', - device_list->devices[i]->device_name, device_list->devices[i]->device_description); - } + print_device_list(device_list); fail: avdevice_free_list_devices(&device_list); From patchwork Tue Dec 21 12:12:38 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: 32788 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5361897iog; Tue, 21 Dec 2021 04:15:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJwNickmOovRwCmVIeJcl9dz2kH9JaN3qyatu//sfpuMvp09xuGrsPIU0qAxrqGBN7/acUzk X-Received: by 2002:a17:907:94c2:: with SMTP id dn2mr2426128ejc.325.1640088916012; Tue, 21 Dec 2021 04:15:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640088916; cv=none; d=google.com; s=arc-20160816; b=XgWadZviT5J2TMK3evy4RFqhCGqJs+OvlYWyOAwAkhJ8QnfPk4+jm7+k5wprES5sEi rlCAzUk9jIotMwpCkD1vMCek/BGZ+WIZbcbiDthkSlQYvnRRxfg+mjrmC2kIQriVb5Jh ckFgXiG1+/P2qRZoYh8QN3bNrQ4QjCTDIEXpfv+bqsODyj/Q2lrE3/XQG6VBonR07ImR G7IQbsJbTHYjcfEN5TigMCNcODNOs1D3uiyj70apKPrhEUbodnCd7syOLIibFRLUoD0h Vrb5koJjcziDu0OVNarKPJLmJRBAK18znWNf1LOSRI2OSxxserGME50wVPpV0rYyXL0L Dgcw== 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=mQQnMvFrSFRN7IveD6OdZyDJ9ZI1Gj+yXAjZW4ekiU0=; b=IHgHzDpKDESk4dQyLg3QU75Ji4me6XdCbyNIP8v3pQfwF8vkp6ztNEANe0+qhR5VBk oNJNbssq4A/t9UjJmmjE1RLL6bmza3ZSC9A/8Kdzs50QFOkFhCOGA8SlaoLzzq2YNYKF Yuoxz85AvaDgc0/KbCgLn2SOeHuMqa58LTJipT0Mz3tPIap6zl1g/K/HcPGsYBtEKTkc TvFnnpurrraXp+9dU/C5w32yLp5MDukyZGOCffn6w0PQTZVgm+BF8O4fXLd+4RokI4Eq WVv4MZYto0rzYoIBLjz19P+4dw4IFZukvixdmSUCf0AdjQbMdj9fNj6hGltE8ULKFOKT 3C1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=nGy6LLqh; 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 x5si11251055ejf.759.2021.12.21.04.15.15; Tue, 21 Dec 2021 04:15:15 -0800 (PST) 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=20210112 header.b=nGy6LLqh; 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 1204E68AFFD; Tue, 21 Dec 2021 14:14:09 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E0E8168AFE2 for ; Tue, 21 Dec 2021 14:14:06 +0200 (EET) Received: by mail-lj1-f172.google.com with SMTP id p8so21079909ljo.5 for ; Tue, 21 Dec 2021 04:14:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xmkgAr45Mp8BrzsIya0skUee1YQBKZ024Tis+be7g4c=; b=nGy6LLqhLsyqsWn7mv+TSdjQbiCMQ5XONpQezIpD6osaPuwnXfKQoGMZYmqy0au6pf iN/3rkvcaybfrQJGb/2Y+ZkAae6fxpBh/lfex009o0Dg2Fx0RAojTBBQYC5yYcdTcfGu v7LFsO1aCdvKQtgilU5N5T9U+w3X9A4g4OU3JG0bw64VICRTo/YyP+pxYanpXl44DGcx QJK72F1X1dX4Xb+fc1Br8qRX3OJ863gZVvZoCyPNB/un8BS+oF+5GCRQepc+7tt6bN/R RkkaGhPcrnDyo9ppzi8yHqWduxCnh3pPTzi2Yvjy9pVA1can3iqiG8mB2mZfBxbiUU5d DPCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xmkgAr45Mp8BrzsIya0skUee1YQBKZ024Tis+be7g4c=; b=xqXyaedVWMZcVDkxoSnx1ann+izNwj35SELkBHx/Q3M3I6AzorKvIB4BS0+RYr3kLu rrNTNCMRslhql7cZAP8qWm2+ljgx1AQ1MxRGxjYi2DwLf/KE5SFAekvh4/3aOeQ2FAS8 5Da2C7HWPCK+f1reKe9zHTYzQgPWBPLtJjY/lSk7icGngNIB8yDjcjdpc8GIvcIk+8j9 B+r6wYGACMjE6OIYcm0RQi/Uu3bEmDiq76u2AUy+v5oC/a0AAg72Bo348tyeZ6a4sWT9 8Jeb1Hqc7MYuoinOMc+JH1C4f+KjudL/xBFzjmi+ZT0M62zATQ1Fm1seBFDQpT9ZaNqF QPNg== X-Gm-Message-State: AOAM532Fvvlj3bo69VaqptFoqbk9kaD+r3SUJX6PQEm7R+wF3YnhpZMu tQKgpuOklipFsupUNqwJQA8rwBPe6KNJNw== X-Received: by 2002:a2e:a4aa:: with SMTP id g10mr2308078ljm.529.1640088845522; Tue, 21 Dec 2021 04:14:05 -0800 (PST) Received: from localhost.localdomain ([196.244.192.13]) by smtp.gmail.com with ESMTPSA id y17sm170905ljk.111.2021.12.21.04.14.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 04:14:05 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 13:12:38 +0100 Message-Id: <20211221121239.1201-12-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211221121239.1201-1-dcnieho@gmail.com> References: <20211221121239.1201-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 11/12] avdevice/dshow: discover source color range/space/etc 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 , Valerii Zapodovnikov Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: D78OYzwLOWMV Enabled discovering a DirectShow device's color range, space, primaries, transfer characteristics and chroma location, if the device exposes that information. Sets them in the stream's codecpars. Co-authored-by: Valerii Zapodovnikov Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 255 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 254 insertions(+), 1 deletion(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 4b1e942c7a..79be32b255 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -29,6 +29,31 @@ #include "libavcodec/raw.h" #include "objidl.h" #include "shlwapi.h" +// NB: technically, we should include dxva.h and use +// DXVA_ExtendedFormat, but that type is not defined in +// the MinGW headers. The DXVA2_ExtendedFormat and the +// contents of its fields is identical to +// DXVA_ExtendedFormat (see https://docs.microsoft.com/en-us/windows/win32/medfound/extended-color-information#color-space-in-media-types) +// and is provided by MinGW as well, so we use that +// instead. NB also that per the Microsoft docs, the +// lowest 8 bits of the structure, i.e. the SampleFormat +// field, contain AMCONTROL_xxx flags instead of sample +// format information, and should thus not be used. +// NB further that various values in the structure's +// fields (e.g. BT.2020 color space) are not provided +// for either of the DXVA structs, but are provided in +// the flags of the corresponding fields of Media Foundation. +// These may be provided by DirectShow devices (e.g. LAVFilters +// does so). So we use those values here too (the equivalence is +// indicated by Microsoft example code: https://docs.microsoft.com/en-us/windows/win32/api/dxva2api/ns-dxva2api-dxva2_videodesc) +typedef DWORD D3DFORMAT; // dxva2api.h header needs these types defined before include apparently in WinSDK (not MinGW). +typedef DWORD D3DPOOL; +#include "dxva2api.h" + +#ifndef AMCONTROL_COLORINFO_PRESENT +// not defined in some versions of MinGW's dvdmedia.h +# define AMCONTROL_COLORINFO_PRESENT 0x00000080 // if set, indicates DXVA color info is present in the upper (24) bits of the dwControlFlags +#endif static enum AVPixelFormat dshow_pixfmt(DWORD biCompression, WORD biBitCount) @@ -54,6 +79,192 @@ static enum AVPixelFormat dshow_pixfmt(DWORD biCompression, WORD biBitCount) return avpriv_find_pix_fmt(avpriv_get_raw_pix_fmt_tags(), biCompression); // all others } +static enum AVColorRange dshow_color_range(DXVA2_ExtendedFormat *fmt_info) +{ + switch (fmt_info->NominalRange) + { + case DXVA2_NominalRange_Unknown: + return AVCOL_RANGE_UNSPECIFIED; + case DXVA2_NominalRange_Normal: // equal to DXVA2_NominalRange_0_255 + return AVCOL_RANGE_JPEG; + case DXVA2_NominalRange_Wide: // equal to DXVA2_NominalRange_16_235 + return AVCOL_RANGE_MPEG; + case DXVA2_NominalRange_48_208: + // not an ffmpeg color range + return AVCOL_RANGE_UNSPECIFIED; + + // values from MediaFoundation SDK (mfobjects.h) + case 4: // MFNominalRange_64_127 + // not an ffmpeg color range + return AVCOL_RANGE_UNSPECIFIED; + + default: + return DXVA2_NominalRange_Unknown; + } +} + +static enum AVColorSpace dshow_color_space(DXVA2_ExtendedFormat *fmt_info) +{ + enum AVColorSpace ret = AVCOL_SPC_UNSPECIFIED; + + switch (fmt_info->VideoTransferMatrix) + { + case DXVA2_VideoTransferMatrix_BT709: + ret = AVCOL_SPC_BT709; + break; + case DXVA2_VideoTransferMatrix_BT601: + ret = AVCOL_SPC_BT470BG; + break; + case DXVA2_VideoTransferMatrix_SMPTE240M: + ret = AVCOL_SPC_SMPTE240M; + break; + + // values from MediaFoundation SDK (mfobjects.h) + case 4: // MFVideoTransferMatrix_BT2020_10 + case 5: // MFVideoTransferMatrix_BT2020_12 + if (fmt_info->VideoTransferFunction==12) // MFVideoTransFunc_2020_const + ret = AVCOL_SPC_BT2020_CL; + else + ret = AVCOL_SPC_BT2020_NCL; + break; + } + + if (ret == AVCOL_SPC_UNSPECIFIED) + { + // if color space not known from transfer matrix, + // fall back to using primaries to guess color space + switch (fmt_info->VideoPrimaries) + { + case DXVA2_VideoPrimaries_BT709: + ret = AVCOL_SPC_BT709; + break; + case DXVA2_VideoPrimaries_BT470_2_SysM: + ret = AVCOL_SPC_FCC; + break; + case DXVA2_VideoPrimaries_BT470_2_SysBG: + case DXVA2_VideoPrimaries_EBU3213: // this is PAL + ret = AVCOL_SPC_BT470BG; + break; + case DXVA2_VideoPrimaries_SMPTE170M: + case DXVA2_VideoPrimaries_SMPTE_C: + ret = AVCOL_SPC_SMPTE170M; + break; + case DXVA2_VideoPrimaries_SMPTE240M: + ret = AVCOL_SPC_SMPTE240M; + break; + } + } + + return ret; +} + +static enum AVColorPrimaries dshow_color_primaries(DXVA2_ExtendedFormat *fmt_info) +{ + switch (fmt_info->VideoPrimaries) + { + case DXVA2_VideoPrimaries_Unknown: + return AVCOL_PRI_UNSPECIFIED; + case DXVA2_VideoPrimaries_reserved: + return AVCOL_PRI_RESERVED; + case DXVA2_VideoPrimaries_BT709: + return AVCOL_PRI_BT709; + case DXVA2_VideoPrimaries_BT470_2_SysM: + return AVCOL_PRI_BT470M; + case DXVA2_VideoPrimaries_BT470_2_SysBG: + case DXVA2_VideoPrimaries_EBU3213: // this is PAL + return AVCOL_PRI_BT470BG; + case DXVA2_VideoPrimaries_SMPTE170M: + case DXVA2_VideoPrimaries_SMPTE_C: + return AVCOL_PRI_SMPTE170M; + case DXVA2_VideoPrimaries_SMPTE240M: + return AVCOL_PRI_SMPTE240M; + + // values from MediaFoundation SDK (mfobjects.h) + case 9: // MFVideoPrimaries_BT2020 + return AVCOL_PRI_BT2020; + case 10: // MFVideoPrimaries_XYZ + return AVCOL_PRI_SMPTE428; + case 11: // MFVideoPrimaries_DCI_P3 + return AVCOL_PRI_SMPTE431; + case 12: // MFVideoPrimaries_ACES (Academy Color Encoding System) + // not an FFmpeg color primary + return AVCOL_PRI_UNSPECIFIED; + + default: + return AVCOL_PRI_UNSPECIFIED; + } +} + +static enum AVColorTransferCharacteristic dshow_color_trc(DXVA2_ExtendedFormat *fmt_info) +{ + switch (fmt_info->VideoTransferFunction) + { + case DXVA2_VideoTransFunc_Unknown: + return AVCOL_TRC_UNSPECIFIED; + case DXVA2_VideoTransFunc_10: + return AVCOL_TRC_LINEAR; + case DXVA2_VideoTransFunc_18: + // not an FFmpeg transfer characteristic + return AVCOL_TRC_UNSPECIFIED; + case DXVA2_VideoTransFunc_20: + // not an FFmpeg transfer characteristic + return AVCOL_TRC_UNSPECIFIED; + case DXVA2_VideoTransFunc_22: + return AVCOL_TRC_GAMMA22; + case DXVA2_VideoTransFunc_709: + return AVCOL_TRC_BT709; + case DXVA2_VideoTransFunc_240M: + return AVCOL_TRC_SMPTE240M; + case DXVA2_VideoTransFunc_sRGB: + return AVCOL_TRC_IEC61966_2_1; + case DXVA2_VideoTransFunc_28: + return AVCOL_TRC_GAMMA28; + + // values from MediaFoundation SDK (mfobjects.h) + case 9: // MFVideoTransFunc_Log_100 + return AVCOL_TRC_LOG; + case 10: // MFVideoTransFunc_Log_316 + return AVCOL_TRC_LOG_SQRT; + case 11: // MFVideoTransFunc_709_sym + // not an FFmpeg transfer characteristic + return AVCOL_TRC_UNSPECIFIED; + case 12: // MFVideoTransFunc_2020_const + case 13: // MFVideoTransFunc_2020 + if (fmt_info->VideoTransferMatrix==5) // MFVideoTransferMatrix_BT2020_12 + return AVCOL_TRC_BT2020_12; + else + return AVCOL_TRC_BT2020_10; + case 14: // MFVideoTransFunc_26 + // not an FFmpeg transfer characteristic + return AVCOL_TRC_UNSPECIFIED; + case 15: // MFVideoTransFunc_2084 + return AVCOL_TRC_SMPTEST2084; + case 16: // MFVideoTransFunc_HLG + return AVCOL_TRC_ARIB_STD_B67; + case 17: // MFVideoTransFunc_10_rel + // not an FFmpeg transfer characteristic? Undocumented also by MS + return AVCOL_TRC_UNSPECIFIED; + + default: + return AVCOL_TRC_UNSPECIFIED; + } +} + +static enum AVChromaLocation dshow_chroma_loc(DXVA2_ExtendedFormat *fmt_info) +{ + if (fmt_info->VideoChromaSubsampling == DXVA2_VideoChromaSubsampling_Cosited) // that is: (DXVA2_VideoChromaSubsampling_Horizontally_Cosited | DXVA2_VideoChromaSubsampling_Vertically_Cosited | DXVA2_VideoChromaSubsampling_Vertically_AlignedChromaPlanes) + return AVCHROMA_LOC_TOPLEFT; + else if (fmt_info->VideoChromaSubsampling == DXVA2_VideoChromaSubsampling_MPEG1) // that is: DXVA2_VideoChromaSubsampling_Vertically_AlignedChromaPlanes + return AVCHROMA_LOC_CENTER; + else if (fmt_info->VideoChromaSubsampling == DXVA2_VideoChromaSubsampling_MPEG2) // that is: (DXVA2_VideoChromaSubsampling_Horizontally_Cosited | DXVA2_VideoChromaSubsampling_Vertically_AlignedChromaPlanes) + return AVCHROMA_LOC_LEFT; + else if (fmt_info->VideoChromaSubsampling == DXVA2_VideoChromaSubsampling_DV_PAL) // that is: (DXVA2_VideoChromaSubsampling_Horizontally_Cosited | DXVA2_VideoChromaSubsampling_Vertically_Cosited) + return AVCHROMA_LOC_TOPLEFT; + else + // unknown + return AVCHROMA_LOC_UNSPECIFIED; +} + static int dshow_read_close(AVFormatContext *s) { @@ -517,6 +728,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, VIDEO_STREAM_CONFIG_CAPS *vcaps = caps; BITMAPINFOHEADER *bih; int64_t *fr; + DXVA2_ExtendedFormat *extended_format_info = NULL; const AVCodecTag *const tags[] = { avformat_get_riff_video_tags(), NULL }; #if DSHOWDEBUG ff_print_VIDEO_STREAM_CONFIG_CAPS(vcaps); @@ -529,6 +741,8 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, VIDEOINFOHEADER2 *v = (void *) type->pbFormat; fr = &v->AvgTimePerFrame; bih = &v->bmiHeader; + if (v->dwControlFlags & AMCONTROL_COLORINFO_PRESENT) + extended_format_info = (DXVA2_ExtendedFormat *) &v->dwControlFlags; } else { goto next; } @@ -545,11 +759,40 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, } else { av_log(avctx, AV_LOG_INFO, " pixel_format=%s", av_get_pix_fmt_name(pix_fmt)); } - av_log(avctx, AV_LOG_INFO, " min s=%ldx%ld fps=%g max s=%ldx%ld fps=%g\n", + av_log(avctx, AV_LOG_INFO, " min s=%ldx%ld fps=%g max s=%ldx%ld fps=%g", vcaps->MinOutputSize.cx, vcaps->MinOutputSize.cy, 1e7 / vcaps->MaxFrameInterval, vcaps->MaxOutputSize.cx, vcaps->MaxOutputSize.cy, 1e7 / vcaps->MinFrameInterval); + if (extended_format_info) { + enum AVColorRange col_range = dshow_color_range(extended_format_info); + enum AVColorSpace col_space = dshow_color_space(extended_format_info); + enum AVColorPrimaries col_prim = dshow_color_primaries(extended_format_info); + enum AVColorTransferCharacteristic col_trc = dshow_color_trc(extended_format_info); + enum AVChromaLocation chroma_loc = dshow_chroma_loc(extended_format_info); + if (col_range != AVCOL_RANGE_UNSPECIFIED || col_space != AVCOL_SPC_UNSPECIFIED || col_prim != AVCOL_PRI_UNSPECIFIED || col_trc != AVCOL_TRC_UNSPECIFIED) { + const char *range = av_color_range_name(col_range); + const char *space = av_color_space_name(col_space); + const char *prim = av_color_primaries_name(col_prim); + const char *trc = av_color_transfer_name(col_trc); + av_log(avctx, AV_LOG_INFO, " (%s, %s/%s/%s", + range ? range : "unknown", + space ? space : "unknown", + prim ? prim : "unknown", + trc ? trc : "unknown"); + if (chroma_loc != AVCHROMA_LOC_UNSPECIFIED) { + const char *chroma = av_chroma_location_name(chroma_loc); + av_log(avctx, AV_LOG_INFO, ", %s", chroma ? chroma : "unknown"); + } + av_log(avctx, AV_LOG_INFO, ")"); + } + else if (chroma_loc != AVCHROMA_LOC_UNSPECIFIED) { + const char *chroma = av_chroma_location_name(chroma_loc); + av_log(avctx, AV_LOG_INFO, "(%s)", chroma ? chroma : "unknown"); + } + } + + av_log(avctx, AV_LOG_INFO, "\n"); continue; } if (ctx->video_codec_id != AV_CODEC_ID_RAWVIDEO) { @@ -1118,6 +1361,7 @@ dshow_add_device(AVFormatContext *avctx, if (devtype == VideoDevice) { BITMAPINFOHEADER *bih = NULL; AVRational time_base; + DXVA2_ExtendedFormat *extended_format_info = NULL; if (IsEqualGUID(&type.formattype, &FORMAT_VideoInfo)) { VIDEOINFOHEADER *v = (void *) type.pbFormat; @@ -1127,6 +1371,8 @@ dshow_add_device(AVFormatContext *avctx, VIDEOINFOHEADER2 *v = (void *) type.pbFormat; time_base = (AVRational) { v->AvgTimePerFrame, 10000000 }; bih = &v->bmiHeader; + if (v->dwControlFlags & AMCONTROL_COLORINFO_PRESENT) + extended_format_info = (DXVA2_ExtendedFormat *) &v->dwControlFlags; } if (!bih) { av_log(avctx, AV_LOG_ERROR, "Could not get media type.\n"); @@ -1145,6 +1391,13 @@ dshow_add_device(AVFormatContext *avctx, av_log(avctx, AV_LOG_DEBUG, "attempt to use full range for HDYC...\n"); par->color_range = AVCOL_RANGE_MPEG; // just in case it needs this... } + if (extended_format_info) { + par->color_range = dshow_color_range(extended_format_info); + par->color_space = dshow_color_space(extended_format_info); + par->color_primaries = dshow_color_primaries(extended_format_info); + par->color_trc = dshow_color_trc(extended_format_info); + par->chroma_location = dshow_chroma_loc(extended_format_info); + } if (par->format == AV_PIX_FMT_NONE) { const AVCodecTag *const tags[] = { avformat_get_riff_video_tags(), NULL }; par->codec_id = av_codec_get_id(tags, bih->biCompression); From patchwork Tue Dec 21 12:12:39 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: 32789 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5362159iog; Tue, 21 Dec 2021 04:15:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJz9WHLwg+s1gYk/+s04VpHjet2lBtU5jXZ5G09Y0TSETVgvmn3thPr7muzwLiCDTWe2+HGy X-Received: by 2002:a17:907:6287:: with SMTP id nd7mr2344556ejc.152.1640088931193; Tue, 21 Dec 2021 04:15:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640088931; cv=none; d=google.com; s=arc-20160816; b=n9Yml9DhPEuf1dozVdzVVigRrIvX4Yj1MTZc5CHKBm46ZJ5KM88ZbIcIEzROBwbha/ ylz5YIvUky90RcP4ZdeFck68gIxE2TxnEqFik1gt9qNQM4BI94JYxnC2MyKP1OMNGcTZ FiMNET3iJCmsSev5Cg9XZBKrYTe7hRR6FGeFFzLNfJmQUHvq6KG6p388M/OY3AQQlJf3 p7Dc38YcKWFP0+/IAdLpGT5nK1CqRumeh4VF8FnxZP3NsetAu3mtD2ML2QKGLZQzqO+A 2kpOJGkslr7yHnaLoa5Y7ZikvzvGE6S7MYiBIhTppKB6vgLWft835pLcpw+PIxZfdQ0m OX3A== 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=mUov6QIfYS0L+l3Y/GD6lU8w32YPfOK9fhqM9sE+UDg=; b=CIVq2JqrC9jruFhukrKqjKjZH7aMINoW+VxbcLy+x9PGul78qoxE9LC0GIr8giO6NZ jB00qYh3brqOiqimKNVhHziBXwENSlAfimBTtC8iDeG4xNQW49i5TvZR8OZkPshMbPOt 40CdjlvJinr0TYYpEDJrwdAbqzI4cY6igt2zWEn1g3xNIU6kcqps0/agC7FKyUkJ9P73 Xyva+UnOBAoffjGzYm0uJMD2J1GyeWce704eDQaSZvf8nOrD2gsP4ZoBGI0WnLB0GxXF G66BfA9HSxTtqs0KotxkFq1TBZCqnctf3g5kc3H7CLae0KuCheokZm1/IFYXW3ZsQuga ZwQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=BGqB1sDg; 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 z22si11794208edl.627.2021.12.21.04.15.28; Tue, 21 Dec 2021 04:15:31 -0800 (PST) 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=20210112 header.b=BGqB1sDg; 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 0C45A68B003; Tue, 21 Dec 2021 14:14:15 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E5C3668AF6F for ; Tue, 21 Dec 2021 14:14:13 +0200 (EET) Received: by mail-lj1-f177.google.com with SMTP id by39so2288406ljb.2 for ; Tue, 21 Dec 2021 04:14:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+OwrTMr3028Gp3cB5RmMx2Md/JT9X4XTp1QHSvVnlYk=; b=BGqB1sDgEEWxI+2pPiFgWWOw8v/T9B1tyrCOHrAWqb7IzC3cjfcdiqRMY86jaDWnHq 1uaX4eSYVWNzNfYDbQmi4SWFMQjJOaFLdxGN+QZybDVR91Q9IsZa27/bqu5Cjj+GcYrF kSxQ6Zi9QuCB4sEIWdLHjXiW50LKGv6FjhGUx715yWtMmbacxt0BPpi85ZKe25GqiU4N UBXcvH/4eThC1ZD+0zVXD58BlDF51BMShVc3BEsfUYkL07tbHmwF650h6QUZumFTw85F TjzgedTzfMt9pHHbZivxKvtJvU9gwvf08pTiuxlcACIS3D7RQRn17JqIm4e/zoDwtiFI MQ1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+OwrTMr3028Gp3cB5RmMx2Md/JT9X4XTp1QHSvVnlYk=; b=dm0p2UsdQumq5pIKoiMa/4N3wcj9pY0C0dhRBJfUJ+Wvv54Zh3oGcbbZU3xf+kVTC2 hUxb4W30z33off9zNfT5MTh9uPjJdT0cWP63Mq+zjiPlXbLhTs2rBTQHZAXuKrPBwA0u WYy2gUfLfJQUKMk5kxaJUpr84Z/Sej6MBNiThRnIpQeu0tn74CRmG+zlYxW+XQtVVXQ1 ZX2DCurwGuqZ0pdd/yceSoEPdLdUoRVVXJ3TK2/s939yPR+2+PtIAzRKQMtYZY0h3igJ RpEVtHAvPcT7vecMoRD4q3DA8XVQc7PRkEpsC5QqBx5/NYmeFaOhlQBKKHGDjPghJITi WBHQ== X-Gm-Message-State: AOAM531NRrkuJfRewK2eTAkhAkIewQ+R/K1fCogR+NS3GI2E2Gt7kwiu RMx7hqKr5Svba7Ym0yh6mErpuEwZxl5fxg== X-Received: by 2002:a2e:80c3:: with SMTP id r3mr2447576ljg.4.1640088852152; Tue, 21 Dec 2021 04:14:12 -0800 (PST) Received: from localhost.localdomain ([196.244.192.13]) by smtp.gmail.com with ESMTPSA id w25sm1611365lfl.33.2021.12.21.04.14.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 04:14:11 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 13:12:39 +0100 Message-Id: <20211221121239.1201-13-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211221121239.1201-1-dcnieho@gmail.com> References: <20211221121239.1201-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 12/12] avdevice/dshow: select format with extended color info 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: 0UEoP6APuqcO Some DirectShow devices (Logitech C920 webcam) expose each DirectShow format they support twice, once without and once with extended color information. During format selection, both match, this patch ensures that the format with extended color information is selected if it is available, else it falls back to a matching format without such information. This also necessitated a new code path taken for default formats of a device (when user didn't request any specific video size, etc), because the default format may be one without extended color information when a twin with extended color information is also available. Getting the extended color information when available is important as it allows setting the color space, range, primaries, transfer characteristics and chroma location of the stream provided by dshow, enabling users to get more correct color automatically out of their device. Closes: #9271 Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 471 ++++++++++++++++++++++++++++++++------------ 1 file changed, 340 insertions(+), 131 deletions(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 79be32b255..b87313acb9 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -23,6 +23,7 @@ #include "libavutil/parseutils.h" #include "libavutil/pixdesc.h" #include "libavutil/opt.h" +#include "libavutil/mem.h" #include "libavformat/internal.h" #include "libavformat/riff.h" #include "avdevice.h" @@ -690,9 +691,111 @@ error: return ret; } +static int dshow_should_set_format(AVFormatContext *avctx, enum dshowDeviceType devtype) +{ + struct dshow_ctx *ctx = avctx->priv_data; + + return (devtype == VideoDevice && (ctx->framerate || + (ctx->requested_width && ctx->requested_height) || + ctx->pixel_format != AV_PIX_FMT_NONE || + ctx->video_codec_id != AV_CODEC_ID_RAWVIDEO)) + || (devtype == AudioDevice && (ctx->channels || ctx->sample_size || ctx->sample_rate)); +} + + +struct dshow_format_info { + enum dshowDeviceType devtype; + // video + int64_t framerate; + enum AVPixelFormat pix_fmt; + enum AVCodecID codec_id; + enum AVColorRange col_range; + enum AVColorSpace col_space; + enum AVColorPrimaries col_prim; + enum AVColorTransferCharacteristic col_trc; + enum AVChromaLocation chroma_loc; + int width; + int height; + // audio + int sample_rate; + int sample_size; + int channels; +}; + +// user must av_free the returned pointer +static struct dshow_format_info *dshow_get_format_info(AM_MEDIA_TYPE *type) +{ + struct dshow_format_info *fmt_info = NULL; + BITMAPINFOHEADER *bih; + DXVA2_ExtendedFormat *extended_format_info = NULL; + WAVEFORMATEX *fx; + enum dshowDeviceType devtype; + int64_t framerate; + + if (!type) + return NULL; + + if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo)) { + VIDEOINFOHEADER *v = (void *) type->pbFormat; + framerate = v->AvgTimePerFrame; + bih = &v->bmiHeader; + devtype = VideoDevice; + } else if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo2)) { + VIDEOINFOHEADER2 *v = (void *) type->pbFormat; + devtype = VideoDevice; + framerate = v->AvgTimePerFrame; + bih = &v->bmiHeader; + if (v->dwControlFlags & AMCONTROL_COLORINFO_PRESENT) + extended_format_info = (DXVA2_ExtendedFormat *) &v->dwControlFlags; + } else if (IsEqualGUID(&type->formattype, &FORMAT_WaveFormatEx)) { + fx = (void *) type->pbFormat; + devtype = AudioDevice; + } else { + return NULL; + } + + fmt_info = av_mallocz(sizeof(struct dshow_format_info)); + if (!fmt_info) + return NULL; + // initialize fields where unset is not zero + fmt_info->pix_fmt = AV_PIX_FMT_NONE; + fmt_info->col_space = AVCOL_SPC_UNSPECIFIED; + fmt_info->col_prim = AVCOL_PRI_UNSPECIFIED; + fmt_info->col_trc = AVCOL_TRC_UNSPECIFIED; + // now get info about format + fmt_info->devtype = devtype; + if (devtype == VideoDevice) { + fmt_info->width = bih->biWidth; + fmt_info->height = bih->biHeight; + fmt_info->framerate = framerate; + fmt_info->pix_fmt = dshow_pixfmt(bih->biCompression, bih->biBitCount); + if (fmt_info->pix_fmt == AV_PIX_FMT_NONE) { + const AVCodecTag *const tags[] = { avformat_get_riff_video_tags(), NULL }; + fmt_info->codec_id = av_codec_get_id(tags, bih->biCompression); + } + else + fmt_info->codec_id = AV_CODEC_ID_RAWVIDEO; + + if (extended_format_info) { + fmt_info->col_range = dshow_color_range(extended_format_info); + fmt_info->col_space = dshow_color_space(extended_format_info); + fmt_info->col_prim = dshow_color_primaries(extended_format_info); + fmt_info->col_trc = dshow_color_trc(extended_format_info); + fmt_info->chroma_loc = dshow_chroma_loc(extended_format_info); + } + } else { + fmt_info->sample_rate = fx->nSamplesPerSec; + fmt_info->sample_size = fx->wBitsPerSample; + fmt_info->channels = fx->nChannels; + } + + return fmt_info; +} + /** - * Cycle through available formats using the specified pin, - * try to set parameters specified through AVOptions and if successful + * Cycle through available formats available from the specified pin, + * try to set parameters specified through AVOptions, or the pin's + * default format if no such parameters were set. If successful, * return 1 in *pformat_set. * If pformat_set is NULL, list all pin capabilities. */ @@ -703,9 +806,27 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, struct dshow_ctx *ctx = avctx->priv_data; IAMStreamConfig *config = NULL; AM_MEDIA_TYPE *type = NULL; + AM_MEDIA_TYPE *previous_match_type = NULL; int format_set = 0; void *caps = NULL; int i, n, size, r; + int wait_for_better = 0; + int use_default; + + // format parameters requested by user + // if none are requested by user, the values will below be set to + // those of the default format + // video + enum AVCodecID requested_video_codec_id = ctx->video_codec_id; + enum AVPixelFormat requested_pixel_format = ctx->pixel_format; + int64_t requested_framerate = ctx->framerate ? ((int64_t)ctx->requested_framerate.den * 10000000) + / ctx->requested_framerate.num : 0; + int requested_width = ctx->requested_width; + int requested_height = ctx->requested_height; + // audio + int requested_sample_rate = ctx->sample_rate; + int requested_sample_size = ctx->sample_size; + int requested_channels = ctx->channels; if (IPin_QueryInterface(pin, &IID_IAMStreamConfig, (void **) &config) != S_OK) return; @@ -716,7 +837,83 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, if (!caps) goto end; + /** + * If we should open the device with the default format, + * then: + * 1. check what the format of the default device is, and + * 2. below we iterate all formats till we find a matching + * one, with most info exposed (see comment below). + */ + use_default = !dshow_should_set_format(avctx, devtype); + if (use_default && pformat_set) + { + HRESULT hr; + + // get default + if ((hr = IAMStreamConfig_GetFormat(config, &type)) != S_OK) { + if (hr == E_NOTIMPL || !IsEqualGUID(&type->majortype, devtype==VideoDevice ? &MEDIATYPE_Video : &MEDIATYPE_Audio)) { + // default not available or of wrong type, + // fall back to iterating exposed formats + // until one of the right type is found + IEnumMediaTypes *types = NULL; + if (IPin_EnumMediaTypes(pin, &types) != S_OK) + goto end; + IEnumMediaTypes_Reset(types); + while (IEnumMediaTypes_Next(types, 1, &type, NULL) == S_OK) { + if (IsEqualGUID(&type->majortype, devtype==VideoDevice ? &MEDIATYPE_Video : &MEDIATYPE_Audio)) { + break; + } + CoTaskMemFree(type); + type = NULL; + } + IEnumMediaTypes_Release(types); + } + + if (!type) + // this pin does not expose any formats of the expected type + goto end; + } + + if (type) { + // interrogate default format, so we know what to search for below + struct dshow_format_info *fmt_info = dshow_get_format_info(type); + if (fmt_info) { + if (fmt_info->devtype == VideoDevice) { + requested_video_codec_id = fmt_info->codec_id; + requested_pixel_format = fmt_info->pix_fmt; + requested_framerate = fmt_info->framerate; + requested_width = fmt_info->width; + requested_height = fmt_info->height; + } else { + requested_sample_rate = fmt_info->sample_rate; + requested_sample_size = fmt_info->sample_size; + requested_channels = fmt_info->channels; + } + av_free(fmt_info); // free but don't set to NULL to enable below check + } + + if (type && type->pbFormat) + CoTaskMemFree(type->pbFormat); + CoTaskMemFree(type); + type = NULL; + if (!fmt_info) + // default format somehow invalid, can't continue with this pin + goto end; + fmt_info = NULL; + } + } + + // NB: some devices (e.g. Logitech C920) expose each video format twice: + // both a format containing a VIDEOINFOHEADER and a format containing + // a VIDEOINFOHEADER2. We want, if possible, to select a format with a + // VIDEOINFOHEADER2, as this potentially provides more info about the + // format. So, if in the iteration below we have found a matching format, + // but it is a VIDEOINFOHEADER, keep looking for a matching format that + // exposes contains a VIDEOINFOHEADER2. Fall back to the VIDEOINFOHEADER + // format if no corresponding VIDEOINFOHEADER2 is found when we finish + // iterating. for (i = 0; i < n && !format_set; i++) { + struct dshow_format_info *fmt_info = NULL; r = IAMStreamConfig_GetStreamCaps(config, i, &type, (void *) caps); if (r != S_OK) goto next; @@ -724,106 +921,101 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, ff_print_AM_MEDIA_TYPE(type); #endif + fmt_info = dshow_get_format_info(type); + if (!fmt_info) + goto next; + if (devtype == VideoDevice) { VIDEO_STREAM_CONFIG_CAPS *vcaps = caps; BITMAPINFOHEADER *bih; int64_t *fr; - DXVA2_ExtendedFormat *extended_format_info = NULL; - const AVCodecTag *const tags[] = { avformat_get_riff_video_tags(), NULL }; #if DSHOWDEBUG ff_print_VIDEO_STREAM_CONFIG_CAPS(vcaps); #endif + + if (fmt_info->devtype != VideoDevice) + goto next; + if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo)) { VIDEOINFOHEADER *v = (void *) type->pbFormat; - fr = &v->AvgTimePerFrame; + fr = &v->AvgTimePerFrame; bih = &v->bmiHeader; + wait_for_better = 1; } else if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo2)) { VIDEOINFOHEADER2 *v = (void *) type->pbFormat; - fr = &v->AvgTimePerFrame; + fr = &v->AvgTimePerFrame; bih = &v->bmiHeader; - if (v->dwControlFlags & AMCONTROL_COLORINFO_PRESENT) - extended_format_info = (DXVA2_ExtendedFormat *) &v->dwControlFlags; - } else { - goto next; + wait_for_better = 0; } + if (!pformat_set) { - enum AVPixelFormat pix_fmt = dshow_pixfmt(bih->biCompression, bih->biBitCount); - if (pix_fmt == AV_PIX_FMT_NONE) { - enum AVCodecID codec_id = av_codec_get_id(tags, bih->biCompression); - const AVCodec *codec = avcodec_find_decoder(codec_id); - if (codec_id == AV_CODEC_ID_NONE || !codec) { + if (fmt_info->pix_fmt == AV_PIX_FMT_NONE) { + const AVCodec *codec = avcodec_find_decoder(fmt_info->codec_id); + if (fmt_info->codec_id == AV_CODEC_ID_NONE || !codec) { av_log(avctx, AV_LOG_INFO, " unknown compression type 0x%X", (int) bih->biCompression); } else { av_log(avctx, AV_LOG_INFO, " vcodec=%s", codec->name); } } else { - av_log(avctx, AV_LOG_INFO, " pixel_format=%s", av_get_pix_fmt_name(pix_fmt)); + av_log(avctx, AV_LOG_INFO, " pixel_format=%s", av_get_pix_fmt_name(fmt_info->pix_fmt)); } av_log(avctx, AV_LOG_INFO, " min s=%ldx%ld fps=%g max s=%ldx%ld fps=%g", vcaps->MinOutputSize.cx, vcaps->MinOutputSize.cy, 1e7 / vcaps->MaxFrameInterval, vcaps->MaxOutputSize.cx, vcaps->MaxOutputSize.cy, 1e7 / vcaps->MinFrameInterval); - if (extended_format_info) { - enum AVColorRange col_range = dshow_color_range(extended_format_info); - enum AVColorSpace col_space = dshow_color_space(extended_format_info); - enum AVColorPrimaries col_prim = dshow_color_primaries(extended_format_info); - enum AVColorTransferCharacteristic col_trc = dshow_color_trc(extended_format_info); - enum AVChromaLocation chroma_loc = dshow_chroma_loc(extended_format_info); - if (col_range != AVCOL_RANGE_UNSPECIFIED || col_space != AVCOL_SPC_UNSPECIFIED || col_prim != AVCOL_PRI_UNSPECIFIED || col_trc != AVCOL_TRC_UNSPECIFIED) { - const char *range = av_color_range_name(col_range); - const char *space = av_color_space_name(col_space); - const char *prim = av_color_primaries_name(col_prim); - const char *trc = av_color_transfer_name(col_trc); - av_log(avctx, AV_LOG_INFO, " (%s, %s/%s/%s", - range ? range : "unknown", - space ? space : "unknown", - prim ? prim : "unknown", - trc ? trc : "unknown"); - if (chroma_loc != AVCHROMA_LOC_UNSPECIFIED) { - const char *chroma = av_chroma_location_name(chroma_loc); - av_log(avctx, AV_LOG_INFO, ", %s", chroma ? chroma : "unknown"); - } - av_log(avctx, AV_LOG_INFO, ")"); - } - else if (chroma_loc != AVCHROMA_LOC_UNSPECIFIED) { - const char *chroma = av_chroma_location_name(chroma_loc); - av_log(avctx, AV_LOG_INFO, "(%s)", chroma ? chroma : "unknown"); - } + + const char *chroma = av_chroma_location_name(fmt_info->chroma_loc); + if (fmt_info->col_range != AVCOL_RANGE_UNSPECIFIED || + fmt_info->col_space != AVCOL_SPC_UNSPECIFIED || + fmt_info->col_prim != AVCOL_PRI_UNSPECIFIED || + fmt_info->col_trc != AVCOL_TRC_UNSPECIFIED) { + const char *range = av_color_range_name(fmt_info->col_range); + const char *space = av_color_space_name(fmt_info->col_space); + const char *prim = av_color_primaries_name(fmt_info->col_prim); + const char *trc = av_color_transfer_name(fmt_info->col_trc); + av_log(avctx, AV_LOG_INFO, " (%s, %s/%s/%s", + range ? range : "unknown", + space ? space : "unknown", + prim ? prim : "unknown", + trc ? trc : "unknown"); + if (fmt_info->chroma_loc != AVCHROMA_LOC_UNSPECIFIED) + av_log(avctx, AV_LOG_INFO, ", %s", chroma ? chroma : "unknown"); + av_log(avctx, AV_LOG_INFO, ")"); } + else if (fmt_info->chroma_loc != AVCHROMA_LOC_UNSPECIFIED) + av_log(avctx, AV_LOG_INFO, "(%s)", chroma ? chroma : "unknown"); av_log(avctx, AV_LOG_INFO, "\n"); continue; } - if (ctx->video_codec_id != AV_CODEC_ID_RAWVIDEO) { - if (ctx->video_codec_id != av_codec_get_id(tags, bih->biCompression)) + if (requested_video_codec_id != AV_CODEC_ID_RAWVIDEO) { + if (requested_video_codec_id != fmt_info->codec_id) goto next; } - if (ctx->pixel_format != AV_PIX_FMT_NONE && - ctx->pixel_format != dshow_pixfmt(bih->biCompression, bih->biBitCount)) { + if (requested_pixel_format != AV_PIX_FMT_NONE && + requested_pixel_format != fmt_info->pix_fmt) { goto next; } - if (ctx->framerate) { - int64_t framerate = ((int64_t) ctx->requested_framerate.den*10000000) - / ctx->requested_framerate.num; - if (framerate > vcaps->MaxFrameInterval || - framerate < vcaps->MinFrameInterval) + if (requested_framerate) { + if (requested_framerate > vcaps->MaxFrameInterval || + requested_framerate < vcaps->MinFrameInterval) goto next; - *fr = framerate; + *fr = requested_framerate; } - if (ctx->requested_width && ctx->requested_height) { - if (ctx->requested_width > vcaps->MaxOutputSize.cx || - ctx->requested_width < vcaps->MinOutputSize.cx || - ctx->requested_height > vcaps->MaxOutputSize.cy || - ctx->requested_height < vcaps->MinOutputSize.cy) + if (requested_width && requested_height) { + if (requested_width > vcaps->MaxOutputSize.cx || + requested_width < vcaps->MinOutputSize.cx || + requested_height > vcaps->MaxOutputSize.cy || + requested_height < vcaps->MinOutputSize.cy) goto next; - bih->biWidth = ctx->requested_width; - bih->biHeight = ctx->requested_height; + bih->biWidth = requested_width; + bih->biHeight = requested_height; } } else { WAVEFORMATEX *fx; -#if DSHOWDEBUG AUDIO_STREAM_CONFIG_CAPS *acaps = caps; +#if DSHOWDEBUG ff_print_AUDIO_STREAM_CONFIG_CAPS(acaps); #endif if (IsEqualGUID(&type->formattype, &FORMAT_WaveFormatEx)) { @@ -840,23 +1032,62 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, ); continue; } - if ( - (ctx->sample_rate && ctx->sample_rate != fx->nSamplesPerSec) || - (ctx->sample_size && ctx->sample_size != fx->wBitsPerSample) || - (ctx->channels && ctx->channels != fx->nChannels ) - ) { - goto next; + if (requested_sample_rate) { + if (requested_sample_rate > acaps->MaximumSampleFrequency || + requested_sample_rate < acaps->MinimumSampleFrequency) + goto next; + fx->nSamplesPerSec = requested_sample_rate; + } + if (requested_sample_size) { + if (requested_sample_size > acaps->MaximumBitsPerSample || + requested_sample_size < acaps->MinimumBitsPerSample) + goto next; + fx->wBitsPerSample = requested_sample_size; + } + if (requested_channels) { + if (requested_channels > acaps->MaximumChannels || + requested_channels < acaps->MinimumChannels) + goto next; + fx->nChannels = requested_channels; } } - if (IAMStreamConfig_SetFormat(config, type) != S_OK) - goto next; - format_set = 1; + + // found a matching format. Either apply or store + // for safekeeping if we might maybe find a better + // format with more info attached to it (see comment + // above loop) + if (!wait_for_better) { + if (IAMStreamConfig_SetFormat(config, type) != S_OK) + goto next; + format_set = 1; + } + else if (!previous_match_type) { + // store this matching format for possible later use. + // If we have already found a matching format, ignore it + previous_match_type = type; + type = NULL; + } next: - if (type->pbFormat) + av_freep(&fmt_info); + if (type && type->pbFormat) CoTaskMemFree(type->pbFormat); CoTaskMemFree(type); } + // previously found a matching VIDEOINFOHEADER format and stored + // it for safe keeping. Searching further for a matching + // VIDEOINFOHEADER2 format yielded nothing. So set the pin's + // format based on the VIDEOINFOHEADER format. + // NB: this never applies to an audio format because + // previous_match_type always NULL in that case + if (!format_set && previous_match_type) { + if (IAMStreamConfig_SetFormat(config, previous_match_type) == S_OK) + format_set = 1; + } + end: + if (previous_match_type && previous_match_type->pbFormat) + CoTaskMemFree(previous_match_type->pbFormat); + CoTaskMemFree(previous_match_type); IAMStreamConfig_Release(config); av_free(caps); if (pformat_set) @@ -975,11 +1206,7 @@ dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype, const char *devtypename = (devtype == VideoDevice) ? "video" : "audio only"; const char *sourcetypename = (sourcetype == VideoSourceDevice) ? "video" : "audio"; - int set_format = (devtype == VideoDevice && (ctx->framerate || - (ctx->requested_width && ctx->requested_height) || - ctx->pixel_format != AV_PIX_FMT_NONE || - ctx->video_codec_id != AV_CODEC_ID_RAWVIDEO)) - || (devtype == AudioDevice && (ctx->channels || ctx->sample_rate || ctx->sample_size)); + int set_format = dshow_should_set_format(avctx, devtype); int format_set = 0; int should_show_properties = (devtype == VideoDevice) ? ctx->show_video_device_dialog : ctx->show_audio_device_dialog; @@ -999,9 +1226,7 @@ dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype, while (!device_pin && IEnumPins_Next(pins, 1, &pin, NULL) == S_OK) { IKsPropertySet *p = NULL; - IEnumMediaTypes *types = NULL; PIN_INFO info = {0}; - AM_MEDIA_TYPE *type; GUID category; DWORD r2; char *name_buf = NULL; @@ -1044,35 +1269,24 @@ dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype, } } - if (set_format) { - dshow_cycle_formats(avctx, devtype, pin, &format_set); - if (!format_set) { - goto next; - } + // will either try to find format matching options supplied by user + // or try to open default format. Successful if returns with format_set==1 + dshow_cycle_formats(avctx, devtype, pin, &format_set); + if (!format_set) { + goto next; } + if (devtype == AudioDevice && ctx->audio_buffer_size) { if (dshow_set_audio_buffer_size(avctx, pin) < 0) { av_log(avctx, AV_LOG_ERROR, "unable to set audio buffer size %d to pin, using pin anyway...", ctx->audio_buffer_size); } } - if (IPin_EnumMediaTypes(pin, &types) != S_OK) - goto next; - - IEnumMediaTypes_Reset(types); - /* in case format_set was not called, just verify the majortype */ - while (!device_pin && IEnumMediaTypes_Next(types, 1, &type, NULL) == S_OK) { - if (IsEqualGUID(&type->majortype, mediatype[devtype])) { - device_pin = pin; - av_log(avctx, AV_LOG_DEBUG, "Selecting pin %s on %s\n", name_buf, devtypename); - goto next; - } - CoTaskMemFree(type); + if (format_set) { + device_pin = pin; + av_log(avctx, AV_LOG_DEBUG, "Selecting pin %s on %s\n", name_buf, devtypename); } - next: - if (types) - IEnumMediaTypes_Release(types); if (p) IKsPropertySet_Release(p); if (device_pin != pin) @@ -1342,6 +1556,7 @@ dshow_add_device(AVFormatContext *avctx, AM_MEDIA_TYPE type; AVCodecParameters *par; AVStream *st; + struct dshow_format_info *fmt_info = NULL; int ret = AVERROR(EIO); type.pbFormat = NULL; @@ -1356,12 +1571,16 @@ dshow_add_device(AVFormatContext *avctx, ctx->capture_filter[devtype]->stream_index = st->index; ff_dshow_pin_ConnectionMediaType(ctx->capture_pin[devtype], &type); + fmt_info = dshow_get_format_info(&type); + if (!fmt_info) { + ret = AVERROR(EIO); + goto error; + } par = st->codecpar; if (devtype == VideoDevice) { BITMAPINFOHEADER *bih = NULL; AVRational time_base; - DXVA2_ExtendedFormat *extended_format_info = NULL; if (IsEqualGUID(&type.formattype, &FORMAT_VideoInfo)) { VIDEOINFOHEADER *v = (void *) type.pbFormat; @@ -1371,8 +1590,6 @@ dshow_add_device(AVFormatContext *avctx, VIDEOINFOHEADER2 *v = (void *) type.pbFormat; time_base = (AVRational) { v->AvgTimePerFrame, 10000000 }; bih = &v->bmiHeader; - if (v->dwControlFlags & AMCONTROL_COLORINFO_PRESENT) - extended_format_info = (DXVA2_ExtendedFormat *) &v->dwControlFlags; } if (!bih) { av_log(avctx, AV_LOG_ERROR, "Could not get media type.\n"); @@ -1383,33 +1600,21 @@ dshow_add_device(AVFormatContext *avctx, st->r_frame_rate = av_inv_q(time_base); par->codec_type = AVMEDIA_TYPE_VIDEO; - par->width = bih->biWidth; - par->height = bih->biHeight; + par->width = fmt_info->width; + par->height = fmt_info->height; par->codec_tag = bih->biCompression; - par->format = dshow_pixfmt(bih->biCompression, bih->biBitCount); + par->format = fmt_info->pix_fmt; if (bih->biCompression == MKTAG('H', 'D', 'Y', 'C')) { av_log(avctx, AV_LOG_DEBUG, "attempt to use full range for HDYC...\n"); par->color_range = AVCOL_RANGE_MPEG; // just in case it needs this... } - if (extended_format_info) { - par->color_range = dshow_color_range(extended_format_info); - par->color_space = dshow_color_space(extended_format_info); - par->color_primaries = dshow_color_primaries(extended_format_info); - par->color_trc = dshow_color_trc(extended_format_info); - par->chroma_location = dshow_chroma_loc(extended_format_info); - } - if (par->format == AV_PIX_FMT_NONE) { - const AVCodecTag *const tags[] = { avformat_get_riff_video_tags(), NULL }; - par->codec_id = av_codec_get_id(tags, bih->biCompression); - if (par->codec_id == AV_CODEC_ID_NONE) { - av_log(avctx, AV_LOG_ERROR, "Unknown compression type. " - "Please report type 0x%X.\n", (int) bih->biCompression); - ret = AVERROR_PATCHWELCOME; - goto error; - } - par->bits_per_coded_sample = bih->biBitCount; - } else { - par->codec_id = AV_CODEC_ID_RAWVIDEO; + par->color_range = fmt_info->col_range; + par->color_space = fmt_info->col_space; + par->color_primaries = fmt_info->col_prim; + par->color_trc = fmt_info->col_trc; + par->chroma_location = fmt_info->chroma_loc; + par->codec_id = fmt_info->codec_id; + if (par->codec_id == AV_CODEC_ID_RAWVIDEO) { if (bih->biCompression == BI_RGB || bih->biCompression == BI_BITFIELDS) { par->bits_per_coded_sample = bih->biBitCount; if (par->height < 0) { @@ -1422,23 +1627,26 @@ dshow_add_device(AVFormatContext *avctx, } } } + } else { + if (par->codec_id == AV_CODEC_ID_NONE) { + av_log(avctx, AV_LOG_ERROR, "Unknown compression type. " + "Please report type 0x%X.\n", (int) bih->biCompression); + ret = AVERROR_PATCHWELCOME; + goto error; + } + par->bits_per_coded_sample = bih->biBitCount; } } else { - WAVEFORMATEX *fx = NULL; - - if (IsEqualGUID(&type.formattype, &FORMAT_WaveFormatEx)) { - fx = (void *) type.pbFormat; - } - if (!fx) { + if (!IsEqualGUID(&type.formattype, &FORMAT_WaveFormatEx)) { av_log(avctx, AV_LOG_ERROR, "Could not get media type.\n"); goto error; } par->codec_type = AVMEDIA_TYPE_AUDIO; - par->format = sample_fmt_bits_per_sample(fx->wBitsPerSample); + par->format = sample_fmt_bits_per_sample(fmt_info->sample_size); par->codec_id = waveform_codec_id(par->format); - par->sample_rate = fx->nSamplesPerSec; - par->channels = fx->nChannels; + par->sample_rate = fmt_info->sample_rate; + par->channels = fmt_info->channels; } avpriv_set_pts_info(st, 64, 1, 10000000); @@ -1446,6 +1654,7 @@ dshow_add_device(AVFormatContext *avctx, ret = 0; error: + av_freep(&fmt_info); if (type.pbFormat) CoTaskMemFree(type.pbFormat); return ret;