⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dsutils.cs

📁 DirectShowLibV1-5針對DirectShow一些函數以及指令和LIB的檔案
💻 CS
📖 第 1 页 / 共 5 页
字号:
        public const int E_TimeExpired = unchecked((int)0x8004027F);
        public const int S_DVDNonOneSequential = unchecked((int)0x00040280);
        public const int E_DVDWrongSpeed = unchecked((int)0x80040281);
        public const int E_DVDMenuDoesNotExist = unchecked((int)0x80040282);
        public const int E_DVDCmdCancelled = unchecked((int)0x80040283);
        public const int E_DVDStateWrongVersion = unchecked((int)0x80040284);
        public const int E_DVDStateCorrupt = unchecked((int)0x80040285);
        public const int E_DVDStateWrongDisc = unchecked((int)0x80040286);
        public const int E_DVDIncompatibleRegion = unchecked((int)0x80040287);
        public const int E_DVDNoAttributes = unchecked((int)0x80040288);
        public const int E_DVDNoGoupPGC = unchecked((int)0x80040289);
        public const int E_DVDLowParentalLevel = unchecked((int)0x8004028A);
        public const int E_DVDNotInKaraokeMode = unchecked((int)0x8004028B);
        public const int S_DVDChannelContentsNotAvailable = unchecked((int)0x0004028C);
        public const int S_DVDNotAccurate = unchecked((int)0x0004028D);
        public const int E_FrameStepUnsupported = unchecked((int)0x8004028E);
        public const int E_DVDStreamDisabled = unchecked((int)0x8004028F);
        public const int E_DVDTitleUnknown = unchecked((int)0x80040290);
        public const int E_DVDInvalidDisc = unchecked((int)0x80040291);
        public const int E_DVDNoResumeInformation = unchecked((int)0x80040292);
        public const int E_PinAlreadyBlockedOnThisThread = unchecked((int)0x80040293);
        public const int E_PinAlreadyBlocked = unchecked((int)0x80040294);
        public const int E_CertificationFailure = unchecked((int)0x80040295);
        public const int E_VMRNotInMixerMode = unchecked((int)0x80040296);
        public const int E_VMRNoApSupplied = unchecked((int)0x80040297);
        public const int E_VMRNoDeinterlace_HW = unchecked((int)0x80040298);
        public const int E_VMRNoProcAMPHW = unchecked((int)0x80040299);
        public const int E_DVDVMR9IncompatibleDec = unchecked((int)0x8004029A);
        public const int E_NoCOPPHW = unchecked((int)0x8004029B);
    }


    sealed public class DsError
    {
        private DsError()
        {
            // Prevent people from trying to instantiate this class
        }

        [DllImport("quartz.dll", CharSet=CharSet.Auto)]
        public static extern int AMGetErrorText(int hr, StringBuilder buf, int max);

        /// <summary>
        /// If hr has a "failed" status code (E_*), throw an exception.  Note that status
        /// messages (S_*) are not considered failure codes.  If DirectShow error text
        /// is available, it is used to build the exception, otherwise a generic com error
        /// is thrown.
        /// </summary>
        /// <param name="hr">The HRESULT to check</param>
        public static void ThrowExceptionForHR(int hr)
        {
            // If a severe error has occurred
            if (hr < 0)
            {
                string s = GetErrorText(hr);

                // If a string is returned, build a com error from it
                if (s != null)
                {
                    throw new COMException(s, hr);
                }
                else
                {
                    // No string, just use standard com error
                    Marshal.ThrowExceptionForHR(hr);
                }
            }
        }

        /// <summary>
        /// Returns a string describing a DS error.  Works for both error codes
        /// (values < 0) and Status codes (values >= 0)
        /// </summary>
        /// <param name="hr">HRESULT for which to get description</param>
        /// <returns>The string, or null if no error text can be found</returns>
        public static string GetErrorText(int hr)
        {
            const int MAX_ERROR_TEXT_LEN = 160;

            // Make a buffer to hold the string
            StringBuilder buf = new StringBuilder(MAX_ERROR_TEXT_LEN, MAX_ERROR_TEXT_LEN);

            // If a string is returned, build a com error from it
            if (AMGetErrorText(hr, buf, MAX_ERROR_TEXT_LEN) > 0)
            {
                return buf.ToString();
            }

            return null;
        }
    }


    sealed public class DsUtils
    {
        private DsUtils()
        {
            // Prevent people from trying to instantiate this class
        }

        /// <summary>
        /// Returns the PinCategory of the specified pin.  Usually a member of PinCategory.  Not all pins have a category.
        /// </summary>
        /// <param name="pPin"></param>
        /// <returns>Guid indicating pin category or Guid.Empty on no category.  Usually a member of PinCategory</returns>
        public static Guid GetPinCategory(IPin pPin)
        {
            Guid guidRet = Guid.Empty;

            // Memory to hold the returned guid
            int iSize = Marshal.SizeOf(typeof (Guid));
            IntPtr ipOut = Marshal.AllocCoTaskMem(iSize);

            try
            {
                int hr;
                int cbBytes;
                Guid g = PropSetID.Pin;

                // Get an IKsPropertySet from the pin
                IKsPropertySet pKs = pPin as IKsPropertySet;

                if (pKs != null)
                {
                    // Query for the Category
                    hr = pKs.Get(g, (int)AMPropertyPin.Category, IntPtr.Zero, 0, ipOut, iSize, out cbBytes);
                    DsError.ThrowExceptionForHR(hr);

                    // Marshal it to the return variable
                    guidRet = (Guid) Marshal.PtrToStructure(ipOut, typeof (Guid));
                }
            }
            finally
            {
                Marshal.FreeCoTaskMem(ipOut);
                ipOut = IntPtr.Zero;
            }

            return guidRet;
        }

        /// <summary>
        ///  Free the nested structures and release any
        ///  COM objects within an AMMediaType struct.
        /// </summary>
        public static void FreeAMMediaType(AMMediaType mediaType)
        {
            if (mediaType != null)
            {
                if (mediaType.formatSize != 0)
                {
                    Marshal.FreeCoTaskMem(mediaType.formatPtr);
                    mediaType.formatSize = 0;
                    mediaType.formatPtr = IntPtr.Zero;
                }
                if (mediaType.unkPtr != IntPtr.Zero)
                {
                    Marshal.Release(mediaType.unkPtr);
                    mediaType.unkPtr = IntPtr.Zero;
                }
            }
        }

        /// <summary>
        ///  Free the nested interfaces within a PinInfo struct.
        /// </summary>
        public static void FreePinInfo(PinInfo pinInfo)
        {
            if (pinInfo.filter != null)
            {
                Marshal.ReleaseComObject(pinInfo.filter);
                pinInfo.filter = null;
            }
        }

    }


    public class DsROTEntry : IDisposable
    {
        [Flags]
            private enum ROTFlags
        {
            RegistrationKeepsAlive = 0x1,
            AllowAnyClient = 0x2
        }

        private int m_cookie = 0;

        #region APIs
        [DllImport("ole32.dll", ExactSpelling=true)]
#if USING_NET11
        private static extern int GetRunningObjectTable(int r, out UCOMIRunningObjectTable pprot);
#else
        private static extern int GetRunningObjectTable(int r, out IRunningObjectTable pprot);
#endif

        [DllImport("ole32.dll", CharSet=CharSet.Unicode, ExactSpelling=true)]
#if USING_NET11
        private static extern int CreateItemMoniker(string delim, string item, out UCOMIMoniker ppmk);
#else
        private static extern int CreateItemMoniker(string delim, string item, out IMoniker ppmk);
#endif
        #endregion

        public DsROTEntry(IFilterGraph graph)
        {
            int hr = 0;
#if USING_NET11
            UCOMIRunningObjectTable rot = null;
            UCOMIMoniker mk = null;
#else
            IRunningObjectTable rot = null;
            IMoniker mk = null;
#endif
            try
            {
                // First, get a pointer to the running object table
                hr = GetRunningObjectTable(0, out rot);
                DsError.ThrowExceptionForHR(hr);

                // Build up the object to add to the table
                int id = System.Diagnostics.Process.GetCurrentProcess().Id;
                IntPtr iuPtr = Marshal.GetIUnknownForObject(graph);
                int iuInt = (int) iuPtr;
                Marshal.Release(iuPtr);
                string item = string.Format("FilterGraph {0} pid {1}", iuInt.ToString("x8"), id.ToString("x8"));
                hr = CreateItemMoniker("!", item, out mk);
                DsError.ThrowExceptionForHR(hr);

                // Add the object to the table
#if USING_NET11
                rot.Register((int)ROTFlags.RegistrationKeepsAlive, graph, mk, out m_cookie);
#else
                m_cookie = rot.Register((int)ROTFlags.RegistrationKeepsAlive, graph, mk);
#endif
            }
            finally
            {
                if (mk != null)
                {
                    Marshal.ReleaseComObject(mk);
                    mk = null;
                }
                if (rot != null)
                {
                    Marshal.ReleaseComObject(rot);
                    rot = null;
                }
            }
        }

        ~DsROTEntry()
        {
            Dispose();
        }

        public void Dispose()
        {
            if (m_cookie != 0)
            {
                GC.SuppressFinalize(this);
#if USING_NET11
                UCOMIRunningObjectTable rot = null;
#else
                IRunningObjectTable rot = null;
#endif

                // Get a pointer to the running object table
                int hr = GetRunningObjectTable(0, out rot);
                DsError.ThrowExceptionForHR(hr);

                try
                {
                    // Remove our entry
                    rot.Revoke(m_cookie);
                    m_cookie = 0;
                }
                finally
                {
                    Marshal.ReleaseComObject(rot);
                    rot = null;
                }
            }
        }
    }


    public class DsDevice : IDisposable
    {
#if USING_NET11
        private UCOMIMoniker m_Mon;
#else
        private IMoniker m_Mon;
#endif
        private string m_Name;

#if USING_NET11
        public DsDevice(UCOMIMoniker Mon)
#else
        public DsDevice(IMoniker Mon)
#endif
        {
            m_Mon = Mon;
            m_Name = null;
        }

#if USING_NET11
        public UCOMIMoniker Mon
#else
        public IMoniker Mon
#endif
        {
            get
            {
                return m_Mon;
            }
        }

        public string Name
        {
            get
            {
                if (m_Name == null)
                {
                    m_Name = GetFriendlyName();
                }
                return m_Name;
            }
        }

        /// <summary>
        /// Returns a unique identifier for a device
        /// </summary>
        public string DevicePath
        {
            get
            {
                string s = null;

                try
                {
                    m_Mon.GetDisplayName(null, null, out s);
                }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -