我正在尝试编写一个简单的帮助应用程序,用于在未检测到信号时提示用户打开摄像机,在这种情况下,这意味着摄像机已关闭和/或 HDMI 电缆未插入 PCMCIA采集卡。如果存在信号,则启动相应的录音应用程序,在本例中为 Wirecast。
我怎么可能在 VisualStudio 中使用 C# 创建它?
更新
我想我现在通过尝试基于建议使用 GraphEdit 的评论之一的建议并查看硬件上可用的内容,离我更近了。我能够在捕获设备的属性中找到一个“检测到信号”标志,如果摄像机打开/关闭或拔下 HDMI 电缆,它会从 0 变为 1,这正是我想要的。
现在,我将如何通过代码访问此标志?cElems
我想我真的很接近,但不知道如何pElems
从caGUID
. cElems
返回值 3,这与下面屏幕截图中显示的 GraphEdit 属性窗口中显示的选项卡数量相同。pElems
每次运行应用程序时都会返回不同的值,所以我不确定该结构中发生了什么。我认为我正在寻找的旗帜位于这些结构中的某个地方。
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DirectShowLib;
namespace Test
{
static class Program
{
[STAThread]
static void Main()
{
using (System.Threading.Mutex mutex = new System.Threading.Mutex(false, "Global\\" + appGuid))
{
if (!mutex.WaitOne(0, false))
{
return;
}
DsDevice[] capDevices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
foreach (var dev in capDevices)
{
if (dev.DevicePath == @"@device:pnp:\\?\pci#ven_1131&dev_7160&subsys_12abf50a&rev_03#6&37bccbbe&0&000800e1#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\{6f814be9-9af6-43cf-9249-c0340100021c}")
{
IFilterGraph2 m_FilterGraph = (IFilterGraph2)new FilterGraph();
IBaseFilter capFilter = null;
ICaptureGraphBuilder2 capGraph = null;
capGraph = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
int hr;
hr = capGraph.SetFiltergraph(m_FilterGraph);
hr = m_FilterGraph.AddSourceFilterForMoniker(dev.Mon, null, dev.Name, out capFilter);
ISpecifyPropertyPages pProp = capFilter as ISpecifyPropertyPages;
FilterInfo filterInfo;
hr = capFilter.QueryFilterInfo(out filterInfo);
DsCAUUID caGUID;
hr = pProp.GetPages(out caGUID);
Console.WriteLine(caGUID.cElems);
Console.WriteLine(caGUID.pElems);
// caGUID.cElems returns '3', which is the correct number of tabs in the property pages shown in GraphEdit.
// caGUID.pElems returns a different value every time
break;
}
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
private static string appGuid = "z0a76b5a-02cd-15c5-b9d9-d303zcdde7b9";
}
}