本文整理汇总了C#中IGraphBuilder.ConnectDirect方法的典型用法代码示例。如果您正苦于以下问题:C# IGraphBuilder.ConnectDirect方法的具体用法?C# IGraphBuilder.ConnectDirect怎么用?C# IGraphBuilder.ConnectDirect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IGraphBuilder
的用法示例。
在下文中一共展示了IGraphBuilder.ConnectDirect方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConnectFilters
public static void ConnectFilters(IGraphBuilder graphBuilder, IPin sourcePin, IPin destinationPin,
bool useIntelligentConnect)
{
int hr = 0;
if (graphBuilder == null)
throw new ArgumentNullException("graphBuilder");
if (sourcePin == null)
throw new ArgumentNullException("sourcePin");
if (destinationPin == null)
throw new ArgumentNullException("destinationPin");
if (useIntelligentConnect)
{
hr = graphBuilder.Connect(sourcePin, destinationPin);
DsError.ThrowExceptionForHR(hr);
}
else
{
hr = graphBuilder.ConnectDirect(sourcePin, destinationPin, null);
DsError.ThrowExceptionForHR(hr);
}
}
示例2: BuildGraph
private void BuildGraph(DirectShowLib.DsDevice dsDevice)
{
int hr = 0;
pGraph = new FilterGraph() as IFilterGraph2;
//graph builder
ICaptureGraphBuilder2 pBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
try
{
hr = pBuilder.SetFiltergraph(pGraph);
DsError.ThrowExceptionForHR(hr);
// Add camera
IBaseFilter camera;
//hr = pGraph.FindFilterByName(dsDevice.Name, out camera);
hr = ((IFilterGraph2)pGraph).AddSourceFilterForMoniker(dsDevice.Mon, null, dsDevice.Name, out camera);
DsError.ThrowExceptionForHR(hr);
hr = pGraph.AddFilter(camera, "camera");
DsError.ThrowExceptionForHR(hr);
// Set format for camera
AMMediaType pmt = new AMMediaType();
pmt.majorType = MediaType.Video;
pmt.subType = MediaSubType.YUY2;
pmt.formatType = FormatType.VideoInfo;
pmt.fixedSizeSamples = true;
pmt.formatSize = 88;
pmt.sampleSize = 829440;
pmt.temporalCompression = false;
VideoInfoHeader format = new VideoInfoHeader();
format.SrcRect = new DsRect();
format.TargetRect = new DsRect();
format.BitRate = 20736000;
format.AvgTimePerFrame = 400000;
format.BmiHeader = new BitmapInfoHeader();
format.BmiHeader.Size = 40;
format.BmiHeader.Width = 720;
format.BmiHeader.Height = 576;
format.BmiHeader.Planes = 1;
format.BmiHeader.BitCount = 24;
format.BmiHeader.Compression = 844715353;
format.BmiHeader.ImageSize = 827440;
pmt.formatPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(format));
Marshal.StructureToPtr(format, pmt.formatPtr, false);
hr = ((IAMStreamConfig)DsFindPin.ByCategory(camera, PinCategory.Capture, 0)).SetFormat(pmt);
//hr = ((IAMStreamConfig)GetPin(pUSB20Camera, "Capture")).SetFormat(pmt);
DsUtils.FreeAMMediaType(pmt);
DsError.ThrowExceptionForHR(hr);
IAMCrossbar crossBar = null;
object dummy;
hr = pBuilder.FindInterface(PinCategory.Capture, MediaType.Video, camera, typeof(IAMCrossbar).GUID, out dummy);
if( hr >=0)
{
crossBar = (IAMCrossbar)dummy;
int oPin, iPin;
int ovLink, ivLink;
ovLink = ivLink = 0;
crossBar.get_PinCounts(out oPin, out iPin);
int pIdxRel;
PhysicalConnectorType physicalConType;
for (int i = 0; i < iPin; i++)
{
crossBar.get_CrossbarPinInfo(true, i, out pIdxRel, out physicalConType);
if (physicalConType == PhysicalConnectorType.Video_Composite)
ivLink = i;
}
for (int i = 0; i < oPin; i++)
{
crossBar.get_CrossbarPinInfo(false, i, out pIdxRel, out physicalConType);
if (physicalConType == PhysicalConnectorType.Video_VideoDecoder)
ovLink = i;
}
try
{
crossBar.Route(ovLink, ivLink);
}
catch
{
throw new Exception("Failed to get IAMCrossbar");
}
}
//add AVI Decompressor
IBaseFilter pAVIDecompressor = (IBaseFilter)new AVIDec();
hr = pGraph.AddFilter(pAVIDecompressor, "AVI Decompressor");
//add color space converter
IBaseFilter pColorSpaceConverter = (IBaseFilter)new Colour();
hr = pGraph.AddFilter(pColorSpaceConverter, "Color space converter");
DsError.ThrowExceptionForHR(hr);
// Connect camera and AVI Decomp
hr = pGraph.ConnectDirect(DsFindPin.ByCategory(camera, PinCategory.Capture, 0), DsFindPin.ByName(pAVIDecompressor, "XForm In"), null);
DsError.ThrowExceptionForHR(hr);
//.........这里部分代码省略.........
示例3: TryConnect
public static bool TryConnect(IGraphBuilder graphbuilder, IBaseFilter source, Guid mediaType,
IBaseFilter targetFilter)
{
bool connected = false;
IEnumPins enumPins;
int hr = source.EnumPins(out enumPins);
DsError.ThrowExceptionForHR(hr);
IPin[] pins = new IPin[1];
int fetched = 0;
while (enumPins.Next(1, pins, out fetched) == 0)
{
if (fetched != 1)
{
break;
}
PinDirection direction;
pins[0].QueryDirection(out direction);
if (direction == PinDirection.Output)
{
IEnumMediaTypes enumMediaTypes;
pins[0].EnumMediaTypes(out enumMediaTypes);
AMMediaType[] mediaTypes = new AMMediaType[20];
int fetchedTypes;
enumMediaTypes.Next(20, mediaTypes, out fetchedTypes);
for (int i = 0; i < fetchedTypes; ++i)
{
if (mediaTypes[i].majorType == mediaType)
{
if (
graphbuilder.ConnectDirect(pins[0], DsFindPin.ByDirection(targetFilter, PinDirection.Input, 0), null) >=
0)
{
connected = true;
break;
}
}
}
}
ReleaseComObject(pins[0]);
}
ReleaseComObject(enumPins);
return connected;
}
示例4: BuildGraph
private void BuildGraph(DirectShowLib.DsDevice dsDevice)
{
int hr = 0;
pGraph = new FilterGraph() as IFilterGraph2;
//graph builder
ICaptureGraphBuilder2 pBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
try
{
hr = pBuilder.SetFiltergraph(pGraph);
DsError.ThrowExceptionForHR(hr);
// Add camera
IBaseFilter camera;
//hr = pGraph.FindFilterByName(dsDevice.Name, out camera);
hr = ((IFilterGraph2)pGraph).AddSourceFilterForMoniker(dsDevice.Mon, null, dsDevice.Name, out camera);
DsError.ThrowExceptionForHR(hr);
hr = pGraph.AddFilter(camera, "camera");
DsError.ThrowExceptionForHR(hr);
// Set format for camera
AMMediaType pmt = new AMMediaType();
pmt.majorType = MediaType.Video;
pmt.subType = MediaSubType.MJPG;
pmt.formatType = FormatType.VideoInfo;
pmt.fixedSizeSamples = true;
pmt.formatSize = 88;
pmt.sampleSize = 2764800;
pmt.temporalCompression = false;
VideoInfoHeader format = new VideoInfoHeader();
format.SrcRect = new DsRect();
format.TargetRect = new DsRect();
format.BitRate = 663552000;
format.AvgTimePerFrame = 333333;
format.BmiHeader = new BitmapInfoHeader();
format.BmiHeader.Size = 40;
format.BmiHeader.Width = 1280;
format.BmiHeader.Height = 720;
format.BmiHeader.Planes = 1;
format.BmiHeader.BitCount = 24;
format.BmiHeader.Compression = 1196444237;
format.BmiHeader.ImageSize = 2764800;
pmt.formatPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(format));
Marshal.StructureToPtr(format, pmt.formatPtr, false);
hr = ((IAMStreamConfig)DsFindPin.ByCategory(camera, PinCategory.Capture, 0)).SetFormat(pmt);
//hr = ((IAMStreamConfig)GetPin(pUSB20Camera, "Capture")).SetFormat(pmt);
DsUtils.FreeAMMediaType(pmt);
DsError.ThrowExceptionForHR(hr);
//add MJPG Decompressor
IBaseFilter pMJPGDecompressor = (IBaseFilter)new MjpegDec();
hr = pGraph.AddFilter(pMJPGDecompressor, "MJPG Decompressor");
DsError.ThrowExceptionForHR(hr);
//add color space converter
IBaseFilter pColorSpaceConverter = (IBaseFilter)new Colour();
hr = pGraph.AddFilter(pColorSpaceConverter, "Color space converter");
DsError.ThrowExceptionForHR(hr);
// Connect camera and MJPEG Decomp
//hr = pGraph.ConnectDirect(GetPin(pUSB20Camera, "Capture"), GetPin(pMJPGDecompressor, "XForm In"), null);
hr = pGraph.ConnectDirect(DsFindPin.ByCategory(camera, PinCategory.Capture, 0), DsFindPin.ByName(pMJPGDecompressor, "XForm In"), null);
DsError.ThrowExceptionForHR(hr);
// Connect MJPG Decomp and color space converter
hr = pGraph.ConnectDirect(DsFindPin.ByName(pMJPGDecompressor, "XForm Out"), DsFindPin.ByName(pColorSpaceConverter, "Input"), null);
DsError.ThrowExceptionForHR(hr);
//add SampleGrabber
//IBaseFilter pSampleGrabber = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_SampleGrabber));
//hr = pGraph.AddFilter(pSampleGrabber, "SampleGrabber");
IBaseFilter sampleGrabber = new SampleGrabber() as IBaseFilter;
hr = pGraph.AddFilter(sampleGrabber, "Sample grabber");
DsError.ThrowExceptionForHR(hr);
// Configure the samplegrabber
AMMediaType pSampleGrabber_pmt = new AMMediaType();
pSampleGrabber_pmt.majorType = MediaType.Video;
pSampleGrabber_pmt.subType = MediaSubType.ARGB32;
pSampleGrabber_pmt.formatType = FormatType.VideoInfo;
pSampleGrabber_pmt.fixedSizeSamples = true;
pSampleGrabber_pmt.formatSize = 88;
pSampleGrabber_pmt.sampleSize = 3686400;
pSampleGrabber_pmt.temporalCompression = false;
VideoInfoHeader pSampleGrabber_format = new VideoInfoHeader();
pSampleGrabber_format.SrcRect = new DsRect();
pSampleGrabber_format.TargetRect = new DsRect();
pSampleGrabber_format.BitRate = 884736885;
pSampleGrabber_format.AvgTimePerFrame = 333333;
pSampleGrabber_format.BmiHeader = new BitmapInfoHeader();
pSampleGrabber_format.BmiHeader.Size = 40;
pSampleGrabber_format.BmiHeader.Width = 1280;
pSampleGrabber_format.BmiHeader.Height = 720;
pSampleGrabber_format.BmiHeader.Planes = 1;
pSampleGrabber_format.BmiHeader.BitCount = 32;
//pSampleGrabber_format.BmiHeader.Compression = 1196444237;
pSampleGrabber_format.BmiHeader.ImageSize = 3686400;
//.........这里部分代码省略.........
示例5: ConnectPins
private static void ConnectPins(IGraphBuilder graphBuilder, IPin pinOut, IBaseFilter toFilter,
string toPinName)
{
IPin pinIn = null;
try
{
pinIn = GetPin(toFilter, toPinName);
DsError.ThrowExceptionForHR(graphBuilder.ConnectDirect(pinOut, pinIn, null));
}
finally
{
if (pinIn != null)
{
Marshal.ReleaseComObject(pinIn);
}
}
}