Example #1
0
        byte[] outputYUV420;//=
        public void SetResolution(int width, int height)
        {
            if (counter == 2)
            {
                return;
            }
            counter++;
            int iRet;

            this.width   = width;
            this.height  = height;
            outputYUV420 = new byte[width * height * 3 / 2];
            object o;

            CaptureGraphBuilder.FindInterface(PinCategory.Capture, MediaType.Video, VideoInput,
                                              typeof(IAMStreamConfig).GUID, out o);
            var         videoStreamConfig = o as IAMStreamConfig;
            AMMediaType media;



            int iC = 0, iS = 0;

            iRet = videoStreamConfig.GetNumberOfCapabilities(out iC, out iS);
            if (iRet != 0)
            {
                Console.WriteLine("TheKing--> Error Found GetNumberOfCapabilities");
            }

            IntPtr ptr       = Marshal.AllocCoTaskMem(iS);
            int    streamId  = 0;
            var    videoInfo = new VideoInfoHeader();

            availableVideoModes.Clear();
            for (int i = 0; i < iC; i++)
            {
                iRet = videoStreamConfig.GetStreamCaps(i, out media, ptr);
                if (iRet != 0)
                {
                    Console.WriteLine("TheKing--> Error Found GetStreamCaps");
                }
                Marshal.PtrToStructure(media.formatPtr, videoInfo);

                if (videoInfo.BmiHeader.Width != 0 && videoInfo.BmiHeader.Height != 0)
                {
                    availableVideoModes.Add(new VideoMode(videoInfo.BmiHeader.Width, videoInfo.BmiHeader.Height));
                }
                if (videoInfo.BmiHeader.Width != width || videoInfo.BmiHeader.Height != height)
                {
                    continue;
                }
                streamId          = i;
                selectedVideoMode = availableVideoModes.Last();
                break;
            }


            iRet = videoStreamConfig.GetStreamCaps(streamId, out media, ptr);
            if (iRet != 0)
            {
                Console.WriteLine("TheKing--> Error Found GetStreamCaps 2");
            }
            Marshal.PtrToStructure(media.formatPtr, videoInfo);
            iRet = videoStreamConfig.SetFormat(media);
            if (iRet != 0)
            {
                Console.WriteLine("TheKing SetFormat --> " + iRet);
            }
            Marshal.FreeCoTaskMem(ptr);


            media           = new AMMediaType();
            media.majorType = MediaType.Video;
            if (counter == 1)
            {
                media.subType = MediaSubType.RGB24; //Input Video Format
            }
            else if (counter == 2)
            {
                media.subType = MediaSubType.RGB24;
            }


            media.formatType       = FormatType.VideoInfo;
            media.fixedSizeSamples = true;

            iRet = SampleGrabber.SetMediaType(media);
            if (iRet != 0)
            {
                Console.WriteLine("TheKing SetMediaType --> " + iRet);
            }
            DsUtils.FreeAMMediaType(media);

            if (counter == 1)
            {
                //InitRingIDSDKLib();

                Thread oThread = new Thread(new ThreadStart(RenderThread));
                oThread.Start();
            }
        }
        public void SetResolution(int width, int height)
        {
            if (counter == 2) return;
            counter++;
            int iRet;
            this.width = width;
            this.height = height;
            outputYUV420 = new byte[width * height * 3 / 2];
            object o;

            CaptureGraphBuilder.FindInterface(PinCategory.Capture, MediaType.Video, VideoInput,
                typeof(IAMStreamConfig).GUID, out o);
            var videoStreamConfig = o as IAMStreamConfig;
            AMMediaType media;

            int iC = 0, iS = 0;
            iRet = videoStreamConfig.GetNumberOfCapabilities(out iC, out iS);
            if (iRet != 0) Console.WriteLine("TheKing--> Error Found GetNumberOfCapabilities");

            IntPtr ptr = Marshal.AllocCoTaskMem(iS);
            int streamId = 0;
            var videoInfo = new VideoInfoHeader();

            availableVideoModes.Clear();
            for (int i = 0; i < iC; i++)
            {
                iRet = videoStreamConfig.GetStreamCaps(i, out media, ptr);
                if (iRet != 0) Console.WriteLine("TheKing--> Error Found GetStreamCaps");
                Marshal.PtrToStructure(media.formatPtr, videoInfo);

                if (videoInfo.BmiHeader.Width != 0 && videoInfo.BmiHeader.Height != 0)
                {
                    availableVideoModes.Add(new VideoMode(videoInfo.BmiHeader.Width, videoInfo.BmiHeader.Height));
                }
                if (videoInfo.BmiHeader.Width != width || videoInfo.BmiHeader.Height != height)
                {
                    continue;
                }
                streamId = i;
                selectedVideoMode = availableVideoModes.Last();
                break;
            }

            iRet = videoStreamConfig.GetStreamCaps(streamId, out media, ptr);
            if (iRet != 0) Console.WriteLine("TheKing--> Error Found GetStreamCaps 2");
            Marshal.PtrToStructure(media.formatPtr, videoInfo);
            iRet = videoStreamConfig.SetFormat(media);
            if(iRet!=0) Console.WriteLine("TheKing SetFormat --> " + iRet);
            Marshal.FreeCoTaskMem(ptr);

            media = new AMMediaType();
            media.majorType = MediaType.Video;
            if (counter == 1)
            {
                media.subType = MediaSubType.RGB24; //Input Video Format
            }
            else if (counter == 2)
            {
                media.subType = MediaSubType.RGB24;
            }

            media.formatType = FormatType.VideoInfo;
            media.fixedSizeSamples = true;

            iRet = SampleGrabber.SetMediaType(media);
            if(iRet!=0) Console.WriteLine("TheKing SetMediaType --> " + iRet);
            DsUtils.FreeAMMediaType(media);

            if (counter == 1)
            {
                //InitRingIDSDKLib();

                Thread oThread = new Thread(new ThreadStart(RenderThread));
                oThread.Start();
            }
        }