From patchwork Sun Dec 19 19:21:22 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: 32726 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3695178iog; Sun, 19 Dec 2021 11:22:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJy6M6v7OrzznXa/0kuL5fmTJ77ZNzdHJX8DuciS/9UI78RNTduqVk/F2F0sOM7x/Zeue6Bw X-Received: by 2002:a17:906:6802:: with SMTP id k2mr10331249ejr.454.1639941733374; Sun, 19 Dec 2021 11:22:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639941733; cv=none; d=google.com; s=arc-20160816; b=pz4iWKWkuroyWNjuRylC3o7U3eSs7Yn3UnXfVy45DqNiW91Va/s/vaSfxr4QL3kCCQ ABWQoTEtjI82Gh7G4gSCke+jfZfXhdxrSAUQNIGiKjGteZ4YLVncv00JJeUQfn/vE6WQ DBZkHllINBw3LgN2oKOpVqjjH/vidP6LAuF5lLLOmnywj14pMda/BhjavOLrx5W9M6tY ACp2NrS9gpybS1wrDI5OxADnoc5sL++xw3MChl3iKmZ/7RuitNdsQfz5p98uwYP0rmkm eZgTIzHJGHwq8enPw0kmCvBg2iGhKf7Ke0l9V4MAFz5W/uJMr6sJ/DCplDBGAB9tJBrJ i1Lw== 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=HKT+KKX4JD3OjzaVESAP4EqN9pa/WDi6lORcGkY0/Nwy++1XEboIDB/YFHQBHAoFsF //lx+7NeO0kpzOi619p2s+cOudHerEhrYqqETC2GE6U9v/EDvieq2J2g256XZcSUDiSN eRuhEGVVWg6sP4HTlCBNis0nzSMR8XeW7xBM+mP71cmZuvNtvkV4T0PlhIrTG3PZn2WG ynIwaoyihrB0Nc4Oy9alDu5+8lniN1SLmXqD/O7/gchcRxHrV2uqdoZ6DXRkFxcxhMZ7 V+OZtbzLeDplahpn5vOzZHsTMFpvRDAEHcE/NviCyxnFVTuXzXHeXWsP3yP0PawIJchj b7XA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=oPHAlvbN; 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 s18si7757595ejo.79.2021.12.19.11.22.13; Sun, 19 Dec 2021 11:22:13 -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=oPHAlvbN; 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 A3AD768AED4; Sun, 19 Dec 2021 21:22:07 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D905C68AE3C for ; Sun, 19 Dec 2021 21:22:00 +0200 (EET) Received: by mail-lf1-f49.google.com with SMTP id g11so16989802lfu.2 for ; Sun, 19 Dec 2021 11:22:00 -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=oPHAlvbNWEF82tmf0ghVIbN03pR+AEsCmszKUtWH1AurTBQEjq8lO2x3Vs1E3zBihT dIzsQ1WXA7adDsn5sVSFEWAaF054CSDTRxfbEO21dYqO4AL3Y1yHwvuRql2nNNBCWT8r AxuCoYKR87aWemga8ObmxFJotMnI/edZgGDuC4GgCwGSGual+Md+BHTJa7HM2cFhgG5x NK/JSn1Poc2cq4ZWncVeJYaInwemCObuZnQF45LIabr6Eb8F0jc6U+tOxR2H8/vWo4ad x+Y1GN4TOJysRIQs+pjFdTEJk9V+TmCN6MR1kX7gXPGhihFSUm5pVI7lsxOBi1HHokAY Sx7A== 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=sPICOxOHPg637Ko2kMW74Pi+Id3ZfJnblq8Y4dumDYBVpf15Wl1VG0ZHO0zR+lEI2N 7y2KFtXFOiDjNRPFAhywYpHKqB1bezRQ8/h9c0NTVUGcnSGVmAB0sYRwnLldsxLABMhw HMuSEBx94t8/ycLhI1ABOnQrt5piRsMlMTfOpDDfSEg4PDtnXSY1Wc9vEL14pzX2p7Oq Ul7r7eniSw6w0XPqs71r4UnTwr20KXYZ/bMMoyg7/+HoJ53ZKZ5W5ZJOVDB+kz+2Tjf6 Ws8OL8nLX9dAbPxYyPeVkLEB+ucQau682bKU0OzrpQ3fhmjdF7vJ3vjmcrY4BdG+W0pF VAwQ== X-Gm-Message-State: AOAM533SJ2JyBOxeARoWNLwyy+fq74ziH1oZOJigOAf0q7SC/MnGVM7g YpvnDFdu4AgcpYU/vbs8Qlr7sk3v9tIEtMtf X-Received: by 2002:ac2:59c8:: with SMTP id x8mr6672053lfn.573.1639941719534; Sun, 19 Dec 2021 11:21:59 -0800 (PST) Received: from localhost.localdomain (84-217-56-54.customers.ownit.se. [84.217.56.54]) by smtp.gmail.com with ESMTPSA id be25sm2320921ljb.114.2021.12.19.11.21.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Dec 2021 11:21:59 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Sun, 19 Dec 2021 20:21:22 +0100 Message-Id: <20211219192134.1296-2-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211219192134.1296-1-dcnieho@gmail.com> References: <20211219192134.1296-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 01/13] 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: AxDTGKJzzbj1 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 Sun Dec 19 19:21:23 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: 32727 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3695292iog; Sun, 19 Dec 2021 11:22:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJzkNczqp2MRoevyJMuhYuAo/F+p+QSJRen4CG7kCalsx2j6nUsIHJthxOlfaUgs44EQfimv X-Received: by 2002:a17:906:7217:: with SMTP id m23mr10103456ejk.735.1639941742777; Sun, 19 Dec 2021 11:22:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639941742; cv=none; d=google.com; s=arc-20160816; b=keOa+nExW3jgXXHxe9TNid359cR51k7Em9Rs+nnhZ0KkgRm3WrohMwaXzSsjzzVlKT 5CVKxMiXeFrNnoHuyiC4BFKifp5YZLBl3hzjnTjZB8ZD1ptZ/c+3LcGMGf3RmPelr4in lIyofnHysbwa11oZG0TJTmR2M+ESpAlwOMPy742mKIWFcFayEPOsuvraMNL++9kiNFD4 1cPJ3fOvEjI47JCZSbwHjNb4KE3o8WCIKteB0L1BB2OnWpNrezW0X9kwUpxkwNSBJiWt 6LD/j94aGo8Leu0AttKW0OFwDRDI5SFk+yNrwnwnk7+R3T4WhQrggHxqvWwpzHNlriWx dFzQ== 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=cb6qFZCRmw9uKI83TutOZzOW3dr94jHYFbzqbF3Z6KM=; b=bHd09EJDqr4aPFr4toG5DwnhPhMCY2HyKaqhngiE9B92Gq3GRyga3mahSAlZ0pxSbB Zn/z582cFwqm3ZsChiPVSMCQOzIQniCatNyD3JPyFxIAOpLMnk7H5qheDWIUfHqyVPjv RYllHHJQh13m6rcdgsQiJ38ON7UFB8ILSMHB4fI+FIPJLf36i9DCF+GXoyKi2gyfDt+z OT0WcJ2NVqGDeFN5gLzZyjKxz2YbfgEQuFAipBgC+5PzFyzJp/Pd2CMUSOHeMgsw2oIY hoRpgqxLdFI48wOHSTz1q/NKBq1CYvG8TaiEZz9dji6OKgyBu859yeeo+VRQjawQFUMW hrVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=EZcKdD9d; 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 r3si8764798edo.571.2021.12.19.11.22.22; Sun, 19 Dec 2021 11:22:22 -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=EZcKdD9d; 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 98C9D68AEC8; Sun, 19 Dec 2021 21:22:13 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D5DB368AEC8 for ; Sun, 19 Dec 2021 21:22:06 +0200 (EET) Received: by mail-lj1-f174.google.com with SMTP id i63so12478620lji.3 for ; Sun, 19 Dec 2021 11:22:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5pFUjJjSlGSp8OHwT/JcqzdN1IRZqm+bZ2QkppFpUzM=; b=EZcKdD9dqYNFZjl/tn+iKEuAkE6TmQv1bXq9v+o8eC6tA0m/53A3QTVQSIizb/sZ12 Oh1shBwpjE34ZE9Cmsz2tJ+NRNzOdT9T6LGYRD208x1FrZEtpK6k9jQuE+yuUk1ZcRkX bLhFYioGlHW0ZMrqc4HU1DFeZUM0e6Rq0xutWDN8Qf24wiKKpdhyLBJjLqfvTXl6TN7Z aeVcbLTc3J+cWyTps561piVaDztqXQ+9rTYiCxpyOEkP19rLyUZvGdcYjSllmXhF5wEv PYXXCMw5NOeH+C4lZ+/1YRpLHRx4j+2tV+W4geyEuvUl2ts1jNsV8UvgGx98Elm7IS/9 APCA== 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=5pFUjJjSlGSp8OHwT/JcqzdN1IRZqm+bZ2QkppFpUzM=; b=hUl0pApN/NBWhzLf3iPMgdubtdC8HjQ7o4JWHLKpeed7FzERy7xqaB7UiSeN6fiWDv drODMVYd/il8/5uptUSRZ0zMtXXyvM/oqiBDmGDeefw532+JtYIVRrPFs5IHe/36WTLR RysS3baWXi8SxKjrX6lV16rZx8UAZZmYdcI1nqWrKODyVOjHu7rAK6pFI6NWnvKCaIGg aaerjjbgcynf/c1cSTX79fv1Hcy1cDoFYx6zJnTkz2Sla5UK7DoVtCgIXZKxxO5faMkk Ga+63yZR3ayTgqfLQwAdwmJRTkkxr26doplBHa+ewa//0CQoC8fepFMSWtxPnUmwSwVw dBaw== X-Gm-Message-State: AOAM5303TSJfFL4iTPbTiNTdgqE6JYfSnNhX1i9HOzYRm2Neu8rq10mt v4Ics80fv7detfpn5ztJPMw4/s2s40LPmtKn X-Received: by 2002:a05:651c:10e:: with SMTP id a14mr12089974ljb.519.1639941725969; Sun, 19 Dec 2021 11:22:05 -0800 (PST) Received: from localhost.localdomain (84-217-56-54.customers.ownit.se. [84.217.56.54]) by smtp.gmail.com with ESMTPSA id i17sm2123315lfe.281.2021.12.19.11.22.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Dec 2021 11:22:05 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Sun, 19 Dec 2021 20:21:23 +0100 Message-Id: <20211219192134.1296-3-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211219192134.1296-1-dcnieho@gmail.com> References: <20211219192134.1296-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 02/13] 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: 8lgApM9F+3cT 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. Closes: #8620 Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 1 + libavdevice/dshow_capture.h | 1 + libavdevice/dshow_pin.c | 11 ++++++----- 3 files changed, 8 insertions(+), 5 deletions(-) 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 Sun Dec 19 19:21:24 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: 32728 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3695371iog; Sun, 19 Dec 2021 11:22:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJwy758ggk73UgG6oWD2KSVxz63KquJt2a6ZSRTLGwumB9xNMyGwwqVKTFbCpblsyn0mzHAQ X-Received: by 2002:a05:6402:297:: with SMTP id l23mr12213370edv.400.1639941752962; Sun, 19 Dec 2021 11:22:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639941752; cv=none; d=google.com; s=arc-20160816; b=w6hA4vlUy0tonm0npncz58VM2eJLmiFihJrYeNybw42Q+BByeIiwoWsLnKuZGCcH60 aGPBSESjxFEwlOETUWUEJdeLrv6vPaZ2YhcabE5sezqs2k5b3S+uNn+Ws9ow4WeAshCD wHdnktsZsoNlmxjDC7Je1n47I7YNMLBhSYVGAYiajyAtCMzXnfkD9FCf5i7zwwejVN7X 24i7afYnVJOqBvbouFM/NJN4psnBB3F44RipvusvtTR1CIigYNkNWckog0jatm9Zb9GH bymiafpQJ2pBMWGBb8nS1j9wA8nYtyHPN2wdwtEfv/Bf5xZrgBlhIx9mtPeW3netP8Ma jXqg== 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=ww9zrGVs3Sf3WtAuexO6dUed3d83/nuLkVjfn9hvYc8=; b=PCWTudJKN62SazcXf1LwQFVuFtoZ4CG1NlBq3Sjti+AYyNE0kAlg1SUeYC+q6e8Jnp ACd0wDJ3vxv9Afb9VHIRd8yTdB+focncXcyfZWebAnavKqr39IzJeFedUUri4YWxTvwc ozbGkDX5Sm9x+1fgCvFjaK9t5LfkMTJjoD4EkWfyI/mESAbuZhjrNTDV9mx39Hg/qe7u ILnmt8ukbR8Ifqjeyom/rDcN0rC9PqgdTtNkNtet+w2walPusyH9iuV8anZPMcW4AWVf EjTzoEyEPmX9jLVVKJQlHX3HfNe1oInme0nUIqpzIFY4k2rxSnKkkW4L2Udb5VSsaGeH oUug== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=midZI9h5; 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 nd7si11198280ejc.515.2021.12.19.11.22.32; Sun, 19 Dec 2021 11:22:32 -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=midZI9h5; 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 CCBE268AEEC; Sun, 19 Dec 2021 21:22:15 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B1C8E68AF33 for ; Sun, 19 Dec 2021 21:22:13 +0200 (EET) Received: by mail-lf1-f46.google.com with SMTP id k37so16989197lfv.3 for ; Sun, 19 Dec 2021 11:22: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=dnt8sXpAh/1gJkyMC/XJOEO2KpkwOeytqXo40qew90g=; b=midZI9h58X/PR60xz4Dx2Nvd8IhjmFE8oab2NCNK0zLczjl25ZLe7PIh79NL44OmiJ fL4EWSt9EZGutBzZ8buNvvMi/jSfS27vOXHKDETp775nbXQxXtgQhPBa4k9h2fPOfOp3 OyGv76QiJhpJUdk3lMtsFsIxCD1lWmr7U+VpV1jOcN5MF+B48IviRGf3IJZ9UNqk6baO jOhqwi/PzEVuqRQhmccN45croTYByn4TAkSGOL/2SJY7SlkdJ41RIXH7GI7NAlmQLj8X d3ilCdzR9iOhHSZO5ZF+LBIqAwvaINOVhPdyWl8vgttqrjnQSW6ehOueUHcurS7//tKq B3cg== 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=dnt8sXpAh/1gJkyMC/XJOEO2KpkwOeytqXo40qew90g=; b=BT7CbueDu7LKqpMgOXPpqg4nS5JkRKtIu3rBV/GbVxnr2Ksg0dVGL+wLgNkObnKs87 T8TOme1yeiOen+4qU0lswayGlCbJLXXbCURch6JxwBHlF+rN7k5PEXALjycS/8xpYiOT olIIp0soJ5mbGhWIeoIH3fwaeoDBlkBoeiRjkWPnBUDcA6KZPavjsvET+cv//qGUcs89 IshdwduIfacEkAlGVBkGhHWyiMtXB2Z3XJEaAKpRlCJN2AD9pWed66RG9NZLNLA01ZrY TzdW+la0dBX2pxG69jp1eB5/PZFLFSqqDGYZd5ehYCxrCOjr6A4B9b0XZGz1TA7QUlF/ cW2w== X-Gm-Message-State: AOAM532Zdg7WFK02X6AeJ0xWTJO5pZ1gsRBBd3zqVqpopsimTWd5GC5h Q3sJeRYGqNhOwVWaTzJMyNen0+magxx5a/9h X-Received: by 2002:a05:6512:3341:: with SMTP id y1mr12168753lfd.311.1639941732396; Sun, 19 Dec 2021 11:22:12 -0800 (PST) Received: from localhost.localdomain (84-217-56-54.customers.ownit.se. [84.217.56.54]) by smtp.gmail.com with ESMTPSA id 18sm2325835ljr.17.2021.12.19.11.22.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Dec 2021 11:22:12 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Sun, 19 Dec 2021 20:21:24 +0100 Message-Id: <20211219192134.1296-4-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211219192134.1296-1-dcnieho@gmail.com> References: <20211219192134.1296-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 03/13] avdevice/dshow: add use_video_device_timestamps to docs 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: S7OPijLLJQAY Signed-off-by: Diederick Niehorster --- doc/indevs.texi | 6 ++++++ 1 file changed, 6 insertions(+) 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 From patchwork Sun Dec 19 19:21:25 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: 32729 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3695441iog; Sun, 19 Dec 2021 11:22:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJw1Aydp4fyJL5OWlibbHxT/7oSnOKUnwvwS/i+jvfYsLThSovufMAlBCCDF71TJLGws+mp/ X-Received: by 2002:a17:906:9756:: with SMTP id o22mr10071925ejy.324.1639941763006; Sun, 19 Dec 2021 11:22:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639941763; cv=none; d=google.com; s=arc-20160816; b=qkztAoJSJmxizdcdcOc1SnUzVIMZYkGXi2rKSQtTBswH2JPynscSlu2dqvpIinVpYs 3wdpVSXUoSUxyim/rkljCBriaz9GUcMsDpm8WNvw8b4HfMk7epdlIhunaQuB/HvLqBoR xXrp14jJofabYVHrZtyrgrMmdU2S0bDiGRevOIOPMpHzpncsVyF7/RLZjBDe7Secc43k knKemqjucndsrpLEJ3JlTw7MsWkjihe4pl52VF+U5A0teH+r7K1VmjP5+6FcpETWr+kt 1pKKXfoTianvXc/kt0YLdM9GYWI9CuFoCu/z3Q0jEOCyrMqyYR7Y+acMFGe230r+a0CZ B0oA== 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=XX8Lt2U0WNfQY21qlyEIN90dwEe5Exn0Pbdzs4hWIy/4p1Bt/MLC2VqCz/JwB/1SFX 9NvN5cOnOp01co1nCN/c1nME4fRtLHtuRgJyaTsml8J2A6MjIuft1qDUB45vUalAH9bw y/tBanCK2+EEgpRwrWdphxa4KXQokuvZ2+h+3JaVbbo21/noU8kDG1Hwb1jo3DFB1ZrZ 2H2M8EGFU5AAq6mLTLSFenXiQkCKasCypfm150gjitwqFAfXncnZuUN8DOVEteB4DyXK Xg+6Y6L3nwtaQ0oubLKsIAHH/ntSKMbaVazT9WN8T93jntYeiBPSqzdH+mf4KRG00lMC DTKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=CPt1VvIM; 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 jg19si542098ejc.796.2021.12.19.11.22.42; Sun, 19 Dec 2021 11:22: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=CPt1VvIM; 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 013AD68AF5B; Sun, 19 Dec 2021 21:22: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 11C3268AF36 for ; Sun, 19 Dec 2021 21:22:19 +0200 (EET) Received: by mail-lf1-f52.google.com with SMTP id b22so16914189lfb.9 for ; Sun, 19 Dec 2021 11:22:19 -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=CPt1VvIM24uHqOYlXm0Yv9XFq/jnvhTFH15qvjHIP2hrwBz3Fs62kmG3r2zQTGkI0s malzBd7oGBaER0EzhLEbdY6nrE/o3XLoi9gwbmkG7YOqNGnfm2PE4shsd+l15pl/mWoL IZzBSP4hIMICoFVR0VTTELc+rigSCPCwQ1SjY2es7/ZQqRT8j9h88zbwijPg9x5l+vdA pDPlFyjFhDszBNcqWbqT8Y5WXURMgto3S0lPVJhb/bxpoI9qc/4TQ/yZlKV7NDpF+rwr QXkopAmgWtWdSCh8ie4PnbidEKtM54XvDnn8swC0yDabZkECUvgWf2nw1LV5rVQmvtPw zP2A== 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=XTlEN6Ecd25ypis6V0FS0NcSG5BRJem9eSE6KALw0JkopDmKAuFpsjtfF7qLAIKUPV O9v8ajlGo33x1AbUiJxuWEb25JqnFy4iYzThs2v/octpeVpmayyuN5+bO+c94wOgjYD3 NtKpSBnV87RQUfBZ9OEXNHCg7YnTXK3Ay/VeR9Pr6M0lWxZCWmkBeDr55Pg3I4fOlxqZ 6TumJtGD0uMn9BnMMtLUuW/DjXncU8JnYQR4/IDUyKd72ZmnAKDDTiPFVsoeI0DxczNb 6tKoB9HQ8gFlN0B7jNAlQmKTu9eKtH/hxC1Zb/rt6poPWQA+dXvBpUHOijy1Z2Ze+yFD WFDA== X-Gm-Message-State: AOAM531JGGT1yGCcl5K7M6vZnFiXAhCz03fHwKHceOCxA/8YN68IAL8J HjzQyKJSCuO80BdxNqTUwRSWZbZA52X0H5Lg X-Received: by 2002:a05:6512:ac9:: with SMTP id n9mr5772183lfu.460.1639941738829; Sun, 19 Dec 2021 11:22:18 -0800 (PST) Received: from localhost.localdomain (84-217-56-54.customers.ownit.se. [84.217.56.54]) by smtp.gmail.com with ESMTPSA id z24sm2127812lfh.289.2021.12.19.11.22.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Dec 2021 11:22:18 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Sun, 19 Dec 2021 20:21:25 +0100 Message-Id: <20211219192134.1296-5-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211219192134.1296-1-dcnieho@gmail.com> References: <20211219192134.1296-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 04/13] 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: 1Da1jFf2ASkK 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 Sun Dec 19 19:21: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: 32730 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3695540iog; Sun, 19 Dec 2021 11:22:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJwEs+l/Ap41XY0c02ToLno+fHrYp2Sbjdy5XYXzdxP4GOnJdYusztOHU9HgYt7FZkXgNGI6 X-Received: by 2002:a50:bb2a:: with SMTP id y39mr12541420ede.348.1639941774465; Sun, 19 Dec 2021 11:22:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639941774; cv=none; d=google.com; s=arc-20160816; b=BWD8NaywqWOGqgZS40fkQdGDaIPvMhLg5AnYDRidN3kO2iByeifgJoY63fv35x7fnq iI9oad8KkTABaqriM641pbQJcxJ56Jt3uf8ea+S6SQQlpyDabrNvnMcj+jul0FzArKLe qAST3MYrpF6jwqIKQlr9kSL6/Ymyx5Mf1vTOj6jWWraUHkW+Iq5ZxkkZqbrLCgiiw6Wx cdUsxDlrPBVOoB/Apq8PJmPsrKLkrX8DzhiPnIlvb6i7r+I+8pFCtld++LQCXEKtLTf+ +qC7vvN8QbbnQT73kpr61zLrxAVYm/IakqDlxbmR6NPxc1HHKm2WpMWbuZ7DHxyi8Nu/ CVgA== 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=gToRTJsqgdPnurE3xYO4uXhF9qAOzAi1knJwJOEHjU9SnznwA4A455khDkNiahMm5A aHjS/16l8NtJVT/GX+jqz6C96MWu7yZBCplnRueRLBdpA8RkLenWC/eRW6AwBrgrAPoP G27J0MGRYYCva+wdSUSiC9Mqb8SJGthLBNKuUQqFct+apE+ijTw+xjCFv3/dN3asRi4U Uee2LYVfDIsc/K1GA4we9O36lLxNZB0v75qvxgaw39Lf6ATCAZrUR2dpKcrHrTol3Vws AmIPMw+TnGkr3MzKLBwjyZYLllrVHm6hM3HGRF/YxU5YzvBnGx9I/9gWrDcqOhkOHm97 3WTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="b5HB1/m+"; 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 qb11si9755415ejc.903.2021.12.19.11.22.54; Sun, 19 Dec 2021 11:22:54 -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="b5HB1/m+"; 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 C4E4D68AF81; Sun, 19 Dec 2021 21:22:27 +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 9DC3268AF4F for ; Sun, 19 Dec 2021 21:22:26 +0200 (EET) Received: by mail-lf1-f54.google.com with SMTP id u13so9647525lff.12 for ; Sun, 19 Dec 2021 11:22:26 -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=b5HB1/m+okSuunD66q0ti1UBNyxzypkt2N67H+x3oyB8I5LbdGlIPM5rklll4snW9D mQHeHMUIRN3beX7GgBQsAdKg5+V5KzjeMtkgcVbDBBLj29QNDXlgDk3OwfNtwTx/U8Il /piQ0ctXd90UpRTeUpistg9sXUqpjXKpKLWJIWkg2MAPfaknPojspHCIu5udpSpSkJ8/ JMYMGdRUqlgZOhGMGKUkyRbLpcLsPjWZ3cbdNDHQPwf86DCv1QlCrSU4WJfDEihq/gMQ yoZ1pNYFkhRZ0XKlcVkI09dOoZ8o7p0pWjqWnLpuMqXkJrOX2zOagiaJ/gSHHhb3BneL /QZg== 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=rnt7QI6i0UWqBXvxImkFW/9w9OeRTRHJQOP3KDXt69SXgpDkQSTuSiIm9zs2+6uGel C3lp9WM104Lx6cUIeSQnkxp3woWafcxaZgSYSMG8UBNVGegcNb1xU2jnVDDy/CUx3TUb oe4m7fFskNVg4MfKhWuZNQ+mi+wSW9lZ6ClxJN+5cwQjf91EaY/+SUo1/jRdo6X0W6xP XAgzorSL305ztpFnJlw1DiEr+5HoXHpsMbOGNaqbhXPu9BSuDigafo5TePg8kqR7Rz8q iYVDhbI1QQ4udcp6y6MEm2lJrdVmZOstPPQXEf0nqkOYfAlXXh8pjIBp+OC4mdAXT+dt eQFw== X-Gm-Message-State: AOAM5321yYtvarCQplIJ3S37FazpKkK5jmryXsofNyX278O91YK0iZLL nugKVtDlDI/TDhxMrmTbvizqthE+mep22ZUO X-Received: by 2002:a19:6e0b:: with SMTP id j11mr2221634lfc.226.1639941745354; Sun, 19 Dec 2021 11:22:25 -0800 (PST) Received: from localhost.localdomain (84-217-56-54.customers.ownit.se. [84.217.56.54]) by smtp.gmail.com with ESMTPSA id x26sm1536079lfn.121.2021.12.19.11.22.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Dec 2021 11:22:24 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Sun, 19 Dec 2021 20:21:26 +0100 Message-Id: <20211219192134.1296-6-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211219192134.1296-1-dcnieho@gmail.com> References: <20211219192134.1296-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 05/13] 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: fnxR7Fw4ASs1 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 Sun Dec 19 19:21: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: 32731 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3695603iog; Sun, 19 Dec 2021 11:23:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJzsSImc4rx1WwjFM80+SA3R98yepkKIzg8PjW6w2CsnMgZvs3AxwGcg8d6gaNAnzZwYxrWf X-Received: by 2002:a05:6402:b41:: with SMTP id bx1mr8276085edb.292.1639941785183; Sun, 19 Dec 2021 11:23:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639941785; cv=none; d=google.com; s=arc-20160816; b=1DVlbG25dyIyntw3rVCnsJ1uKZzfARR1nz82ed4ZkC3l7SgJ2wB0Sp1tp+rxd4gGD/ tcP1z+5nI3BC7CWFvkahoNIMmwzMmlcLhokmkB7Mqm7HAqBpOruXuzPSbk3cP4syFUjq dpINmisXaiKxiFRHm6lU+CYduGosaNaqGVPC0hNOTi1hSA0WffN/ZYKUFnWo6S1j0Yn3 H7D4SKfjTuP9wxv/BblwUw1GnYfs5kb3mUSw3Pq7lY+X6ijcd7vh8kB/FoURQtryZqII PJQdLYthC/pRJ2oCAF7U/KflVNXXlRArGUM9eWVNJ1eG7A91CTurBgQP0klXmNNGQiRp 3qMw== 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=wZlVTfAAKq+ZBUIPGLKWT+27ySpUJb6zSZK5PvIQlXPjPi9h3uc5ODUNQ/mJGXrWLt YG1yMw7hmleTvzJGTLoPvs9MgTUQw5Ej+mDHaZ52H/QW3l4RQUKLpfINIa+RkKgaeL2p fp7WpAuhzwmT89/YxapF2FPdSoQ0SB14nGvsakFWRfILYz/oOU7e6fA+2K2h3UC50d4Z rJbXdHPaZXIjguy134mlvol6VFfgDXmdJnW3nilRKfPX2zX6i/fSwPnR1ZDSX9L9kZWu gGe14mQ2CWaCzrMO6SfahmLAOcoO/uWDtDHgeqMsez0ACVKxua9BotG6vJbtYACzLcY2 ufog== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=AOeYmYrF; 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 nb21si1369734ejc.723.2021.12.19.11.23.04; Sun, 19 Dec 2021 11:23:05 -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=AOeYmYrF; 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 EFE9568AF90; Sun, 19 Dec 2021 21:22:33 +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 B558768AF55 for ; Sun, 19 Dec 2021 21:22:32 +0200 (EET) Received: by mail-lf1-f52.google.com with SMTP id b22so16914904lfb.9 for ; Sun, 19 Dec 2021 11:22:32 -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=AOeYmYrFAR3CDrLyijiWZ1iKBc4Bw+f/Ur6ajJRnW2Gqv8RGHi1owYjZO9fNWaICXt mS0PAHchqsAxqmq8JgYjQrfTTarDf3CQVjDR3Gj3ljbWCYtKEoJuy8IYwugw3JrfrEF2 lMFv6QVi+4cUwjb8pb4EOaugvro8gLfEIF8025MCF8Ts9/5DIzF7K2C3hyU67RxowUPF xDrmk+kl+RtrC3EHHE76Xju+U185kyOFcuVLfdXhKOYB1aD9pRkxeMssole79+1Ysy0E 5WK6E+TLMSWez8kTvApFG132GoYsgVZBikSesr5QXEfcn8P81O2/NGa4amxGHgTaiGVH 7erQ== 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=YvHTXo12JXMeTrqevcD+O4ARcUG7yAtVzxo7PWHsRLOl93cXY+VIHWL0YtTAa8fLLI We0gO0f8loZFNi8r8aCDs9kYDAk3YPbiiK/ucHOfZuOskoPFMQIhOCwu5gqxhYxDwhCX G9LNxjU/pcJxeaxoUDSPIiJcnLKTr586iz8VIQrGe6VPtrKB++3Tpdq5ef7UOQJ13hTm pF8sjOU7UN441WsH6+bR1pfQgs0zQi5I0O67+89VZ7X0UxIgVgc590MiN5IRg05UonJd jn7lMCPImhTEwDVmKW+FcZM8sdJeFxITKf13CrXOJ7G0JGZbFutpZE1zBgJK9EnmWG6U s+oQ== X-Gm-Message-State: AOAM533E5xNfloSHZKsRbCDck7f94pnt9NvmbMOT3nsDTaIUwYr3w3ro 5Er2vlZdKT/ZanLvkgJT78RYaCoMC2lUs5eT X-Received: by 2002:a05:6512:210f:: with SMTP id q15mr4607937lfr.112.1639941751788; Sun, 19 Dec 2021 11:22:31 -0800 (PST) Received: from localhost.localdomain (84-217-56-54.customers.ownit.se. [84.217.56.54]) by smtp.gmail.com with ESMTPSA id a17sm2326693ljq.72.2021.12.19.11.22.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Dec 2021 11:22:31 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Sun, 19 Dec 2021 20:21:27 +0100 Message-Id: <20211219192134.1296-7-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211219192134.1296-1-dcnieho@gmail.com> References: <20211219192134.1296-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 06/13] 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: 0gAsQMPbIv3P 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 Sun Dec 19 19:21: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: 32732 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3695682iog; Sun, 19 Dec 2021 11:23:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJxnObp22oCZ6r5diB6LxB2rBDpL9nnToIIbcrXM1siGnmpovE0zzDp3UlXFiqXpiHYB5+31 X-Received: by 2002:a17:907:1b24:: with SMTP id mp36mr10804268ejc.487.1639941795744; Sun, 19 Dec 2021 11:23:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639941795; cv=none; d=google.com; s=arc-20160816; b=aO4xWNBUaX6TK2+c2c2UTpxSc7wi+iWEWLRLnUBIoEuk5dg4eMUavgwYyneM7MybOh 6pWzSZaXYBlsvsvXiri2pJMcm9faJUSRZjfnKH9j7t7oaYHiYN23wshFKCEbXoxLEg6o zENuuFd9p5hYx8u2T7dmLck06cmIGzVDreKs3XcsvVV5Y0qCQnbwfpWa+QwQxE0l+34G VqgRnMDmYxl+PlWtYsS1koADSDOLCT7NT2JM5jdIeVhJ8Uv3Sb32XU7b7q1/kUmWzL7l yi5i7jhZmQnife+onkLtFJBXIFEzxUzNKGJZHGu1hSdzzRX55hV+H1AglGhiX7IW23vh AG6w== 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=tG8Xe64fCv/CzNO/1KPJRE+HrHmRsg92GLBzOohtaK8=; b=JKi2ld5lSnF6NvZc+rOjVew3ecrn+0SqgPJuiSldS98FlOiThzYFJWLnl3RXCZD2cY bIdx5RXsIrKDesCH0fKW0BJcBVdhQjS0WKmL9jpoHAoTt5KDOppisr2gs0rXq7T5DhKO /WGe9pJjpCDdkjtggWPD/qpH6Yx3Nqhdyowjn2o6quHoXbeTqG5rwswUPAR757mF2xWZ F3PqR/5qCyrGXpF1t9V2ymPVOGzQas9Un51M7WPb39gOAR0i4NGeYFOQUB87dU9Pz88n +6SP1wt0i44jX9Jq8Da+AuadAbpN4th6I2qMZLOy/Whv/QjVggJ8iHbTtS7P59dinK+0 mcTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=fdjS6zb0; 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 f14si3701068ejx.663.2021.12.19.11.23.15; Sun, 19 Dec 2021 11:23: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=fdjS6zb0; 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 0419268AF97; Sun, 19 Dec 2021 21:22:46 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 36E0A68AF86 for ; Sun, 19 Dec 2021 21:22:39 +0200 (EET) Received: by mail-lj1-f173.google.com with SMTP id z8so12470531ljz.9 for ; Sun, 19 Dec 2021 11:22:39 -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=Rce8u6K7LN/Um/IxRb+ZbL4sJ3RSDKU2XLCuNLPgW6Q=; b=fdjS6zb0MyC5Y5z57nEYYdajMUhieGjPXUMFEOooXhfjObZ9Q1o59qllPgA2Kyi7sc yMuSaRValPlKI6UalE/Dh2j92tg9+5MtAVyRBGrX96STR3VOIZxuQsiYrMumsLU3oATC HXbKalE5HohM1D/AeLc6Ah+JJ/odc6LV/kHoRGBzfS8vQu9fBE6xLu4hTbJC5rjKwL+F eW4y9ozxQOWB4gFN/gVV0Jb0djIoj6hxiS0SJgWDH8oACgzKzHu6G+GRhKvWdS35fb4w ClPPpRwxby5d+xlLqqoEwcq3NNezikEhxuUN6b5fF33DCJ4Hn+7O8IYyyzL9Ui1N0IwL 0iIQ== 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=Rce8u6K7LN/Um/IxRb+ZbL4sJ3RSDKU2XLCuNLPgW6Q=; b=TwfdDOfAJeF2Z15g2VoD3EapjIGZDQDnGB/2Q4VjUC9LEjnukcs44ZIApsKes0ABgv KGJCUKza/j46YPpD+VZ/9nw1DEoLewYvPruSlsXjwOOlf9Bov0XgcOluHjtKZoHNf0rz auH7d3iDd3GOoAx/0eUf5jk3EZbPr/ipRJtxAKXT0YDh36263O78W7NVz8dU+BKU20IW MvmS2/k2PoEwTv9KqPHhQUCz7az+V5V3Uh3ywIwCoGipX+ehuPacHOsfS0QsVydxyYjm 12U/c4qbdnNWBxPFeUVh0xSp+be952EejLczCR25Ef6Nynwtrd+P8wZWNAdNwKXuL617 gF0Q== X-Gm-Message-State: AOAM533r74+ZJH2kTDanUpaAG20G82QUw3eOjvQ3toxF/oJ9aPUxCeoV VUIQPeAM3GU0FxHPGQhYj+8/cyQbrpS0IY7s X-Received: by 2002:a2e:99c7:: with SMTP id l7mr11895084ljj.126.1639941758286; Sun, 19 Dec 2021 11:22:38 -0800 (PST) Received: from localhost.localdomain (84-217-56-54.customers.ownit.se. [84.217.56.54]) by smtp.gmail.com with ESMTPSA id c36sm191115lfv.193.2021.12.19.11.22.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Dec 2021 11:22:37 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Sun, 19 Dec 2021 20:21:28 +0100 Message-Id: <20211219192134.1296-8-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211219192134.1296-1-dcnieho@gmail.com> References: <20211219192134.1296-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 07/13] 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: L4k7ESyXv0PC Needed to enable programmatic discovery of DirectShow devices Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 80 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 73 insertions(+), 7 deletions(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 0ef3b3d13e..8c257ca8e7 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,6 +241,7 @@ 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); @@ -282,11 +286,39 @@ dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum, // 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 fail1; + + device->device_name = av_strdup(friendly_name); + device->device_description = av_strdup(unique_name); + if (!device->device_name || !device->device_description) + goto fail1; + + // store to device_list output + if (av_reallocp_array(&(*device_list)->devices, + (*device_list)->nb_devices + 1, + sizeof(*(*device_list)->devices)) < 0) + goto fail1; + (*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: + if (device) { + if (device->device_name) + av_freep(&device->device_name); + if (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 Sun Dec 19 19:21: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: 32733 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3695759iog; Sun, 19 Dec 2021 11:23:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJzyxTUIa3OcKKWfs5Uz/ct9jVhyk5zO4SB3OHEy/ahpoadj5uG3TeDn0WgD3qqC7uKTnm0N X-Received: by 2002:a17:906:af69:: with SMTP id os9mr9809793ejb.656.1639941806011; Sun, 19 Dec 2021 11:23:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639941806; cv=none; d=google.com; s=arc-20160816; b=unGEBQLimQFn1pm8UxMyqd3PeWjDHYpnCw0251leJ3GlRkSQwqHa+uwMw7EnAEAE79 UygE2oqE7hJhKpER/zeUfdBvUlDzOkyqSfQ2FhcqNvDN20a1M82CneH8H+oob/KHA2SE FFOiG0ZytFHSuDbrqXdJil1NByNUjwN8LyVrlfgxB6eZ25i6gWQ9CZ3e7hlbrsTFcHIh HkiHIQlDVRXSg5SZZzjOJbgSjiL/U4IAsSvEaZzlUybr9VCYz4BywgcK6PYosKmEC6z6 wF3EnSaz/GE37D9fLy34JiucSw84SPXaE8g8cSDARt7ViTtlhDH8DF2iKlPxSqqDPJgb qEQw== 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=P/Nb+R18r7YiYrlW0B0+ap1kvBaWBeFlqtv4rvWiICE=; b=omfkF6PMzMBgBZwXwL9rAXjKwwtgbITLFfJ/4RN4EmYekso4NtGObMPFthz4kk9Z6m ZSbKb5EgDIn/tt5WTzaj++TY8DIKLSCxKI7TgUr4zE8ou8xxHYqwWSgu/EjXv2rCYKbQ NULeKn4IQIxNxJF6+17M5QTq2kEr2xilZ+npyfh1qSowHciYTi3FeNE4uIK2sLYPew6J LJ9RfpcOUM1ZcOMCw8sFBs5IsKmMPPi2bnEFT7Nr0jvTkENbXgPpDpSp0+jneGg4xXkW zsy77xbej3QyZT5+s7QpHA15gmQj2XAZF6kCC+ao9q8i5RP883ir7W80pGj3UyEJVa5e 4lbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=lPf3I4LU; 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 hc44si8847734ejc.674.2021.12.19.11.23.25; Sun, 19 Dec 2021 11:23:26 -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=lPf3I4LU; 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 D2A0668AE8C; Sun, 19 Dec 2021 21:22:46 +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 9B70368AF86 for ; Sun, 19 Dec 2021 21:22:45 +0200 (EET) Received: by mail-lf1-f54.google.com with SMTP id d38so17056978lfv.0 for ; Sun, 19 Dec 2021 11:22:45 -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=Orw5EJxf/TzKUx8s11toOLkErxFmfQr8jVi7Kb/rKMU=; b=lPf3I4LUMUyT2+qKk72Muy/roHITMyUn5u59b33wBDbomfrSsjwu9x88nqZL0ttpyr 8yge89W4Pr4SKrunWQdpVHeUH98maA6JG84+H0A65l7K5NZmsak4cC/GCGBsX0SDNnIw +WT+aXU2cA3Hs56uNRh5EMU4RcDq7OhCoNi4S7MHen8ksAlbAamg+V1GrsEtxEMMiXkm MhQoKfOYmbERsw20MPPg3hRpDrrX4JGG1Ai91zWXSLUz5JtnHdMl6Mw7jkFveEuu7uFt Q7fZPPiwVNKzWjl6Gl0BEEQOVVKPYzMtOPaO/cb0WshizmUCbGx0wk9zxqEiQrESgGW2 d3EQ== 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=Orw5EJxf/TzKUx8s11toOLkErxFmfQr8jVi7Kb/rKMU=; b=DyFAjCWs+uaEMXTBV03K6slEn/latfzpc0iPz2bEZsqkxemgeqEfcJsswsvbztXTA8 mV4g0+nl0c+pRYjGoUypXnaDxuxiHKRseBfiYxLlWX1x+H7BcG9kY7m8YWX/0JQwKZhF ELZDGK7cb7R2ZJo0L2lh61LXXG8K0I4ct1Of3rWKieKQLYH9vhYkCwV4UjwjTMYJ4gMg DeWJAtT9b4E0syfQHExeoRVqelgv1V4lquJ/WbqneOCsNdSY4Yd87e7xRxV0mj/SsjLy uKxlbstrwv0FK5uZZQik1K0ZVm1QuP8E3DtXb9ziL5MkQXBuQ1uu0RJf5SdrT0hX4WRw ZacQ== X-Gm-Message-State: AOAM533lpFAW2brL1SjYPnPuYTUyXM4P6yV/hsiDr97pGkPOB4+WkD4k NKJAOI+rOaCgEZDws7+fj4Ai04BvmjW0uu0E X-Received: by 2002:a19:8c45:: with SMTP id i5mr12436937lfj.307.1639941764682; Sun, 19 Dec 2021 11:22:44 -0800 (PST) Received: from localhost.localdomain (84-217-56-54.customers.ownit.se. [84.217.56.54]) by smtp.gmail.com with ESMTPSA id u23sm2342037lji.56.2021.12.19.11.22.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Dec 2021 11:22:44 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Sun, 19 Dec 2021 20:21:29 +0100 Message-Id: <20211219192134.1296-9-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211219192134.1296-1-dcnieho@gmail.com> References: <20211219192134.1296-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 08/13] 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: rxmqwrFBUpr2 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 8c257ca8e7..f25537db5c 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -197,6 +197,79 @@ 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 +315,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 +361,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) @@ -306,12 +387,26 @@ 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 && media_types) { + const char* media_type = av_get_media_type_string(media_types[0]); + av_log(NULL, 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(NULL, AV_LOG_INFO, ", %s", media_type ? media_type : "unknown"); + } + av_log(NULL, AV_LOG_INFO, ")"); + } else { + av_log(NULL, AV_LOG_INFO, " (none)"); + } + av_log(avctx, AV_LOG_INFO, "\n"); + av_log(avctx, AV_LOG_INFO, " Alternative name \"%s\"\n", unique_name); } } -fail1: + fail1: + if (media_types) + av_freep(&media_types); if (device) { if (device->device_name) av_freep(&device->device_name); @@ -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 Sun Dec 19 19:21: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: 32734 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3695832iog; Sun, 19 Dec 2021 11:23:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJzZwyqVprHbNN6NaNUxwhz3Dumjvez/TgLstRAEwsCkY7o7PfDmthzrESzURN/Sag8rRs1B X-Received: by 2002:aa7:cfd5:: with SMTP id r21mr12206746edy.98.1639941814884; Sun, 19 Dec 2021 11:23:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639941814; cv=none; d=google.com; s=arc-20160816; b=Q85rMpghja3BGvBQ9jVOCUTM79s/Zv5f3Z+7cUFR/WQqvU/6dO3oFlh0DMMaWwSaRN FW+EROejkY8uJhXBLFp2rHLMaV4P1YqmUlb/oG07HbQgrBhhEYmfejQe37B0or0P5QZm O3A+pYRmmjtIN+U5As/DFwU2vZRicwY9J/OYIAkNoyqYqVmD1JV6hSbIM4nkbJ+nY1uH fZVpMA6Empg4P02fQq0GMpve5BY2FVQXGFgHoRQpJbBgCVLdZwfBzBZjaCBTviAWZexs 46W0fYWkLzcX8lg39rY7DRCG8zFq+xLQoNxrBF9GFoGcgZ3GCzra9aVOj/WXOf3jd8tv iEpw== 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=SCl7vd8MdT/kLxTictHzeBbuzmbrvPwz4mbp5NW0t6c=; b=Wjjih5FeUOD5olgxnQgyLojHAxNQfNgc/7URvmbxqKxyNfnpA02rzrPVjcwp6nwQL0 +mdMRfLVG8ffl4m3cr+zsVmoHFr5etCanyIGCl7lCQYPFNJFno8xKcsbEktAaxUfdjNr dv1mRzyPnn+Db4pcr2DYtfu5xL/bBSmwQSm3Uz8zBxMGGrr42MW/H13wWKKQ/5RKjK4I PLIFhlLwXdwYlHK58cfEJwYBOWwrDlnIAzyVWhE4SacUxJ73HPloFz4mh+cT0njtw50r ZzjFcsiaW6X0huiW7m4A6JhlAQyZzLfx0PXBrn60c6kObM09a77LXGTHegHgMxaCEE2L JeXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=Xhvxnz6Q; 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 d4si459298edy.441.2021.12.19.11.23.34; Sun, 19 Dec 2021 11:23:34 -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=Xhvxnz6Q; 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 8253868AFAB; Sun, 19 Dec 2021 21:22:53 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3A21468A6F9 for ; Sun, 19 Dec 2021 21:22:51 +0200 (EET) Received: by mail-lj1-f178.google.com with SMTP id k23so12519274lje.1 for ; Sun, 19 Dec 2021 11:22:51 -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=yie/XzRqV5tcCF0aofRHOPPC3ODA4BaeMNA0NuLD30k=; b=Xhvxnz6QOwgFav5wiLyWNPejnm+mL/YDS1sZGXDSdQgSt00jh+hz/0ofQvfejD+i3e 0bIENVla+6YbE2/hw9HoSSu1ImncEejQaUS73mwFLj9bGNGKXzeTeuhNDNmCjqhArIU0 qfLIGLI5/qWEzSoBMkJ7Yn7cx2X3aeXps6OqLdzD3cVRCho6ZOuMVmxW48d6gD4RBUQ3 CYqjYsR6XoAahcJeO+lmGiVslTGNtccFIpcmumC0Wyqmx4723K7fqdHKqZsecurrOGoY BK79VqChV5GJKEwyjDwWITmDCftATnBgZRFvAxtX0yNzYlm8r567pNay+PiAnq/nLFQs FmXw== 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=yie/XzRqV5tcCF0aofRHOPPC3ODA4BaeMNA0NuLD30k=; b=nm6W2Rmr1qqVKSy89Q46SR6aGFptxJt8zKLNMOOULTGf5d6FxJqFfCfmRC3lpIQK1R fOFqWrIq0xaQqgcxLMlNVs7wCTnrHJcQWVCllB9V7GMpmb0DnbX/xvi1crSVNxE1BP4o W3RX7kVSVygRL7Hee4JBIstgb7vffnm6jyALRP/7l5NNa7b34Hi2Wb1dxqR/fwa8lm9W z51xlas3CowC50x2F20p3OhrlJMnyJtQB2HfoX5ZS1XiF4uL5W6rQLpk72cOQIc40pI/ 92mxJaDqfPOd6EKcy61GP0a6QNRamOYvAo9fP8wxzxQN6us21tXG5Gc+wcNEN/ykMRVV jKKw== X-Gm-Message-State: AOAM532P3cFmc8Q8e9an6kxtycal/VRLJBXmBSx6xK1dRo1w8qoF5Xfa xYpN08vXbbIos8H5Wwaa2rNoZ+jkTu6C4k5O X-Received: by 2002:a2e:8753:: with SMTP id q19mr11495607ljj.310.1639941771074; Sun, 19 Dec 2021 11:22:51 -0800 (PST) Received: from localhost.localdomain (84-217-56-54.customers.ownit.se. [84.217.56.54]) by smtp.gmail.com with ESMTPSA id u22sm2127360lff.118.2021.12.19.11.22.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Dec 2021 11:22:50 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Sun, 19 Dec 2021 20:21:30 +0100 Message-Id: <20211219192134.1296-10-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211219192134.1296-1-dcnieho@gmail.com> References: <20211219192134.1296-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 09/13] 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: pk6C4YCjmiP2 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 | 2 ++ libavdevice/avdevice.h | 2 ++ libavdevice/version.h | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c index 2ae26ab8e3..712ef1e80c 100644 --- a/libavdevice/avdevice.c +++ b/libavdevice/avdevice.c @@ -157,6 +157,8 @@ void avdevice_free_list_devices(AVDeviceInfoList **device_list) if (dev) { av_freep(&dev->device_name); av_freep(&dev->device_description); + if (dev->media_types) + 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..c549768e12 100644 --- a/libavdevice/version.h +++ b/libavdevice/version.h @@ -28,7 +28,7 @@ #include "libavutil/version.h" #define LIBAVDEVICE_VERSION_MAJOR 59 -#define LIBAVDEVICE_VERSION_MINOR 0 +#define LIBAVDEVICE_VERSION_MINOR 1 #define LIBAVDEVICE_VERSION_MICRO 101 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \ From patchwork Sun Dec 19 19:21: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: 32735 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3695890iog; Sun, 19 Dec 2021 11:23:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJzx4H7aCCZE+bsJ1nQmBhbyIrlM3y5mQKXIu4TC6DJmjg4vCKDL7meTTh1Oyi0gr3P9OmpL X-Received: by 2002:a17:907:728b:: with SMTP id dt11mr9517363ejc.225.1639941823334; Sun, 19 Dec 2021 11:23:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639941823; cv=none; d=google.com; s=arc-20160816; b=A7FvWS0G6bVur6AE+f61pKfnps0WyOwcu6F9NYkFO+TpWg4txAmopLxUUIwJZ4h7oz w85KzgulQKGoFScYCJNTL0z5tNHaDfmNNulsYWJb6QFlkXBxn2uxA29MgJgilPXqt22E FWc9qT0RVUU+1T3Ldd1+CxL3T8S46w1p0rO7JW1NKDF3zK7VERHJCluMqPYmugDMODsW UGnPi1FOsSC9UV/eWN/rDk4jo6UFhUAhfHxa5vr00iOiLbpKPMYI/nQj8PsUTQnycvt8 pyLJXqCoBTnie2ychWfM7cRJiiLzzafGODSCTaJdNhmV1ciHSoRVI9hEGmUI6jV8GXoD 3Fzw== 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=I99bVLkf4f1gGNkFQ7B/WUO2BMay5a+zdoMy9Mk53xU=; b=Zu2T4ab5HxjOHbuCrEaxxFyBmbPFlvt2PWCGxRCSK1wTEuBYy2glLWd7y9gFBRnq0p AH+2676jOaKHR75mgViyjW0LMKapI0hFsNRNaCGj9nWoR8a24aB5Oa1Qxbkj9rSQ8KiV rMqrLLQf2rXEjCTJHDHQcjGPSM8ljAY0eV2NMjNGdRKogkp6Nxv+871Xrz/YK5b2L8iO eZRLIEpOtHzbB/tt7X4e/cPr4/2iG2DLVZKxTyJbKFQLFTyhJ6DvIXy61QkDK0npOuiG iXyhO/1nWH9NepVU4TSffPUvWFI2+OdxFXyohYu5scFAJ+Yc1rMZj6XA0uXDXL02gMCz vgrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=pqJIZd93; 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 gs39si2931807ejc.803.2021.12.19.11.23.43; Sun, 19 Dec 2021 11:23:43 -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=pqJIZd93; 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 A2ED768AFC0; Sun, 19 Dec 2021 21:22:59 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6659B68AEE7 for ; Sun, 19 Dec 2021 21:22:58 +0200 (EET) Received: by mail-lj1-f173.google.com with SMTP id b19so12434318ljr.12 for ; Sun, 19 Dec 2021 11:22:58 -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=BGjJKuN4tAYhDYMwIqjARqL2KwgR7BpzwzoTWujEi0U=; b=pqJIZd93KVdyP2UDibyqechn/NnmScTp1XX9GCPIPqEhNEf+SFJYTT6MtMxM15Kswi XRAZtSlFj2uvfwtMihs7W1YTKCz8sMJMlSwOByd1rJrLPA6TKD9EUrD3H46As0TQZICU wOFj6paAmuwvP+y6EjUoTf7hv1fd6JSDGuwbJN/N+DRrFgYxbBtPUcp6dmgA2yhwnyHZ 4XLLj8MW1ZaHDHQEJrSSxCTAB8LDlo6by+XZWNf2FH8IiDzzMeO00BDG8AXW+3HQ6nbv hO30RN4FzCdnfC/5fu5EyXWPw09HmwoqP+ftI4Ta0JgsqUffE8xX3nE0QoMZAAuciFRA M81w== 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=BGjJKuN4tAYhDYMwIqjARqL2KwgR7BpzwzoTWujEi0U=; b=fmdHhBQGVCP/y9XKaRsbhIKLYV1fTTMTd/AFF6I7CLU0+PxpBkmQ9VWM4MnfH3KHi0 7r19fANtw/Tl/vKM8pm5yW50NuYcjXii5x+cMu6/lH20NawxuIVfnejm+KHMbzUZER7A AZkN1CmET5pJaYxlTHDwcXUyj9LZcIxG4OehL4GVY04cDlXf1Rwq7OmPWoU5pSmMskmI PhXTfqiLBTij7STpjJ1YO0k929Nphyc3GoSMUoV5m0Pveu4aVSdK3v+kr/3McRKZIakP dTkwJkApIwtKa36DX0Ywj8h+ClV+zqi10Pl3qwgaQe8Ba+rT7IAEhYJEMOukzpqlK2X4 YF/Q== X-Gm-Message-State: AOAM533y/UrQgtUDlIO70iMlF1KXUOiLPKRLzzRpPvntIInQxGaCCTQy Rv+bHsHIEME/IAm6DUczfbBdPqnwBJdCujGg X-Received: by 2002:a05:651c:1049:: with SMTP id x9mr11493552ljm.121.1639941777548; Sun, 19 Dec 2021 11:22:57 -0800 (PST) Received: from localhost.localdomain (84-217-56-54.customers.ownit.se. [84.217.56.54]) by smtp.gmail.com with ESMTPSA id d14sm504531lfg.55.2021.12.19.11.22.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Dec 2021 11:22:57 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Sun, 19 Dec 2021 20:21:31 +0100 Message-Id: <20211219192134.1296-11-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211219192134.1296-1-dcnieho@gmail.com> References: <20211219192134.1296-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 10/13] 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: BorzaTW6cPCw 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 f25537db5c..fa3a06c077 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -377,6 +377,11 @@ dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum, if (!device->device_name || !device->device_description) goto fail1; + device->nb_media_types = nb_media_types; + device->media_types = media_types; + nb_media_types = 0; + media_types = NULL; + // store to device_list output if (av_reallocp_array(&(*device_list)->devices, (*device_list)->nb_devices + 1, @@ -412,6 +417,8 @@ dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum, av_freep(&device->device_name); if (device->device_name) av_freep(&device->device_description); + if (device->media_types) + av_freep(&device->media_types); av_free(device); } if (olestr && co_malloc) From patchwork Sun Dec 19 19:21: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: 32736 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3695960iog; Sun, 19 Dec 2021 11:23:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJw//bJyKdsNTCCEYuQWTvyHqDQ/M8L8ZIZ1TvNwaLFRnt81Z7fWRmFBEgQPikBQVY/xOXEj X-Received: by 2002:a17:906:c1c2:: with SMTP id bw2mr10773444ejb.499.1639941832141; Sun, 19 Dec 2021 11:23:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639941832; cv=none; d=google.com; s=arc-20160816; b=rsYCTO1CI/5lLCQ6a0tSXARHkBi+f/FDp0buUFXsW7DrSETF1X57OiKid5+h1YcD+j cd8k3sX5O0bURboTOdKyL8h33bq/fERiEef0geyQ6uFkXO2AqreMrjl/34Spc/CM9WOD 9Q60bKfZMRyJ4+ILf2TFw0JW0NIdae5z6YrSMvOaKKYsD1fBQrKWTroQ8rJ5u/07QWjC h5f7qOG0m9EbWhozufkFJ0Hg7y+xBArOrxUQ6OL8nEcexOz9M71vgi/8wtASEhO0adYR 3MPQfOngFVX10MGStLTj6I781IejlPKMWPFXWdiIcIbxiD8x59VZUxphUz5U/OpDfwkN jYjg== 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=8mq771mErKkZIbk+UMKQ0hXSxOgfULnRUfk0Kz6cxtA=; b=0jwU+jOdWalWHZt4NazGYC3FSay5M/ScPGWp8zS4+ue5URveCPGpwHqO0mpHZ53L/u w1Q73+7wOZBoFSYLdAbFEozJPbSkk5zDsCLAJm5hVERnTRFqfYNRh8H/byjZkriGTtev H37kYbhrx87xMDAfuS19Dt4Q9OY5Fx918ynNogrEUD3jZCzHZ+9N7NkkdZuUvz/W2GWT NeRQciqElvMUtM+XzFQBqRRsQeMWWqJ6EJZe23SpCKCaOnY4KKfdbjXdNe0MtFY7vFPe A2qhUkN0an0FCAry+m3XJVIy36Z18b5g/BOz0BfqV5LWprUlRw3/6jA7LPxzbJzcxxM6 QnUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=UXrKn4af; 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 f1si8482512edx.111.2021.12.19.11.23.51; Sun, 19 Dec 2021 11:23:52 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=UXrKn4af; 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 CB79C68AFCD; Sun, 19 Dec 2021 21:23:11 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0E19B68AF3B for ; Sun, 19 Dec 2021 21:23:05 +0200 (EET) Received: by mail-lj1-f179.google.com with SMTP id u22so12491931lju.7 for ; Sun, 19 Dec 2021 11:23:05 -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=fGYrFMIxG8sslSFASAK9bNYbz/ljJHcgjAn2T+n25bQ=; b=UXrKn4afWb2qZnlGtvT7TE79HbrJXZhb/NqKBoqj2gW5tvSIKm8TzcowYHa5avZ/v1 kapOTGH++G8dZIYp7Gm7r6haEmm/neFKhsK+JaFCC2ogoiqhDMXCS/sK5klEfyH4SnkU 4ogXFxLBvTEcFCwK5ZYcMPi3my2Fr76ynVoI3XInqZi1Li6+CDIvk+/9cwTIxoJ3Ca44 mY8Rm3P2KnOfJPSPx2bdK58N77915FWPLCgUCXSR1Lzg7QM/wzTMCp+aSrh4E+BPHAI1 5p0rMbbMTucKiTe16BmQx9TpKzGWzWieoCdvHMjgdozS8PgkHAsJVaGNYcFsoL2ZFfaL ocjw== 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=fGYrFMIxG8sslSFASAK9bNYbz/ljJHcgjAn2T+n25bQ=; b=ikN9zxvcyr7u3bsZDe6llyeBMmz/mwb14bS0EztVaL03VPQhA8wuOZ0Nj0avDJUtje qd4tcmz/SpGfEWU9ziQDdR8VrS7DjpFdTPqMVD1ICt/s02IqHX9/cfVNMNu6IDPgNof8 s4LwVREPXJobbLdsz8CGKYG++AMSZ+EOB4Cc9x3ceu5o62XggatUYMbzSjzAUMeWZ9SB UhBBq7pRRK5AWgywNtPOxBAFGpNIVWpYvaV20FrssoGZgPoa+04QKScJ3V+IeEE1lBTz j9D6wGXnOGXxu1WnSCYK8/naengYXcj2wY/eSYsbue9RKcnkSIC0yXEqIB10nM9mTUu0 EBNg== X-Gm-Message-State: AOAM532iKEmBHXb6jSEowz/pZGlri4Uliroc2ToJFJIbs6CNkMTb41s8 Wlt73rIZUqjuNF+sJEct/XsFFm16pThJVPM3 X-Received: by 2002:a2e:3a09:: with SMTP id h9mr11769732lja.141.1639941784198; Sun, 19 Dec 2021 11:23:04 -0800 (PST) Received: from localhost.localdomain (84-217-56-54.customers.ownit.se. [84.217.56.54]) by smtp.gmail.com with ESMTPSA id d6sm1295871lfg.233.2021.12.19.11.23.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Dec 2021 11:23:03 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Sun, 19 Dec 2021 20:21:32 +0100 Message-Id: <20211219192134.1296-12-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211219192134.1296-1-dcnieho@gmail.com> References: <20211219192134.1296-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 11/13] 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: y0srTkWNSQQH fftools now print info about what media type(s), if any, are provided by sink and source avdevices. Signed-off-by: Diederick Niehorster --- fftools/cmdutils.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 3c8e5a82cd..7d7dcce2f9 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("%s %s [%s] (", device_list->default_device == i ? "*" : " ", + device->device_name, device->device_description); + if (device->nb_media_types > 0 && device->media_types) { + 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 Sun Dec 19 19:21: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: 32737 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3696047iog; Sun, 19 Dec 2021 11:24:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJzOoN6/8fkwbQpF3E0wLkXoH5O/kg2KkMlVAfXoIy037SiUDAHp/4Y9Fm9ytU5UCmcg8paI X-Received: by 2002:a17:907:764f:: with SMTP id kj15mr9859931ejc.638.1639941841618; Sun, 19 Dec 2021 11:24:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639941841; cv=none; d=google.com; s=arc-20160816; b=nbpCDQ+UCqUc/UoYKyALecUa050d7LJoXPs+evHewkhrxNMRucQna0sq53MD/1sBv/ 44gWdVDxnJn7b4/dKob3mXon29/NwFSoDSJgZN/ddR+/E/7wk9fOPxgZtEUyiu7ZJRYw t03fevLCgIJPudyBGFvBLBDPxnwmS/sFhdvzwoHwmNFfCfEjAYIrvvNxoDq6/nZxJM99 IWXuT0OuhLnYFaZ5vXSxfReCIdun4mbaYVtYn1mw1OGHWJijFnPzFe5f00p7s3crgSR6 AkagP9WnaBExW/Hjj4k9VToR+hIJKTxzeKtR6f7kw5XuPAlP4U4s2z36ToCT7RxIQh/5 E0Cg== 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=VmdmT2kBUva7CBaXThWdkA2b6XoyFBX7UqMAzHUhEZs=; b=atK1yv5dlcWSe2O7cSBRVBuvSHpEu/K0AdgYh61awso1enNSoL0tTmHUX6J5lza5XC vkm/Y/yIqgKh1dMKovhgoV/2jDhDEa96MqFiP1U/+m6nOFnZihJbABvbtEJzy3/xOVSw I5Y8uDjf+fuEZ2Wfc6oMHNIpaDEkMZ8EgKjcyM3828qku2E8J0ShI1sUN8gNnZ6x5BDh 9zbQgnS3O+cwlYAggY2OuCuwVYRdDQIXY2q5AXFIASgirn8ZirN/WpQnTP4fOX5g9Quy Afaedykz+G5pV24NfpaiwF9IOCc2lRudJCAc0CFMEnBnTTPFkd0wQn41CP7jqBkSzg/y hoGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="Ms5oMK/L"; 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 mp32si9693388ejc.776.2021.12.19.11.24.01; Sun, 19 Dec 2021 11:24:01 -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="Ms5oMK/L"; 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 CA88268AFD4; Sun, 19 Dec 2021 21:23:13 +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 A79FD68AFCD for ; Sun, 19 Dec 2021 21:23:11 +0200 (EET) Received: by mail-lj1-f181.google.com with SMTP id i63so12481921lji.3 for ; Sun, 19 Dec 2021 11:23: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=SCerCC5q6rwkbt6350mznQN3VDbI7ouEUK822fajwSk=; b=Ms5oMK/LqhteZwNBqTfN5EwL2pGdn/Lc6EJIBdXiAedMGeys+p/t4A9DeLDC7jN9k1 vW8CTqOKjQ7rVsYmdYEyWyLj5Vxirw0+poSav70QZmeXuWw+g2tJ/SRYP/g1inXQ4Mx+ 6f9WJXRXhbqPIQOG5ny8HzU3XDcn4QCGRV35NfbMOCVBW1iVLSCLddslNZj2anj2uOs5 ctY8G+587ZGIp0iYp6k+Vt8a8B9P9wKTmGKRp7/4Wp/ahCDIFeKeAyGD4mxRGyjopLYC FFA6C3RJ/0qUsXR1bHyBFmTN9p8Z345seIx2JrzyqbKTdDPPRTdgvfclD58pWGnP2CTN e2QQ== 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=SCerCC5q6rwkbt6350mznQN3VDbI7ouEUK822fajwSk=; b=nFBPKzxtypn/kpsviBl2+gg/hXhSxEPE9LKKyFHNSfsnJIq0UsJBZCfXjCWbOYdpMB G6wlxt2N6py4zLZ3q9cgrPOj8VJrZe+S02u/GevdOiocsxpss4QN0y/Q6XCXbZdFQPf5 SgeAmLXjMP92AMNc/80jdqps3AiM2cdjuKmC5R+Pa8vG0uX1VPspZa5+m4SE2cizSOY+ iPyFH8d2iRMRKxifHH8/2QDsA9F6FLtJ/QyPb5C467prsm/h7mHIcJIrLCuFsy+oxBbP LbTxBHfptQGYK902H66rm/52YeyHSty9ffyr5cds+TiWq2U3eGrU9lkrgKRux4dKT4Rs kH+A== X-Gm-Message-State: AOAM530w2oH6J7wxr+4K+5Fj57Gh0jSKNshNiZaah05uoMtNvsQXpz99 /IsfXoKshDkZsE3idk4VZhsnSv4iS1WEHAH/ X-Received: by 2002:a05:651c:555:: with SMTP id q21mr11927750ljp.193.1639941790677; Sun, 19 Dec 2021 11:23:10 -0800 (PST) Received: from localhost.localdomain (84-217-56-54.customers.ownit.se. [84.217.56.54]) by smtp.gmail.com with ESMTPSA id bj11sm2268644ljb.62.2021.12.19.11.23.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Dec 2021 11:23:10 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Sun, 19 Dec 2021 20:21:33 +0100 Message-Id: <20211219192134.1296-13-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211219192134.1296-1-dcnieho@gmail.com> References: <20211219192134.1296-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 12/13] 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: hkG3K9uiwVts Enabled discovering a DirectShow device's color range, space, primaries, transfer characteristics and chroma location, if the device exposes that information. Sets them in the stream's codecpars. Co-authored-by: Valerii Zapodovnikov Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 255 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 254 insertions(+), 1 deletion(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index fa3a06c077..4ad6ae102c 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -29,6 +29,31 @@ #include "libavcodec/raw.h" #include "objidl.h" #include "shlwapi.h" +// NB: technically, we should include dxva.h and use +// DXVA_ExtendedFormat, but that type is not defined in +// the MinGW headers. The DXVA2_ExtendedFormat and the +// contents of its fields is identical to +// DXVA_ExtendedFormat (see https://docs.microsoft.com/en-us/windows/win32/medfound/extended-color-information#color-space-in-media-types) +// and is provided by MinGW as well, so we use that +// instead. NB also that per the Microsoft docs, the +// lowest 8 bits of the structure, i.e. the SampleFormat +// field, contain AMCONTROL_xxx flags instead of sample +// format information, and should thus not be used. +// NB further that various values in the structure's +// fields (e.g. BT.2020 color space) are not provided +// for either of the DXVA structs, but are provided in +// the flags of the corresponding fields of Media Foundation. +// These may be provided by DirectShow devices (e.g. LAVFilters +// does so). So we use those values here too (the equivalence is +// indicated by Microsoft example code: https://docs.microsoft.com/en-us/windows/win32/api/dxva2api/ns-dxva2api-dxva2_videodesc) +typedef DWORD D3DFORMAT; // dxva2api.h header needs these types defined before include apparently in WinSDK (not MinGW). +typedef DWORD D3DPOOL; +#include "dxva2api.h" + +#ifndef AMCONTROL_COLORINFO_PRESENT +// not defined in some versions of MinGW's dvdmedia.h +# define AMCONTROL_COLORINFO_PRESENT 0x00000080 // if set, indicates DXVA color info is present in the upper (24) bits of the dwControlFlags +#endif static enum AVPixelFormat dshow_pixfmt(DWORD biCompression, WORD biBitCount) @@ -54,6 +79,192 @@ static enum AVPixelFormat dshow_pixfmt(DWORD biCompression, WORD biBitCount) return avpriv_find_pix_fmt(avpriv_get_raw_pix_fmt_tags(), biCompression); // all others } +static enum AVColorRange dshow_color_range(DXVA2_ExtendedFormat *fmt_info) +{ + switch (fmt_info->NominalRange) + { + case DXVA2_NominalRange_Unknown: + return AVCOL_RANGE_UNSPECIFIED; + case DXVA2_NominalRange_Normal: // equal to DXVA2_NominalRange_0_255 + return AVCOL_RANGE_JPEG; + case DXVA2_NominalRange_Wide: // equal to DXVA2_NominalRange_16_235 + return AVCOL_RANGE_MPEG; + case DXVA2_NominalRange_48_208: + // not an ffmpeg color range + return AVCOL_RANGE_UNSPECIFIED; + + // values from MediaFoundation SDK (mfobjects.h) + case 4: // MFNominalRange_64_127 + // not an ffmpeg color range + return AVCOL_RANGE_UNSPECIFIED; + + default: + return DXVA2_NominalRange_Unknown; + } +} + +static enum AVColorSpace dshow_color_space(DXVA2_ExtendedFormat *fmt_info) +{ + enum AVColorSpace ret = AVCOL_SPC_UNSPECIFIED; + + switch (fmt_info->VideoTransferMatrix) + { + case DXVA2_VideoTransferMatrix_BT709: + ret = AVCOL_SPC_BT709; + break; + case DXVA2_VideoTransferMatrix_BT601: + ret = AVCOL_SPC_BT470BG; + break; + case DXVA2_VideoTransferMatrix_SMPTE240M: + ret = AVCOL_SPC_SMPTE240M; + break; + + // values from MediaFoundation SDK (mfobjects.h) + case 4: // MFVideoTransferMatrix_BT2020_10 + case 5: // MFVideoTransferMatrix_BT2020_12 + if (fmt_info->VideoTransferFunction==12) // MFVideoTransFunc_2020_const + ret = AVCOL_SPC_BT2020_CL; + else + ret = AVCOL_SPC_BT2020_NCL; + break; + } + + if (ret == AVCOL_SPC_UNSPECIFIED) + { + // if color space not known from transfer matrix, + // fall back to using primaries to guess color space + switch (fmt_info->VideoPrimaries) + { + case DXVA2_VideoPrimaries_BT709: + ret = AVCOL_SPC_BT709; + break; + case DXVA2_VideoPrimaries_BT470_2_SysM: + ret = AVCOL_SPC_FCC; + break; + case DXVA2_VideoPrimaries_BT470_2_SysBG: + case DXVA2_VideoPrimaries_EBU3213: // this is PAL + ret = AVCOL_SPC_BT470BG; + break; + case DXVA2_VideoPrimaries_SMPTE170M: + case DXVA2_VideoPrimaries_SMPTE_C: + ret = AVCOL_SPC_SMPTE170M; + break; + case DXVA2_VideoPrimaries_SMPTE240M: + ret = AVCOL_SPC_SMPTE240M; + break; + } + } + + return ret; +} + +static enum AVColorPrimaries dshow_color_primaries(DXVA2_ExtendedFormat *fmt_info) +{ + switch (fmt_info->VideoPrimaries) + { + case DXVA2_VideoPrimaries_Unknown: + return AVCOL_PRI_UNSPECIFIED; + case DXVA2_VideoPrimaries_reserved: + return AVCOL_PRI_RESERVED; + case DXVA2_VideoPrimaries_BT709: + return AVCOL_PRI_BT709; + case DXVA2_VideoPrimaries_BT470_2_SysM: + return AVCOL_PRI_BT470M; + case DXVA2_VideoPrimaries_BT470_2_SysBG: + case DXVA2_VideoPrimaries_EBU3213: // this is PAL + return AVCOL_PRI_BT470BG; + case DXVA2_VideoPrimaries_SMPTE170M: + case DXVA2_VideoPrimaries_SMPTE_C: + return AVCOL_PRI_SMPTE170M; + case DXVA2_VideoPrimaries_SMPTE240M: + return AVCOL_PRI_SMPTE240M; + + // values from MediaFoundation SDK (mfobjects.h) + case 9: // MFVideoPrimaries_BT2020 + return AVCOL_PRI_BT2020; + case 10: // MFVideoPrimaries_XYZ + return AVCOL_PRI_SMPTE428; + case 11: // MFVideoPrimaries_DCI_P3 + return AVCOL_PRI_SMPTE431; + case 12: // MFVideoPrimaries_ACES (Academy Color Encoding System) + // not an FFmpeg color primary + return AVCOL_PRI_UNSPECIFIED; + + default: + return AVCOL_PRI_UNSPECIFIED; + } +} + +static enum AVColorTransferCharacteristic dshow_color_trc(DXVA2_ExtendedFormat *fmt_info) +{ + switch (fmt_info->VideoTransferFunction) + { + case DXVA2_VideoTransFunc_Unknown: + return AVCOL_TRC_UNSPECIFIED; + case DXVA2_VideoTransFunc_10: + return AVCOL_TRC_LINEAR; + case DXVA2_VideoTransFunc_18: + // not an FFmpeg transfer characteristic + return AVCOL_TRC_UNSPECIFIED; + case DXVA2_VideoTransFunc_20: + // not an FFmpeg transfer characteristic + return AVCOL_TRC_UNSPECIFIED; + case DXVA2_VideoTransFunc_22: + return AVCOL_TRC_GAMMA22; + case DXVA2_VideoTransFunc_709: + return AVCOL_TRC_BT709; + case DXVA2_VideoTransFunc_240M: + return AVCOL_TRC_SMPTE240M; + case DXVA2_VideoTransFunc_sRGB: + return AVCOL_TRC_IEC61966_2_1; + case DXVA2_VideoTransFunc_28: + return AVCOL_TRC_GAMMA28; + + // values from MediaFoundation SDK (mfobjects.h) + case 9: // MFVideoTransFunc_Log_100 + return AVCOL_TRC_LOG; + case 10: // MFVideoTransFunc_Log_316 + return AVCOL_TRC_LOG_SQRT; + case 11: // MFVideoTransFunc_709_sym + // not an FFmpeg transfer characteristic + return AVCOL_TRC_UNSPECIFIED; + case 12: // MFVideoTransFunc_2020_const + case 13: // MFVideoTransFunc_2020 + if (fmt_info->VideoTransferMatrix==5) // MFVideoTransferMatrix_BT2020_12 + return AVCOL_TRC_BT2020_12; + else + return AVCOL_TRC_BT2020_10; + case 14: // MFVideoTransFunc_26 + // not an FFmpeg transfer characteristic + return AVCOL_TRC_UNSPECIFIED; + case 15: // MFVideoTransFunc_2084 + return AVCOL_TRC_SMPTEST2084; + case 16: // MFVideoTransFunc_HLG + return AVCOL_TRC_ARIB_STD_B67; + case 17: // MFVideoTransFunc_10_rel + // not an FFmpeg transfer characteristic? Undocumented also by MS + return AVCOL_TRC_UNSPECIFIED; + + default: + return AVCOL_TRC_UNSPECIFIED; + } +} + +static enum AVChromaLocation dshow_chroma_loc(DXVA2_ExtendedFormat *fmt_info) +{ + if (fmt_info->VideoChromaSubsampling == DXVA2_VideoChromaSubsampling_Cosited) // that is: (DXVA2_VideoChromaSubsampling_Horizontally_Cosited | DXVA2_VideoChromaSubsampling_Vertically_Cosited | DXVA2_VideoChromaSubsampling_Vertically_AlignedChromaPlanes) + return AVCHROMA_LOC_TOPLEFT; + else if (fmt_info->VideoChromaSubsampling == DXVA2_VideoChromaSubsampling_MPEG1) // that is: DXVA2_VideoChromaSubsampling_Vertically_AlignedChromaPlanes + return AVCHROMA_LOC_CENTER; + else if (fmt_info->VideoChromaSubsampling == DXVA2_VideoChromaSubsampling_MPEG2) // that is: (DXVA2_VideoChromaSubsampling_Horizontally_Cosited | DXVA2_VideoChromaSubsampling_Vertically_AlignedChromaPlanes) + return AVCHROMA_LOC_LEFT; + else if (fmt_info->VideoChromaSubsampling == DXVA2_VideoChromaSubsampling_DV_PAL) // that is: (DXVA2_VideoChromaSubsampling_Horizontally_Cosited | DXVA2_VideoChromaSubsampling_Vertically_Cosited) + return AVCHROMA_LOC_TOPLEFT; + else + // unknown + return AVCHROMA_LOC_UNSPECIFIED; +} + static int dshow_read_close(AVFormatContext *s) { @@ -517,6 +728,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, VIDEO_STREAM_CONFIG_CAPS *vcaps = caps; BITMAPINFOHEADER *bih; int64_t *fr; + DXVA2_ExtendedFormat *extended_format_info = NULL; const AVCodecTag *const tags[] = { avformat_get_riff_video_tags(), NULL }; #if DSHOWDEBUG ff_print_VIDEO_STREAM_CONFIG_CAPS(vcaps); @@ -529,6 +741,8 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, VIDEOINFOHEADER2 *v = (void *) type->pbFormat; fr = &v->AvgTimePerFrame; bih = &v->bmiHeader; + if (v->dwControlFlags & AMCONTROL_COLORINFO_PRESENT) + extended_format_info = (DXVA2_ExtendedFormat *) &v->dwControlFlags; } else { goto next; } @@ -545,11 +759,40 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, } else { av_log(avctx, AV_LOG_INFO, " pixel_format=%s", av_get_pix_fmt_name(pix_fmt)); } - av_log(avctx, AV_LOG_INFO, " min s=%ldx%ld fps=%g max s=%ldx%ld fps=%g\n", + av_log(avctx, AV_LOG_INFO, " min s=%ldx%ld fps=%g max s=%ldx%ld fps=%g", vcaps->MinOutputSize.cx, vcaps->MinOutputSize.cy, 1e7 / vcaps->MaxFrameInterval, vcaps->MaxOutputSize.cx, vcaps->MaxOutputSize.cy, 1e7 / vcaps->MinFrameInterval); + if (extended_format_info) { + enum AVColorRange col_range = dshow_color_range(extended_format_info); + enum AVColorSpace col_space = dshow_color_space(extended_format_info); + enum AVColorPrimaries col_prim = dshow_color_primaries(extended_format_info); + enum AVColorTransferCharacteristic col_trc = dshow_color_trc(extended_format_info); + enum AVChromaLocation chroma_loc = dshow_chroma_loc(extended_format_info); + if (col_range != AVCOL_RANGE_UNSPECIFIED || col_space != AVCOL_SPC_UNSPECIFIED || col_prim != AVCOL_PRI_UNSPECIFIED || col_trc != AVCOL_TRC_UNSPECIFIED) { + const char *range = av_color_range_name(col_range); + const char *space = av_color_space_name(col_space); + const char *prim = av_color_primaries_name(col_prim); + const char *trc = av_color_transfer_name(col_trc); + av_log(avctx, AV_LOG_INFO, " (%s, %s/%s/%s", + range ? range : "unknown", + space ? space : "unknown", + prim ? prim : "unknown", + trc ? trc : "unknown"); + if (chroma_loc != AVCHROMA_LOC_UNSPECIFIED) { + const char *chroma = av_chroma_location_name(chroma_loc); + av_log(avctx, AV_LOG_INFO, ", %s", chroma ? chroma : "unknown"); + } + av_log(avctx, AV_LOG_INFO, ")"); + } + else if (chroma_loc != AVCHROMA_LOC_UNSPECIFIED) { + const char *chroma = av_chroma_location_name(chroma_loc); + av_log(avctx, AV_LOG_INFO, "(%s)", chroma ? chroma : "unknown"); + } + } + + av_log(avctx, AV_LOG_INFO, "\n"); continue; } if (ctx->video_codec_id != AV_CODEC_ID_RAWVIDEO) { @@ -1118,6 +1361,7 @@ dshow_add_device(AVFormatContext *avctx, if (devtype == VideoDevice) { BITMAPINFOHEADER *bih = NULL; AVRational time_base; + DXVA2_ExtendedFormat *extended_format_info = NULL; if (IsEqualGUID(&type.formattype, &FORMAT_VideoInfo)) { VIDEOINFOHEADER *v = (void *) type.pbFormat; @@ -1127,6 +1371,8 @@ dshow_add_device(AVFormatContext *avctx, VIDEOINFOHEADER2 *v = (void *) type.pbFormat; time_base = (AVRational) { v->AvgTimePerFrame, 10000000 }; bih = &v->bmiHeader; + if (v->dwControlFlags & AMCONTROL_COLORINFO_PRESENT) + extended_format_info = (DXVA2_ExtendedFormat *) &v->dwControlFlags; } if (!bih) { av_log(avctx, AV_LOG_ERROR, "Could not get media type.\n"); @@ -1145,6 +1391,13 @@ dshow_add_device(AVFormatContext *avctx, av_log(avctx, AV_LOG_DEBUG, "attempt to use full range for HDYC...\n"); par->color_range = AVCOL_RANGE_MPEG; // just in case it needs this... } + if (extended_format_info) { + par->color_range = dshow_color_range(extended_format_info); + par->color_space = dshow_color_space(extended_format_info); + par->color_primaries = dshow_color_primaries(extended_format_info); + par->color_trc = dshow_color_trc(extended_format_info); + par->chroma_location = dshow_chroma_loc(extended_format_info); + } if (par->format == AV_PIX_FMT_NONE) { const AVCodecTag *const tags[] = { avformat_get_riff_video_tags(), NULL }; par->codec_id = av_codec_get_id(tags, bih->biCompression); From patchwork Sun Dec 19 19:21: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: 32738 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3696156iog; Sun, 19 Dec 2021 11:24:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJzVe8d6z0qTK2x7HTQs9GEe0ZIpbWLHE0JcB2L38x7GNtnmePCGxXl0Ib8qPgyDMcD5O/JK X-Received: by 2002:a05:6402:184c:: with SMTP id v12mr12369666edy.154.1639941852088; Sun, 19 Dec 2021 11:24:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639941852; cv=none; d=google.com; s=arc-20160816; b=oogClauP6bpfYG1GcxUYB0JaM20d6fFdK/DkvOZrNDKQr7If7X41c1DVTv4lMTKzMR IjprzGeF6MKNKOJxPUkd24lrD8iaCNs39maxMUBybsjzYY6KLEry0CJ0IJYnrCdDhytU qvXWrwTG2SCVeJqowNl8QTfVXH+CBNutKGvwek9R3hDUXy6FsmvDoXjr0ywP47FbL691 G85HNuRYQoRwFnnVL29XrFgdgCUuSO1MR+WTsDwb/tAVmujO0lKEJRwPFmSWVpQIrTga WomQJbj1B2QHee8qbNRlQRjDJNdT2m/2Bh9KU2Yu8Fz1cv7/rK1IcXAEIwmpIU/PBeJ7 6Ypg== 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=uZH+i2AEjpaYVWllGp+ldXEzxDNvPGEVQkxkRLYeWbk=; b=m8DUCgf8W1D5AoL9zS42i586JJ+5xfTQOZ/RPx0ZVNMoCiKTNvdSkr8YW56YkfbSH1 OrFOG6L1538B2RKeTq98NKqgKyjFCYHGspI4bZde1KIn0GVxLmwlvt4wj21+LeqDmQPN u4mwxs5RhG9Mk6bFK2vjWij2EIkVWACbW0sjbq5gZbkXDG1nQkbAZ9QOYuqvRtYpUB4U jwJGKbcay6ET3iLpMMiBDzc4V9MNUsJyEQjyPGqrW8ff8QyXf5hsT44bpEeauDl6pXD5 7Q9e0/6UDQBlxAbeHGZrvCXsLAI3SsZdmJkJTqcHguOn/eNFmcQR0avtkK2pzS8ySTKW naSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="b/zXzV91"; 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 u6si5380176ejx.559.2021.12.19.11.24.11; Sun, 19 Dec 2021 11:24:12 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="b/zXzV91"; 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 122B668AFDC; Sun, 19 Dec 2021 21:23:23 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8731E68AFDF for ; Sun, 19 Dec 2021 21:23:18 +0200 (EET) Received: by mail-lf1-f43.google.com with SMTP id x21so8714730lfa.5 for ; Sun, 19 Dec 2021 11:23:18 -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=xW42yQ1pfBONlUZ+SLnj/g9IDS9s2+E43DXg9YJqBUg=; b=b/zXzV91llQOCSGn9MDtkBcVeKGXprceFtR3SRzTO7g6R1pCHbWHhCBdu1Xp7BJA03 Gj6hIbPFrhY1bdQHK/otpxDvAQEZSvPVvnMcDuzGPrPtmFX+RW/vzr7+Ew/dqXUfbbfo WMYsrVc2GnRJOHdYokhWCmLSuANCpEmDZ3yubNYx7trFu2yZT2RaFbFoF71epL1+WZlj l9kfVlNebBQapMyPQyucCWuPRSs9Dj/K/49oECCMIqvDQUg3CKve9/ck79RzpjdlPgz4 ZKJ331W25vhiRDujx1fjJMoDghghgOqGoA+OXHZuPshGut9jAn2f3Vfn5ZG34ItAIKxq qmcA== 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=xW42yQ1pfBONlUZ+SLnj/g9IDS9s2+E43DXg9YJqBUg=; b=4L1nh9bhBPmwiNCIYDMsWz58injJCq88m+H4bO/wALFWyMZFgZx/yguKwnjxXjEeeH dAwpvehpb0OnIxzO47p2YNuKfV4zodlXxYXKr4Fu4B3VpHhVBOU6/ifZrM72iNJe1m4q DmMxI4tcBzGBrb5DsG3sxpxS00UeVX9gJtJpxGlwIkoKDPt+UEa66x7f71wXOWiLv5rP IKbNM2TrV+zMDweZdHR4Wj5SHcQCK1+gkGabXzV5pxt7sskdgR2Eq0aXvejAvy6cmqLH H7uf9uFTCpKDGvEgSAU0zL+Sw8COSnuJIdVnOG0KdKYBR4kPrZIGgQZbPPrkZy/FgGZl HfqA== X-Gm-Message-State: AOAM533jKig1MvdN1w4Xtzb/N7NTgMxsOkS79ug9LYl4UnAADtWlSxsc l0McxVsUjaQrPkRwU0iBRPAARkKE/qkR8TSq X-Received: by 2002:a05:6512:3ca3:: with SMTP id h35mr4331848lfv.155.1639941797161; Sun, 19 Dec 2021 11:23:17 -0800 (PST) Received: from localhost.localdomain (84-217-56-54.customers.ownit.se. [84.217.56.54]) by smtp.gmail.com with ESMTPSA id c20sm2337936ljf.37.2021.12.19.11.23.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Dec 2021 11:23:16 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Sun, 19 Dec 2021 20:21:34 +0100 Message-Id: <20211219192134.1296-14-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211219192134.1296-1-dcnieho@gmail.com> References: <20211219192134.1296-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 13/13] 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: hqp9Rk4zQaCd 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 | 469 +++++++++++++++++++++++++++++++------------- 1 file changed, 338 insertions(+), 131 deletions(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 4ad6ae102c..6f2a3ac1ba 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -23,6 +23,7 @@ #include "libavutil/parseutils.h" #include "libavutil/pixdesc.h" #include "libavutil/opt.h" +#include "libavutil/mem.h" #include "libavformat/internal.h" #include "libavformat/riff.h" #include "avdevice.h" @@ -690,9 +691,111 @@ error: return ret; } +static int dshow_should_set_format(AVFormatContext *avctx, enum dshowDeviceType devtype) +{ + struct dshow_ctx *ctx = avctx->priv_data; + + return (devtype == VideoDevice && (ctx->framerate || + (ctx->requested_width && ctx->requested_height) || + ctx->pixel_format != AV_PIX_FMT_NONE || + ctx->video_codec_id != AV_CODEC_ID_RAWVIDEO)) + || (devtype == AudioDevice && (ctx->channels || ctx->sample_size || ctx->sample_rate)); +} + + +struct dshow_format_info { + enum dshowDeviceType devtype; + // video + int64_t framerate; + enum AVPixelFormat pix_fmt; + enum AVCodecID codec_id; + enum AVColorRange col_range; + enum AVColorSpace col_space; + enum AVColorPrimaries col_prim; + enum AVColorTransferCharacteristic col_trc; + enum AVChromaLocation chroma_loc; + int width; + int height; + // audio + int sample_rate; + int sample_size; + int channels; +}; + +// user must av_free the returned pointer +static struct dshow_format_info *dshow_get_format_info(AM_MEDIA_TYPE *type) +{ + struct dshow_format_info *fmt_info = NULL; + BITMAPINFOHEADER *bih; + DXVA2_ExtendedFormat *extended_format_info = NULL; + WAVEFORMATEX *fx; + enum dshowDeviceType devtype; + int64_t framerate; + + if (!type) + return NULL; + + if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo)) { + VIDEOINFOHEADER *v = (void *) type->pbFormat; + framerate = v->AvgTimePerFrame; + bih = &v->bmiHeader; + devtype = VideoDevice; + } else if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo2)) { + VIDEOINFOHEADER2 *v = (void *) type->pbFormat; + devtype = VideoDevice; + framerate = v->AvgTimePerFrame; + bih = &v->bmiHeader; + if (v->dwControlFlags & AMCONTROL_COLORINFO_PRESENT) + extended_format_info = (DXVA2_ExtendedFormat *) &v->dwControlFlags; + } else if (IsEqualGUID(&type->formattype, &FORMAT_WaveFormatEx)) { + fx = (void *) type->pbFormat; + devtype = AudioDevice; + } else { + return NULL; + } + + fmt_info = av_mallocz(sizeof(struct dshow_format_info)); + if (!fmt_info) + return NULL; + // initialize fields where unset is not zero + fmt_info->pix_fmt = AV_PIX_FMT_NONE; + fmt_info->col_space = AVCOL_SPC_UNSPECIFIED; + fmt_info->col_prim = AVCOL_PRI_UNSPECIFIED; + fmt_info->col_trc = AVCOL_TRC_UNSPECIFIED; + // now get info about format + fmt_info->devtype = devtype; + if (devtype == VideoDevice) { + fmt_info->width = bih->biWidth; + fmt_info->height = bih->biHeight; + fmt_info->framerate = framerate; + fmt_info->pix_fmt = dshow_pixfmt(bih->biCompression, bih->biBitCount); + if (fmt_info->pix_fmt == AV_PIX_FMT_NONE) { + const AVCodecTag *const tags[] = { avformat_get_riff_video_tags(), NULL }; + fmt_info->codec_id = av_codec_get_id(tags, bih->biCompression); + } + else + fmt_info->codec_id = AV_CODEC_ID_RAWVIDEO; + + if (extended_format_info) { + fmt_info->col_range = dshow_color_range(extended_format_info); + fmt_info->col_space = dshow_color_space(extended_format_info); + fmt_info->col_prim = dshow_color_primaries(extended_format_info); + fmt_info->col_trc = dshow_color_trc(extended_format_info); + fmt_info->chroma_loc = dshow_chroma_loc(extended_format_info); + } + } else { + fmt_info->sample_rate = fx->nSamplesPerSec; + fmt_info->sample_size = fx->wBitsPerSample; + fmt_info->channels = fx->nChannels; + } + + return fmt_info; +} + /** - * Cycle through available formats using the specified pin, - * try to set parameters specified through AVOptions and if successful + * Cycle through available formats available from the specified pin, + * try to set parameters specified through AVOptions, or the pin's + * default format if no such parameters were set. If successful, * return 1 in *pformat_set. * If pformat_set is NULL, list all pin capabilities. */ @@ -703,9 +806,27 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, struct dshow_ctx *ctx = avctx->priv_data; IAMStreamConfig *config = NULL; AM_MEDIA_TYPE *type = NULL; + AM_MEDIA_TYPE *previous_match_type = NULL; int format_set = 0; void *caps = NULL; int i, n, size, r; + int wait_for_better = 0; + int use_default; + + // format parameters requested by user + // if none are requested by user, the values will below be set to + // those of the default format + // video + enum AVCodecID requested_video_codec_id = ctx->video_codec_id; + enum AVPixelFormat requested_pixel_format = ctx->pixel_format; + int64_t requested_framerate = ctx->framerate ? ((int64_t)ctx->requested_framerate.den * 10000000) + / ctx->requested_framerate.num : 0; + int requested_width = ctx->requested_width; + int requested_height = ctx->requested_height; + // audio + int requested_sample_rate = ctx->sample_rate; + int requested_sample_size = ctx->sample_size; + int requested_channels = ctx->channels; if (IPin_QueryInterface(pin, &IID_IAMStreamConfig, (void **) &config) != S_OK) return; @@ -716,7 +837,83 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, if (!caps) goto end; + /** + * If we should open the device with the default format, + * then: + * 1. check what the format of the default device is, and + * 2. below we iterate all formats till we find a matching + * one, with most info exposed (see comment below). + */ + use_default = !dshow_should_set_format(avctx, devtype); + if (use_default && pformat_set) + { + HRESULT hr; + + // get default + if ((hr = IAMStreamConfig_GetFormat(config, &type)) != S_OK) { + if (hr == E_NOTIMPL || !IsEqualGUID(&type->majortype, devtype==VideoDevice ? &MEDIATYPE_Video : &MEDIATYPE_Audio)) { + // default not available or of wrong type, + // fall back to iterating exposed formats + // until one of the right type is found + IEnumMediaTypes *types = NULL; + if (IPin_EnumMediaTypes(pin, &types) != S_OK) + goto end; + IEnumMediaTypes_Reset(types); + while (IEnumMediaTypes_Next(types, 1, &type, NULL) == S_OK) { + if (IsEqualGUID(&type->majortype, devtype==VideoDevice ? &MEDIATYPE_Video : &MEDIATYPE_Audio)) { + break; + } + CoTaskMemFree(type); + type = NULL; + } + IEnumMediaTypes_Release(types); + } + + if (!type) + // this pin does not expose any formats of the expected type + goto end; + } + + if (type) { + // interrogate default format, so we know what to search for below + struct dshow_format_info *fmt_info = dshow_get_format_info(type); + if (fmt_info) { + if (fmt_info->devtype == VideoDevice) { + requested_video_codec_id = fmt_info->codec_id; + requested_pixel_format = fmt_info->pix_fmt; + requested_framerate = fmt_info->framerate; + requested_width = fmt_info->width; + requested_height = fmt_info->height; + } else { + requested_sample_rate = fmt_info->sample_rate; + requested_sample_size = fmt_info->sample_size; + requested_channels = fmt_info->channels; + } + av_free(fmt_info); // free but don't set to NULL to enable below check + } + + if (type && type->pbFormat) + CoTaskMemFree(type->pbFormat); + CoTaskMemFree(type); + type = NULL; + if (!fmt_info) + // default format somehow invalid, can't continue with this pin + goto end; + fmt_info = NULL; + } + } + + // NB: some devices (e.g. Logitech C920) expose each video format twice: + // both a format containing a VIDEOINFOHEADER and a format containing + // a VIDEOINFOHEADER2. We want, if possible, to select a format with a + // VIDEOINFOHEADER2, as this potentially provides more info about the + // format. So, if in the iteration below we have found a matching format, + // but it is a VIDEOINFOHEADER, keep looking for a matching format that + // exposes contains a VIDEOINFOHEADER2. Fall back to the VIDEOINFOHEADER + // format if no corresponding VIDEOINFOHEADER2 is found when we finish + // iterating. for (i = 0; i < n && !format_set; i++) { + struct dshow_format_info *fmt_info = NULL; r = IAMStreamConfig_GetStreamCaps(config, i, &type, (void *) caps); if (r != S_OK) goto next; @@ -724,106 +921,101 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, ff_print_AM_MEDIA_TYPE(type); #endif + fmt_info = dshow_get_format_info(type); + if (!fmt_info) + goto next; + if (devtype == VideoDevice) { VIDEO_STREAM_CONFIG_CAPS *vcaps = caps; BITMAPINFOHEADER *bih; int64_t *fr; - DXVA2_ExtendedFormat *extended_format_info = NULL; - const AVCodecTag *const tags[] = { avformat_get_riff_video_tags(), NULL }; #if DSHOWDEBUG ff_print_VIDEO_STREAM_CONFIG_CAPS(vcaps); #endif + + if (fmt_info->devtype != VideoDevice) + goto next; + if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo)) { VIDEOINFOHEADER *v = (void *) type->pbFormat; - fr = &v->AvgTimePerFrame; + fr = &v->AvgTimePerFrame; bih = &v->bmiHeader; + wait_for_better = 1; } else if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo2)) { VIDEOINFOHEADER2 *v = (void *) type->pbFormat; - fr = &v->AvgTimePerFrame; + fr = &v->AvgTimePerFrame; bih = &v->bmiHeader; - if (v->dwControlFlags & AMCONTROL_COLORINFO_PRESENT) - extended_format_info = (DXVA2_ExtendedFormat *) &v->dwControlFlags; - } else { - goto next; + wait_for_better = 0; } + if (!pformat_set) { - enum AVPixelFormat pix_fmt = dshow_pixfmt(bih->biCompression, bih->biBitCount); - if (pix_fmt == AV_PIX_FMT_NONE) { - enum AVCodecID codec_id = av_codec_get_id(tags, bih->biCompression); - const AVCodec *codec = avcodec_find_decoder(codec_id); - if (codec_id == AV_CODEC_ID_NONE || !codec) { + if (fmt_info->pix_fmt == AV_PIX_FMT_NONE) { + const AVCodec *codec = avcodec_find_decoder(fmt_info->codec_id); + if (fmt_info->codec_id == AV_CODEC_ID_NONE || !codec) { av_log(avctx, AV_LOG_INFO, " unknown compression type 0x%X", (int) bih->biCompression); } else { av_log(avctx, AV_LOG_INFO, " vcodec=%s", codec->name); } } else { - av_log(avctx, AV_LOG_INFO, " pixel_format=%s", av_get_pix_fmt_name(pix_fmt)); + av_log(avctx, AV_LOG_INFO, " pixel_format=%s", av_get_pix_fmt_name(fmt_info->pix_fmt)); } av_log(avctx, AV_LOG_INFO, " min s=%ldx%ld fps=%g max s=%ldx%ld fps=%g", vcaps->MinOutputSize.cx, vcaps->MinOutputSize.cy, 1e7 / vcaps->MaxFrameInterval, vcaps->MaxOutputSize.cx, vcaps->MaxOutputSize.cy, 1e7 / vcaps->MinFrameInterval); - if (extended_format_info) { - enum AVColorRange col_range = dshow_color_range(extended_format_info); - enum AVColorSpace col_space = dshow_color_space(extended_format_info); - enum AVColorPrimaries col_prim = dshow_color_primaries(extended_format_info); - enum AVColorTransferCharacteristic col_trc = dshow_color_trc(extended_format_info); - enum AVChromaLocation chroma_loc = dshow_chroma_loc(extended_format_info); - if (col_range != AVCOL_RANGE_UNSPECIFIED || col_space != AVCOL_SPC_UNSPECIFIED || col_prim != AVCOL_PRI_UNSPECIFIED || col_trc != AVCOL_TRC_UNSPECIFIED) { - const char *range = av_color_range_name(col_range); - const char *space = av_color_space_name(col_space); - const char *prim = av_color_primaries_name(col_prim); - const char *trc = av_color_transfer_name(col_trc); - av_log(avctx, AV_LOG_INFO, " (%s, %s/%s/%s", - range ? range : "unknown", - space ? space : "unknown", - prim ? prim : "unknown", - trc ? trc : "unknown"); - if (chroma_loc != AVCHROMA_LOC_UNSPECIFIED) { - const char *chroma = av_chroma_location_name(chroma_loc); - av_log(avctx, AV_LOG_INFO, ", %s", chroma ? chroma : "unknown"); - } - av_log(avctx, AV_LOG_INFO, ")"); - } - else if (chroma_loc != AVCHROMA_LOC_UNSPECIFIED) { - const char *chroma = av_chroma_location_name(chroma_loc); - av_log(avctx, AV_LOG_INFO, "(%s)", chroma ? chroma : "unknown"); - } + + const char *chroma = av_chroma_location_name(fmt_info->chroma_loc); + if (fmt_info->col_range != AVCOL_RANGE_UNSPECIFIED || + fmt_info->col_space != AVCOL_SPC_UNSPECIFIED || + fmt_info->col_prim != AVCOL_PRI_UNSPECIFIED || + fmt_info->col_trc != AVCOL_TRC_UNSPECIFIED) { + const char *range = av_color_range_name(fmt_info->col_range); + const char *space = av_color_space_name(fmt_info->col_space); + const char *prim = av_color_primaries_name(fmt_info->col_prim); + const char *trc = av_color_transfer_name(fmt_info->col_trc); + av_log(avctx, AV_LOG_INFO, " (%s, %s/%s/%s", + range ? range : "unknown", + space ? space : "unknown", + prim ? prim : "unknown", + trc ? trc : "unknown"); + if (fmt_info->chroma_loc != AVCHROMA_LOC_UNSPECIFIED) + av_log(avctx, AV_LOG_INFO, ", %s", chroma ? chroma : "unknown"); + av_log(avctx, AV_LOG_INFO, ")"); } + else if (fmt_info->chroma_loc != AVCHROMA_LOC_UNSPECIFIED) + av_log(avctx, AV_LOG_INFO, "(%s)", chroma ? chroma : "unknown"); av_log(avctx, AV_LOG_INFO, "\n"); continue; } - if (ctx->video_codec_id != AV_CODEC_ID_RAWVIDEO) { - if (ctx->video_codec_id != av_codec_get_id(tags, bih->biCompression)) + if (requested_video_codec_id != AV_CODEC_ID_RAWVIDEO) { + if (requested_video_codec_id != fmt_info->codec_id) goto next; } - if (ctx->pixel_format != AV_PIX_FMT_NONE && - ctx->pixel_format != dshow_pixfmt(bih->biCompression, bih->biBitCount)) { + if (requested_pixel_format != AV_PIX_FMT_NONE && + requested_pixel_format != fmt_info->pix_fmt) { goto next; } - if (ctx->framerate) { - int64_t framerate = ((int64_t) ctx->requested_framerate.den*10000000) - / ctx->requested_framerate.num; - if (framerate > vcaps->MaxFrameInterval || - framerate < vcaps->MinFrameInterval) + if (requested_framerate) { + if (requested_framerate > vcaps->MaxFrameInterval || + requested_framerate < vcaps->MinFrameInterval) goto next; - *fr = framerate; + *fr = requested_framerate; } - if (ctx->requested_width && ctx->requested_height) { - if (ctx->requested_width > vcaps->MaxOutputSize.cx || - ctx->requested_width < vcaps->MinOutputSize.cx || - ctx->requested_height > vcaps->MaxOutputSize.cy || - ctx->requested_height < vcaps->MinOutputSize.cy) + if (requested_width && requested_height) { + if (requested_width > vcaps->MaxOutputSize.cx || + requested_width < vcaps->MinOutputSize.cx || + requested_height > vcaps->MaxOutputSize.cy || + requested_height < vcaps->MinOutputSize.cy) goto next; - bih->biWidth = ctx->requested_width; - bih->biHeight = ctx->requested_height; + bih->biWidth = requested_width; + bih->biHeight = requested_height; } } else { WAVEFORMATEX *fx; -#if DSHOWDEBUG AUDIO_STREAM_CONFIG_CAPS *acaps = caps; +#if DSHOWDEBUG ff_print_AUDIO_STREAM_CONFIG_CAPS(acaps); #endif if (IsEqualGUID(&type->formattype, &FORMAT_WaveFormatEx)) { @@ -840,23 +1032,62 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, ); continue; } - if ( - (ctx->sample_rate && ctx->sample_rate != fx->nSamplesPerSec) || - (ctx->sample_size && ctx->sample_size != fx->wBitsPerSample) || - (ctx->channels && ctx->channels != fx->nChannels ) - ) { - goto next; + if (requested_sample_rate) { + if (requested_sample_rate > acaps->MaximumSampleFrequency || + requested_sample_rate < acaps->MinimumSampleFrequency) + goto next; + fx->nSamplesPerSec = requested_sample_rate; + } + if (requested_sample_size) { + if (requested_sample_size > acaps->MaximumBitsPerSample || + requested_sample_size < acaps->MinimumBitsPerSample) + goto next; + fx->wBitsPerSample = requested_sample_size; + } + if (requested_channels) { + if (requested_channels > acaps->MaximumChannels || + requested_channels < acaps->MinimumChannels) + goto next; + fx->nChannels = requested_channels; } } - if (IAMStreamConfig_SetFormat(config, type) != S_OK) - goto next; - format_set = 1; + + // found a matching format. Either apply or store + // for safekeeping if we might maybe find a better + // format with more info attached to it (see comment + // above loop) + if (!wait_for_better) { + if (IAMStreamConfig_SetFormat(config, type) != S_OK) + goto next; + format_set = 1; + } + else if (!previous_match_type) { + // store this matching format for possible later use. + // If we have already found a matching format, ignore it + previous_match_type = type; + type = NULL; + } next: - if (type->pbFormat) + av_freep(&fmt_info); + if (type && type->pbFormat) CoTaskMemFree(type->pbFormat); CoTaskMemFree(type); } + // previously found a matching VIDEOINFOHEADER format and stored + // it for safe keeping. Searching further for a matching + // VIDEOINFOHEADER2 format yielded nothing. So set the pin's + // format based on the VIDEOINFOHEADER format. + // NB: this never applies to an audio format because + // previous_match_type always NULL in that case + if (!format_set && previous_match_type) { + if (IAMStreamConfig_SetFormat(config, previous_match_type) == S_OK) + format_set = 1; + } + end: + if (previous_match_type && previous_match_type->pbFormat) + CoTaskMemFree(previous_match_type->pbFormat); + CoTaskMemFree(previous_match_type); IAMStreamConfig_Release(config); av_free(caps); if (pformat_set) @@ -975,11 +1206,7 @@ dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype, const char *devtypename = (devtype == VideoDevice) ? "video" : "audio only"; const char *sourcetypename = (sourcetype == VideoSourceDevice) ? "video" : "audio"; - int set_format = (devtype == VideoDevice && (ctx->framerate || - (ctx->requested_width && ctx->requested_height) || - ctx->pixel_format != AV_PIX_FMT_NONE || - ctx->video_codec_id != AV_CODEC_ID_RAWVIDEO)) - || (devtype == AudioDevice && (ctx->channels || ctx->sample_rate || ctx->sample_size)); + int set_format = dshow_should_set_format(avctx, devtype); int format_set = 0; int should_show_properties = (devtype == VideoDevice) ? ctx->show_video_device_dialog : ctx->show_audio_device_dialog; @@ -999,9 +1226,7 @@ dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype, while (!device_pin && IEnumPins_Next(pins, 1, &pin, NULL) == S_OK) { IKsPropertySet *p = NULL; - IEnumMediaTypes *types = NULL; PIN_INFO info = {0}; - AM_MEDIA_TYPE *type; GUID category; DWORD r2; char *name_buf = NULL; @@ -1044,35 +1269,24 @@ dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype, } } - if (set_format) { - dshow_cycle_formats(avctx, devtype, pin, &format_set); - if (!format_set) { - goto next; - } + // will either try to find format matching options supplied by user + // or try to open default format. Successful if returns with format_set==1 + dshow_cycle_formats(avctx, devtype, pin, &format_set); + if (!format_set) { + goto next; } + if (devtype == AudioDevice && ctx->audio_buffer_size) { if (dshow_set_audio_buffer_size(avctx, pin) < 0) { av_log(avctx, AV_LOG_ERROR, "unable to set audio buffer size %d to pin, using pin anyway...", ctx->audio_buffer_size); } } - if (IPin_EnumMediaTypes(pin, &types) != S_OK) - goto next; - - IEnumMediaTypes_Reset(types); - /* in case format_set was not called, just verify the majortype */ - while (!device_pin && IEnumMediaTypes_Next(types, 1, &type, NULL) == S_OK) { - if (IsEqualGUID(&type->majortype, mediatype[devtype])) { - device_pin = pin; - av_log(avctx, AV_LOG_DEBUG, "Selecting pin %s on %s\n", name_buf, devtypename); - goto next; - } - CoTaskMemFree(type); + if (format_set) { + device_pin = pin; + av_log(avctx, AV_LOG_DEBUG, "Selecting pin %s on %s\n", name_buf, devtypename); } - next: - if (types) - IEnumMediaTypes_Release(types); if (p) IKsPropertySet_Release(p); if (device_pin != pin) @@ -1342,6 +1556,7 @@ dshow_add_device(AVFormatContext *avctx, AM_MEDIA_TYPE type; AVCodecParameters *par; AVStream *st; + struct dshow_format_info *fmt_info = NULL; int ret = AVERROR(EIO); type.pbFormat = NULL; @@ -1356,12 +1571,14 @@ 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) + goto error; par = st->codecpar; if (devtype == VideoDevice) { BITMAPINFOHEADER *bih = NULL; AVRational time_base; - DXVA2_ExtendedFormat *extended_format_info = NULL; if (IsEqualGUID(&type.formattype, &FORMAT_VideoInfo)) { VIDEOINFOHEADER *v = (void *) type.pbFormat; @@ -1371,8 +1588,6 @@ dshow_add_device(AVFormatContext *avctx, VIDEOINFOHEADER2 *v = (void *) type.pbFormat; time_base = (AVRational) { v->AvgTimePerFrame, 10000000 }; bih = &v->bmiHeader; - if (v->dwControlFlags & AMCONTROL_COLORINFO_PRESENT) - extended_format_info = (DXVA2_ExtendedFormat *) &v->dwControlFlags; } if (!bih) { av_log(avctx, AV_LOG_ERROR, "Could not get media type.\n"); @@ -1383,33 +1598,21 @@ dshow_add_device(AVFormatContext *avctx, st->r_frame_rate = av_inv_q(time_base); par->codec_type = AVMEDIA_TYPE_VIDEO; - par->width = bih->biWidth; - par->height = bih->biHeight; + par->width = fmt_info->width; + par->height = fmt_info->height; par->codec_tag = bih->biCompression; - par->format = dshow_pixfmt(bih->biCompression, bih->biBitCount); + par->format = fmt_info->pix_fmt; if (bih->biCompression == MKTAG('H', 'D', 'Y', 'C')) { av_log(avctx, AV_LOG_DEBUG, "attempt to use full range for HDYC...\n"); par->color_range = AVCOL_RANGE_MPEG; // just in case it needs this... } - if (extended_format_info) { - par->color_range = dshow_color_range(extended_format_info); - par->color_space = dshow_color_space(extended_format_info); - par->color_primaries = dshow_color_primaries(extended_format_info); - par->color_trc = dshow_color_trc(extended_format_info); - par->chroma_location = dshow_chroma_loc(extended_format_info); - } - if (par->format == AV_PIX_FMT_NONE) { - const AVCodecTag *const tags[] = { avformat_get_riff_video_tags(), NULL }; - par->codec_id = av_codec_get_id(tags, bih->biCompression); - if (par->codec_id == AV_CODEC_ID_NONE) { - av_log(avctx, AV_LOG_ERROR, "Unknown compression type. " - "Please report type 0x%X.\n", (int) bih->biCompression); - ret = AVERROR_PATCHWELCOME; - goto error; - } - par->bits_per_coded_sample = bih->biBitCount; - } else { - par->codec_id = AV_CODEC_ID_RAWVIDEO; + par->color_range = fmt_info->col_range; + par->color_space = fmt_info->col_space; + par->color_primaries = fmt_info->col_prim; + par->color_trc = fmt_info->col_trc; + par->chroma_location = fmt_info->chroma_loc; + par->codec_id = fmt_info->codec_id; + if (par->codec_id == AV_CODEC_ID_RAWVIDEO) { if (bih->biCompression == BI_RGB || bih->biCompression == BI_BITFIELDS) { par->bits_per_coded_sample = bih->biBitCount; if (par->height < 0) { @@ -1422,23 +1625,26 @@ dshow_add_device(AVFormatContext *avctx, } } } + } else { + if (par->codec_id == AV_CODEC_ID_NONE) { + av_log(avctx, AV_LOG_ERROR, "Unknown compression type. " + "Please report type 0x%X.\n", (int) bih->biCompression); + ret = AVERROR_PATCHWELCOME; + goto error; + } + par->bits_per_coded_sample = bih->biBitCount; } } else { - WAVEFORMATEX *fx = NULL; - - if (IsEqualGUID(&type.formattype, &FORMAT_WaveFormatEx)) { - fx = (void *) type.pbFormat; - } - if (!fx) { + if (!IsEqualGUID(&type.formattype, &FORMAT_WaveFormatEx)) { av_log(avctx, AV_LOG_ERROR, "Could not get media type.\n"); goto error; } par->codec_type = AVMEDIA_TYPE_AUDIO; - par->format = sample_fmt_bits_per_sample(fx->wBitsPerSample); + par->format = sample_fmt_bits_per_sample(fmt_info->sample_size); par->codec_id = waveform_codec_id(par->format); - par->sample_rate = fx->nSamplesPerSec; - par->channels = fx->nChannels; + par->sample_rate = fmt_info->sample_rate; + par->channels = fmt_info->channels; } avpriv_set_pts_info(st, 64, 1, 10000000); @@ -1446,6 +1652,7 @@ dshow_add_device(AVFormatContext *avctx, ret = 0; error: + av_freep(&fmt_info); if (type.pbFormat) CoTaskMemFree(type.pbFormat); return ret;