public DsGuid GetCLSID()
 {
     return(DsGuid.FromGuid(
                String.IsNullOrEmpty(CLSID)
       ? Guid.Empty
       : new Guid(CLSID)));
 }
Exemple #2
0
        /// <summary>
        ///	 Retrieve a list of crossbar filters in the graph.
        ///  Most hardware devices should have a maximum of 2 crossbars,
        ///  one for video and another for audio.
        /// </summary>
        protected static IEnumerable <IAMCrossbar> findCrossbars(ICaptureGraphBuilder2 graphBuilder, IBaseFilter deviceFilter)
        {
            //var crossbars = new List<IAMCrossbar>();

            DsGuid category = DsGuid.FromGuid(FindDirection.UpstreamOnly);
            DsGuid type     = new DsGuid();
            Guid   riid     = typeof(IAMCrossbar).GUID;

            object comObj     = null;
            object comObjNext = null;

            // Find the first interface, look upstream from the selected device
            int hr = graphBuilder.FindInterface(category, type, deviceFilter, riid, out comObj);

            while ((hr == 0) && (comObj != null))
            {
                // If found, add to the list
                if (comObj is IAMCrossbar)
                {
                    yield return(comObj as IAMCrossbar);

                    //crossbars.Add(comObj as IAMCrossbar);

                    // Find the second interface, look upstream from the next found crossbar
                    hr     = graphBuilder.FindInterface(category, type, comObj as IBaseFilter, riid, out comObjNext);
                    comObj = comObjNext;
                }
                else
                {
                    comObj = null;
                }
            }

            //return (crossbars);
        }
Exemple #3
0
        /// <summary>
        ///	 Retrieve a list of crossbar filters in the graph.
        ///  Most hardware devices should have a maximum of 2 crossbars,
        ///  one for video and another for audio.
        /// </summary>
        protected ArrayList findCrossbars(ICaptureGraphBuilder2 graphBuilder, IBaseFilter deviceFilter)
        {
            ArrayList crossbars = new ArrayList();

            DsGuid category = new DsGuid(FindDirection.UpstreamOnly);
            DsGuid type     = new DsGuid(new Guid());
            Guid   riid     = typeof(IAMCrossbar).GUID;
            int    hr;

            object comObj     = null;
            object comObjNext = null;

            // Find the first interface, look upstream from the selected device
            hr = graphBuilder.FindInterface(category, type, deviceFilter, riid, out comObj);
            while ((hr == 0) && (comObj != null))
            {
                // If found, add to the list
                if (comObj is IAMCrossbar)
                {
                    crossbars.Add(comObj as IAMCrossbar);

                    // Find the second interface, look upstream from the next found crossbar
                    hr     = graphBuilder.FindInterface(category, type, comObj as IBaseFilter, riid, out comObjNext);
                    comObj = comObjNext;
                }
                else
                {
                    comObj = null;
                }
            }

            return(crossbars);
        }
        /// <summary>
        /// Checks the capabilites of a possibe available stream config interface
        /// </summary>
        /// <param name="graph">The stored graph</param>
        /// <param name="capBuilder">The capture graph builder</param>
        private void CheckCapabilitiesStreamConfig(Graph graph, ICaptureGraphBuilder2 capBuilder)
        {
            DsGuid cat = new DsGuid(PinCategory.Capture);
            Guid   iid = typeof(IAMStreamConfig).GUID;
            object o;
            int    hr = capBuilder.FindInterface(cat, null, _filterVideoCapture, iid, out o);

            if (hr == 0)
            {
                _streamConfig = o as IAMStreamConfig;
                if (_streamConfig == null)
                {
                    _imageWidth = -1;
                    _frameRate  = -1;
                }
            }
            else
            {
                _imageWidth = -1;
                _frameRate  = -1;
            }
            graph.Capture.ImageWidth  = _imageWidth;
            graph.Capture.ImageHeight = _imageHeight;
            graph.Capture.FrameRate   = _frameRate;
        }
Exemple #5
0
        public static bool ShowTunerPinDialog(ICaptureGraphBuilder2 bld, IBaseFilter flt, IntPtr hwnd)
        {
            int    hr;
            object comObj = null;
            ISpecifyPropertyPages spec = null;
            DsCAUUID cauuid            = new DsCAUUID();

            try
            {
                DsGuid cat  = PinCategory.Capture;
                DsGuid type = MediaType.Interleaved;
                DsGuid iid  = typeof(IAMTVTuner).GUID;
                hr = bld.FindInterface(cat, type, flt, iid, out comObj);
                if (hr != 0)
                {
                    type = MediaType.Video;
                    hr   = bld.FindInterface(cat, type, flt, iid, out comObj);
                    if (hr != 0)
                    {
                        return(false);
                    }
                }
                spec = comObj as ISpecifyPropertyPages;
                if (spec == null)
                {
                    return(false);
                }

                hr = spec.GetPages(out cauuid);
                hr = OleCreatePropertyFrame(hwnd, 30, 30, null, 1,
                                            ref comObj, cauuid.cElems, cauuid.pElems, 0, 0, IntPtr.Zero);
                return(true);
            }
            catch (Exception ee)
            {
                Trace.WriteLine("!Ds.NET: ShowCapPinDialog " + ee.Message);
                return(false);
            }
            finally
            {
                if (cauuid.pElems != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(cauuid.pElems);
                }

                spec = null;
                if (comObj != null)
                {
                    Marshal.ReleaseComObject(comObj);
                }
                comObj = null;
            }
        }
Exemple #6
0
        private string CapsString()
        {
            var sb = new StringBuilder();

            sb.AppendFormat("{0}, ", DsGuid.GetNickname(Caps.Guid));
            foreach (var info in Caps.GetType().GetFields())
            {
                sb.AppendFormat("{0}={1}, ", info.Name, info.GetValue(Caps));
            }

            return(sb.ToString());
        }
Exemple #7
0
        void GetInterfaces()
        {
            Type   comType = null;
            object comObj  = null;

            try
            {
                //ICaptureGraphBuilder2 pBuilder = null;

                // Initiate Capture Graph Builder
                Guid clsid = typeof(CaptureGraphBuilder2).GUID;
                comType     = Type.GetTypeFromCLSID(clsid);
                comObj      = Activator.CreateInstance(comType);
                m_bCapGraph = (ICaptureGraphBuilder2)comObj;

                // Initiate Graph Builder
                Guid clsfg = typeof(FilterGraph).GUID;
                comType  = Type.GetTypeFromCLSID(clsfg); //Clsid.FilterGraph);
                comObj   = Activator.CreateInstance(comType);
                m_bGraph = (IGraphBuilder)comObj;

                // Initiate Video Configuration Interface
                DsGuid cat  = PinCategory.Capture;
                DsGuid type = MediaType.Interleaved;
                Guid   iid  = typeof(IAMVideoProcAmp).GUID;
                m_bCapGraph.FindInterface(cat, type, capFilter, iid, out comObj);
                m_iVidConfig = (IAMVideoProcAmp)comObj;

                // test
                //m_iVidConfig.Set(VideoProcAmpProperty.WhiteBalance, 0, VideoProcAmpFlags.Manual);


                // Initiate Camera Configuration Interface
                cat  = PinCategory.Capture;
                type = MediaType.Interleaved;
                iid  = typeof(IAMCameraControl).GUID;
                m_bCapGraph.FindInterface(cat, type, capFilter, iid, out comObj);
                m_iCamConfig = (IAMCameraControl)comObj;
            }
            catch (Exception ee)
            {
                if (comObj != null)
                {
                    Marshal.ReleaseComObject(comObj);
                }

                throw new Exception("Could not get interfaces\r\n" + ee.Message);
            }
        }
Exemple #8
0
        /// <summary>
        /// Adds a IWMWriterNetworkSink to the current AsfWriter output filter
        /// </summary>
        /// <param name="streamPort">The port out of which to stream the transcoded file</param>
        private void AddStreamSinkToCurrentOutputFilter(int streamPort)
        {
            int hr;

            DirectShowLib.IServiceProvider pServiceProvider;  // http://msdn.microsoft.com/en-us/library/dd390985%28VS.85%29.aspx
            WMAsfWriter asfwriter = (WMAsfWriter)currentOutputFilter;

            pServiceProvider = (DirectShowLib.IServiceProvider)asfwriter;

            // Get access to WMwriterAdvanced2 object using pServiceProvider  (poss not futureproof)  (see http://groups.google.com/group/microsoft.public.win32.programmer.directx.video/browse_thread/thread/36b154d41cb76ffd/c571d6ef56de11af?#c571d6ef56de11af )
            DsGuid             dsgWMwriterAdvanced2 = DsGuid.FromGuid(new Guid(GUIDs.IWMWriterAdvanced2));
            IWMWriterAdvanced2 WMWriterAdvanced2    = null;
            object             o = null;

            hr = pServiceProvider.QueryService(dsgWMwriterAdvanced2, dsgWMwriterAdvanced2, out o);  // FAILS IN A STA THREAD
            DsError.ThrowExceptionForHR(hr);
            WMWriterAdvanced2 = (IWMWriterAdvanced2)o;

            IWMWriterNetworkSink nsink;

            WMUtils.WMCreateWriterNetworkSink(out nsink);
            NetworkSink = nsink;
            dc.Add(nsink);
            nsink.SetMaximumClients(1);
            nsink.SetNetworkProtocol(NetProtocol.HTTP);

            NetworkSink.Open(ref streamPort);  // Will throw exception if port is in use



            int nSinks;

            WMWriterAdvanced2.GetSinkCount(out nSinks);
            if (nSinks > 0)
            {
                IWMWriterSink pSink = null;
                WMWriterAdvanced2.GetSink(0, out pSink);
                if (pSink != null)
                {
                    WMWriterAdvanced2.RemoveSink(pSink);
                }
                Marshal.ReleaseComObject(pSink);  pSink = null;
            }
            WMWriterAdvanced2.AddSink(NetworkSink);
        }
Exemple #9
0
        void ConfigureASFWriter(WMAsfWriter asf_filter, WTVStreamingVideoRequest strq, FrameSize SourceFrameSize)
        {
            int hr;

            // Now it's added to the graph, configure it with the selected WM Profile
            SendDebugMessage("Getting WM profile with quality of " + strq.Quality.ToString(), 0);
            WindowsMediaLib.IWMProfileManager profileManager;
            WMUtils.WMCreateProfileManager(out profileManager);
            IWMProfile wmProfile;
            string     txtPrxProfile = getPRXProfileForQuality(strq.Quality);

            if (!(string.IsNullOrEmpty(txtPrxProfile)))
            {
                SendDebugMessage("Adjusting WM profile to fit video within designated frame size", 0);
                // SET VIDEO SIZE TO FIT WITHIN THE RIGHT FRAME
                SendDebugMessage("Source video size is " + SourceFrameSize.ToString(), 0);
                FrameSize containerSize = frameSizeForStreamRequest(strq);
                SendDebugMessage("Container size is " + containerSize.ToString(), 0);
                FrameSize newVideoSize = new FrameSize(SourceFrameSize, containerSize);
                SendDebugMessage("Output size is " + newVideoSize.ToString(), 0);
                SetProfileFrameSize(ref txtPrxProfile, newVideoSize);
                SetProfileCustomSettings(ref txtPrxProfile, ref strq); // returns immediately if not custom quality
                SendDebugMessage("Configuring ASF Writer with profile", 0);
                profileManager.LoadProfileByData(txtPrxProfile, out wmProfile);
                WindowsMediaLib.IConfigAsfWriter configWriter = (WindowsMediaLib.IConfigAsfWriter)asf_filter;
                configWriter.ConfigureFilterUsingProfile(wmProfile);
                configWriter.SetIndexMode(true);  // yes index - DEFAULT

                /* Additional config  - TEST
                 * //DirectShowLib.IConfigAsfWriter2 configAsfWriter2 = (DirectShowLib.IConfigAsfWriter2)asf_filter;
                 * //configAsfWriter2.SetParam(ASFWriterConfig.AutoIndex, 0, 0);  // IT IS DEFAULT */



                // (NOT WORKING)
                // SET ANAMORPHIC VIDEO MARKERS WITHIN STREAM (ASPECT RATIO) *******************************
                UInt32 uiAspectX = (UInt32)SourceFrameSize.Width;
                byte[] bAspectX  = BitConverter.GetBytes(uiAspectX);
                UInt32 uiAspectY = (UInt32)SourceFrameSize.Height;
                byte[] bAspectY  = BitConverter.GetBytes(uiAspectY);

                DirectShowLib.IServiceProvider pServiceProvider;  // http://msdn.microsoft.com/en-us/library/dd390985%28VS.85%29.aspx
                pServiceProvider = (DirectShowLib.IServiceProvider)asf_filter;
                DsGuid dsgIWMHeaderinfo = DsGuid.FromGuid(new Guid(GUIDs.IWMWriterAdvanced2));
                object o3 = null;
                hr = pServiceProvider.QueryService(dsgIWMHeaderinfo, dsgIWMHeaderinfo, out o3);  // FAILS IN A STA THREAD
                DsError.ThrowExceptionForHR(hr);
                IWMHeaderInfo headerinfo = (IWMHeaderInfo)o3;

                // Get access to WMwriterAdvanced2 object using pServiceProvider  (poss not futureproof)  (see http://groups.google.com/group/microsoft.public.win32.programmer.directx.video/browse_thread/thread/36b154d41cb76ffd/c571d6ef56de11af?#c571d6ef56de11af )
                DsGuid dsgWMwriterAdvanced2 = DsGuid.FromGuid(new Guid(GUIDs.IWMWriterAdvanced2));
                object o = null;
                hr = pServiceProvider.QueryService(dsgWMwriterAdvanced2, dsgWMwriterAdvanced2, out o);  // FAILS IN A STA THREAD
                DsError.ThrowExceptionForHR(hr);
                IWMWriterAdvanced2 WMWriterAdvanced2 = null;
                WMWriterAdvanced2 = (IWMWriterAdvanced2)o;

                // Get Access to IWMHeaderInfo3 through WMWriterAdvanced2
                object o2 = null;
                //pServiceProvider = (DirectShowLib.IServiceProvider)WMWriterAdvanced2;
                DsGuid dsgIWMHeaderInfo3 = DsGuid.FromGuid(new Guid(GUIDs.IWMHeaderInfo3));
                hr = pServiceProvider.QueryService(dsgWMwriterAdvanced2, dsgIWMHeaderInfo3, out o2); // LET'S SEE
                DsError.ThrowExceptionForHR(hr);
                IWMHeaderInfo3 WMHeaderInfo3 = null;
                WMHeaderInfo3 = (IWMHeaderInfo3)o2;
                short pwIndex;

                // Add Aspect Ratio information
                WMHeaderInfo3.AddAttribute(2, "AspectRatioX", out pwIndex, AttrDataType.DWORD, 0, bAspectX, bAspectX.Length);
                WMHeaderInfo3.AddAttribute(2, "AspectRatioY", out pwIndex, AttrDataType.DWORD, 0, bAspectY, bAspectY.Length);

                // Try with other interface too
                headerinfo.SetAttribute(2, "AspectRatioX", AttrDataType.DWORD, bAspectX, Convert.ToInt16(bAspectX.Length));
                headerinfo.SetAttribute(2, "AspectRatioY", AttrDataType.DWORD, bAspectY, Convert.ToInt16(bAspectY.Length));



                // ************ DEINTERLACE (experimental)
                if (strq.DeInterlaceMode > 0)
                {
                    DeInterlaceModes dimode = DeInterlaceModes.WM_DM_NOTINTERLACED;
                    // Deinterlace Mode
                    if (strq.DeInterlaceMode == 1)
                    {
                        dimode = DeInterlaceModes.WM_DM_DEINTERLACE_NORMAL;
                    }
                    else if (strq.DeInterlaceMode == 2)
                    {
                        dimode = DeInterlaceModes.WM_DM_DEINTERLACE_HALFSIZE;
                    }

                    // Index of video pin
                    int pinIndex = FilterGraphTools.FindPinIndexByMediaType(currentOutputFilter, PinDirection.Input, MediaType.Video, MediaSubType.Null);



                    byte[] bDiMode = BitConverter.GetBytes((int)dimode);
                    short  szOf    = (short)bDiMode.Length;

                    // Set to use deinterlace mode
                    try
                    {
                        WMWriterAdvanced2.SetInputSetting(pinIndex, g_wszDeinterlaceMode, AttrDataType.DWORD, bDiMode, szOf);
                    }
                    catch (Exception ex)
                    {
                        SendDebugMessageWithException("Could not set interlace mode:", ex);
                    }
                }
            }
            else
            {
                SendDebugMessage("Warning - PRX Profile string was empty; using default WM config.");
            }
        }
 public CodecInfo(String codecName, DsGuid codecClsid) :
     this(codecName)
 {
     CLSID = codecClsid.ToString();
 }
Exemple #11
0
        // ------------------ Public Methods --------------------

        /// <summary> Populate the collection by looking for commonly implemented property pages. </summary>
        protected void addFromGraph(
            ICaptureGraphBuilder2 graphBuilder,
            IBaseFilter videoDeviceFilter, IBaseFilter audioDeviceFilter,
            IBaseFilter videoCompressorFilter, IBaseFilter audioCompressorFilter,
            SourceCollection videoSources, SourceCollection audioSources)
        {
            object filter = null;
            DsGuid cat;
            DsGuid med;
            Guid   iid;
            int    hr;

            Trace.Assert(graphBuilder != null);

            // 1. the video capture filter
            addIfSupported(videoDeviceFilter, "Video Capture Device");

            // 2. the video capture pin
            cat = new DsGuid(PinCategory.Capture);
            med = new DsGuid(MediaType.Interleaved);
            iid = typeof(IAMStreamConfig).GUID;
            hr  = graphBuilder.FindInterface(
                cat, med, videoDeviceFilter, iid, out filter);
            if (hr != 0)
            {
                med = MediaType.Video;
                hr  = graphBuilder.FindInterface(
                    cat, med, videoDeviceFilter, iid, out filter);
                if (hr != 0)
                {
                    filter = null;
                }
            }
            addIfSupported(filter, "Video Capture Pin");

            // 3. the video preview pin
            cat = PinCategory.Preview;
            med = MediaType.Interleaved;
            iid = typeof(IAMStreamConfig).GUID;
            hr  = graphBuilder.FindInterface(
                cat, med, videoDeviceFilter, iid, out filter);
            if (hr != 0)
            {
                med = MediaType.Video;
                hr  = graphBuilder.FindInterface(
                    cat, med, videoDeviceFilter, iid, out filter);
                if (hr != 0)
                {
                    filter = null;
                }
            }
            addIfSupported(filter, "Video Preview Pin");

            // 4. the video crossbar(s)
            ArrayList crossbars = new ArrayList();
            int       num       = 1;

            for (int c = 0; c < videoSources.Count; c++)
            {
                CrossbarSource s = videoSources[c] as CrossbarSource;
                if (s != null)
                {
                    if (crossbars.IndexOf(s.Crossbar) < 0)
                    {
                        crossbars.Add(s.Crossbar);
                        if (addIfSupported(s.Crossbar, "Video Crossbar " + (num == 1 ? "" : num.ToString())))
                        {
                            num++;
                        }
                    }
                }
            }
            crossbars.Clear();

            // 5. the video compressor
            addIfSupported(videoCompressorFilter, "Video Compressor");

            // 6. the video TV tuner
            cat = new DsGuid(PinCategory.Capture);
            med = new DsGuid(MediaType.Interleaved);
            iid = typeof(IAMTVTuner).GUID;
            hr  = graphBuilder.FindInterface(
                cat, med, videoDeviceFilter, iid, out filter);
            if (hr != 0)
            {
                med = MediaType.Video;
                hr  = graphBuilder.FindInterface(
                    cat, med, videoDeviceFilter, iid, out filter);
                if (hr != 0)
                {
                    filter = null;
                }
            }
            addIfSupported(filter, "TV Tuner");

            // 7. the video compressor (VFW)
            IAMVfwCompressDialogs compressDialog = videoCompressorFilter as IAMVfwCompressDialogs;

            if (compressDialog != null)
            {
                VfwCompressorPropertyPage page = new VfwCompressorPropertyPage("Video Compressor", compressDialog);
                InnerList.Add(page);
            }

            // 8. the audio capture filter
            addIfSupported(audioDeviceFilter, "Audio Capture Device");

            // 9. the audio capture pin
            cat = new DsGuid(PinCategory.Capture);
            med = new DsGuid(MediaType.Audio);
            iid = typeof(IAMStreamConfig).GUID;
            hr  = graphBuilder.FindInterface(
                cat, med, audioDeviceFilter, iid, out filter);
            if (hr != 0)
            {
                filter = null;
            }
            addIfSupported(filter, "Audio Capture Pin");

            // 9. the audio preview pin
            cat = new DsGuid(PinCategory.Preview);
            med = new DsGuid(MediaType.Audio);
            iid = typeof(IAMStreamConfig).GUID;
            hr  = graphBuilder.FindInterface(
                cat, med, audioDeviceFilter, iid, out filter);
            if (hr != 0)
            {
                filter = null;
            }
            addIfSupported(filter, "Audio Preview Pin");

            // 10. the audio crossbar(s)
            num = 1;
            for (int c = 0; c < audioSources.Count; c++)
            {
                CrossbarSource s = audioSources[c] as CrossbarSource;
                if (s != null)
                {
                    if (crossbars.IndexOf(s.Crossbar) < 0)
                    {
                        crossbars.Add(s.Crossbar);
                        if (addIfSupported(s.Crossbar, "Audio Crossbar " + (num == 1 ? "" : num.ToString())))
                        {
                            num++;
                        }
                    }
                }
            }
            crossbars.Clear();

            // 11. the audio compressor
            addIfSupported(audioCompressorFilter, "Audio Compressor");
        }
Exemple #12
0
        /// <summary>
        ///	 Retrieve a list of crossbar filters in the graph.
        ///  Most hardware devices should have a maximum of 2 crossbars, 
        ///  one for video and another for audio.
        /// </summary>
        protected ArrayList findCrossbars(ICaptureGraphBuilder2 graphBuilder, IBaseFilter deviceFilter)
        {
            ArrayList crossbars = new ArrayList();

                    DsGuid category = FindDirection.DownstreamOnly;
                    DsGuid type = new DsGuid();
                    DsGuid riid = typeof(IAMCrossbar).GUID;
                    int hr;

                    object comObj = null;
                    object comObjNext = null;

                    // Find the first interface, look upstream from the selected device

                    hr = graphBuilder.FindInterface(category, type, deviceFilter, riid, out comObj);

                    while ( (hr == 0) && (comObj != null) )
                    {
                        // If found, add to the list
                        if ( comObj is IAMCrossbar )
                        {
                            crossbars.Add( comObj as IAMCrossbar );

                            // Find the second interface, look upstream from the next found crossbar

                            hr = graphBuilder.FindInterface(category, type, comObj as IBaseFilter, riid, out comObjNext);

                            comObj = comObjNext;
                        }
                        else
                            comObj = null;
                    }

                    return( crossbars );
        }
Exemple #13
0
        private int BuildOVerlayGraph(string sourcestr)
        {
            int hr = 0;
            DirectShowLib.IPin inpin = null, outpin = null;
            Type comtype = null;
            DsGuid guid;

            if (EnableOverlay())
            {
                DirectShowLib.IBaseFilter source = null; // video file demuxer interface
                DirectShowLib.IFileSourceFilter file_source = null; // video source file interface

                // Haali
                //
                // load Haali in the graph
                //
                guid = new DsGuid("55DA30FC-F16B-49FC-BAA5-AE59FC65F82D");// haali
                comtype = System.Type.GetTypeFromCLSID(guid);
                source = (DirectShowLib.IBaseFilter)Activator.CreateInstance(comtype);
                hr = this.graphBuilder.AddFilter(source, "Haali");

                // set the source file for Haali
                //
                file_source = (DirectShowLib.IFileSourceFilter)source;
                DirectShowLib.AMMediaType media = new AMMediaType();
                //media.majorType= DirectShowLib.MediaType.vide;
                hr = file_source.Load(sourcestr, media);
                DsError.ThrowExceptionForHR(hr);

                // BT AVC overlay internal DMO filter
                //
                DirectShowLib.IBaseFilter avc_overlay_dmo_filter = null; // BT audio check
                DirectShowLib.IDMOWrapperFilter avc_overlay_dmo_wrapper = null;

                //guid = new DsGuid("04FE9017-F873-410E-871E-AB91661A4EF7");// FFDShow decoder filter
                DsGuid avc_overlay_guid = new DsGuid("8ac1be3b-70ef-4b0c-ad91-dbe9d41db405"); // BT AVC overlay decoder guid

                avc_overlay_dmo_filter = (DirectShowLib.IBaseFilter)new DMOWrapperFilter();
                avc_overlay_dmo_wrapper = (IDMOWrapperFilter)avc_overlay_dmo_filter;

                /*
                hr = avc_overlay_dmo_wrapper.Init(avc_overlay_guid, DirectShowLib.DMO.DMOCategory.VideoDecoder);
                DMOError.ThrowExceptionForHR(hr);
                */

                // But it is more useful to show how to scan for the DMO
                //Guid g = FindGuid("BT H.264 Decoder", DMOCategory.VideoEffect);

                hr = avc_overlay_dmo_wrapper.Init(avc_overlay_guid, DMOCategory.VideoDecoder);
                DMOError.ThrowExceptionForHR(hr);

                hr = this.graphBuilder.AddFilter(avc_overlay_dmo_filter, "BT AVC Overlay");
                DsError.ThrowExceptionForHR(hr);

                // get the input pin of the video overlay filter
                Global.debuglog("looking for input pin on avc overlay filter", EventArgs.Empty);
                inpin = DsFindPin.ByDirection((DirectShowLib.IBaseFilter)avc_overlay_dmo_filter, PinDirection.Input, 0);
                if (inpin == null)
                    Global.log("!Could not find input pin on Audio Check", EventArgs.Empty);
                else
                    Global.debuglog("found input pin on Audio Check", EventArgs.Empty);

                //find the video output pin of Haali
                outpin = DsFindPin.ByDirection(source, PinDirection.Output, 0);
                //if (!CheckVideo(outpin)) // if the first pin is not the video, use the second pin
                //    outpin = DsFindPin.ByDirection(source, PinDirection.Output, 1);

                // connect haali video output pin (avc) to BT AVC overlay filter
                hr = this.graphBuilder.Connect(outpin, inpin);

                // render the output pin of the AVC overlay filter
                outpin = DsFindPin.ByDirection((DirectShowLib.IBaseFilter)avc_overlay_dmo_filter, PinDirection.Output, 0);

                hr = this.graphBuilder.Render(outpin);
            }

            return hr;
        }
        /// <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);
            }
        }
Exemple #15
0
        /// <summary>
        /// Returns the <see cref="CameraInfo"/> for the given <see cref="DsDevice"/>.
        /// </summary>
        /// <param name="dev">A <see cref="DsDevice"/> to parse name and capabilities for.</param>
        /// <returns>The <see cref="CameraInfo"/> for the given device.</returns>
        private CameraInfo Caps(DsDevice dev)
        {
            var camerainfo = new CameraInfo();

            // Get the graphbuilder object
            var graphBuilder = (IFilterGraph2) new FilterGraph();

            // Get the ICaptureGraphBuilder2
            var capGraph = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

            IBaseFilter capFilter = null;

            try
            {
                int hr = capGraph.SetFiltergraph(graphBuilder);
                DsError.ThrowExceptionForHR(hr);

                // Add the video device
                hr = graphBuilder.AddSourceFilterForMoniker(dev.Mon, null, "Video input", out capFilter);
                //        DsError.ThrowExceptionForHR(hr);

                if (hr != 0)
                {
                    Console.WriteLine("Error in m_graphBuilder.AddSourceFilterForMoniker(). Could not add source filter. Message: " + DsError.GetErrorText(hr));
                    return(null);
                }

                //hr = m_graphBuilder.AddFilter(capFilter, "Ds.NET Video Capture Device");
                //DsError.ThrowExceptionForHR(hr);

                object o    = null;
                DsGuid cat  = PinCategory.Capture;
                DsGuid type = MediaType.Interleaved;
                DsGuid iid  = typeof(IAMStreamConfig).GUID;

                // Check if Video capture filter is in use
                hr = capGraph.RenderStream(cat, MediaType.Video, capFilter, null, null);
                if (hr != 0)
                {
                    return(null);
                }

                //hr = capGraph.FindInterface(PinCategory.Capture, MediaType.Interleaved, capFilter, typeof(IAMStreamConfig).GUID, out o);
                //if (hr != 0)
                //{
                hr = capGraph.FindInterface(PinCategory.Capture, MediaType.Video, capFilter,
                                            typeof(IAMStreamConfig).GUID, out o);
                DsError.ThrowExceptionForHR(hr);
                //}

                var videoStreamConfig = o as IAMStreamConfig;

                int iCount = 0;
                int iSize  = 0;

                try
                {
                    if (videoStreamConfig != null)
                    {
                        videoStreamConfig.GetNumberOfCapabilities(out iCount, out iSize);
                    }
                }
                catch (Exception)
                {
                    //ErrorLogger.ProcessException(ex, false);
                    return(null);
                }

                pscc = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(VideoStreamConfigCaps)));

                camerainfo.Name             = dev.Name;
                camerainfo.DirectshowDevice = dev;

                for (int i = 0; i < iCount; i++)
                {
                    VideoStreamConfigCaps scc;

                    try
                    {
                        AMMediaType curMedType;
                        if (videoStreamConfig != null)
                        {
                            hr = videoStreamConfig.GetStreamCaps(i, out curMedType, pscc);
                        }
                        Marshal.ThrowExceptionForHR(hr);
                        scc = (VideoStreamConfigCaps)Marshal.PtrToStructure(pscc, typeof(VideoStreamConfigCaps));


                        var CSF = new CamSizeFPS();
                        CSF.FPS    = (int)(10000000 / scc.MinFrameInterval);
                        CSF.Height = scc.InputSize.Height;
                        CSF.Width  = scc.InputSize.Width;

                        if (!InSizeFpsList(camerainfo.SupportedSizesAndFPS, CSF))
                        {
                            if (ParametersOK(CSF))
                            {
                                camerainfo.SupportedSizesAndFPS.Add(CSF);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        //ErrorLogger.ProcessException(ex, false);
                    }
                }

                Marshal.FreeCoTaskMem(pscc);
            }
            finally
            {
                if (graphBuilder != null)
                {
                    Marshal.ReleaseComObject(graphBuilder);
                }
                if (capFilter != null)
                {
                    Marshal.ReleaseComObject(capFilter);
                }
                if (capGraph != null)
                {
                    Marshal.ReleaseComObject(capGraph);
                }
            }

            return(camerainfo);
        }
        /// <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.
            try
            {
                IAMPluginControl pc = new DirectShowPluginControl() as IAMPluginControl;
                if (pc != null)
                {
                    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.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());
            }
        }
Exemple #17
0
 public CodecInfo(String codecName, DsGuid codecClsid) :
   this(codecName)
 {
   CLSID = codecClsid.ToString();
 }
 public static IPin FindCapturePin(ref ICaptureGraphBuilder2 captureGraphBuilder, ref IBaseFilter videoDeviceFilter,
                                   ref Guid mediaType)
 {
   IPin pPin = null;
   DsGuid cat = new DsGuid(PinCategory.Capture);
   int hr = captureGraphBuilder.FindPin(videoDeviceFilter, PinDirection.Output, cat, new DsGuid(mediaType), false, 0,
                                        out pPin);
   if (hr >= 0 && pPin != null)
   {
     Log.Info("Found capture pin");
   }
   return pPin;
 }