public HomeTheaterFacade(Amplifier amplifier, Tuner tuner, DvdPlayer dvdPlayer, CdPlayer cdPlayer, Projector projector, TheaterLights theaterLights, Screen screen, PopcornPopper popcornPopper)
 {
     _amp       = amplifier;
     _tuner     = tuner;
     _dvd       = dvdPlayer;
     _cd        = cdPlayer;
     _projector = projector;
     _lights    = theaterLights;
     _screen    = screen;
     _popper    = popcornPopper;
 }
Exemplo n.º 2
0
        public static void Main()
        {
            var cb = ChessBoardInstances.Get(0);

            // read all fens, including score
            var fens = Tuner.LoadFens("d:\\backup\\chess\\epds\\violent.epd", false, true);

            Console.WriteLine("Fens found : " + fens.Count);

            // NegamaxUtil.isRunning = true;
            EngineConstants.Power2TtEntries = 1;
            TtUtil.Init(false);

            double totalPositions = 0;
            double sameScore      = 0;
            long   totalError     = 0;
            var    watch          = new Stopwatch();

            watch.Start();
            foreach (var entry in fens)
            {
                ChessBoardUtil.SetFen(entry.Key, cb);
                if (cb.CheckingPieces == 0)
                {
                    continue;
                }

                totalPositions++;
                var searchScore = NegamaxUtil.CalculateBestMove(cb, ThreadData, 0, 1, Util.ShortMin, Util.ShortMax, 0);
                TtUtil.ClearValues();
                var qScore = QuiescenceUtil.CalculateBestMove(cb, ThreadData, Util.ShortMin, Util.ShortMax);

                if (searchScore == qScore)
                {
                    sameScore++;
                }
                else
                {
                    var error = searchScore - qScore;
                    // if (error > 500) {
                    // System.out.println(searchScore + " " + qScore);
                    // QuiescenceUtil.calculateBestMove(cb, threadData, Util.SHORT_MIN, Util.SHORT_MAX);
                    // }

                    totalError += error;
                }
            }

            var averageError = (int)(totalError / (totalPositions - sameScore));

            Console.WriteLine($"{sameScore / totalPositions:f4} {averageError}");
            Console.WriteLine("msec: " + watch.ElapsedMilliseconds);
        }
        public async Task <IActionResult> PostTuner([FromBody] Tuner tuner)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Tuner.Add(tuner);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTuner", new { id = tuner.Id }, tuner));
        }
Exemplo n.º 4
0
        public static async Task Main()
        {
            //U de Mann Whitney utilizando configuración de ejemplo y configuración ajustada.
            var best_configuration = await U_Mann_Whitney.TestConfigurations(new NSGA_III_Configuration(new Vector(new float[] { 92, 100 }), "DTLZ1"), new NSGA_III_Configuration(new Vector(new float[] { 96, 100 }), "DTLZ1"), 50, 450);

            Console.WriteLine(best_configuration != null ? $"La configuración {best_configuration} demostró ser superior estadísticamente." : "No existe suficiente evidencia estadística para afirmar la superioridad de una configuración por sobre la otra.");
            return;

            Console.WriteLine($"Hora de inicio: {DateTime.Now:hh:mm:ss}\n");

            #region Black Hole
            //Punto sobre el cual se centrará la red de hipercubos
            var middle_hyperpoint = new Vector(new float[] { 50, 50 });
            //Longitud de cada dimension para cada hipercubo
            float hypercube_length = 33.3f;
            //Factor por el cual se puede amplificar la longitud de cada dimension de hipercubo
            var factor = 1;
            //Profundidad: Capas de envoltura alrededor del punto central
            var depth = 2;
            //Profundidad interior: Capas de puntos contenidos en el hipercubo
            var inner_depth = 1;
            //Cantidad de generaciones (iteraciones) que realiza la metaheurística de bajo nivel (NSGA-III) en cada evaluación
            var evaluation_duration = 200;
            //Cantidad de épocas (iteraciones) que realiza el algoritmo Black Hole
            var number_of_epochs = 10;
            #endregion

            #region Q-Learning
            //Cantidad de iteraciones por ronda. Cada iteración consiste en seleccionar una acción/configuración (ε-Greedy), evaluarla y recompensarla/castigarla según su resultado.
            var iterations_by_round = 100;
            //Incremento por ronda de la cantidad de generaciones (iteraciones) con las que se evalúa cada acción.
            var duration_step_between_rounds = 250;
            //Cantidad de evaluaciones por semilla aleatoria en cada iteración, las que se promedian y evalúan según su desviación estandar
            var number_of_performances_to_average = 2;
            //Cantidad de generaciones (iteraciones) utilizadas para verificar los resultados obtenidos por el Q-Learning
            var verification_duration = 1000;
            #endregion

            var ProblemName = "DTLZ1";

            var best_configuration_NSGA_II = await Tuner.Run(new NSGA_II_Configuration(middle_hyperpoint, ProblemName), hypercube_length, factor, depth, inner_depth, evaluation_duration, number_of_epochs, iterations_by_round, duration_step_between_rounds, number_of_performances_to_average, verification_duration);

            Console.WriteLine($"\nLa mejor configuración encontrada para el problema {ProblemName} utilizando NSGA-II es: {best_configuration_NSGA_II}\n");

            var best_configuration_NSGA_III = await Tuner.Run(new NSGA_III_Configuration(middle_hyperpoint, ProblemName), hypercube_length, factor, depth, inner_depth, evaluation_duration, number_of_epochs, iterations_by_round, duration_step_between_rounds, number_of_performances_to_average, verification_duration);

            Console.WriteLine($"\nLa mejor configuración encontrada para el problema {ProblemName} utilizando NSGA-III es: {best_configuration_NSGA_III}\n");

            Console.WriteLine($"Hora de termino: {DateTime.Now:hh:mm:ss}");

            return;
        }
Exemplo n.º 5
0
    public override void PrepareToSim()
    {
        Source sourse = schemeObject.boardObject.GetComponent <Source>();

        sourse.GetComponent <BoxCollider>().enabled = false;
        Tuner t = sourse.GetComponentInChildren <Tuner>();

        t.min = sourse.min;
        t.max = sourse.max;
        t.GetDelta();
        t.enabled = true;
        t.GetComponent <CapsuleCollider>().enabled = true;
    }
Exemplo n.º 6
0
        static void Facade()
        {
            Screen            screen    = new Screen();
            Tuner             tuner     = new Tuner();
            DVDPlayer         dvdplayer = new DVDPlayer();
            Popcorn           popcorn   = new Popcorn();
            Amplifier         amp       = new Amplifier();
            HomeTheaterFacade facade    = new HomeTheaterFacade(screen, tuner, dvdplayer, popcorn, amp);

            facade.WatchMovie();
            Console.WriteLine();
            facade.EndMovie();
        }
Exemplo n.º 7
0
 public HomeTheaterFacade(Amplifier amp, Tuner tuner, DvdPlayer dvd,
                          CdPlayer cd, Projector projector, Screen screen,
                          TheaterLights lights, PopcornPopper popper)
 {
     this.amp       = amp;
     this.tuner     = tuner;
     this.dvd       = dvd;
     this.cd        = cd;
     this.projector = projector;
     this.screen    = screen;
     this.lights    = lights;
     this.popper    = popper;
 }
Exemplo n.º 8
0
        private LiveTvTunerInfo GetTunerInformation(Tuner i)
        {
            LiveTvTunerInfo tunerinfo = new LiveTvTunerInfo();

            tunerinfo.Name = i.tunerName;
            tunerinfo.Status = GetStatus(i);

            if (i.recordings.Count > 0)
            {
                tunerinfo.ChannelId = i.recordings.Single().Recording.channelOID.ToString();
            }

            return tunerinfo;
        }
Exemplo n.º 9
0
    private LiveTvTunerInfo GetTunerInformation(Tuner i)
    {
        LiveTvTunerInfo tunerinfo = new LiveTvTunerInfo();

        tunerinfo.Name   = i.TunerName;
        tunerinfo.Status = GetStatus(i);

        if (i.Recordings.Count > 0)
        {
            tunerinfo.ChannelId = i.Recordings.Single().Recording.ChannelOid.ToString(CultureInfo.InvariantCulture);
        }

        return(tunerinfo);
    }
Exemplo n.º 10
0
    private LiveTvTunerStatus GetStatus(Tuner i)
    {
        if (i.Recordings.Count > 0)
        {
            return(LiveTvTunerStatus.RecordingTv);
        }

        if (i.LiveTv.Count > 0)
        {
            return(LiveTvTunerStatus.LiveTv);
        }

        return(LiveTvTunerStatus.Available);
    }
Exemplo n.º 11
0
        private LiveTvTunerInfo GetTunerInformation(Tuner i)
        {
            LiveTvTunerInfo tunerinfo = new LiveTvTunerInfo();

            tunerinfo.Name   = i.tunerName;
            tunerinfo.Status = GetStatus(i);

            if (i.recordings.Count > 0)
            {
                tunerinfo.ChannelId = i.recordings.Single().Recording.channelOID.ToString();
            }

            return(tunerinfo);
        }
Exemplo n.º 12
0
        private LiveTvTunerStatus GetStatus(Tuner i)
        {
            if (i.recordings.Count > 0)
            {
                return LiveTvTunerStatus.RecordingTv;
            }

            if (i.liveTV.Count > 0)
            {
                return LiveTvTunerStatus.LiveTv;
            }

            return LiveTvTunerStatus.Available;
        }
Exemplo n.º 13
0
 public HomeTheatreFacade(
     Amplifier amp,
     Tuner tuner,
     DvdPlayer dvdPlayer,
     Screen screen,
     PopcornPopper popcornPopper
     )
 {
     Amp           = amp;
     Tuner         = tuner;
     DvdPlayer     = dvdPlayer;
     Screen        = screen;
     PopcornPopper = popcornPopper;
 }
Exemplo n.º 14
0
        public static void Main()
        {
            var cb = ChessBoardInstances.Get(0);

            // read all fens, including score
            var fens = Tuner.LoadFens("d:\\backup\\chess\\epds\\violent.epd", false, true);

            Console.WriteLine("Fens found : " + fens.Count);

            double sameScore    = 0;
            double totalAttacks = 0;
            var    start        = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

            foreach (var entry in fens)
            {
                ChessBoardUtil.SetFen(entry.Key, cb);
                _threadData.StartPly();
                MoveGenerator.GenerateAttacks(_threadData, cb);
                while (_threadData.HasNext())
                {
                    var move = _threadData.Next();
                    if (!cb.IsLegal(move))
                    {
                        continue;
                    }

                    totalAttacks++;
                    var seeScore      = SeeUtil.GetSeeCaptureScore(cb, move);
                    var materialScore = EvalUtil.CalculateMaterialScore(cb);
                    var qScore        = ChessConstants.ColorFactor[cb.ColorToMoveInverse] * materialScore -
                                        CalculateQScore(cb, move, true);
                    if (seeScore == qScore)
                    {
                        sameScore++;
                    }

                    // else {
                    // seeScore = SEEUtil.getSeeCaptureScore(cb, move);
                    // qScore = ChessConstants.COLOR_FACTOR[cb.colorToMoveInverse] * materialScore - calculateQScore(cb,
                    // move, true);
                    // }
                }

                _threadData.EndPly();
            }

            Console.WriteLine($"{sameScore:f0} {totalAttacks:f0} = {sameScore / totalAttacks:f4}");
            Console.WriteLine("msec: " + (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - start));
        }
Exemplo n.º 15
0
        private void Facade_Click(object sender, RoutedEventArgs e)
        {
            var theaterLights = new TheaterLights();
            var screen        = new Screen();
            var popcornPopper = new PopcornPopper();
            var projector     = new Projector();
            var dvdPlayer     = new DvdPlayer(projector);
            var tuner         = new Tuner();
            var cdPlayer      = new CdPlayer();
            var amplifier     = new Amplifier(tuner, cdPlayer, dvdPlayer);

            var homeTheaterFacade = new HomeTheaterFacade(amplifier, tuner, cdPlayer, dvdPlayer, theaterLights, screen, popcornPopper);

            homeTheaterFacade.WatchMovie();
        }
Exemplo n.º 16
0
        public void FacadeHomeTheater_SimplifiesInterface()
        {
            Amplifier         amp    = new Amplifier();
            Tuner             tuner  = new Tuner();
            DvdPlayer         dvd    = new DvdPlayer();
            CdPlayer          cd     = new CdPlayer();
            Projector         proj   = new Projector();
            Screen            screen = new Screen();
            TheaterLights     light  = new TheaterLights();
            PopcornPopper     pop    = new PopcornPopper();
            HomeTheaterFacade facade = new HomeTheaterFacade(amp, tuner, dvd, cd, proj, light, screen, pop);

            facade.WatchMovie("Inception");
            facade.endMovie();
        }
Exemplo n.º 17
0
        private static DiseqcHandlerBase createConexantHandler(Tuner tuner, IBaseFilter tunerFilter, bool logMessage)
        {
            ConexantDiseqcHandler conexantHandler = new ConexantDiseqcHandler(tunerFilter, tuner);

            if (conexantHandler.CardCapable)
            {
                return(conexantHandler);
            }

            if (logMessage)
            {
                Logger.Instance.Write("Conexant card is not DiSEqC capable");
            }

            return(null);
        }
Exemplo n.º 18
0
        static void Main(string[] args)
        {
            var amplifier     = new Amplifier();
            var cdPlayer      = new CdPlayer(amplifier);
            var dvdPlayer     = new DvdPlayer(amplifier);
            var tuner         = new Tuner(amplifier);
            var theaterLights = new TheteaterLight();
            var popCornPopper = new PopcornPopper();
            var screen        = new Screen();
            var projector     = new Projector(dvdPlayer);

            HomeTheaterFacade homeTheater = new HomeTheaterFacade(amplifier, tuner, dvdPlayer, cdPlayer,
                                                                  theaterLights, popCornPopper, screen, projector);

            homeTheater.WatchMovie("Mr Bean");
        }
Exemplo n.º 19
0
    static void Main()
    {
        Amplifier     amp       = new Amplifier();
        Tuner         tuner     = new Tuner();
        DvdPlayer     dvd       = new DvdPlayer();
        CdPlayer      cd        = new CdPlayer();
        Projector     projector = new Projector();
        Screen        screen    = new Screen();
        TheaterLights lights    = new TheaterLights();
        PopcornPopper popper    = new PopcornPopper();

        HomeTheaterFacade homeTheater = new HomeTheaterFacade(amp, tuner, dvd, cd, projector, screen, lights, popper);

        homeTheater.WatchMovie("Raiders of the Lost Ark");
        homeTheater.EndMovie();
    }
Exemplo n.º 20
0
        private static DiseqcHandlerBase createTeviiHandler(Tuner tuner, IBaseFilter tunerFilter, bool logMessage)
        {
            TeviiDiseqcHandler teviiHandler = new TeviiDiseqcHandler(tunerFilter, tuner);

            if (teviiHandler.CardCapable)
            {
                return(teviiHandler);
            }

            if (logMessage)
            {
                Logger.Instance.Write("Tevii card is not DiSEqC capable");
            }

            return(null);
        }
Exemplo n.º 21
0
        static void Main(string[] args)
        {
            Amplifier   amplifier   = new Amplifier();
            CD          cd          = new CD();
            DVD         dvd         = new DVD();
            Popper      popper      = new Popper();
            Projector   projector   = new Projector();
            Screen      screen      = new Screen();
            SoundSystem soundSystem = new SoundSystem();
            Tuner       tuner       = new Tuner();
            Control     control     = new Control(new HomeTheater1(popper, screen, projector, amplifier, soundSystem, dvd, cd, tuner));

            control.TurnOnDVD();

            Console.Read();
        }
        public HomeTheatherFacade()
        {
            amp       = new Amplifier();
            tuner     = new Tuner();
            dvd       = new DvdPlayer();
            cd        = new CdPlayer();
            projector = new Projector();
            lights    = new TheaterLights();
            screen    = new Screen();
            popper    = new PopcornPopper();

            lights.Name    = "TheaterLights";
            projector.Name = "Projector";
            amp.Name       = "Amplifier";
            popper.Name    = "Popcorn";
        }
Exemplo n.º 23
0
        private static DVBS2HandlerBase createTBSHandler(IBaseFilter tunerFilter, Tuner tuner, bool logMessage)
        {
            TBSDVBS2Handler tbsHandler = new TBSDVBS2Handler(tunerFilter, tuner);

            if (tbsHandler.DVBS2Capable)
            {
                return(tbsHandler);
            }

            if (logMessage)
            {
                Logger.Instance.Write("TBS card is not DVB-S2 capable");
            }

            return(null);
        }
Exemplo n.º 24
0
        private static void FacadePattern()
        {
            Amplifier     amp       = new Amplifier("amplifier");
            Tuner         tuner     = new Tuner("tuner", amp);
            DvdPlayer     dvd       = new DvdPlayer("Dvd Player", amp);
            CdPlayer      cd        = new CdPlayer("CD Player", amp);
            Projector     projector = new Projector("Projector", dvd);
            Screen        screen    = new Screen("Screen");
            TheaterLights lights    = new TheaterLights("Theater lights");
            PopcornPopper popper    = new PopcornPopper("Popcorn popper");

            HomeTheaterFacade homeTheater = new HomeTheaterFacade(amp, tuner, dvd, cd, projector, screen, lights, popper);

            homeTheater.watchMovie("Raiders of the Lost Ark");
            homeTheater.endMovie();
        }
Exemplo n.º 25
0
        private static void TestFacadePattern()
        {
            string        brand = "Top-O-Line";
            Amplifier     a     = new Amplifier(brand);
            Tuner         t     = new Tuner();
            DvdPlayer     d     = new DvdPlayer(brand);
            CdPlayer      c     = new CdPlayer(brand);
            Projector     p     = new Projector(brand);
            Screen        s     = new Screen();
            TheaterLights l     = new TheaterLights();
            PopcornPopper pp    = new PopcornPopper();

            HomeTheaterFacade homeTheater = new HomeTheaterFacade(a, t, d, c, p, s, l, pp);

            Console.WriteLine(homeTheater.WatchMovie("Black Panther"));
            Console.WriteLine(homeTheater.EndMovie());
        }
Exemplo n.º 26
0
        static void Main(string[] args)
        {
            Amplifier        amp           = new Amplifier();
            DvdPlayer        dvdPlayer     = new DvdPlayer();
            CdPlayer         cdPlayer      = new CdPlayer();
            TheaterLights    lights        = new TheaterLights();
            Projector        projector     = new Projector();
            Screen           screen        = new Screen();
            TheaterLights    theaterLights = new TheaterLights();
            Tuner            tuner         = new Tuner();
            PopcornPopper    popper        = new PopcornPopper();
            HomeSystemFacade homeSystem    = new HomeSystemFacade(amp, tuner, dvdPlayer, cdPlayer, projector,
                                                                  lights, screen, popper);

            homeSystem.watchMovie("Inside out");
            homeSystem.endMovie();
        }
Exemplo n.º 27
0
        void lstMarkers_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            try
            {
                FrequencyMarker marker = GetSelected();

                Tuner tuner = GetTuner();

                if (marker != null && tuner != null)
                {
                    tuner.SetFrequency(marker.Frequency);
                }
            }
            catch (Exception)
            {
            }
        }
Exemplo n.º 28
0
 public void Dispose()
 {
     amp       = null;
     tuner     = null;
     dvd       = null;
     cd        = null;
     projector = null;
     lights    = null;
     screen    = null;
     popper    = null;
     expectedWatchMovieOutput    = null;
     expectedEndMovieOutput      = null;
     expectedListenToCDOutput    = null;
     expectedEndCDOutput         = null;
     expectedListenToRadioOutput = null;
     expectedEndRadioOutput      = null;
     homeTheater = null;
 }
Exemplo n.º 29
0
        static void Main(string[] args)
        {
            Amplifier     _amp       = new Amplifier();
            Tuner         _tuner     = new Tuner();
            DvdPlayer     _dvd       = new DvdPlayer();
            CdPlayer      _cd        = new CdPlayer();
            Progector     _progector = new Progector();
            TheaterLights _lights    = new TheaterLights();
            Screen        _screen    = new Screen();
            PopcornPopper _popper    = new PopcornPopper();

            HomeTheaterFacade homeTheater = new HomeTheaterFacade(_amp, _tuner, _dvd, _cd, _progector, _lights, _screen, _popper);

            homeTheater.WatchMovie("Люди в черном");
            Console.WriteLine("\n\n\n");
            Thread.Sleep(2500);
            homeTheater.EndMovie();
        }
Exemplo n.º 30
0
        static void Main(string[] args)
        {
            var amp       = new Amplifier();
            var tuner     = new Tuner();
            var dvd       = new DvdPlayer();
            var cd        = new CdPlayer();
            var projector = new Projector();
            var screen    = new Screen();
            var lights    = new TheaterLights();
            var popper    = new PopcornPopper();

            HomeTheaterFacade homeTheater = new HomeTheaterFacade(amp, tuner, dvd, cd, projector, screen, lights, popper);

            homeTheater.WatchMovie("Raiders of the Lost Ark");
            homeTheater.EndMovie();

            Console.ReadKey();
        }
Exemplo n.º 31
0
        public void FacadeTest()
        {
            Amplifier     amp       = new Amplifier("Top-O-Line Amplifier");
            Tuner         tuner     = new Tuner("Top-O-Line AM/FM Tuner", amp);
            DvdPlayer     dvd       = new DvdPlayer("Top-O-Line DVD Player", amp);
            CdPlayer      cd        = new CdPlayer("Top-O-Line CD Player", amp);
            Projector     projector = new Projector("Top-O-Line Projector", dvd);
            TheaterLights lights    = new TheaterLights("Theater Ceiling Lights");
            Screen        screen    = new Screen("Theater Screen");
            PopcornPopper popper    = new PopcornPopper("Popcorn Popper");

            HomeTheaterFacade homeTheater =
                new HomeTheaterFacade(amp, tuner, dvd, cd,
                                      projector, screen, lights, popper);

            homeTheater.WatchMovie("Raiders of the Lost Ark");
            homeTheater.EndMovie();
        }
        public static void Test()
        {
            var amp       = new Amplifier();
            var tuner     = new Tuner();
            var dvd       = new DvdPlayer();
            var cd        = new CdPlayer();
            var projector = new Projector();
            var screen    = new Screen();
            var lights    = new TheaterLights();
            var popper    = new PopcornPopper();

            var homeTheaterFacade = new HomeTheaterFacade(
                amp, tuner, dvd, cd, projector, screen, lights, popper
                );

            homeTheaterFacade.WatchMovie("Raiders of the Lost Ark");
            homeTheaterFacade.EndMovie();
        }
Exemplo n.º 33
0
 /// <summary>
 /// Creates the filter by trying to detect it
 /// </summary>
 /// <param name="crossbar">The crossbar componen</param>
 /// <param name="tuner">The tuner component</param>
 /// <param name="graph">The stored graph</param>
 /// <param name="graphBuilder">The graphBuilder</param>
 /// <returns>true, if the graph building was successful</returns>
 private bool CreateAutomaticFilterInstance(Graph graph, Tuner tuner, Crossbar crossbar, IFilterGraph2 graphBuilder)
 {
   //get all tv audio tuner devices on this system
   DsDevice[] devices = null;
   try
   {
     devices = DsDevice.GetDevicesOfCat(FilterCategory.AMKSTVAudio);
     devices = DeviceSorter.Sort(devices, tuner.TunerName, crossbar.CrossBarName);
   }
   catch (Exception)
   {
     Log.Log.WriteFile("analog: AddTvAudioFilter no tv audio devices found - Trying TvTuner filter");
   }
   if (devices != null && devices.Length > 0)
   {
     // try each tv audio tuner
     for (int i = 0; i < devices.Length; i++)
     {
       IBaseFilter tmp;
       Log.Log.WriteFile("analog: AddTvAudioFilter try:{0} {1}", devices[i].Name, i);
       //if tv audio tuner is currently in use we can skip it
       if (DevicesInUse.Instance.IsUsed(devices[i]))
         continue;
       int hr;
       try
       {
         //add tv audio tuner to graph
         hr = graphBuilder.AddSourceFilterForMoniker(devices[i].Mon, null, devices[i].Name, out tmp);
       }
       catch (Exception)
       {
         Log.Log.WriteFile("analog: cannot add filter to graph");
         continue;
       }
       if (hr != 0)
       {
         //failed to add tv audio tuner to graph, continue with the next one
         if (tmp != null)
         {
           graphBuilder.RemoveFilter(tmp);
           Release.ComObject("tvAudioFilter filter", tmp);
         }
         continue;
       }
       // try connecting the tv tuner-> tv audio tuner
       if (FilterGraphTools.ConnectPin(graphBuilder, tuner.AudioPin, tmp, 0))
       {
         // Got it !
         // Connect tv audio tuner to the crossbar
         IPin pin = DsFindPin.ByDirection(tmp, PinDirection.Output, 0);
         hr = graphBuilder.Connect(pin, crossbar.AudioTunerIn);
         if (hr < 0)
         {
           //failed
           graphBuilder.RemoveFilter(tmp);
           Release.ComObject("audiotuner pinin", pin);
           Release.ComObject("audiotuner filter", tmp);
         }
         else
         {
           //succeeded. we're done
           Log.Log.WriteFile("analog: AddTvAudioFilter succeeded:{0}", devices[i].Name);
           Release.ComObject("audiotuner pinin", pin);
           _filterTvAudioTuner = tmp;
           _audioDevice = devices[i];
           DevicesInUse.Instance.Add(_audioDevice);
           _tvAudioTunerInterface = tuner.Filter as IAMTVAudio;
           break;
         }
       }
       else
       {
         // cannot connect tv tuner-> tv audio tuner, try next one...
         graphBuilder.RemoveFilter(tmp);
         Release.ComObject("audiotuner filter", tmp);
       }
     }
   }
   if (_filterTvAudioTuner == null)
   {
     Log.Log.WriteFile("analog: AddTvAudioFilter no tv audio devices found - Trying TvTuner filter");
     int hr = graphBuilder.Connect(tuner.AudioPin, crossbar.AudioTunerIn);
     if (hr != 0)
     {
       Log.Log.Error("analog: unable to add TvAudioTuner to graph - even TvTuner as TvAudio fails");
       mode = TvAudioVariant.Unavailable;
     }
     else
     {
       Log.Log.WriteFile("analog: AddTvAudioFilter connected TvTuner with Crossbar directly succeeded!");
       mode = TvAudioVariant.TvTunerConnection;
       _tvAudioTunerInterface = tuner.Filter as IAMTVAudio;
       if (_tvAudioTunerInterface != null)
       {
         Log.Log.WriteFile("analog: AddTvAudioFilter succeeded - TvTuner is also TvAudio");
         _filterTvAudioTuner = tuner.Filter;
         mode = TvAudioVariant.TvTuner;
       }
     }
     graph.TvAudio.Mode = mode;
   }
   else
   {
     mode = TvAudioVariant.Normal;
     graph.TvAudio.Name = _audioDevice.Name;
   }
   if (mode != TvAudioVariant.Unavailable && mode != TvAudioVariant.TvTunerConnection &&
       _tvAudioTunerInterface != null)
   {
     CheckCapabilities(graph);
   }
   return true;
 }
Exemplo n.º 34
0
    /// <summary>
    /// Adds the tv audio tuner to the graph and connects it to the crossbar.
    /// At the end of this method the graph looks like:
    /// [          ] ------------------------->[           ]
    /// [ tvtuner  ]                           [ crossbar  ]
    /// [          ]----[            ]-------->[           ]
    ///                 [ tvaudio    ]
    ///                 [   tuner    ]
    /// </summary>
    /// <param name="crossbar">The crossbar componen</param>
    /// <param name="tuner">The tuner component</param>
    /// <param name="graph">The stored graph</param>
    /// <param name="graphBuilder">The graphBuilder</param>
    /// <returns>true, if the graph building was successful</returns>
    public bool CreateFilterInstance(Graph graph, IFilterGraph2 graphBuilder, Tuner tuner, Crossbar crossbar)
    {
      streams = new List<IAudioStream>();
      if (!string.IsNullOrEmpty(graph.TvAudio.Name) && graph.TvAudio.Mode != TvAudioVariant.Unavailable)
      {
        Log.Log.WriteFile("analog: Using TvAudio configuration from stored graph");

        if (CreateConfigurationBasedFilterInstance(graph, tuner, crossbar, graphBuilder))
        {
          Log.Log.WriteFile("analog: Using TvAudio configuration from stored graph succeeded");
          return true;
        }
      }
      if (tuner.AudioPin == null)
      {
        Log.Log.WriteFile("analog: AddTvAudioFilter no tv audio device needed!");
        mode = TvAudioVariant.Unavailable;
        return true;
      }
      Log.Log.WriteFile("analog: No stored graph for TvAudio component - Trying to detect");
      return CreateAutomaticFilterInstance(graph, tuner, crossbar, graphBuilder);
    }
Exemplo n.º 35
0
 /// <summary>
 /// Adds the cross bar filter to the graph and connects the tv tuner to the crossbar.
 /// at the end of this method the graph looks like:
 /// [tv tuner]----->[crossbar]
 /// </summary>
 /// <param name="tuner">The tuner component</param>
 /// <param name="graph">The stored graph</param>
 /// <param name="graphBuilder">The graphBuilder</param>
 /// <returns>true, if the graph building was successful</returns>
 public bool CreateFilterInstance(Graph graph, IFilterGraph2 graphBuilder, Tuner tuner)
 {
   if (!string.IsNullOrEmpty(graph.Crossbar.Name))
   {
     Log.Log.WriteFile("analog: Using Crossbar configuration from stored graph");
     if (CreateConfigurationBasedFilterInstance(graph, graphBuilder, tuner))
     {
       Log.Log.WriteFile("analog: Using Crossbar configuration from stored graph succeeded");
       return true;
     }
   }
   Log.Log.WriteFile("analog: No stored or invalid graph for Crossbar component - Trying to detect");
   return CreateAutomaticFilterInstance(graph, graphBuilder, tuner);
 }
Exemplo n.º 36
0
 /// <summary>
 /// Creates the filter based on the configuration file
 /// </summary>
 /// <param name="tuner">The tuner component</param>
 /// <param name="graph">The stored graph</param>
 /// <param name="graphBuilder">The graphBuilder</param>
 /// <returns>true, if the graph building was successful</returns>
 private bool CreateConfigurationBasedFilterInstance(Graph graph, IFilterGraph2 graphBuilder, Tuner tuner)
 {
   string deviceName = graph.Crossbar.Name;
   _audioTunerIn = null;
   DsDevice[] devices;
   //get list of all crossbar devices installed on this system
   try
   {
     devices = DsDevice.GetDevicesOfCat(FilterCategory.AMKSCrossbar);
     devices = DeviceSorter.Sort(devices, graph.Tuner.Name);
   }
   catch (Exception)
   {
     Log.Log.WriteFile("analog: AddCrossBarFilter no crossbar devices found");
     return false;
   }
   if (devices == null || devices.Length == 0)
   {
     Log.Log.WriteFile("analog: AddCrossBarFilter no crossbar devices found");
     return false;
   }
   //try each crossbar
   for (int i = 0; i < devices.Length; i++)
   {
     IBaseFilter tmp;
     //if crossbar is already in use then we can skip it
     if (DevicesInUse.Instance.IsUsed(devices[i]))
       continue;
     if (!deviceName.Equals(devices[i].Name))
       continue;
     Log.Log.WriteFile("analog: AddCrossBarFilter use:{0} {1}", devices[i].Name, i);
     int hr;
     try
     {
       //add the crossbar to the graph
       hr = graphBuilder.AddSourceFilterForMoniker(devices[i].Mon, null, devices[i].Name, out tmp);
     }
     catch (Exception)
     {
       Log.Log.WriteFile("analog: cannot add filter to graph");
       continue;
     }
     if (hr != 0)
     {
       //failed. try next crossbar
       if (tmp != null)
       {
         graphBuilder.RemoveFilter(tmp);
         Release.ComObject("CrossBarFilter", tmp);
       }
       continue;
     }
     _crossBarFilter = (IAMCrossbar)tmp;
     _videoPinMap = graph.Crossbar.VideoPinMap;
     _audioPinMap = graph.Crossbar.AudioPinMap;
     _videoPinRelatedAudioMap = graph.Crossbar.VideoPinRelatedAudioMap;
     _videoOutPinIndex = graph.Crossbar.VideoOut;
     _audioOutPinIndex = graph.Crossbar.AudioOut;
     if (_videoOutPinIndex == -1)
     {
       Log.Log.WriteFile("analog: AddCrossbarFilter no video output found");
       graphBuilder.RemoveFilter(tmp);
       _crossBarFilter = null;
       Release.ComObject("CrossBarFilter", tmp);
       continue;
     }
     //connect tv tuner->crossbar
     IPin tunerOut = DsFindPin.ByDirection(tuner.Filter, PinDirection.Output,
                                           graph.Tuner.VideoPin);
     if (tunerOut != null && _videoPinMap.ContainsKey(AnalogChannel.VideoInputType.Tuner) &&
         FilterGraphTools.ConnectPin(graphBuilder, tunerOut, tmp, _videoPinMap[AnalogChannel.VideoInputType.Tuner]))
     {
       // Got it, we're done
       _filterCrossBar = tmp;
       _crossBarDevice = devices[i];
       DevicesInUse.Instance.Add(_crossBarDevice);
       if (_audioTunerIn == null)
       {
         _audioTunerIn = DsFindPin.ByDirection(_filterCrossBar, PinDirection.Input,
                                               _audioPinMap[AnalogChannel.AudioInputType.Tuner]);
       }
       Release.ComObject("tuner video out", tunerOut);
       _videoOut = DsFindPin.ByDirection(_filterCrossBar, PinDirection.Output, _videoOutPinIndex);
       if (_audioOutPinIndex != -1)
       {
         _audioOut = DsFindPin.ByDirection(_filterCrossBar, PinDirection.Output, _audioOutPinIndex);
       }
       Log.Log.WriteFile("analog: AddCrossBarFilter succeeded");
       break;
     }
     // cannot connect tv tuner to crossbar, try next crossbar device
     if (tmp != null)
     {
       graphBuilder.RemoveFilter(tmp);
       Release.ComObject("crossbarFilter filter", tmp);
     }
     if (tunerOut != null)
     {
       Release.ComObject("tuner video out", tunerOut);
     }
   }
   return _filterCrossBar != null;
 }
Exemplo n.º 37
0
    /// <summary>
    /// Creates the filter by trying to detect it
    /// </summary>
    /// <param name="tuner">The tuner component</param>
    /// <param name="graph">The stored graph</param>
    /// <param name="graphBuilder">The graphBuilder</param>
    /// <returns>true, if the graph building was successful</returns>
    private bool CreateAutomaticFilterInstance(Graph graph, IFilterGraph2 graphBuilder, Tuner tuner)
    {
      _audioTunerIn = null;
      DsDevice[] devices;
      //get list of all crossbar devices installed on this system
      try
      {
        devices = DsDevice.GetDevicesOfCat(FilterCategory.AMKSCrossbar);
        devices = DeviceSorter.Sort(devices, graph.Tuner.Name);
      }
      catch (Exception)
      {
        Log.Log.WriteFile("analog: AddCrossBarFilter no crossbar devices found");
        return false;
      }
      if (devices == null || devices.Length == 0)
      {
        Log.Log.WriteFile("analog: AddCrossBarFilter no crossbar devices found");
        return false;
      }
      //try each crossbar
      for (int i = 0; i < devices.Length; i++)
      {
        IBaseFilter tmp;
        Log.Log.WriteFile("analog: AddCrossBarFilter try:{0} {1}", devices[i].Name, i);
        //if crossbar is already in use then we can skip it
        if (DevicesInUse.Instance.IsUsed(devices[i]))
          continue;
        int hr;
        try
        {
          //add the crossbar to the graph
          hr = graphBuilder.AddSourceFilterForMoniker(devices[i].Mon, null, devices[i].Name, out tmp);
        }
        catch (Exception)
        {
          Log.Log.WriteFile("analog: cannot add filter to graph");
          continue;
        }
        if (hr != 0)
        {
          //failed. try next crossbar
          if (tmp != null)
          {
            graphBuilder.RemoveFilter(tmp);
            Release.ComObject("CrossBarFilter", tmp);
          }
          continue;
        }
        _crossBarFilter = (IAMCrossbar)tmp;
        CheckCapabilities();
        if (_videoOutPinIndex == -1)
        {
          Log.Log.WriteFile("analog: AddCrossbarFilter no video output found");
          graphBuilder.RemoveFilter(tmp);
          _crossBarFilter = null;
          Release.ComObject("CrossBarFilter", tmp);
          continue;
        }

        // Check that the crossbar has a tuner video input pin.
        IPin pinIn = null;
        if (_videoPinMap.ContainsKey(AnalogChannel.VideoInputType.Tuner))
        {
          pinIn = DsFindPin.ByDirection(tmp, PinDirection.Input, _videoPinMap[AnalogChannel.VideoInputType.Tuner]);
        }
        if (pinIn == null)
        {
          // no pin found, continue with next crossbar
          Log.Log.WriteFile("analog: AddCrossBarFilter no video tuner input pin detected");
          if (tmp != null)
          {
            graphBuilder.RemoveFilter(tmp);
            _crossBarFilter = null;
            Release.ComObject("CrossBarFilter", tmp);
          }
          continue;
        }
        //connect tv tuner->crossbar
        int tempVideoPinIndex;
        if (FilterGraphTools.ConnectFilter(graphBuilder, tuner.Filter, pinIn, out tempVideoPinIndex))
        {
          // Got it, we're done
          _filterCrossBar = tmp;
          _crossBarDevice = devices[i];
          DevicesInUse.Instance.Add(_crossBarDevice);
          if (_audioTunerIn == null)
          {
            _audioTunerIn = DsFindPin.ByDirection(_filterCrossBar, PinDirection.Input,
                                                  _audioPinMap[AnalogChannel.AudioInputType.Tuner]);
          }
          Release.ComObject("crossbar videotuner pin", pinIn);
          _videoOut = DsFindPin.ByDirection(_filterCrossBar, PinDirection.Output, _videoOutPinIndex);
          if (_audioOutPinIndex != -1)
          {
            _audioOut = DsFindPin.ByDirection(_filterCrossBar, PinDirection.Output, _audioOutPinIndex);
          }
          Log.Log.WriteFile("analog: AddCrossBarFilter succeeded");
          graph.Crossbar.AudioOut = _audioOutPinIndex;
          graph.Crossbar.AudioPinMap = _audioPinMap;
          graph.Crossbar.Name = _crossBarDevice.Name;
          graph.Crossbar.VideoOut = _videoOutPinIndex;
          graph.Crossbar.VideoPinMap = _videoPinMap;
          graph.Crossbar.VideoPinRelatedAudioMap = _videoPinRelatedAudioMap;
          graph.Tuner.VideoPin = tempVideoPinIndex;
          break;
        }
        // cannot connect tv tuner to crossbar, try next crossbar device
        graphBuilder.RemoveFilter(tmp);
        Release.ComObject("crossbar videotuner pin", pinIn);
        Release.ComObject("crossbar filter", tmp);
      }
      return _filterCrossBar != null;
    }