本文整理汇总了C#中ICaptureGraphBuilder2类的典型用法代码示例。如果您正苦于以下问题:C# ICaptureGraphBuilder2类的具体用法?C# ICaptureGraphBuilder2怎么用?C# ICaptureGraphBuilder2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ICaptureGraphBuilder2类属于命名空间,在下文中一共展示了ICaptureGraphBuilder2类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PropertyPageCollection
/// <summary> Initialize collection with property pages from existing graph. </summary>
internal PropertyPageCollection(
ICaptureGraphBuilder2 graphBuilder,
IBaseFilter videoDeviceFilter, IBaseFilter audioDeviceFilter,
IBaseFilter videoCompressorFilter, IBaseFilter audioCompressorFilter,
SourceCollection videoSources, SourceCollection audioSources)
{
addFromGraph( graphBuilder,
videoDeviceFilter, audioDeviceFilter,
videoCompressorFilter, audioCompressorFilter,
videoSources, audioSources );
}
示例2: ShowTunerPinDialog
public static bool ShowTunerPinDialog(ICaptureGraphBuilder2 bld, IBaseFilter flt, IntPtr hwnd)
{
object ppint = null;
ISpecifyPropertyPages pages = null;
bool flag;
DsCAUUID pPages = new DsCAUUID();
try
{
Guid capture = PinCategory.Capture;
Guid interleaved = MediaType.Interleaved;
Guid gUID = typeof(IAMTVTuner).GUID;
if (bld.FindInterface(ref capture, ref interleaved, flt, ref gUID, out ppint) != 0)
{
interleaved = MediaType.Video;
if (bld.FindInterface(ref capture, ref interleaved, flt, ref gUID, out ppint) != 0)
{
return false;
}
}
pages = ppint as ISpecifyPropertyPages;
if (pages == null)
{
return false;
}
int num = pages.GetPages(out pPages);
num = OleCreatePropertyFrame(hwnd, 30, 30, null, 1, ref ppint, pPages.cElems, pPages.pElems, 0, 0, IntPtr.Zero);
flag = true;
}
catch (Exception exception)
{
Trace.WriteLine("!Ds.NET: ShowCapPinDialog " + exception.Message);
flag = false;
}
finally
{
if (pPages.pElems != IntPtr.Zero)
{
Marshal.FreeCoTaskMem(pPages.pElems);
}
pages = null;
if (ppint != null)
{
Marshal.ReleaseComObject(ppint);
}
ppint = null;
}
return flag;
}
示例3: ShowTunerPinDialog
public static bool ShowTunerPinDialog( ICaptureGraphBuilder2 bld, IBaseFilter flt, IntPtr hwnd )
{
int hr;
object comObj = null;
ISpecifyPropertyPages spec = null;
DsCAUUID cauuid = new DsCAUUID();
try
{
DsGuid cat = PinCategory.Capture;
DsGuid type = MediaType.Interleaved;
DsGuid iid = typeof(IAMTVTuner).GUID;
hr = bld.FindInterface( cat, type, flt, iid, out comObj );
if( hr != 0 )
{
type = MediaType.Video;
hr = bld.FindInterface( cat, type, flt, iid, out comObj );
if( hr != 0 )
return false;
}
spec = comObj as ISpecifyPropertyPages;
if( spec == null )
return false;
hr = spec.GetPages( out cauuid );
hr = OleCreatePropertyFrame( hwnd, 30, 30, null, 1,
ref comObj, cauuid.cElems, cauuid.pElems, 0, 0, IntPtr.Zero );
return true;
}
catch( Exception ee )
{
Trace.WriteLine( "!Ds.NET: ShowCapPinDialog " + ee.Message );
return false;
}
finally
{
if( cauuid.pElems != IntPtr.Zero )
Marshal.FreeCoTaskMem( cauuid.pElems );
spec = null;
if( comObj != null )
Marshal.ReleaseComObject( comObj );
comObj = null;
}
}
示例4: Setup
/// <summary>
/// グラフの生成
/// </summary>
/// <param name="output_file">出力ファイル</param>
public virtual void Setup(string output_file)
{
this.Dispose();
try
{
CxDSCameraParam param = this.Param;
// グラフビルダー.
// CoCreateInstance
GraphBuilder = (IGraphBuilder)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(GUID.CLSID_FilterGraph)));
#region フィルタ追加.
// 画像入力フィルタ.
IBaseFilter capture = CreateVideoCapture(param);
if (capture == null)
throw new System.IO.IOException();
this.GraphBuilder.AddFilter(capture, "CaptureFilter");
IPin capture_out = DSLab.Axi.FindPin(capture, 0, PIN_DIRECTION.PINDIR_OUTPUT);
this.CaptureFilter = capture;
this.CaptureOutPin = capture_out;
// サンプルグラバー.
IBaseFilter grabber = (IBaseFilter)CreateSampleGrabber();
if (grabber == null)
throw new System.IO.IOException();
this.GraphBuilder.AddFilter(grabber, "SampleGrabber");
this.SampleGrabber = (ISampleGrabber)grabber;
#endregion
#region キャプチャビルダー:
{
int hr = 0;
CaptureBuilder = (ICaptureGraphBuilder2)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(GUID.CLSID_CaptureGraphBuilder2)));
hr = CaptureBuilder.SetFiltergraph(GraphBuilder);
if (string.IsNullOrEmpty(output_file))
{
// レンダラー.
IBaseFilter renderer = null;
renderer = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(GUID.CLSID_NullRenderer)));
if (renderer == null)
throw new System.IO.IOException();
this.GraphBuilder.AddFilter(renderer, "Renderer");
this.Renderer = renderer;
#if true
// IGraphBuilder.Connect の代わりに ICaptureGraphBuilder2.RenderStream を使用する.
// fig) [capture]-out->-in-[sample grabber]-out->-in-[null render]
hr = CaptureBuilder.RenderStream(new Guid(GUID.PIN_CATEGORY_CAPTURE), new Guid(GUID.MEDIATYPE_Video), capture, grabber, renderer);
#else
// ピンの取得.
IPin grabber_in = DSLab.Axi.FindPin(grabber, 0, PIN_DIRECTION.PINDIR_INPUT);
IPin grabber_out = DSLab.Axi.FindPin(grabber, 0, PIN_DIRECTION.PINDIR_OUTPUT);
IPin renderer_in = DSLab.Axi.FindPin(renderer, 0, PIN_DIRECTION.PINDIR_INPUT);
// ピンの接続.
GraphBuilder.Connect(capture_out, grabber_in);
GraphBuilder.Connect(grabber_out, renderer_in);
// ピンの保管.
//SampleGrabberInPin = grabber_in;
//SampleGrabberOutPin = grabber_out;
//RendererInPin = renderer_in;
#endif
}
else
{
IBaseFilter mux = null;
IFileSinkFilter sync = null;
hr = CaptureBuilder.SetOutputFileName(new Guid(GUID.MEDIASUBTYPE_Avi), output_file, ref mux, ref sync);
hr = CaptureBuilder.RenderStream(new Guid(GUID.PIN_CATEGORY_CAPTURE), new Guid(GUID.MEDIATYPE_Video), capture, grabber, mux);
this.Mux = mux;
this.Sync = sync;
}
}
#endregion
#region 保管: フレームサイズ.
VIDEOINFOHEADER vinfo = DSLab.Axi.GetVideoInfo(SampleGrabber);
this.SampleGrabberCB.BitmapInfo = vinfo.bmiHeader;
this.SampleGrabberCB.FrameSize = new Size(
System.Math.Abs(this.SampleGrabberCB.BitmapInfo.biWidth),
System.Math.Abs(this.SampleGrabberCB.BitmapInfo.biHeight)
);
#endregion
#region 保管: デバイス名称.
try
{
if (string.IsNullOrEmpty(param.FilterInfo.Name) == false)
{
this.DeviceName = param.FilterInfo.Name;
}
else
//.........这里部分代码省略.........
示例5: InitResolution
void InitResolution(ICaptureGraphBuilder2 capGraph, IBaseFilter capFilter, int targetWidth, int targetHeight)
{
object o;
capGraph.FindInterface(PinCategory.Capture, MediaType.Video, capFilter, typeof(IAMStreamConfig).GUID, out o);
AMMediaType media = null;
IAMStreamConfig videoStreamConfig = o as IAMStreamConfig;
IntPtr ptr;
int iC = 0, iS = 0;
videoStreamConfig.GetNumberOfCapabilities(out iC, out iS);
ptr = Marshal.AllocCoTaskMem(iS);
int bestDWidth = 999999;
int bestDHeight = 999999;
int streamID = 0;
for (int i = 0; i < iC; i++)
{
videoStreamConfig.GetStreamCaps(i, out media, ptr);
VideoInfoHeader v;
v = new VideoInfoHeader();
Marshal.PtrToStructure(media.formatPtr, v);
int dW = Math.Abs(targetWidth - v.BmiHeader.Width);
int dH = Math.Abs(targetHeight - v.BmiHeader.Height);
if (dW < bestDWidth && dH < bestDHeight)
{
streamID = i;
bestDWidth = dW;
bestDHeight = dH;
}
}
videoStreamConfig.GetStreamCaps(streamID, out media, ptr);
int hr = videoStreamConfig.SetFormat(media);
Marshal.FreeCoTaskMem(ptr);
DsError.ThrowExceptionForHR(hr);
DsUtils.FreeAMMediaType(media);
media = null;
}
示例6: Init
private void Init()
{
graphBuilder = (IGraphBuilder)new FilterGraph();
//Create the media control for controlling the graph
mediaControl = (IMediaControl)graphBuilder;
mediaEvent = (IMediaEvent)graphBuilder;
volume = 100;
captureGraphBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
// initialize the Capture Graph Builder
int hr = captureGraphBuilder.SetFiltergraph(this.graphBuilder);
DsError.ThrowExceptionForHR(hr);
DeinterlaceLayoutList = new DeinterlaceList();
DeinterlaceLayoutList.Add(new DeInterlaceAlparyLayout(this));
DeinterlaceLayoutList.Add(new DeInterlaceDscalerLayout(this));
DeinterlaceLayoutList.Add(new DeInterlaceFFDShowLayout(this));
aspectRatio = 4.0f / 3.0f;
}
示例7: SourceCollection
/// <summary> Initialize collection with sources from graph. </summary>
internal SourceCollection(ICaptureGraphBuilder2 graphBuilder, IBaseFilter deviceFilter, bool isVideoDevice)
{
addFromGraph( graphBuilder, deviceFilter, isVideoDevice );
}
示例8: SetConfigParms
// Set the Framerate, and video size
private void SetConfigParms(ICaptureGraphBuilder2 capGraph, IBaseFilter capFilter, int iFrameRate, int iWidth, int iHeight)
{
int hr;
object o;
AMMediaType media;
// Find the stream config interface
hr = capGraph.FindInterface(
PinCategory.Capture, MediaType.Video, capFilter, typeof(IAMStreamConfig).GUID, out o );
IAMStreamConfig videoStreamConfig = o as IAMStreamConfig;
if (videoStreamConfig == null)
{
throw new Exception("Failed to get IAMStreamConfig");
}
// Get the existing format block
hr = videoStreamConfig.GetFormat( out media);
DsError.ThrowExceptionForHR( hr );
// copy out the videoinfoheader
VideoInfoHeader v = new VideoInfoHeader();
Marshal.PtrToStructure( media.formatPtr, v );
// if overriding the framerate, set the frame rate
if (iFrameRate > 0)
{
v.AvgTimePerFrame = 10000000 / iFrameRate;
}
// if overriding the width, set the width
if (iWidth > 0)
{
v.BmiHeader.Width = iWidth;
}
// if overriding the Height, set the Height
if (iHeight > 0)
{
v.BmiHeader.Height = iHeight;
}
// Copy the media structure back
Marshal.StructureToPtr( v, media.formatPtr, false );
// Set the new format
hr = videoStreamConfig.SetFormat( media );
DsError.ThrowExceptionForHR( hr );
DsUtils.FreeAMMediaType(media);
media = null;
}
示例9: InitCaptureInterface
private void InitCaptureInterface()
{
// release com object (useless here but can't hurt)
Cleanup(true);
this.fmc = new FilgraphManagerClass();
// create the cg object and add the filter graph to it
Type t = Type.GetTypeFromCLSID(CLSID_CaptureGraphBuilder2);
this.icgb = (ICaptureGraphBuilder2)Activator.CreateInstance(t);
t = Type.GetTypeFromCLSID(CLSID_SampleGrabber);
this.isg = (ISampleGrabber)Activator.CreateInstance(t);
// source filter (the capture device)
this.sf = (IBaseFilter)this.SourceFilterList[this.cbxDevice.SelectedIndex];
// sample grabber filter
this.sgf = (IBaseFilter)this.isg;
object o = null;
this.icgb.RemoteFindInterface(ref PIN_CATEGORY_CAPTURE, ref MEDIATYPE_Video, sf, ref IID_IAMStreamConfig, out o);
this.iamsc = (IAMStreamConfig)o;
// set sample grabber media type
this.SGMediaType = new _AMMediaType();
this.SGMediaType.majortype = MEDIATYPE_Video;
this.SGMediaType.subtype = MEDIASUBTYPE_RGB24;
this.SGMediaType.formattype = FORMAT_VideoInfo;
this.isg.SetMediaType(ref SGMediaType);
this.isg.SetOneShot(0);
this.isg.SetBufferSamples(1);
}
示例10: findCrossbars
/// <summary>
/// Retrieve a list of crossbar filters in the graph.
/// Most hardware devices should have a maximum of 2 crossbars,
/// one for video and another for audio.
/// </summary>
protected ArrayList findCrossbars(ICaptureGraphBuilder2 graphBuilder, IBaseFilter deviceFilter)
{
ArrayList crossbars = new ArrayList();
Guid category = FindDirection.UpstreamOnly;
Guid type = new Guid();
Guid riid = typeof(IAMCrossbar).GUID;
int hr;
object comObj = null;
object comObjNext = null;
// Find the first interface, look upstream from the selected device
hr = graphBuilder.FindInterface( ref category, ref type, deviceFilter, ref riid, out comObj );
while ( (hr == 0) && (comObj != null) )
{
// If found, add to the list
if ( comObj is IAMCrossbar )
{
crossbars.Add( comObj as IAMCrossbar );
// Find the second interface, look upstream from the next found crossbar
hr = graphBuilder.FindInterface( ref category, ref type, comObj as IBaseFilter, ref riid, out comObjNext );
comObj = comObjNext;
}
else
comObj = null;
}
return( crossbars );
}
示例11: SetConfigParms
// Set the Framerate, and video size
private void SetConfigParms(ICaptureGraphBuilder2 capGraph, IBaseFilter capFilter, int iSampleRate, int iChannels)
{
int hr;
object o;
AMMediaType media;
// Find the stream config interface
hr = capGraph.FindInterface(
PinCategory.Capture, MediaType.Audio, capFilter, typeof(IAMStreamConfig).GUID, out o);
IAMStreamConfig audioStreamConfig = o as IAMStreamConfig;
if (audioStreamConfig == null) {
throw new Exception("Failed to get IAMStreamConfig");
}
// Get the existing format block
hr = audioStreamConfig.GetFormat(out media);
DsError.ThrowExceptionForHR(hr);
// copy out the videoinfoheader
WaveFormatEx i = new WaveFormatEx();
Marshal.PtrToStructure(media.formatPtr, i);
i.wFormatTag = 0x0001; // WAVE_FORMAT_PCM
i.wBitsPerSample = 16;
i.nSamplesPerSec = 44100;
i.nChannels = m_Channels;
i.nBlockAlign = 2;
i.nAvgBytesPerSec = (i.nSamplesPerSec * i.nBlockAlign);
i.cbSize = 0;
// if overriding the framerate, set the frame rate
if (iSampleRate > 0) {
i.nSamplesPerSec = iSampleRate;
}
// if overriding the width, set the width
if (iChannels > 0) {
i.nChannels = (short)iChannels;
}
// Copy the media structure back
Marshal.StructureToPtr(i, media.formatPtr, false);
// Set the new format
hr = audioStreamConfig.SetFormat(media);
DsError.ThrowExceptionForHR(hr);
DsUtils.FreeAMMediaType(media);
media = null;
}
示例12: SetVideoCaptureParameters
/// <summary>
/// Sets the capture parameters for the video capture device
/// </summary>
private bool SetVideoCaptureParameters(ICaptureGraphBuilder2 capGraph, IBaseFilter captureFilter, Guid mediaSubType)
{
/* The stream config interface */
object streamConfig;
/* Get the stream's configuration interface */
int hr = capGraph.FindInterface(PinCategory.Capture,
MediaType.Video,
captureFilter,
typeof(IAMStreamConfig).GUID,
out streamConfig);
DsError.ThrowExceptionForHR(hr);
var videoStreamConfig = streamConfig as IAMStreamConfig;
/* If QueryInterface fails... */
if (videoStreamConfig == null)
{
throw new Exception("Failed to get IAMStreamConfig");
}
/* The media type of the video */
AMMediaType media;
/* Get the AMMediaType for the video out pin */
hr = videoStreamConfig.GetFormat(out media);
DsError.ThrowExceptionForHR(hr);
/* Make the VIDEOINFOHEADER 'readable' */
var videoInfo = new VideoInfoHeader();
Marshal.PtrToStructure(media.formatPtr, videoInfo);
/* Setup the VIDEOINFOHEADER with the parameters we want */
videoInfo.AvgTimePerFrame = DSHOW_ONE_SECOND_UNIT / FPS;
videoInfo.BmiHeader.Width = DesiredWidth;
videoInfo.BmiHeader.Height = DesiredHeight;
if (mediaSubType != Guid.Empty)
{
int fourCC = 0;
byte[] b = mediaSubType.ToByteArray();
fourCC = b[0];
fourCC |= b[1] << 8;
fourCC |= b[2] << 16;
fourCC |= b[3] << 24;
videoInfo.BmiHeader.Compression = fourCC;
media.subType = mediaSubType;
}
/* Copy the data back to unmanaged memory */
Marshal.StructureToPtr(videoInfo, media.formatPtr, false);
/* Set the format */
hr = videoStreamConfig.SetFormat(media);
/* We don't want any memory leaks, do we? */
DsUtils.FreeAMMediaType(media);
if (hr < 0)
return false;
return true;
}
示例13: InitTuner
private void InitTuner(ICaptureGraphBuilder2 captureGraphBuilder)
{
Object o;
var hr = captureGraphBuilder.FindInterface(null, null, videoDevice, typeof(IAMTVTuner).GUID, out o);
if (hr >= 0)
{
tuner = (IAMTVTuner)o;
//tuner.put_Mode(AMTunerModeType.TV);
o = null;
//find crossbar
var list = findCrossbars(captureGraphBuilder, (IBaseFilter)tuner);
/*hr = captureGraphBuilder.FindInterface(null, null, (IBaseFilter)Tuner, typeof(IAMCrossbar).GUID, out o);
if (hr >= 0)
{
crossbar = (IAMCrossbar)o;
InitCrossbar();
}
else
crossbar = null;
*/
if (list.Count > 0)
{
crossbar = (IAMCrossbar)list[0];
InitCrossbar();
}
o = null;
// find amtvaudio
hr = captureGraphBuilder.FindInterface(null, null, videoDevice, typeof(IAMTVAudio).GUID, out o);
if (hr >= 0)
{
TVAudio = (IAMTVAudio)o;
}
o = null;
// find IAMAnalogVideoDecoder
hr = captureGraphBuilder.FindInterface(null, null, videoDevice, typeof(IAMAnalogVideoDecoder).GUID, out o);
if (hr >= 0)
{
analogVideoDecoder = (o as IAMAnalogVideoDecoder);
AnalogVideoStandard avs;
analogVideoDecoder.get_TVFormat(out avs);
}
o = null;
}
else
tuner = null;
}
示例14: InitAMStreamConfig
private void InitAMStreamConfig(ICaptureGraphBuilder2 captureGraphBuilder2, IBaseFilter aDev)
{
Object o;
if (AMStreamConfig != null)
{
// IBaseFilter bf = (IBaseFilter)AMStreamConfig;
// RemoveFilter(ref bf);
}
var hr = captureGraphBuilder2.FindInterface(PinCategory.Capture, MediaType.Video, aDev, typeof(IAMStreamConfig).GUID, out o);
DsError.ThrowExceptionForHR(hr);
AMStreamConfig = o as IAMStreamConfig;
if (AMStreamConfig == null)
{
throw new Exception("Failed to get IAMStreamConfig");
}
}
示例15: addFromGraph
// -------------------- Protected Methods -----------------------
/// <summary> Populate the collection from a filter graph. </summary>
protected void addFromGraph( ICaptureGraphBuilder2 graphBuilder, IBaseFilter deviceFilter, bool isVideoDevice )
{
Trace.Assert( graphBuilder != null );
ArrayList crossbars = findCrossbars( graphBuilder, deviceFilter );
foreach ( IAMCrossbar crossbar in crossbars )
{
ArrayList sources = findCrossbarSources( graphBuilder, crossbar, isVideoDevice );
InnerList.AddRange( sources );
}
if ( !isVideoDevice )
{
if ( InnerList.Count == 0 )
{
ArrayList sources = findAudioSources( graphBuilder, deviceFilter );
InnerList.AddRange( sources );
}
}
}