Exemplo n.º 1
0
        CodecConfiguration.Codec?GetCodecInfo(IBaseFilter filter, string name)
        {
            Guid guid;

            filter.GetClassID(out guid);
            CodecConfiguration.Codec c = new CodecConfiguration.Codec()
            {
                CLSID = guid.ToString("B"), Name = name
            };
            CodecConfiguration.CheckCodec(ref c);
            return(c);
        }
Exemplo n.º 2
0
        public Filter(IBaseFilter ibf)
        {
            basefilter = ibf;
            Guid clsid;

            ibf.GetClassID(out clsid);
            FilterInfo fi;

            ibf.QueryFilterInfo(out fi);
            string strGuid    = Graph.GuidToString(clsid);
            string strCatguid = Graph.GuidToString(FilterCategory.LegacyAmFilterCategory);

            filterProps = new FilterProps(fi.achName, "", strGuid, strCatguid);
            filterProps.MakeFileName();
            filterProps.SetFilter(this);
        }
Exemplo n.º 3
0
        public static string DumpFilterInfo(IBaseFilter filter)
        {
            StringBuilder sb = new StringBuilder();

            int hr;

            sb.AppendLine(">>>>>>> BaseFilter info dump BEGIN");

            {
                Guid guid;
                hr = filter.GetClassID(out guid);
                if (0 == hr)
                {
                    sb.AppendLine("ClassID: " + guid.ToString());
                }
                else
                {
                    sb.AppendLine("ClassID: " + GetErrorText(hr));
                }
            }

            {
                string vendorInfo = null;
                hr = filter.QueryVendorInfo(out vendorInfo);
                if (0 == hr)
                {
                    sb.AppendLine(string.Format("VendorInfo: {0}", vendorInfo));
                }
                else
                {
                    sb.AppendLine("VendorInfo: " + GetErrorText(hr));
                }
            }

            {
                FilterInfo fi;
                hr = filter.QueryFilterInfo(out fi);
                if (0 == hr)
                {
                    sb.AppendLine(string.Format("FilterInfo achName: {0}", fi.achName));
                }
                else
                {
                    sb.AppendLine("FilterInfo achName: " + GetErrorText(hr));
                }
            }

            IFileSourceFilter fileSourceFilter = filter as IFileSourceFilter;

            if (fileSourceFilter != null)
            {
                string      fileName;
                AMMediaType mt = new AMMediaType();
                fileSourceFilter.GetCurFile(out fileName, mt);
                DsUtils.FreeAMMediaType(mt);
                sb.AppendLine("IFileSourceFilter CurFile: " + fileName);
            }

            // Pins info
            {
                IEnumPins enumPins = null;
                IPin[]    pins     = new IPin[1] {
                    null
                };

                try
                {
                    hr = filter.EnumPins(out enumPins);
                    DsError.ThrowExceptionForHR(hr);

                    while (enumPins.Next(1, pins, IntPtr.Zero) == 0)
                    {
                        sb.AppendLine(DumpPinInfo(pins[0]));
                        Util.ReleaseComObject(ref pins[0]);
                    }
                }
                finally
                {
                    Marshal.ReleaseComObject(enumPins);
                }
            }

            sb.AppendLine(">>>>>>> BaseFilter info dump END");

            return(sb.ToString());
        }
        /// <summary>
        /// Get a read-only list of all renderers that are supported on the current system.
        /// </summary>
        public ReadOnlyCollection <Renderer> GetPresentVideoRenderers()
        {
            IList <Renderer> renderers = new List <Renderer>();

            if (_pMapper != null)
            {
                IEnumMoniker pEnum;
                IMoniker[]   pMonikers       = new IMoniker[1];
                Guid         IID_IBaseFilter = typeof(IBaseFilter).GUID;

                Guid[] inTypes = new Guid[] { DirectShow.MediaType.Video, Guid.Empty };
                int    hr      = _pMapper.EnumMatchingFilters(out pEnum,
                                                              0,                  // Reserved
                                                              true,               // Use exact match?
                                                              (int)MERIT.MERIT_DO_NOT_USE,
                                                              true,               // At least one input pin?
                                                              inTypes.Length / 2, // Number of major type/subtype pairs for input
                                                              inTypes,            // Array of major type/subtype pairs for input
                                                              IntPtr.Zero,        // Input medium
                                                              IntPtr.Zero,        // Input pin category
                                                              true,               // Must be a renderer?
                                                              false,              // At least one output pin?
                                                              0,                  // Number of major type/subtype pairs for output
                                                              null,               // Array of major type/subtype pairs for output
                                                              IntPtr.Zero,        // Output medium
                                                              IntPtr.Zero);       // Output pin category
                if (DsHlp.SUCCEEDED(hr))
                {
                    try
                    {
                        object o;
                        IntPtr cFetched = IntPtr.Zero;
                        while (pEnum.Next(1, pMonikers, cFetched) == DsHlp.S_OK)
                        {
                            o = null;
                            Guid clsId = Guid.Empty;

                            try
                            {
                                pMonikers[0].BindToObject(null, null,
                                                          ref IID_IBaseFilter, out o);
                                if (o != null && o is IBaseFilter)
                                {
                                    IBaseFilter pBaseFilter = (IBaseFilter)o;
                                    o = null;

                                    pBaseFilter.GetClassID(out clsId);

                                    Marshal.FinalReleaseComObject(pBaseFilter);
                                }
                            }
                            finally
                            {
                                Marshal.ReleaseComObject(pMonikers[0]);
                            }

                            IRenderer renderer = RendererBase.GetRenderer(clsId);
                            if (renderer != null)
                            {
                                renderers.Add(renderer.Renderer);
                            }
                        }
                    }
                    finally
                    {
                        Marshal.ReleaseComObject(pEnum);
                    }
                }
            }
            return(new ReadOnlyCollection <Renderer>(renderers));
        }
Exemplo n.º 5
0
        DSStreamResultCodes InitWithStreamBufferFile(WTVStreamingVideoRequest strq)
        {
            // Init variables
            //IPin[] pin = new IPin[1];
            IBaseFilter DecFilterAudio   = null;
            IBaseFilter DecFilterVideo   = null;
            IBaseFilter MainAudioDecoder = null;
            IBaseFilter MainVideoDecoder = null;
            string      dPin             = string.Empty;
            string      sName            = string.Empty;
            string      dName            = string.Empty;
            string      sPin             = string.Empty;
            FileInfo    fiInputFile      = new FileInfo(strq.FileName);
            string      txtOutputFNPath  = fiInputFile.FullName + ".wmv";

            if (
                (!fiInputFile.Extension.ToLowerInvariant().Equals(".wtv")) &&
                (!fiInputFile.Extension.ToLowerInvariant().Equals(".dvr-ms"))
                )
            {
                return(DSStreamResultCodes.ErrorInvalidFileType);
            }

            int hr = 0;

            try
            {
                // Get the graphbuilder interface
                SendDebugMessage("Creating Graph Object", 0);
                IGraphBuilder graphbuilder = (IGraphBuilder)currentFilterGraph;

                // Add the DVRMS/WTV file / filter to the graph
                SendDebugMessage("Add SBE Source Filter", 0);

                hr = graphbuilder.AddSourceFilter(fiInputFile.FullName, "SBE Filter", out currentSBEfilter); // class variable
                DsError.ThrowExceptionForHR(hr);
                dc.Add(currentSBEfilter);

                // Get the SBE audio and video out pins
                IPin SBEVidOutPin, SBEAudOutPin;
                SBEAudOutPin = FilterGraphTools.FindPinByMediaType(currentSBEfilter, PinDirection.Output, MediaType.Audio, MediaSubType.Null);
                SBEVidOutPin = FilterGraphTools.FindPinByMediaType(currentSBEfilter, PinDirection.Output, MediaType.Video, MediaSubType.Null);

                // Set up two decrypt filters according to file extension (assume audio and video both present )
                if (fiInputFile.Extension.ToLowerInvariant().Equals(".dvr-ms"))
                {
                    // Add DVR-MS decrypt filters
                    SendDebugMessage("Add DVRMS (bda) decryption", 0);
                    DecFilterAudio = (IBaseFilter) new DTFilter();  // THESE ARE FOR DVR-MS (BDA DTFilters)
                    DecFilterVideo = (IBaseFilter) new DTFilter();
                    graphbuilder.AddFilter(DecFilterAudio, "Decrypt / Tag");
                    graphbuilder.AddFilter(DecFilterVideo, "Decrypt / Tag 0001");
                }
                else  // Add WTV decrypt filters
                {
                    SendDebugMessage("Add WTV (pbda) decryption", 0);
                    DecFilterAudio = FilterDefinition.AddToFilterGraph(FilterDefinitions.Decrypt.DTFilterPBDA, ref graphbuilder);
                    DecFilterVideo = FilterDefinition.AddToFilterGraph(FilterDefinitions.Decrypt.DTFilterPBDA, ref graphbuilder, "PBDA DTFilter 0001");
                }
                dc.Add(DecFilterAudio);
                dc.Add(DecFilterVideo);

                // Make the first link in the graph: SBE => Decrypts
                SendDebugMessage("Connect SBE => Decrypt filters", 0);
                IPin DecVideoInPin = DsFindPin.ByDirection(DecFilterVideo, PinDirection.Input, 0);
                FilterGraphTools.ConnectFilters(graphbuilder, SBEVidOutPin, DecVideoInPin, false);
                IPin DecAudioInPin = DsFindPin.ByDirection(DecFilterAudio, PinDirection.Input, 0);
                if (DecAudioInPin == null)
                {
                    SendDebugMessage("WARNING: No Audio Input to decrypt filter.");
                }
                else
                {
                    FilterGraphTools.ConnectFilters(graphbuilder, SBEAudOutPin, DecAudioInPin, false);
                }

                // Get Dec Audio Out pin
                IPin DecAudioOutPin = DsFindPin.ByDirection(DecFilterAudio, PinDirection.Output, 0);

                // Examine Dec Audio out for audio format
                SendDebugMessage("Examining source audio", 0);
                AMMediaType AudioMediaType = null;
                getPinMediaType(DecAudioOutPin, MediaType.Audio, Guid.Empty, Guid.Empty, ref AudioMediaType);
                SendDebugMessage("Audio media subtype: " + AudioMediaType.subType.ToString());
                SendDebugMessage("Examining Audio StreamInfo");
                StreamInfo si         = FileInformation.GetStreamInfo(AudioMediaType);
                bool       AudioIsAC3 = (si.SimpleType == "AC-3");
                if (AudioIsAC3)
                {
                    SendDebugMessage("Audio type is AC3");
                }
                else
                {
                    SendDebugMessage("Audio type is not AC3");
                }
                si = null;
                DsUtils.FreeAMMediaType(AudioMediaType);

                // Add an appropriate audio decoder
                if (AudioIsAC3)
                {
                    if (!FilterGraphTools.IsThisComObjectInstalled(FilterDefinitions.Audio.AudioDecoderMPCHC.CLSID))
                    {
                        SendDebugMessage("Missing AC3 Audio Decoder, and AC3 audio detected.");
                        return(DSStreamResultCodes.ErrorAC3CodecNotFound);
                    }
                    else
                    {
                        MainAudioDecoder = FilterDefinition.AddToFilterGraph(FilterDefinitions.Audio.AudioDecoderMPCHC, ref graphbuilder);   //MainAudioDecoder = FatAttitude.WTVTranscoder.FilterDefinitions.Audio.AudioDecoderFFDShow.AddToFilterGraph(ref graph);
                        Guid tmpGuid; MainAudioDecoder.GetClassID(out tmpGuid);
                        SendDebugMessage("Main Audio decoder CLSID is " + tmpGuid.ToString());
                    }
                }
                else
                {
                    MainAudioDecoder = FilterDefinition.AddToFilterGraph(FilterDefinitions.Audio.AudioDecoderMSDTV, ref graphbuilder);
                }

                // Add a video decoder
                SendDebugMessage("Add DTV decoder", 0);
                MainVideoDecoder = FilterDefinition.AddToFilterGraph(FilterDefinitions.Video.VideoDecoderMSDTV, ref graphbuilder);
                dc.Add(MainAudioDecoder);
                dc.Add(MainVideoDecoder);

                //SetAudioDecoderOutputToPCMStereo(MainAudioDecoder);

                // Add a null renderer
                SendDebugMessage("Add null renderer", 0);
                NullRenderer MyNullRenderer = new NullRenderer();
                dc.Add(MyNullRenderer);
                hr = graphbuilder.AddFilter((IBaseFilter)MyNullRenderer, @"Null Renderer");
                DsError.ThrowExceptionForHR(hr);

                // Link up video through to null renderer
                SendDebugMessage("Connect video to null renderer", 0);
                // Make the second link:  Decrypts => DTV
                IPin DecVideoOutPin = DsFindPin.ByDirection(DecFilterVideo, PinDirection.Output, 0);
                IPin DTVVideoInPin  = DsFindPin.ByName(MainVideoDecoder, @"Video Input"); // IPin DTVVideoInPin = DsFindPin.ByDirection(DTVVideoDecoder, PinDirection.Input, 0);  // first one should be video input?  //
                FilterGraphTools.ConnectFilters(graphbuilder, DecVideoOutPin, DTVVideoInPin, false);
                // 3. DTV => Null renderer
                IPin NullRInPin     = DsFindPin.ByDirection((IBaseFilter)MyNullRenderer, PinDirection.Input, 0);
                IPin DTVVideoOutPin = FilterGraphTools.FindPinByMediaType(MainVideoDecoder, PinDirection.Output, MediaType.Video, MediaSubType.Null);
                FilterGraphTools.ConnectFilters(graphbuilder, DTVVideoOutPin, NullRInPin, false);
                Marshal.ReleaseComObject(NullRInPin); NullRInPin = null;

                // Run graph [can use this also to get media type => see, e.g. dvrmstowmvhd by Babgvant]
                SendDebugMessage("Run graph for testing purposes", 0);
                IMediaControl tempControl = (IMediaControl)graphbuilder;
                IMediaEvent   tempEvent   = (IMediaEvent)graphbuilder;
                DsError.ThrowExceptionForHR(tempControl.Pause());
                DsError.ThrowExceptionForHR(tempControl.Run());
                EventCode pEventCode;
                hr = tempEvent.WaitForCompletion(1000, out pEventCode);
                //DsError.ThrowExceptionForHR(hr);  // DO *NOT* DO THIS HERE!  THERE MAY WELL BE AN ERROR DUE TO EVENTS RAISED BY THE STREAM BUFFER ENGINE, THIS IS A DELIBERATE TEST RUN OF THE GRAPH
                // Stop graph if necessary
                FilterState pFS;
                hr = tempControl.GetState(1000, out pFS);
                if (pFS == FilterState.Running)
                {
                    DsError.ThrowExceptionForHR(tempControl.Stop());
                }

                // Remove null renderer
                hr = graphbuilder.RemoveFilter((IBaseFilter)MyNullRenderer);

                // Now graph has been run and stopped we can get the video width and height from the output pin of the main video decoder
                AMMediaType pmt = null;
                getPinMediaType(DTVVideoOutPin, MediaType.Video, MediaSubType.YUY2, Guid.Empty, ref pmt);
                FrameSize SourceFrameSize;
                if (pmt.formatType == FormatType.VideoInfo2)
                {
                    VideoInfoHeader2 pvih2 = new VideoInfoHeader2();
                    Marshal.PtrToStructure(pmt.formatPtr, pvih2);
                    int VideoWidth  = pvih2.BmiHeader.Width;
                    int VideoHeight = pvih2.BmiHeader.Height;
                    SourceFrameSize = new FrameSize(VideoWidth, VideoHeight);
                }
                else
                {
                    SourceFrameSize = new FrameSize(320, 240);
                }

                // Free up
                DsUtils.FreeAMMediaType(pmt); pmt = null;

                // Link up audio
                // 2. Audio Decrypt -> Audio decoder
                IPin MainAudioInPin = DsFindPin.ByDirection(MainAudioDecoder, PinDirection.Input, 0);
                FilterGraphTools.ConnectFilters(graphbuilder, DecAudioOutPin, MainAudioInPin, false);

                // Add ASF Writer
                // Create an ASF writer filter
                SendDebugMessage("Creating ASF Writer", 0);
                WMAsfWriter asf_filter = new WMAsfWriter();
                dc.Add(asf_filter);                            // CHECK FOR ERRORS
                currentOutputFilter = (IBaseFilter)asf_filter; // class variable
                // Add the ASF filter to the graph
                hr = graphbuilder.AddFilter((IBaseFilter)asf_filter, "WM Asf Writer");
                DsError.ThrowExceptionForHR(hr);

                // Set the filename
                IFileSinkFilter sinkFilter = (IFileSinkFilter)asf_filter;
                string          destPathFN = fiInputFile.FullName + ".wmv";
                hr = sinkFilter.SetFileName(destPathFN, null);
                DsError.ThrowExceptionForHR(hr);

                // Make the final links:  DTV => writer
                SendDebugMessage("Linking audio/video through to decoder and writer", 0);
                IPin DTVAudioOutPin   = DsFindPin.ByDirection(MainAudioDecoder, PinDirection.Output, 0);
                IPin ASFAudioInputPin = FilterGraphTools.FindPinByMediaType((IBaseFilter)asf_filter, PinDirection.Input, MediaType.Audio, MediaSubType.Null);
                IPin ASFVideoInputPin = FilterGraphTools.FindPinByMediaType((IBaseFilter)asf_filter, PinDirection.Input, MediaType.Video, MediaSubType.Null);
                FilterGraphTools.ConnectFilters(graphbuilder, DTVAudioOutPin, ASFAudioInputPin, false);
                if (ASFVideoInputPin != null)
                {
                    FilterGraphTools.ConnectFilters(graphbuilder, DTVVideoOutPin, ASFVideoInputPin, false);
                }

                // Configure ASFWriter
                ConfigureASFWriter(asf_filter, strq, SourceFrameSize);

                // Release pins
                SendDebugMessage("Releasing COM objects (pins)", 0);
                // dec
                Marshal.ReleaseComObject(DecAudioInPin); DecAudioInPin   = null;
                Marshal.ReleaseComObject(DecVideoInPin); DecVideoInPin   = null;
                Marshal.ReleaseComObject(DecVideoOutPin); DecVideoOutPin = null;
                Marshal.ReleaseComObject(DecAudioOutPin); DecAudioOutPin = null;
                // dtv
                Marshal.ReleaseComObject(MainAudioInPin); MainAudioInPin = null;
                Marshal.ReleaseComObject(DTVVideoInPin); DTVVideoInPin   = null;
                Marshal.ReleaseComObject(DTVVideoOutPin); DTVVideoOutPin = null;
                Marshal.ReleaseComObject(DTVAudioOutPin); DTVAudioOutPin = null;
                // asf
                Marshal.ReleaseComObject(ASFAudioInputPin); ASFAudioInputPin = null;
                Marshal.ReleaseComObject(ASFVideoInputPin); ASFVideoInputPin = null;
            }
            catch (Exception ex)
            {
                SendDebugMessageWithException(ex.Message, ex);
                return(DSStreamResultCodes.ErrorExceptionOccurred);
            }

            return(DSStreamResultCodes.OK);
        }
Exemplo n.º 6
0
 private static Merit GetMerit(IBaseFilter filter)
 {
   Guid clsid;
   int hr;
   hr = filter.GetClassID(out clsid);
   if (hr != 0)
   {
     return Merit.DoNotUse;
   }
   //check cache
   if (_meritCache.ContainsKey(clsid))
   {
     return _meritCache[clsid];
   }
   //figure new value
   try
   {
     RegistryKey filterKey =
       Registry.ClassesRoot.OpenSubKey(@"CLSID\{083863F1-70DE-11d0-BD40-00A0C911CE86}\Instance\{" + clsid.ToString() +
                                       @"}");
     if (filterKey == null)
     {
       Log.Debug("Could not get merit value for clsid {0}, key not found!", clsid);
       _meritCache[clsid] = Merit.DoNotUse;
       return Merit.DoNotUse;
     }
     Byte[] filterData = (Byte[])filterKey.GetValue("FilterData", 0x0);
     if (filterData == null || filterData.Length < 8)
     {
       return Merit.DoNotUse;
     }
     Byte[] merit = new Byte[4];
     //merit is 2nd DWORD, reverse byte order
     Array.Copy(filterData, 4, merit, 0, 4);
     uint dwMerit = ReverseByteArrayToDWORD(merit);
     _meritCache[clsid] = (Merit)dwMerit;
     return (Merit)dwMerit;
   }
   catch (Exception e)
   {
     Log.Debug("Could not get merit value for clsid {0}. Error: {1}", clsid, e.Message);
     return Merit.DoNotUse;
   }
 }
 CodecConfiguration.Codec? GetCodecInfo(IBaseFilter filter, string name)
 {
     Guid guid;
     filter.GetClassID(out guid);
     CodecConfiguration.Codec c = new CodecConfiguration.Codec() { CLSID = guid.ToString("B"), Name = name };
     CodecConfiguration.CheckCodec(ref c);
     return c;
 }