コード例 #1
0
        private void ConfigureCompressor()
        {
            // Have the compressor use the same height and width settings as the device

            // Because these are structs that access their members through properties
            // some of the properties (like BitmapInfo) are copied, so we work on the
            // copy and then restore it at the end
            BITMAPINFOHEADER bmih = cVI.BitmapInfo;

            bmih.Width     = SystemInformation.PrimaryMonitorSize.Width;
            bmih.Height    = SystemInformation.PrimaryMonitorSize.Height;
            bmih.Size      = (uint)Marshal.SizeOf(typeof(BITMAPINFOHEADER));
            bmih.Planes    = 1;
            cVI.BitmapInfo = bmih;

            // Configure the bit rate
            cVI.BitRate = (uint)(hsbBitRate.Value * 1024); // Change to kilobits

            // Update the structure in memory
            Marshal.StructureToPtr(cVI, cMT.pbFormat, false);

            // Allow compressor specific configuration
            // e.g. WM9+ requires extra configuration, others may as well
            ConfigureWMScreenEncoder();
            Console.WriteLine(MediaType.Dump(cMT));

            // Use the structure in the compressor
            IAMStreamConfig iSC = (IAMStreamConfig)cOutputPin;

            iSC.SetFormat(ref cMT);

            IAMVideoCompression iVC = (IAMVideoCompression)cOutputPin;
        }
コード例 #2
0
        public void DoTests()
        {
            // Get an audio device
            m_ivc = GetCompressionFilter();

            try
            {
                TestKeyFrameRate();
                TestPFrames();
                TestQuality();
                TestWindow();
                TestOverride();
                TestGetInfo();
            }
            finally
            {
                Marshal.ReleaseComObject(m_ivc);
            }
        }
コード例 #3
0
        // Find an video compression filter
        IAMVideoCompression GetCompressionFilter()
        {
            DsDevice []         capDevices;
            IAMVideoCompression ifcd = null;
            IBaseFilter         ibf;
            int    x;
            string s = "";

            // Get the collection of video devices
            capDevices = DsDevice.GetDevicesOfCat(FilterCategory.VideoCompressorCategory);
            if (capDevices.Length == 0)
            {
                throw new Exception("No video compressors found!");
            }

            for (x = 0; x < capDevices.Length; x++)
            {
                DsDevice dev = capDevices[x];

                dev.Mon.GetDisplayName(null, null, out s);

                if (dev.Name == "Intel Indeo® Video 4.5") //"Microsoft Video 1")
                {
                    break;
                }
            }

            if (x >= capDevices.Length)
            {
                throw new Exception("can't find the video 1 filter");
            }

            ibf = Marshal.BindToMoniker(s) as IBaseFilter;

            IPin outpin = DsFindPin.ByDirection(ibf, PinDirection.Output, 0);

            ifcd = outpin as IAMVideoCompression;

            return(ifcd);
        }
コード例 #4
0
ファイル: Filters.cs プロジェクト: psyCHOder/conferencexp
        private void GetIAMVideoCompression()
        {
            iVC = OutputPin as IAMVideoCompression;

            if(iVC != null)
            {
                // See if it supports GetInfo
                try
                {
                    int pcbVersion = 0;
                    int pcbDescription = 0;

                    // Make the call to get the lengths of the strings
                    iVC.GetInfo(null, ref pcbVersion, null, ref pcbDescription, 
                        out defaultKFR, out defaultPFPKF, out defaultQuality, out capabilities);

                    StringBuilder version = new StringBuilder(pcbVersion / 2);
                    StringBuilder description = new StringBuilder(pcbDescription / 2);
                    
                    iVC.GetInfo(version, ref pcbVersion, description, ref pcbDescription, 
                        out defaultKFR, out defaultPFPKF, out defaultQuality, out capabilities);

                    this.version = version.ToString();
                    this.description = description.ToString();
                    
                    getInfo = true;
                }
                catch(NotImplementedException){}

                // Windows Media lies about its capabilities, so we test them 1 by 1
                if(capabilities == 0) 
                {
                    // Assume it CanCrunch
                    capabilities |= (int)CompressionCaps.CompressionCaps_CanCrunch;

                    try
                    {
                        int kfr;
                        iVC.get_KeyFrameRate(out kfr);
                        iVC.put_KeyFrameRate(kfr);

                        capabilities |= (int)CompressionCaps.CompressionCaps_CanKeyFrame;
                    }
                    catch(Exception){}

                    try
                    {
                        double quality;
                        iVC.get_Quality(out quality);
                        iVC.put_Quality(quality);

                        capabilities |= (int)CompressionCaps.CompressionCaps_CanQuality;
                    }
                    catch(Exception){}

                    try
                    {
                        int pfpkr;
                        iVC.get_PFramesPerKeyFrame(out pfpkr);
                        iVC.put_PFramesPerKeyFrame(pfpkr);

                        capabilities |= (int)CompressionCaps.CompressionCaps_CanBFrame;
                    }
                    catch(Exception){}

                    try
                    {
                        ulong windowSize;
                        iVC.get_WindowSize(out windowSize);
                        iVC.put_WindowSize(windowSize);

                        capabilities |= (int)CompressionCaps.CompressionCaps_CanWindow;
                    }
                    catch(Exception){}
                }
            }
        }
コード例 #5
0
ファイル: Filters.cs プロジェクト: psyCHOder/conferencexp
        private void CompressorDiagnostics(string msg)
        {
#if CompressorDiagnostics

            Trace.WriteLine(msg);

            #region IAMVideoCompression

            IAMVideoCompression iVC = null;

            try
            {
                iVC = (IAMVideoCompression)cOutputPin;
            }
            catch(InvalidCastException)
            {
                Trace.WriteLine("Compressor does not support IAMVideoCompression");
            }
            
            if(iVC != null)
            {
                try
                {
                    int pcbVersion = 0;
                    int pcbDescription = 0;
                    int defaultKFR, defaultPFPK, capabilities;
                    double defaultQuality;

                    // Make the call to get the lengths of the strings
                    iVC.GetInfo(null, ref pcbVersion, null, ref pcbDescription, 
                        out defaultKFR, out defaultPFPK, out defaultQuality, out capabilities);


                    StringBuilder version = new StringBuilder(pcbVersion / 2);
                    StringBuilder description = new StringBuilder(pcbDescription / 2);
                    
                    iVC.GetInfo(version, ref pcbVersion, description, ref pcbDescription, 
                        out defaultKFR, out defaultPFPK, out defaultQuality, out capabilities);

                    Trace.WriteLine(version.ToString());
                    Trace.WriteLine(description.ToString());
                    Trace.WriteLine(defaultKFR);
                    Trace.WriteLine(defaultPFPK);
                    Trace.WriteLine(defaultQuality);
                    Trace.WriteLine(capabilities);
                }
                catch(NotImplementedException)
                {
                    Trace.WriteLine("Compressor does not support IAMVideoCompression.GetInfo");
                }

                try
                {
                    int kfr;
                    iVC.get_KeyFrameRate(out kfr);
                    Trace.WriteLine("KeyFrameRate: " + kfr);
                }
                catch(NotImplementedException)
                {
                    Trace.WriteLine("Compressor does not support IAMVideoCompression.get_KeyFrameRate");
                }

                try
                {
                    int pfpkf;
                    iVC.get_PFramesPerKeyFrame(out pfpkf);
                    Trace.WriteLine("PFramesPerKeyFrame: " + pfpkf);
                }
                catch(NotImplementedException)
                {
                    Trace.WriteLine("Compressor does not support IAMVideoCompression.get_PFramesPerKeyFrame");
                }

                try
                {
                    double q;
                    iVC.get_Quality(out q);
                    Trace.WriteLine("Quality: " + q);
                }
                catch(NotImplementedException)
                {
                    Trace.WriteLine("Compressor does not support IAMVideoCompression.get_Quality");
                }

                try
                {
                    ulong ws;
                    iVC.get_WindowSize(out ws);
                    Trace.WriteLine("WindowSize: " + ws);
                }
                catch(NotImplementedException)
                {
                    Trace.WriteLine("Compressor does not support IAMVideoCompression.get_WindowSize");
                }
            }
            
            #endregion IAMVideoCompression

            #region Native Interfaces

            #region IWMCodecLeakyBucket

            IWMCodecLeakyBucket iCLB = (IWMCodecLeakyBucket)compressor;
            uint bsb;

            try
            {
                iCLB.GetBufferSizeBits(out bsb);
                Trace.WriteLine("IWMCodecLeakyBucket.GetBufferSizeBits: " + bsb);
            }
            catch(COMException){}

            #endregion IWMCodecLeakyBucket

            // IWMCodecMetaData - not implemented by encoder in this version

            // IWMCodecOutputTimestamp - not interesting

            // IWMCodePrivateData - used when setting media type
            
            #region IWMCodecProps
            
            IWMCodecProps iCP = (IWMCodecProps)compressor;
            WMT_PROP_DATATYPE dt;
            uint expSize = 64, actSize;
            IntPtr ipData = Marshal.AllocCoTaskMem((int)expSize);

            try
            {
                actSize = expSize;
                iCP.GetCodecProp(cVI.BitmapInfo.Compression, WM9PropList.g_wszWMCPCodecName, out dt, ipData, ref actSize);
                Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "IWMCodecProps.GetCodecProp.WMCPCodecName: {0}, DataType: {1}, ActualSize: {2}",
                    Marshal.PtrToStringUni(ipData).ToString(), dt.ToString(), actSize.ToString()));
            }
            catch(COMException){}

            actSize = expSize;
            iCP.GetCodecProp(cVI.BitmapInfo.Compression, WM9PropList.g_wszWMCPSupportedVBRModes, out dt, ipData, ref actSize);
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "IWMCodecProps.GetCodecProp.WMCPSupportedVBRModes: {0}, DataType: {1}, ActualSize: {2}",
                Marshal.ReadInt32(ipData).ToString(), dt.ToString(), actSize.ToString()));

            actSize = expSize;
            iCP.GetCodecProp(cVI.BitmapInfo.Compression, WM9PropList.g_wszWMVCComplexityExLive, out dt, ipData, ref actSize);
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "IWMCodecProps.GetCodecProp.WMVCComplexityExLive: {0}, DataType: {1}, ActualSize: {2}",
                Marshal.ReadInt32(ipData).ToString(), dt.ToString(), actSize.ToString()));

            actSize = expSize;
            iCP.GetCodecProp(cVI.BitmapInfo.Compression, WM9PropList.g_wszWMVCComplexityExMax, out dt, ipData, ref actSize);
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "IWMCodecProps.GetCodecProp.WMVCComplexityExMax: {0}, DataType: {1}, ActualSize: {2}",
                Marshal.ReadInt32(ipData).ToString(), dt.ToString(), actSize.ToString()));

            actSize = expSize;
            iCP.GetCodecProp(cVI.BitmapInfo.Compression, WM9PropList.g_wszWMVCComplexityExOffline, out dt, ipData, ref actSize);
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "IWMCodecProps.GetCodecProp.WMVCComplexityExOffline: {0}, DataType: {1}, ActualSize: {2}",
                Marshal.ReadInt32(ipData).ToString(), dt.ToString(), actSize.ToString()));

            actSize = expSize;
            iCP.GetCodecProp(cVI.BitmapInfo.Compression,WM9PropList. g_wszWMVCDefaultCrisp, out dt, ipData, ref actSize);
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "IWMCodecProps.GetCodecProp.WMVCDefaultCrisp: {0}, DataType: {1}, ActualSize: {2}",
                Marshal.ReadInt32(ipData).ToString(), dt.ToString(), actSize.ToString()));

            actSize = expSize;
            iCP.GetCodecProp(cVI.BitmapInfo.Compression, WM9PropList.g_wszWMVCPassesRecommended, out dt, ipData, ref actSize);
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "IWMCodecProps.GetCodecProp.WMVCPassesRecommended: {0}, DataType: {1}, ActualSize: {2}",
                Marshal.ReadInt32(ipData).ToString(), dt.ToString(), actSize.ToString()));

            try
            {
                actSize = expSize;
                iCP.GetFormatProp(ref cMT, WM9PropList.g_wszWMVCVBREnabled, out dt, ipData, ref actSize);
                Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "IWMCodecProps.GetCodecProp.WMVCVBREnabled: {0}, DataType: {1}, ActualSize: {2}",
                    Marshal.ReadInt32(ipData).ToString(), dt.ToString(), actSize.ToString()));
            }
            catch(System.NotImplementedException){}

            try
            {
                actSize = expSize;
                iCP.GetFormatProp(ref cMT, WM9PropList.g_wszWMVCVBRQuality , out dt, ipData, ref actSize);
                Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "IWMCodecProps.GetCodecProp.WMVCVBRQuality: {0}, DataType: {1}, ActualSize: {2}",
                    Marshal.ReadInt32(ipData).ToString(), dt.ToString(), actSize.ToString()));
            }
            catch(System.NotImplementedException){}

            Marshal.FreeCoTaskMem(ipData);

            #endregion IWMCodecProps

            #region IWMCodecStrings

            IWMCodecStrings iCS = (IWMCodecStrings)compressor;
            StringBuilder sbData = new StringBuilder(128);
            uint length;

            iCS.GetName(ref cMT, 128, sbData, out length);
            Trace.WriteLine("IWMCodecStrings.GetName: " + sbData.ToString());
            
            iCS.GetDescription(ref cMT, 128, sbData, out length);
            Trace.WriteLine("IWMCodecStrings.GetDescription: " + sbData.ToString());

            #endregion IWMCodecStrings

            // IWMVideoDecoderHurryup - is a decoder interface  :-)

            #endregion Native Interfaces

            #region PropertyBag

            IPropertyBag iPB = (IPropertyBag)compressor;
            object o;

            // VBR only
//            try
//            {
//                iPB.RemoteRead(WM9PropList.g_wszWMVCAvgBitrate, out o, null, 0, null);
//                Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "IPropertyBag.g_wszWMVCAvgBitrate: {0}", ((int)o).ToString()));
//            }
//            catch(COMException){}

            try
            {
                iPB.RemoteRead(WM9PropList.g_wszWMVCAvgFrameRate, out o, null, 0, null);
                Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "IPropertyBag.g_wszWMVCAvgFrameRate: {0}", ((double)o).ToString()));
            }
            catch(COMException){}

            // VBR only
//            try
//            {
//                iPB.RemoteRead(WM9PropList.g_wszWMVCBAvg, out o, null, 0, null);
//                Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "IPropertyBag.g_wszWMVCBAvg: {0}", ((int)o).ToString()));
//            }
//            catch(COMException){}

            // VBR only
//            try
//            {
//                iPB.RemoteRead(WM9PropList.g_wszWMVCBMax, out o, null, 0, null);
//                Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "IPropertyBag.g_wszWMVCBMax: {0}", ((int)o).ToString()));
//            }
//            catch(COMException){}

            try
            {
                iPB.RemoteRead(WM9PropList.g_wszWMVCBufferFullnessInFirstByte, out o, null, 0, null);
                Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "IPropertyBag.g_wszWMVCBufferFullnessInFirstByte: {0}", ((bool)o).ToString()));
            }
            catch(COMException){}

            try
            {
                iPB.RemoteRead(WM9PropList.g_wszWMVCCodedFrames, out o, null, 0, null);
                Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "IPropertyBag.g_wszWMVCCodedFrames: {0}", ((int)o).ToString()));
            }
            catch(COMException){}
            
            // g_wszWMVCComplexityExLive - must use IWMCodecProps.GetCodecProp instead of IPropertyBag
            // g_wszWMVCComplexityExMax - must use IWMCodecProps.GetCodecProp instead of IPropertyBag
            // g_wszWMVCComplexityExOffline - must use IWMCodecProps.GetCodecProp instead of IPropertyBag

            try
            {
                iPB.RemoteRead(WM9PropList.g_wszWMVCDecoderComplexityProfile, out o, null, 0, null);
                Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "IPropertyBag.g_wszWMVCDecoderComplexityProfile: {0}", o.ToString()));
            }
            catch(COMException){}

            try
            {
                iPB.RemoteRead(WM9PropList.g_wszWMVCDefaultCrisp, out o, null, 0, null);
                Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "IPropertyBag.g_wszWMVCDefaultCrisp: {0}", o.ToString()));
            }
            catch(COMException){}

            try
            {
                iPB.RemoteRead(WM9PropList.g_wszWMVCMaxBitrate, out o, null, 0, null);
                Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "IPropertyBag.g_wszWMVCMaxBitrate: {0}", ((int)o).ToString()));
            }
            catch(COMException){}

            try
            {
                iPB.RemoteRead(WM9PropList.g_wszWMVCPassesRecommended, out o, null, 0, null);
                Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "IPropertyBag.g_wszWMVCPassesRecommended: {0}", ((int)o).ToString()));
            }
            catch(COMException){}

            try
            {
                iPB.RemoteRead(WM9PropList.g_wszWMVCPassesUsed, out o, null, 0, null);
                Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "IPropertyBag.g_wszWMVCPassesUsed: {0}", ((int)o).ToString()));
            }
            catch(COMException){}

            try
            {
                iPB.RemoteRead(WM9PropList.g_wszWMVCTotalFrames, out o, null, 0, null);
                Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "IPropertyBag.g_wszWMVCTotalFrames: {0}", ((int)o).ToString()));
            }
            catch(COMException){}

            try
            {
                iPB.RemoteRead(WM9PropList.g_wszWMVCVBREnabled, out o, null, 0, null);
                Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "IPropertyBag.g_wszWMVCVBREnabled: {0}", ((bool)o).ToString()));
            }
            catch(COMException){}

            try
            {
                iPB.RemoteRead(WM9PropList.g_wszWMVCZeroByteFrames, out o, null, 0, null);
                Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "IPropertyBag.g_wszWMVCZeroByteFrames: {0}", ((int)o).ToString()));
            }
            catch(COMException){}

            #endregion PropertyBag

#endif
        }