public void GrabData(object ParamTo)
        {
            DataGrabArgs ParamToUse = (DataGrabArgs)ParamTo;
            int          ChannelID  = ParamToUse.ChannelID;
            int          Seconds    = ParamToUse.Seconds;
            List <int>   Pids       = ParamToUse.Pids;
            string       Filename   = "Custom_" + ChannelID.ToString() + ".ts";

            Complete = false;
            TvServer server = new TvServer();
            IUser    user   = new User(Filename, false);

            WantedPIDS = Pids;
            TvResult result = default(TvResult);

            //Used to start and ensure we can tune the channel
            result = server.StartTimeShifting(ref user, ChannelID, out _card);

            if ((result == TvResult.Succeeded))
            {
                Thread.Sleep(2000);
                _card.StopTimeShifting();

                result = server.StartTimeShiftingWithCustom(ref user, ChannelID, out _card, Filename, Pids);

                if ((result == TvResult.Succeeded))
                {
                    string NewFile = _card.TimeshiftFolder + "\\" + Filename;
                    TimeStamp = DateTime.Now.AddSeconds(Seconds);
                    ProcessPackets(NewFile);
                    Decoders.Remove(ChannelID);
                }
                else
                {
                    Decoders.Remove(ChannelID);
                    if (OnComplete != null)
                    {
                        OnComplete(true, result.ToString());
                    }
                }
            }
            else
            {
                Decoders.Remove(ChannelID);
                if (OnComplete != null)
                {
                    OnComplete(true, result.ToString());
                }
            }
        }
示例#2
0
        private void gridRadioChannels_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            serverIntf.StopTimeShifting();
            extPlayer.Stop();
            string rtspURL = "";

            if (gridRadioChannels.SelectedRows[0].Cells[2].Value.ToString() == "DVB")
            {
                StBarLabel.Text = "Trying to start timeshifting...";
                StBar.Update();
                TvResult result = serverIntf.StartTimeShifting(int.Parse(gridRadioChannels.SelectedRows[0].Cells[0].Value.ToString()), ref rtspURL);
                StBarLabel.Text = "";
                StBar.Update();
                if (result != TvResult.Succeeded)
                {
                    MessageBox.Show("Could not start timeshifting\nReason: " + result.ToString());
                }
            }
            else
            {
                rtspURL = serverIntf.GetWebStreamURL(int.Parse(gridRadioChannels.SelectedRows[0].Cells[0].Value.ToString()));
            }
            if (ClientSettings.useOverride)
            {
                rtspURL = ClientSettings.overrideURL;
            }
            string args = string.Format(ClientSettings.playerArgs, rtspURL);

            if (!extPlayer.Start(ClientSettings.playerPath, args))
            {
                MessageBox.Show("Failed to start external player.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#3
0
        private bool TuneEPGgrabber(Channel channel, IChannel tuning, Card card, TvResult result)
        {
            try
            {
                _user.CardId = Card.IdCard;
                ITvCardHandler cardHandler;
                if (_tvController.CardCollection.TryGetValue(Card.IdCard, out cardHandler))
                {
                    ICardTuneReservationTicket ticket = null;
                    try
                    {
                        ICardReservation cardReservationImpl = new CardReservationTimeshifting(_tvController);
                        ticket = cardReservationImpl.RequestCardTuneReservation(cardHandler, tuning, _user, channel.IdChannel);

                        if (ticket != null)
                        {
                            result = _tvController.Tune(ref _user, tuning, channel.IdChannel, ticket);
                            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);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        CardReservationHelper.CancelCardReservation(cardHandler, ticket);
                        throw;
                    }
                }
                _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;
            }
        }
        public void ShowVideo(IWin32Window owner)
        {
            Text = "Preview " + _channel.DisplayName;

            TvServer server = new TvServer();
            IUser    user   = UserFactory.CreateBasicUser("setuptv");
            TvResult result = server.StartTimeShifting(ref user, _channel.IdChannel, out _card);

            if (result != TvResult.Succeeded)
            {
                MessageBox.Show("Preview failed:" + result);
                Close();
                throw new Exception(result.ToString());
            }

            Log.Info("preview {0} user:{1} {2} {3} {4}", _channel.DisplayName, user.CardId, user.SubChannel, user.Name,
                     _card.TimeShiftFileName);
            _player = new Player();
            _player.Play(_card.TimeShiftFileName, this);

            this.Show(owner);
        }
        /**
         * \brief  timeshift a channel and get the stream url
         * \param  OriginalURL is the URL given to us by the TVServer
         * \return value is the URL with resolved hostnames,
         */
        public static String playChannel(int chanId, bool resolveHostnames, ref string OriginalURL, ref TvControl.IUser me, ref string timeShiftFileName, ref Int64 timeShiftBufPos, ref long timeShiftBufNr)
        {
            string rtspURL      = "";
            string remoteserver = "";

            //serverIntf.StopTimeShifting(ref me);
            timeshiftChannel.Remove(me.Name);

            TvResult result = serverIntf.StartTimeShifting(chanId, ref rtspURL, ref remoteserver, ref me, ref timeShiftFileName, ref timeShiftBufPos, ref timeShiftBufNr);

            if (result != TvResult.Succeeded)
            {
                rtspURL = "[ERROR]: TVServer answer: " + result.ToString() + "|" + (int)result;
            }
            else
            {
                // we resolve any host names, as xbox can't do NETBIOS resolution..
                try
                {
                    //Workaround for MP TVserver bug when using default port for rtsp => returns rtsp://ip:0
                    rtspURL = rtspURL.Replace(":554", "");
                    rtspURL = rtspURL.Replace(":0", "");

                    OriginalURL = rtspURL;

                    if (resolveHostnames)
                    {
                        Uri       u      = new Uri(rtspURL);
                        IPAddress ipaddr = null;
                        try
                        {
                            ipaddr = IPAddress.Parse(u.DnsSafeHost); //Fails on a hostname
                        }
                        catch { }

                        if ((ipaddr == null) || (ipaddr.IsIPv6LinkLocal || ipaddr.IsIPv6Multicast || ipaddr.IsIPv6SiteLocal))
                        {
                            try
                            {
                                IPHostEntry hostEntry = System.Net.Dns.GetHostEntry(u.DnsSafeHost);

                                string newHost = "";
                                foreach (IPAddress ipaddr2 in hostEntry.AddressList)
                                {
                                    // we only want ipv4.. this is just the xbox after all
                                    if (ipaddr2.AddressFamily != System.Net.Sockets.AddressFamily.InterNetworkV6)
                                    {
                                        newHost = ipaddr2.ToString();
                                        break;
                                    }
                                }

                                rtspURL = u.AbsoluteUri.Replace(u.Scheme + "://" + u.Host + "/", u.Scheme + "://" + newHost + "/");

                                if (newHost.Length == 0)
                                {
                                    Log.Debug("TVServerKodi: No IPv4 adress found for '" + u.DnsSafeHost + "' failed. Returning original URL.");
                                    Console.WriteLine("No IPv4 adress found for '" + u.DnsSafeHost + "' failed. Returning original URL.");
                                }
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("IP resolve for '" + u.DnsSafeHost + "' failed.");
                                Console.WriteLine("Error: " + ex.ToString());
                                Log.Debug("TVServerKodi: IP resolve for '" + u.DnsSafeHost + "' failed.");
                                Log.Debug("TVServerKodi: Error: " + ex.ToString());
                            }
                        }
                    }
                }
                catch
                {
                    //Console.WriteLine("IP resolve failed");
                }

                // update globals
                timeshiftUrl = rtspURL;
                timeshiftChannel.Add(me.Name, chanId);
            }

            Log.Debug("TVServerKodi: PlayChannel " + chanId.ToString() + " => URL=" + rtspURL);
            //Console.WriteLine("PlayChannel result : " + rtspURL);
            return(rtspURL);
        }
    private bool TuneEPGgrabber(Channel channel, IChannel tuning, Card card, TvResult result)
    {
      try
      {
        _user.CardId = card.IdCard;
        ITvCardHandler cardHandler;
        if (_tvController.CardCollection.TryGetValue(card.IdCard, out cardHandler))
        {
          ICardTuneReservationTicket ticket = null;
          try
          {
            ICardReservation cardReservationImpl = new CardReservationTimeshifting(_tvController);
            ticket = cardReservationImpl.RequestCardTuneReservation(cardHandler, tuning, _user);

            if (ticket != null)
            {
              result = _tvController.Tune(ref _user, tuning, channel.IdChannel, ticket);
              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;
              }
            } 
          }
          catch (Exception)
          {
            CardReservationHelper.CancelCardReservation(cardHandler, ticket);
            throw;
          }
                       
        }            
        _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;
      }
    }