From patchwork Tue Dec 21 13:53:26 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: 32791 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5444142iog; Tue, 21 Dec 2021 05:54:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJz4XUDIt7h33e1MIYQ1R5D7SN270sZbB2BES4KBTmQ8aX7MAVuVGaHaweZs8NE/lNvDzO6i X-Received: by 2002:a17:907:7b9e:: with SMTP id ne30mr2866933ejc.24.1640094861795; Tue, 21 Dec 2021 05:54:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640094861; cv=none; d=google.com; s=arc-20160816; b=tGTMNKDelfF4gg8Mo78IHdZ954x9YnMAk2oesQvL5SdMpQTlnkKrCd0VOWev7cocFH Q4lizw/keCK5pOUn5zzJHgtPCjKsQNHSc9710YYFnVi15YVpsqvAOYMZiidUd52KLQUm BbLSgUL+U4ILck48Bdja7eFmlc2DrCogGdNWGfu/jK38/VA/1fXRMZiOODHsV2S/cP9F bxAYr/iYhGB095kUOp/FxDPD5iiSOuUZzVPDIP8Vd/qDEFmymFxDZs9XSWiIkmf06hc4 JtpPCN69SeH8ugTXXXiywRXJLXJ/xR9FxqGrrw1TruRlkw8zJbcj0EzN56QE/HVuUg3D Jf0A== 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=CzWX5dJeG7+LuGW8BxUqlMW/CXDGHepgiTh3MlmyoeRWIBpF8pxOsxBBI1DsRKVtOM GwFLwu0uZwM6MmU3saWwm2+rVYQNIxZrbNl/pKNWDq3RbF9v1tyETNibpwxCcwn5yXRp 7KntsanOeWTSyMoQHQoZVpOAQRwoeDJt5PkrwDJIVcko4XYBqBBaA+7hZaJsLD3y6zi2 uBpr/f6nwPhttanvRMUlZgoPItiPU4uRVZglAc8UFrb3+cpIvw/YMBzDPXzSFRRm/x/N 71A0zuIsfSFF0yWn1aaKmmeJjYnRQP4Z9Z0qm43Mvi6c7O0fY6xN8igch4E+qkD83Sp6 NCoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=ZyhtH3VI; 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 nc5si16538755ejc.792.2021.12.21.05.54.20; Tue, 21 Dec 2021 05:54:21 -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=ZyhtH3VI; 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 4B14168AF88; Tue, 21 Dec 2021 15:54:07 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DEAF768AC7B for ; Tue, 21 Dec 2021 15:53:59 +0200 (EET) Received: by mail-lf1-f53.google.com with SMTP id g26so13691772lfv.11 for ; Tue, 21 Dec 2021 05:53: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=n4ECdPBbt8xqX/bDaPPPd4LEZ+alPN7BkD4xWH+ML2s=; b=ZyhtH3VI25wz63r3pof9/n6sS4j/Vf3jbHUK+/Dm2v8ceP7u8FWv7a2yXPrs+hytRG /mnS71apZ6IlEflb5d3NH5574bnDyURhmDGaW9uxGN8DpNj3/5uUWJ2iXuquXfKbkKCB ZE/PVzUJA7zv8EfgduN/hC2cFZk9bqJeKhAEK/ZAeqBCtobhaiK4jIFHld7E8/JZaIvB U94pgDk32nUHLMcrD3geVLip0vZy4zXF78OeJt4+OnbkoqO8ag86mxrulcQsAuQwJC7v 0XqG03Tkd8cqSswwP7K85fWke3I+q9YuOf8XRhvXg6EkDzxhBr3xsZ46M/1xRGdg9wZw xcOw== 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=LqRQwbfSqwQPin4Kss4s9ehQtT1lAuSN9/dR4T1CFpzLNshaXkiEA2XK5B3InA5lmQ wCAIUhH2Vm9GB1f+9awEnk34DQJ2pFF/P+S+fhwuxkrRogFdkHqi37MAK9JueJZoPrQh c7rP2E7vb1nBA1ZXWVpQ2pcygruVdAk/EKIncYaKyVIlrlmC9I5BxAm2BowS+C8XOFQw EomiQtQZZguiziK+4ktH+BGLEImsX8X53ndX/ihDrI1Vq5GgHQXrt4zK1uLk69A9Z4QO d/OY2qE692FBWYM+Cq1Dog24Owbg+jNAyzrwdKqu/hPmrwJYBmRxMTjWK5giXoMsNdsR vtpw== X-Gm-Message-State: AOAM530+ObNC3fM0howZa8+WotIP1OBBFbhB2tOuIrVfEPcncVb4vGSn /gwJJ5GZAsCHgANtGwbZ4UhKrKHdo1rXNw== X-Received: by 2002:a05:6512:1194:: with SMTP id g20mr3110921lfr.58.1640094839044; Tue, 21 Dec 2021 05:53:59 -0800 (PST) Received: from localhost.localdomain ([196.244.192.13]) by smtp.gmail.com with ESMTPSA id e12sm990474lfr.179.2021.12.21.05.53.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 05:53:58 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 14:53:26 +0100 Message-Id: <20211221135337.1348-2-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211221135337.1348-1-dcnieho@gmail.com> References: <20211221135337.1348-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 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: T+Oo5J/LRtur 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 13:53:27 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: 32792 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5444246iog; Tue, 21 Dec 2021 05:54:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJwZM1HKx9V80YTcHiLlxDYPJRHugFXKST60Qe5yjOEpqyE07ERkEJv6BEv6bN91+m+eVjFT X-Received: by 2002:a50:fc07:: with SMTP id i7mr3356506edr.117.1640094871575; Tue, 21 Dec 2021 05:54:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640094871; cv=none; d=google.com; s=arc-20160816; b=BdoJz+20CGVYlGDlM3mL1mKHgjhH+JTZa5gfdknSz8gfRVEr2sLkS8RiW3XMvJJGqD VUBHiFUvC1jhfOP3nnvLuyoz4zpLvaN5r3IusrMXea68upnOHdIv3+L7j83x3gBKfpfM pDhzSQmwxUQv+LqeIcaQxdLPbLoBmIQEPVvXdF+4WeIFA68lO59KgzYaksuzAzoUEMA+ nDBxfZPjOqlQHIJV91nxzI2c8GSpg78vGAgWGq7RCUk2G+0Wk67SoErn/MQ4wNqDko/k 9DRz54yzqnhEbDhG46axgesQRuC/uEJVrBn4RW0vQ5giV3GwR4cpdsOiEAU167LqjZIt vG+g== 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=doj/kIW+dZcyxcuqlrOdHKeQC2IaOoZVrarA4xVjd+DThpPI4+FhUhqrKDzqvTocxv ztzB1X4aSaLgTQ8mcvRrw8yyp/IYNNLrggS4TRGtAiEedxmQnB7rxnE+VYyjCTLkPZp/ sxqPCoWKWZSq4M0+J5Q3fcvASm1+QmCCjDEUFS4jBYF7fiOW6nnVKlMFuolkORXhDGDw y9Kur2A0DT6Dkl3lFH/WcWa1O54y2nLRST479kTq+NMsQYWpOpFvswCAUnIcLz2wAcyE 3j2qJ1jKIxNiQrK5cXgbMMJyqwdixvi4eYcrUBx+iU2ex/qnjyjuR9c3/VCMVIBHSxi+ /3wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=NM0rak3H; 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 c25si10187107ejb.372.2021.12.21.05.54.30; Tue, 21 Dec 2021 05:54: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=NM0rak3H; 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 4506B68AF9C; Tue, 21 Dec 2021 15:54:13 +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 21B1D68AF55 for ; Tue, 21 Dec 2021 15:54:07 +0200 (EET) Received: by mail-lf1-f50.google.com with SMTP id bt1so29422230lfb.13 for ; Tue, 21 Dec 2021 05:54:07 -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=NM0rak3HxspKcR1b65gbx9XSFgHfhC1DsHBdpiRfTH34/ahmdJC1Kv2Sv1hfaERDNM XAxfUSHgYvsL7X3WAx10eqv+0laOaQtHeS8S4+5EyNkx9Ln8N4WG7v5SbGY9KsT/LIzA FasrDuNQRr4LkR+VSqViuLI4Dfcs0Rik1JCPnTCVqSGWXeMD3wh6b8cSNzzxz8CBY4NB +M4He0dk4Wo5DjlEqLtodkNM4lvcnMyDyIcvLtJ5ZxlaTx9LpR7YXgqz2hzfmazxeYrm CUviMQS2NIRF71Igf73nH2AD2tzFCHHXEbjRByWKEvVbOhK3Jleg7ad9jmfnKqKz0lot xaWg== 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=zkuGlI15C6dwiE95MUw32T9mDoGWo0jkg1LyqnlEOAl4rWud7FYs/ZkzB4QW385eXv DDAWfw1HEp2ZS6TBTocWdoQCcY5CGCft3B+5zIP99K/ZuDZWBI2o1ZQ6OMSaQeQG+uvn Fc8dU9nbAP0uY9NEatsks8c+AuKVVO7JzzeYEWvc/Gve0VcAVD4ucjRFFRCnJSPAxSrs UwgNv8jIGiY++sgPOkEzXWRqquNK5k+jNwtF2Crl7xfSWjGIbaDGxfwP/cRmALfVkYbT lLTNdXMAVZhelkX/QpmXFw0BnHMszDN8EZnRdEvHgWwfQh8R0KypBbYRD1OU1xSlnz7t WY1Q== X-Gm-Message-State: AOAM530Hk9v83Ewf3sm6DF6rnX8LOYUE1GnwAaoeECGR8DeqPYrF+3wc 3J8E3ukjRs5W7vdgTu07a9kcafgZdcdB9A== X-Received: by 2002:ac2:5297:: with SMTP id q23mr3059761lfm.192.1640094846211; Tue, 21 Dec 2021 05:54:06 -0800 (PST) Received: from localhost.localdomain ([196.244.192.13]) by smtp.gmail.com with ESMTPSA id x17sm2705305lji.96.2021.12.21.05.54.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 05:54:05 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 14:53:27 +0100 Message-Id: <20211221135337.1348-3-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211221135337.1348-1-dcnieho@gmail.com> References: <20211221135337.1348-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 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: HxwyPymevujf 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 13:53: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: 32793 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5444354iog; Tue, 21 Dec 2021 05:54:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJzUSjE2dD/JT21pOvLNIOhjcW+kMSlClw/Gmapk+MwgwrCIUWEX4ogjoZ6B2K+GExQ73a4T X-Received: by 2002:a05:6402:2793:: with SMTP id b19mr3269947ede.395.1640094882820; Tue, 21 Dec 2021 05:54:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640094882; cv=none; d=google.com; s=arc-20160816; b=VKkiJ3ldXh4O8RsEtAukU2pxVeqt8NeoGV1jSki+Cdr2iRzEIAR2j1vqw7PRh9lR3+ ZeoXaXfhtdHjIURIZ8ajD63VKIcE4kR4ZoBEFm+swny3ZrBo4CNSmjvIH73f+HHuxJ/4 GVsouFXoymgSwDfVFFbkFSFALkEZrzqEtslzzBShmAP1trHq8H25Dmr5yvVrr9p2UMLV dCNVYgEAfVjR2NzSGs8MrhkqTD9L8+waBW1WJ1geBs2abB2vfTRB5THV8TXRFKU1FbKu Mea39Pax49MTQ6TteZbgKJvf+P3v4ZFeA+E0z86+xqLb13iESaRONXo5iN0zjZJy+2xU iygQ== 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=CsyJmInIIqrJ4/bdutTZYqjA+qNMkcKjh/c0+QFZiQBOq7xpB+jLuGSZxeyUsZ+tR7 iuK7946XqQPe6qRozssZ+v/TohIlG5Z/IHnH1JKiJ6NQOipSifAMmbYHEY/B6+twSkDF gUyKRbsrma8cVvjeUZsdl8q51twFirwMDBN7M4n04KnYO3rLTqokcg5cA/0o8j4oVUxP 2VVOFn0CCcIXZQOrMcfTgstXtugueoidLrDnbAU5/J7+7/pkNjiDmw3Y1cFs9hEj8vks zWZm98Hgqx69ISjsoK7yHW+s5bEzYPZBfLtfUDnJ5HZ48bU3Hcjs+vN8nLs9yMRj+MUd KWSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=eGIyLzME; 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 du16si3653084ejc.647.2021.12.21.05.54.42; Tue, 21 Dec 2021 05:54:42 -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=eGIyLzME; 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 57C2C68AFCF; Tue, 21 Dec 2021 15:54:15 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 39C6D68AC7B for ; Tue, 21 Dec 2021 15:54:13 +0200 (EET) Received: by mail-lj1-f169.google.com with SMTP id bn20so21530990ljb.8 for ; Tue, 21 Dec 2021 05:54: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=tLBGkU73btm2UY8VXqRWlX4bo6pvicPCF5lFX+SbDcM=; b=eGIyLzMEgBWKn+rCeLfzE8Qbh/7CYBGEgX5pJzh+tpeJuFXl52rTE3FMlAiiBmYGVU 07ezbYVQ4enpkdwboPjjfKHG8OWACR9JI/4XGB6CYF99W39gHb9lXZBjnFsICTUzrmHz 7tOzUoakurcxFT1cwNCZkzoOqPDYhLo/K5wif0OEp5Ufb+KcPnbhyfjOBxb4/q7p42ne z88hqqwCHEYTT7PJnx9I4GY/FUrWTVq9bBEynJf72NAl/Nd2NVx0tEm2YUIN3yGjGoMl ez0rYFRpUlmBGyHNBwV1aPxUpV610wdOqvO5H6zeYZZ9E+HtS0B72Ws1NTnS1+zXC3JE 6EmQ== 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=2zGH5naeKzQWHrbLsUWRwrpdzK5sXZi2JkezcTdlTX2RvDyC0xZOOw9DZn6mFDvWik hsE25P8vK+uwQGQ/Z14Sx9k1TuyB0lajvuavm92MSySDA9+xV+F91hRtzHQ0qH9jtPoR sh4iNJ5BoKACMlSpzEKOfJ6cNUPrtD8VwoFAycmohf4mAiHbHMgPvatHXnLwB6J+MSCD Ly3kh73JDvWIwaXI7mI7nLyOocbOvHWKgfMwwbC9YRq97mpDLRAns0wVVwTEk3+aN7hZ cTt8uu2ljQ//bby2YSJKPoaTkbyHhBnMpZt86C0XT0i4/Kz4EJea8bUeK3mk2So/5h9F HNPA== X-Gm-Message-State: AOAM532QnOZGLRBDNWduqydCgBNYwJznBj4eeLuOYYmZbxNhPSOa0DL1 Ftgev26RIQZ5DDfwkgYbCkhH6WiFho2nAw== X-Received: by 2002:a2e:a311:: with SMTP id l17mr2537756lje.9.1640094852998; Tue, 21 Dec 2021 05:54:12 -0800 (PST) Received: from localhost.localdomain ([196.244.192.13]) by smtp.gmail.com with ESMTPSA id r3sm101768ljd.4.2021.12.21.05.54.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 05:54:12 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 14:53:28 +0100 Message-Id: <20211221135337.1348-4-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211221135337.1348-1-dcnieho@gmail.com> References: <20211221135337.1348-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 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: A/v+CvTW0Vcx 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 13:53: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: 32794 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5444484iog; Tue, 21 Dec 2021 05:54:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJwmtBjUY2e4TWLtxrICKbc+zNrja4dPtZbMLUN+Ln2Tzix5OnJATGy+0b1M1G/aN0bqsuO1 X-Received: by 2002:a17:906:eb56:: with SMTP id mc22mr2766346ejb.331.1640094893574; Tue, 21 Dec 2021 05:54:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640094893; cv=none; d=google.com; s=arc-20160816; b=a0WJOwmMuDjXNF5xvRuKNSR7UfsMLBjQ/Gp2fqdT/TA90pDlIKZnx8kx6W+i1zJyn7 yttUUgkez61LehxCcqQeXehGDo6hOtzIBKYKnNsYmF9b3r1nfZceUk2NkTvz60BJ2KOx w1GzbUiJArE9e+0+QtHCbNKgl9AucJUz5SGnbDXQfrP+vxNYt8IiLmepv/eH5+3B1GQq smVqttaAz840hUG2lDQH+eHir27gzeQFaK9o5o3MoZCuI3oAi/MYRKqLQy9jFCiZRnBa 3oCiJ+seZDOpG2l5Zc7keNE+Lo/YKjpFwZH71HishefAHIcqECUlPuPoQNsTuUkySSLv HL4A== 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=TpTYjuJMd6zajpCl7AN5vBRwf6wEk9CmufHTAb5JS7rBy6Ib8TjQWkHwUqN5+sj/BC oChOpof83LzYwFj9tR2Gx3zEI1hKsHz+rabcoJZTiy6qEKKTNn2B4q30CSg6PGLBFYat CV7q7CW2FdO1ClCNbRKt4pqFwrKt9ZOe/5/1/9dyWDSA9zlfE6cHll9hvwC/Empwf3ag tE+iKy6WGWi///rQUxbGfCUs2tJT4N1BzboYIG7fH1XKVktddPIPE86Q2BLdmcxb5ddy 9QwdeZBsVplHSDc3HXtPlFtOxPh9Qyg/2oPhjlp/tfPoFLapVhccDmgkbkuMJWhHaJMm DHLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=a9B+k5wA; 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 h14si14886197edl.521.2021.12.21.05.54.53; Tue, 21 Dec 2021 05:54:53 -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=a9B+k5wA; 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 609CC68AFD9; Tue, 21 Dec 2021 15:54:22 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E904268A921 for ; Tue, 21 Dec 2021 15:54:20 +0200 (EET) Received: by mail-lf1-f52.google.com with SMTP id g26so13694006lfv.11 for ; Tue, 21 Dec 2021 05:54:20 -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=a9B+k5wA2g/lpbne0BrOP7Afsw9DxU9wMagcLoEtKA7HlB0Jq6tfKi9vZc6IeXAtJw 3f2RHiOm9ANLvUMopX9kpgo9Jiuuf+5P4sdDo9ITV63rNBFXy5XR3WmzdhgRRth5qF4C z9GGrBkWxG/SsmxDppTBaWksF8Y6HewA7dv3MevkpDbIXsbbdzOvW9HDbcpsCBez67bv 0aRwFGAteygnQRNlxd2mkP1ficbxMWRINJZxPv81mhB+BaSkIX8BpGxj4IR5GRYXsKKi F/xEuvj7kfcEwsWk3FJeHxYJuTpvayroHUT1awRCDQQ9nYGKCzpwskOyoDCQNfzw8RvE ro9Q== 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=nwacyptFktoxcwgvU4W8ULsUZxO+t6P9rwsFLFku65cmG8CLvhIyIAHJVDyl1z/lnL mWkRKWvM7hX7aibmvGOeDWNI8H81gLdxEKAnJVVrVl/fMT7NxTUmkLFF1UyWdnLWnyk1 txBThr/rQEi6/siRp6u+yNCYLUCGwvWAcKh9zTUOOgCYfAXW5xVj+fcK035yfPH0ZyYx 44p2ple1egV8b3ntqcZFUWrUzAgs+AnKSY1gq0AU611E8BRd8CQch6eo4/m8u2mnbaeT r2X19RiEnjPO1Oyl7ZZTWKU3qrEYTZu5r3pA5ZeqFb022CqPnw4UXePpUN1uyCCmPDcn 7Sdw== X-Gm-Message-State: AOAM531NlwTPclo65H1htzKgloynb3qhnIn2wkbtxdf4TbZaO/1t4sBh 90d48PLwJU7XkuRB9ExXAkFxwmAT0hrzXg== X-Received: by 2002:a05:6512:39ca:: with SMTP id k10mr1955847lfu.496.1640094859751; Tue, 21 Dec 2021 05:54:19 -0800 (PST) Received: from localhost.localdomain ([196.244.192.13]) by smtp.gmail.com with ESMTPSA id u23sm2750910lji.56.2021.12.21.05.54.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 05:54:19 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 14:53:29 +0100 Message-Id: <20211221135337.1348-5-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211221135337.1348-1-dcnieho@gmail.com> References: <20211221135337.1348-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 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: COZsM0tUPTDR 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 13:53: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: 32795 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5444597iog; Tue, 21 Dec 2021 05:55:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJxOQEOZy7ZWk67g9zT12cbwkRpBLgvRvrqMGNmmf91lITBmGtSWHgB/Vf2kj6yb7G4tmz+6 X-Received: by 2002:a17:906:a20e:: with SMTP id r14mr2732277ejy.376.1640094904630; Tue, 21 Dec 2021 05:55:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640094904; cv=none; d=google.com; s=arc-20160816; b=FcPLwFlnv0fmT63c9NJSDV/OHNn92PBWLJFGCLLleffKPjFvJohUgxKy51BPanUlyQ vX8IBdOPuDjpyyyVitqCzlA3CpP4DT77DbCawbbQEVh1ELsf51JPnbp7qS4J8O7y2aWv bv5XDK5bONKKprtQnaY+45BuPzaezI24ADnrvsXz1mC0+NkofUmf4vRYIiOEUBdeZyRn +TO6rVlivW/XONNWqf8pAvZ0A3xE6ihLIkEQOmDb49JutKZl9Eydcg5cDg67793JD57d GuK4NqIJFLfkQNq53IgfT0dT3S09ik10jCgoH4cB/sTy7EXW2w8GK7XOTCUhOor4NBOM CGjw== 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=PlBsWv/8bEoy7gyGsLYBZZ3i2bvzGsbHtwpPlXPna+iA0YFHWizJKYJODJnDif2z+y LDJI7lgDIGR8RGVIOzdeOUsUbOpBAGPRhCagxrJo397PTSDOfVzRrL+dG/4biOdDpGaf JNh7EJeXnw/BF/icTyTBBzU9PHZae30uSATrzQ0DfFImNJPYIcSIZmlAknbOcaUiduK1 aXcWldf41FS54d6mLI2XzB5hNU+ot73JCazwXrDH7WcXa5dmZDJmc8PlPsF1CmtnQy71 k8gIK0cPENKTjGX6W45zhqP5aAe4UjrcyYr5TMYzm2dFGKBuhT7iaEiKPy7iznTRxlQ8 mAVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=h9qM8q+y; 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 zh8si1866774ejb.902.2021.12.21.05.55.04; Tue, 21 Dec 2021 05:55:04 -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=h9qM8q+y; 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 83FD468AFD2; Tue, 21 Dec 2021 15:54:34 +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 CD22168AA83 for ; Tue, 21 Dec 2021 15:54:27 +0200 (EET) Received: by mail-lf1-f41.google.com with SMTP id bt1so29424621lfb.13 for ; Tue, 21 Dec 2021 05:54: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=h9qM8q+y1COkSGw8fkC5PXVQHHe+9VD3GWej7Puwsjzm3/W/qHX0QwjMNcbi7bemGC MghR9of0OXSvfX41M0jScqX+S8OM/KcLH7I2fIXzH1CBlofu+19RgkdWYmolCOGzQKXt ix1D3uccNtZuon5GZXW76vtfUw6Is5W9lGaMc4vR/ZFB2mPLUZc263URzRJ0iIEh7iXF F5SsayApG+uYRRejmm7O3iEhVY0K4no1rv4kDwD/KOxWlmoC6bRMJplWZFarQNFpbYqS KQvICJ0zcQ/6dPoTaNAg9cCu38/igklkLZWdYQfsMnxuCZwRF83v8HEGckrGrkkQiz5z zFyg== 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=3ZK+bqecpblEBlWT/zYh51s4+HKEhc9qq7wA1Cgq3+5P0ywEb8yzvLZHJhoDYe0cAU FkMZ/r7q7s7sTXcZoIll5mykifoFi1euwjqjyh1RI9xqIG97ci+56RR/6aJRh2f1ebaq ky/QPm83mJLH4E0OCbXMjFb4klEs75PDKgidyn4SMKlNXe1Q97Juv06Pge//Dmw1yqV6 Wu1eHhCtYftrfSQN4Z5DD1GC9dYlJVTap9Zo97vbtEmcJobEC4GXKZHG4jjo6jYRvmoH su8S/G0Rc1fn4x4Nlk3SO0ltMW503hrRmP5ojD6i60i9kzDEse5fHgHLLjk3FF0vJpg5 r+iA== X-Gm-Message-State: AOAM532StEo8ITUqHFBLEnySshjpt2IIXa5e4JqEbrqTVakG7Qm90ODg Lwxwxs85+2jB2YFjlEEhFmNQxgZ4J+MOcw== X-Received: by 2002:ac2:5547:: with SMTP id l7mr3103873lfk.324.1640094866752; Tue, 21 Dec 2021 05:54:26 -0800 (PST) Received: from localhost.localdomain ([196.244.192.13]) by smtp.gmail.com with ESMTPSA id k3sm2741285ljn.55.2021.12.21.05.54.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 05:54:26 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 14:53:30 +0100 Message-Id: <20211221135337.1348-6-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211221135337.1348-1-dcnieho@gmail.com> References: <20211221135337.1348-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 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: z/0eHGz1f13/ 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 13:53: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: 32796 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5444730iog; Tue, 21 Dec 2021 05:55:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJxD7SM228dBowgkfVgoUfh3ExX0kdJetKITsyUC+diuTkEssNrEvxTtjMyQnNAeyzYpMNBD X-Received: by 2002:a17:907:7b9e:: with SMTP id ne30mr2869663ejc.24.1640094915094; Tue, 21 Dec 2021 05:55:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640094915; cv=none; d=google.com; s=arc-20160816; b=t3CdUdWV0H19T1IJZ5sX8FgXRj4gv4gYiEZJojP/8l+VivPIfNssRycgKvB10/HlU/ l8lXBe9DZq4QcNnxhj2yoJ59CD6XBvyNkuWAbnRhy0HgWWHywnbUc8sUNxyK7ktDQFf7 7clSbijE1q+0p5A7a7eF6fyTe+4dbLPZXV7dRR2xxhMr2qTlLFz/EgEsN+Xn0Ai/KlR7 qfN61HIKYgmqukDHECUPU48Y2iimoeVxyOEHOLkqDfEneaVRnxkATuobFc5XwA+F3TS2 gFdvwFxsbAjRiCjZBvXt6EtzqWvTAgtHNR9xa4wfS5eVI6NubA8BfPn8K6Q4DwEF6QVW thdA== 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=ROWVTtgqL6f8eW6i80Mb+pSJms4dTm0L0E2cqP4wDWHxb9gCdNUZ20vE7ep/52LP27 nKbxvo4pcY14FSOGWrh8sYY8YmYNY47aMc0/nrVPfa18Tqg7eRstankESYifj9bYm8E3 gLNLNRItiLWkk+DJspNMxJJhqMDcuIv1SfbMGTchOQ8DKfDYZpBAc+LzUpJCY4rvvfoL HXNQnZfj8qV+bxxxSGgnf5DYnh3kdJlme0/qbkowLRWjda2cetOjgN55wtFkASLRpN4P KAJAXnQ8q+UVb2d2PmGbOrTOIFPDV30gCvubgwKUAeBMY/6i4/78nFd1Qq1lwWuOJRql b9mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=HJr4dSk4; 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 mq7si9734080ejc.19.2021.12.21.05.55.14; Tue, 21 Dec 2021 05:55: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=HJr4dSk4; 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 A275768ADCE; Tue, 21 Dec 2021 15:54:36 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DA23368AFDE for ; Tue, 21 Dec 2021 15:54:34 +0200 (EET) Received: by mail-lj1-f181.google.com with SMTP id m12so21532519ljj.6 for ; Tue, 21 Dec 2021 05:54: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=HJr4dSk4nVkrVOkOsJtQg6KasaX39pmvXChnPv31fDcRC9E+Z6oaFHt2PcgGmB2SiA 5VuqDIETLhuHFHu3v7nRXZMjmfRirX08CgAF0X/ED71Y0ZJubHA7ZAmbzxcQuwLEwLL0 F6i8yffxTGsVT3uKm5wU/hv+oHqTU4cp2lKCm4natCStARL15wu0M+UtSUW7xoVe6si6 HQkU9VuJ/owWOJYsnMmuhXYjcBagsosODWKpO5cJu20+JXx7uIE6ohEft+R840+lEtAH Lnd/qFe3SScSVS7kICmXhmDxs7ayq6VuNhm1ytLEKBuNQ9RNPSMmkRPxrzezRUGsDTaK r0CA== 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=Pxb2R+frkQfbT99beBOV7sbPh7Ic3825qzT+1WEPTsxZkGOGm6kCgNOmo/QBGHfjOa GSoLcauvHJaxupLvckQ4RHoqZY75mBkHAOqbaS2q6ylgnetVG/jZSzoXs+GTOzO9zqeV GfIEjZlTB1m05Qmk49q5Fp3AMKpkIK/PboiJ8WpmCi9+6NVMF/F6gbHn8/uaFxCngwUA mHEvgvoy4CqFaH42WMNvSqUili8+/0vvsFPl4maKJMm/cLDf27kiZo0qBBjFTLzNGnhA KV/Z6StZNDOSP73a2+1LILjSwt+6B7Px9+PlIXiHxN0ahzJ/XVwfTL5Dsav5z9HDPLxd 3KBA== X-Gm-Message-State: AOAM530XqKiKjmPaisrNcbbhXP8XLTYxOHHkSZCcW1oMIyW+fL/Geb1Z PL8z5zFf4Cd4GFDuqKTPO7mT5HJTfGnIPA== X-Received: by 2002:a2e:9b03:: with SMTP id u3mr1258989lji.490.1640094873688; Tue, 21 Dec 2021 05:54:33 -0800 (PST) Received: from localhost.localdomain ([196.244.192.13]) by smtp.gmail.com with ESMTPSA id m19sm943098lfu.267.2021.12.21.05.54.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 05:54:33 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 14:53:31 +0100 Message-Id: <20211221135337.1348-7-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211221135337.1348-1-dcnieho@gmail.com> References: <20211221135337.1348-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 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: Nr3xg4r5MhRv 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 13:53: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: 32797 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5444900iog; Tue, 21 Dec 2021 05:55:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJzndvgKtaKIAN4yXIg8fZjVdjytsBneOvTTvN3yZI1kjNIGf4gTAUc1BGqYoSlsMuBU/yIm X-Received: by 2002:a17:906:6d0f:: with SMTP id m15mr2653778ejr.619.1640094927193; Tue, 21 Dec 2021 05:55:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640094927; cv=none; d=google.com; s=arc-20160816; b=T+BfTzDk4Pm9ZFfmo+dqLIJcG7F+Vmxh1owBozISNvv8Hnf+I1Woc0yTxAbQEf3MKY BdnPE0Hku3HS5bjUbZIzvUlOZzv540AkLxdcOe3cRmpWVa77aoguhdFprAk/hTEHLfVj hBS4E02EiiVhaEjDS4oip6VsZqCHoEvcAl5HfAAg+3EnSBY1ibbFhIm2YQSMx+5ionrG UAwCVqEGciV5CSlnm/aSXyEQdr+xYfIUW+PK44hzv2iXa4DZ3qDKP1PiHAd+d/lG9K8w Q9UxD6hewHYTiJcl/69jWaImZnrrtUPSwPAdwaqJxb24/ykWyTniUI595AuHhl9jFlFE NU0A== 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=QCcKFxtCHuY0a2EtZhoy9LYpCkn2CVyhxGg9eGZAdEnCwzkYXNJEV8PAwE1WNJvBqZ AFB6Z1ORFdTOmn5UrHmFxiAf1GVedEozGXJTM9oU7M6rwsEPlHYDpeW/sqAuma85ul0Y dhJ3ciR8ffplYygytLm81kYsrP/11tH0G/yQVXofnH47CcpT5V4m+B8sL1WNHOJgFMMS NmYZWaA/4aOFlB+L/EoDSHKDCwCHg4C/8UKmqag8uhKKGXNRgSA6ViLJ5CGPLa53YIuc ZDK4q4o18NtBg//TyciRCXZILIpIKQkMgsqhN6l2I2HxihotZyeCxvzxAgmS8CtHNnlZ THTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=F+dXnAe9; 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 hp38si8049570ejc.170.2021.12.21.05.55.26; Tue, 21 Dec 2021 05:55:27 -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=F+dXnAe9; 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 98ABE68AFEF; Tue, 21 Dec 2021 15:54:42 +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 505DC68AF52 for ; Tue, 21 Dec 2021 15:54:41 +0200 (EET) Received: by mail-lf1-f41.google.com with SMTP id bu9so7968913lfb.7 for ; Tue, 21 Dec 2021 05:54:41 -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=F+dXnAe919IznYXuwlMyxjSrpHe3u6UlMP+g3kh70xeF8WKd5rtBgdrPTJV/hEWpD1 TkovTDBTQSCke44K5v/+QPbFcuLxpFgYoeXEbjVQVjXqOj5epAv5MV0ee4LNqLXwccIy 0F7INDPGRBTtknKnkukvA6j2aRecdFoXvqBnYgkj7eKXMZ+DbrEPg4EWjfRDrtKYE9jt WUjzEIAav7KZ69QjYmt6vY2m+xVSitQvUkvsfG0sMh0XTssa3kDSHhiHMqpm6/2eWtg2 WqCxyh26fWuOkDDoJ2nx4qdBlVKM1blqIqRO+ytkYRbtlX9Qi/l1VL4+Z/daCrSR8PhV E/Hg== 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=jT9pjSm4HTMO9Yu3RhnoGHKt84mCcuTrnqGdIJnmIzqiSwz3KODr0vCUTz05ZnVt7n aWdtzzz6oB79atkXIMpJsuNyOZtukziClMymsUweO+OCer/RHf5M+sW/uDIaGf6+jm0W 4GSj30MucXFkNKkbRuLKtRu0Ro6Txw3Cg/zBSyNC5zN2ioWg4DhxqaMrfUtYF6X6OL3p j/x1TV/071IuXvshJ/b8OEdG2lNQx93J1Wtny7bVk72Om5FDzLguLNbxK+X4fIfSzccx VzC0PfpwEH7fHIzLW7Q53LRYq2wzt5N2ek2xoKUBiNGboBfDgQ6WLOzjrmFJCfYKMioj 5hZQ== X-Gm-Message-State: AOAM530OAiRDcIXpm/Q4jmv1kzDZs+YtdEpUsEhC1MsOf3HBAQ4XtfhP caKsTTioVO2QvhEfiGf7Xp2GJsYa4tTpIA== X-Received: by 2002:a05:6512:5c2:: with SMTP id o2mr3138541lfo.8.1640094880389; Tue, 21 Dec 2021 05:54:40 -0800 (PST) Received: from localhost.localdomain ([196.244.192.13]) by smtp.gmail.com with ESMTPSA id e12sm990656lfr.179.2021.12.21.05.54.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 05:54:40 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 14:53:32 +0100 Message-Id: <20211221135337.1348-8-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211221135337.1348-1-dcnieho@gmail.com> References: <20211221135337.1348-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 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: 8psufG+Yr6jE 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 13:53: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: 32798 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5445054iog; Tue, 21 Dec 2021 05:55:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJw84dUMwjW9U6SLHI7GYclFAMQKCdmn/8z68bVebmq5aSrwEJXn43Lc2fIwPo7d2+cLHBCp X-Received: by 2002:a17:906:c156:: with SMTP id dp22mr2674689ejc.283.1640094938857; Tue, 21 Dec 2021 05:55:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640094938; cv=none; d=google.com; s=arc-20160816; b=j7NQJJ5t5WVz/pZ85jQ3MyEitz8WI8RramOgH2hVSOxKKHy+vc7EsX9RfGMnnbuAVk WsOxEwnCWQpwTA4xiHkpcEqQ4CLwTp/2b20DhWbg8OSgMDV1fQQjk0JWeL8q/IJz0bg8 IWtm/6vgdG9VmgMkMyshdod5gySjqKp66an4W56NtPQHGZkeDtghQEqgIq0k5RHOlA02 8OB23ARS6iqRs/EulBeQ5JVP4z9ZwM8omJ/gdVvT1qy/+v42csxWZ4ZpkG0PVW0+9pDP 2OZm6dq6hCVJpO/pQ1yU7q0IKYoSGTnqd+ZBMD9sJ/K2FvfX8xJ+6/+8Cf0ajpKjJKd0 FPGg== 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=xzs5+INhCjcpzsm1md31iQ0e1HMS8ZEBGn9Y8QyLNNyW703m5cdoJ/iipeomtaHoZA cx6xOMH32t04hkfBps6+D7zQFkbKPiYaO9+I1V5DWU8yCw3VjR1NYIOaNsw7jZsU0k7M 76yYZeuxKJmN2FxJ78zAMxwg1KU5qIcpKHcRyQuTnKGJppbMe6E1JMjrITQgL4odx2Gw HzPQZSEd00VzPVk/ag1DZv7LUbjplMlol6OPpUajv5+3CMLmVjoQmGyzEtKI0elogviI C7rYK9M2o5oYC2JTIxojbBxHFxUDmlqrpldQ1aH4KJ0e9qB3rQdf3HlUjtU+KKgH+aGh 1C/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=mmaB4jEw; 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 hz5si11273805ejc.124.2021.12.21.05.55.38; Tue, 21 Dec 2021 05:55: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=mmaB4jEw; 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 8D8B568AFFB; Tue, 21 Dec 2021 15:54:55 +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 5C6F468A897 for ; Tue, 21 Dec 2021 15:54:49 +0200 (EET) Received: by mail-lf1-f41.google.com with SMTP id bp20so13852466lfb.6 for ; Tue, 21 Dec 2021 05:54:49 -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=mmaB4jEwHt3AyXAea56u7AEu/1EbmH1oPcYJeCfoVsMbsJia6COFU6BKdaKuPQXNhK pNlg0daQfTtDyt0BpcFIXjzjBehxrzX4W0tHoc3Dax5OWGRsR9TAcxVwo5Gc35vmoNbl rW1eFtktfUSQeAcIPPIsYv8M35WjoKMMoOR91FACUEgBquVxm/aCzAyBoU+IACVLVADH YiIu79dIOMto9uDCCNbAjcnZU84DzHrZkAXNRIfXoP49D7esvYCEgZUMl4V1ZAz9Yc05 Pa3yhkLClgQyZcTGm7lBzCsj4yVLGV8ilHH/18CZTCMhzt9VhcztEEH47EG0WetCMh56 njrw== 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=umrXBtnDUGm0xLh2/qHJbEIxFzHVrVGn7Z3kSHUnC9GgQ5MOvLgsIkmMr0t0oU637j PlT16Pg9oyt6GrYfnuK71iQQhcjUkoKkKFmjicPc1XPIk2Seha27WbrG1JxqmYO9q91r k43DNGZfuRmlhN5JFfyPb/BDW3ivpmGPh/y9sglwPWL2uyrnDUwyhoIFxfm6Kn0qNGA/ fIoZ9ibiAUAt0fZ3xvMkXZZ0E15xo1q388pei9NigwWk1ywIALWdjtgjreZAtUFznzgN nDrGQieVUYKmh/osXhQVREGfcX06hzfPomNwh6wd6+xTpof4XOLabWDalpRxTdpXNHjt 3CcA== X-Gm-Message-State: AOAM530KDD22JPfmilBvN90jy0JH/fuzPDfbs7HnHa1OC6igU/9StC1C Va+ja+34BXbX9ovtSz2gjZmfPZpBr6fqiA== X-Received: by 2002:ac2:5b43:: with SMTP id i3mr3086460lfp.647.1640094888554; Tue, 21 Dec 2021 05:54:48 -0800 (PST) Received: from localhost.localdomain ([196.244.192.13]) by smtp.gmail.com with ESMTPSA id m3sm2735958lji.112.2021.12.21.05.54.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 05:54:48 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 14:53:33 +0100 Message-Id: <20211221135337.1348-9-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211221135337.1348-1-dcnieho@gmail.com> References: <20211221135337.1348-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 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: ahDuN1MsEwLU 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 13:53: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: 32799 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5445212iog; Tue, 21 Dec 2021 05:55:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJxdTByM0UX8gwqanWgQJHjzAGt/lJsr+W6o/hjSrqW53gKstzCyTdZdwBF1EA/DKFmFdk4U X-Received: by 2002:a05:6402:50cf:: with SMTP id h15mr3346395edb.177.1640094950240; Tue, 21 Dec 2021 05:55:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640094950; cv=none; d=google.com; s=arc-20160816; b=KwU1ghNQ4uIBxubxp2WmvwRLgvCQk1ub5i9OSM5bvIRf0yxTWhcd7wdzQO5CjkTGSS NemPORVgKVHp3EgrlZqrVLHyAHOZtS/zeAkXWUb1iWNPqIZ3S+RCe0NNhBNXKUYfGohX qQfmQvQ5ZwF+Tw1V+OELLHSXsPeN/LN6Xosmuyuhw/pKBhWCQvB2ui03D1RMRFwO8I7m 76E2uzb1mt2wxwgxZn1v7hbXCuKCXqYiQPp6C9eVVC4yRpFbyJp5sg2bCWKq2oE7cc+P Q8Lzg4s93BPz/VHUFE7cy6xthTG/verSeAkYNdX1u+vz9Jd1nE3HtIkJw3z+5R6hNXUD bZhg== 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=kwAtIS3zrm0IBetH4+XPlxlH4Qv2s2S7Xoh9CnXQ5mI5t2r7Yv9z7y20tKYyTCfU4P KewXxpUsFZ3c7U/l4xLIEwC/NO9LEn5nqxZAHPYuxap8D8wee0C4y5myx7ZrLfRyDgO9 B66BOXSdq3Gytxztf8N3rK8INW+KdE1SfVHgTOVzPUE2J4h/XeL/z2el/HQsjmdVylEc QGS+fVTegmDtslnqrZFi2EpwS6UNsMMUDLZ1TvKSTMTh0f/za8OM+8daDzxesSvWx4aL wCQkW1OpsOmcY1I7VJ4g/G92HGvXCzuUsga5NpOPT87jWvfij21ZRI7wR5Ollu9Cltkd ZQ3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=KyOANBO6; 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 cf30si2550210edb.85.2021.12.21.05.55.49; Tue, 21 Dec 2021 05:55: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=KyOANBO6; 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 84FE768B004; Tue, 21 Dec 2021 15:54:58 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id ECD6968A897 for ; Tue, 21 Dec 2021 15:54:57 +0200 (EET) Received: by mail-lj1-f175.google.com with SMTP id i63so21511812lji.3 for ; Tue, 21 Dec 2021 05:54:57 -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=KyOANBO6voKZm0dLwpMrJxwpYST0ZAKAKh6aEqnjWBwy6jox4RMQ5linfr3uyssGyJ qBmyi+3Ne/ockcKojenV+fQHLg2qcpCLCm+sFjeybm41ir9LLSnXg3TeU97iiQi2AmzM OAEZwGXjlnrB4vUspy68rY7CGopC40Pvq9814356/rUffMhiSFOsxKFQ+n38s9NtdTGl 2VLGxmt099WnzGoeCgJD3QJBJoUkzjAj8Em7OGb5wJU3kz1un1A8LEqolFubUTpaSExJ 1LYLkTPsRRkeTHNpJW+kNbDoc3arktpz122r11FPP4xjviyTZdDXGbMaUhpAi7OJSEO3 rEdw== 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=x9JhH8MVdpMZmemHcMLnefTe81RABCDWgJbfWfTpuyIur76FDth9RM1Em9GIMKf8QH 9+jRnw0InkQEeIoA0waUEjWqelZO2joGpGbdcr5BuAtq+fTIVovjXj3B/ZoB/c7YQP81 tlKxlUvKDHDlbAkoUtoL10ZDOKf6PCp+97tGpBWA8Fk+DSvj8LpLk0zBpwKO5tPD5B0l vvjRHCrPzZDXLsEeud6T1czXDbujQ/SZN/RSkFfIzRMkw/ESSFueAGL1UuJ2G0d8c8TH GscRBLxvxwHxqNrdecLq3X28DMK2M9YcDiX+uy6GMeUPZabLpKzXblOJcVxXyZZc2J5h usaw== X-Gm-Message-State: AOAM530MvW918ikrpqTgocyq/BcJoVcrJw5eYSQkzQynpFO8uRbTAHK/ BvhLze/FdchOiBspez3KjFZcv06GlgThxw== X-Received: by 2002:a2e:3012:: with SMTP id w18mr2573554ljw.217.1640094896820; Tue, 21 Dec 2021 05:54:56 -0800 (PST) Received: from localhost.localdomain ([196.244.192.13]) by smtp.gmail.com with ESMTPSA id l4sm2627085ljg.60.2021.12.21.05.54.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 05:54:56 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 14:53:34 +0100 Message-Id: <20211221135337.1348-10-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211221135337.1348-1-dcnieho@gmail.com> References: <20211221135337.1348-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 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: mX7h/07mxJMB 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 13:53: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: 32800 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5445394iog; Tue, 21 Dec 2021 05:56:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJyb3NrrZhMBdrasWFtttksPvU4T8ns7qL2FxU7gEAff2i6A+5BiyXXaa8mNEiUpDVpOfcHF X-Received: by 2002:a17:907:98d2:: with SMTP id kd18mr2744819ejc.252.1640094962882; Tue, 21 Dec 2021 05:56:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640094962; cv=none; d=google.com; s=arc-20160816; b=E5ZH/0nll/4WJK/dmqL5Pnsp+v932DH8if2YAaX8szSyBif3Ck1FeaBmJndm+GkGHI X0u37EP7DW9YxVYWgJvN2Ra+h/q4RPsDuMMT33gjl9oD2ZlcrTqae7Om/SKnpR9Edr98 Gliah0hDhQP1mxSi8aY7ElMjRhB0iv95mqUbFEEXIAqrWWQXY7aMmmTuVMPENV0XxLxc avjkyzLS2It/+Djug4prALCLGo9DfI3r8oPokh5bk6vcBQ3H9J1iYwA9NAhvh4GYC8X7 bf9P1l0RCWoeKneoLkM7Q3Wl13abXZM+pGYImrjxnBG0JDBAhqsnGE7MO9FSD79PK0KG nj+g== 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=cO5YfPwP5ypudypnUxh2xYo+rk8ww6DeKlK1Lk5E6To=; b=pav7dTYCVQWqHyxIXRlSeN+MkKV+jCIykrYMCa6cxADxe42vAZ8nI7pYjXbEYhzlM6 L8jEzqF+0gxZj0fkqWV+Wxvq2xAgyCXBjPk9wkG15x49bKMB30xRDWAiD1ddFoTGGb7v 2RgL8FYOo3UVTukynEOaF7F7n+9Z6G1/KOmaFGwJuOuEPwwr7qRMVBFhsYXlTBLjkIX0 1leXIC5akrvZti/FLdnuRDDTVLMXeeO0LxwabfVqHfgUgDI6MDNe7JHRSAlkTHVkC1HK 9MlXq8OrXF+sTvfUGiAnHY8bAUtT0k0YRcQElycetBcGvknHrJbDJgKw40XlXKuqGTwM cPtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=fpAX8Ju8; 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 qk10si112865ejc.455.2021.12.21.05.56.01; Tue, 21 Dec 2021 05:56:02 -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=fpAX8Ju8; 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 94AD668B002; Tue, 21 Dec 2021 15:55:05 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A5628680090 for ; Tue, 21 Dec 2021 15:55:04 +0200 (EET) Received: by mail-lf1-f44.google.com with SMTP id bp20so13854001lfb.6 for ; Tue, 21 Dec 2021 05:55:04 -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=5H6BZ4r9sxJwO8GSbhViSzjChcWwiXvNcCDy8UFdP94=; b=fpAX8Ju8cpEMjc3TpVWqZ3TA8F2hvH/DLBf80dlgtHG5gTeUe8yiYV9U/d4vAIhtI9 odayYhUPZL/o55y80NlL5xiH3n8uO6fcPGQP/UlAiDaBRiluRaGNV8VAGIyiJNrMwBK1 haXSO9S5IuK4x2puTptzdYakcMNlJzGZIzfk7YfMrr/6uqjMIq1OzenvgTgtf4iBcD4i NV7zh7BbFrJEcSgl7iNqOKNEplTFS2YX+EJU3yh35TwaSPY0FecT6breqlk0hTepK+IQ C8+YN9WXGKa/89d+HXdmoZEvSpigK5eZhjg5iAxxSpSoGtTXcQN1rR3wjyz25Frvez5o PciA== 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=5H6BZ4r9sxJwO8GSbhViSzjChcWwiXvNcCDy8UFdP94=; b=OjRGsU7QA6DCIShh7tV70bx5uDZr77L9bLHd8VBZu98uzOzgxxAg/RH8klttkvkjMc 8LgFvuEbF1awSXlE5AH+F/KFCrLKKoBtLsb93CVOu446++vbPaFYcaU46mbnKmi5k4Ya WacmWBY+dSEr5CSGv5dnXJZZmM4goj2xNVDN5nt5LdfgFCeOXjz6IM86qZeLQ/++pTUq ZKrCByGRsPB+V2LjojXQ6Npyj4y01t+t3e5Lwlb7z75a5bG4cR0sQQ/Xi/Xr0b6SpWoD UAOhqrQt20EPBOBR/7KatfNmmr91pJPxr3H1za1dyeN67ykg+EbJg2+HgR4qBrFTaoED /UGw== X-Gm-Message-State: AOAM530xa/uUygiPZQT192QGkczlTKUeDlm3bGavj+DB9UO5IXzYPo3E zwLSdnNeZcjPdMZy3IvCx97Ad9aUw8mZSg== X-Received: by 2002:a05:6512:90c:: with SMTP id e12mr3129838lft.419.1640094903396; Tue, 21 Dec 2021 05:55:03 -0800 (PST) Received: from localhost.localdomain ([196.244.192.13]) by smtp.gmail.com with ESMTPSA id bu36sm2034631lfb.259.2021.12.21.05.55.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 05:55:02 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 14:53:35 +0100 Message-Id: <20211221135337.1348-11-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211221135337.1348-1-dcnieho@gmail.com> References: <20211221135337.1348-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 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: bjx+GY5CvMnX 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 882584e9c2..1444ea2f07 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 13:53: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: 32801 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5445533iog; Tue, 21 Dec 2021 05:56:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJxOCV+HgSNPiSRc5YcttWrAoWUoJY6DDP/qsCVZsaNeEu+2PO9swFvV/XVIH6xbHvOUFm0o X-Received: by 2002:a17:907:76f4:: with SMTP id kg20mr2718590ejc.54.1640094975299; Tue, 21 Dec 2021 05:56:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640094975; cv=none; d=google.com; s=arc-20160816; b=f2aOEoBdfTmIilUEjv+Gt7jovL2of9g5bPksESJns25GOHsidIaXuiW0/CmZyFihdl 9ZUOYFYI+btlNlpDN77s2FYEwod5v1rtTjwzQP2wj6cFqC2xeNxnh1R2aJ2QQSfPjGV1 vKB1C9qI6+l4C0ggwlBK3VWS4skyE4Nd+KvuTdinmmrYd/nJ+X1tCaeIT2ID5NBPDkOm 5x/55WVFX8qD4jatOCVqcatG4FWjwzZf5O1MFRMJv1cmU/gOhuhlZc+pCYTPOzjGTiFJ GM6MVDW1D1TGTRYylGAAkFLEriGjRp/HxRvUsbdSMeEiXx3JkWFCq4zFjlMBENKLJQ1A enIg== 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=onNeJGyMs5lrPcw6Zgk+WJPXc2R1yJrqi+JijDlurOw=; b=xh+cYxdBLngCkk/DAv7zHZJb2ZGUrNFdYHIVuZJM4dxDKMlU3r2kZ+w7dXKYLCx9KD O57A1gqhxGkygp7T3gTSh+bnFfVnkx/bBZRTM2KjkIMUqH70uh1a4VBaxTgKhCxXmzkv RT8vbnuxJZM833yKdZxHhJ2B6P7XdHXiDfgAVb2vvilS3pNTaLtPGeT7Lf4zT27KCF8n jXgFX169lJ1jZgJ8j2thaYR53T7fuKm0USefiCaqXfgrZt3KeP215PZChhh/YYtlmJUL ZH5H0Abo2wWgx5Yyqe0U9UPZkmQW5xNd7dgW7V/nGZ+KuJxbbLKfNwrtKlz+HiPnC1PN Yyqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="N/87YLl+"; 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 kt21si7373616ejb.832.2021.12.21.05.56.14; Tue, 21 Dec 2021 05:56: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="N/87YLl+"; 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 AE1D368B00E; Tue, 21 Dec 2021 15:55:17 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1C63568AF87 for ; Tue, 21 Dec 2021 15:55:11 +0200 (EET) Received: by mail-lf1-f54.google.com with SMTP id bt1so29429194lfb.13 for ; Tue, 21 Dec 2021 05:55:11 -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=oLG9VTD3/zkWqKqpEYNNvSXMcRVLwN7a646sPmvSEow=; b=N/87YLl+yunX/mbqII4MiTqrF7JmHoiQGRvWGYDJO2KAc0lpZChiTdlAQAYmACQD0Q r6jm1FJJMOE5/2pv1577QdNAKBUN+UmSbJK4HZND3eol2TqD/VB0oL1Dr/qfPgviQzv4 C0zpTc3melIgdt9k0M16U9CFxgX+qvhWKU51SHfBR0MZ6XS6KjYuXxA1X1ESZeLqMRKT azUB/ENjzVlQPmSftzEn/ocNGRFp2qYgHTPpCl26orCBJDWvQKgHr1fy06KskVOdYvbY 4vX4ESdVb5Bmi2pGwaFwDzVlzESEc8y6s9qImISH4cKwvsvYeJ+oWEFS3B95Z0HPAJnQ CakQ== 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=oLG9VTD3/zkWqKqpEYNNvSXMcRVLwN7a646sPmvSEow=; b=X66OhYqtmPD9V66NM5dx3vPQMr9QrpAKfilcj+Ys9d/d6SyAsGIU7SDi151K6FxWNh QPjDqGreHd/HfCeGvdTtKiVzaf9n/Rw+bXaWzWeZ1fP5Kpm3qr2nK3o56QVq9G7L1Hz1 I8MQAouhGC6YY/9GdN7dEFEnGl2ORmeF5j6xZni5sW1bYn9WsKsmCBpeXRUCtsGZSyov nOr+EBSBBE0rKSYo6PiL1cpKGlXcXU7Ua9muxCJP5QTG4GS9M3zz9D2WgiSvppwKFRa3 k864G0iatwfVEzFmIJ1chzXmTFUUJrnt2OaP4vWkYywx+esbMqkcgV8CEcvKBsbXhoGX uuSw== X-Gm-Message-State: AOAM533jPAIVFUxJQh9EGFDeTBEHb75WKvXE+y0VnBbXf1/xnfcIKxZ8 QFhTe3hTu6CBV4HRSKeHGZsONeCtMzba/g== X-Received: by 2002:ac2:5b11:: with SMTP id v17mr3202441lfn.204.1640094910069; Tue, 21 Dec 2021 05:55:10 -0800 (PST) Received: from localhost.localdomain ([196.244.192.13]) by smtp.gmail.com with ESMTPSA id m5sm73162ljb.31.2021.12.21.05.55.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 05:55:09 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 14:53:36 +0100 Message-Id: <20211221135337.1348-12-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211221135337.1348-1-dcnieho@gmail.com> References: <20211221135337.1348-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 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: PiXUt9zmTJcb 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 | 223 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 222 insertions(+), 1 deletion(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 4b1e942c7a..05732a8c95 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -29,6 +29,30 @@ #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) +#include "d3d9types.h" +#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 +78,161 @@ 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 AVCOL_RANGE_UNSPECIFIED; + } +} + +static enum AVColorSpace dshow_color_space(DXVA2_ExtendedFormat *fmt_info) +{ + switch (fmt_info->VideoTransferMatrix) + { + case DXVA2_VideoTransferMatrix_BT709: + return AVCOL_SPC_BT709; + case DXVA2_VideoTransferMatrix_BT601: + return AVCOL_SPC_BT470BG; + case DXVA2_VideoTransferMatrix_SMPTE240M: + return AVCOL_SPC_SMPTE240M; + + // values from MediaFoundation SDK (mfobjects.h) + case 4: // MFVideoTransferMatrix_BT2020_10 + case 5: // MFVideoTransferMatrix_BT2020_12 + if (fmt_info->VideoTransferFunction == 12) // MFVideoTransFunc_2020_const + return AVCOL_SPC_BT2020_CL; + else + return AVCOL_SPC_BT2020_NCL; + + default: + return AVCOL_SPC_UNSPECIFIED; + } +} + +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 +696,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 +709,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 +727,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 +1329,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 +1339,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 +1359,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 13:53: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: 32802 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5445671iog; Tue, 21 Dec 2021 05:56:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJyFFFdVOBG45e81PSgMQeDfh+aD0ek1l1TZAEPaTdv27/l0J482T0ImH5EUaiPUoFAdmPZD X-Received: by 2002:a05:6402:4312:: with SMTP id m18mr3352504edc.273.1640094988277; Tue, 21 Dec 2021 05:56:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640094988; cv=none; d=google.com; s=arc-20160816; b=PcYaFMaP2P3prtla/PqiWoZ4Q+3XFd15YGviKqbSursjCkisGSxUxpk5msIwaJSTS5 8Cy1BzWf4Oj2KAsXEn/FA4GZSi5JWOxd4OFGhxFkp+uHKEaCxuFJgu5A3ylsuPXuCyBr 9KUWaCHN8qrpd+DjjWI9gDNUrru2A0p0tjRxZRdeVD0KO1Qhi+AM7mqZhXyLHFjm7OeC e6Q+PBwIfUyp+z42kvxVqj3voBlPkzZHKucPw5n8TACKm6OjdginlX/BiGOlko1xzL3p mX7qrud5L4ma/vOKH+tV4EucgiOBJc+MtNdWU61h7E3QdGY4b59ODfX/SErAjSCzX9eb C9qA== 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=wl/u3G5KMfSkorOJqQVd7S5naO5ED2C7DWSWtjSO4ks=; b=EHUg9wwspz0tB10uLt5R3JAfkAX6henZgmNOzJ1yu07FqucIB2o5FHbuoI/FkGfWF4 uTjAf3I1vFo2mxPjreoZG46S6MOTTSP7s87OpRMibKXsITfOyEePyHRudkecSshzIV9m 5IvKBUpMA0SFJvRVxn3Leu+AfKJH6C3s6C/uYdjvu/B3tUb+X5w2l/d3dmO/RJkP+ZZD 7WEKVtiWsJRnwSEPwJ1kmTctwK/KtTlivlAn7oTbrK7jv2WHNhbVqE4PFswxH8Nri5M3 Afco3xuIApYUMng1SqodOJx6Tqi5+f9i4QkH3k2bfFHQS7Da21adV5ICYVLgB+1F6Ydm Ia2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=cGJDykrr; 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 jv9si6169167ejc.76.2021.12.21.05.56.27; Tue, 21 Dec 2021 05:56:28 -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=cGJDykrr; 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 C6E4D68AF87; Tue, 21 Dec 2021 15:55:21 +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 1472168B010 for ; Tue, 21 Dec 2021 15:55:17 +0200 (EET) Received: by mail-lf1-f42.google.com with SMTP id bq20so28455386lfb.4 for ; Tue, 21 Dec 2021 05:55:17 -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=McTnfOfIZvUgLh/RYQ15VVkPu+2Jeqcwa05/peNgnuw=; b=cGJDykrrl6f813pb2sMNf4+yyUNyrHwWiC7PcWQdGIbFe2Jf/E2MG7ndk8oKqsAL+X JcY+4vNHX8wBqp6VjuoBgHYHPqy6T3CXuL+h6t7o6f+krbRJopkNcFc2X6bBDWY8Ypyb k+LB4NXUE6xQ8ytfFtlqDzchdf3E4/QG/w2rDlRMGkmSt84tMT/nzRX/IVWqjyvinaDH JnHFVJX0z4H27kBSRPPfzDE6Zu/CFEVOpS47TgpkzSeCf3GCfKFb7FCjdPTUNMxBub7g LBfnCFYmVrLDJGjZYMgH5d0KWMTDfG7sHWpLSkIVvDoXV/i63iQpBTKfdJs2OlSdno/3 uSlQ== 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=McTnfOfIZvUgLh/RYQ15VVkPu+2Jeqcwa05/peNgnuw=; b=yjyMSuaTLseRKHeM3vmKuh+hfdGlBtsdWkrqClPORWkpqZB842+sFdswu7oU209aCq BK8RxT7ULSj33tylsZXHcKC9sIDf93AueWJUlA5FntlUJDtC1kUGOwmtw8zJe4UF62t3 mmJLcypNsx8dkNpY5kLO0KuTewvZV2pDWDFE6LzOvZZdGUb5PqQq2b9DCAm86Y5p5MLr hzaNjL6Y9SmRQd/t7amD3cjY2JkMHhfJ+pAXsuPQf8VZaApVsn5Pq/viyNZyC3GOyFxV hmSH4IL/yQPcuI8PSB84FORmdkFiQtnZPzumGUKID4uhCtgjnSquB2+rIfbgbNjk9CQx VZfg== X-Gm-Message-State: AOAM531xlckvcN+a+MEtE7OL/5jJw7pvxxkYO8+O286GtkI/hUk+Ez0A VIGs3Hwyo6YonODTwrj28PhDrPxZS6kLOw== X-Received: by 2002:a05:6512:e99:: with SMTP id bi25mr3219374lfb.317.1640094916604; Tue, 21 Dec 2021 05:55:16 -0800 (PST) Received: from localhost.localdomain ([196.244.192.13]) by smtp.gmail.com with ESMTPSA id w6sm1701102lfu.44.2021.12.21.05.55.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 05:55:16 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 14:53:37 +0100 Message-Id: <20211221135337.1348-13-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211221135337.1348-1-dcnieho@gmail.com> References: <20211221135337.1348-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 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: RocBbr7s4u1f 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 05732a8c95..a93cc45cf7 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" @@ -658,9 +659,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. */ @@ -671,9 +774,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; @@ -684,7 +805,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; @@ -692,106 +889,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)) { @@ -808,23 +1000,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) @@ -943,11 +1174,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; @@ -967,9 +1194,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; @@ -1012,35 +1237,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) @@ -1310,6 +1524,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; @@ -1324,12 +1539,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; @@ -1339,8 +1558,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"); @@ -1351,33 +1568,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) { @@ -1390,23 +1595,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); @@ -1414,6 +1622,7 @@ dshow_add_device(AVFormatContext *avctx, ret = 0; error: + av_freep(&fmt_info); if (type.pbFormat) CoTaskMemFree(type.pbFormat); return ret;