Exemplo n.º 1
0
        /// <summary>
        /// Grabs the epg for a card.
        /// </summary>
        /// <param name="epgCard">The epg card.</param>
        private void GrabEpgOnCard(EpgCard epgCard)
        {
            CardType type = _tvController.Type(epgCard.Card.IdCard);

            //skip analog and webstream cards
            if (type == CardType.Analog || type == CardType.RadioWebStream)
            {
                return;
            }

            while (TransponderList.Instance.GetNextTransponder() != null)
            {
                //skip transponders which are in use
                if (TransponderList.Instance.CurrentTransponder.InUse)
                {
                    continue;
                }

                //check if card type is the same as the channel type of the transponder
                if (type == CardType.Atsc && TransponderList.Instance.CurrentTransponder.TuningDetail.ChannelType != 1)
                {
                    continue;
                }
                if (type == CardType.DvbC && TransponderList.Instance.CurrentTransponder.TuningDetail.ChannelType != 2)
                {
                    continue;
                }
                if (type == CardType.DvbS && TransponderList.Instance.CurrentTransponder.TuningDetail.ChannelType != 3)
                {
                    continue;
                }
                if (type == CardType.DvbT && TransponderList.Instance.CurrentTransponder.TuningDetail.ChannelType != 4)
                {
                    continue;
                }
                if (type == CardType.DvbIP && TransponderList.Instance.CurrentTransponder.TuningDetail.ChannelType != 7)
                {
                    continue;
                }

                //find next channel to grab
                while (TransponderList.Instance.CurrentTransponder.GetNextChannel() != null)
                {
                    //get the channel
                    Channel ch = TransponderList.Instance.CurrentTransponder.CurrentChannel;

                    //check if its time to grab the epg for this channel
                    TimeSpan ts = DateTime.Now - TransponderList.Instance.CurrentTransponder.CurrentChannel.LastGrabTime;
                    if (ts.TotalMinutes < _epgReGrabAfter)
                    {
                        //Log.Epg("Skip card:#{0} transponder #{1}/{2} channel: {3} - Less than regrab time",
                        //         epgCard.Card.IdCard, TransponderList.Instance.CurrentIndex + 1, TransponderList.Instance.Count, ch.DisplayName);
                        continue; // less then 2 hrs ago
                    }
                    if (epgCard.Card.canTuneTvChannel(ch.IdChannel))
                    {
                        Log.Epg("Grab for card:#{0} transponder #{1}/{2} channel: {3}",
                                epgCard.Card.IdCard, TransponderList.Instance.CurrentIndex + 1, TransponderList.Instance.Count,
                                ch.DisplayName);
                        //start grabbing
                        epgCard.GrabEpg();
                        return;
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method will try to start the epg grabber for the channel and tuning details specified
        /// Epg grabbing can only be started if there is a card idle which can receive the channel specified
        /// </summary>
        /// <param name="channel">channel to grab/param>
        /// <param name="tuning">tuning information</param>
        /// <param name="card">card to use for grabbing</param>
        /// <returns>true if grabbing has started else false</returns>
        private bool GrabEpgForChannel(Channel channel, IChannel tuning, Card card)
        {
            if (channel == null)
            {
                Log.Error("Epg: invalid channel");
                return(false);
            }
            if (tuning == null)
            {
                Log.Error("Epg: invalid tuning");
                return(false);
            }
            if (card == null)
            {
                Log.Error("Epg: invalid card");
                return(false);
            }
            if (_tvController == null)
            {
                Log.Error("Epg: invalid tvcontroller");
                return(false);
            }
            if (_user == null)
            {
                Log.Error("Epg: invalid user");
                return(false);
            }
            //remove following check to enable multi-card epg grabbing (still beta)
            if (_tvController.AllCardsIdle == false)
            {
                Log.Epg("Epg: card:{0} cards are not idle", Card.IdCard);
                return(false);
            }

            TvResult result = TvResult.UnknownError;
            //handle ATSC
            ATSCChannel atscChannel = tuning as ATSCChannel;

            if (atscChannel != null)
            {
                if (_tvController.Type(Card.IdCard) == CardType.Atsc)
                {
                    if (IsCardIdle(Card.IdCard) == false)
                    {
                        Log.Epg("Epg: card:{0} atsc card is not idle", Card.IdCard);
                        return(false); //card is busy
                    }
                    return(TuneEPGgrabber(channel, tuning, card, result));
                }
                Log.Epg("Epg: card:{0} could not tune to atsc channel:{1}", Card.IdCard, tuning.ToString());
                return(false);
            }

            //handle DVBC
            DVBCChannel dvbcChannel = tuning as DVBCChannel;

            if (dvbcChannel != null)
            {
                if (_tvController.Type(Card.IdCard) == CardType.DvbC)
                {
                    if (IsCardIdle(Card.IdCard) == false)
                    {
                        Log.Epg("Epg: card:{0} dvbc card is not idle", Card.IdCard);
                        return(false); //card is busy
                    }
                    return(TuneEPGgrabber(channel, tuning, card, result));
                }
                Log.Epg("Epg: card:{0} could not tune to dvbc channel:{1}", Card.IdCard, tuning.ToString());
                return(false);
            }

            //handle DVBS
            DVBSChannel dvbsChannel = tuning as DVBSChannel;

            if (dvbsChannel != null)
            {
                if (_tvController.Type(Card.IdCard) == CardType.DvbS)
                {
                    if (IsCardIdle(Card.IdCard) == false)
                    {
                        Log.Epg("Epg: card:{0} dvbs card is not idle", Card.IdCard);
                        return(false); //card is busy
                    }
                    return(TuneEPGgrabber(channel, tuning, card, result));
                }
                Log.Epg("Epg: card:{0} could not tune to dvbs channel:{1}", Card.IdCard, tuning.ToString());
                return(false);
            }

            //handle DVBT
            DVBTChannel dvbtChannel = tuning as DVBTChannel;

            if (dvbtChannel != null)
            {
                if (_tvController.Type(Card.IdCard) == CardType.DvbT)
                {
                    if (IsCardIdle(Card.IdCard) == false)
                    {
                        Log.Epg("Epg: card:{0} dvbt card is not idle", Card.IdCard);
                        return(false); //card is busy
                    }

                    return(TuneEPGgrabber(channel, tuning, card, result));
                }
                Log.Epg("Epg: card:{0} could not tune to dvbt channel:{1}", Card.IdCard, tuning.ToString());
                return(false);
            }

            //handle DVBIP
            DVBIPChannel dvbipChannel = tuning as DVBIPChannel;

            if (dvbipChannel != null)
            {
                if (_tvController.Type(Card.IdCard) == CardType.DvbIP)
                {
                    if (IsCardIdle(Card.IdCard) == false)
                    {
                        Log.Epg("Epg: card:{0} dvbip card is not idle", Card.IdCard);
                        return(false); //card is busy
                    }
                    return(TuneEPGgrabber(channel, tuning, card, result));
                }
                else
                {
                    Log.Epg("Epg: card:{0} could not tune to dvbip channel:{1}", Card.IdCard, tuning.ToString());
                }
                return(false);
            }
            Log.Epg("Epg: card:{0} could not tune to channel:{1}", Card.IdCard, tuning.ToString());
            return(false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// This method will try to start the epg grabber for the channel and tuning details specified
        /// Epg grabbing can only be started if there is a card idle which can receive the channel specified
        /// </summary>
        /// <param name="channel">channel to grab/param>
        /// <param name="tuning">tuning information</param>
        /// <param name="card">card to use for grabbing</param>
        /// <returns>true if grabbing has started else false</returns>
        private bool GrabEpgForChannel(Channel channel, IChannel tuning, Card card)
        {
            if (channel == null)
            {
                Log.Error("Epg: invalid channel");
                return(false);
            }
            if (tuning == null)
            {
                Log.Error("Epg: invalid tuning");
                return(false);
            }
            if (card == null)
            {
                Log.Error("Epg: invalid card");
                return(false);
            }
            if (_tvController == null)
            {
                Log.Error("Epg: invalid tvcontroller");
                return(false);
            }
            if (_user == null)
            {
                Log.Error("Epg: invalid user");
                return(false);
            }
            //remove following check to enable multi-card epg grabbing (still beta)
            if (_tvController.AllCardsIdle == false)
            {
                Log.Epg("Epg: card:{0} cards are not idle", card.IdCard);
                return(false);
            }

            TvResult result;
            //handle ATSC
            ATSCChannel atscChannel = tuning as ATSCChannel;

            if (atscChannel != null)
            {
                if (_tvController.Type(card.IdCard) == CardType.Atsc)
                {
                    if (IsCardIdle(card.IdCard) == false)
                    {
                        Log.Epg("Epg: card:{0} atsc card is not idle", card.IdCard);
                        return(false); //card is busy
                    }
                    try
                    {
                        IUser cardUser;
                        if (_tvController.IsCardInUse(card.IdCard, out cardUser) == false)
                        {
                            _user.CardId = card.IdCard;
                            result       = RemoteControl.Instance.Tune(ref _user, tuning, channel.IdChannel);
                            if (result == TvResult.Succeeded)
                            {
                                if (!_isRunning || false == _tvController.GrabEpg(this, card.IdCard))
                                {
                                    if (!_isRunning)
                                    {
                                        Log.Epg("Tuning finished but EpgGrabber no longer enabled");
                                    }
                                    _tvController.StopGrabbingEpg(_user);
                                    _user.CardId = -1;
                                    Log.Epg("Epg: card:{0} could not start atsc epg grabbing", card.IdCard);
                                    return(false);
                                }
                                _user.CardId = card.IdCard;
                                return(true);
                            }
                            _user.CardId = -1;
                            Log.Epg("Epg: card:{0} could not tune to channel:{1}", card.IdCard, result.ToString());
                            return(false);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Write(ex);
                        throw;
                    }
                    return(false);
                }
                Log.Epg("Epg: card:{0} could not tune to atsc channel:{1}", card.IdCard, tuning.ToString());
                return(false);
            }

            //handle DVBC
            DVBCChannel dvbcChannel = tuning as DVBCChannel;

            if (dvbcChannel != null)
            {
                if (_tvController.Type(card.IdCard) == CardType.DvbC)
                {
                    if (IsCardIdle(card.IdCard) == false)
                    {
                        Log.Epg("Epg: card:{0} dvbc card is not idle", card.IdCard);
                        return(false); //card is busy
                    }
                    try
                    {
                        _user.CardId = card.IdCard;
                        result       = RemoteControl.Instance.Tune(ref _user, tuning, channel.IdChannel);
                        if (result == TvResult.Succeeded)
                        {
                            if (!_isRunning || false == _tvController.GrabEpg(this, card.IdCard))
                            {
                                if (!_isRunning)
                                {
                                    Log.Epg("Tuning finished but EpgGrabber no longer enabled");
                                }
                                _tvController.StopGrabbingEpg(_user);
                                _user.CardId = -1;
                                Log.Epg("Epg: card:{0} could not start dvbc epg grabbing", card.IdCard);
                                return(false);
                            }
                            _user.CardId = card.IdCard;
                            return(true);
                        }
                        _user.CardId = -1;
                        Log.Epg("Epg: card:{0} could not tune to channel:{1}", card.IdCard, result.ToString());
                        return(false);
                    }
                    catch (Exception ex)
                    {
                        Log.Write(ex);
                        throw;
                    }
                    //unreachable return false;
                }
                Log.Epg("Epg: card:{0} could not tune to dvbc channel:{1}", card.IdCard, tuning.ToString());
                return(false);
            }

            //handle DVBS
            DVBSChannel dvbsChannel = tuning as DVBSChannel;

            if (dvbsChannel != null)
            {
                if (_tvController.Type(card.IdCard) == CardType.DvbS)
                {
                    if (IsCardIdle(card.IdCard) == false)
                    {
                        Log.Epg("Epg: card:{0} dvbs card is not idle", card.IdCard);
                        return(false); //card is busy
                    }
                    try
                    {
                        _user.CardId = card.IdCard;
                        result       = RemoteControl.Instance.Tune(ref _user, tuning, channel.IdChannel);
                        if (result == TvResult.Succeeded)
                        {
                            if (!_isRunning || false == _tvController.GrabEpg(this, card.IdCard))
                            {
                                if (!_isRunning)
                                {
                                    Log.Epg("Tuning finished but EpgGrabber no longer enabled");
                                }
                                _tvController.StopGrabbingEpg(_user);
                                _user.CardId = -1;
                                Log.Epg("Epg: card:{0} could not start dvbs epg grabbing", card.IdCard);
                                return(false);
                            }
                            _user.CardId = card.IdCard;
                            return(true);
                        }
                        _user.CardId = -1;
                        Log.Epg("Epg: card:{0} could not tune to channel:{1}", card.IdCard, result.ToString());
                        return(false);
                    }
                    catch (Exception ex)
                    {
                        Log.Write(ex);
                        throw;
                    }
                    //unreachable return false;
                }
                Log.Epg("Epg: card:{0} could not tune to dvbs channel:{1}", card.IdCard, tuning.ToString());
                return(false);
            }

            //handle DVBT
            DVBTChannel dvbtChannel = tuning as DVBTChannel;

            if (dvbtChannel != null)
            {
                if (_tvController.Type(card.IdCard) == CardType.DvbT)
                {
                    if (IsCardIdle(card.IdCard) == false)
                    {
                        Log.Epg("Epg: card:{0} dvbt card is not idle", card.IdCard);
                        return(false); //card is busy
                    }
                    try
                    {
                        _user.CardId = card.IdCard;
                        result       = RemoteControl.Instance.Tune(ref _user, tuning, channel.IdChannel);
                        if (result == TvResult.Succeeded)
                        {
                            if (!_isRunning || false == _tvController.GrabEpg(this, card.IdCard))
                            {
                                if (!_isRunning)
                                {
                                    Log.Epg("Tuning finished but EpgGrabber no longer enabled");
                                }
                                _tvController.StopGrabbingEpg(_user);
                                _user.CardId = -1;
                                Log.Epg("Epg: card:{0} could not start dvbt grabbing", card.IdCard);
                                return(false);
                            }
                            _user.CardId = card.IdCard;
                            return(true);
                        }
                        _user.CardId = -1;
                        Log.Epg("Epg: card:{0} could not tune to channel:{1}", card.IdCard, result.ToString());
                        return(false);
                    }
                    catch (Exception ex)
                    {
                        Log.Write(ex);
                        throw;
                    }
                    //unreachable return false;
                }
                Log.Epg("Epg: card:{0} could not tune to dvbt channel:{1}", card.IdCard, tuning.ToString());
                return(false);
            }

            //handle DVBIP
            DVBIPChannel dvbipChannel = tuning as DVBIPChannel;

            if (dvbipChannel != null)
            {
                if (_tvController.Type(card.IdCard) == CardType.DvbIP)
                {
                    if (IsCardIdle(card.IdCard) == false)
                    {
                        Log.Epg("Epg: card:{0} dvbip card is not idle", card.IdCard);
                        return(false); //card is busy
                    }
                    try
                    {
                        _user.CardId = card.IdCard;
                        result       = RemoteControl.Instance.Tune(ref _user, tuning, channel.IdChannel);
                        if (result == TvResult.Succeeded)
                        {
                            if (!_isRunning || false == _tvController.GrabEpg(this, card.IdCard))
                            {
                                if (!_isRunning)
                                {
                                    Log.Epg("Tuning finished but EpgGrabber no longer enabled");
                                }
                                _tvController.StopGrabbingEpg(_user);
                                _user.CardId = -1;
                                Log.Epg("Epg: card:{0} could not start dvbip grabbing", card.IdCard);
                                return(false);
                            }
                            _user.CardId = card.IdCard;
                            return(true);
                        }
                        else
                        {
                            _user.CardId = -1;
                            Log.Epg("Epg: card:{0} could not tune to channel:{1}", card.IdCard, result.ToString());
                            return(false);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Write(ex);
                        throw ex;
                    }
                    //unreachable return false;
                }
                else
                {
                    Log.Epg("Epg: card:{0} could not tune to dvbip channel:{1}", card.IdCard, tuning.ToString());
                }
                return(false);
            }
            Log.Epg("Epg: card:{0} could not tune to channel:{1}", card.IdCard, tuning.ToString());
            return(false);
        }