示例#1
0
        private 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);

            IInternalControllerService control = GlobalServiceProvider.Get <IInternalControllerService>();

            IVirtualCard card;
            IUser        user;
            TvResult     result = control.StartTimeShifting(currentUser.Name, channelId, out card, out user);

            ServiceRegistration.Get <ILogger>().Debug("Tried to start timeshifting, result {0}", result);

            if (result != TvResult.Succeeded)
            {
                // TODO: should we retry?
                ServiceRegistration.Get <ILogger>().Error("Starting timeshifting failed with result {0}", result);
                throw new Exception("Failed to start tv stream: " + result);
            }
            return(userName.StartsWith(LOCAL_USERNAME + "-") ? card.TimeShiftFileName : card.RTSPUrl);
        }
示例#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);
        }
        private void btnCustom_Click(object sender, EventArgs e)
        {
            TvResult    result;
            long        mSecsElapsed;
            VirtualCard card;

            Channel tv3_plus = Channel.Retrieve(9);
            Channel tv3      = Channel.Retrieve(125);

            Channel nosignal = Channel.Retrieve(5651);

            IUser low  = UserFactory.CreateBasicUser("low", 1);
            IUser low2 = UserFactory.CreateBasicUser("low2", 1);
            IUser high = UserFactory.CreateBasicUser("high", 5);

            //StartTimeshifting(tv3, low, 0, out mSecsElapsed, out result, out card);


            //ThreadPool.QueueUserWorkItem(delegate { StartTimeshifting(nosignal, low, 0, out mSecsElapsed, out result, out card); });

            //Thread.Sleep(1000);

            //ThreadPool.QueueUserWorkItem(delegate { StartTimeshifting(nosignal, low, 0, out mSecsElapsed, out result, out card); });


            //StartTimeshifting(tv3_plus, low2, 0, out mSecsElapsed, out result, out card);

            StartTimeshifting(tv3, high, 0, out mSecsElapsed, out result, out card);

            //Thread.Sleep(3000);

            //StartTimeshifting(tv3_plus, high, 0, out mSecsElapsed, out result, out card);
        }
        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);
        }
        private void ChannelTestThread(List <Channel> channelsO)
        {
            var rnd = new Random();

            while (_running)
            {
                try
                {
                    List <List <Channel> > channelChunks = null;

                    if (_usersShareChannels)
                    {
                        channelChunks = new List <List <Channel> >();

                        for (int i = 0; i < _concurrentTunes; i++)
                        {
                            channelChunks.Add(channelsO);
                        }
                    }
                    else
                    {
                        channelChunks = SplitIntoChunks(channelsO, (int)Decimal.Floor(channelsO.Count / _concurrentTunes));
                    }

                    for (int i = 0; i < _concurrentTunes; i++)
                    {
                        if (channelChunks.Count >= i + 1)
                        {
                            IEnumerable <Channel> channelsForUser = channelChunks[i];
                            channelsForUser = channelsForUser.Randomize();

                            int    priority = GetUserPriority();
                            string name     = "stress-" + Convert.ToString(rnd.Next(1, 500)) + " [" + priority + "]";
                            IUser  user     = UserFactory.CreateBasicUser(name, priority);

                            while (_users.ContainsKey(user.Name))
                            {
                                user.Name = "stress-" + Convert.ToString(rnd.Next(1, 500)) + " [" + priority + "]";
                            }

                            _users.Add(user.Name, true);
                            ThreadPool.QueueUserWorkItem(delegate { TuneChannelsForUser(user, channelsForUser); });
                            Thread.Sleep(500);
                        }
                    }

                    while (true)
                    {
                        int nrOfBusy = 0;

                        foreach (KeyValuePair <string, bool> kvp in _users)
                        {
                            bool isCurrentBusy = kvp.Value;
                            if (isCurrentBusy)
                            {
                                nrOfBusy++;
                            }
                        }

                        if (nrOfBusy == 0)
                        {
                            _users.Clear();
                            break;
                        }
                        Thread.Sleep(100);
                        Application.DoEvents();
                    }
                }
                finally
                {
                    if (!_repeat)
                    {
                        _running = false;
                    }
                }
            }
        }