Exemplo n.º 1
0
        public static bool StopTimeshift(ref TvControl.IUser me)
        {
            bool result = serverIntf.StopTimeShifting(ref me);

            timeshiftUrl = null;
            return(result);
        }
Exemplo n.º 2
0
        protected override string SwitchTVServerToChannel(string userName, int channelId)
        {
            if (String.IsNullOrEmpty(userName))
            {
                ServiceRegistration.Get <ILogger>().Error("Called SwitchTVServerToChannel with empty userName");
                throw new ArgumentNullException("userName");
            }

            IUser currentUser = UserFactory.CreateBasicUser(userName, -1);

            ServiceRegistration.Get <ILogger>().Debug("Starting timeshifiting with username {0} on channel id {1}", userName, channelId);

            // actually start timeshifting
            VirtualCard card;
            TvResult    result = _tvControl.StartTimeShifting(ref currentUser, channelId, out card);

            // make sure result is correct and return
            if (result != TvResult.Succeeded)
            {
                ServiceRegistration.Get <ILogger>().Error("Starting timeshifting failed with result {0}", result);
                return(null);
            }
            if (card == null)
            {
                ServiceRegistration.Get <ILogger>().Error("Couldn't get virtual card");
                return(null);
            }
            return(userName.StartsWith(LOCAL_USERNAME + "-") ? card.TimeShiftFileName : card.RTSPUrl);
        }
Exemplo n.º 3
0
        public static ChannelInfo getTimeshiftInfo(ref TvControl.IUser me)
        {
            int channelnr = 0;

            if (timeshiftChannel.TryGetValue(me.Name, out channelnr))
            {
                return(serverIntf.GetChannelInfo(channelnr));
            }
            else if (me.IdChannel > 0)
            {
                return(serverIntf.GetChannelInfo(me.IdChannel));
            }

            return(null);
        }
Exemplo n.º 4
0
 public static TimeShiftURLs getTimeshiftURLs(ref TvControl.IUser me)
 {
     return(serverIntf.GetTimeshiftURLs(ref me));
 }
Exemplo n.º 5
0
        /**
         * \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);
        }