Ejemplo n.º 1
0
        public void DoTests()
        {
            int  hr;
            Guid g, g2, g3, gA;

            m_pi = new DirectShowPluginControl() as IAMPluginControl;

            hr = m_pi.GetPreferredClsidByIndex(0, out g, out g2);
            DsError.ThrowExceptionForHR(hr);

            hr = m_pi.GetPreferredClsid(g, out g3);
            DsError.ThrowExceptionForHR(hr);
            Debug.Assert(g3 == g2);

            hr = m_pi.IsDisabled(g2);
            Debug.Assert(hr < 0);

            hr = m_pi.SetDisabled(g2, true);
            DsError.ThrowExceptionForHR(hr);
            hr = m_pi.IsDisabled(g2);
            Debug.Assert(hr >= 0);

            hr = m_pi.GetDisabledByIndex(0, out gA);
            DsError.ThrowExceptionForHR(hr);
            Debug.Assert(gA == g2);

            hr = m_pi.SetDisabled(g2, false);
            DsError.ThrowExceptionForHR(hr);

            hr = m_pi.SetPreferredClsid(g, null);
            DsError.ThrowExceptionForHR(hr);

            hr = m_pi.GetPreferredClsid(g, out g3);
            Debug.Assert(hr < 0);

            hr = m_pi.SetPreferredClsid(g, g2);
            DsError.ThrowExceptionForHR(hr);

            hr = m_pi.GetPreferredClsid(g, out g3);
            DsError.ThrowExceptionForHR(hr);

            Debug.Assert(g3 == g2);

            hr = m_pi.IsLegacyDisabled("asdf.acm"); // W7 has no disabled drivers
            Debug.Assert(hr < 0);                   // see HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DirectShow\DoNotUseDrivers32
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds preferred audio/video codecs.
        /// </summary>
        protected virtual void AddPreferredCodecs()
        {
            VideoSettings settings = ServiceRegistration.Get <ISettingsManager>().Load <VideoSettings>();

            if (settings == null)
            {
                return;
            }

            //IAMPluginControl is supported in Win7 and later only.
            DirectShowPluginControl dspc = null;
            IAMPluginControl        pc   = null;

            try
            {
                dspc = new DirectShowPluginControl();
                pc   = dspc as IAMPluginControl;
                if (pc != null)
                {
                    // Set black list of codecs to ignore, they are known to cause issues like hangs and crashes
                    // MPEG Audio Decoder
                    if (settings.DisabledCodecs != null && settings.DisabledCodecs.Any())
                    {
                        foreach (var disabledCodec in settings.DisabledCodecs)
                        {
                            ServiceRegistration.Get <ILogger>().Info("{0}: Disable codec '{1}'", PlayerTitle, disabledCodec.Name);
                            pc.SetDisabled(disabledCodec.GetCLSID(), true);
                        }
                    }

                    if (settings.Mpeg2Codec != null)
                    {
                        pc.SetPreferredClsid(MediaSubType.Mpeg2Video, settings.Mpeg2Codec.GetCLSID());
                    }

                    if (settings.H264Codec != null)
                    {
                        pc.SetPreferredClsid(MediaSubType.H264, settings.H264Codec.GetCLSID());
                    }

                    if (settings.AVCCodec != null)
                    {
                        pc.SetPreferredClsid(CodecHandler.MEDIASUBTYPE_AVC, settings.AVCCodec.GetCLSID());
                    }

                    if (settings.HEVCCodec != null)
                    {
                        DsGuid clsid = settings.HEVCCodec.GetCLSID();
                        pc.SetPreferredClsid(CodecHandler.MEDIASUBTYPE_HVC1, clsid);
                        pc.SetPreferredClsid(CodecHandler.MEDIASUBTYPE_HEVC, clsid);
                    }

                    if (settings.Splitter != null)
                    {
                        pc.SetPreferredClsid(Guid.Empty, settings.Splitter.GetCLSID());
                    }

                    if (settings.AudioCodecLATMAAC != null)
                    {
                        pc.SetPreferredClsid(CodecHandler.MEDIASUBTYPE_LATM_AAC_AUDIO, settings.AudioCodecLATMAAC.GetCLSID());
                    }

                    if (settings.AudioCodecAAC != null)
                    {
                        pc.SetPreferredClsid(CodecHandler.MEDIASUBTYPE_AAC_AUDIO, settings.AudioCodecAAC.GetCLSID());
                    }

                    if (settings.AudioCodec != null)
                    {
                        DsGuid clsid = settings.AudioCodec.GetCLSID();
                        foreach (Guid guid in new[]
                        {
                            MediaSubType.Mpeg2Audio,
                            MediaSubType.MPEG1AudioPayload,
                            CodecHandler.WMMEDIASUBTYPE_MP3,
                            CodecHandler.MEDIASUBTYPE_MPEG1_AUDIO,
                            CodecHandler.MEDIASUBTYPE_MPEG2_AUDIO
                        })
                        {
                            pc.SetPreferredClsid(guid, clsid);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Debug("{0}: Exception in IAMPluginControl: {1}", PlayerTitle, ex.ToString());
            }
            finally
            {
                FilterGraphTools.TryRelease(ref dspc);
            }
        }