Esempio n. 1
0
        /// <summary>
        /// Returns DeviceIndex of KNC1 card
        /// </summary>
        /// <param name="TvCard">TvCard object</param>
        /// <returns>The device index</returns>
        public static int GetDeviceIndex(TvCardBase TvCard)
        {
            // temporary list to hold device paths
            List <String>  deviceids  = new List <String>();
            IList <Server> dbsServers = Server.ListAll();

            foreach (Server server in dbsServers)
            {
                foreach (Card dbsCard in server.ReferringCard())
                {
                    // only count all KNC cards
                    if (dbsCard.Name.StartsWith("KNC BDA") || dbsCard.Name.StartsWith("Mystique"))
                    {
                        deviceids.Add(dbsCard.DevicePath);
                    }
                }
            }

            int idx   = -1;
            int found = 0;

            // loop through all cards and return found as index
            if (deviceids.Count > 0)
            {
                // use sorted list, should be same order as in Windows hardware manager
                deviceids.Sort();
                foreach (String curId in deviceids)
                {
                    idx++;
                    if (TvCard.DevicePath == curId)
                    {
                        found = idx;
                        break;
                    }
                }
            }
            return(found);
        }
Esempio n. 2
0
    //anysee _anysee = null;

    #endregion

    //ctor
    /// <summary>
    /// Initializes a new instance of the <see cref="ConditionalAccess"/> class.
    /// </summary>
    /// <param name="tunerFilter">The tuner filter.</param>
    /// <param name="analyzerFilter">The capture filter.</param>
    /// <param name="winTvUsbCiFilter">The WinTV CI filter.</param>
    /// <param name="card">Determines the type of TV card</param>    
    public ConditionalAccess(IBaseFilter tunerFilter, IBaseFilter analyzerFilter, IBaseFilter winTvUsbCiFilter,
                             TvCardBase card)
    {
      try
      {
        //System.Diagnostics.Debugger.Launch();        
        if (card != null && card.DevicePath != null)
        {
          //fetch decrypt limit from DB and apply it.
          TvBusinessLayer layer = new TvBusinessLayer();
          Card c = layer.GetCardByDevicePath(card.DevicePath);
          _decryptLimit = c.DecryptLimit;
          _useCam = c.CAM;
          _CamType = (CamType)c.CamType;
          Log.Log.WriteFile("CAM is {0} model", _CamType);
        }

        _mapSubChannels = new Dictionary<int, ConditionalAccessContext>();
        TunerDri driTuner = card as TunerDri;
        if (driTuner != null)
        {
          _tunerDri = driTuner;
          _ciMenu = driTuner;
        }
        if (tunerFilter == null && analyzerFilter == null)
          return;
        //DVB checks. Conditional Access & DiSEqC etc.
        bool isDVBS = (card is TvCardDVBS);
        bool isDVBT = (card is TvCardDVBT);
        bool isDVBC = (card is TvCardDVBC);

        if (isDVBC || isDVBS || isDVBT)
        {
          Log.Log.WriteFile("Check for KNC");
          // Lookup device index of current card. only counting KNC cards by device path
          int DeviceIndex = KNCDeviceLookup.GetDeviceIndex(card);
          _knc = new KNCAPI(tunerFilter, (uint)DeviceIndex);
          if (_knc.IsKNC)
          {
            //if (_knc.IsCamReady()) 
            _ciMenu = _knc; // Register KNC CI Menu capabilities when CAM detected and ready
            Log.Log.WriteFile("KNC card detected");
            return;
          }
          Release.DisposeToNull(ref _knc);

          Log.Log.WriteFile("Check for Digital Everywhere");
          _digitalEveryWhere = new DigitalEverywhere(tunerFilter);
          if (_digitalEveryWhere.IsDigitalEverywhere)
          {
            Log.Log.WriteFile("Digital Everywhere card detected");
            _diSEqCMotor = new DiSEqCMotor(_digitalEveryWhere);

            if (_digitalEveryWhere.IsCamReady())
            {
              Log.Log.WriteFile("Digital Everywhere registering CI menu capabilities");
              _ciMenu = _digitalEveryWhere; // Register FireDTV CI Menu capabilities when CAM detected and ready
            }
            //_digitalEveryWhere.ResetCAM();
            return;
          }
          Release.DisposeToNull(ref _digitalEveryWhere);

          Log.Log.WriteFile("Check for Twinhan");
          _twinhan = new Twinhan(tunerFilter);
          if (_twinhan.IsTwinhan)
          {
            Log.Log.WriteFile("Twinhan card detected");
            _diSEqCMotor = new DiSEqCMotor(_twinhan);
            Log.Log.WriteFile("Twinhan registering CI menu capabilities");
            _ciMenu = _twinhan; // Register Twinhan CI Menu capabilities when CAM detected and ready
            return;
          }
          Release.DisposeToNull(ref _twinhan);

          Log.Log.WriteFile("Check for TechnoTrend");
          _technoTrend = new TechnoTrendAPI(tunerFilter);
          if (_technoTrend.IsTechnoTrend)
          {
            ////if (_technoTrend.IsCamPresent()) 
            _ciMenu = _technoTrend; // Register Technotrend CI Menu capabilities
            Log.Log.WriteFile("TechnoTrend card detected");
            return;
          }
          Release.DisposeToNull(ref _technoTrend);

          Log.Log.WriteFile("Check for Hauppauge");
          _hauppauge = new Hauppauge(tunerFilter);
          if (_hauppauge.IsHauppauge)
          {
            Log.Log.WriteFile("Hauppauge card detected");
            Log.Log.WriteFile("Check for Hauppauge WinTV CI");
            if (winTvUsbCiFilter != null)
            {
              Log.Log.WriteFile("WinTV CI detected in graph - using capabilities...");
              _winTvCiModule = new WinTvCiModule(winTvUsbCiFilter);

              Log.Log.WriteFile("WinTV CI registering CI menu capabilities");
              _ciMenu = _winTvCiModule; // WinTv CI Menu capabilities 
            }
            _diSEqCMotor = new DiSEqCMotor(_hauppauge);
            return;
          }
          Release.DisposeToNull(ref _hauppauge);
          Release.DisposeToNull(ref _winTvCiModule);

          /*Log.Log.Info("Check for anysee");
          _anysee = new anysee(tunerFilter, analyzerFilter);
          if (_anysee.Isanysee)
          {
            Log.Log.Info("anysee device detected");
            return;
          }*/

          Log.Log.WriteFile("Check for ProfRed");
          _profred = new ProfRed(tunerFilter);
          if (_profred.IsProfRed)
          {
            Log.Log.WriteFile("ProfRed card detected");
            _diSEqCMotor = new DiSEqCMotor(_profred);
            return;
          }
          Release.DisposeToNull(ref _profred);

          // TeVii support
          _TeVii = new TeVii();
          _TeVii.Init(tunerFilter);
          _TeVii.DevicePath = card.DevicePath;
          Log.Log.WriteFile("Check for {0}", _TeVii.Provider);
          _TeVii.CheckAndOpen();
          if (_TeVii.IsSupported)
          {
            _diSEqCMotor = new DiSEqCMotor(_TeVii);
            _HWProvider = _TeVii;
            Log.Log.WriteFile("Check for Hauppauge WinTV CI");
            if (winTvUsbCiFilter != null)
            {
              Log.Log.WriteFile("WinTV CI detected in graph - using capabilities...");
              _winTvCiModule = new WinTvCiModule(winTvUsbCiFilter);
            }
            return;
          }
          Release.DisposeToNull(ref _TeVii);

          // DigitalDevices support
          _DigitalDevices = new DigitalDevices(tunerFilter);
          if (_DigitalDevices.IsGenericBDAS)
          {
            _genericbdas = _DigitalDevices;
            if (_DigitalDevices.IsSupported)
            {
              _ciMenu = _DigitalDevices;
            }
            return; // detected
          }
          Release.DisposeToNull(ref _DigitalDevices);

          Log.Log.WriteFile("Check for Conexant based card");
          _conexant = new ConexantBDA(tunerFilter);
          if (_conexant.IsConexant)
          {
            Log.Log.WriteFile("Conexant BDA card detected");
            Log.Log.WriteFile("Check for Hauppauge WinTV CI");
            if (winTvUsbCiFilter != null)
            {
              Log.Log.WriteFile("WinTV CI detected in graph - using capabilities...");
              _winTvCiModule = new WinTvCiModule(winTvUsbCiFilter);
            }
            return;
          }
          Release.DisposeToNull(ref _conexant);
          Release.DisposeToNull(ref _winTvCiModule);

          Log.Log.WriteFile("Check for GenPix BDA based card");
          _genpix = new GenPixBDA(tunerFilter);
          if (_genpix.IsGenPix)
          {
            Log.Log.WriteFile("GenPix BDA card detected");
            Log.Log.WriteFile("Check for Hauppauge WinTV CI");
            if (winTvUsbCiFilter != null)
            {
              Log.Log.WriteFile("WinTV CI detected in graph - using capabilities...");
              _winTvCiModule = new WinTvCiModule(winTvUsbCiFilter);
            }
            return;
          }
          Release.DisposeToNull(ref _genpix);
          Release.DisposeToNull(ref _winTvCiModule);

          Log.Log.WriteFile("Check for Generic DVB-S card");
          _genericbdas = new GenericBDAS(tunerFilter);
          if (_genericbdas.IsGenericBDAS)
          {
            Log.Log.WriteFile("Generic BDA card detected");
            Log.Log.WriteFile("Check for Hauppauge WinTV CI");
            if (winTvUsbCiFilter != null)
            {
              Log.Log.WriteFile("WinTV CI detected in graph - using capabilities...");
              _winTvCiModule = new WinTvCiModule(winTvUsbCiFilter);
            }
            return;
          }
          Release.DisposeToNull(ref _genericbdas);

          //Final WinTV-CI check for DVB-T hybrid cards
          Log.Log.WriteFile("Check for Hauppauge WinTV CI");
          if (winTvUsbCiFilter != null)
          {
            Log.Log.WriteFile("WinTV CI detected in graph - using capabilities...");
            _winTvCiModule = new WinTvCiModule(winTvUsbCiFilter);
            return;
          }
          Release.DisposeToNull(ref _winTvCiModule);
        }

        //ATSC checks
        bool isATSC = (card is TvCardATSC);
        if (isATSC)
        {
          Log.Log.WriteFile("Check for ViXS ATSC QAM card");
          _isvixsatsc = new ViXSATSC(tunerFilter);
          if (_isvixsatsc.IsViXSATSC)
          {
            Log.Log.WriteFile("ViXS ATSC QAM card detected");
            return;
          }
          Release.DisposeToNull(ref _isvixsatsc);

          Log.Log.WriteFile("Check for Generic ATSC QAM card");
          _isgenericatsc = new GenericATSC(tunerFilter);
          if (_isgenericatsc.IsGenericATSC)
          {
            Log.Log.WriteFile("Generic ATSC QAM card detected");
            return;
          }
          Release.DisposeToNull(ref _isgenericatsc);
        }
      }
      catch (Exception ex)
      {
        Log.Log.Write(ex);
      }
    }
Esempio n. 3
0
        //anysee _anysee = null;

        #endregion

        //ctor
        /// <summary>
        /// Initializes a new instance of the <see cref="ConditionalAccess"/> class.
        /// </summary>
        /// <param name="tunerFilter">The tuner filter.</param>
        /// <param name="analyzerFilter">The capture filter.</param>
        /// <param name="winTvUsbCiFilter">The WinTV CI filter.</param>
        /// <param name="card">Determines the type of TV card</param>
        public ConditionalAccess(IBaseFilter tunerFilter, IBaseFilter analyzerFilter, IBaseFilter winTvUsbCiFilter,
                                 TvCardBase card)
        {
            try
            {
                //System.Diagnostics.Debugger.Launch();
                if (card != null && card.DevicePath != null)
                {
                    //fetch decrypt limit from DB and apply it.
                    TvBusinessLayer layer = new TvBusinessLayer();
                    Card            c     = layer.GetCardByDevicePath(card.DevicePath);
                    _decryptLimit = c.DecryptLimit;
                    _useCam       = c.CAM;
                    _CamType      = (CamType)c.CamType;
                    Log.Log.WriteFile("CAM is {0} model", _CamType);
                }

                _mapSubChannels = new Dictionary <int, ConditionalAccessContext>();
                TunerDri driTuner = card as TunerDri;
                if (driTuner != null)
                {
                    _tunerDri = driTuner;
                    _ciMenu   = driTuner;
                }
                if (tunerFilter == null && analyzerFilter == null)
                {
                    return;
                }
                //DVB checks. Conditional Access & DiSEqC etc.
                bool isDVBS = (card is TvCardDVBS);
                bool isDVBT = (card is TvCardDVBT);
                bool isDVBC = (card is TvCardDVBC);

                if (isDVBC || isDVBS || isDVBT)
                {
                    Log.Log.WriteFile("Check for KNC");
                    // Lookup device index of current card. only counting KNC cards by device path
                    int DeviceIndex = KNCDeviceLookup.GetDeviceIndex(card);
                    _knc = new KNCAPI(tunerFilter, (uint)DeviceIndex);
                    if (_knc.IsKNC)
                    {
                        //if (_knc.IsCamReady())
                        _ciMenu = _knc; // Register KNC CI Menu capabilities when CAM detected and ready
                        Log.Log.WriteFile("KNC card detected");
                        return;
                    }
                    Release.DisposeToNull(ref _knc);

                    Log.Log.WriteFile("Check for Digital Everywhere");
                    _digitalEveryWhere = new DigitalEverywhere(tunerFilter);
                    if (_digitalEveryWhere.IsDigitalEverywhere)
                    {
                        Log.Log.WriteFile("Digital Everywhere card detected");
                        _diSEqCMotor = new DiSEqCMotor(_digitalEveryWhere);

                        if (_digitalEveryWhere.IsCamReady())
                        {
                            Log.Log.WriteFile("Digital Everywhere registering CI menu capabilities");
                            _ciMenu = _digitalEveryWhere; // Register FireDTV CI Menu capabilities when CAM detected and ready
                        }
                        //_digitalEveryWhere.ResetCAM();
                        return;
                    }
                    Release.DisposeToNull(ref _digitalEveryWhere);

                    Log.Log.WriteFile("Check for Twinhan");
                    _twinhan = new Twinhan(tunerFilter);
                    if (_twinhan.IsTwinhan)
                    {
                        Log.Log.WriteFile("Twinhan card detected");
                        _diSEqCMotor = new DiSEqCMotor(_twinhan);
                        Log.Log.WriteFile("Twinhan registering CI menu capabilities");
                        _ciMenu = _twinhan; // Register Twinhan CI Menu capabilities when CAM detected and ready
                        return;
                    }
                    Release.DisposeToNull(ref _twinhan);

                    Log.Log.WriteFile("Check for TechnoTrend");
                    _technoTrend = new TechnoTrendAPI(tunerFilter);
                    if (_technoTrend.IsTechnoTrend)
                    {
                        ////if (_technoTrend.IsCamPresent())
                        _ciMenu = _technoTrend; // Register Technotrend CI Menu capabilities
                        Log.Log.WriteFile("TechnoTrend card detected");
                        return;
                    }
                    Release.DisposeToNull(ref _technoTrend);

                    Log.Log.WriteFile("Check for Hauppauge");
                    _hauppauge = new Hauppauge(tunerFilter);
                    if (_hauppauge.IsHauppauge)
                    {
                        Log.Log.WriteFile("Hauppauge card detected");
                        Log.Log.WriteFile("Check for Hauppauge WinTV CI");
                        if (winTvUsbCiFilter != null)
                        {
                            Log.Log.WriteFile("WinTV CI detected in graph - using capabilities...");
                            _winTvCiModule = new WinTvCiModule(winTvUsbCiFilter);

                            Log.Log.WriteFile("WinTV CI registering CI menu capabilities");
                            _ciMenu = _winTvCiModule; // WinTv CI Menu capabilities
                        }
                        _diSEqCMotor = new DiSEqCMotor(_hauppauge);
                        return;
                    }
                    Release.DisposeToNull(ref _hauppauge);
                    Release.DisposeToNull(ref _winTvCiModule);

                    /*Log.Log.Info("Check for anysee");
                     * _anysee = new anysee(tunerFilter, analyzerFilter);
                     * if (_anysee.Isanysee)
                     * {
                     * Log.Log.Info("anysee device detected");
                     * return;
                     * }*/

                    Log.Log.WriteFile("Check for ProfRed");
                    _profred = new ProfRed(tunerFilter);
                    if (_profred.IsProfRed)
                    {
                        Log.Log.WriteFile("ProfRed card detected");
                        _diSEqCMotor = new DiSEqCMotor(_profred);
                        return;
                    }
                    Release.DisposeToNull(ref _profred);

                    // TeVii support
                    _TeVii = new TeVii();
                    _TeVii.Init(tunerFilter);
                    _TeVii.DevicePath = card.DevicePath;
                    Log.Log.WriteFile("Check for {0}", _TeVii.Provider);
                    _TeVii.CheckAndOpen();
                    if (_TeVii.IsSupported)
                    {
                        _diSEqCMotor = new DiSEqCMotor(_TeVii);
                        _HWProvider  = _TeVii;
                        Log.Log.WriteFile("Check for Hauppauge WinTV CI");
                        if (winTvUsbCiFilter != null)
                        {
                            Log.Log.WriteFile("WinTV CI detected in graph - using capabilities...");
                            _winTvCiModule = new WinTvCiModule(winTvUsbCiFilter);
                        }
                        return;
                    }
                    Release.DisposeToNull(ref _TeVii);

                    // DigitalDevices support
                    _DigitalDevices = new DigitalDevices(tunerFilter);
                    if (_DigitalDevices.IsGenericBDAS)
                    {
                        _genericbdas = _DigitalDevices;
                        if (_DigitalDevices.IsSupported)
                        {
                            _ciMenu = _DigitalDevices;
                        }
                        return; // detected
                    }
                    Release.DisposeToNull(ref _DigitalDevices);

                    Log.Log.WriteFile("Check for Conexant based card");
                    _conexant = new ConexantBDA(tunerFilter);
                    if (_conexant.IsConexant)
                    {
                        Log.Log.WriteFile("Conexant BDA card detected");
                        Log.Log.WriteFile("Check for Hauppauge WinTV CI");
                        if (winTvUsbCiFilter != null)
                        {
                            Log.Log.WriteFile("WinTV CI detected in graph - using capabilities...");
                            _winTvCiModule = new WinTvCiModule(winTvUsbCiFilter);
                        }
                        return;
                    }
                    Release.DisposeToNull(ref _conexant);
                    Release.DisposeToNull(ref _winTvCiModule);

                    Log.Log.WriteFile("Check for GenPix BDA based card");
                    _genpix = new GenPixBDA(tunerFilter);
                    if (_genpix.IsGenPix)
                    {
                        Log.Log.WriteFile("GenPix BDA card detected");
                        Log.Log.WriteFile("Check for Hauppauge WinTV CI");
                        if (winTvUsbCiFilter != null)
                        {
                            Log.Log.WriteFile("WinTV CI detected in graph - using capabilities...");
                            _winTvCiModule = new WinTvCiModule(winTvUsbCiFilter);
                        }
                        return;
                    }
                    Release.DisposeToNull(ref _genpix);
                    Release.DisposeToNull(ref _winTvCiModule);

                    Log.Log.WriteFile("Check for Generic DVB-S card");
                    _genericbdas = new GenericBDAS(tunerFilter);
                    if (_genericbdas.IsGenericBDAS)
                    {
                        Log.Log.WriteFile("Generic BDA card detected");
                        Log.Log.WriteFile("Check for Hauppauge WinTV CI");
                        if (winTvUsbCiFilter != null)
                        {
                            Log.Log.WriteFile("WinTV CI detected in graph - using capabilities...");
                            _winTvCiModule = new WinTvCiModule(winTvUsbCiFilter);
                        }
                        return;
                    }
                    Release.DisposeToNull(ref _genericbdas);

                    //Final WinTV-CI check for DVB-T hybrid cards
                    Log.Log.WriteFile("Check for Hauppauge WinTV CI");
                    if (winTvUsbCiFilter != null)
                    {
                        Log.Log.WriteFile("WinTV CI detected in graph - using capabilities...");
                        _winTvCiModule = new WinTvCiModule(winTvUsbCiFilter);
                        return;
                    }
                    Release.DisposeToNull(ref _winTvCiModule);
                }

                //ATSC checks
                bool isATSC = (card is TvCardATSC);
                if (isATSC)
                {
                    Log.Log.WriteFile("Check for ViXS ATSC QAM card");
                    _isvixsatsc = new ViXSATSC(tunerFilter);
                    if (_isvixsatsc.IsViXSATSC)
                    {
                        Log.Log.WriteFile("ViXS ATSC QAM card detected");
                        return;
                    }
                    Release.DisposeToNull(ref _isvixsatsc);

                    Log.Log.WriteFile("Check for Generic ATSC QAM card");
                    _isgenericatsc = new GenericATSC(tunerFilter);
                    if (_isgenericatsc.IsGenericATSC)
                    {
                        Log.Log.WriteFile("Generic ATSC QAM card detected");
                        return;
                    }
                    Release.DisposeToNull(ref _isgenericatsc);
                }
            }
            catch (Exception ex)
            {
                Log.Log.Write(ex);
            }
        }
        private bool BeforeTune(IChannel channel, ref IUser user, out TvResult result)
        {
            result = TvResult.UnknownError;
            //@FIX this fails for back-2-back recordings
            //if (CurrentDbChannel(ref user) == idChannel && idChannel >= 0)
            //{
            //  return true;
            //}
            Log.Debug("card: user: {0}:{1}:{2} tune {3}", user.Name, user.CardId, user.SubChannel, channel.ToString());
            _cardHandler.Card.CamType = (CamType)_cardHandler.DataBaseCard.CamType;
            _cardHandler.SetParameters();

            //check if transponder differs
            ITvCardContext context = _cardHandler.Card.Context as ITvCardContext;

            if (_cardHandler.Card.SubChannels.Length > 0)
            {
                if (IsTunedToTransponder(channel) == false)
                {
                    if (context.IsOwner(user) || user.IsAdmin)
                    {
                        Log.Debug("card: to different transponder");

                        //remove all subchannels, except for this user...
                        IUser[] users = context.Users;
                        for (int i = 0; i < users.Length; ++i)
                        {
                            if (users[i].Name != user.Name)
                            {
                                Log.Debug("  stop subchannel: {0} user: {1}", i, users[i].Name);

                                //fix for b2b mantis; http://mantis.team-mediaportal.com/view.php?id=1112
                                if (users[i].IsAdmin)
                                // if we are stopping an on-going recording/schedule (=admin), we have to make sure that we remove the schedule also.
                                {
                                    Log.Debug("user is scheduler: {0}", users[i].Name);
                                    int recScheduleId = RemoteControl.Instance.GetRecordingSchedule(users[i].CardId,
                                                                                                    users[i].IdChannel);

                                    if (recScheduleId > 0)
                                    {
                                        Schedule schedule = Schedule.Retrieve(recScheduleId);
                                        Log.Info("removing schedule with id: {0}", schedule.IdSchedule);
                                        RemoteControl.Instance.StopRecordingSchedule(schedule.IdSchedule);
                                        schedule.Delete();
                                    }
                                }
                                else
                                {
                                    _cardHandler.Card.FreeSubChannel(users[i].SubChannel);
                                    context.Remove(users[i]);
                                }
                            }
                        }
                    }
                    else
                    {
                        Log.Debug("card: user: {0} is not the card owner. Cannot switch transponder", user.Name);
                        result = TvResult.NotTheOwner;
                        return(false);
                    }
                }
                else // same transponder, free previous subchannel before tuning..
                {
                    _cardHandler.Card.FreeSubChannel(user.SubChannel);
                }
            }

            if (OnBeforeTuneEvent != null)
            {
                OnBeforeTuneEvent(_cardHandler);
            }

            TvCardBase card = _cardHandler.Card as TvCardBase;

            if (card != null)
            {
                card.AfterTuneEvent -= new TvCardBase.OnAfterTuneDelegate(Card_OnAfterTuneEvent);
                card.AfterTuneEvent += new TvCardBase.OnAfterTuneDelegate(Card_OnAfterTuneEvent);
            }
            else
            {
                HybridCard hybridCard = _cardHandler.Card as HybridCard;
                if (hybridCard != null)
                {
                    hybridCard.AfterTuneEvent = new TvCardBase.OnAfterTuneDelegate(Card_OnAfterTuneEvent);
                }
            }

            result = TvResult.Succeeded;
            return(true);
        }