예제 #1
0
 public static bool IsSameTransponder(int cardId, TvDatabase.TuningDetail tuning, TvDatabase.Channel otherChannel)
 {
     TvDatabase.TuningDetail otherTuning = Utility.FindTuningDetailOnCard(otherChannel, cardId);
     if (tuning != null &&
         otherTuning != null)
     {
         if (tuning.ChannelType >= 2 && tuning.ChannelType <= 4 && // DVB-x channel? ,no Atsc(==1)
             tuning.ChannelType == otherTuning.ChannelType &&
             tuning.Frequency == otherTuning.Frequency &&
             tuning.Symbolrate == otherTuning.Symbolrate &&
             tuning.Polarisation == otherTuning.Polarisation &&
             tuning.Bandwidth == otherTuning.Bandwidth &&
             tuning.Modulation == otherTuning.Modulation)
         {
             return(true);
         }
         if (tuning.ChannelType == 0 && // Analog
             tuning.ChannelType == otherTuning.ChannelType &&
             tuning.IdChannel == otherTuning.IdChannel)
         {
             return(true);
         }
     }
     return(false);
 }
예제 #2
0
        public static bool CardFreeOrUsingSameTransponder(TvDatabase.Card card, TvDatabase.Channel channel, IUser userToIgnore)
        {
            IUser[] cardUsers = TvServerPlugin.TvController_GetUsersForCard(card.IdCard);
            if (cardUsers != null)
            {
                TvDatabase.TuningDetail tuning = Utility.FindTuningDetailOnCard(channel, card.IdCard);

                HashSet <int> activeChannels = new HashSet <int>();

                foreach (IUser cardUser in cardUsers)
                {
                    if (userToIgnore == null ||
                        cardUser.Name != userToIgnore.Name)
                    {
                        if (!cardUser.Name.Equals("epg", StringComparison.InvariantCultureIgnoreCase))
                        {
                            activeChannels.Add(cardUser.IdChannel);
                            if (!Utility.IsSameTransponder(card.IdCard, tuning, cardUser.IdChannel))
                            {
                                return(false);
                            }
                        }
                    }
                }

                return(activeChannels.Contains(channel.IdChannel) ||
                       card.DecryptLimit == 0 ||
                       activeChannels.Count < card.DecryptLimit);
            }
            return(true);
        }
        public override string AllocateCard(Channel channel, CardChannelAllocation[] alreadyAllocated, bool useReversePriority)
        {
            try
            {
                //
                // Find the channel in MediaPortal (match by DisplayName) and get all the
                // cards this channel is mapped to.
                //
                TvDatabase.Channel     mpChannel;
                List <TvDatabase.Card> availableCards = GetCardsForChannel(channel, out mpChannel);

                // Sort the cards by reverse(!) priority.
                int order = useReversePriority ? -1 : 1;
                availableCards.Sort(delegate(TvDatabase.Card c1, TvDatabase.Card c2) { return(order * c1.Priority.CompareTo(c2.Priority)); });

                //
                // Now remove all cards that were previously allocated.
                //
                foreach (CardChannelAllocation allocation in alreadyAllocated)
                {
                    TvDatabase.Card        allocatedCard           = GetCardByCardId(allocation.CardId);
                    List <int>             allocatedHybridGroupIds = Utility.GetHybridGroupIds(allocatedCard);
                    List <TvDatabase.Card> cardsToRemove           = new List <TvDatabase.Card>();
                    foreach (TvDatabase.Card card in availableCards)
                    {
                        bool isHybrid = (card.IdCard != allocatedCard.IdCard) &&
                                        Utility.IsInSameHybridGroup(card, allocatedHybridGroupIds);
                        if (isHybrid ||
                            !IsCardFreeOrSharedByAllocation(card, mpChannel, allocation, alreadyAllocated))
                        {
                            cardsToRemove.Add(card);
                        }
                    }
                    foreach (TvDatabase.Card cardToRemove in cardsToRemove)
                    {
                        availableCards.Remove(cardToRemove);
                    }
                }

                //
                // If there's still at least one card available, return the card
                // with the highest priority.
                //
                foreach (TvDatabase.Card card in availableCards)
                {
                    TvDatabase.TuningDetail tuning = Utility.FindTuningDetailOnCard(mpChannel, card.IdCard);
                    if (tuning != null)
                    {
                        return(GetCardId(card));
                    }
                }
            }
            catch (Exception ex)
            {
                Log(TraceEventType.Error, ex.Message);
            }
            return(null);
        }
예제 #4
0
 public static bool IsSameTransponder(int cardId, TvDatabase.TuningDetail tuning, int otherChannelId)
 {
     TvDatabase.Channel otherChannel = TvDatabase.Channel.Retrieve(otherChannelId);
     if (otherChannel != null)
     {
         return(IsSameTransponder(cardId, tuning, otherChannel));
     }
     return(false);
 }
 private bool EnsureCardFree(bool allowOtherArgusUser, ref string errorMessage, out bool argusIsRecordingOnCard)
 {
     argusIsRecordingOnCard = false;
     IUser[] cardUsers = TvServerPlugin.TvController_GetUsersForCard(_recordOnCard.IdCard);
     if (cardUsers != null)
     {
         TvDatabase.TuningDetail tuning = Utility.FindTuningDetailOnCard(_channel, _recordOnCard.IdCard);
         foreach (IUser cardUser in cardUsers)
         {
             if (!cardUser.Name.Equals("epg", StringComparison.InvariantCultureIgnoreCase))
             {
                 if (cardUser.Name.StartsWith("ArgusTV"))
                 {
                     if (!allowOtherArgusUser &&
                         !Utility.IsSameTransponder(_recordOnCard.IdCard, tuning, cardUser.IdChannel))
                     {
                         // Seems another ARGUS TV user is using this card, but on a different
                         // transponder!  Normally this should never happen, but in rare conditions
                         // we need to be able to handle this.
                         errorMessage           = "Card is in use by previous recording";
                         argusIsRecordingOnCard = true;
                         return(false);
                     }
                 }
                 else
                 {
                     IUser tmpUser = cardUser;
                     if (TvServerPlugin.TvController_IsRecording(ref tmpUser))
                     {
                         if (!TvServerPlugin.TvController_StopRecording(ref tmpUser))
                         {
                             errorMessage = "Failed to stop recording on channel " + _channel.DisplayName;
                             return(false);
                         }
                     }
                     else if (TvServerPlugin.TvController_IsTimeShifting(ref tmpUser))
                     {
                         if (!Utility.IsSameTransponder(_recordOnCard.IdCard, tuning, tmpUser.IdChannel))
                         {
                             if (!TvServerPlugin.TvController_StopTimeShifting(ref tmpUser, TvStoppedReason.RecordingStarted))
                             {
                                 errorMessage = "Failed to stop timeshifting on channel " + _channel.DisplayName;
                                 return(false);
                             }
                         }
                     }
                 }
             }
         }
     }
     return(true);
 }
        private bool IsCardFreeOrSharedByAllocation(TvDatabase.Card card, TvDatabase.Channel mpChannel, CardChannelAllocation allocation,
                                                    CardChannelAllocation[] alreadyAllocated)
        {
            TvDatabase.TuningDetail tuning = Utility.FindTuningDetailOnCard(mpChannel, card.IdCard);
            if (GetCardId(card) == allocation.CardId &&
                tuning != null)
            {
                //
                // The card is allocated by this allocation, but may be able to reuse the card. So let's
                // check if the if the card (and CAM) allow this.
                //
                // Note: "!ChannelAlreadyAllocatedOn(alreadyAllocated, allocation.CardId, channelId)" was
                // not added since TV Server can record the same channel several times on the same transponder.
                if (card.DecryptLimit == 0 ||
                    CountNumTimesAllocated(alreadyAllocated, allocation.CardId) < card.DecryptLimit)
                {
                    // Get the previously allocated channel and its tuning details and let's check if the
                    // channel we want is on the same transponder as that channel.
                    TvDatabase.Channel allocatedChannel = GetLinkedMediaPortalChannel(allocation.ChannelType,
                                                                                      allocation.ChannelId, allocation.ChannelName);
                    TvDatabase.Card allocatedCard = GetCardByCardId(allocation.CardId);
                    if (allocatedChannel != null &&
                        allocatedCard != null &&
                        Utility.IsSameTransponder(allocatedCard.IdCard, tuning, allocatedChannel))
                    {
                        // Same transponder, so we can actually re-use this card and consider it free.
                        return(true);
                    }
                }
                // The card is allocated by this allocation, and it's not for a channel on the same
                // transponder, so it's not free.
                return(false);
            }

            // The card is not allocated by this allocation, so it's free.
            return(true);
        }