本文整理汇总了C#中IGraphBuilder.AddSourceFilter方法的典型用法代码示例。如果您正苦于以下问题:C# IGraphBuilder.AddSourceFilter方法的具体用法?C# IGraphBuilder.AddSourceFilter怎么用?C# IGraphBuilder.AddSourceFilter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IGraphBuilder
的用法示例。
在下文中一共展示了IGraphBuilder.AddSourceFilter方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetInterface
private void GetInterface()
{
object o;
int hr;
m_pGraph = (IGraphBuilder)new FilterGraph();
IBaseFilter pSource;
hr = m_pGraph.AddSourceFilter(@"C:\SourceForge\mflib\Test\Media\AspectRatio4x3.wmv", null, out pSource);
DsError.ThrowExceptionForHR(hr);
IBaseFilter pEVR = (IBaseFilter)new EnhancedVideoRenderer();
hr = m_pGraph.AddFilter(pEVR, "EVR");
DsError.ThrowExceptionForHR(hr);
ICaptureGraphBuilder2 cgb;
cgb = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
hr = cgb.SetFiltergraph(m_pGraph);
DsError.ThrowExceptionForHR(hr);
hr = cgb.RenderStream(null, MediaType.Video, pSource, null, pEVR);
DsError.ThrowExceptionForHR(hr);
IMFGetService gs = pEVR as IMFGetService;
hr = gs.GetService(MFServices.MR_VIDEO_MIXER_SERVICE, typeof(IMFVideoProcessor).GUID, out o);
MFError.ThrowExceptionForHR(hr);
m_vp = o as IMFVideoProcessor;
}
示例2: Setup
/// <summary>
/// グラフの生成
/// </summary>
public virtual void Setup()
{
this.Dispose();
try
{
// グラフ.
// CoCreateInstance
GraphBuilder = (IGraphBuilder)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(GUID.CLSID_FilterGraph)));
#region フィルタ追加.
// ファイル入力.
IBaseFilter capture = null;
GraphBuilder.AddSourceFilter(SourceFile, "CaptureFilter", ref capture);
if (capture == null)
throw new System.IO.IOException();
#if false
// DMO ラッパーフィルタ.
// https://msdn.microsoft.com/ja-jp/library/cc371140.aspx
IBaseFilter dmo = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(GUID.CLSID_DMOWrapperFilter)));
if (dmo != null)
{
//// Mpeg4 Decoder DMO
//// F371728A-6052-4D47-827C-D039335DFE0A
//// 4A69B442-28BE-4991-969C-B500ADF5D8A8
//// mpg4decd.dll [C:\Windows\System32, C:\Windows\SysWOW64]
var idmo = (IDMOWrapperFilter)dmo;
idmo.Init(new Guid("F371728A-6052-4D47-827C-D039335DFE0A"), new Guid("4A69B442-28BE-4991-969C-B500ADF5D8A8"));
idmo = null;
this.GraphBuilder.AddFilter(dmo, "Mpeg4 Decoder DMO");
}
#endif
#if false
// Avi Splitter
IBaseFilter splitter = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(GUID.CLSID_AVISplitter)));
if (splitter == null)
throw new System.IO.IOException();
this.GraphBuilder.AddFilter(splitter, "Avi Splitter");
// Avi Decompressor
IBaseFilter decompressor = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(GUID.CLSID_AVIDec)));
if (decompressor == null)
throw new System.IO.IOException();
this.GraphBuilder.AddFilter(decompressor, "Avi Decompressor");
#endif
// サンプルグラバー.
IBaseFilter grabber = (IBaseFilter)CreateSampleGrabber();
if (grabber == null)
throw new System.IO.IOException();
this.GraphBuilder.AddFilter(grabber, "SampleGrabber");
// レンダラー.
IBaseFilter renderer = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(GUID.CLSID_NullRenderer)));
if (renderer == null)
throw new System.IO.IOException();
this.GraphBuilder.AddFilter(renderer, "Renderer");
#endregion
#region ピンの取得.
IPin capture_out = DSLab.Axi.FindPin(capture, 0, PIN_DIRECTION.PINDIR_OUTPUT);
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);
#endregion
#region ピンの接続.
GraphBuilder.Connect(capture_out, grabber_in);
GraphBuilder.Connect(grabber_out, renderer_in);
#endregion
#region 保管: インターフェース.
CaptureFilter = capture;
CaptureOutPin = capture_out;
SampleGrabber = (ISampleGrabber)grabber;
SampleGrabberInPin = grabber_in;
SampleGrabberOutPin = grabber_out;
Renderer = renderer;
RendererInPin = renderer_in;
#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 インタフェースの抽出:
{
DSLab.IGraphBuilder graph = this.GraphBuilder;
//.........这里部分代码省略.........
示例3: Player_Connect
/// <summary>
/// プレイヤーの接続
/// </summary>
/// <param name="filename"></param>
private void Player_Connect(string filename)
{
#region グラフビルダーの生成:
{
Graph = (IGraphBuilder)Axi.CoCreateInstance(GUID.CLSID_FilterGraph);
if (Graph == null)
throw new System.IO.IOException("Failed to create a GraphBuilder.");
Builder = (ICaptureGraphBuilder2)Axi.CoCreateInstance(GUID.CLSID_CaptureGraphBuilder2);
if (Builder == null)
throw new System.IO.IOException("Failed to create a GraphBuilder.");
Builder.SetFiltergraph(Graph);
}
#endregion
#region 映像入力用: ソースフィルタを生成します.
{
Graph.AddSourceFilter(filename, "VideoSource", ref VideoSource);
if (VideoSource == null)
throw new System.IO.IOException("Failed to create a VideoSource.");
}
#endregion
#region 映像捕獲用: サンプルグラバーを生成します.
{
VideoGrabber = (IBaseFilter)Axi.CoCreateInstance(GUID.CLSID_SampleGrabber);
if (VideoGrabber == null)
throw new System.IO.IOException("Failed to create a VideoGrabber.");
Graph.AddFilter(VideoGrabber, "VideoGrabber");
// サンプルグラバフィルタの入力形式設定.
// SetMediaType で必要なメディア タイプを指定します。
// http://msdn.microsoft.com/ja-jp/library/cc369546.aspx
// ※AM_MEDIA_TYPE 構造体のメンバをすべて設定する必要はない。
// ※デフォルトでは、サンプル グラバに優先メディア タイプはない。
// ※サンプル グラバを正しいフィルタに確実に接続するには、フィルタ グラフを作成する前にこのメソッドを呼び出す。
// majortype: http://msdn.microsoft.com/ja-jp/library/cc370108.aspx
// subtype : http://msdn.microsoft.com/ja-jp/library/cc371040.aspx
{
var grabber = (ISampleGrabber)VideoGrabber;
var mt = new AM_MEDIA_TYPE();
mt.majortype = new Guid(GUID.MEDIATYPE_Video);
mt.subtype = new Guid(GUID.MEDIASUBTYPE_RGB24);
mt.formattype = new Guid(GUID.FORMAT_VideoInfo);
grabber.SetMediaType(mt);
grabber.SetBufferSamples(false); // サンプルコピー 無効.
grabber.SetOneShot(false); // One Shot 無効.
//grabber.SetCallback(VideoGrabberCB, 0); // 0:SampleCB メソッドを呼び出すよう指示する.
grabber.SetCallback(VideoGrabberCB, 1); // 1:BufferCB メソッドを呼び出すよう指示する.
}
}
#endregion
#region 音声捕獲用: サンプルグラバーを生成します.
{
AudioGrabber = (IBaseFilter)Axi.CoCreateInstance(GUID.CLSID_SampleGrabber);
if (AudioGrabber == null)
throw new System.IO.IOException("Failed to create a AudioGrabber.");
Graph.AddFilter(AudioGrabber, "AudioGrabber");
// サンプルグラバフィルタの入力形式設定.
// SetMediaType で必要なメディア タイプを指定します。
// http://msdn.microsoft.com/ja-jp/library/cc369546.aspx
// ※AM_MEDIA_TYPE 構造体のメンバをすべて設定する必要はない。
// ※デフォルトでは、サンプル グラバに優先メディア タイプはない。
// ※サンプル グラバを正しいフィルタに確実に接続するには、フィルタ グラフを作成する前にこのメソッドを呼び出す。
// majortype: http://msdn.microsoft.com/ja-jp/library/cc370108.aspx
// subtype : http://msdn.microsoft.com/ja-jp/library/cc371040.aspx
{
var grabber = (ISampleGrabber)AudioGrabber;
var mt = new AM_MEDIA_TYPE();
mt.majortype = new Guid(GUID.MEDIATYPE_Audio);
mt.subtype = new Guid(GUID.MEDIASUBTYPE_PCM);
mt.formattype = new Guid(GUID.FORMAT_WaveFormatEx);
grabber.SetMediaType(mt);
grabber.SetBufferSamples(false); // サンプルコピー 無効.
grabber.SetOneShot(false); // One Shot 無効.
//grabber.SetCallback(AudioGrabberCB, 0); // 0:SampleCB メソッドを呼び出すよう指示する.
grabber.SetCallback(AudioGrabberCB, 1); // 1:BufferCB メソッドを呼び出すよう指示する.
}
}
#endregion
#region 映像出力用: レンダラーを生成します.
{
VideoRenderer = (IBaseFilter)Axi.CoCreateInstance(GUID.CLSID_NullRenderer);
if (VideoRenderer == null)
throw new System.IO.IOException("Failed to create a VideoRenderer.");
Graph.AddFilter(VideoRenderer, "VideoRenderer");
}
#endregion
#region 音声出力用: レンダラーを生成します.
{
//.........这里部分代码省略.........
示例4: PlayMovieInWindow
internal void PlayMovieInWindow(string filename)
{
FileLogger.Log("PlayMovieInWindow: {0}", filename);
lastJump = 0;
int hr = 0;
if (filename == string.Empty)
return;
this.graphBuilder = (IGraphBuilder)new FilterGraph();
FileLogger.Log("PlayMovieInWindow: Create Graph");
this.evrRenderer = FilterGraphTools.AddFilterFromClsid(this.graphBuilder, new Guid("{FA10746C-9B63-4B6C-BC49-FC300EA5F256}"), "EVR");
if (evrRenderer != null)
{
FileLogger.Log("PlayMovieInWindow: Add EVR");
SetupEvrDisplay();
//#if DEBUG
if (ps.PublishGraph)
rot = new DsROTEntry(this.graphBuilder);
//#endif
IObjectWithSite grfSite = graphBuilder as IObjectWithSite;
if (grfSite != null)
grfSite.SetSite(new FilterBlocker(filename));
string fileExt = Path.GetExtension(filename).ToLower();
if (ps.PreferredDecoders != null)
{
foreach (string pa in ps.PreferredDecoders)
{
string[] pvA = pa.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
if (pvA[0].ToLower() == fileExt)
{
for (int i = 1; i < pvA.Length; i++)
{
string strFilter = pvA[i].Trim();
IBaseFilter filter = null;
try
{
if (Regex.IsMatch(strFilter, @"{?\w{8}-\w{4}-\w{4}-\w{4}-\w{12}}?"))
filter = FilterGraphTools.AddFilterFromClsid(graphBuilder, new Guid(strFilter), strFilter);
else
filter = FilterGraphTools.AddFilterByName(graphBuilder, FilterCategory.LegacyAmFilterCategory, strFilter);
if (filter != null)
{
FileLogger.Log("Added {0} to the graph", strFilter);
}
else
FileLogger.Log("{0} not added to the graph", strFilter);
}
finally
{
if (filter != null)
Marshal.ReleaseComObject(filter);
filter = null;
}
}
}
}
}
// Have the graph builder construct its the appropriate graph automatically
//hr = this.graphBuilder.RenderFile(filename, null);
IBaseFilter sourceFilter = null;
try
{
hr = graphBuilder.AddSourceFilter(filename, "Source", out sourceFilter);
DsError.ThrowExceptionForHR(hr);
IPin outPin = DsFindPin.ByConnectionStatus(sourceFilter, PinConnectedStatus.Unconnected, 0);
while (outPin != null)
{
try
{
hr = graphBuilder.Render(outPin);
DsError.ThrowExceptionForHR(hr);
}
finally
{
if (outPin != null)
Marshal.ReleaseComObject(outPin);
outPin = null;
}
outPin = DsFindPin.ByConnectionStatus(sourceFilter, PinConnectedStatus.Unconnected, 0);
}
}
finally
{
if (sourceFilter != null)
Marshal.ReleaseComObject(sourceFilter);
}
//.........这里部分代码省略.........
示例5: PlayMovieInWindow
//.........这里部分代码省略.........
IMPAudioRendererConfig arSett = audioRenderer as IMPAudioRendererConfig;
if (arSett != null)
{
int ac3Mode;
hr = arSett.GetInt(MPARSetting.AC3_ENCODING, out ac3Mode);
int sc;
hr = arSett.GetInt(MPARSetting.SPEAKER_CONFIG, out sc);
int sm;
hr = arSett.GetInt(MPARSetting.WASAPI_MODE, out sm);
bool em;
hr = arSett.GetBool(MPARSetting.WASAPI_EVENT_DRIVEN, out em);
/*DeviceDefinition[] */
IntPtr dc;
//int count;
//hr = arSett.GetAvailableAudioDevices(out dc, out count);
//DsError.ThrowExceptionForHR(hr);
////DeviceDefinition[] dd = new DeviceDefinition[count];
//AudioDeviceDefinition dd = (AudioDeviceDefinition)Marshal.PtrToStructure(dc, typeof(AudioDeviceDefinition));
//if (dc != null)
// Marshal.ReleaseComObject(dc);
hr = arSett.SetString(MPARSetting.SETTING_AUDIO_DEVICE, ps.AudioPlaybackDevice);
//arSett.SetSpeakerMatchOutput(true);
arSett.SetBool(MPARSetting.WASAPI_EVENT_DRIVEN, true);
arSett.SetInt(MPARSetting.USE_FILTERS, (int)MPARUseFilters.ALL);
arSett.SetBool(MPARSetting.ALLOW_BITSTREAMING, true);
arSett.SetInt(MPARSetting.AC3_ENCODING, (int)AC3Encoding.DISABLED);
arSett.SetBool(MPARSetting.ENABLE_TIME_STRETCHING, false);
}
//try
//{
hr = graphBuilder.AddSourceFilter(filename, "Source", out sourceFilter);
if (hr < 0)
{
//if it doesn't work before failing try to load it with the WMV reader
sourceFilter = (IBaseFilter)new WMAsfReader();
hr = graphBuilder.AddFilter(sourceFilter, "WM/ASF Reader");
DsError.ThrowExceptionForHR(hr);
hr = ((IFileSourceFilter)sourceFilter).Load(filename, null);
DsError.ThrowExceptionForHR(hr);
wmReader = sourceFilter as WindowsMediaLib.IWMReaderAdvanced2;
}
IPin outPin = DsFindPin.ByConnectionStatus(sourceFilter, PinConnectedStatus.Unconnected, 0);
while (outPin != null)
{
try
{
hr = graphBuilder.Render(outPin);
DsError.ThrowExceptionForHR(hr);
}
finally
{
if (outPin != null)
Marshal.ReleaseComObject(outPin);
outPin = null;
}
outPin = DsFindPin.ByConnectionStatus(sourceFilter, PinConnectedStatus.Unconnected, 0);
}
if (ps.MultiChannelWMA)
{
示例6: CreateSourceFilter
/// <summary>
/// Create our RTSP source filter and load the
/// RTSP source url
/// </summary>
/// <param name="pGraph">The graph the filter will live in</param>
/// <param name="url">The URL to load into the filter</param>
/// <returns></returns>
private IBaseFilter CreateSourceFilter(IGraphBuilder pGraph, string url)
{
//var clsidRTSPFilter = new Guid("{B3F5D418-CDB1-441C-9D6D-2063D5538962}"); //RTSPSource.ax
//var pRTSPFilter2 = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(clsidRTSPFilter));
//int hr = pGraph.AddFilter(pRTSPFilter2, "RTSP Filter");
//CheckHr(hr, "Can't add RTSP Filter to graph");
////set source filename
//var pRTSPFilter2Src = pRTSPFilter2 as IFileSourceFilter;
//if (pRTSPFilter2Src == null)
// CheckHr(unchecked((int)0x80004002), "Can't get IFileSourceFilter");
//if (pRTSPFilter2Src != null)
// hr = pRTSPFilter2Src.Load(url, null);
//CheckHr(hr, "Can't load file");
//Filter = true;
IBaseFilter pSourceFilter2;
int hr = pGraph.AddSourceFilter(url, "SourceFilter", out pSourceFilter2);
CheckHr(hr, "Can't add source Filter to graph for url="+url);
return pSourceFilter2;
}
示例7: Form1_Load
private void Form1_Load(object sender, EventArgs e)
{
m_PictureReady = new ManualResetEvent(false);
// ¨PlayMovieInWindow( "c:\\temp\\beckscen2.avi" );
int hr;
this.graphBuilder = (IGraphBuilder)new FilterGraph();
// this.graphBuilder.AddFilter(
// Get the SampleGrabber interface
ISampleGrabber sampGrabber = new SampleGrabber() as ISampleGrabber;
IBaseFilter ibfRenderer = null;
IBaseFilter capFilter = null;
IPin iPinInFilter = null;
IPin iPinOutFilter = null;
IPin iPinInDest = null;
// Add the video source
hr = graphBuilder.AddSourceFilter(Filename, "Ds.NET FileFilter", out capFilter);
DsError.ThrowExceptionForHR(hr);
// Hopefully this will be the video pin
IPin iPinOutSource = DsFindPin.ByDirection(capFilter, PinDirection.Output, 0);
IBaseFilter baseGrabFlt = sampGrabber as IBaseFilter;
ConfigureSampleGrabber(sampGrabber);
iPinInFilter = DsFindPin.ByDirection(baseGrabFlt, PinDirection.Input, 0);
iPinOutFilter = DsFindPin.ByDirection(baseGrabFlt, PinDirection.Output, 0);
// Add the frame grabber to the graph
hr = graphBuilder.AddFilter(baseGrabFlt, "Ds.NET Grabber");
DsError.ThrowExceptionForHR(hr);
hr = graphBuilder.Connect(iPinOutSource, iPinInFilter);
DsError.ThrowExceptionForHR(hr);
// Get the default video renderer
ibfRenderer = (IBaseFilter)new VideoRendererDefault();
// Add it to the graph
hr = graphBuilder.AddFilter(ibfRenderer, "Ds.NET VideoRendererDefault");
DsError.ThrowExceptionForHR(hr);
iPinInDest = DsFindPin.ByDirection(ibfRenderer, PinDirection.Input, 0);
// Connect the graph. Many other filters automatically get added here
hr = graphBuilder.Connect(iPinOutFilter, iPinInDest);
DsError.ThrowExceptionForHR(hr);
this.mediaControl = (IMediaControl)this.graphBuilder;
this.mediaEventEx = (IMediaEventEx)this.graphBuilder;
this.mediaSeeking = (IMediaSeeking)this.graphBuilder;
this.mediaPosition = (IMediaPosition)this.graphBuilder;
this.videoWindow = this.graphBuilder as IVideoWindow;
this.basicVideo = this.graphBuilder as IBasicVideo;
this.basicAudio = this.graphBuilder as IBasicAudio;
hr = this.videoWindow.put_Owner(panel1.Handle);
DsError.ThrowExceptionForHR(hr);
hr = this.videoWindow.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipSiblings | WindowStyle.ClipChildren);
DsError.ThrowExceptionForHR(hr);
if (this.basicVideo == null)
return;
int lHeight, lWidth;
hr = this.basicVideo.GetVideoSize(out lWidth, out lHeight);
Console.WriteLine("video: %d x %d\n", lWidth, lHeight);
m_videoWidth = lWidth;
m_videoHeight = lHeight;
SaveSizeInfo(sampGrabber);
newbitmap = new Bitmap(lWidth, lHeight, PixelFormat.Format24bppRgb);
origbitmap = new Bitmap(lWidth, lHeight, PixelFormat.Format24bppRgb);
m_ImageChanged = true;
pictureBox1.Width = lWidth;
pictureBox1.Height = lHeight;
pictureBox2.Width = lWidth;
pictureBox2.Height = lHeight;
pictureBox2.Top = pictureBox1.Top + lHeight + 4;
duration = 0.0f;
this.mediaPosition.get_Duration(out duration);
m_ipBuffer = Marshal.AllocCoTaskMem(Math.Abs(m_stride) * m_videoHeight);
// this.ClientSize = new Size(lWidth, lHeight);
Application.DoEvents();
hr = this.videoWindow.SetWindowPosition(0, 0, panel1.Width, panel1.Height);
this.mediaControl.Run();
timer1.Enabled = true;
// buildCaptureGRaph( this.de ( (capDevices[iDeviceNum], iWidth, iHeight, iBPP, hControl);
//.........这里部分代码省略.........