protected void AddAndConnectBDABoardFilters()
{
int hr = 0;
DsDevice[] devices;
this.captureGraphBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
captureGraphBuilder.SetFiltergraph(this.graphBuilder);
try
{
if (this.TunerDevice != null)
{
IBaseFilter tmp;
hr = graphBuilder.AddSourceFilterForMoniker(this.TunerDevice.Mon, null, this.TunerDevice.Name, out tmp);
DsError.ThrowExceptionForHR(hr);
hr = captureGraphBuilder.RenderStream(null, null, this.networkProvider, null, tmp);
if (hr == 0)
{
// Got it !
this.tuner = tmp;
}
else
{
// Try another...
int hr2 = graphBuilder.RemoveFilter(tmp);
Marshal.ReleaseComObject(tmp);
DsError.ThrowExceptionForHR(hr);
return;
}
}
else
{
// Enumerate BDA Source filters category and found one that can connect to the network provider
devices = DsDevice.GetDevicesOfCat(FilterCategory.BDASourceFiltersCategory);
for (int i = 0; i < devices.Length; i++)
{
IBaseFilter tmp;
hr = graphBuilder.AddSourceFilterForMoniker(devices[i].Mon, null, devices[i].Name, out tmp);
DsError.ThrowExceptionForHR(hr);
hr = captureGraphBuilder.RenderStream(null, null, this.networkProvider, null, tmp);
if (hr == 0)
{
// Got it !
this.tuner = tmp;
break;
}
else
{
// Try another...
hr = graphBuilder.RemoveFilter(tmp);
Marshal.ReleaseComObject(tmp);
}
}
}
// Assume we found a tuner filter...
if (this.CaptureDevice != null)
{
IBaseFilter tmp;
hr = graphBuilder.AddSourceFilterForMoniker(this.CaptureDevice.Mon, null, this.CaptureDevice.Name, out tmp);
DsError.ThrowExceptionForHR(hr);
hr = captureGraphBuilder.RenderStream(null, null, this.tuner, null, tmp);
if (hr == 0)
{
// Got it !
this.capture = tmp;
// Connect it to the MPEG-2 Demux
hr = captureGraphBuilder.RenderStream(null, null, this.capture, null, this.mpeg2Demux);
if (hr < 0)
// BDA also support 3 filter scheme (never show it in real life).
throw new ApplicationException("This application only support the 2 filters BDA scheme");
}
else
{
// Try another...
int hr2 = graphBuilder.RemoveFilter(tmp);
Marshal.ReleaseComObject(tmp);
DsError.ThrowExceptionForHR(hr);
return;
}
}
else
{
this.capture = null;
// Connect it to the MPEG-2 Demux
hr = captureGraphBuilder.RenderStream(null, null, this.tuner, null, this.mpeg2Demux);
if (hr < 0)
// BDA also support 3 filter scheme (never show it in real life).
throw new ApplicationException("This application only support the 2 filters BDA scheme");
//// Then enumerate BDA Receiver Components category to found a filter connecting
//// to the tuner and the MPEG2 Demux
//devices = DsDevice.GetDevicesOfCat(FilterCategory.BDAReceiverComponentsCategory);
//for (int i = 0; i < devices.Length; i++)
//{
// IBaseFilter tmp;
// hr = graphBuilder.AddSourceFilterForMoniker(devices[i].Mon, null, devices[i].Name, out tmp);
// DsError.ThrowExceptionForHR(hr);
// hr = captureGraphBuilder.RenderStream(null, null, this.tuner, null, tmp);
// if (hr == 0)
// {
// // Got it !
// this.capture = tmp;
// // Connect it to the MPEG-2 Demux
// hr = captureGraphBuilder.RenderStream(null, null, this.capture, null, this.mpeg2Demux);
// if (hr < 0)
// // BDA also support 3 filter scheme (never show it in real life).
// throw new ApplicationException("This application only support the 2 filters BDA scheme");
// break;
// }
// else
// {
// // Try another...
// hr = graphBuilder.RemoveFilter(tmp);
// Marshal.ReleaseComObject(tmp);
// }
//}
}
}
finally
{
}
}