Exemple #1
0
 /// <summary>
 /// Checks if the schedule specified is currently being recorded and ifso
 /// returns on which card
 /// </summary>
 /// <param name="idSchedule">id of the Schedule</param>
 /// <param name="card">returns card is recording the channel</param>
 /// <returns>true if a card is recording the schedule, otherwise false</returns>
 public bool IsRecordingSchedule(int idSchedule, out VirtualCard card)
 {
     card = null;
     try
     {
         return(RemoteControl.Instance.IsRecordingSchedule(idSchedule, out card));
     }
     catch (Exception e)
     {
         HandleFailure("IsRecordingSchedule", e);
     }
     return(false);
 }
Exemple #2
0
 /// <summary>
 /// Start timeshifting on a specific channel
 /// </summary>
 /// <param name="user">The user.</param>
 /// <param name="idChannel">id of the channel</param>
 /// <param name="card">returns on which card timeshifting is started</param>
 /// <param name="forceCardId">Indicated, if the card should be forced</param>
 /// <returns>
 /// TvResult indicating whether method succeeded
 /// </returns>
 public TvResult StartTimeShifting(ref IUser user, int idChannel, out VirtualCard card, bool forceCardId)
 {
     card = null;
     try
     {
         TvResult result = RemoteControl.Instance.StartTimeShifting(ref user, idChannel, out card, forceCardId);
         return(result);
     }
     catch (Exception e)
     {
         HandleFailure("StartTimeShifting.3", e);
     }
     return(TvResult.UnknownError);
 }
 /// <summary>
 /// Start timeshifting on a specific channel
 /// </summary>
 /// <param name="user">The user.</param>
 /// <param name="idChannel">id of the channel</param>
 /// <param name="card">returns on which card timeshifting is started</param>
 /// <param name="cardChanged">indicates if card was changed</param>
 /// <returns>
 /// TvResult indicating whether method succeeded
 /// </returns>
 public TvResult StartTimeShifting(ref IUser user, int idChannel, out VirtualCard card, out bool cardChanged)
 {
     card        = null;
     cardChanged = false;
     try
     {
         TvResult result = RemoteControl.Instance.StartTimeShifting(ref user, idChannel, out card, out cardChanged);
         return(result);
     }
     catch (Exception)
     {
         HandleFailure();
     }
     return(TvResult.UnknownError);
 }
Exemple #4
0
        /// <summary>
        /// Determines whether the specified channel is recording.
        /// </summary>
        /// <param name="idChannel">The id of the channel.</param>
        /// <param name="card">The vcard.</param>
        /// <returns>
        ///     <c>true</c> if the specified channel name is recording; otherwise, <c>false</c>.
        /// </returns>
        public bool IsRecording(int idChannel, out VirtualCard card)
        {
            VirtualCard vc = card = null;

            try
            {
                bool result = WaitFor <bool> .Run(VirtualCard.CommandTimeOut,
                                                  () => RemoteControl.Instance.IsRecording(idChannel, out vc));

                card = vc;
                return(result);
            }
            catch (Exception e)
            {
                HandleFailure("IsRecording", e);
            }
            return(false);
        }
 /// <summary>
 /// Determines whether the specified channel name is recording.
 /// </summary>
 /// <param name="channelName">Name of the channel.</param>
 /// <param name="card">The vcard.</param>
 /// <returns>
 /// 	<c>true</c> if the specified channel name is recording; otherwise, <c>false</c>.
 /// </returns>
 public bool IsRecording(int idChannel, out VirtualCard card)
 {
   card = null;
   Dictionary<int, ITvCardHandler>.Enumerator en = _cards.GetEnumerator();
   while (en.MoveNext())
   {
     ITvCardHandler tvcard = en.Current.Value;
     IUser[] users = tvcard.Users.GetUsers();
     if (users == null)
       continue;
     if (users.Length == 0)
       continue;
     for (int i = 0; i < users.Length; ++i)
     {
       IUser user = users[i];
       if (tvcard.CurrentChannelName(ref user) == null)
         continue;
       if (tvcard.CurrentDbChannel(ref user) == idChannel)
       {
         if (tvcard.Recorder.IsRecording(ref user))
         {
           card = GetVirtualCard(user);
           return true;
         }
       }
     }
   }
   return false;
 }
Exemple #6
0
        /// <summary>
        /// Kicks a user from a TV card if timeshifting.
        /// </summary>
        /// <param name="card"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static bool StopTimeshifting(Card card)
        {
            SetupConnection();

            VirtualCard vcard;
            IUser[] usersForCard = RemoteControl.Instance.GetUsersForCard(card.IdCard);

            foreach (IUser user in usersForCard)
            {
                vcard = new VirtualCard(user, RemoteControl.HostName);
                try
                {
                    if (vcard.IsTimeShifting)
                    {
                        vcard.StopTimeShifting();
                        return true;
                    }
                }
                catch (Exception ex)
                {
                    return false;
                }
            }

            return false;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TvServerEventArgs"/> class.
 /// </summary>
 /// <param name="eventType">Type of the _event.</param>
 /// <param name="card">The card.</param>
 /// <param name="user">The user.</param>
 public TvServerEventArgs(TvServerEventType eventType, VirtualCard card, User user)
 {
   _eventType = eventType;
   _card = card;
   _user = user;
 }
 /// <summary>
 /// returns the virtualcard which is recording the channel specified
 /// </summary>
 /// <param name="channelId">Id of the channel</param>
 /// <returns>virtual card</returns>
 public VirtualCard GetCardRecordingChannel(int channelId)
 {
   IList<Card> cards = Card.ListAll();
   foreach (Card card in cards)
   {
     if (card.Enabled == false) continue;
     if (!RemoteControl.Instance.CardPresent(card.IdCard)) continue;
     IUser[] usersForCard = RemoteControl.Instance.GetUsersForCard(card.IdCard);
     if (usersForCard == null) continue;
     if (usersForCard.Length == 0) continue;
     for (int i = 0; i < usersForCard.Length; ++i)
     {
       if (usersForCard[i].IdChannel == channelId)
       {
         VirtualCard vcard = new VirtualCard(usersForCard[i], RemoteControl.HostName);
         if (vcard.IsRecording)
         {
           vcard.RecordingFolder = card.RecordingFolder;
           return vcard;
         }
       }
     }
   }
   return null;
 }
Exemple #9
0
    /// <summary>
    /// Update the state of the following buttons    
    /// - record now
    /// </summary>
    private void UpdateStateOfRecButton()
    {
      if (!Connected)
      {
        btnTvOnOff.Selected = false;
        return;
      }
      bool isTimeShifting = Card.IsTimeShifting;

      //are we recording a tv program?      
      if (Navigator.Channel != null && Card != null)
      {
        string label;
        TvServer server = new TvServer();
        VirtualCard vc;
        if (server.IsRecording(Navigator.Channel.IdChannel, out vc))
        {
          if (!isTimeShifting)
          {
            Card = vc;
          }
          //yes then disable the timeshifting on/off buttons
          //and change the Record Now button into Stop Record
          label = GUILocalizeStrings.Get(629); //stop record
        }
        else
        {
          //nop. then change the Record Now button
          //to Record Now
          label = GUILocalizeStrings.Get(601); // record
        }
        if (label != btnRecord.Label)
        {
          btnRecord.Label = label;
        }
      }
    }
 public WebReceptionDetails GetReceptionDetails()
 {
     WebReceptionDetails details = new WebReceptionDetails();
       if (!ConnectToDatabase())
     return details;
       VirtualCard vcard;
       try
       {
     vcard = new VirtualCard(new User("gemx",true), RemoteControl.HostName);
       }
       catch (Exception)
       {
     return details;
       }
       details.signalLevel = vcard.SignalLevel;
       details.signalQuality = vcard.SignalQuality;
       return details;
 }
 /// <summary>
 /// returns a virtual card for this tvcard
 /// </summary>
 /// <returns></returns>
 public VirtualCard GetVirtualCard(IUser user)
 {
   VirtualCard card = new VirtualCard(user);
   card.RecordingFormat = _dbsCard.RecordingFormat;
   card.RecordingFolder = _dbsCard.RecordingFolder;
   card.TimeshiftFolder = _dbsCard.TimeShiftFolder;
   card.RemoteServer = Dns.GetHostName();
   return card;
 }
Exemple #12
0
 /// <summary>
 /// Start timeshifting on a specific channel
 /// </summary>
 /// <param name="user">The user.</param>
 /// <param name="idChannel">id of the channel</param>
 /// <param name="card">returns on which card timeshifting is started</param>
 /// <param name="forceCardId">Indicated, if the card should be forced</param>
 /// <returns>
 /// TvResult indicating whether method succeeded
 /// </returns>
 public TvResult StartTimeShifting(ref IUser user, int idChannel, out VirtualCard card, bool forceCardId)
 {
   card = null;
   try
   {
     TvResult result = RemoteControl.Instance.StartTimeShifting(ref user, idChannel, out card, forceCardId);
     return result;
   }
   catch (Exception e)
   {
     HandleFailure("StartTimeShifting.3", e);
   }
   return TvResult.UnknownError;
 }
Exemple #13
0
    private void OnActiveStreams()
    {
      GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU);
      if (dlg == null)
      {
        return;
      }
      dlg.Reset();
      dlg.SetHeading(692); // Active Tv Streams
      int selected = 0;
      string remoteHostName = string.Empty;
      IList<Card> cards = TvDatabase.Card.ListAll();
      List<Channel> channels = new List<Channel>();
      int count = 0;
      TvServer server = new TvServer();
      List<IUser> _users = new List<IUser>();
      foreach (Card card in cards)
      {
        if (card.Enabled == false)
        {
          continue;
        }
        if (!RemoteControl.Instance.CardPresent(card.IdCard))
        {
          continue;
        }
        IUser[] users = RemoteControl.Instance.GetUsersForCard(card.IdCard);

        if (users == null)
        {
          return;
        }
        for (int i = 0; i < users.Length; ++i)
        {
          IUser user = users[i];
          Log.Debug("rtsp url: {0}, {1}", user, RemoteControl.Instance.GetStreamingUrl(user));
          
          if (card.IdCard != user.CardId)
          {
            continue;
          }
          bool isRecording;
          bool isTimeShifting;
          VirtualCard tvcard = new VirtualCard(user, RemoteControl.HostName);
          isRecording = tvcard.IsRecording;
          isTimeShifting = tvcard.IsTimeShifting;
          if (isTimeShifting || (isRecording && !isTimeShifting))
          {
            int idChannel = tvcard.IdChannel;
            user = tvcard.User;
            Channel ch = Channel.Retrieve(idChannel);
            channels.Add(ch);
            GUIListItem item = new GUIListItem();
            item.Label = ch.DisplayName;
            item.Label2 = user.Name;
            string strLogo = Utils.GetCoverArt(Thumbs.TVChannel, ch.DisplayName);
            if (string.IsNullOrEmpty(strLogo))
            {
              strLogo = "defaultVideoBig.png";
            }
            item.IconImage = strLogo;
            if (isRecording)
            {
              item.PinImage = Thumbs.TvRecordingIcon;
            }
            else
            {
              item.PinImage = "";
            }
            dlg.Add(item);
            _users.Add(user);
            if (Card != null && Card.IdChannel == idChannel)
            {
              selected = count;
            }
            count++;
          }
        }
      }
      if (channels.Count == 0)
      {
        GUIDialogOK pDlgOK = (GUIDialogOK)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_OK);
        if (pDlgOK != null)
        {
          pDlgOK.SetHeading(692); //my tv
          pDlgOK.SetLine(1, GUILocalizeStrings.Get(1511)); // No Active streams
          pDlgOK.SetLine(2, "");
          pDlgOK.DoModal(this.GetID);
        }
        return;
      }
      dlg.SelectedLabel = selected;
      dlg.DoModal(this.GetID);
      if (dlg.SelectedLabel < 0)
      {
 
        return;
      }

      string selectedUrl = RemoteControl.Instance.GetStreamingUrl(_users[dlg.SelectedLabel]);
      VirtualCard vCard = new VirtualCard(_users[dlg.SelectedLabel], RemoteControl.HostName);
      Channel channel = Navigator.GetChannel(vCard.IdChannel);
      User myUser = new User();

      /// Connect to the virtual user and play
      if (_users[dlg.SelectedLabel].Name.Contains("Placeshift Virtual User"))
      {
        if (inPlaceShift)
        {
          vPlaceshiftCard.StopTimeShifting();
        }
        else if (Card.IsTimeShifting)
        {
          Card.StopTimeShifting();
        }

        myUser.CardId = vCard.Id;

        // Replace the virtual user to local user
        RemoteControl.Instance.ReplaceTimeshiftUser(vCard.Id, myUser, _users[dlg.SelectedLabel].Name);

        // Send heartbeat ASAP
        RemoteControl.Instance.HeartBeat(myUser);

        if (!g_Player.Play(selectedUrl, g_Player.MediaType.TV, null, false))
        {
          StopPlayback();
        }

        // Seek to same position as the TV was stopped on another client.
        double TimeshiftPosition = RemoteControl.Instance.GetTimeshiftPosition(vCard.Id, myUser);
        g_Player.SeekAbsolute(TimeshiftPosition);

        Navigator.setChannel(channel);
        UpdateCurrentChannel();

        Log.Debug("placeshift selected active rtspUrl: {0} for channel: {1}, user: {2}, vCard.Id: {3}, TimeshiftPosition: {4}", 
          selectedUrl, channel.DisplayName, _users[dlg.SelectedLabel].Name, vCard.Id, TimeshiftPosition);

        // Setup vPlaceshiftCard for stoptimeshift
        vPlaceshiftCard = vCard;
        vPlaceshiftCard.User.Name = myUser.Name;
        inPlaceShift = true;
      }
      else
      {
        if (myUser.Name != _users[dlg.SelectedLabel].Name && OnShareTsBuffer())
        {
          if (inPlaceShift)
          {
            vPlaceshiftCard.StopTimeShifting();
          }
          else if (Card.IsTimeShifting)
          {
            Card.StopTimeShifting();
          }

          if (!g_Player.Play(selectedUrl, g_Player.MediaType.TV, null, false))
          {
            StopPlayback();
          }

          Navigator.setChannel(channel);
          UpdateCurrentChannel();

        }
        else
        {
         ViewChannel(channel);
        }
      }
    }
 /// <summary>
 /// Initializes a new instance of the <see cref="TvServerEventArgs"/> class.
 /// </summary>
 /// <param name="eventType">Type of the _event.</param>
 /// <param name="card">The card.</param>
 /// <param name="user">The user.</param>
 /// <param name="channel">The channel.</param>
 public TvServerEventArgs(TvServerEventType eventType, VirtualCard card, User user, IChannel channel)
 {
   _eventType = eventType;
   _card = card;
   _user = user;
   _channel = channel;
 }
 /// <summary>
 /// Method which returns which card is currently recording the Schedule with the specified scheduleid
 /// </summary>
 /// <param name="idSchedule">database id of the schedule</param>
 /// <param name="card">virtual card</param>
 /// <returns>true if a card is recording the schedule, else false</returns>
 public bool IsRecordingSchedule(int idSchedule, out VirtualCard card)
 {
   card = null;
   foreach (RecordingDetail rec in _recordingsInProgressList)
   {
     if (rec.Schedule.IdSchedule == idSchedule)
     {
       IUser user = UserFactory.CreateSchedulerUser(rec.Schedule.IdSchedule, rec.CardInfo.Id);          
       card = new VirtualCard(user);
       return true;
     }
   }
   return false;
 }
 /// <summary>
 /// Start timeshifting on a specific channel
 /// </summary>
 /// <param name="user">The user.</param>
 /// <param name="idChannel">id of the channel</param>
 /// <param name="card">returns on which card timeshifting is started</param>
 /// <param name="cardChanged">indicates if card was changed</param>
 /// <returns>
 /// TvResult indicating whether method succeeded
 /// </returns>
 public TvResult StartTimeShifting(ref IUser user, int idChannel, out VirtualCard card, out bool cardChanged)
 {
   card = null;
   cardChanged = false;
   try
   {
     TvResult result = RemoteControl.Instance.StartTimeShifting(ref user, idChannel, out card, out cardChanged);
     return result;
   }
   catch (Exception)
   {
     HandleFailure();
   }
   return TvResult.UnknownError;
 }
        public List<StreamingStatus> GetStreamingStatus()
        {
            List<StreamingStatus> states = new List<StreamingStatus>();
            VirtualCard vcard;
            try
            {

                IList<TvDatabase.Card> cards = Card.ListAll();

                foreach (Card card in cards)
                {
                    IUser user = new User();
                    user.CardId = card.IdCard;
                    IUser[] usersForCard = controller.GetUsersForCard(card.IdCard);
                    if (usersForCard == null)
                    {
                        StreamingStatus state = new StreamingStatus();
                        vcard = new VirtualCard(user, RemoteControl.HostName);
                        string tmp = "idle";
                        if (vcard.IsScanning) tmp = "Scanning";
                        if (vcard.IsGrabbingEpg) tmp = "Grabbing EPG";
                        state.cardId = card.IdCard;
                        state.cardName = vcard.Name;
                        state.cardType = vcard.Type.ToString();
                        state.status = tmp;
                        state.channelName = "";
                        state.userName = "";
                        states.Add(state);
                        continue;
                    }
                    if (usersForCard.Length == 0)
                    {
                        StreamingStatus state = new StreamingStatus();
                        vcard = new VirtualCard(user, RemoteControl.HostName);
                        string tmp = "idle";
                        if (vcard.IsScanning) tmp = "Scanning";
                        if (vcard.IsGrabbingEpg) tmp = "Grabbing EPG";
                        state.cardId = card.IdCard;
                        state.cardName = vcard.Name;
                        state.cardType = vcard.Type.ToString();
                        state.status = tmp;
                        state.channelName = "";
                        state.userName = "";
                        states.Add(state);
                        continue;
                    }
                    for (int i = 0; i < usersForCard.Length; ++i)
                    {
                        StreamingStatus state = new StreamingStatus();
                        string tmp = "idle";
                        vcard = new VirtualCard(usersForCard[i], RemoteControl.HostName);
                        if (vcard.IsTimeShifting)
                            tmp = "Timeshifting";
                        else
                            if (vcard.IsRecording)
                                tmp = "Recording";
                            else
                                if (vcard.IsScanning)
                                    tmp = "Scanning";
                                else
                                    if (vcard.IsGrabbingEpg)
                                        tmp = "Grabbing EPG";
                        state.cardId = card.IdCard;
                        state.cardName = vcard.Name;
                        state.cardType = vcard.Type.ToString();
                        state.status = tmp;
                        state.channelName = vcard.ChannelName;
                        state.userName = vcard.User.Name;
                        state.channelId = vcard.IdChannel;
                        state.TimeShiftFileName = vcard.TimeShiftFileName;
                        state.RTSPUrl = vcard.RTSPUrl;
                        states.Add(state);
                    }
                }
            }
            catch (Exception ex)
            {
                lastException = ex;
                Console.WriteLine(ex.ToString());
                Log.Error("TVServerKodi: " + ex.ToString());
                return null;
            }
            return states;
        }
 public ReceptionDetails GetReceptionDetails()
 {
     VirtualCard vcard;
     try
     {
         vcard = new VirtualCard(me, RemoteControl.HostName);
     }
     catch (Exception ex)
     {
         lastException = ex;
         Console.WriteLine(ex.ToString());
         Log.Error("TVServerXBMC: " + ex.ToString());
         return null;
     }
     ReceptionDetails details = new ReceptionDetails();
     details.signalLevel = vcard.SignalLevel;
     details.signalQuality = vcard.SignalQuality;
     return details;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TvServerEventArgs"/> class.
 /// </summary>
 /// <param name="eventType">Type of the event.</param>
 /// <param name="card">The card.</param>
 /// <param name="user">The user.</param>
 /// <param name="conflict">The conflict.</param>
 public TvServerEventArgs(TvServerEventType eventType, VirtualCard card, User user, Conflict conflict)
 {
   _eventType = eventType;
   _card = card;
   _user = user;
   _channel = channel;
   _conflict = conflict;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TvServerEventArgs"/> class.
 /// </summary>
 /// <param name="eventType">Type of the event.</param>
 /// <param name="card">The card.</param>
 /// <param name="user">The user.</param>
 /// <param name="schedule">The schedule.</param>
 /// <param name="recording">The recording.</param>
 public TvServerEventArgs(TvServerEventType eventType, VirtualCard card, User user, Schedule schedule,
                          Recording recording)
 {
   _eventType = eventType;
   _card = card;
   _user = user;
   _channel = channel;
   _schedule = schedule;
   _recording = recording;
 }
Exemple #21
0
 /// <summary>
 /// Determines whether the specified channel is recording.
 /// </summary>
 /// <param name="idChannel">The id of the channel.</param>
 /// <param name="card">The vcard.</param>
 /// <returns>
 /// 	<c>true</c> if the specified channel name is recording; otherwise, <c>false</c>.
 /// </returns>
 public bool IsRecording(int idChannel, out VirtualCard card)
 {
   VirtualCard vc = card = null;
   try
   {
     bool result = WaitFor<bool>.Run(VirtualCard.CommandTimeOut,
                                     () => RemoteControl.Instance.IsRecording(idChannel, out vc));
     card = vc;
     return result;
   }
   catch (Exception e)
   {
     HandleFailure("IsRecording", e);
   }
   return false;
 }
    /// <summary>
    /// Determines whether the specified channel name is recording.
    /// </summary>
    /// <param name="channelName">Name of the channel.</param>
    /// <param name="card">The vcard.</param>    
    /// <param name="isTS">timeshifting.</param>    
    /// <param name="isREC">recording</param>    
    /// <returns>
    /// 	<c>true</c> if the specified channel name is recording or timeshifting; otherwise, <c>false</c>.
    /// </returns>
    public bool IsRecordingTimeshifting(string channelName, out VirtualCard card, out bool isTS, out bool isREC)
    {
      isREC = false;
      isTS = false;
      card = null;
      Dictionary<int, ITvCardHandler>.Enumerator en = _cards.GetEnumerator();
      ITvCardHandler tvcard;
      IUser recUser = null;
      while (en.MoveNext())
      {
        tvcard = en.Current.Value;
        IUser[] users = tvcard.Users.GetUsers();
        if (users == null)
          continue;
        if (users.Length == 0)
          continue;
        for (int i = 0; i < users.Length; ++i)
        {
          IUser user = users[i];
          if (tvcard.CurrentChannelName(ref user) == null)
            continue;
          if (tvcard.CurrentChannelName(ref user) == channelName)
          {
            if (!isREC)
            {
              isREC = tvcard.Recorder.IsRecording(ref user);
              if (isREC)
              {
                recUser = user;
              }
            }
            if (!isTS)
            {
              isTS = tvcard.TimeShifter.IsTimeShifting(ref user);
            }
          }
        }
      }

      if (isREC || isTS)
      {
        if (recUser != null)
        {
          card = GetVirtualCard(recUser);
        }
        return true;
      }
      return false;
    }
Exemple #23
0
 /// <summary>
 /// Checks if the schedule specified is currently being recorded and ifso
 /// returns on which card
 /// </summary>
 /// <param name="idSchedule">id of the Schedule</param>
 /// <param name="card">returns card is recording the channel</param>
 /// <returns>true if a card is recording the schedule, otherwise false</returns>
 public bool IsRecordingSchedule(int idSchedule, out VirtualCard card)
 {
   card = null;
   try
   {
     return RemoteControl.Instance.IsRecordingSchedule(idSchedule, out card);
   }
   catch (Exception e)
   {
     HandleFailure("IsRecordingSchedule", e);
   }
   return false;
 }
 /// <summary>
 /// Start timeshifting on a specific channel
 /// </summary>
 /// <param name="user">user credentials.</param>
 /// <param name="idChannel">The id channel.</param>
 /// <param name="card">returns card for which timeshifting is started</param>
 /// <param name="forceCardId">Indicated, if the card should be forced</param>
 /// <param name="cardChanged">indicates if card was changed</param>
 /// <returns>
 /// TvResult indicating whether method succeeded
 /// </returns>
 public TvResult StartTimeShifting(ref IUser user, int idChannel, out VirtualCard card, bool forceCardId)
 {
   bool cardChanged = false;
   return StartTimeShifting(ref user, idChannel, out card, forceCardId, out cardChanged);
 }
        public List<WebActiveStream> GetActiveStreams()
        {
            IList<Card> cards = Card.ListAll();
              List<Channel> channels = new List<Channel>();
              TvControl.TvServer server = new TvControl.TvServer();
              List<User> _users = new List<User>();
              List<WebActiveStream> activestream = new List<WebActiveStream>();
              if(!ConnectToDatabase())
            return activestream;

              foreach (Card card in cards)
              {
            if (card.Enabled == false)
              continue;
            if (!RemoteControl.Instance.CardPresent(card.IdCard))
              continue;
            User[] users = RemoteControl.Instance.GetUsersForCard(card.IdCard);
            if (users == null)
              return activestream;

            for (int i = 0; i < users.Length; ++i)
            {
              User user = users[i];
              if (card.IdCard != user.CardId)
            continue;

              bool isRecording;
              bool isTimeShifting;

              VirtualCard tvcard = new VirtualCard(user, RemoteControl.HostName);
              isRecording = tvcard.IsRecording;
              isTimeShifting = tvcard.IsTimeShifting;
              if (isTimeShifting || (isRecording && !isTimeShifting))
              {
            int idChannel = tvcard.IdChannel;
            try
            {
              WebChannel channel = new WebChannel(Channel.Retrieve(idChannel));
              WebTvServerUser tvServerUser = new WebTvServerUser(tvcard.User);
              WebActiveStream stream = new WebActiveStream(tvServerUser, channel);
              activestream.Add(stream);
            }
            catch (Exception ex)
            {
              // FIXME: handle it
            }
              }
            }
              }
              return activestream;
        }
    /// <summary>
    /// Start timeshifting on a specific channel
    /// </summary>
    /// <param name="user">user credentials.</param>
    /// <param name="idChannel">The id channel.</param>
    /// <param name="card">returns card for which timeshifting is started</param>
    /// <param name="forceCardId">Indicated, if the card should be forced</param>
    /// <param name="cardChanged">indicates if card was changed</param>
    /// <returns>
    /// TvResult indicating whether method succeeded
    /// </returns>
    public TvResult StartTimeShifting(ref IUser user, int idChannel, out VirtualCard card, bool forceCardId,
                                      out bool cardChanged)
    {
      cardChanged = false;
      if (user == null)
      {
        card = null;
        return TvResult.UnknownError;
      }

      string intialTimeshiftingFilename = "";

      VirtualCard initialCard = null;

      if (user.CardId != -1)
        initialCard = GetVirtualCard(user);

      if (initialCard != null && initialCard.TimeShiftFileName != null)
      {
        intialTimeshiftingFilename = initialCard.TimeShiftFileName;
      }

      Channel channel = Channel.Retrieve(idChannel);
      Log.Write("Controller: StartTimeShifting {0} {1}", channel.DisplayName, channel.IdChannel);
      card = null;
      if (_epgGrabber != null)
      {
        _epgGrabber.Stop();
      }
      IUser userCopy = null;
      try
      {
        TvResult result;
        List<CardDetail> freeCards = _cardAllocation.GetFreeCardsForChannel(_cards, channel, ref user, out result);
        if (freeCards.Count == 0)
        {
          //no free cards available
          Log.Write("Controller: StartTimeShifting failed:{0}", result);

          if (_epgGrabber != null && AllCardsIdle)
          {
            _epgGrabber.Start();
          }
          return result;
        }

        int maxCards;
        if (_maxFreeCardsToTry == 0)
        {
          maxCards = freeCards.Count;
        }
        else
        {
          maxCards = Math.Min(_maxFreeCardsToTry, freeCards.Count);

          if (maxCards > freeCards.Count)
          {
            maxCards = freeCards.Count;
          }
        }

        Log.Write("Controller: try max {0} of {1} cards for timeshifting", maxCards, freeCards.Count);
        TvBusinessLayer layer = new TvBusinessLayer();
        //keep tuning each card until we are succesful                
        for (int i = 0; i < maxCards; i++)
        {
          int nrOfOtherUsersTimeshiftingOnCard = 0;
          if (i > 0)
          {
            Log.Write("Controller: Timeshifting failed, lets try next available card.");
            cardChanged = (maxCards > 1);
          }
          userCopy = new User(user.Name, user.IsAdmin);

          CardDetail cardInfo = freeCards[i];
          userCopy.CardId = cardInfo.Id;
          if (forceCardId && user.CardId != cardInfo.Id)
          {
            continue;
          }
          IChannel tuneChannel = cardInfo.TuningDetail;

          //setup folders
          if (cardInfo.Card.RecordingFolder == String.Empty)
          {
            cardInfo.Card.RecordingFolder = String.Format(@"{0}\Team MediaPortal\MediaPortal TV Server\recordings",
                                                          Environment.GetFolderPath(
                                                            Environment.SpecialFolder.CommonApplicationData));
            if (!Directory.Exists(cardInfo.Card.RecordingFolder))
            {
              Log.Write("Controller: creating recording folder {0} for card {0}", cardInfo.Card.RecordingFolder,
                        cardInfo.Card.Name);
              Directory.CreateDirectory(cardInfo.Card.RecordingFolder);
            }
          }
          if (cardInfo.Card.TimeShiftFolder == String.Empty)
          {
            cardInfo.Card.TimeShiftFolder = String.Format(
              @"{0}\Team MediaPortal\MediaPortal TV Server\timeshiftbuffer",
              Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
            if (!Directory.Exists(cardInfo.Card.TimeShiftFolder))
            {
              Log.Write("Controller: creating timeshifting folder {0} for card {0}", cardInfo.Card.TimeShiftFolder,
                        cardInfo.Card.Name);
              Directory.CreateDirectory(cardInfo.Card.TimeShiftFolder);
            }
          }

          //todo : if the owner is changing channel to a new transponder, then kick any leeching users.
          ITvCardHandler tvcard = _cards[cardInfo.Id];
          bool isTS = tvcard.TimeShifter.IsAnySubChannelTimeshifting;
          bool skipCard = false;
          if (isTS)
          {
            IUser[] users = tvcard.Users.GetUsers();
            for (int j = users.Length - 1; j > -1; j--)
            {
              IUser u = users[j];
              if (user.Name.Equals(u.Name))
              {
                continue;
              }

              IChannel tmpChannel = tvcard.CurrentChannel(ref u);

              if (tmpChannel == null)
              {
                tvcard.Users.RemoveUser(u);
                //removing inactive user which shouldnt happen, but atleast its better than having timeshfiting fail.
                continue;
              }

              bool isDiffTS = tuneChannel.IsDifferentTransponder(tmpChannel);

              if (isDiffTS)
              {
                Log.Write("Controller: kicking leech user {0} off card {1} since owner {2} changed transponder", u.Name,
                          cardInfo.Card.Name, user.Name);
                StopTimeShifting(ref u, TvStoppedReason.OwnerChangedTS);
              }
              else
              {
                DVBBaseChannel dvbBaseChannel = tmpChannel as DVBBaseChannel;
                if (dvbBaseChannel != null)
                {
                  TuningDetail userChannel = layer.GetTuningDetail(dvbBaseChannel);
                  bool isOnSameChannel = (idChannel == userChannel.IdChannel);

                  if (isOnSameChannel)
                  {
                    if (tvcard.Users.IsOwner(userCopy))
                    {
                      if (i < maxCards)
                      {
                        Log.Write("Controller: skipping card:{0} since other users are present on the same channel.",
                                  userCopy.CardId);
                        skipCard = true;
                        break; //try next card  
                      }
                    }
                    else
                    {
                      nrOfOtherUsersTimeshiftingOnCard++;
                      if (!u.IsAdmin)
                      {
                        userCopy.SubChannel = u.SubChannel;
                      }
                    }
                  }
                }
              }
            }
          }

          if (skipCard)
          {
            continue;
          }

          //tune to the new channel                  
          result = CardTune(ref userCopy, tuneChannel, channel);
          if (result != TvResult.Succeeded)
          {
            user.FailedCardId = userCopy.FailedCardId;
            StopTimeShifting(ref userCopy);
            continue; //try next card            
          }
          Log.Info("control2:{0} {1} {2}", userCopy.Name, userCopy.CardId, userCopy.SubChannel);
          if (!IsTimeShifting(ref userCopy))
          {
            CleanTimeShiftFiles(cardInfo.Card.TimeShiftFolder,
                                String.Format("live{0}-{1}.ts", userCopy.CardId, userCopy.SubChannel));
          }
          string timeshiftFileName = String.Format(@"{0}\live{1}-{2}.ts", cardInfo.Card.TimeShiftFolder, userCopy.CardId,
                                                   userCopy.SubChannel);

          //start timeshifting
          result = StartTimeShifting(ref userCopy, ref timeshiftFileName);
          if (result != TvResult.Succeeded)
          {
            StopTimeShifting(ref userCopy);
            continue; //try next card
          }
          Log.Write("Controller: StartTimeShifting started on card:{0} to {1}", userCopy.CardId, timeshiftFileName);
          card = GetVirtualCard(userCopy);
          card.NrOfOtherUsersTimeshiftingOnCard = nrOfOtherUsersTimeshiftingOnCard;
          RemoveUserFromOtherCards(card.Id, userCopy); //only remove user from other cards if new tuning was a success
          UpdateChannelStatesForUsers();

          if (card != null && card.TimeShiftFileName != null)
          {
            string newTimeshiftingFilename = card.TimeShiftFileName;
            cardChanged = (intialTimeshiftingFilename != newTimeshiftingFilename);
          }

          break; //if we made it to the bottom, then we have a successful timeshifting.
        }

        if (result != TvResult.Succeeded)
        {
          if (_epgGrabber != null && AllCardsIdle)
          {
            _epgGrabber.Start();
          }
        }

        return result;
      }
      catch (Exception ex)
      {
        if (userCopy != null)
        {
          user.FailedCardId = userCopy.FailedCardId;
        }
        if (_epgGrabber != null && AllCardsIdle)
        {
          _epgGrabber.Start();
        }
        Log.Write(ex);
        return TvResult.UnknownError;
      }
    }
 public List<WebTvServerStatus> GetTvServerStatus()
 {
     List<WebTvServerStatus> states = new List<WebTvServerStatus>();
       if (!ConnectToDatabase())
     return states;
       VirtualCard vcard;
       try
       {
     IList<Card> cards = Card.ListAll();
     foreach (Card card in cards)
     {
       User user = new User();
       User[] usersForCard = null;
       user.CardId = card.IdCard;
       try
       {
     usersForCard = RemoteControl.Instance.GetUsersForCard(card.IdCard);
       }
       catch (Exception)
       {
       }
       if (usersForCard == null)
       {
     WebTvServerStatus state = new WebTvServerStatus();
     state.recordingFolder = card.RecordingFolder;
     state.timeshiftFolder = card.TimeShiftFolder;
     vcard = new VirtualCard(user, RemoteControl.HostName);
     string tmp = "idle";
     state.status = (int)CardStatus.Idle;
     if (vcard.IsScanning)
     {
       tmp = "Scanning";
       state.status = (int)CardStatus.Scanning;
     }
     if (vcard.IsGrabbingEpg)
     {
       tmp = "Grabbing EPG";
       state.status = (int)CardStatus.Grabbing_EPG;
     }
     state.idCard = card.IdCard;
     state.cardName = vcard.Name;
     state.cardType = (int)vcard.Type;
     state.cardTypeStr = vcard.Type.ToString();
     state.statusStr = tmp;
     state.channel = "";
     state.userName = "";
     states.Add(state);
     continue;
       }
       if (usersForCard.Length == 0)
       {
     WebTvServerStatus state = new WebTvServerStatus();
     state.recordingFolder = card.RecordingFolder;
     state.timeshiftFolder = card.TimeShiftFolder;
     vcard = new VirtualCard(user, RemoteControl.HostName);
     string tmp = "idle";
     state.status = (int)CardStatus.Idle;
     if (vcard.IsScanning)
     {
       tmp = "Scanning";
       state.status = (int)CardStatus.Scanning;
     }
     if (vcard.IsGrabbingEpg)
     {
       tmp = "Grabbing EPG";
       state.status = (int)CardStatus.Grabbing_EPG;
     }
     state.idCard = card.IdCard;
     state.cardName = vcard.Name;
     state.cardType = (int)vcard.Type;
     state.cardTypeStr = vcard.Type.ToString();
     state.statusStr = tmp;
     state.channel = "";
     state.userName = "";
     states.Add(state);
     continue;
       }
       for (int i = 0; i < usersForCard.Length; ++i)
       {
     WebTvServerStatus state = new WebTvServerStatus();
     state.recordingFolder = card.RecordingFolder;
     state.timeshiftFolder = card.TimeShiftFolder;
     string tmp = "idle";
     state.status = (int)CardStatus.Idle;
     vcard = new VirtualCard(usersForCard[i], RemoteControl.HostName);
     if (vcard.IsTimeShifting)
     {
       tmp = "Timeshifting";
       state.status = (int)CardStatus.TimeShifting;
     }
     else
       if (vcard.IsRecording)
       {
         tmp = "Recording";
         state.status = (int)CardStatus.Recording;
       }
       else
         if (vcard.IsScanning)
         {
           tmp = "Scanning";
           state.status = (int)CardStatus.Scanning;
         }
         else
           if (vcard.IsGrabbingEpg)
           {
             tmp = "Grabbing EPG";
             state.status = (int)CardStatus.Grabbing_EPG;
           }
     state.idCard = card.IdCard;
     state.cardName = vcard.Name;
     state.cardType = (int)vcard.Type;
     state.cardTypeStr = vcard.Type.ToString();
     state.statusStr = tmp;
     state.idChannel = vcard.IdChannel;
     state.channel = vcard.ChannelName;
     state.userName = vcard.User.Name;
     states.Add(state);
       }
     }
       }
       catch (Exception ex)
       {
       }
       return states;
 }
 /// <summary>
 /// Start timeshifting on a specific channel
 /// </summary>
 /// <param name="user">user credentials.</param>
 /// <param name="idChannel">The id channel.</param>
 /// <param name="card">returns card for which timeshifting is started</param>
 /// <param name="cardChanged">indicates if card was changed</param>
 /// <returns>
 /// TvResult indicating whether method succeeded
 /// </returns>
 public TvResult StartTimeShifting(ref IUser user, int idChannel, out VirtualCard card, out bool cardChanged)
 {
   return StartTimeShifting(ref user, idChannel, out card, false, out cardChanged);
 }
    private void UpdateCardStatus()
    {
      if (ServiceHelper.IsStopped) return;
      if (_cards == null) return;
      if (_cards.Count == 0) return;
      try
      {
        ListViewItem item;
        int off = 0;
        foreach (Card card in _cards)
        {
          IUser user = new User();
          user.CardId = card.IdCard;
          if (off >= mpListView1.Items.Count)
          {
            item = mpListView1.Items.Add("");
            item.SubItems.Add("");
            item.SubItems.Add("");
            item.SubItems.Add("");
            item.SubItems.Add("");
            item.SubItems.Add("");
            item.SubItems.Add("");
            item.SubItems.Add("");
          }
          else
          {
            item = mpListView1.Items[off];
          }
          bool cardPresent = RemoteControl.Instance.CardPresent(card.IdCard);
          if (!cardPresent)
          {
            item.SubItems[0].Text = card.IdCard.ToString();
            item.SubItems[1].Text = "n/a";
            item.SubItems[2].Text = "n/a";
            item.SubItems[3].Text = "";
            item.SubItems[4].Text = "";
            item.SubItems[5].Text = "";
            item.SubItems[6].Text = card.Name;
            item.SubItems[7].Text = "0";
            off++;
            continue;
          }

          ColorLine(card, item);
          VirtualCard vcard = new VirtualCard(user);
          item.SubItems[0].Text = card.IdCard.ToString();
          item.SubItems[0].Tag = card.IdCard;
          item.SubItems[1].Text = vcard.Type.ToString();

          if (card.Enabled == false)
          {
            item.SubItems[0].Text = card.IdCard.ToString();
            item.SubItems[1].Text = vcard.Type.ToString();
            item.SubItems[2].Text = "disabled";
            item.SubItems[3].Text = "";
            item.SubItems[4].Text = "";
            item.SubItems[5].Text = "";
            item.SubItems[6].Text = card.Name;
            item.SubItems[7].Text = "0";
            off++;
            continue;
          }

          IUser[] usersForCard = RemoteControl.Instance.GetUsersForCard(card.IdCard);
          if (usersForCard == null || usersForCard.Length == 0)
          {
            string tmp = "idle";
            if (vcard.IsScanning) tmp = "Scanning";
            if (vcard.IsGrabbingEpg) tmp = "Grabbing EPG";
            item.SubItems[2].Text = tmp;
            item.SubItems[3].Text = "";
            item.SubItems[4].Text = "";
            item.SubItems[5].Text = "";
            item.SubItems[6].Text = card.Name;
            item.SubItems[7].Text = Convert.ToString(RemoteControl.Instance.GetSubChannels(card.IdCard));
            off++;
            continue;
          }

          bool userFound = false;
          for (int i = 0; i < usersForCard.Length; ++i)
          {
            string tmp = "idle";
            // Check if the card id fits. Hybrid cards share the context and therefor have
            // the same users.
            if (usersForCard[i].CardId != card.IdCard)
            {
              continue;
            }
            userFound = true;
            vcard = new VirtualCard(usersForCard[i]);
            item.SubItems[0].Text = card.IdCard.ToString();
            item.SubItems[0].Tag = card.IdCard;
            item.SubItems[1].Text = vcard.Type.ToString();
            if (vcard.IsTimeShifting) tmp = "Timeshifting";
            if (vcard.IsRecording && vcard.User.IsAdmin) tmp = "Recording";
            if (vcard.IsScanning) tmp = "Scanning";
            if (vcard.IsGrabbingEpg) tmp = "Grabbing EPG";
            if (vcard.IsTimeShifting && vcard.IsGrabbingEpg) tmp = "Timeshifting (Grabbing EPG)";
            if (vcard.IsRecording && vcard.User.IsAdmin && vcard.IsGrabbingEpg) tmp = "Recording (Grabbing EPG)";
            item.SubItems[2].Text = tmp;
            tmp = vcard.IsScrambled ? "yes" : "no";
            item.SubItems[4].Text = tmp;
            string channelDisplayName;
            if (_channelNames.TryGetValue(vcard.IdChannel, out channelDisplayName))
            {
              item.SubItems[3].Text = channelDisplayName;
            }
            else
            {
              item.SubItems[3].Text = vcard.ChannelName;
            }
            item.SubItems[5].Text = usersForCard[i].Name;
            item.SubItems[6].Text = card.Name;
            item.SubItems[7].Text = Convert.ToString(RemoteControl.Instance.GetSubChannels(card.IdCard));
            off++;

            if (off >= mpListView1.Items.Count)
            {
              item = mpListView1.Items.Add("");
              item.SubItems.Add("");
              item.SubItems.Add("");
              item.SubItems.Add("");
              item.SubItems.Add("");
              item.SubItems.Add("");
              item.SubItems.Add("");
              item.SubItems.Add("");
            }
            else
            {
              item = mpListView1.Items[off];
            }
          }
          // If we haven't found a user that fits, than it is a hybrid card which is inactive
          // This means that the card is idle.
          if (!userFound)
          {
            item.SubItems[2].Text = "idle";
            item.SubItems[3].Text = "";
            item.SubItems[4].Text = "";
            item.SubItems[5].Text = "";
            item.SubItems[6].Text = card.Name;
            item.SubItems[7].Text = Convert.ToString(RemoteControl.Instance.GetSubChannels(card.IdCard));

            off++;
          }
        }
        for (int i = off; i < mpListView1.Items.Count; ++i)
        {
          item = mpListView1.Items[i];
          item.SubItems[0].Text = "";
          item.SubItems[1].Text = "";
          item.SubItems[2].Text = "";
          item.SubItems[3].Text = "";
          item.SubItems[4].Text = "";
          item.SubItems[5].Text = "";
          item.SubItems[6].Text = "";
          item.SubItems[7].Text = "";
        }
      }
      catch (Exception ex)
      {
        Log.Write(ex);
      }
    }
    /// <summary>
    /// Checks if the schedule specified is currently being recorded and ifso
    /// returns on which card
    /// </summary>
    /// <param name="idSchedule">id of the Schedule</param>
    /// <param name="card">returns the card which is recording the channel</param>
    /// <returns>true if a card is recording the schedule, otherwise false</returns>
    public bool IsRecordingSchedule(int idSchedule, out VirtualCard card)
    {
      card = null;
      try
      {
        Log.Info("IsRecordingSchedule:{0} {1}", idSchedule, _isMaster);
        if (_isMaster == false)
          return false;
        if (!_scheduler.IsRecordingSchedule(idSchedule, out card))
        {
          Log.Info("IsRecordingSchedule: scheduler is not recording schedule");
          return false;
        }
        Log.Info("IsRecordingSchedule: scheduler is recording schedule on cardid:{0}", card.Id);

        return true;
      }
      catch (Exception ex)
      {
        Log.Write(ex);
        return false;
      }
    }
Exemple #31
0
    private void OnActiveStreams()
    {
      GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU);
      if (dlg == null)
      {
        return;
      }
      dlg.Reset();
      dlg.SetHeading(692); // Active Tv Streams
      int selected = 0;

      IList<Card> cards = TvDatabase.Card.ListAll();
      List<Channel> channels = new List<Channel>();
      int count = 0;
      TvServer server = new TvServer();
      List<IUser> _users = new List<IUser>();
      foreach (Card card in cards)
      {
        if (card.Enabled == false)
        {
          continue;
        }
        if (!RemoteControl.Instance.CardPresent(card.IdCard))
        {
          continue;
        }
        IUser[] users = RemoteControl.Instance.GetUsersForCard(card.IdCard);
        if (users == null)
        {
          return;
        }
        for (int i = 0; i < users.Length; ++i)
        {
          IUser user = users[i];
          if (card.IdCard != user.CardId)
          {
            continue;
          }
          bool isRecording;
          bool isTimeShifting;
          VirtualCard tvcard = new VirtualCard(user, RemoteControl.HostName);
          isRecording = tvcard.IsRecording;
          isTimeShifting = tvcard.IsTimeShifting;
          if (isTimeShifting || (isRecording && !isTimeShifting))
          {
            int idChannel = tvcard.IdChannel;
            user = tvcard.User;
            Channel ch = Channel.Retrieve(idChannel);
            channels.Add(ch);
            GUIListItem item = new GUIListItem();
            item.Label = ch.DisplayName;
            item.Label2 = user.Name;
            string strLogo = Utils.GetCoverArt(Thumbs.TVChannel, ch.DisplayName);
            if (string.IsNullOrEmpty(strLogo))
            {
              strLogo = "defaultVideoBig.png";
            }
            item.IconImage = strLogo;
            if (isRecording)
            {
              item.PinImage = Thumbs.TvRecordingIcon;
            }
            else
            {
              item.PinImage = "";
            }
            dlg.Add(item);
            _users.Add(user);
            if (Card != null && Card.IdChannel == idChannel)
            {
              selected = count;
            }
            count++;
          }
        }
      }
      if (channels.Count == 0)
      {
        GUIDialogOK pDlgOK = (GUIDialogOK)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_OK);
        if (pDlgOK != null)
        {
          pDlgOK.SetHeading(692); //my tv
          pDlgOK.SetLine(1, GUILocalizeStrings.Get(1511)); // No Active streams
          pDlgOK.SetLine(2, "");
          pDlgOK.DoModal(this.GetID);
        }
        return;
      }
      dlg.SelectedLabel = selected;
      dlg.DoModal(this.GetID);
      if (dlg.SelectedLabel < 0)
      {
        return;
      }

      VirtualCard vCard = new VirtualCard(_users[dlg.SelectedLabel], RemoteControl.HostName);
      Channel channel = Navigator.GetChannel(vCard.IdChannel);
      ViewChannel(channel);
    }
    /// <summary>
    /// returns a virtual card for the card specified.
    /// </summary>
    /// <param name="user">User</param>
    /// <returns></returns>
    private VirtualCard GetVirtualCard(IUser user)
    {
      if (ValidateTvControllerParams(user))
      {
        return null;
      }

      VirtualCard card = new VirtualCard(user);
      card.RecordingFormat = _cards[user.CardId].DataBaseCard.RecordingFormat;
      card.RecordingFolder = _cards[user.CardId].DataBaseCard.RecordingFolder;
      card.TimeshiftFolder = _cards[user.CardId].DataBaseCard.TimeShiftFolder;
      card.RemoteServer = Dns.GetHostName();
      return card;
    }
Exemple #33
0
    /// <summary>
    /// Tunes to a new channel
    /// </summary>
    /// <param name="channel"></param>
    /// <returns></returns>
    public static bool ViewChannelAndCheck(Channel channel)
    {
      bool checkResult;
      bool doContinue;

      if (!Connected)
      {
        return false;
      }

      _status.Clear();

      _doingChannelChange = false;

      try
      {
        checkResult = PreTuneChecks(channel, out doContinue);
        if (doContinue == false)
          return checkResult;

        _doingChannelChange = true;
        TvResult succeeded;


        IUser user = new User();
        if (Card != null)
        {
          user.CardId = Card.Id;
        }

        if ((g_Player.Playing && g_Player.IsTimeShifting && !g_Player.Stopped) && (g_Player.IsTV || g_Player.IsRadio))
        {
          _status.Set(LiveTvStatus.WasPlaying);
        }

        //Start timeshifting the new tv channel
        TvServer server = new TvServer();
        VirtualCard card;
        int newCardId = -1;

        // check which card will be used
        newCardId = server.TimeShiftingWouldUseCard(ref user, channel.IdChannel);

        //Added by joboehl - If any major related to the timeshifting changed during the start, restart the player.           
        if (newCardId != -1 && Card.Id != newCardId)
        {
          _status.Set(LiveTvStatus.CardChange);
          RegisterCiMenu(newCardId);
        }

        // we need to stop player HERE if card has changed.        
        if (_status.AllSet(LiveTvStatus.WasPlaying | LiveTvStatus.CardChange))
        {
          Log.Debug("TVHome.ViewChannelAndCheck(): Stopping player. CardId:{0}/{1}, RTSP:{2}", Card.Id, newCardId,
                    Card.RTSPUrl);
          Log.Debug("TVHome.ViewChannelAndCheck(): Stopping player. Timeshifting:{0}", Card.TimeShiftFileName);
          Log.Debug("TVHome.ViewChannelAndCheck(): rebuilding graph (card changed) - timeshifting continueing.");
        }
        if (_status.IsSet(LiveTvStatus.WasPlaying))
        {
          RenderBlackImage();
          g_Player.PauseGraph();
        }
        else
        {
          // if CI menu is not attached due to card change, do it if graph was not playing 
          // (some handlers use polling threads that get stopped on graph stop)
          if (_status.IsNotSet(LiveTvStatus.CardChange))
            RegisterCiMenu(newCardId);
        }

        // if card was not changed
        if (_status.IsNotSet(LiveTvStatus.CardChange))
        {
          g_Player.OnZapping(0x80); // Setup Zapping for TsReader, requesting new PAT from stream
        }
        bool cardChanged = false;
        succeeded = server.StartTimeShifting(ref user, channel.IdChannel, out card, out cardChanged);

        if (_status.IsSet(LiveTvStatus.WasPlaying))
        {
          if (card != null)
            g_Player.OnZapping((int)card.Type);
          else
            g_Player.OnZapping(-1);
        }


        if (succeeded != TvResult.Succeeded)
        {
          //timeshifting new channel failed. 
          g_Player.Stop();

          // ensure right channel name, even if not watchable:Navigator.Channel = channel; 
          ChannelTuneFailedNotifyUser(succeeded, _status.IsSet(LiveTvStatus.WasPlaying), channel);

          _doingChannelChange = true; // keep fullscreen false;
          return true; // "success"
        }

        if (card != null && card.NrOfOtherUsersTimeshiftingOnCard > 0)
        {
          _status.Set(LiveTvStatus.SeekToEndAfterPlayback);
        }

        if (cardChanged)
        {
          _status.Set(LiveTvStatus.CardChange);
          if (card != null)
          {
            RegisterCiMenu(card.Id);
          }
          _status.Reset(LiveTvStatus.WasPlaying);
        }
        else
        {
          _status.Reset(LiveTvStatus.CardChange);
          _status.Set(LiveTvStatus.SeekToEnd);
        }

        // Update channel navigator
        if (Navigator.Channel != null &&
            (channel.IdChannel != Navigator.Channel.IdChannel || (Navigator.LastViewedChannel == null)))
        {
          Navigator.LastViewedChannel = Navigator.Channel;
        }
        Log.Info("succeeded:{0} {1}", succeeded, card);
        Card = card; //Moved by joboehl - Only touch the card if starttimeshifting succeeded. 

        // if needed seek to end
        if (_status.IsSet(LiveTvStatus.SeekToEnd))
        {
          SeekToEnd(true);
        }

        // continue graph
        g_Player.ContinueGraph();
        if (!g_Player.Playing || _status.IsSet(LiveTvStatus.CardChange) || (g_Player.Playing && !(g_Player.IsTV || g_Player.IsRadio)))
        {
          StartPlay();

          // if needed seek to end
          if (_status.IsSet(LiveTvStatus.SeekToEndAfterPlayback))
          {
            double dTime = g_Player.Duration - 5;
            g_Player.SeekAbsolute(dTime);
          }
        }

        _playbackStopped = false;
        _doingChannelChange = false;
        _ServerNotConnectedHandled = false;
        return true;
      }
      catch (Exception ex)
      {
        Log.Debug("TvPlugin:ViewChannelandCheckV2 Exception {0}", ex.ToString());
        _doingChannelChange = false;
        Card.User.Name = new User().Name;
        g_Player.Stop();
        Card.StopTimeShifting();
        return false;
      }
      finally
      {
        StopRenderBlackImage();        
        _userChannelChanged = false;
        FireOnChannelChangedEvent();
        Navigator.UpdateCurrentChannel();
      }
    }
Exemple #34
0
        /// <summary>
        /// Stops and deletes an active recording.
        /// </summary>
        /// <param name="card"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static bool StopRecording(Card card)
        {
            SetupConnection();

            VirtualCard vcard;
            IUser[] usersForCard = RemoteControl.Instance.GetUsersForCard(card.IdCard);

            foreach (IUser user in usersForCard)
            {
                vcard = new VirtualCard(user, RemoteControl.HostName);
                try
                {
                    if (vcard.IsRecording)
                    {
                        Recording recording = Recording.Retrieve(vcard.RecordingFileName);
                        vcard.StopRecording();
                        recording.Delete();
                        return true;
                    }
                }
                catch (Exception ex)
                {
                    return false;
                }
            }

            return false;
        }