From patchwork Fri Jun 11 20:30: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: 28207 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp762297iol; Fri, 11 Jun 2021 13:32:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZNXO1hfCD9yW+u3nygluXLIkmrN7/IxCYRKw05jMNz+5lpOiUo8u+/dKDW9XSbXMvbFhu X-Received: by 2002:a50:d6c6:: with SMTP id l6mr5593195edj.3.1623443531344; Fri, 11 Jun 2021 13:32:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443531; cv=none; d=google.com; s=arc-20160816; b=uFlEFBbNHlkhErMrqkSl8HFln/YMg+vJ16YomL/7uhdCk1kBZIWr6d6orV/vy77dyF B4CaCOUFJ94ioVxbXYdtBVygLniymd2Wv/ADCteXd78JOQa5tIXUV1BptjNZ6J82HdZn 3BRoDtxCAl2tfm1W5Kf0aP2DkDUcVtltC6PWA9Dkd11Qk5tBtxfbt57LSLLSikT/12bS sqD7uT6Z/+MOsitCwcD55xXOYFsBg0c1ldbUlwkJAFGKjKUgkrzt+HxNta3htzpr6Q79 dFV/T144KbcwkPEw8kAp6CIJuZ5F2In0pbBZF/8K9jUKxV95yfCv6inreLX/OjRUFLLO BiGg== 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=kYAZYOZtF9xhwIuqeDYP34z4yQk0BzB2rqBgCkwN0Tk=; b=HoiJfyrjcrUvyNOxNhlr5lOcERiiGeuoYXpobEtf32WnDikGwdFTNXR7UNspoCsZD8 DWKqGFJHdmaBnUMuTUAMegg9Vxn0CNwIsC+hNtTYlA1c5jeXSTJnWmWkzej+aKzn8DQA 5Sr79ZYSZoXcX4FYbmyjnJQM88Z1cIFM+ravBvaQsuHxTvcotqSlHjWtmw76Iz3qNjpw 1K0TWWB/ePOxD4el94E5NvNbG3Ax0s6ZJ71D68B8QWIBrE2kQ1HjmhOA+12Up23NkwAD ImArBwa6dpLpglNm3ONLhS39IGzmMypbKcAxYCOlNgFUf3L1Cz4q1eBuV1ZbBWVlLRPX YvKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=oOvHHRk3; 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 h93si6210942edd.584.2021.06.11.13.32.05; Fri, 11 Jun 2021 13:32:11 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=oOvHHRk3; 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 312A86809E6; Fri, 11 Jun 2021 23:32:02 +0300 (EEST) 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 559C76807AA for ; Fri, 11 Jun 2021 23:31:56 +0300 (EEST) Received: by mail-lf1-f52.google.com with SMTP id f30so10381614lfj.1 for ; Fri, 11 Jun 2021 13:31:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SbExGgeUT35U6RmVJmhZABx69VMLgDlfh0lckw2KIEE=; b=oOvHHRk3mfuLiFhs45N0OPRIwwpvEmlJcC2tVJDAC7Cly7F7C/lPgiLeVmZVcRsjDW eUvB32DkJRQpmg6CMoIQxoBzykKBdUgvoZdRFJZjNQfSBh5vTTh5YA4c91VyRF5U0N7E zjGBJ1ty0ClrsuoC8NKAuPl/eU/O6ngDITgo8qbQgp07wlUfN/au2piXeloUuAEubZBC gHUc/kQenpRYLdFowk5pI2OMlwQKHgyrRyqIxHUE/4svfQDpCyR3F+NOpIjduWY5jgG6 OoYesF4KTbJutdUSrPCYEVyO9ZHcbhVAEyt8k5XAVmFSMangp9P0k3b1XRtXIA5v8Wke xXeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SbExGgeUT35U6RmVJmhZABx69VMLgDlfh0lckw2KIEE=; b=TGwuFG4gjlnH/1JjDc26qyS5h2WoIlgOLea8xMNSSNrIHA0Qp5fxGQC8QHowEeuScX NuUzKwicdY10ZpzaS556KUuTLqtwo3p2akisJ3E7jy4ckOcxCpl/8igvgakku8z0iS2T irbrPQqdOBlKKxlijlXOutVho5/vKm15HALJAXRVRaDT8JTDSoyO2Y5G0Hm8ze7PPSvv dAyykpBUAFHB9DxhzDp8ioclgYfky92lMabzgxNoGikv/LeUeReV7FrkRUrmbrI6LwOT X8OvUZLlKMvwe50UNU6IDWcKWGy9LejSC/OtTKPav1QFy6lFzU/A4mDKygby3d8iXb4z XVPw== X-Gm-Message-State: AOAM532O4tnSdLpPSYz+y9C7cde2pymzxg8klJNr5gUdpErIAV8+Qk/Y qkDr60X4JTaRiMo8R39BP02bM+AC6FmRiA== X-Received: by 2002:a19:645e:: with SMTP id b30mr3650221lfj.577.1623443515366; Fri, 11 Jun 2021 13:31:55 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id o21sm684885lfr.253.2021.06.11.13.31.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:31:54 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:32 +0200 Message-Id: <20210611203104.1692-2-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 01/33] 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: igVi/AI538EN 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 | 15 ++++++++------- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 8d0a6fcc09..2e9f9ddf3f 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -1317,6 +1317,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..ab0ead8041 100644 --- a/libavdevice/dshow_pin.c +++ b/libavdevice/dshow_pin.c @@ -309,12 +309,16 @@ 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) { - /* PTS from video devices is unreliable. */ - IReferenceClock_GetTime(clock, &curtime); + if (devtype == VideoDevice && !ctx->use_video_device_timestamps) { + /* PTS from video devices is unreliable. */ + IReferenceClock_GetTime(clock, &curtime); } else { IMediaSample_GetTime(sample, &curtime, &dummy); if(curtime > 400000000000000000LL) { @@ -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 Fri Jun 11 20:30: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: 28208 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp762465iol; Fri, 11 Jun 2021 13:32:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylCM56CkAuLBjT7Km/6Ken3SfiitZRFHg/WsRqz4QWYWXLgD+9xNT3RWju3JMs1sjU/Z0s X-Received: by 2002:a17:907:1de6:: with SMTP id og38mr5258374ejc.471.1623443544557; Fri, 11 Jun 2021 13:32:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443544; cv=none; d=google.com; s=arc-20160816; b=eiApPuKIIiulBDI0FaYAkrFgncDnePb+kv2vqILi4ul0Nv7d9QcbNrSZe5xGG5B78V K2Z7NJoH9wuWvwsELwxfQB0KDEnQR+vSeG7vNGvhMbenPJWKgj1wMVlXwPSE/DAVkvi5 DY/B9xrL1p3Fca9oZypZqjSRvbaqwd7/ErZP6qU1iGkmOZqnXCR1j71Uk7fecu2ttrR6 Q9202VrMXDgq4zQSH2VSPU+i8J/A98kVA+6TxW2c6kA/ab47CgPFplhpN9Lx3qFCQ0jh hK00KbJf1bsoB1RZFvSxPrAuGWTN6oCpY3Q5xTtimbPHYtEekGkY8fBY5+rdo3NacdNx OfFw== 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=y89IWCDtNEdg82+DPT3uAlsVAZPx1zB1cADW/vCIeUI=; b=b1K16QTnLwe3cv8JWoWuvlSb/Q54g9T5dZKDIksv5ALMAdPNH/+mLTrLtf7eFZR+tO vlqAlFbhf61VTo992RAlU0wIaVAJNvuC1n9qN3w/NFNfVUJ558S910JGPHAsIJU2ZHcf nhQzVRM80tX0Un9qJutPxLLTPf2FFxLuHgydJ00/WTGEKwOV7NwEdFFMrE/DcYh9rHbh PIBrHkVOKPJlkj+UlpF+5fz8iD3e1qO+U/HJ0vc3A3TcRZxUVQnyw5BNC/lnzz+hyaoR kqijjIjNEM2TOug2sj3Rxze5/5CRDyywKm0zgtx1uOwqQ7hUw0B59q/EhR6q97rOL3ry kajw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=t5JCdXGG; 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 f1si5892528edt.327.2021.06.11.13.32.22; Fri, 11 Jun 2021 13:32:24 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=t5JCdXGG; 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 812A5680B24; Fri, 11 Jun 2021 23:32:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3DEE1680BD5 for ; Fri, 11 Jun 2021 23:32:13 +0300 (EEST) Received: by mail-lf1-f42.google.com with SMTP id v22so10376891lfa.3 for ; Fri, 11 Jun 2021 13:32:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mAEjrl7hEHQBcrq0yJPFwd642liMEhpSRVnsQ9bOCMY=; b=t5JCdXGGG880AeiZtS66TqKePghumVxI6ZKu+QU30Xco+iXgEEkKU/G7jU6rAnrrtq eFpXCO1KGc8pnhx+TutFDylbWANV/SCBXcVokA3puBhsgCNlEQWcx6Nfh1m550dpDGvf 1yUl3mqJwDXPrCn5/jzmJDG8GjsprZCYBUAgyKupD7cl1UwM7uQ/jhikc4ciXgk2ZvtQ MI2KzUtjKbtACKOc7qzngqo5lhCK920ofodNossBPfOzHnigiNqyLNNeBKZFAqPzgSm8 WKxxcr+gnkmm7yaXTwJAtvypBdU0gCSK7a8iLLfXGhA0EunkTwQCtJ4QxUhMRnHqKFlW 05aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mAEjrl7hEHQBcrq0yJPFwd642liMEhpSRVnsQ9bOCMY=; b=fS6Per+TrbN0hPrPgnPvOCFQrblwfJ8yr27kK4aKhpxr2e+lItDzRADWdjK3J6KUG2 VEAOndIEFhryY9dQsb6zMOQU/Z3az0fXzOC4ClUTpy0IVAQNHJNtsre0iJLuHgkmFqOf 7BRpXZv2jBoT3rcuHqNzU16QBtTsdwsefmuQurs4zLC3b/59Lrr2nJoqCKANv7wULdpt ux9k8sl01Hfn694hA6O0Ecvn9yF/p8qP4gZA+/rk+r3GcdXWIx9DMiC5eZOnCWm0j1T2 GGS/3Pnu7ep38lnvjIKQDq/rgHJOXfkcIdEos4Mclvarl5/HBsa3Ae8TfFPFkzhChpQh jryg== X-Gm-Message-State: AOAM5312cwp+OogAzgvLJdrkinTSg4r6JoFqVxGoO881M39bkO5Bk/s5 ey5wltuQz2uslx9YUM1iJY2sJtVdSd8Acw== X-Received: by 2002:a05:6512:3694:: with SMTP id d20mr3887311lfs.184.1623443532275; Fri, 11 Jun 2021 13:32:12 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id s19sm845064lji.79.2021.06.11.13.32.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:32:11 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:33 +0200 Message-Id: <20210611203104.1692-3-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 02/33] 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: ZPADTOuIEPL3 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 b377924c2f..685b1357a6 100644 --- a/doc/indevs.texi +++ b/doc/indevs.texi @@ -611,6 +611,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 Fri Jun 11 20:30: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: 28231 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp767369iol; Fri, 11 Jun 2021 13:40:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7MvMQGEQo3IAJ4AGKPeo+Vj0Mtp6WoBNkoiNuSq8nPlJoWGBG7YFavzOWSHLqULBUpHYC X-Received: by 2002:a17:906:5289:: with SMTP id c9mr5232435ejm.342.1623444043810; Fri, 11 Jun 2021 13:40:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623444043; cv=none; d=google.com; s=arc-20160816; b=tuKVVdYdiIOpsWVAdmep4Tw25Xlw20GrUvKKgyIaftfZ7jLGciNX8Rk9EIyCNcbaYX 1MBS8lS1/M380eVAMAFCvGiWYXKR1bIkEOUIAV4cNCC3AfkD6cqfqbsSXjdCXn6UoBly jQcUvgSYqAml3LlLr2kZr5BjJs92ifaZkFsARLcmP7vSwftfTMhgSdOwZwpB/SWpzfp1 KwMqdcGza4AApXhtkfyFykSUPmgSDgTze0xqO1Kyeb5RbF3AWDoruB/w7N9Xu/pR6ogZ HrT9rSegn4ovPRf3oCepxQOG0gBPczTfEmHzkZzFYrHEgqzwXwSHcT20dRFG0R1p3O2R K4zg== 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=77meImzbdS3Wg123h/r5CNEltt37/ZM5vmYIz1Fu0zM=; b=Zr24R14mgVwDp/rqfGqZEbGxDldkGoD17KvwS4Dkn46Z4mf53ZYZuqZ4rMkwZhM/Fg AKk3ouxMjnI3I/gFlADP2HYwWg7bwz3bIIeI6MKbXa0D0wQz6+RvCGm8ktpZiMgnkNwD KZLgV2XxiUMMnMoqg804cQT8W+DxjPoE9Hx7FFnXT/wlYnXBH/E7wSvzt0er1yIa4DZX 3UrMx4IrVxzXdFfRMUdfMPk7YerLEiQ3f+c5YaxdPlxGqb3uCPITkSPS9lrCnn1lMhQF HRcrRK07OZFCBJc5YHkrKcj8Ya4RgBYAoBZ+sPFK6o+GkScBRbvGGfYOtMmKqM7S3BGL PNRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=WRIurASa; 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 t6si5732092edw.27.2021.06.11.13.40.43; Fri, 11 Jun 2021 13:40:43 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=WRIurASa; 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 7DBD4680204; Fri, 11 Jun 2021 23:40:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9A47368993B for ; Fri, 11 Jun 2021 23:40:32 +0300 (EEST) Received: by mail-wr1-f44.google.com with SMTP id n7so1198275wri.3 for ; Fri, 11 Jun 2021 13:40:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=B7Y54CkZrOXtX1X35Gx+Xt+gMNhJm6+AeCVPasFc/hs=; b=WRIurASaXnpf/OT/QzYTuJtijNL7NRj9Ok4FB39P+G0dJZ68bKhjHFQgxXi0zJThGK HU7LJqiaDQSjK1dpCEtn9v3t2HOCtSjkEh7O3AqWedyqxDTApnaZOS9C/7p4ZjRGfcAD Gfa7IYAYSKKO9Te8e9NALu8NAf97mLJFAho0X3pIJCcS0NFYY2G2/NeGqzc6UqepOG0w AOjJzG3S4PLI4iftMZmVicwXMaBKi9sbJ1MZpqBKI+13O+EdCD9mMerFHi9HaP2Kg4Kq IvYHjqo7iqAK+lOtAJ+EbZ04s4Q3GzrfA8arLZDGQzYmUpXdknVRspzyYkHMEbcy0EC/ 1jUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=B7Y54CkZrOXtX1X35Gx+Xt+gMNhJm6+AeCVPasFc/hs=; b=g+4HXe6SFlCnnSO57jvi/wXmWB2w7pfOILN8CbIEGre7Age0pGLgFVrL49moreCv1j IFKCWKs2SNgl7rnqfaP7H5MRMnnmtby01/t5CU2jQ7FMToq3O1+g7rzKTxXFYWsCNUId pOKbVOU85eEgc2hP7oCmHZ+Ntjvyk+qYhGc01aEeHmdcuToL7V2ZWwH49xpqrOP8649o d9Uc7L4/yDHrl2ZpqZsgGOLkpBmdaFVawBPYNyI5q+Z1e5cK08VV8zmMH9KqL3GjRWYT /A68hv07TWmnPP1X7HETG3MhUOQUkTwCOYYU0x7KqxaLa/xOxXlnJhgIeoY9DEcBZtJJ jjLA== X-Gm-Message-State: AOAM5319BieLB5TqKvV4/ulrdcEP09vaWj2hvtjzKfkNhfOU3XVA6lNx QoePe5hbsPbUAZ0Xg1cMwzafJww4oxETjw== X-Received: by 2002:a2e:9007:: with SMTP id h7mr4372113ljg.390.1623443549247; Fri, 11 Jun 2021 13:32:29 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id u24sm684691lfc.162.2021.06.11.13.32.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:32:28 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:34 +0200 Message-Id: <20210611203104.1692-4-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 03/33] 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: Gtv1XTLbYIq5 No need to query twice, use value we've already unconditionally got. Improve variable names Signed-off-by: Diederick Niehorster --- libavdevice/dshow_pin.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/libavdevice/dshow_pin.c b/libavdevice/dshow_pin.c index ab0ead8041..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); + /* PTS from video devices is unreliable. */ + 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 Fri Jun 11 20:30:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 28210 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp762800iol; Fri, 11 Jun 2021 13:32:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwu5hv+q+fX0jo7kBwohrnuFKeLl3CbxaDg/LZt5VfLQkmJjsNJUwVryn2s8fmbhi12KIW X-Received: by 2002:a17:906:b24a:: with SMTP id ce10mr5273875ejb.83.1623443576075; Fri, 11 Jun 2021 13:32:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443576; cv=none; d=google.com; s=arc-20160816; b=epVLp8tgENsbP8SV5sV89Za7fqym2sHarIL+ydR52DjLbSVTpy0M6NpwaVPh+e4tvx oTzyzptPK4xRnr/90TRajl/X9FeheOQjYpmgft8plpJtdn6lXgZgBUMHs51nS2kmIu0O qQ89c95jIReI23biJt72kquVR72efYj4RUPDVgQ2cr86HEZaBQbZk4bh/bib9Ocz923i tPjpJLF0A0fLDUa3OKQ3zSNZEbdowh/OuXP1eYpdQbhhpQKcb3vQig6jmuCRm+E+1nxv Ar8GoVCm4HeRN4uo9eYtkQ1lIoW/TBWxk2lX6QtvlJzmE7Oz0aWPy9YyXWzdnBEYWAPA oDNQ== 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=1GNbKic4/hTLN8/M2EuCDzyPjx1FXZ2iUnm51nzwk7Y=; b=WH2kA0lEi/ZjWxliknKFz7ClTJNR7Ga+/pm5YKjZW2mZzF3E3wudRks2thtdy9Y4xJ 4wZCm0yz6AFoOfXtH8kXutt7xcz7881H8hIrJE4M80C3FOvROCpuw1y0uQc0pft9lwOJ Dxlqv2uqPBut07T5hVgOSxAVKlH99aMImny7h2Z1mxBUxqqkbL6P+nArah456G64Izcs 1q/uNCLwftLbRC6VNyhgsdjmJLxef8keCebn4JTQwOaT5PGhmUKBxXNFbfA0bO85JLSE o84SsL/VORU45qLyGfTfzMyLqqu4Y+sxwB7PdjAPq4vLRB1dj7g0elrDAfpymV/DuZ0Z bupQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=OfRfbW1s; 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 os28si6808038ejb.695.2021.06.11.13.32.55; Fri, 11 Jun 2021 13:32:56 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=OfRfbW1s; 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 9077E687F27; Fri, 11 Jun 2021 23:32:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6EF486809E6 for ; Fri, 11 Jun 2021 23:32:47 +0300 (EEST) Received: by mail-lj1-f172.google.com with SMTP id 131so11323539ljj.3 for ; Fri, 11 Jun 2021 13:32:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=adnbYYXt3y1rSvkqYNUbMSM3zzoFE+m4ORetAFLtEoA=; b=OfRfbW1smin6hQWURr2aaVXwaIYMsJa/J71OWLFZRsStezJ6yaJxU2sO+obfLNLBw2 PAMTIoE/kaSlh9SadgBdRxdPOtiV3tSDAlDZYp8J93cVLjbCFL9C7FJ6yMg4rzcnqdAs 4FVbdZteYwZfRXqfjfYriFksxPw+1Emucl0pHgmieRPoya9OHuq+S3e7fjvw3tMIYya+ qhMQSvohs4YOye8rz7SKE2UPv8QP16Za3WxAigRiFs4JjsziAu8m2g4ADNmf74mfP+wN damN4kDNUSE8c0UGm6TWm7fDNX721r8uboj+uDh3JANF9kUh5DnOiFRVae3TvvV17Nf9 IjhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=adnbYYXt3y1rSvkqYNUbMSM3zzoFE+m4ORetAFLtEoA=; b=gd1Q6gsvj34lj1dtCoCHOsWfEuyUBF1VaYcoAGTZpPsvi+VahP8eukXhHzpzAtQNsl ihOV2deGv+ayl9oD040xnM0xIXf38faQTJdpvCWgKuMnmEgYCnIcSiO73NZlaszrqLiO JrUrLIl3bvw+3KivP2M80YzUTw+PoFwKP/PYpYJqEWyWl5QMTCviKw4m4puLPgo8x4sZ yhQe+37hmHTSO962tm7hs1/gIg8XQkZKxcK7FdPZuI8I2VGt5j1DD04ngVQ4haKCjYOP o7RR4GBY31aDen7asjstDStwRydSruUAmxTBPVj++a7HBcGKTyktkOm9rYoTAND2n+BR QETA== X-Gm-Message-State: AOAM533Lf+dGDhAo+Bc4g92TD4KdNE8Z84DNN/W382v2OTrO5MaYZ7mT g8TkDYWfyTfmRqTg7o6RrjsMY/eNCxWRvg== X-Received: by 2002:a2e:9bd3:: with SMTP id w19mr4341282ljj.381.1623443566006; Fri, 11 Jun 2021 13:32:46 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id o17sm687248lfb.114.2021.06.11.13.32.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:32:45 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:35 +0200 Message-Id: <20210611203104.1692-5-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 04/33] 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: tFISaHTqkYCZ 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. Better debug message in case sample dropped: could now be audio or video frame Signed-off-by: Diederick Niehorster --- libavdevice/dshow_pin.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/libavdevice/dshow_pin.c b/libavdevice/dshow_pin.c index 1d0e880480..310f48c85e 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,26 @@ 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; + } + 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); return S_OK; - } - chosentime = sampletime; + } else + chosentime = sampletime; } // media sample time is relative to graph start time sampletime += pin->filter->start_time; From patchwork Fri Jun 11 20:30:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 28205 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp762938iol; Fri, 11 Jun 2021 13:33:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHq+QpxH4Ubu9OvbL5eecyMTaZ2piKpmPjGdCgyFgl0Jb9jVpZDE+djpgv+fWXvi29NnpZ X-Received: by 2002:a17:907:7713:: with SMTP id kw19mr5029513ejc.249.1623443588895; Fri, 11 Jun 2021 13:33:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443588; cv=none; d=google.com; s=arc-20160816; b=C3N4BrOhJvQgKwms7DlKl+KZigtvZ7d0G++CIfyI+pbLcb2yluuqIZL54JdV5pfe3j kosRwdFLXvo2jO6BM1fsdXCrZu33LxsNEDCOVpQ+VrYdcLZqKEQ5jXIYRehs3Z3sAQyM QrvBwD/EDSqNmKv4fnR2dWa+aOxX9xl7UE5QmmQFmgR4R7e9Uu/ahb22H3TLxGDn0+3k NXsQ0NSC2YpS+8lBPbR+htj/wW8QFAchA3S0fclptaP6LWzeo3Sh/sg7hfXA8SfuEsb5 ZAKLni2D0qF2PQIB+UVQK3b5LNey9zvF/iQorqy6622GJIl++YFS1VD7lxWnH3PcoiQQ +leA== 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=sokqD8fQSNwKlswcn3buB/0JwLtVDks8mYMf2PcTuYE=; b=Ya4K44a/kGT4Zd53Vedb3O+r9wFd6rTAPV/SAwornKxerN7g0eWqAO5LUuyb7gUa/J HZQEb4ytQYXZMLqwAVgCsacQjmeZFSOfHytykXyDb6XXfAyTDkbcKsNe3DD/jA6pPgaJ E5bW7GpXN/8RiLVmeig6Ji8754p6r70yyKfN/KElmMzxeX4i1CXZBU3IsJFm9sFBJ5xH n2uukCbNZ3Vrb6uyqAhTB/xh5RcDdqqLrWmpsCe4pzFRdc07kjkTNWzSEZH9GJxdzxpw zTJi4ibTCNkcsP7zbiAGDesb4GszLiEI9mLRxtGMKKfPDKevvUaDoXTmD+gla/rTDLGm ml1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=Y2sPfriD; 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 f27si5811287ejl.134.2021.06.11.13.33.08; Fri, 11 Jun 2021 13:33:08 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=Y2sPfriD; 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 6E25868804B; Fri, 11 Jun 2021 23:33:05 +0300 (EEST) 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 084AD680BD5 for ; Fri, 11 Jun 2021 23:33:03 +0300 (EEST) Received: by mail-lf1-f49.google.com with SMTP id x24so4732797lfr.10 for ; Fri, 11 Jun 2021 13:33:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yJeuo0ydICb0kyFsuJvu0RLWdFppQ9yrf/CpLl4W04Y=; b=Y2sPfriD6Pson+1Pxlkl6dWG8XV7MFO7GSwSVSIL/fCZ1HN8zckHY6PUGCrtgJulJi qEHV8J/rx2Uef7R1GUjIaxoHrqIrqACD65prBew8MxR0nv10u1YdjfipTfOIsFiAnlUO qGV6ni+aGuWc7Jshf2TX/Rr3NUp/2PHzCUsIerG+7CzPstMcmPpTGbpnZBOtQa+2Z4P4 d+TFU2pQnDi+/Z37qtYn37x/DtGGNV5aPabBVObJZon8wxVpk/zeCDdr7Cit57EzTk2f rFVfRjCi/JZKuV0nD8EXtP9PGVnuVUQfUAK5A+P+FE2vwC0DJeyLUpvRQSBynprARIBV QcGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yJeuo0ydICb0kyFsuJvu0RLWdFppQ9yrf/CpLl4W04Y=; b=L96+zZBSZPSDf2KZeQUitXHM3Isa466gKgHTDD0aILw/GrXDVIKvcZ/sLgtPgdnIN1 tnQxP14OEVsmP6ifuNh5m0DzP1VtJADN8MqPGbj/Hoxfgp2bXD6rU2e2j9iYADDIYu3f cnlYC6+Q9mOp9vynnRSaprpOhesagxYckMFsoeh5MqtriSl0RluguCxtRBPBgAWSrO/Z U+4NxUbleiKsMr/nr7+nrOeozjHMxQZI4iTFkY2UpDwUyv8YhHWqiTnAiGICWJnHTgu7 S3FeTC5cmA+B+0DmNT26/r9O2cFr+acjSspxJC5yWpOqbWipHdnPZI7KWTFNFEnVo8/m L7Vw== X-Gm-Message-State: AOAM530hDUqK9+ejbIRXKtlcyM8RTIaOoepfXzG9QOBvuH15ANVjQJYi HG+uupmOBMSTDvPTqqXGHX5pr7HYvSxFRQ== X-Received: by 2002:ac2:4a7a:: with SMTP id q26mr3643595lfp.395.1623443582751; Fri, 11 Jun 2021 13:33:02 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id w17sm688629lfn.5.2021.06.11.13.33.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:33:02 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:36 +0200 Message-Id: <20210611203104.1692-6-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 05/33] 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: jNIKGAVm0gL4 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 2e9f9ddf3f..389daa6380 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -1336,6 +1336,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 Fri Jun 11 20:30:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 28209 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp763091iol; Fri, 11 Jun 2021 13:33:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvDv8tK239/KGIY/JgjbsTcdBPQtu2m16O8o/ZIOHrnPJAbyQEE2yCPnNWjTYKlNXXM1Dy X-Received: by 2002:a17:906:63d2:: with SMTP id u18mr5252458ejk.186.1623443606727; Fri, 11 Jun 2021 13:33:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443606; cv=none; d=google.com; s=arc-20160816; b=Vvg32kL5hnPk2NwHP1VWRuTmW4frMObECP1M7hdof+0U7/uSBkrmZJL8gNhunYBTma gvOcUogtDD5nGCZy+QYiyCTjL5iMGqsycRkH3xfgaEGWzDPK9suu11i4+j0vTIkonF8P IaUoRFvvec/QcRFazZCndiHSG1+1JRdDjiFNtqXeTcYIERudndStNCWoYw9ayZ7h1r0m EPewGI6KNPMPKo71GidFGNHA+qWs0jEaC/WDkWY7klwzfQVg0P6mrRAv3iE0sYt8OPSm tEPtA3dIVMKT4D0Jt4Td3Yek1ER1kHDjj1uuu1NcwP4+KWntKdvh+wkZNMcLIrAX7bmH MYLg== 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=c58zCNFxeu/uoUmlzUOM1hC3IXccJZaE5xrwkjZOTxc=; b=Eqj7QXhjgnZDD83bsooYF65FfmZ/rOuDozjb/N/cT5d+vPEqhD/uChP+WFqhnTdZ6x JGm2Vx3nIt3S9xWzi7kUBOJBNloQhKi+Qh1vr4QcFNXqNUkZ3ahePbaer1GuVLJwhkRP 853w4huxDVDqJ28jsMGm1bZapqUm/A0BqH49RpWuhZpcJb7Kjgf8f7mn0lMhLS5nb/gt HLbKt9GgqdVgki4+6XCMFt3kZHf4KgdMKYZzlonpr/ojHDDBfQjaNjowM8ZHM5OhNXqx bbosEnjzUOZegiuQ8jYWBAVmxNy/XsjuScBdAZxdBpgMMnOMrS6Jn3MiNLLt/UcXvQMs nDvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=Z85hLjPe; 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 g4si5777009ejo.319.2021.06.11.13.33.25; Fri, 11 Jun 2021 13:33:26 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=Z85hLjPe; 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 681C0680331; Fri, 11 Jun 2021 23:33:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3ED1D680CED for ; Fri, 11 Jun 2021 23:33:20 +0300 (EEST) Received: by mail-lj1-f177.google.com with SMTP id 131so11325209ljj.3 for ; Fri, 11 Jun 2021 13:33:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BrTK3X3u/wxoTVDT2kQRQncJycwAhH4CuYt0VViKbQU=; b=Z85hLjPe00d/oK9xv11/3fAzd84zUjpmbXg/Y31UWrfUqM7DW6BHuBW2he6mj2bicF 9LBcBpBm0Bd2MGTotLGWYDD1/OGlUNy7/x3oyXJ4kF9mhELpdxX60FG5RZC94Tqb9tcP tK71MOfn88+xh3g9MZRxQDFkpcg4KmpEWJkUtrmtayQtfGlVgZ7fInQ9o8ylj6EsEZCX sfsyfDY/sT0GlPBKz8ZIRrut9IkOfqthMXni2YH35xuHVIt40qgsSIYxn6wtBlRlucMu HsY0r9tFwfGUK2Lwtxyl6TXM68D+GPxTiFDGlQygnszKbWC5j8G5AW9wufDkDSeJU5Tw ca7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BrTK3X3u/wxoTVDT2kQRQncJycwAhH4CuYt0VViKbQU=; b=Z+QiXinDHPIwYsHyrKvKFEoW4Hb3XycgasbESfECZotyv6WJYs7/uRqIWOqhJ6hFMj zvx90dmhk52hVB3l9nfKTsH5JUW5IvfU0X771vBrSF2JZrMT4VPbdJ7sWWIiSPOBnBIa u8SGWz1dioEkTNW3ZfVINGloTavAGkZkMIaO5/XGI2faqdgu/d8XBWgqk7Xqe7lXrbAO fZSNQgHCKDxe9FQpazaaxUf71NGObmQT/XxQuAd9d0q52b0rLcQlkOKxTrZ5eeNdqj1S +EErigT6D5/P65XUYPDkM62omzE4dO3OzhF8V0yHvX2DS5bu6u0UMPe9NbBao89YTFWb dyPA== X-Gm-Message-State: AOAM531sxtShkqzuqVlJ1necLPW9lcshq3K8WHgV1fhrRq4/5wRJEoB+ HLkdWuDyiVJhXd472aRm5rAkzbr0ZEJjnA== X-Received: by 2002:a2e:b01a:: with SMTP id y26mr4399238ljk.278.1623443599680; Fri, 11 Jun 2021 13:33:19 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id l17sm685055lfc.238.2021.06.11.13.33.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:33:19 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:37 +0200 Message-Id: <20210611203104.1692-7-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 06/33] 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: JB9pGODf80DA 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 389daa6380..25de6b1acd 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 @@ -713,7 +778,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; if ((r = dshow_cycle_pins(avctx, devtype, sourcetype, device_filter, NULL)) < 0) @@ -773,7 +838,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; } @@ -1130,9 +1195,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; } @@ -1336,6 +1401,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 Fri Jun 11 20:30:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 28206 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp763255iol; Fri, 11 Jun 2021 13:33:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/oQbIHB/5UdKyOa7+FpoA3uEkXmceaybyqGRkPIBRurOuRF5Tw/pSd5QcyH7FE59sOTHu X-Received: by 2002:a17:906:eb17:: with SMTP id mb23mr5320247ejb.239.1623443622573; Fri, 11 Jun 2021 13:33:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443622; cv=none; d=google.com; s=arc-20160816; b=WWJ4XzUNQ3CJJ6edWUyHDZM3N9/4pSqQ/0XnOKIRlFWyHRoeKGoWo9cwZy17HTxw07 XFDSzPlpiqo2f5vgEMp57iTKslGeEUvqRzQGWqjx7vWRYjXME3CaDjO7lm6jZFeoLSKw Q+FeuyDyZkgw69elx/COShLX7L69LT6097Mjnb/gh5uk0TIRCKRcNyiXJyrGqtQP/Zin 9+8bfuNI8yRDSo62Oxtojsy4sIcau+Aoja3V5tO1HmJ6xSO8Zg+f7nBTfZkx/Vqb6G7g CAkHjUUMmTlxhF2IQAZj7DuRAVCmHfbIzwHDEDBcMSDo3YX5MSj2HFR8Vh/uvt21dJk4 bdCQ== 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=r4TCCbmYS4Gea8+w0+RQLm61JsyAJaXWteXbkW6kefI=; b=wDw1ME8nmghgA6YnzOdRe8rRtsl6TcKo3XY2T4yvgJJKQshBI/p0MTxRk1AFp7jff7 Ue17643el907mvKWdJp0lecthU05FnCyjfdX5ybheImOtIK4WZi1Chygqa0+ETiA3o6E Xoa7EEtfpEST7aMQdP9ZvF5bV1DKh0taw1jxN/m0CcSL39GzKEYc+YO9v1IuFKyV2oJu tFRpy2hI3ecapSbKIuOo2SMv2aM3M3w+9ipRtvZSmOGnH1AMomJ7cex2s6n/NwjZLtQb s9yXvbqlhXYl7WDrEQldKMlpFAnYmm5EqUyKoLG2XsKm0jSXl4zdrfYFTA4JeIttJ1u+ Wb/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=HOhI446O; 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 b6si6364423edu.115.2021.06.11.13.33.42; Fri, 11 Jun 2021 13:33:42 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=HOhI446O; 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 6611C68814B; Fri, 11 Jun 2021 23:33:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 90335687F27 for ; Fri, 11 Jun 2021 23:33:37 +0300 (EEST) Received: by mail-lj1-f176.google.com with SMTP id r16so11389098ljc.0 for ; Fri, 11 Jun 2021 13:33:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3rUKQxo3ad42j1iPnnbOHplre1vZ9tYsRgcPCB5N31w=; b=HOhI446OpWuW5pfB5+4eXq5UWoin+QbceHhjgzxXtkU83xEipPiRlt2QOds2W8aNNJ nEFRU1FU2SAOhsHsyFGkGDA+TGwv437XrYtaWTyula/HXuBKWpnNie04Hyv1CQx7XwRy z9P0tjQ9sfRL9w2jQzdoyx2CcZvr0LL0fFzKtHOg732kRHn+W+bN2WmA4DDIySO3awRp ytncLFnvSmXKvxle1Jb+rksu9vMlUhz7gBOo1z3NMerbKF9SXCGP4S4/vIe+Tbqaq6nv QryhUPznQggqy1muYdwVUW4UCpBpWveJSh9hT4gD4s/3bhloXkspNhNIcsOVXlaxkqjb NoJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3rUKQxo3ad42j1iPnnbOHplre1vZ9tYsRgcPCB5N31w=; b=Ck7/VvJqjtDSI2hEuD5+8Cm9/2jix8cudSK2q07b+s/1YFkv989lWDQ1UzX6ukQe2/ 2tFhzf0b/4iQ9EEDAu96p6zJqdqBMDtJcZKUHfGKHZHB4wfwgEqgfnDTCu4SNFCCKFlu gQ2KHxy6vjuS1lXNXUH9iQNsXBurW12+/Yik1WqSWhtjSlxECP+WN7MVuCsPMJOhaLjJ tK/lJwXE6va2rFr7onRKkiy4SoFmbmq5IWJ8rVFkdqvDwpJNNHVo/iRckwQkCdZe+ePv wBgjrGUoT82BhB2eGsxopIzyaun1RernSBu5wx6cwyMLD0CShAt8HtkfWq++iSGYuVKw VO/Q== X-Gm-Message-State: AOAM533rtSDgp78W9xUOiGVtn0peNoajlf/Hk+oLqrvPqRd46sENkzvs IXD9Y5dkpbzM9CumObOzTiX9lZh/EuUe9w== X-Received: by 2002:a2e:8e2b:: with SMTP id r11mr4403653ljk.349.1623443616629; Fri, 11 Jun 2021 13:33:36 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id t13sm845330lji.19.2021.06.11.13.33.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:33:36 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:38 +0200 Message-Id: <20210611203104.1692-8-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 07/33] 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: 3V1tdNeVa+aZ 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 25de6b1acd..5d7f065a8c 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); @@ -1194,9 +1289,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 Fri Jun 11 20:30:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 28228 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp763538iol; Fri, 11 Jun 2021 13:34:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXDT6nCH/mi7TSz7gmB6P5/+OwwWeaDT3gjPQKOKYUsu8aHeoZOq1hWrm6ldWpNcKbfnNt X-Received: by 2002:a17:906:7f0e:: with SMTP id d14mr5089517ejr.103.1623443649864; Fri, 11 Jun 2021 13:34:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443649; cv=none; d=google.com; s=arc-20160816; b=DAO/NHzqP9j7u9fzymcMXXqfOECUKiTwmYKvHka+jIV6o/4QIiMf0+yBGSxJAOVmiC hYgGR3S43H6leXPV5XmzU2gYbWTc1CgW/GBTa4UKe0Jp3+sJKvuX3Q1tEQhzD4yQXTXN un2YXBUhd+hNrdntauVftuY6+lX4Am4iuf8RMi7WFhYaswaYCVim9xn3zgIaa05qOyMU pXOg05KQskzIrg4hzE/OPexw8QObqXEsnAZ57q5F79goBGDcqDL9dduhcfF6NIWx0Vdq +rOY/eQdgcYOGjjbHrmnK/oikvWvqNQOTQ2M8DS3uxG+aAASv+VN4ro5qTam/pkJzG3p nsWQ== 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=XTcUtUDazvrxnQ1U/B+ZA4MUuvoZ9f5eNe084JO+cnk=; b=QIsVeX+2boS3lGufQZDirPJRsjHwgfrLWGeHh/OkXf/1GCujhqa46JNQS+EkgA9jM+ wYcTlpedG2JRDe5B2AfaBe9slzyuYWlwFeu96Y+tEpa2xACOOcILnvnea1XEQtPe6xwq KGmisG6IzO4Cr6cPXlJ1Zqq/XhtUIot5ZKUiyjP6n47FHwe4CLcsFR9bPNi55GqfL2hy oxfEU6X8Vv3i093FGD8RfsJ1VwiSZJY7fw52PD96+yE3WtjFW2u1ZhRMxNx3pOqH4KR8 NbiCoZs6tA2NPOBAPW9SyaMHGAf3g1t3s1dZOOhZrOaj2poP2ANw2fWkePfjEjPbR8yu sg1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=KUJpbhzF; 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 a13si5460917edv.228.2021.06.11.13.34.04; Fri, 11 Jun 2021 13:34:09 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=KUJpbhzF; 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 7766C680869; Fri, 11 Jun 2021 23:34:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 51DFD680869 for ; Fri, 11 Jun 2021 23:33:54 +0300 (EEST) Received: by mail-lf1-f48.google.com with SMTP id i10so10373902lfj.2 for ; Fri, 11 Jun 2021 13:33:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jkH7//Ug1KRjrqJO2w+IvuSqaoye+0tWmmd3ktLeHBM=; b=KUJpbhzFse0wgZSivBEgXV4gOh5rch3x7kXLFRbAENC7MclK1BSQrmR2j4Hq7X5th9 6y4VObFufstlao7+D/flRPgcdLKYlAIiFIt9ovnkGQvZtCKzR0BkxxEDDRxQP83P2WVo 4KigROe9Y8ONBftNno6eQU5qhAaxa3Rbb823h7ywu1y0+HqTVePOQrZqrqgRtk1zJGzw K8DIIXdHGukwwhRBRi/b9EUYz73DM2RZj6kjaV2iIIVsK/T10JhWdIN8BHuOjrBciZ2t WxBAx3ZQU/oJ0hLRgSCPfBtMf1LyIOCqK+k8HgPtsp14sf1Q5zh6sCQAc9WZ5r1bWc9e GvXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jkH7//Ug1KRjrqJO2w+IvuSqaoye+0tWmmd3ktLeHBM=; b=iu6im97vl8j6tAWuezl5WA8WK5TGyIznabDF1kS6wYhzpVaCJRBh/f24wWVckU3Y+x T6fEbHPAZThFY7dFh/lsNmzoNtqfkpO2zSJ66msKV7zYjvU0sBvYyBHFzVLq87FxXYSh 7QPrrhEAZ+Cr0EaqH8EJJ33EN2385+8xNI0E/TNu5Bz68y9e/G01Mmq8PRxTkExRXNtK L7eQza5dD0IbQR2i9/NczUwusJdDu10GPR4URWSTo7nCp70aTu9A0PjOgyWaoIa8oPVI pxU2joVhIipRAdy+KauJz4fdX/ZA++BWRxPAbWAKnmgy7r9qWj8PXP9o4K038WXRh88U ANDw== X-Gm-Message-State: AOAM532T5HHvySUw5SndHVWN3ix0T+E0CsHf7N5Zd3H/ej71SLge6CuA mNjAOPJfb+7qyTx1JQp4S+mpX3C/6ZmTrw== X-Received: by 2002:a05:6512:3d17:: with SMTP id d23mr3670959lfv.596.1623443633462; Fri, 11 Jun 2021 13:33:53 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id z4sm661145lji.61.2021.06.11.13.33.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:33:53 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:39 +0200 Message-Id: <20210611203104.1692-9-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 08/33] 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: 8HxuXuL3VFhg 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 22b7595ab1..4a40929007 100644 --- a/libavdevice/avdevice.c +++ b/libavdevice/avdevice.c @@ -158,6 +158,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 6021a0dd65..6e593ba00e 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 100 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \ From patchwork Fri Jun 11 20:30:40 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: 28227 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp763649iol; Fri, 11 Jun 2021 13:34:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbalcC9Thdt79ON+fUs3nCjh9Ly+b9aCEtQ2Psv+ZnuLJuOSqb/dj8UFVWqnVnsQCXKt4J X-Received: by 2002:a05:6402:2049:: with SMTP id bc9mr5554505edb.298.1623443659117; Fri, 11 Jun 2021 13:34:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443659; cv=none; d=google.com; s=arc-20160816; b=UTtJVQWiNEldbjrpG5rsHo8kElpufuIP4IQCJEt6As9ZgP6VtTzZAaJOrPheq8tk+Q ZywtOlLkfzvsAunVEKmpQAMKx5armUy/9qVnxamCDvDwKcHNprhdKRENObtyeaaB0aBn S6Wyaj3/+CsCmEOnKYKibHx5Zl+k/hRkowuIIiPgy03wTADW3SyWSNKtSYA+BHVbyqfk VB21wHiBiUvms+GiVkxMrJ+Atg5MYcwIJo6Z0yDcJAqDkZ0ugtZszhM3CgvC99c8rLto 3P02NGQeioxQcJUmZ2dkT2snYKTwldEQK2mrxfeR+lIcRvOPoXfVN2ttBtkNPsXZsgji PI+Q== 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=VYovX04yvtBmGUvtMmqfxUhgmFYZc8zPOOCCuJCieso=; b=HfpZLPtqFhWkYp5s9tGdGqQR3s4kcnwjbKNkxVCQWmXGYTeM6jJ/5eDV7ELsavTIAB iZvz9fOWcw2HUzRReBkr0xvSrg/BnyN0KgbLKr/C9PaD3sQxAG9p2i81oGIEdds2sVtt +oxWIWx4hXyNPxzK4RxOnRtLnsAkNQOI3NRdz8t5vR97lMO6IvWKOF6WxQRHLQnah9zh eF8qqf1+CHye1gJ5xsrT46NY71MODLwarV5gKqGzx6av8fFABBFFSBjjI9fRiYkuvRL9 zGr64blf/dMa2xLUnr2DIRglp7ifq53x24LyIX5Y3fS1k7RvfASWtBladUquhg/h4QmG OaJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=ebKRCvHy; 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 c12si6390362edx.372.2021.06.11.13.34.16; Fri, 11 Jun 2021 13:34:19 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=ebKRCvHy; 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 2362E6880FC; Fri, 11 Jun 2021 23:34:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 93FDA681871 for ; Fri, 11 Jun 2021 23:34:11 +0300 (EEST) Received: by mail-lf1-f47.google.com with SMTP id v22so10384118lfa.3 for ; Fri, 11 Jun 2021 13:34:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XQsT+HJ/fpI/+IE04CMwa1gpL/ijG1wbnVrrc1uV5K8=; b=ebKRCvHyUXnN0CxN3NMozGeUTzjMQXFuPaDrA1T4jzTa0mrbBDLWpYSz0J1TlgXUAR qj8TEskCMePPLEaF2KRSkiHlTCtjLbZnWlHNccaYbRrkadn/l1btWs1Oy0hrqe4f5PtX FzcLfl9dm6KZtjH9hlKz8BW13+8nMX/dV4fI5yzuUWbydTbeBAy2N9sXJ/lLQ7wu8iZO mGUKUVse6wmJnbtIygQpkdtTjnSWeAgu8LFESwYMRs0Jc3Spn9ljIGcuJKnDMqKu3bIv 7pjiBk0xbRQE0HI+1LNj2HwuOVyD+wZ/IRlFw8P4gE34JAp1B/AW4VqV/OzGRCgYP+kx oxrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XQsT+HJ/fpI/+IE04CMwa1gpL/ijG1wbnVrrc1uV5K8=; b=ki5boCcKKjDPlPEBYHOUMoG/bSSHXa/cmkYOEPVhs+ueADrLLZyR83oWRRkymF0LP0 3OPaP0lDLvg6SQFtBaO5ePvqPaft7PcXrO7WeKVWotLQ8vlQFhcfuPLzkOJ5ccIuNC2C PNb38YsPQ+EHsKtQIHCHX6LsLJtZPRccEPu3ZqH5ov93uoVVD6IFSS1c1gWteUzRDsX1 RmYBCSAZueqTZVpqgVyBu50BqWQTUzF5nW7iN7MzjEMUwbHabvEppdf3XQypHtTYEDOX aiSSS/ecbtE5jkxwb6PT/JwDOb2FBVhZXU5uGmzFUOzNpwURO3D00H2dUdiEL00FjOkZ CTMA== X-Gm-Message-State: AOAM530fok9UwoPkFJSA/d+TEka6/Ri8IFkAGOp3aXBfTle/j7tikU1K AgsChz0cWZidgTDrr9bmFyBCHqkjtvvc4g== X-Received: by 2002:a05:6512:11e7:: with SMTP id p7mr3510949lfs.615.1623443650462; Fri, 11 Jun 2021 13:34:10 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id o6sm685575lfr.268.2021.06.11.13.34.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:34:09 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:40 +0200 Message-Id: <20210611203104.1692-10-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 09/33] 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: TVxqlwZE9cNk 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 5d7f065a8c..3e41f4f99f 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 Fri Jun 11 20:30:41 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: 28222 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp763820iol; Fri, 11 Jun 2021 13:34:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxe9ZJMhWYy2AD+JqdVYw++A9pe/GhgAjsIqlT3JT+hUeH7CLaS6XWt9fkqco8a2Jynn78V X-Received: by 2002:a05:6402:34c6:: with SMTP id w6mr5558705edc.174.1623443678330; Fri, 11 Jun 2021 13:34:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443678; cv=none; d=google.com; s=arc-20160816; b=oAGAwAJOrPUeRFELRXP92gnzokCza05scdOLQXanH81RLq6EaCiGLeRk+rtsTTL6JY UQKxPo3Kz4Ynur8COeYZPoRc+O7l13QB9wXvdO4TwzbaHE0aO/19XSOPRCUu4OtMpXa1 UVM26iFq3k22OjgqHQ2NoeSlyC+dYqBQidBXWp7rh8boGAhT/m2YssCOH5nWkPpTuj6A +0b4pxeODV7eQoWJu9eu84huVoDOZkjAvvWz7M6D55qAZxUeSgTjsDlypEI7CARSBeUZ dj1TfBPZP8FXHsSj7Qwpsf7FeWys7LxGNPlhPpvuYmIIlX/CUXJOh76JqC31mRf0AAkP cghw== 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=q6gqTAwjyV7nSZcAfC7yAlIR3Xp86kl+WoPhoKkWdFM=; b=xBHbhnod1U54VRGDy3l8fhE5Wk/+mYcPLLEb63vk4I7tTCJmudwd+ibovdJdlIYqOo 4DC2KOvrPMXOpWNAnwD6+dHh+1hLS4ELO157Yd2H85s/O31go8M5ZRcdJiWzOSer0dQ0 2TwolnGc11DmIxsvhraQqp0XYOkRVPxEQU+TieRQLze7tI8WnkKA60eCygQ1j3V19K70 Lxx8Tk2BlEogjN2sx8dsD6wSkcBYv+7/o/cSlZrS0Q7d/5a4p2Z36xBkjBoRTUtLemjz sJNuMeLKqZRBC6+xelL9GcRI3YWINWPrqgr5gaNp9ljxkWHNdK4US8EuvlkXwyBWy/Mn nVVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=kmbdfiaq; 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 ba10si5489357edb.344.2021.06.11.13.34.32; Fri, 11 Jun 2021 13:34:38 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=kmbdfiaq; 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 5926E688369; Fri, 11 Jun 2021 23:34:30 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 764AD688133 for ; Fri, 11 Jun 2021 23:34:28 +0300 (EEST) Received: by mail-lf1-f45.google.com with SMTP id bp38so10430049lfb.0 for ; Fri, 11 Jun 2021 13:34:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PCpBiIxJ5wN1A32mGErddipjUglV0HVAvbQbp4YgtUg=; b=kmbdfiaq7ThnaYlTitpZ2Fr0kALV02pj4p/CcF+bFpYa77tmlEA+Zm3NaF3CHWxdWH 9ypkldC9z9Wb6MHblcJ7kRP/HVc6HzJZ5HGh8mtQIj2uDTuMfLRXUcfUDBVfIzPTTEJn pq/2AfI68bhCY4VIwxMzmLUHsVTZgVxlJSxz+6RId9WmqruzGd79YqKGFRwpGXA8w+Tv xw6VLKIVIYEtlW4YQEaTotiirqydLmSw4yMfUpf4V/0mvpk5XeKLs+Dqf8fuxHdv0v8U Hl9Iwzi5LJhiV/F+GgqkqgGug67OuAWkHaMMaB6oJbwz5RvWzZ5ODLspm3c7HvtF6IsC QcFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PCpBiIxJ5wN1A32mGErddipjUglV0HVAvbQbp4YgtUg=; b=GA9C4e1zH5ks/Rk+ooQt+t+Fc+4rE2CFF69k2idJamND5IYiDGZIa+b/cFaKwUBYJf SlYEajKjfo8PmL/xY0WLVdcSnazVHwsnb1z0SBR011zaoJqRmwHCaDfvWFy4rptbg8fV X3z/h3DIHdo4WhyupTKAAmmqNVlgvJjmxEB/fEYiH2HQ4DraCP7g/2O5mkAij7oxQmAB Rt3/1L1/I8/mliLj9aw5OzDy27xALe/5F/pQ5n++SLZRDD8omVIqNQd5Oj+2C2sO0AAU jfpWVJxfE/wAbhb1Ejeo4LseW/+g2Kqb5wIp1DMjkZX+8AG1dXt7YoQSmbHSz9KNzRM8 nIvw== X-Gm-Message-State: AOAM530K1LfeAd++h0Y52gRqHQpF7vkpPZrnsPq1ev18U86/lJHKwpzr csBcsprnFP6aj0ToHzODerEGTxUCn+sR3Q== X-Received: by 2002:a05:6512:3f8d:: with SMTP id x13mr3823153lfa.278.1623443667260; Fri, 11 Jun 2021 13:34:27 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id c9sm841573ljb.22.2021.06.11.13.34.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:34:26 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:41 +0200 Message-Id: <20210611203104.1692-11-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 10/33] 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: n5UTWANwe4bp 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 4148285971..e7bd9f2644 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -2205,9 +2205,29 @@ double get_rotation(AVStream *st) } #if CONFIG_AVDEVICE +static void print_device_list(AVDeviceInfoList *device_list) +{ + // print devices + for (int i = 0; i < device_list->nb_devices; i++) { + printf("%s %s [%s]", device_list->default_device == i ? "*" : " ", + device_list->devices[i]->device_name, device_list->devices[i]->device_description); + if (device_list->devices[i]->nb_media_types > 0 && device_list->devices[i]->media_types) { + const char* media_type = av_get_media_type_string(device_list->devices[i]->media_types[0]); + printf(" (%s", media_type ? media_type : "unknown"); + for (int i = 1; i < device_list->devices[i]->nb_media_types; ++i) { + media_type = av_get_media_type_string(device_list->devices[i]->media_types[i]); + printf(", %s", media_type ? media_type : "unknown"); + } + printf(")"); + } 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)) @@ -2225,10 +2245,7 @@ static int print_device_sources(const AVInputFormat *fmt, AVDictionary *opts) goto fail; } - for (i = 0; i < device_list->nb_devices; i++) { - printf("%s %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); @@ -2237,7 +2254,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)) @@ -2255,10 +2272,7 @@ static int print_device_sinks(const AVOutputFormat *fmt, AVDictionary *opts) goto fail; } - for (i = 0; i < device_list->nb_devices; i++) { - printf("%s %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 Fri Jun 11 20:30:42 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: 28219 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp764027iol; Fri, 11 Jun 2021 13:34:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwLtME4BJiXtBscoSUOT/6IzdZJQNEJJ3zdAsBA/BNRTt8GT7WOw1cb43iCjRbD0QEB2ch X-Received: by 2002:a50:d54c:: with SMTP id f12mr5397407edj.301.1623443696527; Fri, 11 Jun 2021 13:34:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443696; cv=none; d=google.com; s=arc-20160816; b=IxaZ3dadb5KWVTy9lyEZvKVNOcvpIjvu+a4KPidYdRADedYTSZDLD36HW8VwX0/ih8 dUoKif4cHGewGvukH+2VRaGR5AzQvi6/nOHulyWz9syCpmiKCl9Nu2tusuRyVGLWdvg4 NEgAc54qgSWIBhDvHnul9IB7ANPjqvbumXQJOebVK4m0z8HqcYC4XNWXpkr1vwtqN/Xr ZYoX11mOBdkMNBxsqoW+Dh5ysejTWQ5iufvb97z2DN5xQsGdiYjLEt5nVPyogV+NgIHE tzecHx7ozlD/rGfxLnP4P8BeJoSCWz2B+ALeqIe1RdwmfuF5+rSAv8yzwfoT0Ac/2CEu C9Qw== 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=Lhr7c0A5CcpDAjfasLOmPhMMxOy3fS8sMdOLJ/T4DhM=; b=CzXJ4u6i+XqEbWN88DQli0yFKVDnT7Nfvr8NapUg3B0BgdNsQ4qJdqoJ36K2FUMg/U IBoNgbMcfWKYrHtCSD657SGeQzWHuIj+E4+yXetZZsVEFwk3SFJvjOm+keAYarM+eWzZ kF1n/jyc63BSeaIvkhuSoAHzcvvnLiOg0cvm+b5QzRxUwPoenH0qDYWXkI7asbPFj/9O +QG+o5z+gAYq61xEbFSxCDrRaGfshxLYOCEf82/la2/1eLvNIUPQ9Td0B7J8JRNH2xJx 5SRUCxYeDC98K3fLO1eWup8LyWqhlbTSz+vpOhHFPfAPA6n1QhdKnnwLvalcLdl+mhtM /BPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=IClQ++s3; 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 y21si5603463ejb.616.2021.06.11.13.34.49; Fri, 11 Jun 2021 13:34:56 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=IClQ++s3; 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 4AA086883D3; Fri, 11 Jun 2021 23:34:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 80900680869 for ; Fri, 11 Jun 2021 23:34:45 +0300 (EEST) Received: by mail-lf1-f45.google.com with SMTP id bp38so10431081lfb.0 for ; Fri, 11 Jun 2021 13:34:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AOr5y9ufe2X1eTxCLAimNaBYZyAhYJD5nOwwUGmduZg=; b=IClQ++s3Q7biagZrlZUkFQwrIXdu26FBvhaIG5sAP2ATEzMoDzjuOwM0a7K6k4bDRW lyAO+sX1d4ttWwGa8dSSmpofeNKea1OrrqooZCXwRNI/B7mCZREKHZUwbOz7nGkohAX/ Uka6iaH5XaYJNMNri73VyxD4pFl4xAlQpRxSVIvvX+WDEagdx6/VAYzrc1r/2LvY+D81 Yq5mCafyso2IH4r6fLwwAbUxLd3kpNSM57q0UQ5W0nOZchaBFEe1wlt8yHvzL74j1giN mc6XN2VHDetPjJ+TdUXjW4g3D7IQztFZPb11qjlaFzMAwME6tKY5Ym1khhx865lSzlnF O3Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AOr5y9ufe2X1eTxCLAimNaBYZyAhYJD5nOwwUGmduZg=; b=WMwT5FYDvYIXgb4PVY33JgTU4fyE27c70b36xbQG3fxod63N/3Dtq6GApVEbiwOlM2 FsUYdmkmcxOBCYD4LqTepeL+Nts/5YR+UF6sj5bdLQDNFPtA1oqycJThyhRZO2LLbquF J7QnjJjHyKAhbIAPMjaiW6tkk3wxmoGtCVQqNNCaotWdQiQvqeuvT9lpESYX7gYP5r7L 2YIuCvrB/8tU9XzfweCMEb5NsLTlyfUR1+6E/PmcMBwcFg8uLo61CzeO2+wQ68sx1jUv wDjTZLTriSmNXeo9G911mqs2XL0japb/eHKOBk8PB71AizlX21+FennfvXi0OQTnaMOW FdUA== X-Gm-Message-State: AOAM5314FUByHtzqEvmp1+NhbeJWGAXaVwUCFuwVPWgR4FLApC/P3GRT PD+f4HMadyths8Lnq87ptunkASaweITJLg== X-Received: by 2002:a05:6512:3b26:: with SMTP id f38mr3837319lfv.102.1623443684576; Fri, 11 Jun 2021 13:34:44 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id x11sm686061lfn.137.2021.06.11.13.34.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:34:43 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:42 +0200 Message-Id: <20210611203104.1692-12-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 11/33] avformat: add control_message function to AVInputFormat 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: UGuveBVnK+KF Control messages are useful for programmatic control of not only outdevs but also indevs. Bumping avformat version. Signed-off-by: Diederick Niehorster --- libavdevice/avdevice.c | 8 +++++--- libavformat/avformat.h | 6 ++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c index 4a40929007..e339cebf2d 100644 --- a/libavdevice/avdevice.c +++ b/libavdevice/avdevice.c @@ -53,9 +53,11 @@ const char * avdevice_license(void) int avdevice_app_to_dev_control_message(struct AVFormatContext *s, enum AVAppToDevMessageType type, void *data, size_t data_size) { - if (!s->oformat || !s->oformat->control_message) - return AVERROR(ENOSYS); - return s->oformat->control_message(s, type, data, data_size); + if (s->oformat && s->oformat->control_message) + return s->oformat->control_message(s, type, data, data_size); + if (s->iformat && s->iformat->control_message) + return s->iformat->control_message(s, type, data, data_size); + return AVERROR(ENOSYS); } int avdevice_dev_to_app_control_message(struct AVFormatContext *s, enum AVDevToAppMessageType type, diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 043baeea1f..7e9db81d26 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -742,6 +742,12 @@ typedef struct AVInputFormat { */ int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags); + /** + * Allows sending messages from application to device. + */ + int (*control_message)(struct AVFormatContext *s, int type, + void *data, size_t data_size); + /** * Returns device list with it properties. * @see avdevice_list_devices() for more details. From patchwork Fri Jun 11 20:30:43 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: 28224 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp764168iol; Fri, 11 Jun 2021 13:35:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9OAa9w2OQsJtq+xVLJgWmU6fonEWgffSB2W4l45EugBzk+ds4HyVpHL6LHgyhl2h75/g5 X-Received: by 2002:a17:906:f849:: with SMTP id ks9mr5016519ejb.402.1623443714850; Fri, 11 Jun 2021 13:35:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443714; cv=none; d=google.com; s=arc-20160816; b=OzAs+sRx2/Qg7OOAMmY/N6Fq9a/9zXDijtYhuTV+bTgD3RewCThlnozE9XodHrGZa0 hS0rychZK8EFzLlQ1WscHP76+7fBqMeX5UFTkl/H63piwb+xlWHmPOXyDJgBCN7ybUdU 8PMr+act0Rj1HKjJ0nFkEZYaBk1Sd4jDqAkn3jLn4CMKo0H99uIwBY3uc2weuvRCAp+Z tyE3bKzR7xAzA20de2K+u5lMHGSWlFdedHuJEgOjSBgRlSHjtBlEKPXyZtPx+Gzsnrmr v3wJQk1eySimQLdD+R6ZL2cu7jAyZc/ZTZlbTvpT+0dPu0w8dEVg6STE5gSXsHUkIikK FkWg== 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=zp7QA6B+4ZZuAbtARPFtbfOpL69b8RtnQdtvRqQv5+E=; b=PMb6PxPGCB6LWqXanaKu5BbjHQnh/PBpU8G0Q0qXbKCWj+NBPFADTTILJptSyG7frA tAlFCx3M5R1Wj2nNv3glAKO385hLhLDCMMXk8TGfiDWkmTZ7jfexhzzSDo6AdKFT/+ry jaaeyf+81cg9NFcau30Sa3BrmOy5eiea4A0ztlNW03GJGZBpZYXdYlg/FIOEb7OqMU4X BPyRNnez+aaSiEYxdL2n9Dk9pHsemJWqqCDwp+iVbf/YiPS6fOMKqTZQsxMgp7fk7DML bPjMSi3pdWaNM9mC6hbBWGte2O1DlnkZXMRa3vSl4PAD+kT+1fJERyuTp70kY0PoGoBJ Tj8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=OCR00puM; 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 k9si5966903edx.45.2021.06.11.13.35.06; Fri, 11 Jun 2021 13:35:14 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=OCR00puM; 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 4EF8B689247; Fri, 11 Jun 2021 23:35:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 430CB6880FC for ; Fri, 11 Jun 2021 23:35:02 +0300 (EEST) Received: by mail-lj1-f176.google.com with SMTP id n17so11324008ljg.2 for ; Fri, 11 Jun 2021 13:35:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=O2S1HiLuI+qoKwalxeviirb50hmX4gtDZ2Hsn1yydlY=; b=OCR00puM6Byxxa2q9s+AWx7MnW6LT1LMhI3BKru3WeEciFlKZaDmEaJxZglgLMUZGA TeNgP17JjA2eS/wrsP82y+Shp6qvmRuxEJZRshmYHAZRLMOZlpLnagIjHcQnKhmcNh/J 2uV4tILknXUplJfgn0lqkN0oZyUd8whHNQ8XWLO6dHkVNBNjzD2HvdINnWPkDeHmNaLn dj9o+uLKhC85YRgU3bEpZTm/2eY648JBCK7IvcSOYzqjWZG5UhbW8RjWfZk4yZ5q2EIK qCfFr03rQgoH3WOw/lr4Ah6tLNP8oUEAHVdNzJAw5PR5WRxFDjG9b63jHPUrOyCuwmTO b47g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O2S1HiLuI+qoKwalxeviirb50hmX4gtDZ2Hsn1yydlY=; b=gRLRdy5bDF6C+x3jXVEN+IIsFmxlGHxvXFIQv1Xxh/eV9BBu2ULdKYL0Aj+Ybe+tZi lzCI+4ViXkenyKvK8keXiUE89UDGqGPAt6GwF3v0Mr/VB8xXR9V2LcLRetZJSfJq/U5q Pu20peJTN4kAmoyh+t/rUeZITg/WYHsCq3CyHHQxrSQrH9xWuB3BLjckFw3JneOqYE7E qI98Kxo9rzVOPK4n+GetbWFykp7rEZZAnKPr2opFDwRogo0JgaoMo9r1wtbmR9F5A9Cm 6Wgr1njm0Dz2TnfGplaVrCV6i1rnghakWp6SbDS7+Vt4At68HzRHAjbpWcDgz3ESgvqz xOyw== X-Gm-Message-State: AOAM532DeQr/yoi+dhHPX8QcFqd7MQJP7l2ea4odDBm3LL04Vt+ySUP7 i22RByCD5zUIHa6SWPjBP9O/gHgwB7TSpA== X-Received: by 2002:a2e:a4c2:: with SMTP id p2mr4398843ljm.365.1623443701364; Fri, 11 Jun 2021 13:35:01 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id u8sm685993lft.223.2021.06.11.13.35.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:35:00 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:43 +0200 Message-Id: <20210611203104.1692-13-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 12/33] avdevice/dshow: implement control_message interface 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: rIMeBVNbAyX6 This allows programmatic users of avdevice to start and stop the DirectShow Capture graph (i.e. receive frames or not). This is important because now the buffer fills up and starts dropping samples when enqueued packets are not read out immediately after the demuxer is opened. Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 42 +++++++++++++++++++++++++++++++++++++ libavdevice/dshow_capture.h | 1 + 2 files changed, 43 insertions(+) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 3e41f4f99f..9f041e90f8 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -1079,6 +1079,45 @@ error: return ret; } +static int dshow_control_message(AVFormatContext *avctx, int type, void *data, size_t data_size) +{ + struct dshow_ctx *ctx = avctx->priv_data; + int run_state = ctx->is_running; + HRESULT hr; + + switch (type) { + case AV_APP_TO_DEV_PAUSE: + run_state = 0; + break; + case AV_APP_TO_DEV_PLAY: + run_state = 1; + break; + case AV_APP_TO_DEV_TOGGLE_PAUSE: + run_state = !run_state; + break; + } + + // if play state change requested, apply + if (run_state != ctx->is_running) { + if (run_state) + hr = IMediaControl_Run(ctx->control); + else + hr = IMediaControl_Pause(ctx->control); + + if (hr == S_FALSE) { + OAFilterState pfs; + hr = IMediaControl_GetState(ctx->control, 0, &pfs); + } + if (hr != S_OK) { + av_log(avctx, AV_LOG_ERROR, "Could not run/pause graph\n"); + return AVERROR(EIO); + } + ctx->is_running = run_state; + } + + return 0; +} + static enum AVCodecID waveform_codec_id(enum AVSampleFormat sample_fmt) { switch (sample_fmt) { @@ -1317,6 +1356,7 @@ static int dshow_read_header(AVFormatContext *avctx) } } } + ctx->is_running = 0; if (ctx->device_name[VideoDevice]) { if ((r = dshow_open_device(avctx, devenum, VideoDevice, VideoSourceDevice)) < 0 || (r = dshow_add_device(avctx, VideoDevice)) < 0) { @@ -1390,6 +1430,7 @@ static int dshow_read_header(AVFormatContext *avctx) av_log(avctx, AV_LOG_ERROR, "Could not run graph (sometimes caused by a device already in use by other application)\n"); goto error; } + ctx->is_running = 1; ret = 0; @@ -1502,6 +1543,7 @@ const AVInputFormat ff_dshow_demuxer = { .read_packet = dshow_read_packet, .read_close = dshow_read_close, .get_device_list= dshow_get_device_list, + .control_message = dshow_control_message, .flags = AVFMT_NOFILE | AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK, .priv_class = &dshow_class, }; diff --git a/libavdevice/dshow_capture.h b/libavdevice/dshow_capture.h index 5a2691518c..bb0f76a8f2 100644 --- a/libavdevice/dshow_capture.h +++ b/libavdevice/dshow_capture.h @@ -331,6 +331,7 @@ struct dshow_ctx { IMediaControl *control; IMediaEvent *media_event; + int is_running; enum AVPixelFormat pixel_format; enum AVCodecID video_codec_id; From patchwork Fri Jun 11 20:30:44 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: 28212 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp764451iol; Fri, 11 Jun 2021 13:35:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxme3mgZABfUEspxMi+wIBFadRlGgU9/ICg34PMRbqXaGvpWqVo2elJj3FXa5koEfnDv9Zw X-Received: by 2002:a17:906:3da9:: with SMTP id y9mr5245931ejh.303.1623443743709; Fri, 11 Jun 2021 13:35:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443743; cv=none; d=google.com; s=arc-20160816; b=DGpbdNq81M4l6T36/V3rYEqc+c+90gGkyR4m/5oNbb7OoXDb31vR1v8QnbUhjxuSi5 Z7OAMmIIbssAAOtbosM3Lf00KjVVXBSOVpsJKCQfLGKpoFfa8RFVqOZ4i+ci1Ad6mxOO rAHCgqix/6II3nK0fvwtIvhI5Z3SXgiMTxXvByi/ZYT0BDIXe6F/+JUv3fM47YIq9Wyz IXlBdoubNIcYhOGVRTs9r6sAU3vB0XpnC2n9Luj0nOJroOeTD0ODz3dUUXhhwDBtyORe u3k8SiEYjNy1pufR5EZD6F2t/idkx1VMov6sxo3UCCslusq2wyOI/rraQNQ4gRD3nZAR e9EA== 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=vXzvftL8tNKA6YByCkmhtezNTtx19DUCryBIybLHYH0=; b=VAOKUi3Yuoy//YPp3hBwDSv8dyM1WiZhrztOBX97nbmcsKiRhAaMgGe9Ifrxdlq+cD em2iUzwfsANE4h1coYSi3ExHVuXDHaGbRW/0qDR1V/+gqIDGneEIj9z8YsF5Pnl+HchZ GE81psHQMIm4doFBGUO5eitjKBRw9i/9+ut4Ux2sbgOi/B3zoXBhozYvMT5EPKA5/M26 8rHmNyxVWw719NMl9GcFNindjbxuoOd+Jy4+jnD2QBKK9bXqjOOMVl/r8273ZX/Ab7lb lCHAhftghhdz9y1/gTza9pXgPIyl/AZ185Xx5FT8ZjkFynnPG0NJdiEqa9x8zXKmQhtd b7DQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=W0F2eVM7; 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 f6si6050414ejl.241.2021.06.11.13.35.24; Fri, 11 Jun 2021 13:35:43 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=W0F2eVM7; 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 73CD0689767; Fri, 11 Jun 2021 23:35:21 +0300 (EEST) 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 609BA680267 for ; Fri, 11 Jun 2021 23:35:19 +0300 (EEST) Received: by mail-lj1-f173.google.com with SMTP id r16so11284452ljk.9 for ; Fri, 11 Jun 2021 13:35:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gdbFtrmMHyQgF9UhHtf/VoQVophBV2w7zjcP62i5XT4=; b=W0F2eVM7OzFmr9K0YOyRkYyAxUIID8TB1L90CuBLyoEjQZxBkLaee40XPp9V+eFQkz SXKVtHYB6PPTDXQ82/UXbyPAG9HTlGFnTTDog+naRqjusRL1noRVyMcV20mIMtAwAP+W sSlmt+m+PmbPE/8wZQZusBV5IWeSwc7D24uoseg+vcTW8KyfvBHQNhk0qnUn3zQkEf4q esbOlaSqk0NQ8oXM6K6r4vVqSVzgR/In3sBh/iQTdGlxmVRJNRorPLcNVtM03y+iB/YR Kv3AUftPBtv2/hDFtLxHzdoXqBy43yMJXichuH5k6j2Exn0FaTfrxjPEusDVPeFoJ8/S SkwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gdbFtrmMHyQgF9UhHtf/VoQVophBV2w7zjcP62i5XT4=; b=JpfnQ1nCSIzLw0YVX3E19JBhVSDMkJ4+K7V9Fxmhl++OpyoCdHCqMI3mhOI+Qho7+O j0fsbDvvLB+PlVZcIhLTtgzkNKfq/VQSq7sJJNuTh+pwdKrA7sVDUbnH14uLIj3wRZs1 T02L4F3rfuu6MRRVusf4I7D38G1JBZ8T4IQmFxNp1siKNN3/KV1qGiUsBTqmel/UboHF q4Gzse4qcDjlMfHo5a29wSzfsl/lDUfF+ySKipVaWpZIAGKrwH81ftckJeJbtyCGf3X3 nR30FBcA6eA6LmUWGRWFivHRS37TUNpIhTJftMoK/iYYXhU8W2mSOU/jSRgW+nlJFDmN Q7sg== X-Gm-Message-State: AOAM533iCaALS+OaJgJ2Wvt+mo9RxiufBJyZyqebQQ/Vny4Pqu9te5Q+ S+G2dJyUTZgLFNaGVqUdy+T9GX5ZCDahOw== X-Received: by 2002:a05:651c:2c7:: with SMTP id f7mr4331556ljo.287.1623443718268; Fri, 11 Jun 2021 13:35:18 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id b18sm686101lfb.277.2021.06.11.13.35.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:35:17 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:44 +0200 Message-Id: <20210611203104.1692-14-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 13/33] avdevice: adding control message requesting to show config dialog 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: DOwr0GZxQo0C This control message can be used to programmatically ask a device to show one of its configuration dialogs. Adding documentation of this message's int argument. Bumping avdevice version. Signed-off-by: Diederick Niehorster --- doc/indevs.texi | 34 ++++++++++++++++++++++++++++++++++ libavdevice/avdevice.h | 10 ++++++++++ libavdevice/version.h | 2 +- 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/doc/indevs.texi b/doc/indevs.texi index 685b1357a6..970441ee06 100644 --- a/doc/indevs.texi +++ b/doc/indevs.texi @@ -668,6 +668,40 @@ $ ffmpeg -f dshow -show_video_device_dialog true -crossbar_video_input_pin_numbe @end itemize +@subsection Libavdevice user notes + +The dshow device supports the @code{avdevice_app_to_dev_control_message} +interface. + +It understands the @code{AV_APP_TO_DEV_PAUSE}, @code{AV_APP_TO_DEV_PLAY} +and @code{AV_APP_TO_DEV_TOGGLE_PAUSE} commands, which respective stop and +start whether data is captured from the connected device, and toggle +capture state. + +It furthermore understands the @code{AV_APP_TO_DEV_CONFIG} message, which +requests the device to show a configuration dialog (if available). An +@code{int} should be passed along with this command to indicate which +configuration dialog should be shown. The bits in this @code{int} have +the following meaning: + +@itemize @bullet +@item +1st bit: If set, the dialog for the audio device will be shown. If not set +the dialog for the video device will be shown. + +@item +2nd bit: If set, show property dialog for the audio or video capture device, +allowing to change audio or video filter properties and configurations +manually. + +@item +3rd bit: If set, show property dialog where crossbar pin routings of the +audio/video device can be manually modified. + +@item +4th bit: If set, show property dialog where TV channels and frequencies can be manually modified (in case of video device), or TV audio (like mono vs. stereo, Language A, B or C) can be manually modified in case of audio device. +@end itemize + @section fbdev Linux framebuffer input device. diff --git a/libavdevice/avdevice.h b/libavdevice/avdevice.h index 6f24976dcc..bbeb1ae21b 100644 --- a/libavdevice/avdevice.h +++ b/libavdevice/avdevice.h @@ -190,6 +190,16 @@ enum AVAppToDevMessageType { */ AV_APP_TO_DEV_GET_VOLUME = MKBETAG('G', 'V', 'O', 'L'), AV_APP_TO_DEV_GET_MUTE = MKBETAG('G', 'M', 'U', 'T'), + + /** + * Request to show configuration dialog. + * + * If device has a configuration dialog of type indicated by + * data, show it. + * + * data: int (device-specific). + */ + AV_APP_TO_DEV_CONFIG = MKBETAG('C', 'O', 'N', 'F'), }; /** diff --git a/libavdevice/version.h b/libavdevice/version.h index 6e593ba00e..0381d6cd0d 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 1 +#define LIBAVDEVICE_VERSION_MINOR 2 #define LIBAVDEVICE_VERSION_MICRO 100 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \ From patchwork Fri Jun 11 20:30:45 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: 28211 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp764622iol; Fri, 11 Jun 2021 13:36:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw54vsp8bmbCmqaYqiXgBqpV8+B1xWLqNrevTC1rJUSjNF+ijgJxQ6OoY4vmekjrMPE6VHp X-Received: by 2002:a05:6402:31ba:: with SMTP id dj26mr5416591edb.71.1623443760872; Fri, 11 Jun 2021 13:36:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443760; cv=none; d=google.com; s=arc-20160816; b=BCcGOkk+Uv9bk8Czr1uJivUEnpk0KJKSEBDgpdp1y9fggT5BmlmhU3EZPRDVpHgYm9 7OgPkSXnaJrHvNTpIVBb6C5kJxhaLS4qVkUrjIoGzq5KCMdDuGnB+NVu1CiJBOQIARQE DcmEQui4I2WRxqc3UxoHvmc4QozGrmD2pGfdRUv9NqEBEhNbd4iQy0CY4J3w9HTIRgEK oy+JqjpJWJKwKjRux2QAJsn1q9JsxBiUE050NhX8Lh1k11Hj4hjq8y10DfcA4rtePMxC QVzFzz5iTFZV4G0XiyLKv/gAOQoFEshfnbOJZJ2smi58Q1E0g5mmwtq1/UI3lubD/0mD wqpQ== 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=M0ffoaj71A3wghe0ujw18GvS3rsLO1NbcpZYmlHMrv4=; b=SUZsO1Nf2bH3EVqQ3aAU9g+CfgN00Pey+DvSFMwffJjxeIIJJRZpCZP5YwtKwIAM2S z2v9yWEPQ3+gcbXrP1F7PV+5CrhX2T5XXE3iQxJAb4BWeNVb66VYpILbUyiYToXjmbK/ ajEhcGbIQCaHYnzq6RVtz+kmiOjPDIhGJx+jMEt8gFSxMFHsSUIGCMqNWAm9zhDV2MOH IY5Q4aLMmE9VnINAlzHgIiHq0oKpQxj8Mb4TkdanGT/tMwnUUFIHvJzU9Ey3fer4fECb shw6LjClxvSGKIG627E4JZaLdD2yH0BR87G7h/pr5PVanh4dw5BkETR1fVIT2vwBKMsv SmkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=Mq0P0II3; 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 f17si5707428eds.78.2021.06.11.13.35.45; Fri, 11 Jun 2021 13:36:00 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=Mq0P0II3; 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 98DA568980E; Fri, 11 Jun 2021 23:35:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F30916883C9 for ; Fri, 11 Jun 2021 23:35:35 +0300 (EEST) Received: by mail-lf1-f48.google.com with SMTP id j2so10357510lfg.9 for ; Fri, 11 Jun 2021 13:35:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RlN10Tx/WPucIl/WAKARARDEjMbJM+blL7G6lm1/GT8=; b=Mq0P0II3rwcy4O12rSf1eNwi48aLuhaTZtZ3zul1QNGxbclpY7CaTwJuwNdejVNklA YKbkJ5oaZ1pB6ygM0TJJt2ySmLrmOA0977rlplW0C4Pw1ATzJGb2GNFT9JGUvyx9VA0P wsktpCJ+mzWr4qcNIQ46+ZdhyDKOXva3rPd3+WmgwkQqG0jLuGNQq9S+HvtPU0MUF6Wu n6YZMjtN0sK0ITj5Q738DljA4paeMQ4Zt4OAc/5n1uNRkM93VCM4rULVPkzXIZcdEC8D LpG1ByuSozEmjMcwl9ld5nLurN38yLw7MLQo4SHbj8PkdBQr+SAacIjDENKQ5H6/9Ptq UXdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RlN10Tx/WPucIl/WAKARARDEjMbJM+blL7G6lm1/GT8=; b=emMojctMRE5cFf3Gpmqz37QMGXoFIMCXj/zo32RqNty717YklxXRgO2l7eO3FD0yTR Jq4y4PxqQZ/rplLyyD18Ez4GxwxZkNdxc48Xj+3fMWs350edyT+QguuPGagvp6suJtDj QDoBdruK3fvxyqNtEP2fpFYFED//jlCZe1SkRGa+s0dJk6sXl+0BLq2i17coOgZLXMia a5uFfDVGeKrbYutcjfyE+2iIxn0uWuIUV7X3Bax4EBdGFn8s6Cyi84/VnyGFn9CtX4r2 /cTBVupeDPheZ1HFn7vCl5vW5BWB7xmgoaTZZpiVzsyQXNNEDY84i3m3luamkLE90zwJ 9LPw== X-Gm-Message-State: AOAM532bC8GCOgMyQtn1Lkdt8xImEWbnG6OYjhRoWZuuv15xtLs6RCl3 SdjIBwKKugEJG2rlCmMgydu301TQkCyoQg== X-Received: by 2002:a05:6512:3b2a:: with SMTP id f42mr3668287lfv.425.1623443735156; Fri, 11 Jun 2021 13:35:35 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id i13sm685873lfe.81.2021.06.11.13.35.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:35:34 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:45 +0200 Message-Id: <20210611203104.1692-15-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 14/33] avdevice/dshow: accept show config dialog control message 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: j3WFhruqq2Re DirectShow source will pop up its configuration dialog when AV_APP_TO_DEV_CONFIG is received. Implementation for several other possible configuration dialogs is more involved and will be provided in the next commit. Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 9f041e90f8..018792a886 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -1084,6 +1084,7 @@ static int dshow_control_message(AVFormatContext *avctx, int type, void *data, s struct dshow_ctx *ctx = avctx->priv_data; int run_state = ctx->is_running; HRESULT hr; + int ret = 0; switch (type) { case AV_APP_TO_DEV_PAUSE: @@ -1095,6 +1096,32 @@ static int dshow_control_message(AVFormatContext *avctx, int type, void *data, s case AV_APP_TO_DEV_TOGGLE_PAUSE: run_state = !run_state; break; + case AV_APP_TO_DEV_CONFIG: { + /* For documentation of dialog variable, see ffmpeg-devices.html in docs */ + int dialog; + enum dshowDeviceType devtype; + + if (!data) + av_log(avctx, AV_LOG_ERROR, "Use the data argument to indicate which dialog should be shown."); + dialog = *(int *) data; + devtype = (dialog & 1) ? AudioDevice : VideoDevice; + + if (dialog & 1<<1) { + // device_dialog + if (ctx->device_filter[devtype]) + ff_dshow_show_filter_properties(ctx->device_filter[devtype], avctx); + } else if (dialog & 1<<2) { + // crossbar_connection_dialog + // TODO + } else if (dialog & 1<<3) { + // tv_tuner_dialog + // TODO + } + break; + } + + default: + ret = AVERROR(ENOSYS); } // if play state change requested, apply @@ -1115,7 +1142,7 @@ static int dshow_control_message(AVFormatContext *avctx, int type, void *data, s ctx->is_running = run_state; } - return 0; + return ret; } static enum AVCodecID waveform_codec_id(enum AVSampleFormat sample_fmt) From patchwork Fri Jun 11 20:30:46 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: 28217 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp764651iol; Fri, 11 Jun 2021 13:36:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZM3pu07SdWaUUTQig/s9Xf7uFj5mtc9gAglnZjJnGvuRm0YCmxLpCKZ8eYIAa7kllTCaf X-Received: by 2002:aa7:c68f:: with SMTP id n15mr5510110edq.145.1623443763604; Fri, 11 Jun 2021 13:36:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443763; cv=none; d=google.com; s=arc-20160816; b=B09SJFSVGH4aKxfxVVEIsgN1WGgXHJUhm/tQX0yrhR3pTMqUf2T4cjv5YjuLW9A68U vQs4PPZW/AtG87w+cCLOO4CtY3yHFaZ6HZ4TESsA3/q3K9x0eCdEAm7d5eq8L16vX9RC 9Eod78DIiT9L7UpihB/VRNQCzr/JS4wJcT2lQ/f8um9p4hkMCihsWEXyw8FMXDEL2Qgv 5d6aqxb3kwl1U3N/4Ez8wM0wPHM7tM3v2cWt5BAqHjw7YGotS88FR68/sxgmeyBlPzVT zxjkzM7wNctpEiRRrtZcf2c9Y64RzkQKpvLCgpnkB8+DliLu7vbX5WwG/13/BGKVXzl6 nTbA== 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=DdPue27c3QISKq4jFONbUUxFtqra3Swzsq3IITW0nPk=; b=KJmDxdtX6gODC7/mA9AMEjtm51hzUYl3zISgWQtg3X9N4QrCdb/NcVFsINlOXT0lN2 BPj2qgyvxupLpnxP7KvbDyUrB6DT4fzfGacP6OTNVmmH1fABZtDtYQQKTmW0VS4SQxs7 hCUh8jtB+cF9gvqwcnb0A1KjWnGV5FXN+arJx05ZS8NjyqFkXJfduhc0Q2SIP4xlowR1 GTHdiCj0zYCcluvAEZBB7H4Jm5DNUwuZkBJnMRMZZXzLU0X+Im277o8Ze3IxLoUoLf/c scWhGC/Mndw0u1sPkoDjX8/Vv2Nb8G3h/Ij6JQWwtfpui4NvR0PrEiCiWzMvRnEqylDL +RHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=T2U0iyee; 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 y3si5346349edr.383.2021.06.11.13.35.58; Fri, 11 Jun 2021 13:36:03 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=T2U0iyee; 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 A13B0688388; Fri, 11 Jun 2021 23:35:55 +0300 (EEST) 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 7F487689246 for ; Fri, 11 Jun 2021 23:35:53 +0300 (EEST) Received: by mail-lj1-f178.google.com with SMTP id e11so11236056ljn.13 for ; Fri, 11 Jun 2021 13:35:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SN9rIlY8PdQY3SDxkDGkMVGDwlQJjAoo7o1D+SG5i5E=; b=T2U0iyeeLALCVYwqB8n7B+P16Pdon4ugZDXcwmsoHWsShz3l+6NgaBTIyhHuPGRS7J q738z+IrSOBbaG+KX4gJHOMIKsoejSx2Onnta7JZN9oDtQkwTM5635MVga67C34wVyKo rnccQt9gmJpVvw4ZGC8bQOUWFG2DMJZhnVrB3S7zE1kQal6g9xOaKuRQCuWEZ++Sn/l7 EKfO5WLVnl4/R0ojInd34h5onm5mTsNpHR2qp4UW6LvTY7soz1dV/iZikGM39fzg6+CK prda+gKUCrWs2Ie2uSHT0EZLm6XD2ugyz9wjYr4YqSWshZVCLmZ6o9+WDyugKTabP0+u SX3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SN9rIlY8PdQY3SDxkDGkMVGDwlQJjAoo7o1D+SG5i5E=; b=Yf5igJ6g+OOD+oKyfP7/DfGlX72OLJm4sHJXbHrjT3jTwfjEThF32geQJGCxVLiiTG YAGPQ0QTjmLYtqBUasR14lchXXjhXX6Rpm1VzegNzzGC2AAoxvrm0JbdsvlG84LmkjdK LvXoekxLpcFNvWGCNZ46dw1l8bqbrV1VCuzURb14qNE9I6I3Y4brHHI0XTTfn5gkSmgS k6Qq5PqsiKRAM41uNmZp68sqT3douyALr2XizdrKT/qks6JN+PI3vgV1PZps/QuakHBW nN0OiwqMS29nNGSTvMust+HEZSC9aYeGaRN6KAG6Qnqa6pcP+7CHbHUa/d/K5Guh9zXE F6cg== X-Gm-Message-State: AOAM533/RKUU1W279Vbgjk3i7op2DNAFF9+WkQPjw6Qri97VOUev4uwu jjX5zcBu1jjpMO9b8NKaKf9ZN+cPmIJw6g== X-Received: by 2002:a2e:9e95:: with SMTP id f21mr4262251ljk.137.1623443752267; Fri, 11 Jun 2021 13:35:52 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id o6sm685980lfr.268.2021.06.11.13.35.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:35:51 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:46 +0200 Message-Id: <20210611203104.1692-16-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 15/33] avdevice/dshow: tv_tuner_audio_dialog cleanup missing 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: gf1z3D+nRyHF Cleanup was missing for when the show_analog_tv_tuner_audio_dialog is true. Signed-off-by: Diederick Niehorster --- libavdevice/dshow_crossbar.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavdevice/dshow_crossbar.c b/libavdevice/dshow_crossbar.c index 2438683cde..961defe690 100644 --- a/libavdevice/dshow_crossbar.c +++ b/libavdevice/dshow_crossbar.c @@ -204,5 +204,9 @@ end: IAMTVTuner_Release(tv_tuner_filter); if (tv_tuner_base_filter) IBaseFilter_Release(tv_tuner_base_filter); + if (tv_audio_filter) + IAMAudioInputMixer_Release(tv_audio_filter); + if (tv_audio_base_filter) + IBaseFilter_Release(tv_audio_base_filter); return hr; } From patchwork Fri Jun 11 20:30:47 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: 28218 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp764761iol; Fri, 11 Jun 2021 13:36:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxelUwOF65grsIIy2lJEuSf3ShWgwBGXGy0g1f+afoaDRVMCdbgXuyUYrgtVvwQp4vY/xjd X-Received: by 2002:a50:f403:: with SMTP id r3mr5476593edm.101.1623443776045; Fri, 11 Jun 2021 13:36:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443776; cv=none; d=google.com; s=arc-20160816; b=dDzpZZ9Jzv4epxDeagkfxDeUkPvSeVJhaBVcOj5zBZK3UgI1NDTsvezKezeAHvQNd3 LbgHTN86VEgDV4FZwL41VJmtDdTz7Iz2ljldFaFMVbI4Cb7sSu71jc/5YkQgTlmR7g7E V8GrMbBBwi05dSNrI5NIYjfs33/BQiRI0BMJUEyyfichA08bjGa92ok/r+Nm/myCsTk9 kXvUR/aRvYkuEU45Qm9XOsfGM9CeYaNmUB5sgCj17P31dyLuE3CGx5+UoqjvouZFqWb/ efPL0tGvmkCuOilq4gFlSj6ktLC6bL/zInilKkdM033aZU01I1QDEsclOba15y//vkBz CGvg== 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=eOkmXaxo5dD/xhnrz+rPrnkFqAqS1DWGct7eA2PQqfg=; b=dSufn7Higt34uAxT60Bv6vrF4NPQgD0TxyziVAKr3KfT0foFQwyRM3SkGpNvLDfDFB uoICiEHVX1Str/CPCZQuXK7LLYRA+/R/IZIbiKsW80OgKDSQVXfXbEzUcJlBN5+LHYl9 GQZsKj59o86NI+15g5NRKy2XumqK7FKeVITfiXFgW5UH4JeXM/ZMUylhCmSau+r1gzS5 iLvk1VucXbXZZi2JxoWsYLDn4hrtfGoukLqXEUdh2Qe3IoKbTDNEGvk7XNg8hqIf+Y8G M6XUYRIlSlGEZqt7PArPFfS2fRs2bg9cPirhWBjCTnGQ4FzXPbQ8ddx87KDvabE9i6d0 VV1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=qxLYyx62; 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 v11si5879392eju.491.2021.06.11.13.36.15; Fri, 11 Jun 2021 13:36:16 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=qxLYyx62; 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 97F48689903; Fri, 11 Jun 2021 23:36:11 +0300 (EEST) 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 589DF689721 for ; Fri, 11 Jun 2021 23:36:10 +0300 (EEST) Received: by mail-lf1-f43.google.com with SMTP id f30so10396701lfj.1 for ; Fri, 11 Jun 2021 13:36:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o0ih72Swgbi+XpOc/D51T8Jyj1rgSUCHHMBW/usDxE8=; b=qxLYyx627Mkabl7p4P/dC1u2r1/mZrbbc2flWoXeSbc7zw8Hn9nn0b9QSKauFUUzkY IXUqmGCuxl9jaT9g8/KYMOyX1iQRNtDL1o2MPz3WI0n+u+N6DahQftTjwYWMhj/ZGl/R t5J+7k2+eK1HHbjTNIXYH35LjDmFa/pADyanQxg+rl5dw+zzjQOZdZRDWwtXQwrHpSDw Q66DmEgrtX1OYQHA0YLjyph39dnDjh1rZDboGipGruRCP+JuGayOvkGmzX3vVHDOTbUW r+trbrJgHXl0nUEjfDtD4AjGOuUjGeGQNfg6sQHVeMIh8YMSDTg7btki312wCSyuFzUN mbYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o0ih72Swgbi+XpOc/D51T8Jyj1rgSUCHHMBW/usDxE8=; b=QfAThSyCVyDyw7PY3ORRDq9dym/l1LOUe+L5lt6sNX84L9dziw7CsDeldZi0K4vcTQ Gu7a2N0XY+/i37KoMv3BEyxshu7S6g10ozFN5TNpAN1+7YfyM6N82hY43u06JyHvPjO+ rmUkD5mU/9wQLOj1IIT2lPO9XIgruc0IkXh/XaHpRaKzmGqOnc5CVX7X9l+jSyQMMUci jQxUDQ+IQgFve7Mvk4u//6iYWKFuvPXxEQgKQlRN+gzm5ScMZg6T7PKJcjNMRskPVd2c hmfh9BRfSiSJNYgai40kcWPR7oWxS6e4TM04zJws2XntTnfEN1pGv0XvusC+4Wv7Bbh+ 8pqg== X-Gm-Message-State: AOAM532v4ccJrhTOcMunGUXvgyi4jAJreGHGu3uWIc8wvkUOLakuLqf2 j+Dix5Ev6+VYUqfFM4Ukgp1g8Tpk6aIsUA== X-Received: by 2002:a05:6512:3253:: with SMTP id c19mr3583509lfr.405.1623443769147; Fri, 11 Jun 2021 13:36:09 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id t6sm684981lfp.301.2021.06.11.13.36.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:36:08 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:47 +0200 Message-Id: <20210611203104.1692-17-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 16/33] avdevice/dshow: add config dialog command for crossbar and tv tuner 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: Jxg9Uoewufl5 The "show config dialog" command message can now also trigger dialog boxes for the crossbar connecting pins filter the analog tuner audio / analog tuner filters. _Untested_ as I do not have either device. Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 51 ++++++++++++++++++-- libavdevice/dshow_capture.h | 10 ++++ libavdevice/dshow_crossbar.c | 91 +++++++++++++++++++++++------------- 3 files changed, 114 insertions(+), 38 deletions(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 018792a886..add46e82ac 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -60,6 +60,11 @@ dshow_read_close(AVFormatContext *s) struct dshow_ctx *ctx = s->priv_data; PacketList *pktl; + if (ctx->graph_builder2[VideoDevice]) + ICaptureGraphBuilder2_Release(ctx->graph_builder2[VideoDevice]); + if (ctx->graph_builder2[AudioDevice]) + ICaptureGraphBuilder2_Release(ctx->graph_builder2[AudioDevice]); + if (ctx->control) { IMediaControl_Stop(ctx->control); IMediaControl_Release(ctx->control); @@ -1040,6 +1045,7 @@ dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum, av_log(avctx, AV_LOG_ERROR, "Could not create CaptureGraphBuilder2\n"); goto error; } + ctx->graph_builder2[devtype] = graph_builder2; ICaptureGraphBuilder2_SetFiltergraph(graph_builder2, graph); if (r != S_OK) { av_log(avctx, AV_LOG_ERROR, "Could not set graph for CaptureGraphBuilder2\n"); @@ -1064,9 +1070,6 @@ dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum, ret = 0; error: - if (graph_builder2 != NULL) - ICaptureGraphBuilder2_Release(graph_builder2); - if (pers_stream) IPersistStream_Release(pers_stream); @@ -1112,10 +1115,48 @@ static int dshow_control_message(AVFormatContext *avctx, int type, void *data, s ff_dshow_show_filter_properties(ctx->device_filter[devtype], avctx); } else if (dialog & 1<<2) { // crossbar_connection_dialog - // TODO + if (ctx->device_filter[devtype] && ctx->graph_builder2[devtype]) { + IAMCrossbar *cross_bar = NULL; + IBaseFilter *cross_bar_base_filter = NULL; + hr = ff_dshow_get_crossbar_and_filter(ctx->graph_builder2[devtype], ctx->device_filter[devtype], cross_bar, &cross_bar_base_filter); + + if (hr == S_OK && cross_bar_base_filter) + ff_dshow_show_filter_properties(cross_bar_base_filter, avctx); + + if (cross_bar) + IAMCrossbar_Release(cross_bar); + if (cross_bar_base_filter) + IBaseFilter_Release(cross_bar_base_filter); + } } else if (dialog & 1<<3) { // tv_tuner_dialog - // TODO + if (ctx->device_filter[devtype] && ctx->graph_builder2[devtype]) { + if (devtype == VideoDevice) { + IAMTVTuner *tv_tuner_filter = NULL; + IBaseFilter *tv_tuner_base_filter = NULL; + hr = ff_dshow_get_tvtuner_and_filter(ctx->graph_builder2[devtype], ctx->device_filter[devtype], tv_tuner_filter, tv_tuner_base_filter); + + if (hr == S_OK && tv_tuner_base_filter) + ff_dshow_show_filter_properties(tv_tuner_base_filter, avctx); + + if (tv_tuner_filter) + IAMTVTuner_Release(tv_tuner_filter); + if (tv_tuner_base_filter) + IBaseFilter_Release(tv_tuner_base_filter); + } else { + IAMAudioInputMixer *tv_audio_filter = NULL; + IBaseFilter *tv_audio_base_filter = NULL; + hr = ff_dshow_get_audiomixer_and_filter(ctx->graph_builder2[devtype], ctx->device_filter[devtype], tv_audio_filter, tv_audio_base_filter); + + if (hr == S_OK && tv_audio_base_filter) + ff_dshow_show_filter_properties(tv_audio_base_filter, avctx); + + if (tv_audio_filter) + IAMAudioInputMixer_Release(tv_audio_filter); + if (tv_audio_base_filter) + IBaseFilter_Release(tv_audio_base_filter); + } + } } break; } diff --git a/libavdevice/dshow_capture.h b/libavdevice/dshow_capture.h index bb0f76a8f2..127695a86b 100644 --- a/libavdevice/dshow_capture.h +++ b/libavdevice/dshow_capture.h @@ -318,6 +318,7 @@ struct dshow_ctx { IPin *device_pin[2]; DShowFilter *capture_filter[2]; DShowPin *capture_pin[2]; + ICaptureGraphBuilder2 *graph_builder2[2]; HANDLE mutex; HANDLE event[2]; /* event[0] is set by DirectShow @@ -352,6 +353,15 @@ struct dshow_ctx { HRESULT ff_dshow_try_setup_crossbar_options(ICaptureGraphBuilder2 *graph_builder2, IBaseFilter *device_filter, enum dshowDeviceType devtype, AVFormatContext *avctx); +HRESULT ff_dshow_get_crossbar_and_filter(ICaptureGraphBuilder2 *graph_builder2, IBaseFilter *device_filter, + IAMCrossbar *cross_bar, IBaseFilter **cross_bar_base_filter); + +HRESULT ff_dshow_get_tvtuner_and_filter(ICaptureGraphBuilder2 *graph_builder2, IBaseFilter *device_filter, + IAMTVTuner *tv_tuner_filter, IBaseFilter *tv_tuner_base_filter); + +HRESULT ff_dshow_get_audiomixer_and_filter(ICaptureGraphBuilder2 *graph_builder2, IBaseFilter *device_filter, + IAMAudioInputMixer *tv_audio_filter, IBaseFilter *tv_audio_base_filter); + void ff_dshow_show_filter_properties(IBaseFilter *pFilter, AVFormatContext *avctx); #endif /* AVDEVICE_DSHOW_CAPTURE_H */ diff --git a/libavdevice/dshow_crossbar.c b/libavdevice/dshow_crossbar.c index 961defe690..6b714e849c 100644 --- a/libavdevice/dshow_crossbar.c +++ b/libavdevice/dshow_crossbar.c @@ -133,6 +133,44 @@ setup_crossbar_options(IAMCrossbar *cross_bar, enum dshowDeviceType devtype, AVF return S_OK; } +HRESULT +ff_dshow_get_crossbar_and_filter(ICaptureGraphBuilder2 *graph_builder2, IBaseFilter *device_filter, + IAMCrossbar *cross_bar, IBaseFilter **cross_bar_base_filter) +{ + HRESULT hr = ICaptureGraphBuilder2_FindInterface(graph_builder2, &LOOK_UPSTREAM_ONLY, (const GUID *) NULL, + device_filter, &IID_IAMCrossbar, (void **) &cross_bar); + if (hr != S_OK) + /* no crossbar found */ + return hr; + + if (cross_bar_base_filter) + hr = IAMCrossbar_QueryInterface(cross_bar, &IID_IBaseFilter, (void**)cross_bar_base_filter); + + return hr; +} + +HRESULT +ff_dshow_get_tvtuner_and_filter(ICaptureGraphBuilder2 *graph_builder2, IBaseFilter *device_filter, + IAMTVTuner *tv_tuner_filter, IBaseFilter *tv_tuner_base_filter) +{ + HRESULT hr = ICaptureGraphBuilder2_FindInterface(graph_builder2, &LOOK_UPSTREAM_ONLY, NULL, + device_filter, &IID_IAMTVTuner, (void **) &tv_tuner_filter); + if (hr == S_OK) + hr = IAMCrossbar_QueryInterface(tv_tuner_filter, &IID_IBaseFilter, (void **) &tv_tuner_base_filter); + return hr; +} + +HRESULT +ff_dshow_get_audiomixer_and_filter(ICaptureGraphBuilder2 *graph_builder2, IBaseFilter *device_filter, + IAMAudioInputMixer *tv_audio_filter, IBaseFilter *tv_audio_base_filter) +{ + HRESULT hr = ICaptureGraphBuilder2_FindInterface(graph_builder2, &LOOK_UPSTREAM_ONLY, NULL, + device_filter, &IID_IAMTVAudio, (void **) &tv_audio_filter); + if (hr == S_OK) + hr = IAMCrossbar_QueryInterface(tv_audio_filter, &IID_IBaseFilter, (void **) &tv_audio_base_filter); + return hr; +} + /** * Given a fully constructed graph, check if there is a cross bar filter, and configure its pins if so. */ @@ -140,55 +178,42 @@ HRESULT ff_dshow_try_setup_crossbar_options(ICaptureGraphBuilder2 *graph_builder2, IBaseFilter *device_filter, enum dshowDeviceType devtype, AVFormatContext *avctx) { - struct dshow_ctx *ctx = avctx->priv_data; - IAMCrossbar *cross_bar = NULL; - IBaseFilter *cross_bar_base_filter = NULL; - IAMTVTuner *tv_tuner_filter = NULL; - IBaseFilter *tv_tuner_base_filter = NULL; - IAMAudioInputMixer *tv_audio_filter = NULL; - IBaseFilter *tv_audio_base_filter = NULL; + struct dshow_ctx *ctx = avctx->priv_data; + IAMCrossbar *cross_bar = NULL; + IBaseFilter *cross_bar_base_filter = NULL; + IAMTVTuner *tv_tuner_filter = NULL; + IBaseFilter *tv_tuner_base_filter = NULL; + IAMAudioInputMixer *tv_audio_filter = NULL; + IBaseFilter *tv_audio_base_filter = NULL; HRESULT hr; + int should_show_crossbar_properties = (devtype == VideoDevice) ? ctx->show_video_crossbar_connection_dialog : ctx->show_audio_crossbar_connection_dialog; - hr = ICaptureGraphBuilder2_FindInterface(graph_builder2, &LOOK_UPSTREAM_ONLY, (const GUID *) NULL, - device_filter, &IID_IAMCrossbar, (void**) &cross_bar); + hr = ff_dshow_get_crossbar_and_filter(graph_builder2, device_filter, cross_bar, should_show_crossbar_properties ? &cross_bar_base_filter : NULL); if (hr != S_OK) { - /* no crossbar found */ - hr = S_OK; + if (!cross_bar) + /* no crossbar found */ + hr = S_OK; goto end; } + /* TODO some TV tuners apparently have multiple crossbars? */ - if (devtype == VideoDevice && ctx->show_video_crossbar_connection_dialog || - devtype == AudioDevice && ctx->show_audio_crossbar_connection_dialog) { - hr = IAMCrossbar_QueryInterface(cross_bar, &IID_IBaseFilter, (void **) &cross_bar_base_filter); - if (hr != S_OK) - goto end; + if (should_show_crossbar_properties && cross_bar_base_filter) ff_dshow_show_filter_properties(cross_bar_base_filter, avctx); - } if (devtype == VideoDevice && ctx->show_analog_tv_tuner_dialog) { - hr = ICaptureGraphBuilder2_FindInterface(graph_builder2, &LOOK_UPSTREAM_ONLY, NULL, - device_filter, &IID_IAMTVTuner, (void**) &tv_tuner_filter); - if (hr == S_OK) { - hr = IAMCrossbar_QueryInterface(tv_tuner_filter, &IID_IBaseFilter, (void **) &tv_tuner_base_filter); - if (hr != S_OK) - goto end; + hr = ff_dshow_get_tvtuner_and_filter(graph_builder2, device_filter, tv_tuner_filter, tv_tuner_base_filter); + if (hr == S_OK && tv_tuner_base_filter) ff_dshow_show_filter_properties(tv_tuner_base_filter, avctx); - } else { + else av_log(avctx, AV_LOG_WARNING, "unable to find a tv tuner to display dialog for!"); - } } if (devtype == AudioDevice && ctx->show_analog_tv_tuner_audio_dialog) { - hr = ICaptureGraphBuilder2_FindInterface(graph_builder2, &LOOK_UPSTREAM_ONLY, NULL, - device_filter, &IID_IAMTVAudio, (void**) &tv_audio_filter); - if (hr == S_OK) { - hr = IAMCrossbar_QueryInterface(tv_audio_filter, &IID_IBaseFilter, (void **) &tv_audio_base_filter); - if (hr != S_OK) - goto end; + hr = ff_dshow_get_audiomixer_and_filter(graph_builder2, device_filter, tv_audio_filter, tv_audio_base_filter); + if (hr == S_OK && tv_audio_base_filter) ff_dshow_show_filter_properties(tv_audio_base_filter, avctx); - } else { + else av_log(avctx, AV_LOG_WARNING, "unable to find a tv audio tuner to display dialog for!"); - } } hr = setup_crossbar_options(cross_bar, devtype, avctx); From patchwork Fri Jun 11 20:30:48 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: 28214 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp764946iol; Fri, 11 Jun 2021 13:36:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw38KZPxXV8epoKcXRo0Y+82z5Sv1KvNVkKsZMAlPBI6h+UdY8jy3AYyKGIm7++jN0O0nhs X-Received: by 2002:aa7:ca1a:: with SMTP id y26mr5435467eds.314.1623443793008; Fri, 11 Jun 2021 13:36:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443793; cv=none; d=google.com; s=arc-20160816; b=Xdndp72NFfQ7d+dHlQVGBBaAkxXBuxO+ugWQVafhTugML9LniarQp219J/A4oQRCfK +52ejHCGRzOusPlOBrs9T1m6lYAP5Og+eICOnSC/581ODlAb/G1Eaeev9MtIkTlhFM9Y Tx8tH5KDM3qiKMYO6GW+FljlZfROmoszKIkXSgfRI1uYZmzqo8p5SvtK3I7adrbHV2uc HR4YSv9Jb8b3BwNSc10K7xYZs9fT51tNxsF0b2sb3GGIhkcm0GOE3DBNaFmGQPioPA22 94mtU9jy04glaJ63qS3D9YmfbMp3eIKTv/r1f1H7Brr0Ta5X2AJDLAT2IJtw0BAvKgId 4Sxg== 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=rmCQgPMQ5fQ2XDD/LM7i3AUtovhmxjtVkc4wttaHhsk=; b=LgHrhwvZKxS/QDosw2BgFC7OEa2ejv55uR+zSxpYQnX8GUAarx4pKc4UWrlMSS4HQ1 EnhoCTQdfagYORMHf2E/VnfxIqg6Vx5lhdJ7lXRiZ0U3SkdKcMtO0wCm9P2MCACC+jc4 l8BDEkQnfBl/vxnqZLlO1FQP+McGZyOyYodbfyTk8L3WqKt6c3K5Ln/Cgrf/FVkbdNuV DforqgXyx9UJEbwNWLbb4CXolj1OEdXhrZHlOFdse/jWvxSEK/N6/adoSFiIjg/ZEtDP 9KoCpKEw1NUsS3EnpPoF8e/c1idGCO2CZrihkInuK/L5ee3O6n/nPiAjtzsffD7f9fP8 932Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=A2aleIuk; 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 s16si5587247edr.339.2021.06.11.13.36.32; Fri, 11 Jun 2021 13:36:32 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=A2aleIuk; 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 7B8FC689953; Fri, 11 Jun 2021 23:36:28 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 624AB689888 for ; Fri, 11 Jun 2021 23:36:27 +0300 (EEST) Received: by mail-lj1-f170.google.com with SMTP id c11so11302435ljd.6 for ; Fri, 11 Jun 2021 13:36:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TE4pQexxKpuMxaxw+XpswcO3ST7+W3ej+mMWH6D3ols=; b=A2aleIukk3wQNMfoUXjLC07pJeHM+fWILsiNZDUBIvnUMpnCe4S6OLwTGwpyATdrRf sK6DLC7qJE7vZ8Ny805iiQkdeiC7Ax8OHcb3D/56bbd6iJYzDcx9TrRHdcVFZyWwU3Jm zVGpgQjkVYke8MfrO7z60aKALSu+ady+5mc8eX0H0dnCA+1KsV10E2JA4hcBmhkBFeYH N/NxznmrIb4rfYZz+L0bq82Drmaz1jEXR2qRW7sfQc0X4UJUO5f75q3OYbvZ5uqusKkr Ie1y3RfYpZHi/f9rqErRX3HxwaCovKNzoALyd2WkfK1numKTJrAAwh7vlxulkLYDu1rp 7bnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TE4pQexxKpuMxaxw+XpswcO3ST7+W3ej+mMWH6D3ols=; b=oEqcOVtBU5x99CzKzjjzmOJP9wIMz1dSDKdgjS72G1bzCTcvBsZ5xiOYrk16rO4Vtv mcwkOTgErXrAk/T/wbA/kbe5yRnx4R/B3OAb2A1u4ZSv0XXEaK/ieA/WBKSlc2gMBHOv MefoU2M8+U1KTSt/VEw5QGZmHadtX+10en4Udf9TGuTJrnDkn5f73734tsptVcDXbndc p+OZ1XVfQxPyJQTJSEQad+Ujtc5xvzF6s9/H0Yq+2NHvqmJFIbK5665ITd9qjh4AFKlF fiVJkq8x91/RI5U+8TwHq9KqCW3I1WJMY8yOu1j8YzjpgOiFcqIswdrUObl/TkY01xAg KNYw== X-Gm-Message-State: AOAM531/Qj1bLi4o1JdJJ7huMsi8rnXvl9k/mUCC1EQcljICzODO6Qxu gun3MFxPB86YX80OFoiTqb8teoqx4Y+1vg== X-Received: by 2002:a2e:844a:: with SMTP id u10mr4401493ljh.443.1623443786105; Fri, 11 Jun 2021 13:36:26 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id m19sm686637lfb.121.2021.06.11.13.36.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:36:25 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:48 +0200 Message-Id: <20210611203104.1692-18-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 17/33] 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: FAxbe8W6sEYe 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. Signed-off-by: Diederick Niehorster Co-authored-by: Valerii Zapodovnikov Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 250 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 249 insertions(+), 1 deletion(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index add46e82ac..b3fcd9444e 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -29,6 +29,26 @@ #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" static enum AVPixelFormat dshow_pixfmt(DWORD biCompression, WORD biBitCount) @@ -54,6 +74,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) { @@ -522,6 +728,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, VIDEO_STREAM_CONFIG_CAPS *vcaps = caps; BITMAPINFOHEADER *bih; int64_t *fr; + DXVA_ExtendedFormat *extended_format_info = NULL; const AVCodecTag *const tags[] = { avformat_get_riff_video_tags(), NULL }; #if DSHOWDEBUG ff_print_VIDEO_STREAM_CONFIG_CAPS(vcaps); @@ -534,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 = (DXVA_ExtendedFormat*)&v->dwControlFlags; } else { goto next; } @@ -550,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) { @@ -1233,6 +1471,7 @@ dshow_add_device(AVFormatContext *avctx, if (devtype == VideoDevice) { BITMAPINFOHEADER *bih = NULL; AVRational time_base; + DXVA_ExtendedFormat* extended_format_info = NULL; if (IsEqualGUID(&type.formattype, &FORMAT_VideoInfo)) { VIDEOINFOHEADER *v = (void *) type.pbFormat; @@ -1242,6 +1481,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 = (DXVA_ExtendedFormat*)&v->dwControlFlags; } if (!bih) { av_log(avctx, AV_LOG_ERROR, "Could not get media type.\n"); @@ -1260,6 +1501,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 Fri Jun 11 20:30:49 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: 28225 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp765133iol; Fri, 11 Jun 2021 13:36:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmaaMv26xxOYsEVxf7JyrwVq1nn02OsikZ6Ifb494aTIz6TojTIYe8DX/9E54oPIs+464F X-Received: by 2002:a17:906:7c49:: with SMTP id g9mr5321872ejp.84.1623443814711; Fri, 11 Jun 2021 13:36:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443814; cv=none; d=google.com; s=arc-20160816; b=OoPkzGLYm4kgszXv6gSctf5E3fMRyqYjsUjLVEm5ivSjYJ/RiRcg1Bc6TyrsIwAuQ6 M35lxAleS0jz4IZTw1sTPsbcjTLOQY5Wm4zftCSV72cNpsHbqpg+TmSgIW724nGzf1tG N+5xps/o6zSYzcIIrEQ5rNNpaDLAWj7YNzLo6OpyVquo0JvINAAYLAQKLSyZ81qYiq+G zZKMZ1w/oEPJRD1oJZvrpHVSx25akwvNBedRGPgd6o4FjYXtN8NgrjvpNLFaEV4j9k96 VMdb31V124yXtcs+6WF1wet97HO/IpGzdB8fmE7VVqnFAYJLuQpaPT0dx2O0+nTmqaB2 ZIMA== 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=P65C2ImregTsFGkfdUpKnEpqyTiE1dSi3DCGEN4NT4Y=; b=vktpivrbbI9K8WjsM0nZdfK2s+nzTpkQD25qDT4hJefZGKyl6d/ra5svO2VoJR97V1 u07HAwj+uUNVZEaVArD1Ojbh/ky978Ee2EhDirxmqoSspMEv/tBcnNuTHM+du9h4Zq2o qq8hsDJa8VQ+iO1nyda/nweCp4+cTw2KOxxh++B9/Nu4WITK0ijbmHHqv4NSyAxyyQsW dZ60jiB2wHVLGMs12cj9cBy3tQQfKE/kBLkwPF6HuJoAYLF3C78E9firsyKm0M+7iEGm KV9D91wBSey/0VL5gVfy+NFZoqWhP2VZr5wTbjFJkaFHOMMOFjh1htCzsWx5buaq+zdZ F5QA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=nQxaMOYe; 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 yc20si5475915ejb.387.2021.06.11.13.36.54; Fri, 11 Jun 2021 13:36:54 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=nQxaMOYe; 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 5F794689884; Fri, 11 Jun 2021 23:36:51 +0300 (EEST) 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 026E3688388 for ; Fri, 11 Jun 2021 23:36:45 +0300 (EEST) Received: by mail-lj1-f179.google.com with SMTP id r16so11288459ljk.9 for ; Fri, 11 Jun 2021 13:36:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oFvt3auICRkG8MFKLrLyih0PjQJVmaYb9ShJQetAS5I=; b=nQxaMOYeoc3VvWm4yRNLH37eek14we63eZj6TGGH9R1lNosQTbqUKL4YMaJZcwMsxz LfyR7Ozqn0dNidDdRNuf4K+LWfr4UVigr+qkKlvy3jBLntT+fOqzU2vA6QKp26Gs3zcx EEfkP2ir8BBxK2L2Js2yoC2jVTty8YRfwRjPG+ohKJF/352x5WeKYvIYHU7buA0cee74 KZy/lUhOJB0QHBft172SK9fiDY+6GV6wwcbvl68uV6hsiD9d+PUWvkKWfqSMsLGVBL6Z w6gnQd6MZ8TKKqT9g733NNwT9lVhyndJCqFaX/gPRj1rlN8V07GOvlvvkQ4I1a4Bf9LL 0sNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oFvt3auICRkG8MFKLrLyih0PjQJVmaYb9ShJQetAS5I=; b=m0Eg1dK1YhEDMn+7ko40KnpYZErO6BOcNzUAizcwa9Za5PJD1MsdyQvOzDo5iBLelu dhEK7HrjDpEn8ZzXpZxP1BOBAxrIuMnN/VLUpzte8HwjJnU/YgEYo8rcjy2CIt2IuGAV AkzbgFRXs4oVt3WF7FQ8ef6kwXq+sxQ8wSAXu0da1sfdhaXya39t8BH8L1uETK1bEUa4 wFAO74B0GN0o6XjL9RM7kvyABNzYLs3t4xrkjz9/kx6HCvvx5vOOEbMBbG37KWDGceUl FbNGFW2qEsuaIy3r1LvecaC2uWZRPEKQkALn+FFdi7neu568sUC4N66A/Lc2zjl41vdr q6ew== X-Gm-Message-State: AOAM530nBXMp0aRUj3GkPfMuSLt1VRaiM8nR86stsBQ3hh0cM03/GFBk /33vF4KZonPlLvcj4El+vRQiaEnDlOe1Tw== X-Received: by 2002:a2e:b60d:: with SMTP id r13mr4466304ljn.314.1623443803729; Fri, 11 Jun 2021 13:36:43 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id x19sm745216lfe.270.2021.06.11.13.36.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:36:43 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:49 +0200 Message-Id: <20210611203104.1692-19-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 18/33] 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: HicXypt151xv 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 | 460 ++++++++++++++++++++++++++++++++------------ 1 file changed, 332 insertions(+), 128 deletions(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index b3fcd9444e..34c7b63220 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,84 @@ 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 video formats + 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,101 +922,96 @@ 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; - DXVA_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 = (DXVA_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 { AUDIO_STREAM_CONFIG_CAPS *acaps = caps; @@ -837,34 +1030,63 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, acaps->MaximumChannels, acaps->MaximumBitsPerSample, acaps->MaximumSampleFrequency); continue; } - if (ctx->sample_rate) { - if (ctx->sample_rate > acaps->MaximumSampleFrequency || - ctx->sample_rate < acaps->MinimumSampleFrequency) + if (requested_sample_rate) { + if (requested_sample_rate > acaps->MaximumSampleFrequency || + requested_sample_rate < acaps->MinimumSampleFrequency) goto next; - fx->nSamplesPerSec = ctx->sample_rate; + fx->nSamplesPerSec = requested_sample_rate; } - if (ctx->sample_size) { - if (ctx->sample_size > acaps->MaximumBitsPerSample || - ctx->sample_size < acaps->MinimumBitsPerSample) + if (requested_sample_size) { + if (requested_sample_size > acaps->MaximumBitsPerSample || + requested_sample_size < acaps->MinimumBitsPerSample) goto next; - fx->wBitsPerSample = ctx->sample_size; + fx->wBitsPerSample = requested_sample_size; } - if (ctx->channels) { - if (ctx->channels > acaps->MaximumChannels || - ctx->channels < acaps->MinimumChannels) + if (requested_channels) { + if (requested_channels > acaps->MaximumChannels || + requested_channels < acaps->MinimumChannels) goto next; - fx->nChannels = ctx->channels; + 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) + if (fmt_info) + av_free(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) @@ -983,11 +1205,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)); + 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; @@ -1007,9 +1225,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; @@ -1052,35 +1268,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) @@ -1452,6 +1657,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; @@ -1466,12 +1672,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; - DXVA_ExtendedFormat* extended_format_info = NULL; if (IsEqualGUID(&type.formattype, &FORMAT_VideoInfo)) { VIDEOINFOHEADER *v = (void *) type.pbFormat; @@ -1481,8 +1689,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 = (DXVA_ExtendedFormat*)&v->dwControlFlags; } if (!bih) { av_log(avctx, AV_LOG_ERROR, "Could not get media type.\n"); @@ -1493,33 +1699,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) { @@ -1532,6 +1726,14 @@ 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; @@ -1556,6 +1758,8 @@ dshow_add_device(AVFormatContext *avctx, ret = 0; error: + if (fmt_info) + av_free(fmt_info); if (type.pbFormat) CoTaskMemFree(type.pbFormat); return ret; @@ -1858,8 +2062,8 @@ 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, .control_message = dshow_control_message, + .get_device_list= dshow_get_device_list, .flags = AVFMT_NOFILE | AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK, .priv_class = &dshow_class, }; From patchwork Fri Jun 11 20:30:50 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: 28221 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp765303iol; Fri, 11 Jun 2021 13:37:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9YTXSE2C1mlqvc572fXa9Be3XIU9eH5l1hBJycfMkbrlQrLaQIW3u07gW6yx2NkiJeO7v X-Received: by 2002:a17:906:a294:: with SMTP id i20mr5276060ejz.330.1623443828321; Fri, 11 Jun 2021 13:37:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443828; cv=none; d=google.com; s=arc-20160816; b=PPMPnzCFwtaqQfxvJgBa2oIkBOcBMdsSm5puM249mAnQlarjBDFL8/rZ/cbXaF6CnN +7EbRuuER5KmkRsDSMOcaQmfRWUG+ch8jix1bZyiMfQkP2NHLLqMuGfF/xcENf1gE5Nf UpUf4VSRyuaejO8sYDEEPqvlvYlBzPIk/uCk0MEbkOycE73o2HyypuFTgsmcqumtmdIu RfIeGfzkCos052ABuDTCOmP6qukM2KcDLosdJog8n5fFQiVK44I3/w6/u3wlLsG4sZWd ZZLE38yitReqEgYJ16pf7dwDpy+Krg8OiQtSvSSf9LkU3KIJAHJ1VA6HNzgtw6z4B/gP ULlQ== 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=8mu2Nsq5ufSmfGyj6YKVBXfqYJ5IMvy8MGTzRw7+Dyk=; b=HNf+J2DMmTtN93K7hVgzlghCY2/GleHNpo2uCGCO3x9RolJ/zzACmI7jw3B3zgZ4HH arydTSP5X7Z8EzLfSrwa+Uumoi/p/lorB5h9dc6qgp+1xPcN+VNDXtEeSfVhlyF1oMd1 2ESkt6oJ/ROYZKO/uq3pAWPmq5ETyZL1IXoKRi3NG+1GDsJpW5kEf+ZFEDLcNiqZX+3H UdFXi98aEhC7Z9h51lfERsoYHeWv4yIeU4X/hnMgsGsXd43cFsU0Li86/UnldkKGLxTA 5TSPylQd6/quNWv0YHbjDFG4psR0yie6Rf38iSAvX3JbB05F7Z1oCKT9q0ubvLAx76o5 7zkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=SfYtdUc9; 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 u23si5863685edi.175.2021.06.11.13.37.07; Fri, 11 Jun 2021 13:37:08 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=SfYtdUc9; 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 637BF6808CC; Fri, 11 Jun 2021 23:37:04 +0300 (EEST) 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 DCFE76808CC for ; Fri, 11 Jun 2021 23:37:01 +0300 (EEST) Received: by mail-lf1-f52.google.com with SMTP id p7so10387952lfg.4 for ; Fri, 11 Jun 2021 13:37:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=l1eLY/v/V4skxYZ7ZTRZY0QUE3Et6Oq3M/DuBR/5lZc=; b=SfYtdUc9W5kCKLIkEBDqMvRN7jI6RX0ndwfsa+FNnnxIqGMO8iYdJkPgK4QUcpK/Ta 6phlk5+E5qRG3BLs+F1Ypmml1Th63BMOoJvMLarh0iXJ5IgVfJkPzoD4u7l00cBEwkF5 OqkJ91vCIMqo5hoAeAWELVk1opnOl48ziqSKKSusCYzAT7XH/btDYuR+QWqcnl2GjiME IrcqWxoAgd/qS2uJT1Ct60LOrE2H7YG1H9PpVWpWtPUoRuk1bIgbWDDm8fZWEOPKOjQ2 rop638EdlJP4K1mhRWxFR2gkqWaYBze3i5iIVGRoS1TzSs3N/3yQfeu3nQXpXIcbaLBR 61FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=l1eLY/v/V4skxYZ7ZTRZY0QUE3Et6Oq3M/DuBR/5lZc=; b=Ak/4IXIvtwQhC30WNuC0SeqOWDN89JGo7UubIR7rP2n1a0iCXiB0zBMWIKSKy6t/Wp epI8rAk2ogIvfuMMhH82M+YlnhsdjdcYz6wG10YIU7xxpoR/5UHRO5v/Vja16ocdpGMc goTrvunzYQEent9koZLQRedh/muyP8CQpGt60J1oJ94MhKL/dKgtM47UoFkdhox7qfe8 lH3+HqRi9Qg8lPcW4B8vHKO2JNhRMOO1LwyOSBv7/CJqxFwG/x5S+IuEdsgXmTXxxMpB RVeBJu6wFay3FSue+KwXxaBuchq1nomH9/dU+P2BR2mCoIiPloVYI6dDmtMEAvaXKK7I IhJQ== X-Gm-Message-State: AOAM533qwWBqa+Su+T0B/17sxYgmE3eKiH8mkg8gdaxhrcCt6rtOiq1p vYmiIm9ccu7TW7T6MotvuAWggKaIb7rF1w== X-Received: by 2002:a05:6512:39ca:: with SMTP id k10mr3789381lfu.473.1623443820690; Fri, 11 Jun 2021 13:37:00 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id o6sm685129lfg.212.2021.06.11.13.36.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:37:00 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:50 +0200 Message-Id: <20210611203104.1692-20-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 19/33] avdevice/avdevice: Revert "Deprecate AVDevice Capabilities API" 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: nAiXQriKMKG0 This reverts commit 4f49ca7bbc75a9db4cdf93f27f95a668c751f160. The next few patches clean up the API and implement this capability for avdevice/dshow. Signed-off-by: Diederick Niehorster --- libavdevice/avdevice.c | 71 ++++++++++++++++++++++++++++++++++++++---- libavdevice/avdevice.h | 5 --- libavformat/avformat.h | 21 +++++++++++++ 3 files changed, 86 insertions(+), 11 deletions(-) diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c index e339cebf2d..695b9143af 100644 --- a/libavdevice/avdevice.c +++ b/libavdevice/avdevice.c @@ -27,11 +27,39 @@ #include "libavutil/ffversion.h" const char av_device_ffversion[] = "FFmpeg version " FFMPEG_VERSION; -#if FF_API_DEVICE_CAPABILITIES +#define E AV_OPT_FLAG_ENCODING_PARAM +#define D AV_OPT_FLAG_DECODING_PARAM +#define A AV_OPT_FLAG_AUDIO_PARAM +#define V AV_OPT_FLAG_VIDEO_PARAM +#define OFFSET(x) offsetof(AVDeviceCapabilitiesQuery, x) + const AVOption av_device_capabilities[] = { + { "codec", "codec", OFFSET(codec), AV_OPT_TYPE_INT, + {.i64 = AV_CODEC_ID_NONE}, AV_CODEC_ID_NONE, INT_MAX, E|D|A|V }, + { "sample_format", "sample format", OFFSET(sample_format), AV_OPT_TYPE_SAMPLE_FMT, + {.i64 = AV_SAMPLE_FMT_NONE}, AV_SAMPLE_FMT_NONE, INT_MAX, E|D|A }, + { "sample_rate", "sample rate", OFFSET(sample_rate), AV_OPT_TYPE_INT, + {.i64 = -1}, -1, INT_MAX, E|D|A }, + { "channels", "channels", OFFSET(channels), AV_OPT_TYPE_INT, + {.i64 = -1}, -1, INT_MAX, E|D|A }, + { "channel_layout", "channel layout", OFFSET(channel_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, + {.i64 = -1}, -1, INT_MAX, E|D|A }, + { "pixel_format", "pixel format", OFFSET(pixel_format), AV_OPT_TYPE_PIXEL_FMT, + {.i64 = AV_PIX_FMT_NONE}, AV_PIX_FMT_NONE, INT_MAX, E|D|V }, + { "window_size", "window size", OFFSET(window_width), AV_OPT_TYPE_IMAGE_SIZE, + {.str = NULL}, -1, INT_MAX, E|D|V }, + { "frame_size", "frame size", OFFSET(frame_width), AV_OPT_TYPE_IMAGE_SIZE, + {.str = NULL}, -1, INT_MAX, E|D|V }, + { "fps", "fps", OFFSET(fps), AV_OPT_TYPE_RATIONAL, + {.dbl = -1}, -1, INT_MAX, E|D|V }, { NULL } }; -#endif + +#undef E +#undef D +#undef A +#undef V +#undef OFFSET unsigned avdevice_version(void) { @@ -68,18 +96,49 @@ int avdevice_dev_to_app_control_message(struct AVFormatContext *s, enum AVDevToA return s->control_message_cb(s, type, data, data_size); } -#if FF_API_DEVICE_CAPABILITIES int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s, AVDictionary **device_options) { - return AVERROR(ENOSYS); + int ret; + av_assert0(s && caps); + av_assert0(s->iformat || s->oformat); + if ((s->oformat && !s->oformat->create_device_capabilities) || + (s->iformat && !s->iformat->create_device_capabilities)) + return AVERROR(ENOSYS); + *caps = av_mallocz(sizeof(**caps)); + if (!(*caps)) + return AVERROR(ENOMEM); + (*caps)->device_context = s; + if (((ret = av_opt_set_dict(s->priv_data, device_options)) < 0)) + goto fail; + if (s->iformat) { + if ((ret = s->iformat->create_device_capabilities(s, *caps)) < 0) + goto fail; + } else { + if ((ret = s->oformat->create_device_capabilities(s, *caps)) < 0) + goto fail; + } + av_opt_set_defaults(*caps); + return 0; + fail: + av_freep(caps); + return ret; } void avdevice_capabilities_free(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s) { - return; + if (!s || !caps || !(*caps)) + return; + av_assert0(s->iformat || s->oformat); + if (s->iformat) { + if (s->iformat->free_device_capabilities) + s->iformat->free_device_capabilities(s, *caps); + } else { + if (s->oformat->free_device_capabilities) + s->oformat->free_device_capabilities(s, *caps); + } + av_freep(caps); } -#endif int avdevice_list_devices(AVFormatContext *s, AVDeviceInfoList **device_list) { diff --git a/libavdevice/avdevice.h b/libavdevice/avdevice.h index bbeb1ae21b..6443f865d5 100644 --- a/libavdevice/avdevice.h +++ b/libavdevice/avdevice.h @@ -331,7 +331,6 @@ int avdevice_dev_to_app_control_message(struct AVFormatContext *s, enum AVDevToAppMessageType type, void *data, size_t data_size); -#if FF_API_DEVICE_CAPABILITIES /** * Following API allows user to probe device capabilities (supported codecs, * pixel formats, sample formats, resolutions, channel counts, etc). @@ -427,7 +426,6 @@ typedef struct AVDeviceCapabilitiesQuery { /** * AVOption table used by devices to implement device capabilities API. Should not be used by a user. */ -attribute_deprecated extern const AVOption av_device_capabilities[]; /** @@ -447,7 +445,6 @@ extern const AVOption av_device_capabilities[]; * * @return >= 0 on success, negative otherwise. */ -attribute_deprecated int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s, AVDictionary **device_options); @@ -457,9 +454,7 @@ int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatConte * @param caps Device capabilities data to be freed. * @param s Context of the device. */ -attribute_deprecated void avdevice_capabilities_free(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s); -#endif /** * Structure describes basic parameters of the device. diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 7e9db81d26..54457572b1 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -583,6 +583,16 @@ typedef struct AVOutputFormat { * @see avdevice_list_devices() for more details. */ int (*get_device_list)(struct AVFormatContext *s, struct AVDeviceInfoList *device_list); + /** + * Initialize device capabilities submodule. + * @see avdevice_capabilities_create() for more details. + */ + int (*create_device_capabilities)(struct AVFormatContext *s, struct AVDeviceCapabilitiesQuery *caps); + /** + * Free device capabilities submodule. + * @see avdevice_capabilities_free() for more details. + */ + int (*free_device_capabilities)(struct AVFormatContext *s, struct AVDeviceCapabilitiesQuery *caps); enum AVCodecID data_codec; /**< default data codec */ /** * Initialize format. May allocate data here, and set any AVFormatContext or @@ -754,6 +764,17 @@ typedef struct AVInputFormat { */ int (*get_device_list)(struct AVFormatContext *s, struct AVDeviceInfoList *device_list); + /** + * Initialize device capabilities submodule. + * @see avdevice_capabilities_create() for more details. + */ + int (*create_device_capabilities)(struct AVFormatContext *s, struct AVDeviceCapabilitiesQuery *caps); + + /** + * Free device capabilities submodule. + * @see avdevice_capabilities_free() for more details. + */ + int (*free_device_capabilities)(struct AVFormatContext *s, struct AVDeviceCapabilitiesQuery *caps); } AVInputFormat; /** * @} From patchwork Fri Jun 11 20:30:51 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: 28215 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp765493iol; Fri, 11 Jun 2021 13:37:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+OA4gmiDjw22hBXErqVGTnVLMbGqvu4cO53yA0kjx2S2JqR3AHjGNur1exZn4oYfJb0uB X-Received: by 2002:a05:6402:10d7:: with SMTP id p23mr5446821edu.74.1623443849215; Fri, 11 Jun 2021 13:37:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443849; cv=none; d=google.com; s=arc-20160816; b=aTzH5NsBzDm1xVoaCRc/ZauwbDfLbb9A0FAnO7BjPC/wi/9O/mspFyXNauXSLCuYH4 yQVLRjFwgAw8FossdK3Q8lUVGaeaav92PmJJwdYbqhgQRWKusewpVflPP9TgJM8XfZYV nxSHXxeU3rv+8CQw/YCIizBb02K4HW5SqMzJ+LTKt4GoRW4XhQgDsGU2ddqPM1rNd/y9 FT2LOXhHM75X4Huj4XtuYxXwqk9DksbbjV3ET3ciCE/J12mFSiB42fOqknun3rNfDpce tKfmUsWb3IxjH/zIZx5fWv6N9G7FYFED1OzRv5sfax0OJURndZv/Z+lmlJdGyb9xfo+L yGBQ== 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=+kuaml8ht81jUriUkajf/mq3rOInxGfJrVd2RDKJg9U=; b=MxwMAVAEGwTpQuWxgqrJJ43QN8H0n+uidyQYONiQuq+/0eml+OgdVVIzsmhSyrNYkS Xxs52pDbw+FhjpUTvZ6aXVfOSIwrkQ+twk3TmY/PN73SHL1zy+w7iQlGIfvySIUijHN/ 1Wis5S85MQdTT12odhoOshVpxcvBJhOchjXgNSGWicnMuL3i5C2FKHH5BaLftREsrRgw OOVeBU90gAhXz80sF/QqYGVh8a+Hnj9lAt1soHSOq6PAoW2qqZX2OCCBu/VWY7lH57Mn qI49ElwwLOd24Lrb5aUmI+fkth8TFS8WtdWmWjmOkyf1kkE5HyTivO3oE/KgsIkXTn3b IJsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=RfpY7g+g; 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 jv9si5670272ejc.70.2021.06.11.13.37.28; Fri, 11 Jun 2021 13:37:29 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=RfpY7g+g; 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 67C51688388; Fri, 11 Jun 2021 23:37:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 51B7F689902 for ; Fri, 11 Jun 2021 23:37:18 +0300 (EEST) Received: by mail-lf1-f50.google.com with SMTP id a1so10322585lfr.12 for ; Fri, 11 Jun 2021 13:37:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qkbHYUrU14uDT19T+xY2ZYh7EkHJUnhKrc8Ot4TNgRo=; b=RfpY7g+gPbWLG/wQyVKWDTbvCEZSNc6XUb/B8QulAWFmzhyUQLGGOazVTThEd0RURw dWM/rs3kHs15uKdPziRFRjXXidRBlvZu6dYT8VCtyxBufueVfASK8ZveDgLPijCpnA+K Qt2Mcd+Nsx4KEziaUbKqKLdQqXBPXrxb4E22yIDnQBuE10cqv0tgaab8tOkWyIuhp/L2 LWhcLg/v9UQunnwnJTI5KutgoZO/FrnJXNp3gGGiUaS/8bVurEsaXfL1MNH33LZIIqml 4q4+eQAe3KUu93jJoJU9nIPzkHlFhVC3tU4Liy5Guh2MYftbxEIO8opg+cgAKsR9wkfV thYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qkbHYUrU14uDT19T+xY2ZYh7EkHJUnhKrc8Ot4TNgRo=; b=H4ghLDXrN0n7WbZHtstU2Q3Ja6RfzPrDB5YwLlmeWNpym+cQ1hV90uY40ovqAYQGW2 OQnTQeFvglLFqTJJ+cYf9SKBiewLgAudzcSj+JBeL6xcHUFI1XWw++jGVLJ6NgJAIEfb 3JGWL5hQGSeXiXJ2g7ECIjH5AFTAIkKX+PdHCAgxnNVmzyPvWY79EfjQEpgSmotAfJ1i Pf0N0I43so8Elw4NV38GoWRd+2lrIuSV/IxqR1xLkv6QBBsnXYrzwmLsx2I9L1WOYlt4 H7sWil+AO6sdljFY4O3UDftMsx/rsWLSQbBlgsp3A8F05VofGILEVn4VAaX/HT1xqn3A NsZg== X-Gm-Message-State: AOAM531jXf75G52kSYgGo6ItdTWHVNdMSp2erbslX0dU7GBj9K3i3qMw /T8ZIS2NR7AMnY9znMX9M7j/S6cFc8rU7A== X-Received: by 2002:a05:6512:2283:: with SMTP id f3mr3731349lfu.523.1623443837468; Fri, 11 Jun 2021 13:37:17 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id 10sm745339lfq.160.2021.06.11.13.37.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:37:17 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:51 +0200 Message-Id: <20210611203104.1692-21-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 20/33] avdevice/avdevice: clean up avdevice_capabilities_create 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: Z4gVpgXrjpIp Draw implementation in line with that of avdevice_list_devices Signed-off-by: Diederick Niehorster --- libavdevice/avdevice.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c index 695b9143af..e66906e91b 100644 --- a/libavdevice/avdevice.c +++ b/libavdevice/avdevice.c @@ -100,11 +100,14 @@ int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatConte AVDictionary **device_options) { int ret; - av_assert0(s && caps); + av_assert0(s); + av_assert0(caps); av_assert0(s->iformat || s->oformat); if ((s->oformat && !s->oformat->create_device_capabilities) || - (s->iformat && !s->iformat->create_device_capabilities)) + (s->iformat && !s->iformat->create_device_capabilities)) { + *caps = NULL; return AVERROR(ENOSYS); + } *caps = av_mallocz(sizeof(**caps)); if (!(*caps)) return AVERROR(ENOMEM); From patchwork Fri Jun 11 20:30:52 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: 28229 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp765729iol; Fri, 11 Jun 2021 13:37:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQrefZc2xnPV8TCG4heI6WebVdDBaQmtMjZYlYNJjNoWRPcNNQ+8a27PMIx1ileAzrt2jl X-Received: by 2002:a17:906:c1d2:: with SMTP id bw18mr5194810ejb.123.1623443870576; Fri, 11 Jun 2021 13:37:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443870; cv=none; d=google.com; s=arc-20160816; b=Xrw+HD8X9kEkiLyCly4JhaEAszmkQm+r/MfeuaalDDOqKy0G9NDl8A9sjqQ1TLGZke ucHVvxtOWsDaeaSYYaRUrSHi2ROwf+MJ5pUrit4SlKVXXXXG8iQfxECd+et6IxPUCCOs 7zbjYUipeypNanoIppGih28kjzFIJ+xKVjhcdjO84uf7onPXc/WKotZiN3hIsy6Dki/N CNSE9tv5m73s+eY0DqxgDk5hv1dWdEFf/ZWqdyol/f/9yW5yDDPUMWE50mFiezVsfmOf Wp4gYSDzFh3JVj7HxjFstyxrbEQXmz/2XcNhrxxqEaUAf4mORtMk8sVObVH9VJYdQJfs F7+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=YlSTOPXLyhOZIYdaJBIwYauJhjf0J8qEzMi/oB8L8NI=; b=mOBeDxObTwwbIJY7fLxDc4fOkUI5Y9vomTCkH4EuZ/8uuN7qVCoekZoR5/cIxv/qKC 2uEPS3fhwOUseZdFPnW63628txmNE9FjGuAENfEiE8jRwu27cJdl1N3FK6uhDzDqr8ai EVmdDyWix1hSobgi6kGxSbg/nY9a2L0hJeNSNFQBdxqBl3jxa+XhHGfObbFmE6OHwjdl UUY2ZlovN/6oylfWKN5plmk1y80eq2jo/iMDDUVgrGTxw88k9Sa11wUtVyjjhmVF/BrT 5/jdbX6hc8e2HxTSrFd5ZajJQ4wT/1tYiip9qMwfFtUzD2dHZuhYMdfg7hr9B9cJbPLb +ylw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=TpAIB0Uv; 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 b10si1620577ede.515.2021.06.11.13.37.50; Fri, 11 Jun 2021 13:37:50 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=TpAIB0Uv; 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 7B6B2689A1E; Fri, 11 Jun 2021 23:37:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2A19F689815 for ; Fri, 11 Jun 2021 23:37:35 +0300 (EEST) Received: by mail-lf1-f42.google.com with SMTP id x24so4749163lfr.10 for ; Fri, 11 Jun 2021 13:37:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GU+kKVsguBIJ4ET4yU+2x2SC9Cwposawz5Z3d4qxKDk=; b=TpAIB0UvkviTNawjuIbazH2Qjzm8rJmKATEd9Qp0NsOmtBNSUMuhqFH818sabLKHjQ 682/4l1VuTCIgEEKkyWZFyg3bzr6ciw1sfxX68tgytSVgHIIInhxfZbDc00U6DkK6iMA N06eeglMQ9r8lO6E7oMwCv4DTDT/ZwseeJ4++SGvY6TcnQ+wZx0to40Y9d7yP5oBQ7Uz keKLWaguko6geuxmW1evLkH12B5Un+fCeqqmPv+fy2oU567Vhz+v4WHV1CcaM/q0xDDH pOMneQRmkaUFtqyduGierCDslt/SImiUID6NFT7bn9RYej6NyphOcYVwWFV4dTW58uWp jMiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GU+kKVsguBIJ4ET4yU+2x2SC9Cwposawz5Z3d4qxKDk=; b=WAHUpU+q4E8OnVQvYQgsq34ZTVMbyn9Dac8YQjBDubFrlpej1aJQ18qQUVXehTj83h Ha7L8Q1JnGxnHtrWhYIHNSpDqpMegvFpMwcnzehYbXz19SZS8INBFF35ZPmc7lQQpLBj dXNHZ65Out0sl4H8M8oaXS1r0jEuqW2Nd1zBHwmvj0CibEl7DuH/d+qqf41AcpuckGYr owd8fXDg8Vm0lJLPYftYoV7nn2x5hooChY8QiRdJRBPa2oN4VTXlz7C+nm95NG1Y6gRa gE0hbr+BGcKQIs3cRT7A1e8ANt/SKWuhurncbA+4zKeJLS+PRY/dRayDVeQ/ebmzzyqD 5voA== X-Gm-Message-State: AOAM533T9wLo5Whf3+XHzQQQeydlmb+aSKfv/RLZiLz3nvhOX1mJsQmW DfgMS2eqlCVR+WwHhxOuOQpdzoeocMx08g== X-Received: by 2002:a19:ad44:: with SMTP id s4mr3701596lfd.563.1623443854352; Fri, 11 Jun 2021 13:37:34 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id z15sm687273lfs.207.2021.06.11.13.37.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:37:33 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:52 +0200 Message-Id: <20210611203104.1692-22-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 21/33] avdevice: capabilities API details no longer public 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: qsvpM5ehILXl Signed-off-by: Diederick Niehorster --- libavdevice/avdevice.c | 2 +- libavdevice/avdevice.h | 28 +--------------------------- libavdevice/internal.h | 33 +++++++++++++++++++++++++++++++++ libavdevice/version.h | 2 +- 4 files changed, 36 insertions(+), 29 deletions(-) diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c index e66906e91b..cb139e6d4a 100644 --- a/libavdevice/avdevice.c +++ b/libavdevice/avdevice.c @@ -33,7 +33,7 @@ const char av_device_ffversion[] = "FFmpeg version " FFMPEG_VERSION; #define V AV_OPT_FLAG_VIDEO_PARAM #define OFFSET(x) offsetof(AVDeviceCapabilitiesQuery, x) -const AVOption av_device_capabilities[] = { +const AVOption ff_device_capabilities[] = { { "codec", "codec", OFFSET(codec), AV_OPT_TYPE_INT, {.i64 = AV_CODEC_ID_NONE}, AV_CODEC_ID_NONE, INT_MAX, E|D|A|V }, { "sample_format", "sample format", OFFSET(sample_format), AV_OPT_TYPE_SAMPLE_FMT, diff --git a/libavdevice/avdevice.h b/libavdevice/avdevice.h index 6443f865d5..44c4f185a2 100644 --- a/libavdevice/avdevice.h +++ b/libavdevice/avdevice.h @@ -400,33 +400,7 @@ int avdevice_dev_to_app_control_message(struct AVFormatContext *s, * avformat_free_context(oc); * @endcode */ - -/** - * Structure describes device capabilities. - * - * It is used by devices in conjunction with av_device_capabilities AVOption table - * to implement capabilities probing API based on AVOption API. Should not be used directly. - */ -typedef struct AVDeviceCapabilitiesQuery { - const AVClass *av_class; - AVFormatContext *device_context; - enum AVCodecID codec; - enum AVSampleFormat sample_format; - enum AVPixelFormat pixel_format; - int sample_rate; - int channels; - int64_t channel_layout; - int window_width; - int window_height; - int frame_width; - int frame_height; - AVRational fps; -} AVDeviceCapabilitiesQuery; - -/** - * AVOption table used by devices to implement device capabilities API. Should not be used by a user. - */ -extern const AVOption av_device_capabilities[]; +typedef struct AVDeviceCapabilitiesQuery AVDeviceCapabilitiesQuery; /** * Initialize capabilities probing API based on AVOption API. diff --git a/libavdevice/internal.h b/libavdevice/internal.h index 67c90e1f87..e7a72d008d 100644 --- a/libavdevice/internal.h +++ b/libavdevice/internal.h @@ -19,10 +19,43 @@ #ifndef AVDEVICE_INTERNAL_H #define AVDEVICE_INTERNAL_H +#include "libavutil/log.h" +#include "libavutil/opt.h" +#include "libavutil/pixfmt.h" +#include "libavutil/rational.h" +#include "libavutil/samplefmt.h" +#include "libavcodec/codec_id.h" #include "libavformat/avformat.h" av_warn_unused_result int ff_alloc_input_device_context(struct AVFormatContext **avctx, const AVInputFormat *iformat, const char *format); +/** + * Structure describes device capabilities. + * + * It is used by devices in conjunction with ff_device_capabilities AVOption table + * to implement capabilities probing API based on AVOption API. + */ +typedef struct AVDeviceCapabilitiesQuery { + const AVClass *av_class; + AVFormatContext *device_context; + enum AVCodecID codec; + enum AVSampleFormat sample_format; + enum AVPixelFormat pixel_format; + int sample_rate; + int channels; + int64_t channel_layout; + int window_width; + int window_height; + int frame_width; + int frame_height; + AVRational fps; +} AVDeviceCapabilitiesQuery; + +/** + * AVOption table used by devices to implement device capabilities API. + */ +extern const AVOption ff_device_capabilities[]; + #endif diff --git a/libavdevice/version.h b/libavdevice/version.h index 0381d6cd0d..53af6fa0d0 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 2 +#define LIBAVDEVICE_VERSION_MINOR 3 #define LIBAVDEVICE_VERSION_MICRO 100 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \ From patchwork Fri Jun 11 20:30:53 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: 28213 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp765830iol; Fri, 11 Jun 2021 13:38:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiys0JqCqxcLkrBKN0yW5bZt2q5LEe/4QHmDF/HiFWHOeBivXKXYSrJoNhlVYmxbeFV4Fz X-Received: by 2002:a17:906:ce4a:: with SMTP id se10mr5459666ejb.235.1623443882075; Fri, 11 Jun 2021 13:38:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443882; cv=none; d=google.com; s=arc-20160816; b=Hu5y7BhZ2me1GchIvWliSogzFPEZ0Jd7n8Xh4egBq8lsCJPAqJVPRh1jybVN4qEQ0E aBxw4TSpZCN72Tk1VcwW/phq8WX0HOywnHjHoxGu/UchbI31taJx0J8yl1RfkGoexh5S HCdvzsR2p78utATmW00dmdx9NPp5KweVkabSAd9mxT8Zd4a6XAz9P6OlOl3oha+IUqBt i8Sux6LSwHWPOQoqdVXvzlA2HFmWtQiXEdLZgdVOi2V2K2ltIzo7xnApV6PifCvIruwL fF9dIgudYS1AInucyrpJ7t9BSnxk1xPuY1MmqYvLwkR9bOwVbC01363VGrvKXStXsAro ztdQ== 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=iNQ4O9x6epDd9kjcHFF+f/bH81fJXpQmp3sPhsK4tIs=; b=Q91Hewa3VwPhWirdLg8xc49Vh/6rIHlNqv7FI2J/25jvnFwx1++EklwDzyztkug2T/ 4lVhODCF6CrdZGXigkL/kluQwhBszIlO4DXR+g+PYyEgyoSQDr6SG6sdGl42K28cQZgn FGcQIHfChqQ0PQv4uNCoc29SjTKGZHmunUK5qEvAJ99cF2AN4eXz7O115ATGkkMjV+Dp KzT17V9BkLXXpNQiSxrqvzLFeNsAX+nsSuSqNqFUJaxFTPqnYIQ2akVkQG87mCmpgGF0 EbHE5LbOXFTiAxUjyKgntM33GwXWNjJVHvB6URHZjOIqvL18Bi/5Qwy2s/HB88QW1TOa 4Adw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=TsauhrBU; 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 t27si5418809ejd.372.2021.06.11.13.38.01; Fri, 11 Jun 2021 13:38:02 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=TsauhrBU; 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 02A6A689ADA; Fri, 11 Jun 2021 23:37:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EE8EF68995F for ; Fri, 11 Jun 2021 23:37:51 +0300 (EEST) Received: by mail-lj1-f177.google.com with SMTP id z22so11295774ljh.8 for ; Fri, 11 Jun 2021 13:37:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hWUOtf3fx0nNSVFiY2Jq7UBL6A6pYL8afp8Eutfhcts=; b=TsauhrBU8xZdmzRKXQylymIjFKDOvmwAV4UgGhZX3AhRPuuYCfWIceRkrCzjha7G2d 4u4J2jbQvt5vcbZtXP1g683VrlgmYnoW17j7SPks+vFr5J9Shp+gCgI7O7UlxXtWFWBl mlsSij8vasp7qAPNA0QxFE2HBoRE7oenGT8jsceyNgQxCsKFmbqK2eEzDa+8Ycg/8Mui imBPifPD/25JPo7gjq1cFZXx0MHm1fC4Qh2cHc3SUjkXIO1hkp4YBjkmlmRtBC/Ofh8s DxTzxB52B6UvTwXsZcjDy3TnH1HWo4dVKu2uwPG1GgD9wubRP8bG7FDH8SruRoZruR5J 3MVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hWUOtf3fx0nNSVFiY2Jq7UBL6A6pYL8afp8Eutfhcts=; b=gperY036xqa/JrvyG6Ew6w4RIAo0r6kjUYyx5xmtDb5q6dy75WKGQft5Qz03/ON8RH caVuLqa9tn+Y0pn7I+LrBCBWe0NlpWQGHWwop/vsGG7QXc9K3ul4tF4XHdli0m+Emrxj bqG/bX+ukdnr16ACKNSyVhqLhG20pbpOeQS3fRb0Cv9pAZU/MqSnCCqC+SNEy4gQBM1X MLFmiHXCq15AF+xeGlwuYVIM/xjK8xWTFtKuaMHBhZWHHP24jd6Lbqi7En2Xn90/r0JC C27u20c2h2AtIU113hrUW+Q3U3Z5qBEiqRUWx+9UULMndWowqi72KyHQ9UdZQpp7ugKr cHoA== X-Gm-Message-State: AOAM530hAHB5YoKdBxB0gJx7kB3hAy12MBcxtUNBsMSjD32jl6jm5Bpz GUPnAm3Th5/QERj93L5GkLWdktO3RzWWrA== X-Received: by 2002:a2e:9b8f:: with SMTP id z15mr4255849lji.304.1623443871090; Fri, 11 Jun 2021 13:37:51 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id t16sm843803lji.136.2021.06.11.13.37.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:37:50 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:53 +0200 Message-Id: <20210611203104.1692-23-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 22/33] avutil/opt: document AVOptionRange min_value > max_value 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: hJp4IXRLrc0J AVOptionRange needs a way to encode that an options is not set. Here i provide a documentation solution. When a range is invalid (value_min > value_max), it should be considered unset/value not available. When querying a range of formats of an avdevice, sometimes for a given format the queried option is not available. This is not an error as the user is asking for a valid capability, it just doesn't always apply to all the matching formats of the device. This cannot be communicated through a single special value (like 0 or -1) as that has the same problem asany special value solution. Documenting that an invalid range means value not available allows communicating this situation without adding a field to the AVOptionRange struct. Signed-off-by: Diederick Niehorster --- libavutil/opt.c | 2 +- libavutil/opt.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/libavutil/opt.c b/libavutil/opt.c index 41284d4ecd..edb2c2ca41 100644 --- a/libavutil/opt.c +++ b/libavutil/opt.c @@ -1865,9 +1865,9 @@ int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const ch ranges->range[0] = range; ranges->nb_ranges = 1; ranges->nb_components = 1; - range->is_range = 1; range->value_min = field->min; range->value_max = field->max; + range->is_range = field->max > field->min; switch (field->type) { case AV_OPT_TYPE_BOOL: diff --git a/libavutil/opt.h b/libavutil/opt.h index c2329e5589..3c64e8d3a5 100644 --- a/libavutil/opt.h +++ b/libavutil/opt.h @@ -313,6 +313,11 @@ typedef struct AVOptionRange { * Value range. * For string ranges this represents the min/max length. * For dimensions this represents the min/max pixel count or width/height in multi-component case. + * If value_min < value_max, the struct encodes a range. + * If value_min == value_max, the struct encodes a single value. + * If value_min > value_max, the range is empty (a value is not available). + * Good sentinel values to use when a range is empty + * are value_min=0, value_max=-1, but this is not required. */ double value_min, value_max; /** From patchwork Fri Jun 11 20:30:54 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: 28216 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp766160iol; Fri, 11 Jun 2021 13:38:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBv5C0ybCjE4cDvve8ou+FfD4M3ZOS+JDtrVs7wKpuuaLMU5aQ2V9ux6RJ9anza1w30n7x X-Received: by 2002:a17:907:270c:: with SMTP id w12mr5178733ejk.175.1623443899598; Fri, 11 Jun 2021 13:38:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443899; cv=none; d=google.com; s=arc-20160816; b=IJ0zy9zEiWIAe8gjLjyE2ymZwOA4VdP1KGbKem/iUL7oy3BzYKvNtOIRIuUkmThpjJ rHfinCyZ2X6Sm0GYjHNjDbm8c/3FLXti3ZOaDRvMJOxETbvQBBLvoKjXzvSQgzSCco3+ z9DqA2uy7zlqtFzVf+wtbQmuQR6cyZfxkptUm3kr/66AF4MZcBsBuU27UxMUbPb8FTGE Rcnzl6ZzjUqrCXIvjmO5YClFYN/261j4O23lHVCEFQfPEvdCPWvvJL9RwYKDLGx5vTYz N7RaNlRd3kHW3coES2AU+E+rBaGGFdqJ73IF49bpefzYxHR7QUOv9hUPIs7sSdpAg9Wz E7nQ== 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=FDHDZDVIc2luBdDk/C2twnOrBee02Unz5yx3+16zgmY=; b=CJFbdYhYNZLhwuXF9cahW6Lzzdm0C2+ePeaeqwYvhkw6B8bcvF0rFWzNYKj5mOiXhl PFZiEcaqqhxdRXL56Nue/WeLWKnhwBHitFGzDFqwqnoYBsQy8UKz+6/JsX7wcCskqh8i 78lJhI5TYmW2Sb5kbykcZCnjysxbon8UivYuNImoGDxgEq+SgvtAbUBy2aOoQzseSxbf gTfjM8hVH7pXGRTGst4dncUhlqem8hKcZTSzYxC27Qi8UOU7G4iXG4u8cy5PEqvhuV1y vEIjUr7a/95Ag6HdMoeDAO0xMz3BN5Y24iLbz+W13e74Mm4PeybuNnyBRuBPM1QBowlx TGWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=Kek6aoBq; 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 y1si5570052edu.152.2021.06.11.13.38.18; Fri, 11 Jun 2021 13:38:19 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=Kek6aoBq; 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 DC477689965; Fri, 11 Jun 2021 23:38:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E865A688388 for ; Fri, 11 Jun 2021 23:38:08 +0300 (EEST) Received: by mail-lj1-f182.google.com with SMTP id x14so11321042ljp.7 for ; Fri, 11 Jun 2021 13:38:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FOWRE2gVlL9IfMVOz3GKh1a3HX5SUGmdMciAmvht/Fk=; b=Kek6aoBqbNTxlLxC3AD2xndSnlOt4dqWrby/d/g8dMLfTohonwA51z2UvPFGZaHg8O Vnmov10dTHN7WMvMxxReg5QZWsM+6fnzkYj1gpwP3s18VjqHLlnLW4waPc5I4+n0ksZK mMT5ZwAMYJsAW1u2kIXW6GLS3ftzEI8EHMxTz99DTpRvKpJZB+keUjSWfSXh4kky8D+w MMcRidgZy1oOZ4UY5v5+QLdgOdtiVaaPsX4ni3CejjTvBHy/2nkBC8vMAQRE+M10oW5+ nXh0xRwlc5811AoIQ1F6HjIkq+cADw2Jp7pSnkBVIkheQlQrQ9O/+fdJzPuq5PsdMHaD l/yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FOWRE2gVlL9IfMVOz3GKh1a3HX5SUGmdMciAmvht/Fk=; b=kJtd9FjwdISu/kp+Z3NazhdVnqUEm3bLBF6hn9/RRViSmHgdwqQwTe1Z3x350j8+Zr BnNCAItYesYkHmE8kwNPcYCUwKaa/CKiZFz8oO8wlA9fRCTQYolKFkoIroN32rdhTfeF qBSzlshURdZ2LzSoFsgLNq2HWGPCar+/qrXGl7wWcrikdcZEvPhkYVFsSuSZopbmFMKn H31rK0p4wT1M7LhBmlpf4LSLQms1j6BO5kUX93MHWyWcQ+hfJklN5vJJDuanersU1bCk fUFkmebvqKdNeVLRsdw4FS6Vm2CMns2qnm7iRvK8QttwigkpoThclWK8LhXKwRisnyRJ Jp6A== X-Gm-Message-State: AOAM531lEtx7qyEpfDIa7aP7sD4UgHDSpZY0+tRxbP+6rQFVUGG7pVvn cGBXp4Wej9r+VfGrEuXjqJRGRhKBu9H12g== X-Received: by 2002:a2e:a612:: with SMTP id v18mr4455862ljp.358.1623443887993; Fri, 11 Jun 2021 13:38:07 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id b18sm686787lfb.277.2021.06.11.13.38.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:38:07 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:54 +0200 Message-Id: <20210611203104.1692-24-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 23/33] avutil/opt: add av_opt_print_num 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: Rw4caCysh7to This function allows formatting an option value stored in a double (such as the min and max fields of an AVOption, or min_value and max_value of an AVOptionRange) properly, e.g. 1 for a AV_OPT_TYPE_PIXEL_FMT -> yuyv422. Useful when printing more info about an option than just its value. Usage will be shown in upcoming device_get_capabilities example. av_opt_get (body changed) still passes FATE. Signed-off-by: Diederick Niehorster --- libavutil/opt.c | 81 +++++++++++++++++++++++++++++++++++++-------- libavutil/opt.h | 17 +++++++++- libavutil/version.h | 2 +- 3 files changed, 85 insertions(+), 15 deletions(-) diff --git a/libavutil/opt.c b/libavutil/opt.c index edb2c2ca41..108e9baf3b 100644 --- a/libavutil/opt.c +++ b/libavutil/opt.c @@ -776,24 +776,14 @@ static void format_duration(char *buf, size_t size, int64_t d) *(--e) = 0; } -int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val) +static int print_option(void *dst, enum AVOptionType type, int search_flags, AVOption *o, uint8_t **out_val) { - void *dst, *target_obj; - const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); uint8_t *bin, buf[128]; int len, i, ret; int64_t i64; - if (!o || !target_obj || (o->offset<=0 && o->type != AV_OPT_TYPE_CONST)) - return AVERROR_OPTION_NOT_FOUND; - - if (o->flags & AV_OPT_FLAG_DEPRECATED) - av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", name, o->help); - - dst = (uint8_t *)target_obj + o->offset; - buf[0] = 0; - switch (o->type) { + switch (type) { case AV_OPT_TYPE_BOOL: ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(get_bool_name(*(int *)dst), "invalid")); break; @@ -820,7 +810,8 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val) ret = snprintf(buf, sizeof(buf), "%d/%d", ((AVRational *)dst)->num, ((AVRational *)dst)->den); break; case AV_OPT_TYPE_CONST: - ret = snprintf(buf, sizeof(buf), "%f", o->default_val.dbl); + if (o) + ret = snprintf(buf, sizeof(buf), "%f", o->default_val.dbl); break; case AV_OPT_TYPE_STRING: if (*(uint8_t **)dst) { @@ -889,6 +880,70 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val) return *out_val ? 0 : AVERROR(ENOMEM); } +int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val) +{ + void *dst, *target_obj; + const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); + + if (!o || !target_obj || (o->offset<=0 && o->type != AV_OPT_TYPE_CONST)) + return AVERROR_OPTION_NOT_FOUND; + + if (o->flags & AV_OPT_FLAG_DEPRECATED) + av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", name, o->help); + + dst = (uint8_t *)target_obj + o->offset; + + return print_option(dst, o->type, search_flags, o, out_val); +} + +int av_opt_print_num(enum AVOptionType type, double val, uint8_t **out_val) +{ + *out_val = NULL; + + switch (type) { + case AV_OPT_TYPE_FLAGS: + case AV_OPT_TYPE_BOOL: + case AV_OPT_TYPE_INT: + case AV_OPT_TYPE_PIXEL_FMT: + case AV_OPT_TYPE_SAMPLE_FMT: + { + int temp = lrint(val); + return print_option(&temp, type, 0, NULL, out_val); + } + case AV_OPT_TYPE_INT64: + case AV_OPT_TYPE_DURATION: + case AV_OPT_TYPE_CHANNEL_LAYOUT: + { + int64_t temp = llrint(val); + return print_option(&temp, type, 0, NULL, out_val); + } + case AV_OPT_TYPE_UINT64: + { + uint64_t temp = llrint(val); + return print_option(&temp, type, 0, NULL, out_val); + } + case AV_OPT_TYPE_FLOAT: + { + float temp = (float)val; + return print_option(&temp, type, 0, NULL, out_val); + } + case AV_OPT_TYPE_DOUBLE: + return print_option(&val, type, 0, NULL, out_val); + + default: + // AV_OPT_TYPE_DICT, + // AV_OPT_TYPE_COLOR, + // AV_OPT_TYPE_BINARY, + // AV_OPT_TYPE_STRING, + // AV_OPT_TYPE_RATIONAL, + // AV_OPT_TYPE_IMAGE_SIZE, + // AV_OPT_TYPE_VIDEO_RATE, + // AV_OPT_TYPE_CONST + // cannot be stored in a single double, and are thus not a valid input + return AVERROR(EINVAL); + } +} + static int get_number(void *obj, const char *name, const AVOption **o_out, double *num, int *den, int64_t *intnum, int search_flags) { diff --git a/libavutil/opt.h b/libavutil/opt.h index 3c64e8d3a5..f9da141588 100644 --- a/libavutil/opt.h +++ b/libavutil/opt.h @@ -361,7 +361,7 @@ typedef struct AVOptionRanges { * for (range_index = 0; range_index < ranges->nb_ranges; range_index++) { * for (component_index = 0; component_index < ranges->nb_components; component_index++) * range[component_index] = ranges->range[ranges->nb_ranges * component_index + range_index]; - * //do something with range here. + * //do something with range here. For printing the value, av_opt_print_num() may be of use. * } * av_opt_freep_ranges(&ranges); * @endcode @@ -760,6 +760,21 @@ int av_opt_get_channel_layout(void *obj, const char *name, int search_flags, int * be freed with av_dict_free() by the caller */ int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val); + +/** + * Format option value and output to string. + * @param[in] type Type of the option. + * @param[in] val An option value that can be represented as a double + (e.g. min or max fields of AVOption, or min_value and + max_value of AVOptionRange) + * @param[out] out_val Value of the option will be written as a string here + * + * @return >=0 on success, a negative error code otherwise + * + * @note the returned string will be av_malloc()ed and must be av_free()ed by the caller + */ +int av_opt_print_num(enum AVOptionType type, double val, uint8_t **out_val); + /** * @} */ diff --git a/libavutil/version.h b/libavutil/version.h index e11eaa20d0..34b83112de 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,7 +79,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 57 -#define LIBAVUTIL_VERSION_MINOR 0 +#define LIBAVUTIL_VERSION_MINOR 1 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ From patchwork Fri Jun 11 20:30:55 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: 28226 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp766155iol; Fri, 11 Jun 2021 13:38:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHO9eoglYkexUAwkwyG1MpYROddimp+j5zDBGwhf95HRACif5G4eiolNgkwNooGolCSURe X-Received: by 2002:aa7:c450:: with SMTP id n16mr5498735edr.386.1623443911278; Fri, 11 Jun 2021 13:38:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443911; cv=none; d=google.com; s=arc-20160816; b=G3cjliHBkRCP12ucxNCZr6qqxTLteNuvcB9REt7l2gkss2Lg2lDFduERGF29y46MlA +dIQKdmwj+mc5sXxB598ln61hFdsrUbVGJsyjahgRUMbk2V86CB+fIUA3QOoric41c3W CsAGEvLNUvoMRrGsE4lLSlEqmSa6fIIgGCd01M8EpuimHrbWEZXVDDMgVjXX8Y/uUaAh LLLhSqv9YtUEkIIyLn8cyNjAmi3G6RvpdLtvL2D0gkXwfX+hjN3+QBITdppAgwAzQAnM nY35dSwWtvf9pxd/gis0ZOLJ3UkjEThyHld46ZaImI2l5Zqx/uD0innBhM1cLTnwJRzU FSQA== 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=kQAA2fHQyl2mGLlRrnd72W0PldqKyCYw7DSY47bbOng=; b=Zkfw76QPJFHCoWoPGZ8dWbit0osl1iOHmNEmh8tXmgauci0v8kqxsuvkEKzfRSPGtm 5ypoKqbsY8ciY4CA5YgpHm/yIgDG2v9T9R50THGkz4j0QAKYoOsRL81aVPBWEfdrgyk9 755ZxFI6IRSaA9wsXf0M2HjvleHYm96FwJAkCuuM+3e5uEyi5sII0Y75eQ3kYqod5E20 YYnm6p+RjIBf0PkLzhzI6HX4q1qnQkc7wzcTlqTOQUD2SYwbqDIAOKnfXf4MvVyBpkuJ hQLo1ZqdsTkhKYMLJV2MW0x9okTlObCHqrPuU2VSxrHLEG6rn0lzi3yf1Qi86LXHF9uw 2Zjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=DYIt2YF2; 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 r15si5446270edo.442.2021.06.11.13.38.30; Fri, 11 Jun 2021 13:38:31 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=DYIt2YF2; 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 D008C6808CC; Fri, 11 Jun 2021 23:38:27 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B7DF6689815 for ; Fri, 11 Jun 2021 23:38:25 +0300 (EEST) Received: by mail-lf1-f47.google.com with SMTP id m21so10346021lfg.13 for ; Fri, 11 Jun 2021 13:38:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ji5OwGis+lTZN5i+0WIlbAnoYmZK9arobLG3ykad+II=; b=DYIt2YF24T3/pE8jIXO27SuQFocyWczQNZ3hn7fXVfDA4sCIZAJ5iidxEZd5TgjUCl in3GP791JwarZ8nRNXljq1T06MDn8LpIBKBnjVUS2SS8KPZ4jYhEPnJv2FGmOC+hBm07 D0ZCVXTjOjIgXq6HAuA7NVJShq9HG61MkvRYSMDd5FeZuBz806+FZEvrtYkJnDDiPCmo OR6WdUzipw0vfbzm1wch5JO68ShGQPNDLxK87pioiO4RGzTnTE1FztZEO/QIhuZRRifw PYUzdBqmji+VDMd/Kt6SMxZUPngqyC57FzND4PeiS+ejWhraoHAhiBKovFmR3SYOkpxv nn6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ji5OwGis+lTZN5i+0WIlbAnoYmZK9arobLG3ykad+II=; b=I3I/Bxi9qG84D5Fgrao3kH2ux79/NbKucNAoj2mGtQOUn79mN0tlcTaPv7s9uTvStg k0WFuHdB+I61ox3htP6x2lzuq9TFlu77vLy+KsYhM/zYaCKPXHwzZfg8v4Q34j2E8WDx gdqDFejbIVerZrHMs81MbOq4wQS+ghGbT0qaP7fNg4ns5scXcQo4WzBKCeWjUCVBQvEA ioie616I1cwj7xshiWkpC5+5hRlGD/5xr/JuX7Ax9w6goWxHcN3+BiBHoIb9f8OHm7FC unmoIG6pV7YuD1c/bt34h14GQqjonTtek7u3ZXhGYsfSapI0wGgBvojF5HBUpZPDWstS G1mg== X-Gm-Message-State: AOAM531SecoyVMMpvqmkaUo4A0blx7HXxsQh+z+uuV4RFK4mNNyEPi76 sjKgJW1l76l5VT9K37eCSGDc/KS6aQ6rbw== X-Received: by 2002:ac2:596a:: with SMTP id h10mr3566021lfp.360.1623443904847; Fri, 11 Jun 2021 13:38:24 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id bi2sm530374lfb.190.2021.06.11.13.38.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:38:24 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:55 +0200 Message-Id: <20210611203104.1692-25-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 24/33] avdevice: Add internal helpers for querying device capabilities 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: UKc2hAGxRejT Signed-off-by: Diederick Niehorster --- libavdevice/internal.h | 31 +++++++++++++++++++++++++++ libavdevice/utils.c | 48 ++++++++++++++++++++++++++++++++++++++++++ libavdevice/version.h | 2 +- 3 files changed, 80 insertions(+), 1 deletion(-) diff --git a/libavdevice/internal.h b/libavdevice/internal.h index e7a72d008d..ce316082be 100644 --- a/libavdevice/internal.h +++ b/libavdevice/internal.h @@ -58,4 +58,35 @@ typedef struct AVDeviceCapabilitiesQuery { */ extern const AVOption ff_device_capabilities[]; +/** + * Enumeration indicating which device capability is being queried. + */ +enum AVDeviceCapabilitiesQueryType { + AV_DEV_CAP_QUERY_NONE = 0, + // both audio and video + AV_DEV_CAP_QUERY_CODEC, + // audio + AV_DEV_CAP_QUERY_SAMPLE_FORMAT, + AV_DEV_CAP_QUERY_SAMPLE_RATE, + AV_DEV_CAP_QUERY_CHANNELS, + AV_DEV_CAP_QUERY_CHANNEL_LAYOUT, + // video + AV_DEV_CAP_QUERY_PIXEL_FORMAT, + AV_DEV_CAP_QUERY_WINDOW_SIZE, + AV_DEV_CAP_QUERY_FRAME_SIZE, + AV_DEV_CAP_QUERY_FPS +}; + +/** + * Find AVDeviceCapabilitiesQueryType enumeration by means of options name. + * Returns AV_DEV_CAP_QUERY_NONE if not found. + */ +enum AVDeviceCapabilitiesQueryType ff_device_get_query_type(const char* option_name); + +/** + * Get component name from AVDeviceCapabilitiesQueryType enumeration and component index. + * (Some options have multiple components, e.g. AV_DEV_CAP_QUERY_FRAME_SIZE). + */ +const char* ff_device_get_query_component_name(enum AVDeviceCapabilitiesQueryType query_type, int component); + #endif diff --git a/libavdevice/utils.c b/libavdevice/utils.c index d9a52c53ab..de9023f215 100644 --- a/libavdevice/utils.c +++ b/libavdevice/utils.c @@ -19,6 +19,7 @@ #include "internal.h" #include "libavutil/opt.h" #include "libavformat/avformat.h" +#include "libavutil/avassert.h" int ff_alloc_input_device_context(AVFormatContext **avctx, const AVInputFormat *iformat, const char *format) { @@ -57,3 +58,50 @@ int ff_alloc_input_device_context(AVFormatContext **avctx, const AVInputFormat * avformat_free_context(s); return ret; } + +typedef struct AVDeviceCapabilitiesQueryTypeEntry { + const char* name; + enum AVDeviceCapabilitiesQueryType query_type; +} AVDeviceCapabilitiesQueryTypeEntry; + +static const AVDeviceCapabilitiesQueryTypeEntry query_table[] = { + // both audio and video + { "codec", AV_DEV_CAP_QUERY_CODEC }, + // audio + { "sample_format", AV_DEV_CAP_QUERY_SAMPLE_FORMAT }, + { "sample_rate", AV_DEV_CAP_QUERY_SAMPLE_RATE }, + { "channels", AV_DEV_CAP_QUERY_CHANNELS }, + { "channel_layout", AV_DEV_CAP_QUERY_CHANNEL_LAYOUT }, + // video + { "pixel_format", AV_DEV_CAP_QUERY_PIXEL_FORMAT }, + { "frame_size", AV_DEV_CAP_QUERY_FRAME_SIZE }, + { "window_size", AV_DEV_CAP_QUERY_WINDOW_SIZE }, + { "fps", AV_DEV_CAP_QUERY_FPS }, +}; + +enum AVDeviceCapabilitiesQueryType ff_device_get_query_type(const char* option_name) +{ + for (int i = 0; i < FF_ARRAY_ELEMS(query_table); ++i) { + if (!strcmp(query_table[i].name, option_name)) + return query_table[i].query_type; + } + // not found + return AV_DEV_CAP_QUERY_NONE; +} + +const char* ff_device_get_query_component_name(enum AVDeviceCapabilitiesQueryType query_type, int component) +{ + if (query_type == AV_DEV_CAP_QUERY_WINDOW_SIZE || query_type == AV_DEV_CAP_QUERY_FRAME_SIZE) { + // special case: different name for each component + return component == 0 ? "pixel_count" : (component == 1 ? "width" : (component == 2 ? "height" : "")); + } + else { + av_assert0(component == 0); + for (int i = 0; i < FF_ARRAY_ELEMS(query_table); ++i) { + if (query_table[i].query_type == query_type) + return query_table[i].name; + } + } + // not found + return NULL; +} \ No newline at end of file diff --git a/libavdevice/version.h b/libavdevice/version.h index 53af6fa0d0..e0361aebc1 100644 --- a/libavdevice/version.h +++ b/libavdevice/version.h @@ -29,7 +29,7 @@ #define LIBAVDEVICE_VERSION_MAJOR 59 #define LIBAVDEVICE_VERSION_MINOR 3 -#define LIBAVDEVICE_VERSION_MICRO 100 +#define LIBAVDEVICE_VERSION_MICRO 101 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \ LIBAVDEVICE_VERSION_MINOR, \ From patchwork Fri Jun 11 20:30:56 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: 28223 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp766319iol; Fri, 11 Jun 2021 13:38:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwM8F265OTqssykkiyeJXED9NGrw+3rNBbmed6NLbZhnjzMtFmOzpf0z9sXFHy2fDzjeOcS X-Received: by 2002:a17:906:4a48:: with SMTP id a8mr5299179ejv.472.1623443927606; Fri, 11 Jun 2021 13:38:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443927; cv=none; d=google.com; s=arc-20160816; b=qo29kzqUdxvTgtTAFTkMc7a3GVJhKilKGSyEubyBoLStiu3Osx34/kTekzq7oC7y7+ aXuOf76aFdG0YrG8GeSz0Z0RPtJR8hK2tNHgc7zIKzQGkoOdA6Bq49VMiaMlgEOwIWro 1vZIzhDoHVeL1hAwk3uruLF5O9ppye8ss5+IpE6Yhzz/L4TFrNQhVq53DUBaD82rz1sb 7YiKuis4CAVM74UP/tPr1odgxI4Gh2Km7DTmBC9+SFSaes0kPjVe0o0spYtwrwpDgLfA gDH7YonkUvAHRpqoPabV4ka15prgytox1QLPpS+DFkNkU91IEQmPC74wNAT+nCoT2dzD pnZA== 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=9uIk9dZFM83XUGVxAlJiDzPBa3uHiY1dQHhkvXdJEps=; b=ioW3PZkCFa9vEsyLg6cPDNzeF7/VwTDZAhttI+ozrFujN2uL2EMVGB6+qcS7tgBsDI +oRe6/bpItBcydCRClB+ZCtaOaAYYlCOeSFmCroWJ08+eQIQKSjx2FAf7MbCeafPbAo7 sZe/keYL+ck4KsqL7ldcBU6xVZeF5miyGZcy5ZM6dO17jfE2VG+8K8jOXlKXgCBZbiQ1 +4ZAwbcp85eKnFCEyU9wapiWbp5TmtyAFmpyY5FbmDgsfc4qXteqsLk9Nk0nLZrY/1+o zT5wa1qrmhBr2OIKuMUFN3kvqFu4ouu6DJz0mPigBSJCJCtu3OlpwU2YbXkhClUnq/fp 8x7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b="kPjmcX+/"; 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 x2si5799490eju.99.2021.06.11.13.38.47; Fri, 11 Jun 2021 13:38:47 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b="kPjmcX+/"; 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 E2A11689AA0; Fri, 11 Jun 2021 23:38:44 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D92716899A2 for ; Fri, 11 Jun 2021 23:38:42 +0300 (EEST) Received: by mail-lf1-f44.google.com with SMTP id r5so10393970lfr.5 for ; Fri, 11 Jun 2021 13:38:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PgGWjxD93RILpjWuwQZ6Dd/BNfDTkb1ct8AqHYeZL8c=; b=kPjmcX+/32KUwo/ODh6TOXhi08bzaidZH42yi050xTfan2e439aknKfpaGJ12uU5uN VYqUV+ZbTeBiyggSZAbSAy5IHGuM7xttdpBz98B6uVDwY7xrusIamHIjstQpDgrauQaK 5tE0LiovmkWukLlP7MY7WaEaxj0Xiywdnaq30hHNppuiRjp8pQew/gQ5izkw9GRLzA8t IYqQrmE2kr1jtsxEj/o1Tq+z4F2/dGSfAdfKXjpXdcX1koGR/Z4tfBbYLdG4TKIj3dSi qoj15dctJw6Nf9kIu1BSiy4dbduCaPcu2E0XnjUixlZs6Fw7VJrn9/G3tnWwwB6aT7Cs 4rPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PgGWjxD93RILpjWuwQZ6Dd/BNfDTkb1ct8AqHYeZL8c=; b=slshLvbwkFGVZFdCKnOKWz0qsHgMvHjxWVTrV9RFi0cG6gUWXIs/0S+durIhiNJrjM rqG63q6OCjpXMkZqYD4S5FwSg9NjE+Uti08g1krPlhYPBRXOOENZWx5D9Kl+XzQMcZE2 GTBV2paRNA9PTR9NtMEcRyun7PDbMabBgkiFVw6YPTSHqH1I7xyLDfn3DrcCHbZTZhaF +uCZ9cmkFwqBqXZcXzb01cDSCcBL6noNSrgMvtGsBRHh9GN+7wv7hTgrxYivvJLP00Iu kzrZP2VnOuqvNsUzx8JFhZ+Jd8tk6+hPQokDWkCOY1iDowLpsyg6jrbYmr4gwqu+Ny1O hZIw== X-Gm-Message-State: AOAM532yS2atGFCHk7BR68FCnVbQNkSA2MOvfV/6YDrnZTITU+L5U1DH 6DHK8s1FdJJnQEsBBfJxTDGoeUlAoCMiSQ== X-Received: by 2002:a05:6512:3f9a:: with SMTP id x26mr3973712lfa.75.1623443921738; Fri, 11 Jun 2021 13:38:41 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id t27sm845561ljo.130.2021.06.11.13.38.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:38:41 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:56 +0200 Message-Id: <20210611203104.1692-26-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 25/33] avdevice/dshow: move audio format helpers 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: WNObjRlEbWul Needs to be moved up in file for upcoming implementation of avdevice_capabilities_create. Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 34c7b63220..4605bd6f8e 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -75,6 +75,26 @@ 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 AVCodecID waveform_codec_id(enum AVSampleFormat sample_fmt) +{ + switch (sample_fmt) { + case AV_SAMPLE_FMT_U8: return AV_CODEC_ID_PCM_U8; + case AV_SAMPLE_FMT_S16: return AV_CODEC_ID_PCM_S16LE; + case AV_SAMPLE_FMT_S32: return AV_CODEC_ID_PCM_S32LE; + default: return AV_CODEC_ID_NONE; /* Should never happen. */ + } +} + +static enum AVSampleFormat sample_fmt_bits_per_sample(int bits) +{ + switch (bits) { + case 8: return AV_SAMPLE_FMT_U8; + case 16: return AV_SAMPLE_FMT_S16; + case 32: return AV_SAMPLE_FMT_S32; + default: return AV_SAMPLE_FMT_NONE; /* Should never happen. */ + } +} + static enum AVColorRange dshow_color_range(DXVA2_ExtendedFormat* fmt_info) { switch (fmt_info->NominalRange) @@ -1629,26 +1649,6 @@ static int dshow_control_message(AVFormatContext *avctx, int type, void *data, s return ret; } -static enum AVCodecID waveform_codec_id(enum AVSampleFormat sample_fmt) -{ - switch (sample_fmt) { - case AV_SAMPLE_FMT_U8: return AV_CODEC_ID_PCM_U8; - case AV_SAMPLE_FMT_S16: return AV_CODEC_ID_PCM_S16LE; - case AV_SAMPLE_FMT_S32: return AV_CODEC_ID_PCM_S32LE; - default: return AV_CODEC_ID_NONE; /* Should never happen. */ - } -} - -static enum AVSampleFormat sample_fmt_bits_per_sample(int bits) -{ - switch (bits) { - case 8: return AV_SAMPLE_FMT_U8; - case 16: return AV_SAMPLE_FMT_S16; - case 32: return AV_SAMPLE_FMT_S32; - default: return AV_SAMPLE_FMT_NONE; /* Should never happen. */ - } -} - static int dshow_add_device(AVFormatContext *avctx, enum dshowDeviceType devtype) From patchwork Fri Jun 11 20:30:57 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: 28238 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:bbc9:0:0:0:0:0 with SMTP id c9csp837360ybk; Fri, 11 Jun 2021 13:39:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbRl5TW8AkSxLzcKUIy2iXfqvP80teiA0oc/MRt/mH1l5dMbnmV1UdjxcukT9xCGHdVRn+ X-Received: by 2002:a05:6402:b76:: with SMTP id cb22mr5571538edb.112.1623443947287; Fri, 11 Jun 2021 13:39:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443947; cv=none; d=google.com; s=arc-20160816; b=CBqJ0Z6rrIktSofk0pn7JDHBkBIfqrSPciPq6Tqz4Hu97oa1STgjxpwpYc89T2OJx4 mJhHTRfs+YzPjkEvyDdgnrUEy9wloEeJdIy/nUwFMkf8S2SzN61oEY09DwU+JRJzukqV PEM2dqa7hB2aQ0Ods71BjFRB2rFCN89EfhvhxLrzwO/pOqSVNwgvjGLNpZxlyzIeHBTn cSnuQ9amaakIQdyxyQK1EQJz2Kmb8Zuj3M6Vol7fhezbGQPInHS3IPJwbf1WAONSc8cu +ew120CmkGEzfv6+eBTx5ppW1Zl/e1atAK8lTQ+DDV/EmQj++YX8A8nz40zjm2IbZVdW CE+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=WfF5XpC15srTX2gClPycVo2bNkFzorkdz0kEPfdyCXA=; b=swndysGmvwWMYf/Lp0J5jcKWngOXAS9e8N9yiXAF/oSheewuMhZo8quVmUV3N8+yyX /IOc1YKHvRRInyl6NVeS522uW9w58yGHb/v/Ghx2AuG+bvPjmI2EI6Ou0j+ghGz3Wkda 0GrMelqEmwCHOuYOTGlyPSWZxPHZERseT/x9XzrzrYgkQUKQS8/T40nbFEz+H88aj+Ok KFae8PxdwlAkab1TJT5zisVJkwOoepXopsTgp0wTo9GTVTzK9r6l3AF2ia28qtFebbJH 0RabAV8iGKsMiHW1Tf53hTtTWVT7kWRqktGFqaaL9nKnnAiHBMb12oHCrAeK+oivr9pK bT4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=eXJLG5uC; 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 4si5404450ejr.126.2021.06.11.13.39.07; Fri, 11 Jun 2021 13:39:07 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=eXJLG5uC; 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 DA9AD689A1C; Fri, 11 Jun 2021 23:39:05 +0300 (EEST) 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 57633687F49 for ; Fri, 11 Jun 2021 23:38:59 +0300 (EEST) Received: by mail-lf1-f52.google.com with SMTP id i10so10391685lfj.2 for ; Fri, 11 Jun 2021 13:38:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zOnyLsTJaUlPcwMzIJa5TFJ3p88iINfW6mWzFNoxVY4=; b=eXJLG5uC7j5CSmddNzrB0BXOsGgOoL2weIguNH4BtN6srbywww5nj/8AIF6gNQrnpo 1ee8mKg7abekSl3knbimTscKmbUo77fzGGm/URx0kGLTb3NElhE3NWYxBQvWJ+wytjnq SH4kBmOlQ3Fc/DBM4LbiNW9fw4XSpeNKj9NhFQbdZ/oJg959vDC9d3krY65jb7O3n4jd Scpy2OmyBTF71bk8VOZAZFNBKVgSp8jWqqAwiDc7CZ2gpe2YkVCRVghsCxQBpbKZcVwS g3IqGvtzDzqZ+FP62AC6Uegi7NsgnUGTfex0cX88eTL3mG23oyZytDgEILrhSsqhofxZ xQvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zOnyLsTJaUlPcwMzIJa5TFJ3p88iINfW6mWzFNoxVY4=; b=NELdyMADT+3iel1icXzWZC+hxnOtTV7IpcbI8w6lWQbgoMbWgUEjWJv8ZHBOzTYuby niq11ArgvFKjEFlJJpmsGKMLsbS/5ax8Ao9wVIBYlaucu+q9hE2+rLHMb36mCGrn/42h DyxfUGwSiEaPMwPrJBscmPfI3cCUoCO4B15H9bFy2Ne8HhAaaJyIZXgiLJoWGAFKQjiv /09lhlf2lZpv/Hfi4tCJwlkCu9r7+q9N2dowC8UwMavWB8fbgO9aHu7LTjdhVLWrNv8+ ipITg0+nyR4s3j7eAJl6OiGB3mgeS8KrS4L9bAZ6Bqq4B3a7dao/bo0FlKKdyys+ashr 7mXg== X-Gm-Message-State: AOAM532oGQgKv+z6hoQy18l9KQ+uq4/SYptzAZHub5dRTEG4t/lXEyXs hOhbn4L7rs7p2kyKkEkoQoyhOhhXORk5YA== X-Received: by 2002:a05:6512:3054:: with SMTP id b20mr3671491lfb.375.1623443938577; Fri, 11 Jun 2021 13:38:58 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id h19sm686508lfj.256.2021.06.11.13.38.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:38:58 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:57 +0200 Message-Id: <20210611203104.1692-27-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 26/33] avdevice/dshow: when closing, set context fields back to zero 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: ixZ+lc2X3SDz Content-Length: 3391 After the avdevice capabilities API is implemented, the format context may be reused after querying device capabilities in a later avformat_open_input call. To enable this reuse, after releasing resources, make sure to also set the corresponding pointers back to NULL. This correctly indicates their state after cleanup. Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 4605bd6f8e..20f58aee63 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -291,14 +291,18 @@ dshow_read_close(AVFormatContext *s) ICaptureGraphBuilder2_Release(ctx->graph_builder2[VideoDevice]); if (ctx->graph_builder2[AudioDevice]) ICaptureGraphBuilder2_Release(ctx->graph_builder2[AudioDevice]); + ctx->graph_builder2[0] = NULL; + ctx->graph_builder2[1] = NULL; if (ctx->control) { IMediaControl_Stop(ctx->control); IMediaControl_Release(ctx->control); } + ctx->control = NULL; if (ctx->media_event) IMediaEvent_Release(ctx->media_event); + ctx->media_event = NULL; if (ctx->graph) { IEnumFilters *fenum; @@ -316,25 +320,34 @@ dshow_read_close(AVFormatContext *s) IEnumFilters_Release(fenum); } IGraphBuilder_Release(ctx->graph); + ctx->graph = NULL; } if (ctx->capture_pin[VideoDevice]) ff_dshow_pin_Release(ctx->capture_pin[VideoDevice]); if (ctx->capture_pin[AudioDevice]) ff_dshow_pin_Release(ctx->capture_pin[AudioDevice]); + ctx->capture_pin[0] = NULL; + ctx->capture_pin[1] = NULL; if (ctx->capture_filter[VideoDevice]) ff_dshow_filter_Release(ctx->capture_filter[VideoDevice]); if (ctx->capture_filter[AudioDevice]) ff_dshow_filter_Release(ctx->capture_filter[AudioDevice]); + ctx->capture_filter[0] = NULL; + ctx->capture_filter[1] = NULL; if (ctx->device_pin[VideoDevice]) IPin_Release(ctx->device_pin[VideoDevice]); if (ctx->device_pin[AudioDevice]) IPin_Release(ctx->device_pin[AudioDevice]); + ctx->device_pin[0] = NULL; + ctx->device_pin[1] = NULL; if (ctx->device_filter[VideoDevice]) IBaseFilter_Release(ctx->device_filter[VideoDevice]); if (ctx->device_filter[AudioDevice]) IBaseFilter_Release(ctx->device_filter[AudioDevice]); + ctx->device_filter[0] = NULL; + ctx->device_filter[1] = NULL; av_freep(&ctx->device_name[0]); av_freep(&ctx->device_name[1]); @@ -343,10 +356,13 @@ dshow_read_close(AVFormatContext *s) if(ctx->mutex) CloseHandle(ctx->mutex); + ctx->mutex = NULL; if(ctx->event[0]) CloseHandle(ctx->event[0]); if(ctx->event[1]) CloseHandle(ctx->event[1]); + ctx->event[0] = NULL; + ctx->event[1] = NULL; pktl = ctx->pktl; while (pktl) { @@ -355,6 +371,7 @@ dshow_read_close(AVFormatContext *s) av_free(pktl); pktl = next; } + ctx->pktl = NULL; CoUninitialize(); From patchwork Fri Jun 11 20:30:58 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: 28244 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:bbc9:0:0:0:0:0 with SMTP id c9csp837491ybk; Fri, 11 Jun 2021 13:39:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEIGZGMT5qi9qEPO5Yh2bMZW0sPn9vPsdHmEYFOaAX61y4US5Gg/DEaBYL24D8+IFeeXBQ X-Received: by 2002:a17:906:55cb:: with SMTP id z11mr5227988ejp.475.1623443960604; Fri, 11 Jun 2021 13:39:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443960; cv=none; d=google.com; s=arc-20160816; b=qgqbswHKnQcMIGoMn/jn72T/fBemSL9nl7aVVPJcREcQr8vs6VuAdxMsU0F7Fxcs2V VNHRuCM+ukfqypbrtwHs7kDFgqmuMk79xtIqSu3Wm2gRnnPF3WXXEoipk0ulVl8r++4s nZXy04NDL8i17iUPid4gaWjUS/JzE5IlLZN1D9oM5YgjFhhgQq3Me+0GCRh13N8gXaOB R8h+0rq95vZ5ef5quSKeW6E7et87zy9jOhv6rs/mEphK5dhvgY/j+y6rQrqw8e2yVYfp /3gnLCL9HXxXVntxKyAIAxAW/o43yGPnzys9x6HGaye72t99/5Fb87WKN0uoFkdUbXwd 25BQ== 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=4mEP6bFWTq4viyWxTYVGEP9JWA2xH6oKlvZ7K5PgbzM=; b=amHJUMBcZ0GMjWhVgOZAYQUfrgBq5arVd26z+Q5M9z14/zTEez+Lx9/Hh24Ld5583y Cb4+n2piE9rV0Ac9+iqskpRqcVVHuZXFXxk66krGyqsRVs60edVPxS1gGWZZ07m+oM0u Cr1osqRE/3NaSUlIeEhZLo1gR5cJ0MrhcPPwhSr3LrJR/owNkb1eAAHGdRArE8OS5cKm 7S9YDNy/bTs8Gcz1P3IoJ74a5H7siSOaoYrKBJu7Hgmp/PpCI+hzollDUyRHPDZovPAa +7ugthouti1Nw0LUF5HmHrVcjJhyM0cQupiwj875WxKj3gerbd4/H7FS/3eJkNeFqpUa Jslg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=S6RIQllX; 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 f22si5504119ejq.458.2021.06.11.13.39.20; Fri, 11 Jun 2021 13:39:20 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=S6RIQllX; 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 E62B2689ADE; Fri, 11 Jun 2021 23:39:18 +0300 (EEST) 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 2CAE76808CC for ; Fri, 11 Jun 2021 23:39:16 +0300 (EEST) Received: by mail-lf1-f49.google.com with SMTP id r5so10395946lfr.5 for ; Fri, 11 Jun 2021 13:39:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=46RlDjkLKngfgdVk0aKspVyPXpCL9SnAmNkdoVCUWKo=; b=S6RIQllXpfYDLzQVQOFmJzlv6YU4MKrn9cwMloi6991hOhGQ3iiepVULoRfixTW0Im mWUYiDJL+nLKxUWWa6HjC3PnjdTukl0nYXw1ZLojsEqnoMAH1AUetjlvy750a4CjW8W6 X5cjsu+rGkZmK7RlhWvYP3ZfVmltE77Nrqcq2d1cdIZ7VTatALsChzgFTZiOgTilujAm 8j52FQ45kk3udmMgZioWle+Y3MojV8FQ01UDHW+C8IuCQPsemd+w1u+nVM1gsMUAPSxr lQQenpu+OCXLZpCWyxmtlqQoWnW6E9EjZNbjT6/6KOhOvPgjcem8GxLnssrSXGjQu6SS GC0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=46RlDjkLKngfgdVk0aKspVyPXpCL9SnAmNkdoVCUWKo=; b=H0obApEAQsMe3bcAVN/Vm8XBAQlo1r2+DdBotLd1guneEypPlj23yVTkrfd27l3nec wnUTQqEAFEXHBVRWc2DksXNBUsMlNea2BjAReQRBMiT3BrHKlhMsoyGS3RH4hJ857Lte 2JG3u8+LG6OGemey4OxhvrV1yeGtvk6jGPxRnd5hoaopGml6YI5vv1gMuO/vVjQLrKBg RAUUO6Ma3695tYOFI/U+WbYZ2DybiWe2L69qJyaWRdHTGNDpODRwXE2NEucPSRd5RkdY bboYpQrCo07IxzXUddtMSx0CiAWr1N8bBEatHzocmQWrqSKrPtLPhehffeVVK7FwRwwV FbUg== X-Gm-Message-State: AOAM532tNvMtY5qAUSCPgPpa63eh6f50Nl9/dJFNUP9/Sd8GZ3xN0jhI kJ6MiwSSLeni0b0tIp3Qvy8+Ic/B6ADGlg== X-Received: by 2002:a19:ca4a:: with SMTP id h10mr3613117lfj.131.1623443955774; Fri, 11 Jun 2021 13:39:15 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id t3sm687479lfl.78.2021.06.11.13.39.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:39:15 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:58 +0200 Message-Id: <20210611203104.1692-28-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 27/33] avdevice/dshow: implement capabilities API 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: r5qlbnFiqdW0 Content-Length: 25710 This implements avdevice_capabilities_create for the dshow device (avdevice_capabilities_free not needed as it would be no-op). This enables configuration discovery of DirectShow devices through the API, which is important for my use case. It enables making proper GUIs presenting users with options, instead of asking them to discover a dshow device's capabilities through the list_options option with an FFmpeg tool, and listing what they want to configure in dumb text boxes. Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 377 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 358 insertions(+), 19 deletions(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 20f58aee63..73113acddd 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -27,6 +27,7 @@ #include "libavformat/internal.h" #include "libavformat/riff.h" #include "avdevice.h" +#include "internal.h" #include "libavcodec/raw.h" #include "objidl.h" #include "shlwapi.h" @@ -834,11 +835,15 @@ static struct dshow_format_info* dshow_get_format_info(AM_MEDIA_TYPE* type) * 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. + * If pformat_set is NULL or the ranges input is not NULL, list all + * pin capabilities. + * When listing pin capabilities, if ranges is NULL, output to log, + * else store capabilities in ranges. */ static void dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, - IPin *pin, int *pformat_set) + IPin *pin, int *pformat_set, + AVOptionRanges *ranges, enum AVDeviceCapabilitiesQueryType query_type) { struct dshow_ctx *ctx = avctx->priv_data; IAMStreamConfig *config = NULL; @@ -882,7 +887,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, * one, with most info exposed (see comment below). */ use_default = !dshow_should_set_format(avctx, devtype); - if (use_default && pformat_set) + if (use_default && pformat_set && !ranges) { HRESULT hr; @@ -950,7 +955,9 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, // 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++) { + for (i = 0; i < n && (!format_set || ranges); i++) { + AVOptionRange *new_range[3] = { NULL }; + int nb_range = 0; struct dshow_format_info *fmt_info = NULL; r = IAMStreamConfig_GetStreamCaps(config, i, &type, (void *) caps); if (r != S_OK) @@ -986,7 +993,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, wait_for_better = 0; } - if (!pformat_set) { + if (!pformat_set && !ranges) { 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) { @@ -1050,6 +1057,60 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, bih->biWidth = requested_width; bih->biHeight = requested_height; } + + if (ranges) { + for (int j = 0; j < ranges->nb_components; j++) { + new_range[j] = av_mallocz(sizeof(**new_range)); + if (!new_range[j]) + goto next; + new_range[j]->value_max = -1.; // init (min:0, max:-1 means value not set) + ++nb_range; + + switch (query_type) + { + case AV_DEV_CAP_QUERY_CODEC: + if (dshow_pixfmt(bih->biCompression, bih->biBitCount) == AV_PIX_FMT_NONE) { + const AVCodecTag* const tags[] = { avformat_get_riff_video_tags(), NULL }; + new_range[j]->value_min = av_codec_get_id(tags, bih->biCompression); + } + else + new_range[j]->value_min = AV_CODEC_ID_RAWVIDEO; + new_range[j]->value_max = new_range[j]->value_min; + break; + case AV_DEV_CAP_QUERY_PIXEL_FORMAT: + new_range[j]->value_min = new_range[j]->value_max = dshow_pixfmt(bih->biCompression, bih->biBitCount); + new_range[j]->value_min; + break; + case AV_DEV_CAP_QUERY_FRAME_SIZE: + { + switch (j) + { + case 0: + new_range[j]->value_min = vcaps->MinOutputSize.cx * vcaps->MinOutputSize.cy; + new_range[j]->value_max = vcaps->MaxOutputSize.cx * vcaps->MaxOutputSize.cy; + break; + case 1: + new_range[j]->value_min = vcaps->MinOutputSize.cx; + new_range[j]->value_max = vcaps->MaxOutputSize.cx; + break; + case 2: + new_range[j]->value_min = vcaps->MinOutputSize.cy; + new_range[j]->value_max = vcaps->MaxOutputSize.cy; + break; + } + break; + } + case AV_DEV_CAP_QUERY_FPS: + new_range[j]->value_min = 1e7 / vcaps->MaxFrameInterval; + new_range[j]->value_max = 1e7 / vcaps->MinFrameInterval; + break; + + // default: + // an audio property is being queried, output all fields 0 (mallocz above) is fine + } + } + } + } else { AUDIO_STREAM_CONFIG_CAPS *acaps = caps; WAVEFORMATEX *fx; @@ -1061,7 +1122,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, } else { goto next; } - if (!pformat_set) { + if (!pformat_set && !ranges) { av_log(avctx, AV_LOG_INFO, " min ch=%lu bits=%lu rate=%6lu max ch=%lu bits=%lu rate=%6lu\n", acaps->MinimumChannels, acaps->MinimumBitsPerSample, acaps->MinimumSampleFrequency, acaps->MaximumChannels, acaps->MaximumBitsPerSample, acaps->MaximumSampleFrequency); @@ -1085,15 +1146,69 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, goto next; fx->nChannels = requested_channels; } + + if (ranges) { + for (int j = 0; j < ranges->nb_components; j++) { + new_range[j] = av_mallocz(sizeof(**new_range)); + if (!new_range[j]) + goto next; + new_range[j]->value_max = -1.; // init (min:0, max:-1 means value not set) + ++nb_range; + + switch (query_type) + { + case AV_DEV_CAP_QUERY_SAMPLE_FORMAT: + new_range[j]->value_min = sample_fmt_bits_per_sample(acaps->MinimumBitsPerSample); + new_range[j]->value_max = sample_fmt_bits_per_sample(acaps->MaximumBitsPerSample); + break; + case AV_DEV_CAP_QUERY_SAMPLE_RATE: + new_range[j]->value_min = acaps->MinimumSampleFrequency; + new_range[j]->value_max = acaps->MaximumSampleFrequency; + break; + case AV_DEV_CAP_QUERY_CHANNELS: + new_range[j]->value_min = acaps->MinimumChannels; + new_range[j]->value_max = acaps->MaximumChannels; + break; + + // default: + // a video property is being queried, output all fields 0 (mallocz above) is fine + // NB: this is a for-loop since some of the video queries are multi-component + // and all components should be set + } + } + } } // 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) { + // above loop). If storing all capabilities of device + // in ranges, try to apply in all cases, and store + // caps if successfully applied + if (!wait_for_better || ranges) { if (IAMStreamConfig_SetFormat(config, type) != S_OK) goto next; + else if (ranges) { + // format matched and could be set successfully. + // fill in some fields for each capability + for (int j = 0; j < nb_range; j++) { + new_range[j]->str = av_strdup(ff_device_get_query_component_name(query_type, j)); + if (!new_range[j]->str) + goto next; + new_range[j]->is_range = new_range[j]->value_min < new_range[j]->value_max; + } + + // store to ranges output + if (av_reallocp_array(&ranges->range, + ranges->nb_ranges*ranges->nb_components + nb_range*ranges->nb_components, + sizeof(*ranges->range)) < 0) + goto next; + for (int j = 0; j < nb_range; ++j) { + ranges->range[ranges->nb_ranges] = new_range[j]; + ranges->nb_ranges++; + new_range[j] = NULL; // copied into array, make sure not freed below + } + } format_set = 1; } else if (!previous_match_type) { @@ -1105,6 +1220,12 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, next: if (fmt_info) av_free(fmt_info); + for (int j = 0; j < nb_range; ++j) { + if (new_range[j]) { + av_freep(&new_range[j]->str); + av_freep(&new_range[j]); + } + } if (type && type->pbFormat) CoTaskMemFree(type->pbFormat); CoTaskMemFree(type); @@ -1227,10 +1348,13 @@ end: * devtype, retrieve the first output pin and return the pointer to the * object found in *ppin. * If ppin is NULL, cycle through all pins listing audio/video capabilities. + * If ppin is not NULL and ranges is also not null, enumerate all formats + * supported by the selected pin. */ static int dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype, - enum dshowSourceFilterType sourcetype, IBaseFilter *device_filter, IPin **ppin) + enum dshowSourceFilterType sourcetype, IBaseFilter *device_filter, + IPin **ppin, AVOptionRanges *ranges, enum AVDeviceCapabilitiesQueryType query_type) { struct dshow_ctx *ctx = avctx->priv_data; IEnumPins *pins = 0; @@ -1269,6 +1393,7 @@ dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype, wchar_t *pin_id = NULL; char *pin_buf = NULL; char *desired_pin_name = devtype == VideoDevice ? ctx->video_pin_name : ctx->audio_pin_name; + int nb_ranges = ranges ? ranges->nb_ranges : 0; IPin_QueryPinInfo(pin, &info); IBaseFilter_Release(info.pFilter); @@ -1293,7 +1418,7 @@ dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype, if (!ppin) { av_log(avctx, AV_LOG_INFO, " Pin \"%s\" (alternative pin name \"%s\")\n", name_buf, pin_buf); - dshow_cycle_formats(avctx, devtype, pin, NULL); + dshow_cycle_formats(avctx, devtype, pin, NULL, NULL, AV_DEV_CAP_QUERY_NONE); goto next; } @@ -1307,12 +1432,15 @@ dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype, // 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 ranges is non-NULL, will iterate over all formats and return info + // about all the valid ones. If any valid found, format_set==1, else + // format_set will be 0 + dshow_cycle_formats(avctx, devtype, pin, &format_set, ranges, query_type); if (!format_set) { goto next; } - if (devtype == AudioDevice && ctx->audio_buffer_size) { + if (devtype == AudioDevice && ctx->audio_buffer_size && !ranges) { 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); } @@ -1325,8 +1453,25 @@ dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype, next: if (p) IKsPropertySet_Release(p); - if (device_pin != pin) + if (device_pin != pin) { IPin_Release(pin); + // remove any option ranges info we just added, wrong pin + if (ranges && nb_ranges>0) { + int nb_original_entries = nb_ranges * ranges->nb_components; + for (int i = nb_original_entries; i < ranges->nb_ranges * ranges->nb_components; i++) { + AVOptionRange* range = ranges->range[i]; + if (range) { + av_freep(&range->str); + av_freep(&ranges->range[i]); + } + } + if (av_reallocp_array(&ranges->range, nb_original_entries, sizeof(*ranges->range)) < 0) + ranges->nb_ranges = 0; + else + ranges->nb_ranges = nb_ranges; + } + device_pin = NULL; + } av_free(name_buf); av_free(pin_buf); if (pin_id) @@ -1358,17 +1503,19 @@ next: */ static int dshow_list_device_options(AVFormatContext *avctx, ICreateDevEnum *devenum, - enum dshowDeviceType devtype, enum dshowSourceFilterType sourcetype) + enum dshowDeviceType devtype, enum dshowSourceFilterType sourcetype, + AVOptionRanges *ranges, enum AVDeviceCapabilitiesQueryType query_type) { struct dshow_ctx *ctx = avctx->priv_data; IBaseFilter *device_filter = NULL; + IPin *device_pin = NULL; char *device_unique_name = NULL; int r; if ((r = dshow_cycle_devices(avctx, devenum, devtype, sourcetype, &device_filter, &device_unique_name, NULL)) < 0) return r; ctx->device_filter[devtype] = device_filter; - if ((r = dshow_cycle_pins(avctx, devtype, sourcetype, device_filter, NULL)) < 0) + if ((r = dshow_cycle_pins(avctx, devtype, sourcetype, device_filter, ranges ? &device_pin : NULL, ranges, query_type)) < 0) return r; av_freep(&device_unique_name); return 0; @@ -1452,7 +1599,7 @@ dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum, goto error; } - if ((r = dshow_cycle_pins(avctx, devtype, sourcetype, device_filter, &device_pin)) < 0) { + if ((r = dshow_cycle_pins(avctx, devtype, sourcetype, device_filter, &device_pin, NULL, AV_DEV_CAP_QUERY_NONE)) < 0) { ret = r; goto error; } @@ -1879,14 +2026,14 @@ static int dshow_read_header(AVFormatContext *avctx) } if (ctx->list_options) { if (ctx->device_name[VideoDevice]) - if ((r = dshow_list_device_options(avctx, devenum, VideoDevice, VideoSourceDevice))) { + if ((r = dshow_list_device_options(avctx, devenum, VideoDevice, VideoSourceDevice, NULL, AV_DEV_CAP_QUERY_NONE))) { ret = r; goto error; } if (ctx->device_name[AudioDevice]) { - if (dshow_list_device_options(avctx, devenum, AudioDevice, AudioSourceDevice)) { + if (dshow_list_device_options(avctx, devenum, AudioDevice, AudioSourceDevice, NULL, AV_DEV_CAP_QUERY_NONE)) { /* show audio options from combined video+audio sources as fallback */ - if ((r = dshow_list_device_options(avctx, devenum, AudioDevice, VideoSourceDevice))) { + if ((r = dshow_list_device_options(avctx, devenum, AudioDevice, VideoSourceDevice, NULL, AV_DEV_CAP_QUERY_NONE))) { ret = r; goto error; } @@ -2032,6 +2179,197 @@ static int dshow_read_packet(AVFormatContext *s, AVPacket *pkt) return ctx->eof ? AVERROR(EIO) : pkt->size; } +// TODO: consider if and how to expose extra info we have about formats, such as color_range +static int dshow_query_ranges(AVOptionRanges** ranges_arg, void* obj, const char* key, int flags) +{ + AVDeviceCapabilitiesQuery *caps = obj; + const AVFormatContext *avctx = caps->device_context; + struct dshow_ctx *ctx = avctx->priv_data; + + int backup_sample_size; + int backup_sample_rate; + int backup_channels; + enum AVCodecID backup_video_codec_id; + enum AVPixelFormat backup_pixel_format; + int backup_requested_width; + int backup_requested_height; + char* backup_framerate = NULL; + + enum AVDeviceCapabilitiesQueryType query_type = AV_DEV_CAP_QUERY_NONE; + + AVOptionRanges *ranges = av_mallocz(sizeof(**ranges_arg)); + const AVOption *field = av_opt_find(obj, key, NULL, 0, flags); + int ret; + + ICreateDevEnum *devenum = NULL; + + *ranges_arg = NULL; + + if (!ranges) { + ret = AVERROR(ENOMEM); + goto fail1; + } + + if (!field) { + ret = AVERROR_OPTION_NOT_FOUND; + goto fail1; + } + + // turn option name into cap query + query_type = ff_device_get_query_type(field->name); + + if (query_type == AV_DEV_CAP_QUERY_CHANNEL_LAYOUT || query_type == AV_DEV_CAP_QUERY_WINDOW_SIZE) { + av_log(avctx, AV_LOG_ERROR, "Querying the option %s is not supported for a dshow device\n", field->name); + ret = AVERROR(EINVAL); + goto fail1; + } + + if (ctx->device_name[0]) { + av_log(avctx, AV_LOG_ERROR, "You cannot query device capabilities on an opened device\n"); + ret = AVERROR(EIO); + goto fail1; + } + + if (!parse_device_name(avctx)) { + av_log(avctx, AV_LOG_ERROR, "You must set a device name (AVFormatContext url) to specify which device to query capabilities from\n"); + ret = AVERROR(EINVAL); + goto fail1; + } + + // take backup of dshow parameters/options + // audio + backup_sample_size = ctx->sample_size; + backup_sample_rate = ctx->sample_rate; + backup_channels = ctx->channels; + // video + backup_video_codec_id = ctx->video_codec_id; + backup_pixel_format = ctx->pixel_format; + backup_requested_width = ctx->requested_width; + backup_requested_height= ctx->requested_height; + backup_framerate = ctx->framerate; + + + // set format constraints set in AVDeviceCapabilitiesQuery + // audio (NB: channel_layout not used) + ctx->sample_size = av_get_bytes_per_sample(caps->sample_format) << 3; + ctx->sample_rate = (caps->sample_rate == -1) ? 0 : caps->sample_rate; + ctx->channels = (caps->channels == -1) ? 0 : caps->channels; + // video (NB: window_width and window_height not used) + ctx->video_codec_id = caps->codec; + ctx->pixel_format = caps->pixel_format; + ctx->requested_width = caps->frame_width; + ctx->requested_height = caps->frame_height; + // checking whether requested framerate is set is done by !ctx->framerate + if (caps->fps.num > 0 && caps->fps.den > 0) { + ctx->requested_framerate = caps->fps; + ctx->framerate = av_strdup("dummy"); // just make sure its non-zero + if (!ctx->framerate) { + ret = AVERROR(ENOMEM); + goto fail2; + } + } + else + ctx->framerate = NULL; // make sure its NULL (if it wasn't, we already have a backup of the pointer to restore later) + + // now iterate matching format of pin that would be selected when device + // is opened with options currently in effect. + // for each matching format, output its parameter range, also if that same + // range already returned for another format. That way, user can reconstruct + // possible valid combinations by av_opt_query_ranges() for each of the + // format options and matching returned values by sequence number. + CoInitialize(0); + + if (CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, + &IID_ICreateDevEnum, (void **) &devenum)) { + av_log(avctx, AV_LOG_ERROR, "Could not enumerate system devices.\n"); + ret = AVERROR(EIO); + goto fail2; + } + ctx->video_codec_id = avctx->video_codec_id ? avctx->video_codec_id + : AV_CODEC_ID_RAWVIDEO; + + ranges->nb_components = (field->type == AV_OPT_TYPE_IMAGE_SIZE && (flags & AV_OPT_MULTI_COMPONENT_RANGE)) ? 3 : 1; + if (ctx->device_name[VideoDevice]) + if ((ret = dshow_list_device_options(avctx, devenum, VideoDevice, VideoSourceDevice, ranges, query_type)) < 0) + goto fail2; + if (ctx->device_name[AudioDevice]) { + if (dshow_list_device_options(avctx, devenum, AudioDevice, AudioSourceDevice, ranges, query_type) < 0) { + /* show audio options from combined video+audio sources as fallback */ + if ((ret = dshow_list_device_options(avctx, devenum, AudioDevice, VideoSourceDevice, ranges, query_type)) < 0) + goto fail2; + } + } + ret = ranges->nb_ranges ? ranges->nb_components : 0; + + // when dealing with a multi-component item (regardless of whether + // AV_OPT_MULTI_COMPONENT_RANGE is set or not), we need to reorganize the + // output range array from [r1_c1 r1_c2 r1_c3 r2_c1 r2_c2 r2_c3 ...] to + // [r1_c1 r2_c1 ... r1_c2 r2_c2 ... r1_c3 r2_c3 ...] to be consistent with + // documentation of AVOptionRanges in libavutil/opt.h + if (ranges->nb_ranges && ranges->nb_components>1) { + AVOptionRange **new_range = av_malloc_array(ranges->nb_components * ranges->nb_ranges, sizeof(*ranges->range)); + AVOptionRange **old_range = ranges->range; + if (!new_range) { + ret = AVERROR(ENOMEM); + goto fail2; + } + ranges->nb_ranges /= ranges->nb_components; + for (int n = 0; n < ranges->nb_components * ranges->nb_ranges; n++) { + int i = n / ranges->nb_components; + int j = n % ranges->nb_components; + new_range[ranges->nb_ranges * j + i] = old_range[n]; + } + ranges->range = new_range; + av_freep(&old_range); + } + + // success, set output + *ranges_arg = ranges; + +fail2: + // set dshow parameters/options back to original values + // audio + ctx->sample_size = backup_sample_size; + ctx->sample_rate = backup_sample_rate; + ctx->channels = backup_channels; + // video + ctx->video_codec_id = backup_video_codec_id; + ctx->pixel_format = backup_pixel_format; + ctx->requested_width = backup_requested_width; + ctx->requested_height = backup_requested_height; + if (ctx->framerate) + av_free(ctx->framerate); + ctx->framerate = backup_framerate; + + if (devenum) + ICreateDevEnum_Release(devenum); + + // clear state variables that may have been set during the above process + // (e.g. frees device names, removes device_filters, etc) + dshow_read_close(avctx); + +fail1: + if (ret < 0) + av_opt_freep_ranges(&ranges); + + return ret; +} + +// fake class to point av_opt_query_ranges to our query_ranges function +static const AVClass dshow_dev_caps_class = { + .class_name = "", + .item_name = av_default_item_name, + .option = ff_device_capabilities, + .version = LIBAVUTIL_VERSION_INT, + .query_ranges = dshow_query_ranges, +}; + +static int dshow_create_device_capabilities(struct AVFormatContext* avctx, AVDeviceCapabilitiesQuery *caps) +{ + caps->av_class = &dshow_dev_caps_class; + return 0; +} + #define OFFSET(x) offsetof(struct dshow_ctx, x) #define DEC AV_OPT_FLAG_DECODING_PARAM static const AVOption options[] = { @@ -2081,6 +2419,7 @@ const AVInputFormat ff_dshow_demuxer = { .read_close = dshow_read_close, .control_message = dshow_control_message, .get_device_list= dshow_get_device_list, + .create_device_capabilities = dshow_create_device_capabilities, .flags = AVFMT_NOFILE | AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK, .priv_class = &dshow_class, }; From patchwork Fri Jun 11 20:30:59 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: 28236 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:bbc9:0:0:0:0:0 with SMTP id c9csp837652ybk; Fri, 11 Jun 2021 13:39:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmIhI3rVECVrUOdmZKY7hd65q35HJVrzGTVnzHonwjUeyBBsQf14ZSZ2Xi+D0jbB7jBcu/ X-Received: by 2002:a05:6402:344:: with SMTP id r4mr5451078edw.226.1623443976482; Fri, 11 Jun 2021 13:39:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443976; cv=none; d=google.com; s=arc-20160816; b=0quEQeXPrafEXWVqAVbAAaQAn76uaiSxVw7UkfnP72+UmS0sfFLHq/GqNDUJbsgBgF qGdVbDpUG0IK245/ByNb5B/yqGGaHYCbFLP1D7gL/pVzW8ozCDzsXAVJdwnciwyFNvEX eLLslkapt16ifDGcVTfIYzKKLBDR3p9zkwUhMVOUm49xarMgEjYoIUhnsXsi9qT+or83 m75iXiDVx/gymN92EVVSj4M4vECZSGLQNACg+w2A8HdaK8jgB+f0JemSkDdzJqJkBbu7 1bKcfkoIoSfGCw638SCBsxL3uNEXso+hDiatO5/K3H28YQVZJgzdtM+7K40aIBECkFmf 2MEw== 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=x8ebOPa1sat17RWnvmXDNAgeFSFQUbmj1zqw7fw3+to=; b=TUhWJAa6WADfMSnxwtIlJDxNXAARfRVzFIS2FWZtb26n9cejsAJwhA40KkF0LVa1LW C3d3t0Jcwt6X8qYxHjQVnU3NdBBaExaqDV2BoSO6ZtAc4y9GpiY7j26A6qF/dHi58ej8 EGfU8CGh8uvXG/n4c0HpiNzaTEuXoYf3WrJSHIx+UjBZ2g+2iVpY1vskleQt7St9rn+0 DXnY3VQ2puDkmyymJ+Hc9ZXwt2n3J4MHBT+f+7YGSveGlRewWFZdR/isis/ojS0l6CGX xo1cvXHOp3S14zIqpVC0K25DgMyNQNkBV1LwBQ5pxa5SCbEK1FnHwNO23nTHjs4U9QAo kXIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=l4iULm6c; 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 p10si5580699edy.258.2021.06.11.13.39.36; Fri, 11 Jun 2021 13:39:36 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=l4iULm6c; 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 0DBAF689ADA; Fri, 11 Jun 2021 23:39:35 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C738E688181 for ; Fri, 11 Jun 2021 23:39:33 +0300 (EEST) Received: by mail-lj1-f177.google.com with SMTP id r16so11296335ljk.9 for ; Fri, 11 Jun 2021 13:39:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IbevVvoGqyPBQJMizcqWMdn1ypgKWx2OMmgk2zmrqF0=; b=l4iULm6cR2d4Y28WYIBoVPhjzNVYY4h18UkA4zXbXymWfM3q1+nOS80CkZhQuhskQF L/n78Q+SXuh7e4+hHqn22ylKzQWo8VxjIGnapfWTs4rhPDz/dxtSMNk61YxUZOE/mN5c EYPaj4bxzR+ftMAwAQscznmmXeXAmCYGcAl9QOLjCqZbQ6qwS01uDaGPvtgUUwL8S9j0 +uWFW1OrIPI5lsdzpBc/cZk+eHvx+fh5XOBpPBoxgp9rKSUM7YfdIPd0L0PDt9XpXTcW 4SCKeBOXuFZi5cpvsvR4eKy4W1ZFqvSbWk1r8XUbwK2kV6D25DU2ZpwN+JY5SQgO8JD/ ebaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IbevVvoGqyPBQJMizcqWMdn1ypgKWx2OMmgk2zmrqF0=; b=cJQMIRoFfZ0c2wbTdYb8JueStCN36VW40aTghyXLbVmr1brrSvui5Qo0btcMqoU6E1 xDB9hbYtZPm8n7qQrpw+mxuah639C/d30y6Y26g29buxxetn1esUFj0ecCnzo9wo6qoL JjTYWkG+Ean9efwEeUP5liJ0azQg/YM1NJadnOA5UDeAHk/V3XfwpPitnofrtV6R6OzY mSOLlbg6j9t/NCm2uSjxi8E/fbnqgChaCtaeI1dosAE/IR3kglmNkwGhHTYcnc+txWcW Z3mU+j1R/IAHEYjCMz0XAQK6dBc+dDJBaK5CnBdm9MIEEvnu5DvvHCVzm+eQPjcvuSz7 zDdw== X-Gm-Message-State: AOAM530SLIz2/HglV0Q4tY2tppTGk7rncTg73rbrMixuT7Nj3wXCSrdm 7rHnkkK0wDAFeZstV9Shi6QLQnYKTAuC6w== X-Received: by 2002:a2e:2f1d:: with SMTP id v29mr4246449ljv.44.1623443972571; Fri, 11 Jun 2021 13:39:32 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id g19sm685569lfu.274.2021.06.11.13.39.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:39:32 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:59 +0200 Message-Id: <20210611203104.1692-29-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 28/33] avdevice/dshow: cosmetics 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: UzlK6Vy0oh8j Content-Length: 2236 Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 73113acddd..92cfaa062d 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -959,6 +959,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, AVOptionRange *new_range[3] = { NULL }; int nb_range = 0; struct dshow_format_info *fmt_info = NULL; + r = IAMStreamConfig_GetStreamCaps(config, i, &type, (void *) caps); if (r != S_OK) goto next; @@ -2411,15 +2412,15 @@ static const AVClass dshow_class = { }; const AVInputFormat ff_dshow_demuxer = { - .name = "dshow", - .long_name = NULL_IF_CONFIG_SMALL("DirectShow capture"), - .priv_data_size = sizeof(struct dshow_ctx), - .read_header = dshow_read_header, - .read_packet = dshow_read_packet, - .read_close = dshow_read_close, - .control_message = dshow_control_message, - .get_device_list= dshow_get_device_list, + .name = "dshow", + .long_name = NULL_IF_CONFIG_SMALL("DirectShow capture"), + .priv_data_size = sizeof(struct dshow_ctx), + .read_header = dshow_read_header, + .read_packet = dshow_read_packet, + .read_close = dshow_read_close, + .control_message = dshow_control_message, + .get_device_list = dshow_get_device_list, .create_device_capabilities = dshow_create_device_capabilities, - .flags = AVFMT_NOFILE | AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK, - .priv_class = &dshow_class, + .flags = AVFMT_NOFILE | AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK, + .priv_class = &dshow_class, }; From patchwork Fri Jun 11 20:31:00 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: 28237 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:bbc9:0:0:0:0:0 with SMTP id c9csp837839ybk; Fri, 11 Jun 2021 13:39:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwF5/joTnKsb8dvDX7cdU5c6qKEZsekRANTv10OrHc+/Ui0CnJuM8FADyw1kpzqx9ZmvHXc X-Received: by 2002:a05:6402:520b:: with SMTP id s11mr5455608edd.111.1623443993959; Fri, 11 Jun 2021 13:39:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443993; cv=none; d=google.com; s=arc-20160816; b=lW4YB/9oolWcvf9fZ7XtLoOLiW05A2fna2LJLpJd1Up/3fhdNt6dapyWQVzZyu/Mph jcr6E1MkBa1xLh+fw0vcaalpR4msxVmAjsQuLdRbV9WKn/jbI6Hqw0luviifqytx5IEE w2icxFTgJDu48364EXTUNQwS9DgmaqxaWqvOLAtvprr8N3pE260U+a+Ha2ygOoB3JK0T Ekesk3gb8WSw35a/2dcomk9LU7hmkmQfnpX6NlJDCpshbLOcacvOnXApQLsh7GL2+Grd B/5xK2auuxfQhlOkleX4WgcMtaEFFaUd8jdAaOJ+dLmxOHZTC5uLRAm02NltFNacp4j4 0wVQ== 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=dNw5PkdZKUZGXGLpkPbRnNtj8PygWiwHNlyhEkB3hL4=; b=lPkplmCCwhkl84t29CYen7+MBTGNkGl32UABUbL9x8HzQB3ivdm3a6D1HaJ4Qkc93s SAQPuF7oN/Mh72n1a4PDc4hNcFYY2SCiiFKGwOd6C0RvObMI+5iPG6C92Y1CAKz8A9K6 1dYDddoHb3dA/I4TQOHJ+Jjjgvsbzm9jW5+GOisFVsOLKMkkRjX1Fp0++wxxJvpCD3lV r1OAVmkkuHqbMHy5FIrKsz4YvNc6QQXrOWxgtILfHOuTussog/3528hJjoqNiSdsxVuY 7Om8SXZmPIFkR/oNIGgHvONJirdWXfKPJYnwUXE7K1JEzcbjz8/R4aijNga44f8gCitp ZE5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=VptQS062; 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 m29si5459024ejl.33.2021.06.11.13.39.53; Fri, 11 Jun 2021 13:39:53 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=VptQS062; 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 18E54689B33; Fri, 11 Jun 2021 23:39:52 +0300 (EEST) 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 5A15568813A for ; Fri, 11 Jun 2021 23:39:50 +0300 (EEST) Received: by mail-lj1-f173.google.com with SMTP id r16so11297078ljk.9 for ; Fri, 11 Jun 2021 13:39:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Mp3kOdotOYUMKYYj93Ysqn1Fp3AujUZVQdFSiwb69T8=; b=VptQS06231ZXlOuJm2y9/VV1UdR1/QvUL5480UfHKKKG5LBp4zMbkB8a9lzw6pZdNO r7XmSlFi6/tXsFP6tatWPmpthZpI5xTum8Lr5UI337rrEscuSQDJkrgfFj8+KEYEieMM kIJIfnpET2BzOv+hTyhNb4tfO9xmkvg1jg39vJ/Ir0G10ZuE1bJZmMVgfHsBwtEKUus+ sWhu6pPOpZrGR8I0V7aiEbl7dRcqhYA6KYwTkK9KBIf+nUsND9gI/EI24Fs+tYwmHIKE 6GHtf+ooP7OV7CTnpaD30vNLSDCj7i7QK+MQPVRxxq1jA+TgLgNryKhjPgeO02OSauyT K33w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Mp3kOdotOYUMKYYj93Ysqn1Fp3AujUZVQdFSiwb69T8=; b=ke8b26TTUc3q7P8VSNt+NWXmgI0ggZSvI/PCwK5X2VUuWkD+dgFBfeJ8M/iC7gdK7k A+xWmVdxhObrc0pfjNqOF89+XloXHbD/6ZNpyAkQY2/ugVOZ2nVh8EAh51lsBIPDiX0Z 9nUPif98gut8OdJz7GFH/MhQW2ip5RSmfPu/vEvAImNtTFRJytObmU6NfZam39uhN8M1 QScXHCoxnE7N6zwo5deDNOivoGUaiTDoouqaddSo4d5NSBfAsnSdd+mTdE/Bkv8RHPCe 3PSBF5N0rLT+r9A9N9gIZg7toP3lk0pXT3Ts75SFRN/+Z2WuceRYtQd4mgjEGyZtwOB4 Ibug== X-Gm-Message-State: AOAM531Utpr6ObsMs4BTOZF3K0MLPsdh8uFEZmNUEofSTcBeX3c4OQUR YMXqqii6OmUMmgjzwHKTpvA3lzTkB+x46Q== X-Received: by 2002:a05:651c:1422:: with SMTP id u34mr4393102lje.149.1623443989389; Fri, 11 Jun 2021 13:39:49 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id a17sm687957lfs.59.2021.06.11.13.39.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:39:48 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:31:00 +0200 Message-Id: <20210611203104.1692-30-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 29/33] avformat: add avformat_alloc_input_context() 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: DJebomalyvpB Content-Length: 8778 avformat_alloc_input_context function analogous to avformat_alloc_output_context2, except that it does not take a filename argument as guessing the format by just the filename does not make sense. avformat_alloc_input_context can be used e.g. with the avdevice capabilities API, which needs an allocated input format with priv_data (and default options) set, but device should not be opened. Added some checks to avformat_open_input, for the case that a AVFormatContext* allocated by avformat_alloc_input_context is provided: 1. if avformat_open_input's AVInputFormat *fmt argument is not NULL, clean up any already set s->iformat 2. if s->url is already set and avformat_open_input's filename argument is not NULL, free current url and replace by provided filename 3. if s->url is already set and avformat_open_input's filename argument is NULL, do not set s->url to "", but keep current url 4. if s->priv_data has already been allocated, do not do so again. 4b. do reset options to default and apply provided options (if any) 5. add 4b to docs of avformat_open_input Bumping avformat version. Signed-off-by: Diederick Niehorster --- libavformat/avformat.h | 29 +++++++++++++++-- libavformat/utils.c | 74 ++++++++++++++++++++++++++++++++++++++---- libavformat/version.h | 2 +- 3 files changed, 95 insertions(+), 10 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 54457572b1..80575524b4 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1879,6 +1879,26 @@ AVProgram *av_new_program(AVFormatContext *s, int id); * @} */ + /** + * Allocate an AVFormatContext for an input format. + * avformat_free_context() can be used to free the context and + * everything allocated by the framework within it. NB: in general + * the correct format cannot be known (unless the user has extra + * information) until the file is opened. If forcing a format by + * this method, but it turns out not to match the file's format + * upon avformat_open_input(), the latter will throw an error. + * + * @param *ctx is set to the created format context, or to NULL in + * case of failure + * @param iformat format to use for allocating the context, if NULL + * format_name is used instead + * @param format_name the name of input format to use for allocating the + * context + * @return >= 0 in case of success, a negative AVERROR code in case of + * failure + */ +int avformat_alloc_input_context(AVFormatContext** ctx, const AVInputFormat* iformat, + const char* format_name); /** * Allocate an AVFormatContext for an output format. @@ -1974,9 +1994,9 @@ int av_probe_input_buffer(AVIOContext *pb, const AVInputFormat **fmt, * Open an input stream and read the header. The codecs are not opened. * The stream must be closed with avformat_close_input(). * - * @param ps Pointer to user-supplied AVFormatContext (allocated by avformat_alloc_context). - * May be a pointer to NULL, in which case an AVFormatContext is allocated by this - * function and written into ps. + * @param ps Pointer to user-supplied AVFormatContext (allocated by avformat_alloc_context, or + * avformat_alloc_input_context). May be a pointer to NULL, in which case an + * AVFormatContext is allocated by this function and written into ps. * Note that a user-supplied AVFormatContext will be freed on failure. * @param url URL of the stream to open. * @param fmt If non-NULL, this parameter forces a specific input format. @@ -1984,6 +2004,9 @@ int av_probe_input_buffer(AVIOContext *pb, const AVInputFormat **fmt, * @param options A dictionary filled with AVFormatContext and demuxer-private options. * On return this parameter will be destroyed and replaced with a dict containing * options that were not found. May be NULL. + * Note that if a AVFormatContext allocated by avformat_alloc_input_context + * is provided, any demuxer-private options will be overwritten by their defaults + * before applying this new set of demuxer-private options, if any. * * @return 0 on success, a negative AVERROR on failure. * diff --git a/libavformat/utils.c b/libavformat/utils.c index 5582d108d0..cf1a884043 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -478,6 +478,56 @@ static int update_stream_avctx(AVFormatContext *s) } +int avformat_alloc_input_context(AVFormatContext** avctx, const AVInputFormat* iformat, + const char* format) +{ + AVFormatContext* s = avformat_alloc_context(); + int ret = 0; + + *avctx = NULL; + if (!s) + goto nomem; + + if (!iformat) { + if (format) { + iformat = av_find_input_format(format); + if (!iformat) { + av_log(s, AV_LOG_ERROR, "Requested input format '%s' not found\n", format); + ret = AVERROR(EINVAL); + goto error; + } + } + else { + av_log(s, AV_LOG_ERROR, "You should provide an input format or the name of an input format when calling this function\n"); + ret = AVERROR(EINVAL); + goto error; + } + } + + s->iformat = iformat; + if (s->iformat->priv_data_size > 0) { + s->priv_data = av_mallocz(s->iformat->priv_data_size); + if (!s->priv_data) + goto nomem; + if (s->iformat->priv_class) { + *(const AVClass**)s->priv_data = s->iformat->priv_class; + av_opt_set_defaults(s->priv_data); + } + } + else + s->priv_data = NULL; + + *avctx = s; + return 0; +nomem: + av_log(s, AV_LOG_ERROR, "Out of memory\n"); + ret = AVERROR(ENOMEM); +error: + avformat_free_context(s); + return ret; +} + + int avformat_open_input(AVFormatContext **ps, const char *filename, const AVInputFormat *fmt, AVDictionary **options) { @@ -492,8 +542,14 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, av_log(NULL, AV_LOG_ERROR, "Input context has not been properly allocated by avformat_alloc_context() and is not NULL either\n"); return AVERROR(EINVAL); } - if (fmt) + if (fmt) { + if (s->iformat) { + if (s->iformat->priv_class && s->priv_data) + av_opt_free(s->priv_data); + av_freep(&s->priv_data); + } s->iformat = fmt; + } if (options) av_dict_copy(&tmp, *options, 0); @@ -504,7 +560,9 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, if ((ret = av_opt_set_dict(s, &tmp)) < 0) goto fail; - if (!(s->url = av_strdup(filename ? filename : ""))) { + if (filename && s->url) + av_freep(&s->url); + if (!s->url && !(s->url = av_strdup(filename ? filename : ""))) { ret = AVERROR(ENOMEM); goto fail; } @@ -547,12 +605,16 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, s->duration = s->start_time = AV_NOPTS_VALUE; - /* Allocate private data. */ + /* Allocate private data and set options. */ if (s->iformat->priv_data_size > 0) { - if (!(s->priv_data = av_mallocz(s->iformat->priv_data_size))) { - ret = AVERROR(ENOMEM); - goto fail; + /* allocate if not already allocated */ + if (!s->priv_data) { + if (!(s->priv_data = av_mallocz(s->iformat->priv_data_size))) { + ret = AVERROR(ENOMEM); + goto fail; + } } + /* Overwrite any options already set (1: back to defaults, 2: apply options, if any) */ if (s->iformat->priv_class) { *(const AVClass **) s->priv_data = s->iformat->priv_class; av_opt_set_defaults(s->priv_data); diff --git a/libavformat/version.h b/libavformat/version.h index 7f02e18f24..6519bba101 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -32,7 +32,7 @@ // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium) // Also please add any ticket numbers that you believe might be affected here #define LIBAVFORMAT_VERSION_MAJOR 59 -#define LIBAVFORMAT_VERSION_MINOR 3 +#define LIBAVFORMAT_VERSION_MINOR 4 #define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ From patchwork Fri Jun 11 20:31:01 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: 28234 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp767118iol; Fri, 11 Jun 2021 13:40:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhNaTcrYDEAQJ65disYZEqWgpzrdt2VWGpeyQgUIfUXXXcDH2oyzBj05w9urDhFTARmlcl X-Received: by 2002:a17:906:a281:: with SMTP id i1mr5206476ejz.307.1623444012212; Fri, 11 Jun 2021 13:40:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623444012; cv=none; d=google.com; s=arc-20160816; b=be8Q50y6QoUrM6IJ4E1wjRhKH4hswQvDjpZ96v+ljvkdtaANluRfQx9XVZ4dnbD33C l5fWA0lCCwaztcMTPqXvmQcVhNDjEyaz2FUWMESgJlvCBMHd/xEW/g3JgiF+hBf5ZIu6 d6R1Ezz0huPxIYeWZ2XLdSkmOBtI83npT5ZuwWlHo2ywwIYUI10Be6VNmbZXh5olEDm9 ngSBiNRbeX4E0M6ek/ag0PjPx+nyHzk0C3Fq5c7OKRcrSOVitrw+vLRanTPMMgmtor+u 9WPSlBjErzIYe8yMZHySAAjoJqfigEdh20cqEZB23uS2VSb5tXUzIiM6xXEi9l2a4Sb4 TsDg== 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=ZtELuqM1JV/P9TOpGQgeFKUdz3vzyzR/F2+pHeKPPO0=; b=m1zll49dZH6unYMkc8AkgIEHVRdEEigKYES4yBXeMIa8xvpqYp/bVW5nZGz518+tju 68e/bOtc5E5CgWcO0HJAPYQJ3NdZfHR3g1YLrSC4UEwD3ZvSkGXhZIGGNuRrxsF67O1m yE0gssAPkSQBL+057+OpG5Gcv2CsKqg6kbJPUaturfAd+RS+zk/BpmzVhapSN1eQ/65K +zLTCc1+0YclNCJ/QL7jQLIYWLKXeO2oP/HRe/ZqZscU1d97319wait1b0nummry5qa+ jVExd3aM1bGJEqGFYR2chdlEpjFkOvwR6vJ/j8X7cIMLSFZzgV9WXvehhP66MMJx5axe 7QnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=aQCUoICb; 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 m29si5840992ejn.735.2021.06.11.13.40.11; Fri, 11 Jun 2021 13:40:12 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=aQCUoICb; 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 6F86B689965; Fri, 11 Jun 2021 23:40:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8CABC689965 for ; Fri, 11 Jun 2021 23:40:07 +0300 (EEST) Received: by mail-lf1-f48.google.com with SMTP id m21so10351865lfg.13 for ; Fri, 11 Jun 2021 13:40:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PLRtbBXXbyB2eKYVrABu+l9I4Mlyat1Ix0fjXHhbjQQ=; b=aQCUoICb8TztxKi3c3eZ2FRF/si/sqSP7cPIHKLVmimrzgWWEtmy18+1ws19Z+y+ri LGvgCW7eLeqP3x/APBuIbsrNYTOMc7p4zjsRunIK/96z9ZQuUoByzBfBCovtIaXZgkVS 7Ldp+3xmjHzGsSgD+aKfNWtOLQY83ueVygqwHWYyiNtOXDd70z6/UpiiIWUhF/HbJYN2 WTMnlUh4UoOCv7EHlmgx+XxsZXOJlGiejjKTND+cky+R0AOAAm6OPloe5XgErvpZ5N6a vs7gN8YgGp8ktKnIgR8/QB6JeGFAwWE2YC0bmk1EIthmnqRyI4MaFdvoI8qkhdHiFxGJ Mpbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PLRtbBXXbyB2eKYVrABu+l9I4Mlyat1Ix0fjXHhbjQQ=; b=WgNL1BQbbLnYZdZ7/P2FE4WeaGRWUyxcgvEAwE2c+xTAxcg09FHR43aOeI/1pDLROu 71oWhDIzWQSI+IYN/UE8e02l8m305uePGSXi4eBuhP3j/23q1H3JAQWl3h/A9+CkYbR4 JZudtcoSmwUwjouqx1Dhgt1RHDKTB+20ciyYwwtyPxoh9kbWJCxQgVdHGA7N76D6KO// SIS6PK0E+hWv/WhqOM7TbHbDzg4AuDlgPXwngLwUI6rmHo9tNVSKGgausVRMsibvMPay dYK/fJNsalKcySOlRYtUr0CLhGvMjYYmVGXt6TEYLcMIiy+sDkuBSbYVsSc1IAW8cD16 z1mg== X-Gm-Message-State: AOAM530Nm4840Jsc/Zwcms886uNpYcg5AwLDckZVbWZGXxAG5KP4l0z8 48EXo8LkIT6PqRYB7lDCI53hJL1KXwz5Eg== X-Received: by 2002:a05:6512:24a:: with SMTP id b10mr3690637lfo.136.1623444006489; Fri, 11 Jun 2021 13:40:06 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id a13sm847342ljb.47.2021.06.11.13.40.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:40:06 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:31:01 +0200 Message-Id: <20210611203104.1692-31-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 30/33] doc/examples: adding device_get_capabilities example 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: USg0YxvXdtUP Signed-off-by: Diederick Niehorster --- configure | 2 + doc/examples/.gitignore | 1 + doc/examples/Makefile | 1 + doc/examples/Makefile.example | 1 + doc/examples/device_get_capabilities.c | 190 +++++++++++++++++++++++++ 5 files changed, 195 insertions(+) create mode 100644 doc/examples/device_get_capabilities.c diff --git a/configure b/configure index 6bfd98b384..31b1790c8d 100755 --- a/configure +++ b/configure @@ -1705,6 +1705,7 @@ EXAMPLE_LIST=" decode_audio_example decode_video_example demuxing_decoding_example + device_get_capabilities_example encode_audio_example encode_video_example extract_mvs_example @@ -3712,6 +3713,7 @@ avio_reading_deps="avformat avcodec avutil" decode_audio_example_deps="avcodec avutil" decode_video_example_deps="avcodec avutil" demuxing_decoding_example_deps="avcodec avformat avutil" +device_get_capabilities_example_deps="avdevice avformat avutil" encode_audio_example_deps="avcodec avutil" encode_video_example_deps="avcodec avutil" extract_mvs_example_deps="avcodec avformat avutil" diff --git a/doc/examples/.gitignore b/doc/examples/.gitignore index 44960e1de7..256f33a600 100644 --- a/doc/examples/.gitignore +++ b/doc/examples/.gitignore @@ -3,6 +3,7 @@ /decode_audio /decode_video /demuxing_decoding +/device_get_capabilities /encode_audio /encode_video /extract_mvs diff --git a/doc/examples/Makefile b/doc/examples/Makefile index 81bfd34d5d..de707bb3ca 100644 --- a/doc/examples/Makefile +++ b/doc/examples/Makefile @@ -3,6 +3,7 @@ EXAMPLES-$(CONFIG_AVIO_READING_EXAMPLE) += avio_reading EXAMPLES-$(CONFIG_DECODE_AUDIO_EXAMPLE) += decode_audio EXAMPLES-$(CONFIG_DECODE_VIDEO_EXAMPLE) += decode_video EXAMPLES-$(CONFIG_DEMUXING_DECODING_EXAMPLE) += demuxing_decoding +EXAMPLES-$(CONFIG_DEVICE_GET_CAPABILITIES_EXAMPLE) += device_get_capabilities EXAMPLES-$(CONFIG_ENCODE_AUDIO_EXAMPLE) += encode_audio EXAMPLES-$(CONFIG_ENCODE_VIDEO_EXAMPLE) += encode_video EXAMPLES-$(CONFIG_EXTRACT_MVS_EXAMPLE) += extract_mvs diff --git a/doc/examples/Makefile.example b/doc/examples/Makefile.example index a232d97f98..b861b9cc74 100644 --- a/doc/examples/Makefile.example +++ b/doc/examples/Makefile.example @@ -16,6 +16,7 @@ EXAMPLES= avio_list_dir \ decode_audio \ decode_video \ demuxing_decoding \ + device_get_capabilities \ encode_audio \ encode_video \ extract_mvs \ diff --git a/doc/examples/device_get_capabilities.c b/doc/examples/device_get_capabilities.c new file mode 100644 index 0000000000..46a7d1a86f --- /dev/null +++ b/doc/examples/device_get_capabilities.c @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2021 Diederick Niehorster + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/** + * @file + * avdevice getting capabilities example. + * + * Shows how to use the avdevice capabilities API to probe + * device capabilities (supported codecs, pixel formats, sample + * formats, resolutions, channel counts, etc) + * @example device_get_capabilities.c + */ + +#include +#include +#include +#include + +void print_option_ranges(enum AVOptionType type, AVOptionRanges* ranges) +{ + for (int range_index = 0; range_index < ranges->nb_ranges; range_index++) { + for (int component_index = 0; component_index < ranges->nb_components; component_index++) + { + AVOptionRange* range = ranges->range[ranges->nb_ranges * component_index + range_index]; + if (component_index > 0) + printf(", "); + printf("%s: ", range->str); + if (range->value_min > range->value_max) { + printf(""); + } else { + uint8_t* buf; + if (av_opt_print_num(type, range->value_min, &buf) < 0) + // fallback to just printing value + printf("%.2f", range->value_min); + else { + printf("%s", (const char*)buf); + av_freep(&buf); + } + if (range->is_range) { + if (av_opt_print_num(type, range->value_max, &buf) < 0) + // fallback to just printing value + printf(" -- %.2f", range->value_max); + else { + printf(" -- %s", (const char*)buf); + av_freep(&buf); + } + } + } + } + printf("\n"); + } +} + + + +int main (int argc, char **argv) +{ + int ret = 0; + const char* device_name = NULL; + const char* input_name = NULL; + const char* query_cap = NULL; + const char* set_cap_name = NULL; + const char* set_cap_value = NULL; + + const AVInputFormat* fmt = NULL; + AVFormatContext* fmt_ctx = NULL; + AVDeviceCapabilitiesQuery* caps = NULL; + AVOptionRanges* ranges = NULL; + AVDictionary* options = NULL; + const AVOption* opt = NULL; + + if (argc != 6) { + fprintf(stderr, "usage: %s device_name input_name query_cap set_cap_name set_cap_value\n" + "API example program to show how to use the avdevice\n" + "capabilities API to probe device capabilities \n" + "(supported codecs, pixel formats, sample formats,\n" + "resolutions, channel counts, etc).\n\n" + "example invocation: " + "%s dshow video=\"Integrated Webcam\" frame_size pixel_format yuyv422", + argv[0], argv[0]); + exit(1); + } + device_name = argv[1]; + input_name = argv[2]; + query_cap = argv[3]; + set_cap_name = argv[4]; + set_cap_value = argv[5]; + + // make sure avdevices can be found among input and output formats + avdevice_register_all(); + // find specified device + fmt = av_find_input_format(device_name); + if (!fmt) { + fprintf(stderr, "Could not find the device '%s'\n",device_name); + ret = AVERROR(EINVAL); + goto end; + } + + // prepare device format context, and set device to query, + ret = avformat_alloc_input_context(&fmt_ctx, fmt, NULL); + if (ret < 0) { + fprintf(stderr, "Cannot allocate input format context\n"); + goto end; + } + fmt_ctx->url = av_strdup("video=Integrated Webcam:audio=OBS-Audio"); + + // prepare query object, setting device options (if any) + ret = avdevice_capabilities_create(&caps, fmt_ctx, &options); + if (ret < 0) { + fprintf(stderr, "avdevice_capabilities_create() failed\n"); + goto end; + } + + // check capability to query, and get info about the return type + opt = av_opt_find(caps, query_cap, NULL, 0, 0); + if (!opt) { + fprintf(stderr, "Capability '%s' you wish to query is not available\n", query_cap); + ret = AVERROR_OPTION_NOT_FOUND; + goto end; + } + + // query the capability without any filter set + ret = av_opt_query_ranges(&ranges, caps, opt->name, AV_OPT_MULTI_COMPONENT_RANGE); + if (ret < 0) { + fprintf(stderr, "av_opt_query_ranges() failed\n"); + goto end; + } + + // print results + print_option_ranges(opt->type, ranges); + av_opt_freep_ranges(&ranges); + + printf("=============\n"); + + // set one capability, which may filter out some returned capabilities + // (or all, if set to an invalid value) + ret = av_opt_set(caps, set_cap_name, set_cap_value, 0); + if (ret < 0) { + fprintf(stderr, "av_opt_set() failed\n"); + goto end; + } + + // query again + ret = av_opt_query_ranges(&ranges, caps, opt->name, AV_OPT_MULTI_COMPONENT_RANGE); + if (ret < 0) { + fprintf(stderr, "av_opt_query_ranges() failed\n"); + goto end; + } + + // print results + print_option_ranges(opt->type, ranges); + + +end: + if (ranges) + av_opt_freep_ranges(&ranges); + if (caps) + avdevice_capabilities_free(&caps, fmt_ctx); + + if (fmt_ctx) + avformat_free_context(fmt_ctx); + + if (ret < 0) { + char a[AV_ERROR_MAX_STRING_SIZE] = { 0 }; + av_make_error_string(a, AV_ERROR_MAX_STRING_SIZE, ret); + + printf("Error: %s\n", a); + } + + return ret < 0; +} From patchwork Fri Jun 11 20:31:02 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: 28230 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp767295iol; Fri, 11 Jun 2021 13:40:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGf968idJKYNDKBlP9NxMgHhTA51PvEcFxMH8pAV4iVr+rORVUao+mZM3quvbVCJjscDV3 X-Received: by 2002:a05:6402:34c6:: with SMTP id w6mr5577367edc.174.1623444033977; Fri, 11 Jun 2021 13:40:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623444033; cv=none; d=google.com; s=arc-20160816; b=h34zNkQyHuuhZwUBz4WVPBSlAEHmWicBYcR4h+/21gODu/jJ4G9drUX1sop2ArWMhJ NcZXYT6Sd6ZORHuMMnnQnkaa2WHMaDQSW98O3YjG3hMTPRmUe40NwTugMTXdoJj0redr p46B+F+QmfxnRg+glRbX920LtEhC31MIg7ptMBWoSUxYVixK1ZFvV+jEmC6eZ6bJslxd /u/0PgEI79QzBKgCwtPr1HC5ZGDeqqSIaKwCK3zKdhbP+22RslMXL7k2eHGbwYjTGH35 m6Xchj2g2Ar//BaB9XwKCqSMg2CEhScywO9divVfqdHCcidtJGmkxMEcWzaUDHjo4vvT IWOA== 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=IrDst6eY/FmevbXjerxXr42ZZQbWVKkW3PHdSFdvq54=; b=HLjR82dM6NfaLKgE/Lr+XcIsey5DNnFRgkOuLpQRTzIeW0TZUFCV/fGOBpFCOYxI4c qTu0/G2PErsXsyTcmXhWJqw7yn7YDxsHHQMhyXlz9oyvqz458dwpdL98URssI4gIdvvI 9MZKXfVznBPbjWqyLIOrCjWxAfVKHAbJiTc2y7g6tfU++gPeUYaTU7Ud4LhY2KZv5TSW oGK0W9QwyKAn4VJtDQfSyJbuml3zHcio1ha+eFYmZbHLgNBkqwRVy/mP9o5DgYwKU/9W WY1o0hpKqqKB2Y3Es1/INw6rgmj4ny6SeWfzp1uelepAhTrVMtzBODlJ2+YaZ1RVUOGT qWHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=p73KXVpf; 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 ka6si6013633ejc.204.2021.06.11.13.40.33; Fri, 11 Jun 2021 13:40:33 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=p73KXVpf; 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 70788689B37; Fri, 11 Jun 2021 23:40:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 38E17680267 for ; Fri, 11 Jun 2021 23:40:24 +0300 (EEST) Received: by mail-lj1-f171.google.com with SMTP id a19so8140297ljq.12 for ; Fri, 11 Jun 2021 13:40:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qRgAhwEaIAPRZtmx9B1/sp/bKAQK+XSNSi8QFTYYZ28=; b=p73KXVpfILzZQwE+YRhds6JuaYe8ohbBv6IO+UIUhFbmcJWdwYTGtTT4Wgpf9BAWXo am6tVK9qAxOAbf2TcuyAr/oz/3ExEz2YXVUA6HC19fZXjsXqfWWPaC8o2Pv3ulAOAtt8 +7tAVor7bLVk5i6VAMBU2IJNElaf1z3JDn7jNi58Hk8vcLERJybYogTL5oF0voa1diJc kR4irpaLdwkXdv3nCkBKJlmQSrroMpsfgGGyiAC3nx97+DWCJdvdq2NnX5TPvAxoQ4FC s4Q9itmUzD/r4BK1N9fZs5xINnXJCc8L1U4CWhnBJsi8mPy1lrmSjF8lVTvCt7ph4FZK aRgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qRgAhwEaIAPRZtmx9B1/sp/bKAQK+XSNSi8QFTYYZ28=; b=jFVR29+yqQY3sVKp4Ta6zszpO2W3KVkf/cobCwvDinPftp+xU0OJg+yQtvePcNGF8L pfiMJZsG2SKt+9L9jMak1zmdfHcQ5Z8NIH2an/LH+ZToZhDPE960S+qC61tb9QAxUH/b hlT26y87PGDv9lyKbER9/p2XJgoRP6+KjFvWRjSmRVU3PJzDcRr0TgjpoEa2Di05g3oC s0u41rWpyDnXK3g2/dlFOUEw3PkpxsRtEKggFujd6C+ixdPY8/jH4GjJeB8UejzJKZAV rSUfM7WVsexD9qCiVCZpuU+HD2ebxiFG0PQq8AoPKvCeplqVBCrNZ1EGq9SJWUvUTBmx gpLQ== X-Gm-Message-State: AOAM53189UcqGP+8hDZgodpn4rDdmPlDPqfXIgdOgK18bGk+biifTp2z ggjKxrM4eSIiKBevMZFCJ0DJI5EXHrWzKQ== X-Received: by 2002:a05:651c:1318:: with SMTP id u24mr4561482lja.91.1623444023362; Fri, 11 Jun 2021 13:40:23 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id r18sm918358lji.36.2021.06.11.13.40.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:40:22 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:31:02 +0200 Message-Id: <20210611203104.1692-32-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 31/33] Makefile/examples: cosmetics 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: d29c+TJaCjZP Signed-off-by: Diederick Niehorster --- doc/examples/Makefile | 48 +++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/doc/examples/Makefile b/doc/examples/Makefile index de707bb3ca..7988ed4226 100644 --- a/doc/examples/Makefile +++ b/doc/examples/Makefile @@ -1,27 +1,27 @@ -EXAMPLES-$(CONFIG_AVIO_LIST_DIR_EXAMPLE) += avio_list_dir -EXAMPLES-$(CONFIG_AVIO_READING_EXAMPLE) += avio_reading -EXAMPLES-$(CONFIG_DECODE_AUDIO_EXAMPLE) += decode_audio -EXAMPLES-$(CONFIG_DECODE_VIDEO_EXAMPLE) += decode_video -EXAMPLES-$(CONFIG_DEMUXING_DECODING_EXAMPLE) += demuxing_decoding -EXAMPLES-$(CONFIG_DEVICE_GET_CAPABILITIES_EXAMPLE) += device_get_capabilities -EXAMPLES-$(CONFIG_ENCODE_AUDIO_EXAMPLE) += encode_audio -EXAMPLES-$(CONFIG_ENCODE_VIDEO_EXAMPLE) += encode_video -EXAMPLES-$(CONFIG_EXTRACT_MVS_EXAMPLE) += extract_mvs -EXAMPLES-$(CONFIG_FILTER_AUDIO_EXAMPLE) += filter_audio -EXAMPLES-$(CONFIG_FILTERING_AUDIO_EXAMPLE) += filtering_audio -EXAMPLES-$(CONFIG_FILTERING_VIDEO_EXAMPLE) += filtering_video -EXAMPLES-$(CONFIG_HTTP_MULTICLIENT_EXAMPLE) += http_multiclient -EXAMPLES-$(CONFIG_HW_DECODE_EXAMPLE) += hw_decode -EXAMPLES-$(CONFIG_METADATA_EXAMPLE) += metadata -EXAMPLES-$(CONFIG_MUXING_EXAMPLE) += muxing -EXAMPLES-$(CONFIG_QSVDEC_EXAMPLE) += qsvdec -EXAMPLES-$(CONFIG_REMUXING_EXAMPLE) += remuxing -EXAMPLES-$(CONFIG_RESAMPLING_AUDIO_EXAMPLE) += resampling_audio -EXAMPLES-$(CONFIG_SCALING_VIDEO_EXAMPLE) += scaling_video -EXAMPLES-$(CONFIG_TRANSCODE_AAC_EXAMPLE) += transcode_aac -EXAMPLES-$(CONFIG_TRANSCODING_EXAMPLE) += transcoding -EXAMPLES-$(CONFIG_VAAPI_ENCODE_EXAMPLE) += vaapi_encode -EXAMPLES-$(CONFIG_VAAPI_TRANSCODE_EXAMPLE) += vaapi_transcode +EXAMPLES-$(CONFIG_AVIO_LIST_DIR_EXAMPLE) += avio_list_dir +EXAMPLES-$(CONFIG_AVIO_READING_EXAMPLE) += avio_reading +EXAMPLES-$(CONFIG_DECODE_AUDIO_EXAMPLE) += decode_audio +EXAMPLES-$(CONFIG_DECODE_VIDEO_EXAMPLE) += decode_video +EXAMPLES-$(CONFIG_DEMUXING_DECODING_EXAMPLE) += demuxing_decoding +EXAMPLES-$(CONFIG_DEVICE_GET_CAPABILITIES_EXAMPLE) += device_get_capabilities +EXAMPLES-$(CONFIG_ENCODE_AUDIO_EXAMPLE) += encode_audio +EXAMPLES-$(CONFIG_ENCODE_VIDEO_EXAMPLE) += encode_video +EXAMPLES-$(CONFIG_EXTRACT_MVS_EXAMPLE) += extract_mvs +EXAMPLES-$(CONFIG_FILTER_AUDIO_EXAMPLE) += filter_audio +EXAMPLES-$(CONFIG_FILTERING_AUDIO_EXAMPLE) += filtering_audio +EXAMPLES-$(CONFIG_FILTERING_VIDEO_EXAMPLE) += filtering_video +EXAMPLES-$(CONFIG_HTTP_MULTICLIENT_EXAMPLE) += http_multiclient +EXAMPLES-$(CONFIG_HW_DECODE_EXAMPLE) += hw_decode +EXAMPLES-$(CONFIG_METADATA_EXAMPLE) += metadata +EXAMPLES-$(CONFIG_MUXING_EXAMPLE) += muxing +EXAMPLES-$(CONFIG_QSVDEC_EXAMPLE) += qsvdec +EXAMPLES-$(CONFIG_REMUXING_EXAMPLE) += remuxing +EXAMPLES-$(CONFIG_RESAMPLING_AUDIO_EXAMPLE) += resampling_audio +EXAMPLES-$(CONFIG_SCALING_VIDEO_EXAMPLE) += scaling_video +EXAMPLES-$(CONFIG_TRANSCODE_AAC_EXAMPLE) += transcode_aac +EXAMPLES-$(CONFIG_TRANSCODING_EXAMPLE) += transcoding +EXAMPLES-$(CONFIG_VAAPI_ENCODE_EXAMPLE) += vaapi_encode +EXAMPLES-$(CONFIG_VAAPI_TRANSCODE_EXAMPLE) += vaapi_transcode EXAMPLES := $(EXAMPLES-yes:%=doc/examples/%$(PROGSSUF)$(EXESUF)) EXAMPLES_G := $(EXAMPLES-yes:%=doc/examples/%$(PROGSSUF)_g$(EXESUF)) From patchwork Fri Jun 11 20:31:03 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: 28233 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp767461iol; Fri, 11 Jun 2021 13:40:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDT4MvEojADLdnBQLjhm9YStRWMoWl2w6dnlUlhc52FBu/efyBDnyro6f+pmNKzvZASB20 X-Received: by 2002:a17:906:26ce:: with SMTP id u14mr5180439ejc.187.1623444053970; Fri, 11 Jun 2021 13:40:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623444053; cv=none; d=google.com; s=arc-20160816; b=bJBdpJkY+uAGGYkP1xmjAW1M8CeTn5b/yQPTOTksB1YRDupW98aIvlomqkFehyAaIj C6gnUGKJlgDIeyNGbyj0sMZfpiflmL4qDXInj9OT3XmeCgNhp8no/1wwom2qPGIHCQOp 5k52hmBy5Iaa+C6a7aFj20OFqGJQP0gmWzldMoZ/TMZjTFewrZucoTFsSNwrJYu2H9qc i6a06jU7MoUVsA66y4dUH0zoMLmOMqugcoesVCfzsrnPxtKmAsHKDzPrMF+TduYzMWCN BgXRIXE2BvrGthUJMVdQ9hr/t+3rWep24kJUGI0hCDMEsWOrtIEDb6jI3O+/skMvZARe jjaw== 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=3a1pVSTSNj3anxIlcIJPQkwNBvhenGn6cUvC7shf9Yk=; b=GxWuSAeZD3tb/R7rakh1HjlatdZU6WPgKTa4QyjWPHoMUXSWx4FRnbdQzdoqKXRMCD Rh9j3sKK/7c2vLEEqbpDyG2EtsYtBX+YdKwVXczsQkVvrg3uUKjnoLDt/Qr4L0SThwJ7 +mGmNGssJPZYjXmUdnVHIOOKlO+ly0SwX0aWDmrcQFyo5isjKp83NvGwaotXfFwiwPeH l1IZWCqr1ub2UL16ET0aFiNANYHu2kJuDTTny1dnlMyoR9/uIVxIVUPZ9hjCFUS4LneN KQ/RN7GgBafootPawSX00/5La5G5j2wG7hEdK4EIJO7h4PpruebyWt3LTLSmQx8I88TS t3hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=V18FNSIe; 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 f10si5603787ejt.614.2021.06.11.13.40.53; Fri, 11 Jun 2021 13:40:53 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=V18FNSIe; 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 B1967689C2B; Fri, 11 Jun 2021 23:40:43 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 42E2A689B33 for ; Fri, 11 Jun 2021 23:40:41 +0300 (EEST) Received: by mail-lf1-f44.google.com with SMTP id p17so10383105lfc.6 for ; Fri, 11 Jun 2021 13:40:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TcbjFB1/FSqcF2QcLiWCLVDIfPj88HwUoK0ieNEXDuk=; b=V18FNSIe1tZC+wLlHFioY47HguinjKNHjFHy4DQYq0egTO51iTQIw5xhWu7nZnaw2k 3OxJoXfs8YbK0FNLFE1SxBvp3iuEa//qc66e8tWI86sqvO9rD8hSXKpkyc1kX6NjpcEb W9LHMtRlEZxQqWL3R2SI9ISNauP24xpqdToYzftY4rpBm7PN0m9CF2yxcYRufVjbAbi2 Ti+DNrzNpCSj/BccFcq5JJOApbjKilHHIyIAsMc8Dh8ECZI9klzAYjAFR3z3yorqzVls NreZPw0eHTyAJddMHZ/ra/qpHo6fw+z2QVv+3UJeBeL59IICn66VcRy9EOJs4XrDpd9E OgAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TcbjFB1/FSqcF2QcLiWCLVDIfPj88HwUoK0ieNEXDuk=; b=qYxmiAPU5CrJUtOdMzfq206P83p+Kng0CLLmN1ZGNtERiqFjmUGPniB7gIM/yI7S80 sjPBO33px4eQC4MwDJAR/LNy0ge0rT8OPLvhlB2oqhpr/wTQ3WLxhJv2vM2udWc35Ijk A/Rj8upgSXAUIbTyUlRXaNUBiEQTDVii5i5WBqs6jCDCPENT0w7XdAwKu9MOZ/x7JLxe +k544NedYbJAG8zq8sQBDLUBa8w1fDWVsk27486xqFlTNYcxnQGwum6resakHKO0kznl 6mk5Sw2Ndo3ZCzVYldwRA1JcWwYvZ+P/KFfhPwrfsNcmRi1UyB6rtf7kzZa8Dki5txV4 2a7A== X-Gm-Message-State: AOAM533JvQhHsakmeBEChPp/XdmT+gfIc2CVxsAcxuIW77zbNTMNTx38 3k/S1tJvEE9Fj6lNjdxmCT6gTjPyJmnjNA== X-Received: by 2002:a05:6512:3d8f:: with SMTP id k15mr3893652lfv.362.1623444040372; Fri, 11 Jun 2021 13:40:40 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id q184sm906143ljb.54.2021.06.11.13.40.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:40:39 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:31:03 +0200 Message-Id: <20210611203104.1692-33-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 32/33] 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: 7G69SPQEc8K1 list_options true would crash when both a video and an audio device were specified as input. Crash would occur on line 1618 (in this new rev) because ctx->device_unique_name[otherDevType] would be NULL Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 92cfaa062d..d3937df41a 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -1516,9 +1516,9 @@ dshow_list_device_options(AVFormatContext *avctx, ICreateDevEnum *devenum, if ((r = dshow_cycle_devices(avctx, devenum, devtype, sourcetype, &device_filter, &device_unique_name, NULL)) < 0) return r; ctx->device_filter[devtype] = device_filter; + ctx->device_unique_name[devtype] = device_unique_name; if ((r = dshow_cycle_pins(avctx, devtype, sourcetype, device_filter, ranges ? &device_pin : NULL, ranges, query_type)) < 0) return r; - av_freep(&device_unique_name); return 0; } @@ -1578,7 +1578,8 @@ dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum, goto error; } } - if (ctx->device_filter[otherDevType]) { + + if (ctx->device_filter[otherDevType]) { // avoid adding add two instances of the same device to the graph, one for video, one for audio // a few devices don't support this (could also do this check earlier to avoid double crossbars, etc. but they seem OK) if (strcmp(device_filter_unique_name, ctx->device_unique_name[otherDevType]) == 0) { @@ -2040,6 +2041,7 @@ static int dshow_read_header(AVFormatContext *avctx) } } } + // don't exit yet, allow it to list crossbar options in dshow_open_device } ctx->is_running = 0; if (ctx->device_name[VideoDevice]) { From patchwork Fri Jun 11 20:31:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 28232 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp767564iol; Fri, 11 Jun 2021 13:41:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxfIqFxndi8DIMRRtsu7nb7DFMhlxUxxfnTnQN2TW7ZqzovkX/FX03w7shEdcUVlXk18nl X-Received: by 2002:a17:906:d0c9:: with SMTP id bq9mr5161686ejb.313.1623444064839; Fri, 11 Jun 2021 13:41:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623444064; cv=none; d=google.com; s=arc-20160816; b=XwagRn3mxdtxvJdUgWn37/wqijAlE7nUhgK0AeKBKB6gpdEhuBgUG9hl6b/6e7SK87 pyLHaM2XKU4C1mKe+2NQd0whJYEk9JXYwMW6J4JZ6emO8eSHYKQ5dGbjJVALuidmjVpb QGLxm0yqTB/P65SrsObTu33a+Xxw30+bcnP2Rek8l/o92XDNJygud/CjQf3fUfSaHBCt xHEosXp7lQYsIFYDaJIFW3bKNOjmSxfVkyLMgnrIHcouDb2FIalBOT4ueMBfccyHcImb Q2LhU03OHBS/RV0ia4NjSEqQOkz9jQoIfKx2RU6tvpHKk+hXL8yjwsPiXA31OkWl8bfH uNag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=e/47X675pQoa84E5wTliarzUsXZmDc6HwrBOBdhBxOw=; b=PaTvKO2M2yOMKOeXQxabXnhkFcQxj13jf6c/2bLKP5wunItywK2f4jTqfVrnQpoGxh E3/In98nogtHJvJ1MTdCkBOralw8i1bTQdhg21IDSL4yS+gyzfQg0hKkD9e4u8GkxgXd 4GArLPDXFfmq3Yuss7zSSwJnA9r+r2ym1N9AXhFg8KuZbPfARONCLebHgcCugy4ljtrx jJ/MyhWvc/9rM0CLyEvHQxCyKcuBQyjMEQivBYpdhsPYYW2oDy4yzUKVYafQ5rgJJLLJ tWJzkYpDRfef78l8lHuroQUf1VcfEZwj0PuRRHj6b+DenzaCTZqDCkLQ1hhRBX4IT/sx 56AQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b="cV/whrbO"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id i16si5672938ejo.417.2021.06.11.13.41.04; Fri, 11 Jun 2021 13:41:04 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b="cV/whrbO"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D0E55689B7F; Fri, 11 Jun 2021 23:40:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3B6136891F1 for ; Fri, 11 Jun 2021 23:40:57 +0300 (EEST) Received: by mail-lf1-f45.google.com with SMTP id p7so10401746lfg.4 for ; Fri, 11 Jun 2021 13:40:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=44o2W9uZemXMa+mDxhh0Dbo3YYfEl238oBpq5Oxh56M=; b=cV/whrbOVFxNGF5MTCArc1xIbtUKVZlfmj8XCwoeMn7qQEMz0WTJri9sCxjglAh9AN 1TVJH5PaPAni+Yv6YuuuRCYibSbBaMv+8tsMNIQGO1rUOS+6VPTvJzRXQxhwn6C2Ns5M SFuRRjgGmegXwm3qppQKDkJ5XLL/3A39WADKOfy2W6lA+KTdvKndeeIEoqD78N6aWys+ 14clYnOG1RbYm4HlegYY1ObStB0NBB4RQddEygnewJRMzCH727T02tGlSFZj+bFfAZxy RWzw3aaESHPJTKv//kMUyKwrQpQkEZj+ipZm9eRfvFI/neCUZM4mZ4fDh+beuCgOj6VK DB4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=44o2W9uZemXMa+mDxhh0Dbo3YYfEl238oBpq5Oxh56M=; b=UXqBO89mKiMnQXqDRhMlMfDbRGCpPBX+9XF10YSVsQNy/QubbrqIqSRakBrZAnwwcn nLHNqXesvMa0NqBNhVLwm3ctqHqNUxNjxtjKaYMiSgnN/nf4G+im/N16dQ4cheC8FPyq dtRCLqRlEQKPS5nVq7YRawdY0ZvMvgN/ZQV9vGdbQL5z8oLIKBjO41JN4FaSb7O2DU0P vE4hZVydCLm1cejr5iEyRFgC+HwjQaMjS1PRNoIqW9xHYBJE0/bNAs1kQNynZ5wGhP/g T/XxHcX5OFQYHK9EyzyqtMiXhuObwg7wcWJH+AMKC0Yo3SytNkcukSsAUey4ucZsRXwj S6kQ== X-Gm-Message-State: AOAM530PK/+CDb+LWkUtneiCXplBld2nLvHIEsPDj8ysmejNJETQ23T1 7bVSiJBn+jibeVjuPbZNNucrTubfxlaz2A== X-Received: by 2002:a05:6512:3a85:: with SMTP id q5mr3673243lfu.404.1623444057165; Fri, 11 Jun 2021 13:40:57 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id u8sm846782lja.77.2021.06.11.13.40.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:40:56 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:31:04 +0200 Message-Id: <20210611203104.1692-34-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 33/33] avdevice/dshow: capabilities query also works on opened device X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Diederick Niehorster Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Kbtq+Qb9wxIy While the capabilities API is in principle meant to be used with an allocated format context belonging to an unopened device, small changes make it work for an opened dshow device as well. So hereby done. Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index d3937df41a..11fa71db13 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -853,7 +853,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, void *caps = NULL; int i, n, size, r; int wait_for_better = 0; - int use_default; + int use_default, already_opened; // format parameters requested by user // if none are requested by user, the values will below be set to @@ -879,6 +879,9 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, if (!caps) goto end; + // get if device is already opened + already_opened = ctx->device_name[0] || ctx->device_name[1]; + /** * If we should open the device with the default format, * then: @@ -1187,7 +1190,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, // in ranges, try to apply in all cases, and store // caps if successfully applied if (!wait_for_better || ranges) { - if (IAMStreamConfig_SetFormat(config, type) != S_OK) + if (!already_opened && IAMStreamConfig_SetFormat(config, type) != S_OK) // skip if device already opened goto next; else if (ranges) { // format matched and could be set successfully. @@ -1513,12 +1516,19 @@ dshow_list_device_options(AVFormatContext *avctx, ICreateDevEnum *devenum, char *device_unique_name = NULL; int r; - if ((r = dshow_cycle_devices(avctx, devenum, devtype, sourcetype, &device_filter, &device_unique_name, NULL)) < 0) - return r; - ctx->device_filter[devtype] = device_filter; - ctx->device_unique_name[devtype] = device_unique_name; + if (!ctx->device_filter[devtype]) { + if ((r = dshow_cycle_devices(avctx, devenum, devtype, sourcetype, &device_filter, &device_unique_name, NULL)) < 0) + return r; + } else + device_filter = ctx->device_filter[devtype]; if ((r = dshow_cycle_pins(avctx, devtype, sourcetype, device_filter, ranges ? &device_pin : NULL, ranges, query_type)) < 0) return r; + + if (!ctx->device_filter[devtype]) { + // put them in context so they'll be cleaned up again + ctx->device_filter[devtype] = device_filter; + ctx->device_unique_name[devtype] = device_unique_name; + } return 0; } @@ -2188,6 +2198,7 @@ static int dshow_query_ranges(AVOptionRanges** ranges_arg, void* obj, const char AVDeviceCapabilitiesQuery *caps = obj; const AVFormatContext *avctx = caps->device_context; struct dshow_ctx *ctx = avctx->priv_data; + int already_opened; int backup_sample_size; int backup_sample_rate; @@ -2227,13 +2238,11 @@ static int dshow_query_ranges(AVOptionRanges** ranges_arg, void* obj, const char goto fail1; } - if (ctx->device_name[0]) { - av_log(avctx, AV_LOG_ERROR, "You cannot query device capabilities on an opened device\n"); - ret = AVERROR(EIO); - goto fail1; - } + already_opened = ctx->device_name[0] || ctx->device_name[1]; + if (already_opened) + av_log(avctx, AV_LOG_WARNING, "Querying device capabilities on an opened device: may yield false positives\n"); - if (!parse_device_name(avctx)) { + if (!already_opened && !parse_device_name(avctx)) { av_log(avctx, AV_LOG_ERROR, "You must set a device name (AVFormatContext url) to specify which device to query capabilities from\n"); ret = AVERROR(EINVAL); goto fail1; @@ -2349,7 +2358,8 @@ fail2: // clear state variables that may have been set during the above process // (e.g. frees device names, removes device_filters, etc) - dshow_read_close(avctx); + if (!already_opened) + dshow_read_close(avctx); fail1: if (ret < 0)