本文整理汇总了C#中IFilterGraph2.Render方法的典型用法代码示例。如果您正苦于以下问题:C# IFilterGraph2.Render方法的具体用法?C# IFilterGraph2.Render怎么用?C# IFilterGraph2.Render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFilterGraph2
的用法示例。
在下文中一共展示了IFilterGraph2.Render方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConnectAllOutputFiltersFrom
protected virtual void ConnectAllOutputFiltersFrom(IBaseFilter fromFilter, IFilterGraph2 graph)
{
// Get the pin enumerator
IEnumPins ppEnum;
int hr = fromFilter.EnumPins(out ppEnum);
DsError.ThrowExceptionForHR(hr);
try
{
// Walk the pins looking for a match
IPin[] pPins = new IPin[1];
//22 int lFetched;
//22 while ((ppEnum.Next(1, pPins, out lFetched) >= 0) && (lFetched == 1))
while (ppEnum.Next(1, pPins, IntPtr.Zero) >= 0)
{
// Read the direction
PinDirection ppindir;
hr = pPins[0].QueryDirection(out ppindir);
DsError.ThrowExceptionForHR(hr);
// Is it the right direction?
if (ppindir == PinDirection.Output)
{
if (pPins[0] != null)
{
hr = graph.Render(pPins[0]);
//DsError.ThrowExceptionForHR(hr);
}
}
Marshal.ReleaseComObject(pPins[0]);
}
}
finally
{
Marshal.ReleaseComObject(ppEnum);
}
}
示例2: SetupGraph
private void SetupGraph(Control hWin)
{
if (theCaptureDevice == null) return;
int hr;
IBaseFilter ibfRenderer = null;
ISampleGrabber sampGrabber = null;
IBaseFilter capFilter = null;
IPin iPinInFilter = null;
IPin iPinOutFilter = null;
IPin iPinInDest = null;
// Get the graphbuilder object
m_FilterGraph = new FilterGraph() as IFilterGraph2;
try
{
// Add the video input device to the graph
hr = m_FilterGraph.AddFilter(theCaptureDevice, "source filter");
DsError.ThrowExceptionForHR(hr);
if (captureDeviceCrossbar != null)
{
// Add the video inputs' crossbar to the graph
hr = m_FilterGraph.AddFilter(captureDeviceCrossbar, "source crossbar");
DsError.ThrowExceptionForHR(hr);
//// Get crossbars's output
IPin iPinOutCrossbar = DsFindPin.ByDirection(captureDeviceCrossbar, PinDirection.Output, 0);
m_FilterGraph.Render(iPinOutCrossbar);
}
// Get input device's output
iPinOutSource = DsFindPin.ByDirection(theCaptureDevice, PinDirection.Output, 0);
ibfRenderer = (IBaseFilter)new VideoRendererDefault();
// Add it to the graph
hr = m_FilterGraph.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 = m_FilterGraph.Connect(iPinOutSource, iPinInDest);
DsError.ThrowExceptionForHR(hr);
IVideoWindow videoWindow = m_FilterGraph as IVideoWindow;
hr = videoWindow.put_Owner(hWin.Handle);
DsError.ThrowExceptionForHR(hr);
hr = videoWindow.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipChildren | WindowStyle.ClipSiblings);
DsError.ThrowExceptionForHR(hr);
hr = videoWindow.put_Visible(OABool.True);
DsError.ThrowExceptionForHR(hr);
Rectangle rc = hWin.ClientRectangle;
hr = videoWindow.SetWindowPosition(0, 0, rc.Right, rc.Bottom);
DsError.ThrowExceptionForHR(hr);
}
finally
{
if (theCaptureDevice != null)
{
Marshal.ReleaseComObject(theCaptureDevice);
theCaptureDevice = null;
}
if (capFilter != null)
{
Marshal.ReleaseComObject(capFilter);
capFilter = null;
}
if (sampGrabber != null)
{
Marshal.ReleaseComObject(sampGrabber);
sampGrabber = null;
}
if (ibfRenderer != null)
{
Marshal.ReleaseComObject(ibfRenderer);
ibfRenderer = null;
}
if (iPinInFilter != null)
{
Marshal.ReleaseComObject(iPinInFilter);
iPinInFilter = null;
}
if (iPinOutFilter != null)
{
Marshal.ReleaseComObject(iPinOutFilter);
iPinOutFilter = null;
}
if (iPinInDest != null)
{
Marshal.ReleaseComObject(iPinInDest);
iPinInDest = null;
}
}
}
示例3: Play
public bool Play(string fileName, Form form)
{
_form = form;
Log.WriteFile("play:{0}", fileName);
_graphBuilder = (IFilterGraph2)new FilterGraph();
_rotEntry = new DsROTEntry(_graphBuilder);
TsReader reader = new TsReader();
_tsReader = (IBaseFilter)reader;
Log.Info("TSReaderPlayer:add TsReader to graph");
_graphBuilder.AddFilter(_tsReader, "TsReader");
#region load file in TsReader
Log.WriteFile("load file in Ts");
IFileSourceFilter interfaceFile = (IFileSourceFilter)_tsReader;
if (interfaceFile == null)
{
Log.WriteFile("TSReaderPlayer:Failed to get IFileSourceFilter");
return false;
}
int hr = interfaceFile.Load(fileName, null);
if (hr != 0)
{
Log.WriteFile("TSReaderPlayer:Failed to load file");
return false;
}
#endregion
#region render pin
Log.Info("TSReaderPlayer:render TsReader outputs");
IEnumPins enumPins;
_tsReader.EnumPins(out enumPins);
IPin[] pins = new IPin[2];
int fetched;
while (enumPins.Next(1, pins, out fetched) == 0)
{
if (fetched != 1) break;
PinDirection direction;
pins[0].QueryDirection(out direction);
if (direction == PinDirection.Input)
{
Release.ComObject(pins[0]);
continue;
}
_graphBuilder.Render(pins[0]);
Release.ComObject(pins[0]);
}
Release.ComObject(enumPins);
#endregion
_videoWin = _graphBuilder as IVideoWindow;
if (_videoWin != null)
{
_videoWin.put_Visible(OABool.True);
_videoWin.put_Owner(form.Handle);
_videoWin.put_WindowStyle(
(WindowStyle)((int)WindowStyle.Child + (int)WindowStyle.ClipSiblings + (int)WindowStyle.ClipChildren));
_videoWin.put_MessageDrain(form.Handle);
_videoWin.SetWindowPosition(form.ClientRectangle.X, form.ClientRectangle.Y, form.ClientRectangle.Width,
form.ClientRectangle.Height);
}
Log.WriteFile("run graph");
_mediaCtrl = (IMediaControl)_graphBuilder;
hr = _mediaCtrl.Run();
Log.WriteFile("TSReaderPlayer:running:{0:X}", hr);
return true;
}
示例4: Play
//.........这里部分代码省略.........
mpeg2ProgramStream.unkPtr = IntPtr.Zero;
mpeg2ProgramStream.sampleSize = 0;
mpeg2ProgramStream.temporalCompression = false;
mpeg2ProgramStream.fixedSizeSamples = true;
mpeg2ProgramStream.formatType = FormatType.None;
mpeg2ProgramStream.formatSize = 0;
mpeg2ProgramStream.formatPtr = IntPtr.Zero;
hr = interfaceFile.Load(fileName, mpeg2ProgramStream);
if (hr != 0)
{
Log.WriteFile("TSStreamBufferPlayer9:Failed to load file");
return false;
}
#region connect tsfilesource->demux
Log.WriteFile("connect tsfilesource->demux");
Log.WriteFile("TSStreamBufferPlayer9:connect tsfilesource->mpeg2 demux");
IPin pinTsOut = DsFindPin.ByDirection((IBaseFilter)_tsFileSource, PinDirection.Output, 0);
if (pinTsOut == null)
{
Log.WriteFile("TSStreamBufferPlayer9:failed to find output pin of tsfilesource");
return false;
}
IPin pinDemuxIn = DsFindPin.ByDirection(_mpegDemux, PinDirection.Input, 0);
if (pinDemuxIn == null)
{
Log.WriteFile("TSStreamBufferPlayer9:failed to find output pin of tsfilesource");
return false;
}
hr = _graphBuilder.Connect(pinTsOut, pinDemuxIn);
if (hr != 0)
{
Log.WriteFile("TSStreamBufferPlayer9:failed to connect tsfilesource->mpeg2 demux:{0:X}", hr);
return false;
}
Release.ComObject(pinTsOut);
Release.ComObject(pinDemuxIn);
#endregion
#region map demux pids
Log.WriteFile("map mpeg2 pids");
IMPEG2StreamIdMap pStreamId = (IMPEG2StreamIdMap)_pinVideo;
hr = pStreamId.MapStreamId(0xe0, MPEG2Program.ElementaryStream, 0, 0);
if (hr != 0)
{
Log.WriteFile("TSStreamBufferPlayer9: failed to map pid 0xe0->video pin");
return false;
}
pStreamId = (IMPEG2StreamIdMap)_pinAudio;
hr = pStreamId.MapStreamId(0xc0, MPEG2Program.ElementaryStream, 0, 0);
if (hr != 0)
{
Log.WriteFile("TSStreamBufferPlayer9: failed to map pid 0xc0->audio pin");
return false;
}
#endregion
#region render demux audio/video pins
Log.WriteFile("render pins");
hr = _graphBuilder.Render(_pinAudio);
if (hr != 0)
{
Log.WriteFile("TSStreamBufferPlayer9:failed to render video output pin:{0:X}", hr);
}
hr = _graphBuilder.Render(_pinVideo);
if (hr != 0)
{
Log.WriteFile("TSStreamBufferPlayer9:failed to render audio output pin:{0:X}", hr);
}
#endregion
#endregion
_videoWin = _graphBuilder as IVideoWindow;
if (_videoWin != null)
{
_videoWin.put_Visible(OABool.True);
_videoWin.put_Owner(form.Handle);
_videoWin.put_WindowStyle(
(WindowStyle)((int)WindowStyle.Child + (int)WindowStyle.ClipSiblings + (int)WindowStyle.ClipChildren));
_videoWin.put_MessageDrain(form.Handle);
_videoWin.SetWindowPosition(190, 250, 150, 150);
}
Log.WriteFile("run graph");
_mediaCtrl = (IMediaControl)_graphBuilder;
hr = _mediaCtrl.Run();
Log.WriteFile("TSStreamBufferPlayer9:running:{0:X}", hr);
return true;
}
示例5: Play
public bool Play(string fileName, Control parent, out string ErrorOrSplitter)
{
ErrorOrSplitter = "";
int hr;
_parentControl = parent;
_graphBuilder = (IFilterGraph2)new FilterGraph();
_rotEntry = new DsROTEntry(_graphBuilder);
// add the video renderer (evr does not seem to work here)
IBaseFilter vmr9Renderer = DirectShowUtil.AddFilterToGraph(_graphBuilder, "Video Mixing Renderer 9");
((IVMRAspectRatioControl9)vmr9Renderer).SetAspectRatioMode(VMRAspectRatioMode.LetterBox);
DirectShowUtil.ReleaseComObject(vmr9Renderer, 2000);
// add the audio renderer
IBaseFilter audioRenderer = DirectShowUtil.AddAudioRendererToGraph(_graphBuilder, MPSettings.Instance.GetValueAsString("movieplayer", "audiorenderer", "Default DirectSound Device"), false);
DirectShowUtil.ReleaseComObject(audioRenderer, 2000);
// add the source filter
string sourceFilterName = OnlineVideos.MediaPortal1.Player.OnlineVideosPlayer.GetSourceFilterName(fileName);
if (string.IsNullOrEmpty(sourceFilterName)) return false;
IBaseFilter sourceFilter = null;
try
{
sourceFilter = DirectShowUtil.AddFilterToGraph(_graphBuilder, sourceFilterName);
}
catch (Exception ex)
{
ErrorOrSplitter = ex.Message;
return false;
}
hr = ((IFileSourceFilter)sourceFilter).Load(fileName, null);
if (hr != 0)
{
ErrorOrSplitter = DirectShowLib.DsError.GetErrorText(hr);
DirectShowUtil.ReleaseComObject(sourceFilter, 2000);
return false;
}
// wait for our filter to buffer before rendering the pins
OnlineVideos.MPUrlSourceFilter.IFilterState filterState = sourceFilter as OnlineVideos.MPUrlSourceFilter.IFilterState;
if (filterState != null)
{
bool ready = false;
while ((!ready) && (hr == 0))
{
hr = filterState.IsFilterReadyToConnectPins(out ready);
System.Threading.Thread.Sleep(25);
}
}
if (hr != 0)
{
ErrorOrSplitter = DirectShowLib.DsError.GetErrorText(hr);
DirectShowUtil.ReleaseComObject(sourceFilter, 2000);
return false;
}
OnlineVideos.MediaPortal1.Player.OnlineVideosPlayer.AddPreferredFilters(_graphBuilder, sourceFilter);
// try to connect the filters
int numConnected = 0;
IEnumPins pinEnum;
hr = sourceFilter.EnumPins(out pinEnum);
if ((hr == 0) && (pinEnum != null))
{
pinEnum.Reset();
IPin[] pins = new IPin[1];
int iFetched;
int iPinNo = 0;
do
{
iPinNo++;
hr = pinEnum.Next(1, pins, out iFetched);
if (hr == 0)
{
if (iFetched == 1 && pins[0] != null)
{
PinDirection pinDir;
pins[0].QueryDirection(out pinDir);
if (pinDir == PinDirection.Output)
{
hr = _graphBuilder.Render(pins[0]);
if (hr == 0)
{
numConnected++;
IPin connectedPin;
if (pins[0].ConnectedTo(out connectedPin) == 0 && connectedPin != null)
{
PinInfo connectedPinInfo;
connectedPin.QueryPinInfo(out connectedPinInfo);
FilterInfo connectedFilterInfo;
connectedPinInfo.filter.QueryFilterInfo(out connectedFilterInfo);
DirectShowUtil.ReleaseComObject(connectedPin, 2000);
IBaseFilter connectedFilter;
//.........这里部分代码省略.........
示例6: Initialize
public bool Initialize(string n, string p, string t)
{
int hr = 0;
path = p;
name = n;
textureName = t;
if (textureName == null)
{
textureName = Manager.TextureName(this);
}
log.InfoFormat("DirectShowCodec[{0}] Initialize: {1} ({2}), texture '{3}'", ID(), name, path, textureName);
// check for DirectX-ness
if (!(Root.Instance.RenderSystem is Axiom.RenderSystems.DirectX9.D3D9RenderSystem))
{
throw new Exception("DirectShow movie codec is DirectX only");
}
if ((Root.Instance.RenderSystem as D3D9RenderSystem).PrimaryWindow == null)
{
throw new Exception("Initializing before primary window has been created");
}
D3DRenderWindow rw = (Root.Instance.RenderSystem as D3D9RenderSystem).PrimaryWindow;
// Create a DirectShow FilterGraph
graphBuilder = (IFilterGraph2)new FilterGraph();
// Add it in ROT for debug purpose
rot = new DsROTEntry(graphBuilder);
// Create a VMR9 object
vmr9 = (IBaseFilter)new VideoMixingRenderer9();
IVMRFilterConfig9 filterConfig = (IVMRFilterConfig9)vmr9;
// We want the Renderless mode!
hr = filterConfig.SetRenderingMode(VMR9Mode.Renderless);
DsError.ThrowExceptionForHR(hr);
// One stream is enough for this sample
hr = filterConfig.SetNumberOfStreams(1);
DsError.ThrowExceptionForHR(hr);
// Create the Allocator / Presenter object
Device device = (Device)rw.GetCustomAttribute("D3DDEVICE");
allocator = new DirectShowAllocator(device, ID(), TextureName());
IVMRSurfaceAllocatorNotify9 vmrSurfAllocNotify = (IVMRSurfaceAllocatorNotify9)vmr9;
// Notify the VMR9 filter about our allocator
hr = vmrSurfAllocNotify.AdviseSurfaceAllocator(IntPtr.Zero, allocator);
DsError.ThrowExceptionForHR(hr);
// Notify our allocator about the VMR9 filter
hr = allocator.AdviseNotify(vmrSurfAllocNotify);
DsError.ThrowExceptionForHR(hr);
IVMRMixerControl9 mixerControl = (IVMRMixerControl9)vmr9;
// Select the mixer mode : YUV or RGB
hr = mixerControl.SetMixingPrefs(VMR9MixerPrefs.RenderTargetYUV | VMR9MixerPrefs.NoDecimation | VMR9MixerPrefs.ARAdjustXorY | VMR9MixerPrefs.BiLinearFiltering);
DsError.ThrowExceptionForHR(hr);
// Add the VMR-9 filter to the graph
hr = graphBuilder.AddFilter(vmr9, "Video Mixing Renderer 9");
DsError.ThrowExceptionForHR(hr);
bool shouldStream = false;
string url = path;
#if false
int maxRedirects = DirectShowWebReader.MAX_REDIRECTS;
DirectShowWebReader reader = null;
while (maxRedirects != 0)
{
if (url.StartsWith("http://") || url.StartsWith("https://"))
{
try
{
// Start reading the data
reader = new DirectShowWebReader();
hr = reader.Load(url);
DsError.ThrowExceptionForHR(hr);
shouldStream = true;
break;
}
catch (DirectShowWebReader.RedirectException e)
{
log.Info("Redirect to (" + e.url + ")");
url = e.url;
maxRedirects--;
reader = null;
}
}
else
{
shouldStream = false;
reader = null;
break;
}
}
//.........这里部分代码省略.........
示例7: SetupGraph
private void SetupGraph(Control hWin)
{
if (theCaptureDevice == null) return;
int hr;
IBaseFilter ibfRenderer = null;
ISampleGrabber sampGrabber = null;
IBaseFilter capFilter = null;
IPin iPinInFilter = null;
IPin iPinOutFilter = null;
IPin iPinInDest = null;
// Get the graphbuilder object
m_FilterGraph = new FilterGraph() as IFilterGraph2;
//#if DEBUG
// m_rot = new DsROTEntry(m_FilterGraph);
//#endif
try
{
// Add the video input device to the graph
hr = m_FilterGraph.AddFilter(theCaptureDevice, "source filter");
DsError.ThrowExceptionForHR(hr);
if (captureDeviceCrossbar != null)
{
// Add the video inputs' crossbar to the graph
hr = m_FilterGraph.AddFilter(captureDeviceCrossbar, "source crossbar");
DsError.ThrowExceptionForHR(hr);
//// Get crossbars's output
IPin iPinOutCrossbar = DsFindPin.ByDirection(captureDeviceCrossbar, PinDirection.Output, 0);
m_FilterGraph.Render(iPinOutCrossbar);
}
// Get input device's output
iPinOutSource = DsFindPin.ByDirection(theCaptureDevice, PinDirection.Output, 0);
//DisplayPropertyPageForCapturePin(IntPtr.Zero);
//m_FilterGraph.Render(iPinOutSource);
//// Get the SampleGrabber interface
//sampGrabber = new SampleGrabber() as ISampleGrabber;
//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 = m_FilterGraph.AddFilter(baseGrabFlt, "Ds.NET Grabber");
//DsError.ThrowExceptionForHR(hr);
//hr = m_FilterGraph.Connect(iPinOutSource, iPinInFilter);
//DsError.ThrowExceptionForHR(hr);
//m_FilterGraph.Render(iPinOutSource);
ibfRenderer = (IBaseFilter)new VideoRendererDefault();
// Add it to the graph
hr = m_FilterGraph.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 = m_FilterGraph.Connect(iPinOutSource, iPinInDest);
DsError.ThrowExceptionForHR(hr);
IVideoWindow videoWindow = m_FilterGraph as IVideoWindow;
hr = videoWindow.put_Owner(hWin.Handle);
DsError.ThrowExceptionForHR(hr);
hr = videoWindow.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipChildren | WindowStyle.ClipSiblings);
DsError.ThrowExceptionForHR(hr);
hr = videoWindow.put_Visible(OABool.True);
DsError.ThrowExceptionForHR(hr);
Rectangle rc = hWin.ClientRectangle;
hr = videoWindow.SetWindowPosition(0, 0, rc.Right, rc.Bottom);
DsError.ThrowExceptionForHR(hr);
//// Add the video source
////hr = m_FilterGraph.AddSourceFilter(FileName, "Ds.NET FileFilter", out capFilter);
////DsError.ThrowExceptionForHR(hr);
//// Hopefully this will be the video pin
//IPin iPinOutSource = DsFindPin.ByDirection(theCaptureDevice, 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 = m_FilterGraph.AddFilter(baseGrabFlt, "Ds.NET Grabber");
//DsError.ThrowExceptionForHR(hr);
//.........这里部分代码省略.........