예제 #1
0
 public GenericFilter(Predicate <T> filterFunction)
 {
     this.filterFunction = filterFunction;
     this.InputPin       = new PinIn <T>(this);
     this.SuccessPin     = new PinOut <T>();
     this.FailurePin     = new PinOut <T>();
 }
예제 #2
0
        public GenericDelay(TimeSpan interval)
        {
            InputPin  = new PinIn <T>(this);
            OutputPin = new PinOut <T>();

            this.interval = interval;
            next          = DateTime.Now;
        }
예제 #3
0
        //static void Main(string[] args)
        //{
        //    //GameOfLifeSource golSrc = new GameOfLifeSource(1680, 1050);
        //    GameOfLifeSource golSrc = new GameOfLifeSource(840, 525); // 1680 x 1050 / 2
        //    //GameOfLifeSource golSrc = new GameOfLifeSource(560, 350); // 1680 x 1050 / 3
        //    //GameOfLifeSource golSrc = new GameOfLifeSource(336, 210); // 1680 x 1050 / 5
        //    GenericDelay<Image> delayFilt = new GenericDelay<Image>(new TimeSpan(0, 0, 0, 0, 100));
        //    //WallpaperFilter wpFilt = new WallpaperFilter();
        //    DisplayFilter displayFilt = new DisplayFilter();

        //    golSrc.OutputPin.AttachTo(delayFilt.InputPin);
        //    delayFilt.OutputPin.AttachTo(displayFilt.InputPin);
        //    displayFilt.OutputPin.AttachTo(golSrc.InputPin);

        //    PinOut<Image> golSrcOut = new PinOut<Image>();
        //    golSrcOut.AttachTo(golSrc.InputPin);
        //    golSrcOut.Send(null);
        //    //golSrcOut.Send(null);
        //    //golSrcOut.Send(null);
        //    //golSrcOut.Send(null);
        //    Console.ReadLine();
        //}

        static void Main(string[] args)
        {
            RedditSource          redditSource = new RedditSource("http://www.reddit.com/r/pics/.json");
            GenericFilter <Image> sizeFilt     = new GenericFilter <Image>(img => 100 < img.Width && img.Width < 1000 && 100 < img.Height && img.Height < 800);
            BorderFilter          brdInnerFilt = new BorderFilter(Color.Black, 1);
            BorderFilter          brdOuterFilt = new BorderFilter(Color.White, 9);
            RotateFilter          rotFilt      = new RotateFilter(-30, 30);
            CanvasFilter          cvsFilt      = new CanvasFilter();
            GenericDelay <Image>  delayFilt    = new GenericDelay <Image>(new TimeSpan(0, 0, 30));
            WallpaperFilter       wpFilt       = new WallpaperFilter();

            redditSource.OutputPin.AttachTo(sizeFilt.InputPin);
            sizeFilt.SuccessPin.AttachTo(brdInnerFilt.InputPin);
            sizeFilt.FailurePin.AttachTo(redditSource.InputPin);
            brdInnerFilt.OutputPin.AttachTo(brdOuterFilt.InputPin);
            brdOuterFilt.OutputPin.AttachTo(rotFilt.InputPin);
            rotFilt.OutputPin.AttachTo(cvsFilt.PictureInputPin);
            cvsFilt.OutputPin.AttachTo(delayFilt.InputPin);
            cvsFilt.OutputPin.AttachTo(cvsFilt.CanvasInputPin);
            delayFilt.OutputPin.AttachTo(wpFilt.InputPin);
            wpFilt.OutputPin.AttachTo(redditSource.InputPin);

            /* prime canvas */
            PinOut <Image> canvasOut = new PinOut <Image>();

            canvasOut.AttachTo(cvsFilt.CanvasInputPin);
            Image canvas;

            try
            {
                int          bytesRead;
                byte[]       buf = new byte[1024];
                FileStream   fs  = new FileStream(Path.Combine(Environment.CurrentDirectory, "wall.bmp"), FileMode.Open);
                MemoryStream ms  = new MemoryStream();
                while ((bytesRead = fs.Read(buf, 0, 1024)) > 0)
                {
                    ms.Write(buf, 0, bytesRead);
                }
                ms.Seek(0, SeekOrigin.Begin);
                fs.Close();
                canvas = Image.FromStream(ms);
            }
            catch (FileNotFoundException)
            {
                Size monitorSize = SystemInformation.PrimaryMonitorSize;
                canvas = new Bitmap(monitorSize.Width, monitorSize.Height);
            }
            canvasOut.Send(canvas);

            PinOut <Image> ljSrcOut = new PinOut <Image>();

            ljSrcOut.AttachTo(redditSource.InputPin);
            ljSrcOut.Send(null); /* only need a signal to kick off the source */
            ljSrcOut.Send(null); /* put two images in the loop to test multithreading */
            //ljSrcOut.Send(null); /* hell, why not three? */
            //ljSrcOut.Send(null); /* we are approaching levels of insanity heretofore untold */
            Console.ReadLine();
        }
예제 #4
0
        public RotateFilter(float minAngle, float maxAngle)
        {
            InputPin  = new PinIn <Image>(this);
            OutputPin = new PinOut <Image>();
            random    = new Random();

            this.minAngle = minAngle;
            this.maxAngle = maxAngle;
        }
예제 #5
0
        public CanvasFilter()
        {
            PictureInputPin = new PinIn <Image>(this);
            CanvasInputPin  = new PinIn <Image>(this);
            OutputPin       = new PinOut <Image>();

            pic    = null;
            canvas = null;
            random = new Random();
        }
예제 #6
0
        //static void Main(string[] args)
        //{
        //    //GameOfLifeSource golSrc = new GameOfLifeSource(1680, 1050);
        //    GameOfLifeSource golSrc = new GameOfLifeSource(840, 525); // 1680 x 1050 / 2
        //    //GameOfLifeSource golSrc = new GameOfLifeSource(560, 350); // 1680 x 1050 / 3
        //    //GameOfLifeSource golSrc = new GameOfLifeSource(336, 210); // 1680 x 1050 / 5
        //    GenericDelay<Image> delayFilt = new GenericDelay<Image>(new TimeSpan(0, 0, 0, 0, 100));
        //    //WallpaperFilter wpFilt = new WallpaperFilter();
        //    DisplayFilter displayFilt = new DisplayFilter();
        //    golSrc.OutputPin.AttachTo(delayFilt.InputPin);
        //    delayFilt.OutputPin.AttachTo(displayFilt.InputPin);
        //    displayFilt.OutputPin.AttachTo(golSrc.InputPin);
        //    PinOut<Image> golSrcOut = new PinOut<Image>();
        //    golSrcOut.AttachTo(golSrc.InputPin);
        //    golSrcOut.Send(null);
        //    //golSrcOut.Send(null);
        //    //golSrcOut.Send(null);
        //    //golSrcOut.Send(null);
        //    Console.ReadLine();
        //}
        static void Main(string[] args)
        {
            RedditSource redditSource = new RedditSource("http://www.reddit.com/r/pics/.json");
            GenericFilter<Image> sizeFilt = new GenericFilter<Image>(img => 100 < img.Width && img.Width < 1000 && 100 < img.Height && img.Height < 800);
            BorderFilter brdInnerFilt = new BorderFilter(Color.Black, 1);
            BorderFilter brdOuterFilt = new BorderFilter(Color.White, 9);
            RotateFilter rotFilt = new RotateFilter(-30, 30);
            CanvasFilter cvsFilt = new CanvasFilter();
            GenericDelay<Image> delayFilt = new GenericDelay<Image>(new TimeSpan(0, 0, 30));
            WallpaperFilter wpFilt = new WallpaperFilter();

            redditSource.OutputPin.AttachTo(sizeFilt.InputPin);
            sizeFilt.SuccessPin.AttachTo(brdInnerFilt.InputPin);
            sizeFilt.FailurePin.AttachTo(redditSource.InputPin);
            brdInnerFilt.OutputPin.AttachTo(brdOuterFilt.InputPin);
            brdOuterFilt.OutputPin.AttachTo(rotFilt.InputPin);
            rotFilt.OutputPin.AttachTo(cvsFilt.PictureInputPin);
            cvsFilt.OutputPin.AttachTo(delayFilt.InputPin);
            cvsFilt.OutputPin.AttachTo(cvsFilt.CanvasInputPin);
            delayFilt.OutputPin.AttachTo(wpFilt.InputPin);
            wpFilt.OutputPin.AttachTo(redditSource.InputPin);

            /* prime canvas */
            PinOut<Image> canvasOut = new PinOut<Image>();
            canvasOut.AttachTo(cvsFilt.CanvasInputPin);
            Image canvas;
            try
            {
                int bytesRead;
                byte[] buf = new byte[1024];
                FileStream fs = new FileStream(Path.Combine(Environment.CurrentDirectory, "wall.bmp"), FileMode.Open);
                MemoryStream ms = new MemoryStream();
                while ((bytesRead = fs.Read(buf, 0, 1024)) > 0)
                    ms.Write(buf, 0, bytesRead);
                ms.Seek(0, SeekOrigin.Begin);
                fs.Close();
                canvas = Image.FromStream(ms);
            }
            catch (FileNotFoundException)
            {
                Size monitorSize = SystemInformation.PrimaryMonitorSize;
                canvas = new Bitmap(monitorSize.Width, monitorSize.Height);
            }
            canvasOut.Send(canvas);

            PinOut<Image> ljSrcOut = new PinOut<Image>();
            ljSrcOut.AttachTo(redditSource.InputPin);
            ljSrcOut.Send(null); /* only need a signal to kick off the source */
            ljSrcOut.Send(null); /* put two images in the loop to test multithreading */
            //ljSrcOut.Send(null); /* hell, why not three? */
            //ljSrcOut.Send(null); /* we are approaching levels of insanity heretofore untold */
            Console.ReadLine();
        }
예제 #7
0
        public DisplayFilter()
        {
            InputPin  = new PinIn <Image>(this);
            OutputPin = new PinOut <Image>();

            dff = new DisplayFilterForm();

            Thread thr = new Thread(new ParameterizedThreadStart(DispForm));

            thr.IsBackground = true;
            thr.Start(dff);
        }
예제 #8
0
            public Shift595N(int SDIPin, int SRCLKPin, int CLKPin, int NumOfRegisters)
            {
                this.PinSDI   = new PinOut(SDIPin);
                this.PinRCLK  = new PinOut(CLKPin);
                this.PinSRCLK = new PinOut(SRCLKPin);

                //calculate the number of bits that need to be set
                PinQT = NumOfRegisters * 8 - 1;

                currentstate = new BitArray(PinQT + 1);

                allEnabled(false);
            }
예제 #9
0
        public BorderFilter(Color borderColor, int borderSize)
        {
            if (borderSize < 0)
            {
                throw new ArgumentException("borderWidth must be positive");
            }

            InputPin  = new PinIn <Image>(this);
            OutputPin = new PinOut <Image>();

            this.borderColor = borderColor;
            this.borderSize  = borderSize;
        }
            public Shift165N(int PLPin, int CPPin, int CEPin, int Q7Pin, int NumOfRegisters)
            {
                this.PinPL = new PinOut(PLPin);
                this.PinCP = new PinOut(CPPin);
                this.PinCE = new PinOut(CEPin);
                this.PinQ7 = new PinIn(Q7Pin);

                //calculate the number of bits that need to be set
                PinQT = NumOfRegisters * 8 - 1;

                this.currentstate = new BitArray(PinQT + 1);

                read();
                this.timer = ThreadPoolTimer.CreatePeriodicTimer(Timer_tick, TimeSpan.FromMilliseconds(125));
            }
예제 #11
0
        /*
         * TIVO Files Pin Mapping (pin name between ||) (NOTE: XXXX changes from each machine and AC3 changes if the audio codec changes)
         *  Audio       -> Source Pin |Output| -> MainConcept MPEG DeMultiplexer |Input| |AC3 (PID XXXX @ Prog# 1)|    -> Dump |Input|
         *  Video       -> Source Pin |Output| -> MainConcept MPEG DeMultiplexer |Input| |Video (PID XXXX @ Prog# 1)|  -> Dump |Input|
         */
        public void BuildGraph()
        {
            int hr;

            IntPtr    fetched  = IntPtr.Zero;
            IntPtr    fetched2 = IntPtr.Zero;
            IEnumPins FilterPins;

            IPin[] pins = new IPin[1];
            string PinID;

            // TiVO Directshow filters are only accessible through userspace otherwise decryption fails, so if we are running the engine as a service (instead of command line) we should prompt the user
            if ((_Ext == "tivo") && GlobalDefs.IsEngineRunningAsService)
            {
                _jobLog.WriteEntry(this, "You need to start MCEBuddy engine as a Command line program. TiVO Desktop Directshow decryption filters do not work with a Windows Service.", Log.LogEntryType.Error);
            }

            // Create the source filter for dvrms or wtv or TIVO (will automatically connect to TIVODecryptorTag in source itself)
            _jobLog.WriteEntry(this, "Loading file using DirectShow source filter", Log.LogEntryType.Debug);
            hr = _gb.AddSourceFilter(_SourceFile, "Source Filter", out _SourceF);
            checkHR(hr);

            // If this is a TIVO while, while the source filter automatically decrypts the inputs we need to connect the MPEG demultiplexer to get the audio and video output pins
            if (_Ext == "tivo")
            {
                IPin               PinOut, PinIn;
                IntPtr             ptr;
                PinInfo            demuxPinInfo;
                List <IBaseFilter> filterList = new List <IBaseFilter>();

                // Check if the source filter is a TiVO source filter (otherwise sometimes it tries to use the normal source filter which will fail since the stream in encrypted)
                string     vendorInfo;
                FilterInfo filterInfo;

                _SourceF.QueryFilterInfo(out filterInfo);
                _SourceF.QueryVendorInfo(out vendorInfo);

                _jobLog.WriteEntry(this, "TiVO Source filter loaded by Directshow -> " + filterInfo.achName + " (" + vendorInfo + ")", Log.LogEntryType.Debug);

                if (vendorInfo == null || !vendorInfo.ToLower().Contains("tivo"))
                {
                    string exception = "";

                    // Check if you are running 64Bit MCEBuddy, TiVO needs 32bit MCEBuddy since TiVO directshow dll are 32bit and can only be loaded by 32bit processes
                    if (IntPtr.Size == 8)
                    {
                        exception += "You need to run 32bit MCEBuddy, TiVO Directshow fiters cannot be accessed by a 64bit program.";
                    }
                    else
                    {
                        exception += "TiVO Desktop installation not detected by Windows DirectShow.";
                    }

                    throw new Exception(exception); // Get out of here and let the parent know something is wrong
                }

                hr = _SourceF.FindPin("Output", out PinOut); // Get the Source filter pinOut |Output|
                checkHR(hr);

                // When TIVO desktop is installed, Render automatically builds the filter graph with the necessary demuxing filters - we cannot manually add the MainConcept demux filter since the class isn't registered but somehow Render is able to find it and load it (along with other redundant filters like DTV, audio etc which we need to remove)
                _jobLog.WriteEntry(this, "DirectShow building TiVO filter chain", Log.LogEntryType.Debug);
                hr = _gb.Render(PinOut);
                checkHR(hr);

                hr = PinOut.ConnectedTo(out ptr); // Find out which input Pin (Mainconcept Demux filter) the output of the Source Filter is connected to
                checkHR(hr);
                PinIn = (IPin)Marshal.GetObjectForIUnknown(ptr);

                hr = PinIn.QueryPinInfo(out demuxPinInfo); // Get the mainconcept demux filter from the pin
                checkHR(hr);

                demuxPinInfo.filter.QueryFilterInfo(out filterInfo);
                demuxPinInfo.filter.QueryVendorInfo(out vendorInfo);
                _jobLog.WriteEntry(this, "Checking downstream TiVO filter chain starting with TiVO Demux filter -> " + filterInfo.achName + " (" + vendorInfo + ")", Log.LogEntryType.Debug);
                if (!GetFilterChain(demuxPinInfo.filter, PinDirection.Output, filterList)) // Get the list of all downstreams (redudant) filters (like DTV, Audio, video render etc) from the demux filter that were added by the automatic Render function above (check if there are no downstream filters, then TIVO desktop is not installed)
                {
                    throw new Exception("Unable to get TIVO filter chain");
                }

                // Now remove all the filters in the chain downstream after the demux filter from the graph builder (we dont' need them, we will add out own filters later)
                _jobLog.WriteEntry(this, "Removing redundant filters from TiVO filter chain", Log.LogEntryType.Debug);
                foreach (IBaseFilter filter in filterList)
                {
                    filter.QueryFilterInfo(out filterInfo);
                    filter.QueryVendorInfo(out vendorInfo);
                    _jobLog.WriteEntry(this, "Removing filter -> " + filterInfo.achName + " (" + vendorInfo + ")", Log.LogEntryType.Debug);
                    _gb.RemoveFilter(filter);
                    Marshal.FinalReleaseComObject(filter); // Release the COM object
                }

                // Now the TIVO MainConcept Demux Filter is our new "Source" filter
                _SourceF = demuxPinInfo.filter;
            }

            // TODO: We need to find a way to insert a filter which can allow us to select audio streams (e.g. LAV filter, currently it only allows us access to the default audio stream and not multiple audio streams)

            // Cycle through pins, connecting as appropriate
            hr = _SourceF.EnumPins(out FilterPins);
            checkHR(hr);
            while (FilterPins.Next(pins.Length, pins, fetched) == 0)
            {
                IntPtr          ptypes = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(IntPtr)));
                AMMediaType     mtypes;
                IEnumMediaTypes enummtypes;
                IntPtr          ptrEnum;
                pins[0].EnumMediaTypes(out ptrEnum);
                enummtypes = (IEnumMediaTypes)Marshal.GetObjectForIUnknown(ptrEnum);
                while (enummtypes.Next(1, ptypes, fetched2) == 0)
                {
                    /* Extract Audio, Video or Subtitle streams -> References:
                     * http://nate.deepcreek.org.au/svn/DigitalWatch/trunk/bin/MediaTypes.txt
                     * http://msdn.microsoft.com/en-us/library/ms932033.aspx
                     * https://sourceforge.net/p/tsubget/home/Dumping%20a%20Stream/
                     * http://msdn.microsoft.com/en-us/library/windows/desktop/dd695343(v=vs.85).aspx
                     * http://msdn.microsoft.com/en-us/library/windows/desktop/dd390660(v=vs.85).aspx
                     * http://msdn.microsoft.com/en-us/library/windows/desktop/dd407354(v=vs.85).aspx
                     * http://whrl.pl/RcRv5p (extracting Teletext from WTV/DVRMS)
                     */
                    IntPtr ptrStructure = Marshal.ReadIntPtr(ptypes);
                    mtypes = (AMMediaType)Marshal.PtrToStructure(ptrStructure, typeof(AMMediaType));
                    if ((mtypes.majorType == MediaType.Video) ||
                        (mtypes.majorType == MediaType.Audio) ||
                        (mtypes.majorType == MediaType.Mpeg2PES) ||
                        (mtypes.majorType == MediaType.Stream) ||
                        (mtypes.majorType == MediaType.AuxLine21Data) ||
                        (mtypes.majorType == MediaType.VBI) ||
                        (mtypes.majorType == MediaType.MSTVCaption) ||
                        (mtypes.majorType == MediaType.DTVCCData) ||
                        (mtypes.majorType == MediaType.Mpeg2Sections && mtypes.subType == MediaSubType.None && mtypes.formatType == FormatType.None))
                    {
                        string DumpFileName = "";

                        if ((mtypes.majorType == MediaType.Video) && ((_extractMediaType & ExtractMediaType.Video) != 0)) // Video
                        {
                            DumpFileName = Path.Combine(_workPath, Path.GetFileNameWithoutExtension(_SourceFile) + "_VIDEO");
                            _VideoPart   = DumpFileName;
                            _jobLog.WriteEntry(this, "Found Video stream, extracting -> " + DumpFileName, Log.LogEntryType.Debug);
                        }
                        else if (((mtypes.majorType == MediaType.Audio) || // Audio types https://msdn.microsoft.com/en-us/library/windows/desktop/dd390676(v=vs.85).aspx
                                  ((mtypes.majorType == MediaType.Mpeg2PES) && ((mtypes.subType == MediaSubType.DolbyAC3) || (mtypes.subType == MediaSubType.DTS) || (mtypes.subType == MediaSubType.DvdLPCMAudio) || (mtypes.subType == MediaSubType.Mpeg2Audio))) ||
                                  ((mtypes.majorType == MediaType.Stream) && ((mtypes.subType == MediaSubType.DolbyAC3) || (mtypes.subType == MediaSubType.MPEG1Audio) || (mtypes.subType == MediaSubType.Mpeg2Audio) || (mtypes.subType == MediaSubType.DolbyDDPlus) || (mtypes.subType == MediaSubType.MpegADTS_AAC) || (mtypes.subType == MediaSubType.MpegLOAS)))
                                  ) &&
                                 ((_extractMediaType & ExtractMediaType.Audio) != 0))
                        {
                            DumpFileName = Path.Combine(_workPath, Path.GetFileNameWithoutExtension(_SourceFile) + "_AUDIO" + AudioParts.Count.ToString());
                            _AudioParts.Add(DumpFileName);
                            _jobLog.WriteEntry(this, "Found Audio stream, extracting -> " + DumpFileName, Log.LogEntryType.Debug);
                        }
                        else if ((_extractMediaType & ExtractMediaType.Subtitle) != 0)// Subtitles
                        {
                            DumpFileName = Path.Combine(_workPath, Path.GetFileNameWithoutExtension(_SourceFile) + "_SUBTITLE" + SubtitleParts.Count.ToString());
                            SubtitleParts.Add(DumpFileName);
                            _jobLog.WriteEntry(this, "Found Subtitle stream, extracting -> " + DumpFileName, Log.LogEntryType.Debug);
                        }

                        if (!String.IsNullOrWhiteSpace(DumpFileName)) // If we are asked to extract something
                        {
                            hr = pins[0].QueryId(out PinID);
                            ConnectDecryptedDump(PinID, DumpFileName);
                        }
                    }
                    else
                    {
                        // Debug - looking for more subtitle types (very poorly documented by Microsoft)
                        Guid type        = mtypes.majorType;
                        Guid subtype     = mtypes.subType;
                        Guid formattyype = mtypes.formatType;
                    }
                }
                Marshal.FreeCoTaskMem(ptypes); // Free up the memory
            }
        }
예제 #12
0
        public void Receive(PinIn <T> pin, T item)
        {
            PinOut <T> outPin = filterFunction(item) ? SuccessPin : FailurePin;

            outPin.Send(item);
        }
예제 #13
0
 public GenericTransform(Func <T, T> transformFunction)
 {
     this.transformFunction = transformFunction;
     this.InputPin          = new PinIn <T>(this);
     this.OutputPin         = new PinOut <T>();
 }
예제 #14
0
 public WallpaperFilter()
 {
     InputPin  = new PinIn <Image>(this);
     OutputPin = new PinOut <Image>();
 }