Exemple #1
0
        private void SetupGraphInternal(DsDevice dev, SystemCodecEntry compressor, VideoFormatHelper.SupportedVideoFormat selectedFormat, ref float iFrameRate, ref int iWidth, ref int iHeight, string fileName)
        {
            filterGraph = (IFilterGraph2) new FilterGraph();
            mediaCtrl   = filterGraph as IMediaControl;

            capBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

            samplGrabber = (ISampleGrabber) new SampleGrabber();

            int hr = capBuilder.SetFiltergraph(filterGraph);

            DsError.ThrowExceptionForHR(hr);

            if (rot != null)
            {
                rot.Dispose();
                rot = null;
            }
            rot = new DsROTEntry(filterGraph);

            if (fileName != null)
            {
                deviceFilter = BuildFileCaptureGraph(dev, compressor.Device, selectedFormat, fileName, ref iFrameRate, ref iWidth, ref iHeight);
            }
            else
            {
                deviceFilter = BuildPreviewOnlyCaptureGraph(dev, selectedFormat, ref iFrameRate, ref iWidth, ref iHeight);
            }

            // Now that sizes are fixed/known, store the sizes
            SaveSizeInfo(samplGrabber);
        }
Exemple #2
0
        public static SystemCodecEntry GetSupportedVideoCodec(string codecName)
        {
            List <SystemCodecEntry> supportedCodecs = GetSupportedVideoCodecs();

            SystemCodecEntry rv = supportedCodecs.FirstOrDefault(x => x.DeviceName == codecName && x.IsInstalled);

            DsDevice unsupportedCodec = DsDevice.GetDevicesOfCat(FilterCategory.VideoCompressorCategory).FirstOrDefault(x => x.Name == codecName);

            if (unsupportedCodec != null)
            {
                return new SystemCodecEntry()
                       {
                           Device = unsupportedCodec
                       }
            }
            ;

            if (rv == null)
            {
                rv = supportedCodecs.SingleOrDefault(x => x.Codec == SupportedCodec.Uncompressed);
            }

            return(rv);
        }
    }
Exemple #3
0
        // From DirectShowNet Forums: http://sourceforge.net/p/directshownet/discussion/460697/thread/edb37d2a/
        // ----------------------------------------------------------------------------------------------------------------
        // The ugly truth is that some people who have written codecs have done a lousy job of it, and they barely work.
        // Some codecs are complex and need special handling. A generic program to work with all codecs is probably impossible.
        // And if it were possible, it would be so complex that it would be a failure as a sample, since no one would be able
        // to read the code and figure out how it worked (which is what samples are for).
        // ------------------------------------------------------------------------------------------------------------------
        // It also appears that if the application is not built as x86 it will not display a whole bunch of codecs on 64bit machines
        // http://social.msdn.microsoft.com/Forums/en-US/windowsdirectshowdevelopment/thread/d9029891-25e5-4ed1-ab31-9cae7c6c8eae/
        // There is not much we can do here other than making sure the build is always x86
        public static List <SystemCodecEntry> GetSupportedVideoCodecs()
        {
            var supportedCodecs = new List <SystemCodecEntry>();

            var allCodecs = new List <DsDevice>();

            allCodecs.AddRange(DsDevice.GetDevicesOfCat(FilterCategory.VideoCompressorCategory));

            foreach (SupportedCodec codec in Enum.GetValues(typeof(SupportedCodec)))
            {
                if (codec == SupportedCodec.Unsupported)
                {
                    continue;
                }

                var entry = new SystemCodecEntry {
                    Codec = codec
                };

                entry.Device = allCodecs.FirstOrDefault(x => x.Name == entry.DeviceName);

                supportedCodecs.Add(entry);
            }

            return(supportedCodecs);
        }
Exemple #4
0
        public void SetupFileRecorderGraph(DsDevice dev, SystemCodecEntry compressor, VideoFormatHelper.SupportedVideoFormat selectedFormat, ref float iFrameRate, ref int iWidth, ref int iHeight, string fileName)
        {
            try
            {
                SetupGraphInternal(dev, compressor, selectedFormat, ref iFrameRate, ref iWidth, ref iHeight, fileName);

                latestBitmap = new Bitmap(iWidth, iHeight, PixelFormat.Format24bppRgb);
                fullRect     = new Rectangle(0, 0, latestBitmap.Width, latestBitmap.Height);
            }
            catch
            {
                CloseResources();
                throw;
            }
        }
Exemple #5
0
        private void FindInputAndCompressorToUse(out DsDevice inputDevice, out SystemCodecEntry compressor)
        {
            inputDevice = null;
            compressor  = null;

            List <DsDevice> allInputDevices = new List <DsDevice>(DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice));

            if (!string.IsNullOrEmpty(settings.PreferredCaptureDevice))
            {
                inputDevice = allInputDevices.FirstOrDefault(x => x.Name == settings.PreferredCaptureDevice);
            }
            else if (allInputDevices.Count > 0)
            {
                inputDevice = allInputDevices[0];
            }

            compressor = VideoCodecs.GetSupportedVideoCodec(settings.PreferredCompressorDevice);
        }
Exemple #6
0
        public void ReloadSettings()
        {
            if (IsConnected && (videoInputDevice != null || videoCompressor != null))
            {
                DsDevice         inputDevice;
                SystemCodecEntry compressor;

                FindInputAndCompressorToUse(out inputDevice, out compressor);

                bool reconnect = false;

                if (inputDevice != null &&
                    videoInputDevice != null &&
                    videoInputDevice.DevicePath != inputDevice.DevicePath)
                {
                    // We have a new video device. Will need to reconnect to it
                    reconnect = true;
                }

                if (compressor != null &&
                    videoCompressor != null &&
                    videoCompressor.Codec != compressor.Codec)
                {
                    // We have a new compressor device. Will need to reconnect
                    reconnect = true;
                }

                if (reconnect)
                {
                    EnsureDisconnected();

                    videoInputDevice = inputDevice;
                    videoCompressor  = compressor;

                    EnsureConnected();
                }
            }
        }