private void ConnectStreamBufferSourceFilter()
{
IBaseFilter videoDecoder = this.H264DecoderDevice == null ? this.videoMpeg2DecoderFilter : this.videoH264DecoderFilter;
//this.streamBufferSource as IStreamBufferConfigure
IPin videoDvrOut = null, videoDecoderIn = null;
try
{
videoDvrOut = DsFindPin.ByDirection(this.streamBufferSource, PinDirection.Output, 1);
//TODO Create output pin for the StreamBufferSource
videoDecoderIn = DsFindPin.ByDirection(videoDecoder, PinDirection.Input, 0);
//AMMediaType mediaH264 = new AMMediaType();
//mediaH264.majorType = MediaType.Video;
//mediaH264.subType = new Guid(0x8d2d71cb, 0x243f, 0x45e3, 0xb2, 0xd8, 0x5f, 0xd7, 0x96, 0x7e, 0xc0, 0x9b);
//mediaH264.sampleSize = 0;
//mediaH264.temporalCompression = false;
//mediaH264.fixedSizeSamples = false;
//mediaH264.unkPtr = IntPtr.Zero;
//mediaH264.formatType = FormatType.Mpeg2Video;
//MPEG2VideoInfo videoH264PinFormat = GetVideoH264PinFormat();
//mediaH264.formatSize = Marshal.SizeOf(videoH264PinFormat);
//mediaH264.formatPtr = Marshal.AllocHGlobal(mediaH264.formatSize);
//Marshal.StructureToPtr(videoH264PinFormat, mediaH264.formatPtr, false);
////int hr = videoDvrOut.Connect(videoDecoderIn, mediaH264);
//int hr = videoDecoderIn.Connect(videoDvrOut, mediaH264);
//Marshal.FreeHGlobal(mediaH264.formatPtr);
//DsError.ThrowExceptionForHR(hr);
//if (this.H264DecoderDevice != null)
//{
// AMMediaType mediaH264 = new AMMediaType();
// mediaH264.majorType = MediaType.Video;
// //mediaH264.subType = new Guid(0x8d2d71cb, 0x243f, 0x45e3, 0xb2, 0xd8, 0x5f, 0xd7, 0x96, 0x7e, 0xc0, 0x9b);
// mediaH264.subType = new Guid(0x34363248, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71);
// mediaH264.sampleSize = 0;
// mediaH264.temporalCompression = true; // false;
// mediaH264.fixedSizeSamples = true; // false;
// mediaH264.unkPtr = IntPtr.Zero;
// mediaH264.formatType = FormatType.Mpeg2Video;
// MPEG2VideoInfo videoH264PinFormat = GetVideoH264PinFormat();
// mediaH264.formatSize = Marshal.SizeOf(videoH264PinFormat);
// mediaH264.formatPtr = Marshal.AllocHGlobal(mediaH264.formatSize);
// Marshal.StructureToPtr(videoH264PinFormat, mediaH264.formatPtr, false);
// //IPin pinDemuxerVideoH264;
// //int hr = mpeg2Demultiplexer.CreateOutputPin(mediaH264, "H264", out pinDemuxerVideoH264);
// //if (pinDemuxerVideoH264 != null)
// //Marshal.ReleaseComObject(pinDemuxerVideoH264);
// int hr = this.graphBuilder2.ConnectDirect(videoDvrOut, videoDecoderIn, mediaH264);
// //hr = this.graphBuilder2.Connect(videoDvrOut, videoDecoderIn);
// DsError.ThrowExceptionForHR(hr);
// Marshal.FreeHGlobal(mediaH264.formatPtr);
//}
//else
FilterGraphTools.ConnectFilters(this.graphBuilder2, videoDvrOut, videoDecoderIn, false);
//int hr = this.graphBuilder2.Render(videoDvrOut);
// H264 video stream cannot connect to H264 decoder (Cyberlink)!!!
}
finally
{
if (videoDvrOut != null) Marshal.ReleaseComObject(videoDvrOut);
if (videoDecoderIn != null) Marshal.ReleaseComObject(videoDecoderIn);
}
IPin videoDecoderOut = null, videoVMRIn = null;
try
{
videoDecoderOut = DsFindPin.ByDirection(videoDecoder, PinDirection.Output, 0);
videoVMRIn = DsFindPin.ByDirection(this.videoRenderer, PinDirection.Input, 0);
FilterGraphTools.ConnectFilters(this.graphBuilder2, videoDecoderOut, videoVMRIn, false);
}
finally
{
if (videoDecoderOut != null) Marshal.ReleaseComObject(videoDecoderOut);
if (videoVMRIn != null) Marshal.ReleaseComObject(videoVMRIn);
}
IPin audioDvrOut = null, audioRendererIn = null;
try
{
audioDvrOut = DsFindPin.ByDirection(this.streamBufferSource, PinDirection.Output, 0);
audioRendererIn = DsFindPin.ByDirection(this.audioRenderer, PinDirection.Input, 0);
FilterGraphTools.ConnectFilters(this.graphBuilder2, audioDvrOut, audioRendererIn, true);
}
finally
{
if (audioDvrOut != null) Marshal.ReleaseComObject(audioDvrOut);
if (audioRendererIn != null) Marshal.ReleaseComObject(audioRendererIn);
}
}