本文整理汇总了C#中IFilterGraph2.Connect方法的典型用法代码示例。如果您正苦于以下问题:C# IFilterGraph2.Connect方法的具体用法?C# IFilterGraph2.Connect怎么用?C# IFilterGraph2.Connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFilterGraph2
的用法示例。
在下文中一共展示了IFilterGraph2.Connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConnectFilter
private static bool ConnectFilter(IFilterGraph2 graphBuilder, IBaseFilter networkFilter, IBaseFilter tunerFilter)
{
IPin pinOut = DsFindPin.ByDirection(networkFilter, PinDirection.Output, 0);
IPin pinIn = DsFindPin.ByDirection(tunerFilter, PinDirection.Input, 0);
int hr = graphBuilder.Connect(pinOut, pinIn);
return (hr == 0);
}
示例2: SetupGraph
/// <summary> build the capture graph for grabber. </summary>
private void SetupGraph(DsDevice dev, int iSampleRate, int iChannels)
{
int hr;
ISampleGrabber sampGrabber = null;
IBaseFilter capFilter = null;
ICaptureGraphBuilder2 capGraph = null;
IBaseFilter baseGrabFlt = null;
IBaseFilter nullrenderer = null;
IMediaFilter mediaFilt = m_FilterGraph as IMediaFilter;
// Get the graphbuilder object
m_FilterGraph = (IFilterGraph2)new FilterGraph();
m_mediaCtrl = m_FilterGraph as IMediaControl;
try {
// Get the ICaptureGraphBuilder2
capGraph = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
// Get the SampleGrabber interface
sampGrabber = (ISampleGrabber)new SampleGrabber();
// Start building the graph
hr = capGraph.SetFiltergraph(m_FilterGraph);
DsError.ThrowExceptionForHR(hr);
// Add the audio device
hr = m_FilterGraph.AddSourceFilterForMoniker(dev.Mon, null, "Audio input", out capFilter);
DsError.ThrowExceptionForHR(hr);
// If any of the default config items are set
if (iSampleRate + iChannels > 0) {
SetConfigParms(capGraph, capFilter, iSampleRate, iChannels);
}
// Get the SampleGrabber interface
sampGrabber = new SampleGrabber() as ISampleGrabber;
baseGrabFlt = sampGrabber as IBaseFilter;
ConfigureSampleGrabber(sampGrabber);
// Add the frame grabber to the graph
hr = m_FilterGraph.AddFilter(baseGrabFlt, "Ds.NET Grabber");
DsError.ThrowExceptionForHR(hr);
// ---------------------------------
// Connect the file filter to the sample grabber
// Hopefully this will be the audio pin, we could check by reading it's mediatype
IPin iPinOut = DsFindPin.ByDirection(capFilter, PinDirection.Output, 0);
// Get the input pin from the sample grabber
IPin iPinIn = DsFindPin.ByDirection(baseGrabFlt, PinDirection.Input, 0);
hr = m_FilterGraph.Connect(iPinOut, iPinIn);
DsError.ThrowExceptionForHR(hr);
// Add the null renderer to the graph
nullrenderer = new NullRenderer() as IBaseFilter;
hr = m_FilterGraph.AddFilter(nullrenderer, "Null renderer");
DsError.ThrowExceptionForHR(hr);
// ---------------------------------
// Connect the sample grabber to the null renderer
iPinOut = DsFindPin.ByDirection(baseGrabFlt, PinDirection.Output, 0);
iPinIn = DsFindPin.ByDirection(nullrenderer, PinDirection.Input, 0);
hr = m_FilterGraph.Connect(iPinOut, iPinIn);
DsError.ThrowExceptionForHR(hr);
// Read and cache the resulting settings
SaveSizeInfo(sampGrabber);
} finally {
if (capFilter != null) {
Marshal.ReleaseComObject(capFilter);
capFilter = null;
}
if (sampGrabber != null) {
Marshal.ReleaseComObject(sampGrabber);
sampGrabber = null;
}
if (capGraph != null) {
Marshal.ReleaseComObject(capGraph);
capGraph = null;
}
}
}
示例3: 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;
}
}
}
示例4: SetupGraph
// Build the capture graph for grabber and renderer.</summary>
// (Control to show video in, Filename to play)
private void SetupGraph(Control hWin, string FileName)
{
int hr;
IBaseFilter ibfRenderer = null;
IPin iPinInFilter = null;
IPin iPinOutFilter = null;
IPin iPinInDest = null;
m_FilterGraph = new FilterGraph() as IFilterGraph2;
ICaptureGraphBuilder2 icgb2 = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;
try
{
hr = icgb2.SetFiltergraph(m_FilterGraph);
DsError.ThrowExceptionForHR(hr);
IBaseFilter sourceFilter = null;
hr = m_FilterGraph.AddSourceFilter(FileName, "Ds.NET FileFilter", out sourceFilter);
DsError.ThrowExceptionForHR(hr);
// Hopefully this will be the video pin
IPin iPinOutSource = DsFindPin.ByDirection(sourceFilter, PinDirection.Output, 0);
// Get the SampleGrabber interface
m_sampGrabber = (ISampleGrabber)new SampleGrabber();
IBaseFilter baseGrabFlt = (IBaseFilter)m_sampGrabber;
// Configure the Sample Grabber
ConfigureSampleGrabber(m_sampGrabber);
iPinInFilter = DsFindPin.ByDirection(baseGrabFlt, PinDirection.Input, 0);
iPinOutFilter = DsFindPin.ByDirection(baseGrabFlt, PinDirection.Output, 0);
// Add it to the filter
hr = m_FilterGraph.AddFilter(baseGrabFlt, "Ds.NET Grabber");
DsError.ThrowExceptionForHR(hr);
hr = m_FilterGraph.Connect(iPinOutSource, iPinInFilter);
DsError.ThrowExceptionForHR(hr);
// Get the default video renderer
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(iPinOutFilter, iPinInDest);
DsError.ThrowExceptionForHR(hr);
// Configure the Video Window
IVideoWindow videoWindow = m_FilterGraph as IVideoWindow;
ConfigureVideoWindow(videoWindow, hWin);
// Grab some other interfaces
m_mediaEvent = m_FilterGraph as IMediaEvent;
m_mediaCtrl = m_FilterGraph as IMediaControl;
m_mediaPosition = m_FilterGraph as IMediaPosition;
}
finally
{
if (icgb2 != null)
{
Marshal.ReleaseComObject(icgb2);
icgb2 = null;
}
}
}
示例5: PrepareCapture
public void PrepareCapture(int i_width, int i_height,float i_frame_rate)
{
const int BBP = 32;
//既にキャプチャ中なら諦める。
if (this.m_graphi_active)
{
throw new Exception();
}
//現在確保中のグラフインスタンスを全て削除
CleanupGraphiObjects();
int hr;
ISampleGrabber sampGrabber = null;
IBaseFilter capFilter = null;
IPin pSampleIn = null;
//グラフビルダを作る。
this.m_FilterGraph = new FilterGraph() as IFilterGraph2;
try
{
//フィルタグラフにキャプチャを追加して、capFilterにピンを受け取る。
hr = m_FilterGraph.AddSourceFilterForMoniker(this.m_dev.Mon, null, this.m_dev.Name, out capFilter);
DsError.ThrowExceptionForHR(hr);
//stillピンを探す
m_pinStill = DsFindPin.ByCategory(capFilter, PinCategory.Still, 0);
//stillピンが無ければPreviewを探す。
if (m_pinStill == null)
{
m_pinStill = DsFindPin.ByCategory(capFilter, PinCategory.Preview, 0);
}
// Still haven't found one. Need to put a splitter in so we have
// one stream to capture the bitmap from, and one to display. Ok, we
// don't *have* to do it that way, but we are going to anyway.
if (m_pinStill == null)
{
// There is no still pin
m_VidControl = null;
m_pinStill = DsFindPin.ByCategory(capFilter, PinCategory.Capture, 0);
}else{
// Get a control pointer (used in Click())
m_VidControl = capFilter as IAMVideoControl;
m_pinStill = DsFindPin.ByCategory(capFilter, PinCategory.Capture, 0);
}
if (i_height + i_width + BBP > 0)
{
SetConfigParms(m_pinStill, i_width, i_height,i_frame_rate, BBP);
}
// Get the SampleGrabber interface
sampGrabber = new SampleGrabber() as ISampleGrabber;
//sampGrabberの設定
IBaseFilter baseGrabFlt = sampGrabber as IBaseFilter;
ConfigureSampleGrabber(sampGrabber);
pSampleIn = DsFindPin.ByDirection(baseGrabFlt, PinDirection.Input, 0);
// Add the sample grabber to the graph
hr = m_FilterGraph.AddFilter(baseGrabFlt, "Ds.NET Grabber");
DsError.ThrowExceptionForHR(hr);
if (m_VidControl == null)
{
// Connect the Still pin to the sample grabber
hr = m_FilterGraph.Connect(m_pinStill, pSampleIn);
DsError.ThrowExceptionForHR(hr);
}else{
// Connect the Still pin to the sample grabber
hr = m_FilterGraph.Connect(m_pinStill, pSampleIn);
DsError.ThrowExceptionForHR(hr);
}
hr = sampGrabber.GetConnectedMediaType(this._capture_mediatype);
DsError.ThrowExceptionForHR(hr);
//ビデオフォーマット等の更新
upateVideoInfo(sampGrabber);
}
finally
{
if (sampGrabber != null)
{
Marshal.ReleaseComObject(sampGrabber);
sampGrabber = null;
}
if (pSampleIn != null)
{
Marshal.ReleaseComObject(pSampleIn);
pSampleIn = null;
}
}
}
示例6: CreateFilterInstance
/// <summary>
/// Creates the teletext component in the graph. First we try to use the stored informations in the graph
/// </summary>
/// <param name="graph">The stored graph</param>
/// <param name="graphBuilder">The graphbuilder</param>
/// <param name="capture">The capture component</param>
/// <returns>true, if the building was successful; false otherwise</returns>
public bool CreateFilterInstance(Graph graph, IFilterGraph2 graphBuilder, Capture capture)
{
Log.Log.WriteFile("analog: SetupTeletext()");
Guid guidBaseFilter = typeof (IBaseFilter).GUID;
object obj;
//find and add tee/sink to sink filter
DsDevice[] devices = DsDevice.GetDevicesOfCat(FilterCategory.AMKSSplitter);
devices[0].Mon.BindToObject(null, null, ref guidBaseFilter, out obj);
_teeSink = (IBaseFilter)obj;
int hr = graphBuilder.AddFilter(_teeSink, devices[0].Name);
if (hr != 0)
{
Log.Log.Error("analog:SinkGraphEx.SetupTeletext(): Unable to add tee/sink filter");
return false;
}
//connect capture filter -> tee sink filter
IPin pin = DsFindPin.ByDirection(_teeSink, PinDirection.Input, 0);
hr = graphBuilder.Connect(capture.VBIPin, pin);
Release.ComObject(pin);
if (hr != 0)
{
//failed...
Log.Log.Error("analog: unable to connect capture->tee/sink");
graphBuilder.RemoveFilter(_teeSink);
Release.ComObject(_teeSink);
_teeSink = _filterWstDecoder = null;
return false;
}
if (!string.IsNullOrEmpty(graph.Teletext.Name))
{
Log.Log.WriteFile("analog: Using Teletext-Component configuration from stored graph");
devices = DsDevice.GetDevicesOfCat(graph.Teletext.Category);
foreach (DsDevice device in devices)
{
if (device.Name != null && device.Name.Equals(graph.Teletext.Name))
{
//found it, add it to the graph
Log.Log.Info("analog:Using teletext component - {0}", graph.Teletext.Name);
device.Mon.BindToObject(null, null, ref guidBaseFilter, out obj);
_filterWstDecoder = (IBaseFilter)obj;
hr = graphBuilder.AddFilter(_filterWstDecoder, device.Name);
if (hr != 0)
{
//failed...
Log.Log.Error("analog:SinkGraphEx.SetupTeletext(): Unable to add WST Codec filter");
graphBuilder.RemoveFilter(_filterWstDecoder);
_filterWstDecoder = null;
}
break;
}
}
}
if (_filterWstDecoder == null)
{
Log.Log.WriteFile("analog: No stored or invalid graph for Teletext component - Trying to detect");
//find the WST codec filter
devices = DsDevice.GetDevicesOfCat(FilterCategory.AMKSVBICodec);
foreach (DsDevice device in devices)
{
if (device.Name != null && device.Name.IndexOf("WST") >= 0)
{
//found it, add it to the graph
Log.Log.Info("analog:Found WST Codec filter");
device.Mon.BindToObject(null, null, ref guidBaseFilter, out obj);
_filterWstDecoder = (IBaseFilter)obj;
hr = graphBuilder.AddFilter(_filterWstDecoder, device.Name);
if (hr != 0)
{
//failed...
Log.Log.Error("analog:Unable to add WST Codec filter");
graphBuilder.RemoveFilter(_teeSink);
Release.ComObject(_teeSink);
_teeSink = _filterWstDecoder = null;
return false;
}
graph.Teletext.Name = device.Name;
graph.Teletext.Category = FilterCategory.AMKSVBICodec;
break;
}
}
//Look for VBI Codec for Vista users as Vista doesn't use WST Codec anymore
if (_filterWstDecoder == null)
{
devices = DsDevice.GetDevicesOfCat(FilterCategory.AMKSMULTIVBICodec);
foreach (DsDevice device in devices)
if (device.Name != null && device.Name.IndexOf("VBI") >= 0)
{
//found it, add it to the graph
Log.Log.Info("analog:Found VBI Codec filter");
device.Mon.BindToObject(null, null, ref guidBaseFilter, out obj);
_filterWstDecoder = (IBaseFilter)obj;
hr = graphBuilder.AddFilter(_filterWstDecoder, device.Name);
//.........这里部分代码省略.........
示例7: CreateAutomaticFilterInstance
/// <summary>
/// Creates the filter by trying to detect it
/// </summary>
/// <param name="crossbar">The crossbar componen</param>
/// <param name="tuner">The tuner component</param>
/// <param name="graph">The stored graph</param>
/// <param name="graphBuilder">The graphBuilder</param>
/// <returns>true, if the graph building was successful</returns>
private bool CreateAutomaticFilterInstance(Graph graph, Tuner tuner, Crossbar crossbar, IFilterGraph2 graphBuilder)
{
//get all tv audio tuner devices on this system
DsDevice[] devices = null;
try
{
devices = DsDevice.GetDevicesOfCat(FilterCategory.AMKSTVAudio);
devices = DeviceSorter.Sort(devices, tuner.TunerName, crossbar.CrossBarName);
}
catch (Exception)
{
Log.Log.WriteFile("analog: AddTvAudioFilter no tv audio devices found - Trying TvTuner filter");
}
if (devices != null && devices.Length > 0)
{
// try each tv audio tuner
for (int i = 0; i < devices.Length; i++)
{
IBaseFilter tmp;
Log.Log.WriteFile("analog: AddTvAudioFilter try:{0} {1}", devices[i].Name, i);
//if tv audio tuner is currently in use we can skip it
if (DevicesInUse.Instance.IsUsed(devices[i]))
continue;
int hr;
try
{
//add tv audio tuner to graph
hr = graphBuilder.AddSourceFilterForMoniker(devices[i].Mon, null, devices[i].Name, out tmp);
}
catch (Exception)
{
Log.Log.WriteFile("analog: cannot add filter to graph");
continue;
}
if (hr != 0)
{
//failed to add tv audio tuner to graph, continue with the next one
if (tmp != null)
{
graphBuilder.RemoveFilter(tmp);
Release.ComObject("tvAudioFilter filter", tmp);
}
continue;
}
// try connecting the tv tuner-> tv audio tuner
if (FilterGraphTools.ConnectPin(graphBuilder, tuner.AudioPin, tmp, 0))
{
// Got it !
// Connect tv audio tuner to the crossbar
IPin pin = DsFindPin.ByDirection(tmp, PinDirection.Output, 0);
hr = graphBuilder.Connect(pin, crossbar.AudioTunerIn);
if (hr < 0)
{
//failed
graphBuilder.RemoveFilter(tmp);
Release.ComObject("audiotuner pinin", pin);
Release.ComObject("audiotuner filter", tmp);
}
else
{
//succeeded. we're done
Log.Log.WriteFile("analog: AddTvAudioFilter succeeded:{0}", devices[i].Name);
Release.ComObject("audiotuner pinin", pin);
_filterTvAudioTuner = tmp;
_audioDevice = devices[i];
DevicesInUse.Instance.Add(_audioDevice);
_tvAudioTunerInterface = tuner.Filter as IAMTVAudio;
break;
}
}
else
{
// cannot connect tv tuner-> tv audio tuner, try next one...
graphBuilder.RemoveFilter(tmp);
Release.ComObject("audiotuner filter", tmp);
}
}
}
if (_filterTvAudioTuner == null)
{
Log.Log.WriteFile("analog: AddTvAudioFilter no tv audio devices found - Trying TvTuner filter");
int hr = graphBuilder.Connect(tuner.AudioPin, crossbar.AudioTunerIn);
if (hr != 0)
{
Log.Log.Error("analog: unable to add TvAudioTuner to graph - even TvTuner as TvAudio fails");
mode = TvAudioVariant.Unavailable;
}
else
{
Log.Log.WriteFile("analog: AddTvAudioFilter connected TvTuner with Crossbar directly succeeded!");
mode = TvAudioVariant.TvTunerConnection;
_tvAudioTunerInterface = tuner.Filter as IAMTVAudio;
//.........这里部分代码省略.........
示例8: SetupGraph
/// <summary> build the capture graph for grabber. </summary>
private void SetupGraph(string FileName)
{
int hr;
ISampleGrabber sampGrabber = null;
IBaseFilter baseGrabFlt = null;
IBaseFilter capFilter = null;
IBaseFilter nullrenderer = null;
// Get the graphbuilder object
m_FilterGraph = new FilterGraph() as IFilterGraph2;
m_mediaCtrl = m_FilterGraph as IMediaControl;
m_MediaEvent = m_FilterGraph as IMediaEvent;
IMediaFilter mediaFilt = m_FilterGraph as IMediaFilter;
try
{
#if DEBUG
m_rot = new DsROTEntry(m_FilterGraph);
#endif
// Add the video source
hr = m_FilterGraph.AddSourceFilter(FileName, "Ds.NET FileFilter", out capFilter);
DsError.ThrowExceptionForHR(hr);
// Get the SampleGrabber interface
sampGrabber = new SampleGrabber() as ISampleGrabber;
baseGrabFlt = sampGrabber as IBaseFilter;
ConfigureSampleGrabber(sampGrabber);
// Add the frame grabber to the graph
hr = m_FilterGraph.AddFilter(baseGrabFlt, "Ds.NET Grabber");
DsError.ThrowExceptionForHR(hr);
// ---------------------------------
// Connect the file filter to the sample grabber
// Hopefully this will be the video pin, we could check by reading it's mediatype
IPin iPinOut = DsFindPin.ByDirection(capFilter, PinDirection.Output, 0);
// Get the input pin from the sample grabber
IPin iPinIn = DsFindPin.ByDirection(baseGrabFlt, PinDirection.Input, 0);
hr = m_FilterGraph.Connect(iPinOut, iPinIn);
DsError.ThrowExceptionForHR(hr);
// Add the null renderer to the graph
nullrenderer = new NullRenderer() as IBaseFilter;
hr = m_FilterGraph.AddFilter(nullrenderer, "Null renderer");
DsError.ThrowExceptionForHR(hr);
// ---------------------------------
// Connect the sample grabber to the null renderer
iPinOut = DsFindPin.ByDirection(baseGrabFlt, PinDirection.Output, 0);
iPinIn = DsFindPin.ByDirection(nullrenderer, PinDirection.Input, 0);
hr = m_FilterGraph.Connect(iPinOut, iPinIn);
DsError.ThrowExceptionForHR(hr);
// Turn off the clock. This causes the frames to be sent
// thru the graph as fast as possible
hr = mediaFilt.SetSyncSource(null);
DsError.ThrowExceptionForHR(hr);
// Read and cache the image sizes
SaveSizeInfo(sampGrabber);
}
finally
{
if (capFilter != null)
{
Marshal.ReleaseComObject(capFilter);
capFilter = null;
}
if (sampGrabber != null)
{
Marshal.ReleaseComObject(sampGrabber);
sampGrabber = null;
}
if (nullrenderer != null)
{
Marshal.ReleaseComObject(nullrenderer);
nullrenderer = null;
}
}
}
示例9: AddMpeg2Demultiplexer
/// <summary>
/// Adds a mpeg2 demultiplexer to the graph
/// </summary>
/// <param name="_graphBuilder">The graph builder</param>
private void AddMpeg2Demultiplexer(IFilterGraph2 _graphBuilder)
{
Log.Log.WriteFile("analog: AddMpeg2Demultiplexer");
if (_filterMpeg2Demux != null)
return;
if (_pinCapture == null)
return;
_filterMpeg2Demux = (IBaseFilter)new MPEG2Demultiplexer();
int hr = _graphBuilder.AddFilter(_filterMpeg2Demux, "MPEG2 Demultiplexer");
if (hr != 0)
{
Log.Log.WriteFile("analog: AddMPEG2DemuxFilter returns:0x{0:X}", hr);
throw new TvException("Unable to add MPEG2 demultiplexer");
}
Log.Log.WriteFile("analog: connect capture->mpeg2 demux");
IPin pin = DsFindPin.ByDirection(_filterMpeg2Demux, PinDirection.Input, 0);
hr = _graphBuilder.Connect(_pinCapture, pin);
if (hr != 0)
{
Log.Log.WriteFile("analog: ConnectFilters returns:0x{0:X}", hr);
throw new TvException("Unable to connect capture-> MPEG2 demultiplexer");
}
IMpeg2Demultiplexer demuxer = (IMpeg2Demultiplexer)_filterMpeg2Demux;
demuxer.CreateOutputPin(FilterGraphTools.GetVideoMpg2Media(), "Video", out _pinVideo);
demuxer.CreateOutputPin(FilterGraphTools.GetAudioMpg2Media(), "Audio", out _pinAudio);
demuxer.CreateOutputPin(FilterGraphTools.GetAudioLPCMMedia(), "LPCM", out _pinLPCM);
IMPEG2StreamIdMap map = (IMPEG2StreamIdMap)_pinVideo;
map.MapStreamId(224, MPEG2Program.ElementaryStream, 0, 0);
map = (IMPEG2StreamIdMap)_pinAudio;
map.MapStreamId(0xC0, MPEG2Program.ElementaryStream, 0, 0);
map = (IMPEG2StreamIdMap)_pinLPCM;
map.MapStreamId(0xBD, MPEG2Program.ElementaryStream, 0xA0, 7);
}
示例10: AddInterVideoMuxer
/// <summary>
/// Adds the InterVideo muxer and connects the compressor to it.
/// This is the preferred muxer for Plextor cards and others.
/// It will be used if the InterVideo Audio Encoder is used also.
/// </summary>
/// <param name="_graphBuilder">GraphBuilder</param>
/// <param name="_capture">Capture</param>
/// <returns></returns>
private bool AddInterVideoMuxer(IFilterGraph2 _graphBuilder, Capture _capture)
{
IPin pinOut;
Log.Log.Info("analog: using intervideo muxer");
string muxVideoIn = "video compressor";
const string monikerInterVideoMuxer =
@"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\{317DDB63-870E-11D3-9C32-00104B3801F7}";
_filterAnalogMpegMuxer = Marshal.BindToMoniker(monikerInterVideoMuxer) as IBaseFilter;
int hr = _graphBuilder.AddFilter(_filterAnalogMpegMuxer, "InterVideo MPEG Muxer");
if (hr != 0)
{
Log.Log.WriteFile("analog: add intervideo muxer returns:0x{0:X}", hr);
throw new TvException("Unable to add InterVideo Muxer");
}
Log.Log.Info("analog: add intervideo muxer successful");
// next connect video compressor->muxer
if (_isPlextorConvertX)
{
muxVideoIn = "Plextor ConvertX";
//no video compressor needed with the Plextor device so we use the first capture pin
pinOut = DsFindPin.ByDirection(_capture.VideoFilter, PinDirection.Output, 0);
}
else
{
pinOut = DsFindPin.ByDirection(_filterVideoCompressor, PinDirection.Output, 0);
}
IPin pinIn = DsFindPin.ByDirection(_filterAnalogMpegMuxer, PinDirection.Input, 0);
if (pinOut == null)
{
Log.Log.Info("analog: no output pin found on {0}", muxVideoIn);
throw new TvException("no output pin found on video out");
}
if (pinIn == null)
{
Log.Log.Info("analog: no input pin found on intervideo muxer");
throw new TvException("no input pin found on intervideo muxer");
}
hr = _graphBuilder.Connect(pinOut, pinIn);
if (hr != 0)
{
Log.Log.WriteFile("analog: unable to connect {0}-> intervideo muxer returns:0x{1:X}", muxVideoIn, hr);
throw new TvException("Unable to add unable to connect to video in on intervideo muxer");
}
Log.Log.WriteFile("analog: connected video -> intervideo muxer");
// next connect audio compressor->muxer
pinOut = DsFindPin.ByDirection(_filterAudioCompressor, PinDirection.Output, 0);
pinIn = DsFindPin.ByDirection(_filterAnalogMpegMuxer, PinDirection.Input, 1);
if (pinOut == null)
{
Log.Log.Info("analog: no output pin found on audio compressor");
throw new TvException("no output pin found on audio compressor");
}
if (pinIn == null)
{
Log.Log.Info("analog: no input pin found on intervideo muxer");
throw new TvException("no input pin found on intervideo muxer");
}
hr = _graphBuilder.Connect(pinOut, pinIn);
if (hr != 0)
{
Log.Log.WriteFile("analog:unable to connect audio compressor->intervideo muxer returns:0x{0:X}", hr);
throw new TvException("Unable to add unable to connect audio compressor->intervideo muxer");
}
Log.Log.WriteFile("analog: connected audio -> intervideo muxer");
//and finally we have a capture pin...
_pinCapture = DsFindPin.ByDirection(_filterAnalogMpegMuxer, PinDirection.Output, 0);
if (_pinCapture == null)
{
Log.Log.WriteFile("analog:unable find capture pin");
throw new TvException("unable find capture pin");
}
return true;
}
示例11: AddAnalogMuxer
/// <summary>
/// Adds the mpeg muxer
/// </summary>
/// <param name="_graphBuilder">GraphBuilder</param>
/// <returns></returns>
private bool AddAnalogMuxer(IFilterGraph2 _graphBuilder)
{
Log.Log.Info("analog:AddAnalogMuxer");
const string monikerPowerDirectorMuxer =
@"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\{7F2BBEAF-E11C-4D39-90E8-938FB5A86045}";
_filterAnalogMpegMuxer = Marshal.BindToMoniker(monikerPowerDirectorMuxer) as IBaseFilter;
int hr = _graphBuilder.AddFilter(_filterAnalogMpegMuxer, "Analog MPEG Muxer");
if (hr != 0)
{
Log.Log.WriteFile("analog:AddAnalogMuxer returns:0x{0:X}", hr);
throw new TvException("Unable to add AddAnalogMuxer");
}
// next connect audio compressor->muxer
IPin pinOut = DsFindPin.ByDirection(_filterAudioCompressor, PinDirection.Output, 0);
IPin pinIn = DsFindPin.ByDirection(_filterAnalogMpegMuxer, PinDirection.Input, 1);
if (pinOut == null)
{
Log.Log.Info("analog:no output pin found on audio compressor");
throw new TvException("no output pin found on audio compressor");
}
if (pinIn == null)
{
Log.Log.Info("analog:no input pin found on analog muxer");
throw new TvException("no input pin found on muxer");
}
hr = _graphBuilder.Connect(pinOut, pinIn);
if (hr != 0)
{
Log.Log.WriteFile("analog:unable to connect audio compressor->muxer returns:0x{0:X}", hr);
throw new TvException("Unable to add unable to connect audio compressor->muxer");
}
Log.Log.WriteFile("analog: connected audio -> muxer");
// next connect video compressor->muxer
pinOut = DsFindPin.ByDirection(_filterVideoCompressor, PinDirection.Output, 0);
pinIn = DsFindPin.ByDirection(_filterAnalogMpegMuxer, PinDirection.Input, 0);
if (pinOut == null)
{
Log.Log.Info("analog:no output pin found on video compressor");
throw new TvException("no output pin found on video compressor");
}
if (pinIn == null)
{
Log.Log.Info("analog:no input pin found on analog muxer");
throw new TvException("no input pin found on muxer");
}
hr = _graphBuilder.Connect(pinOut, pinIn);
if (hr != 0)
{
Log.Log.WriteFile("analog:unable to connect video compressor->muxer returns:0x{0:X}", hr);
throw new TvException("Unable to add unable to connect video compressor->muxer");
}
//and finally we have a capture pin...
Log.Log.WriteFile("analog: connected video -> muxer");
_pinCapture = DsFindPin.ByDirection(_filterAnalogMpegMuxer, PinDirection.Output, 0);
if (_pinCapture == null)
{
Log.Log.WriteFile("analog:unable find capture pin");
throw new TvException("unable find capture pin");
}
return true;
}
示例12: AddVideoCompressor
/// <summary>
/// Adds the video compressor.
/// </summary>
/// <param name="_graphBuilder">GraphBuilder</param>
/// <returns></returns>
private bool AddVideoCompressor(IFilterGraph2 _graphBuilder)
{
Log.Log.WriteFile("analog: AddVideoCompressor");
DsDevice[] devices1 = DsDevice.GetDevicesOfCat(FilterCategory.VideoCompressorCategory);
DsDevice[] devices2 = DsDevice.GetDevicesOfCat(FilterCategory.LegacyAmFilterCategory);
IList<SoftwareEncoder> videoEncoders = _layer.GetSofwareEncodersVideo();
DsDevice[] videoDevices = new DsDevice[videoEncoders.Count];
for (int x = 0; x < videoEncoders.Count; ++x)
{
videoDevices[x] = null;
}
for (int i = 0; i < devices1.Length; i++)
{
for (int x = 0; x < videoEncoders.Count; ++x)
{
if (videoEncoders[x].Name == devices1[i].Name)
{
videoDevices[x] = devices1[i];
break;
}
}
}
for (int i = 0; i < devices2.Length; i++)
{
for (int x = 0; x < videoEncoders.Count; ++x)
{
if (videoEncoders[x].Name == devices2[i].Name)
{
videoDevices[x] = devices2[i];
break;
}
}
}
//for each compressor
Log.Log.WriteFile("analog: AddVideoCompressor found:{0} compressor", videoDevices.Length);
for (int i = 0; i < videoDevices.Length; i++)
{
IBaseFilter tmp;
if (videoDevices[i] == null || !EncodersInUse.Instance.Add(videoDevices[i], videoEncoders[i]))
{
continue;
}
Log.Log.WriteFile("analog: try compressor:{0}", videoDevices[i].Name);
int hr;
try
{
//add compressor filter to graph
hr = _graphBuilder.AddSourceFilterForMoniker(videoDevices[i].Mon, null, videoDevices[i].Name, out tmp);
}
catch (Exception)
{
Log.Log.WriteFile("analog: cannot add compressor to graph");
EncodersInUse.Instance.Remove(videoDevices[i]);
continue;
}
if (hr != 0)
{
//failed to add filter to graph, continue with the next one
if (tmp != null)
{
_graphBuilder.RemoveFilter(tmp);
Release.ComObject("videocompressor", tmp);
}
EncodersInUse.Instance.Remove(videoDevices[i]);
continue;
}
if (tmp == null)
{
EncodersInUse.Instance.Remove(videoDevices[i]);
continue;
}
// check if this compressor filter has an mpeg audio output pin
Log.Log.WriteFile("analog: connect video pin->video compressor");
IPin pinVideo = DsFindPin.ByDirection(tmp, PinDirection.Input, 0);
// we found a nice compressor, lets try to connect the analog video pin to the compressor
hr = _graphBuilder.Connect(_pinAnalogVideo, pinVideo);
if (hr != 0)
{
Log.Log.WriteFile("analog: failed to connect video pin->video compressor");
//unable to connec the pin, remove it and continue with next compressor
_graphBuilder.RemoveFilter(tmp);
Release.ComObject("videocompressor", tmp);
EncodersInUse.Instance.Remove(videoDevices[i]);
continue;
}
//succeeded.
_videoCompressorDevice = videoDevices[i];
_filterVideoCompressor = tmp;
return true;
}
return false;
}
示例13: 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);
//.........这里部分代码省略.........
示例14: SetupGraph
/// <summary> build the capture graph for grabber. </summary>
private void SetupGraph(string FileName, Control hWin)
{
int hr;
IBaseFilter ibfRenderer = null;
ISampleGrabber sampGrabber = null;
IBaseFilter capFilter = null;
IPin iPinInFilter = null;
IPin iPinOutFilter = null;
IPin iPinInDest = null;
IBasicAudio basicAudio = null;
// Get the graphbuilder object
m_FilterGraph = new FilterGraph() as IFilterGraph2;
#if DEBUG
m_rot = new DsROTEntry(m_FilterGraph);
#endif
try
{
// Get the SampleGrabber interface
sampGrabber = new SampleGrabber() as ISampleGrabber;
// 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(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 = m_FilterGraph.AddFilter(baseGrabFlt, "Ds.NET Grabber");
DsError.ThrowExceptionForHR(hr);
hr = m_FilterGraph.Connect(iPinOutSource, iPinInFilter);
DsError.ThrowExceptionForHR(hr);
// Get the default video renderer
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(iPinOutFilter, iPinInDest);
DsError.ThrowExceptionForHR(hr);
SaveSizeInfo(sampGrabber);
// Set the output window
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);
//TODO : Need a better way to hide the video in the parent Window
Rectangle rc = hWin.ClientRectangle;
if (mParentWindowDisplay)
hr = videoWindow.SetWindowPosition(0, 0, rc.Right, rc.Bottom);
else
hr = videoWindow.SetWindowPosition(0, 0, 0, 0);
DsError.ThrowExceptionForHR(hr);
IGraphBuilder graphBuilder = m_FilterGraph as IGraphBuilder;
ICaptureGraphBuilder2 captureGraphBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
// Attach the filter graph to the capture graph
hr = captureGraphBuilder.SetFiltergraph(graphBuilder);
DsError.ThrowExceptionForHR(hr);
hr = captureGraphBuilder.RenderStream(null, MediaType.Audio, capFilter, null, null);
}
finally
{
if (capFilter != null)
{
Marshal.ReleaseComObject(capFilter);
capFilter = null;
}
if (sampGrabber != null)
{
Marshal.ReleaseComObject(sampGrabber);
sampGrabber = null;
}
//.........这里部分代码省略.........
示例15: ConnectEncoderFilter
/// <summary>
/// This method tries to connect a encoder filter to the capture filter
/// See the remarks in AddTvEncoderFilter() for the possible options
/// </summary>
/// <param name="filterEncoder">The filter encoder.</param>
/// <param name="isVideo">if set to <c>true</c> the filterEncoder is used for video.</param>
/// <param name="isAudio">if set to <c>true</c> the filterEncoder is used for audio.</param>
/// <param name="matchPinNames">if set to <c>true</c> the pin names of the encoder filter should match the pin names of the capture filter.</param>
/// <param name="_graphBuilder">GraphBuilder</param>
/// <param name="_capture">Capture</param>
/// <returns>
/// true if encoder is connected correctly, otherwise false
/// </returns>
private static bool ConnectEncoderFilter(IBaseFilter filterEncoder, bool isVideo, bool isAudio, bool matchPinNames,
IFilterGraph2 _graphBuilder, Capture _capture)
{
Log.Log.WriteFile("analog: ConnectEncoderFilter video:{0} audio:{1}", isVideo, isAudio);
//find the inputs of the encoder. could be 1 or 2 inputs.
IPin pinInput1 = DsFindPin.ByDirection(filterEncoder, PinDirection.Input, 0);
IPin pinInput2 = DsFindPin.ByDirection(filterEncoder, PinDirection.Input, 1);
//log input pins
if (pinInput1 != null)
Log.Log.WriteFile("analog: found pin#0 {0}", FilterGraphTools.LogPinInfo(pinInput1));
if (pinInput2 != null)
Log.Log.WriteFile("analog: found pin#1 {0}", FilterGraphTools.LogPinInfo(pinInput2));
string pinName1 = FilterGraphTools.GetPinName(pinInput1);
string pinName2 = FilterGraphTools.GetPinName(pinInput2);
int pinsConnected = 0;
int pinsAvailable = 0;
IPin[] pins = new IPin[20];
IEnumPins enumPins = null;
try
{
// for each output pin of the capture device
_capture.VideoFilter.EnumPins(out enumPins);
enumPins.Next(20, pins, out pinsAvailable);
Log.Log.WriteFile("analog: pinsAvailable on capture filter:{0}", pinsAvailable);
for (int i = 0; i < pinsAvailable; ++i)
{
int hr;
// check if this is an output pin
PinDirection pinDir;
pins[i].QueryDirection(out pinDir);
if (pinDir == PinDirection.Input)
continue;
//log the pin info...
Log.Log.WriteFile("analog: capture pin:{0} {1}", i, FilterGraphTools.LogPinInfo(pins[i]));
string pinName = FilterGraphTools.GetPinName(pins[i]);
// first lets try to connect this output pin of the capture filter to the 1st input pin
// of the encoder
// only try to connect when pin name matching is turned off
// or when the pin names are the same
if (matchPinNames == false || (String.Compare(pinName, pinName1, true) == 0))
{
//try to connect the output pin of the capture filter to the first input pin of the encoder
hr = _graphBuilder.Connect(pins[i], pinInput1);
if (hr == 0)
{
//succeeded!
Log.Log.WriteFile("analog: connected pin:{0} {1} with pin0", i, pinName);
pinsConnected++;
}
//check if all pins are connected
if (pinsConnected == 1 && (isAudio == false || isVideo == false))
{
//yes, then we are done
Log.Log.WriteFile("analog: ConnectEncoderFilter succeeded");
return true;
}
}
// next lets try to connect this output pin of the capture filter to the 2nd input pin
// of the encoder
// only try to connect when pin name matching is turned off
// or when the pin names are the same
if (matchPinNames == false || (String.Compare(pinName, pinName2, true) == 0))
{
//try to connect the output pin of the capture filter to the 2nd input pin of the encoder
hr = _graphBuilder.Connect(pins[i], pinInput2);
if (hr == 0)
{
//succeeded!
Log.Log.WriteFile("analog: connected pin:{0} {1} with pin1", i, pinName);
pinsConnected++;
}
//check if all pins are connected
if (pinsConnected == 2)
{
//yes, then we are done
Log.Log.WriteFile("analog: ConnectEncoderFilter succeeded");
return true;
}
//Log.Log.WriteFile("analog: ConnectEncoderFilter to Capture {0} failed", pinName2);
}
}
}
finally
{
if (enumPins != null)
Release.ComObject("ienumpins", enumPins);
if (pinInput1 != null)
//.........这里部分代码省略.........