コード例 #1
0
        public void BandwidthTests(ChannelSources src, BandwidthValues val)
        {
            ParametersField parameters = new ParametersField(src);
            string          text       = "B" + (short)val;

            parameters.EvaluateParameters(text);
            Assert.AreEqual(val, parameters.Bandwidth);
            Assert.AreEqual(text, parameters.ToString());
        }
コード例 #2
0
ファイル: Player.cs プロジェクト: krethh/AISDE_2
        public void Simulate(double time)
        {
            CurrentTime = 0;
            Server server = new Server();

            Events.Enqueue(new BandwidthEvent {
                Time = RandomNumberFromExpDistribution(5), BandwidthChange = BandwidthEvent.NextBandwidthChange()
            });
            Events.Enqueue(new DownloadingFinishedEvent {
                Time = CHUNK_LENGTH * server.VideoSize / Bandwidth
            });
            Events.Enqueue(new MeasurementEvent {
                Time = 0
            });

            int CyclesWithTooMuch = 0, CyclesWithTooLittle = 0;

            while (CurrentTime < time)
            {
                Event nextEvent  = Events.Dequeue();
                var   bufferGone = nextEvent.Time - CurrentTime;

                if (nextEvent as BandwidthEvent != null)
                {
                    BandwidthEvent bandwidthEvent = (BandwidthEvent)nextEvent;
                    BufferSize -= bufferGone;
                    BufferSize  = BufferSize < 0 ? 0 : BufferSize;

                    CurrentTime = bandwidthEvent.Time;
                    Bandwidth  += bandwidthEvent.BandwidthChange;

                    OnLogCreated(new LogEventArgs
                    {
                        Message = "Bandwidth change, time = " + Truncate(CurrentTime.ToString()) + ", buffer = " + Truncate(BufferSize.ToString()) +
                                  ", bandwidth = " + Bandwidth + ", size = " + server.VideoSize
                    });

                    Events.Enqueue(new BandwidthEvent
                    {
                        Time            = CurrentTime + RandomNumberFromExpDistribution(10),
                        BandwidthChange = BandwidthEvent.NextBandwidthChange()
                    });
                }

                else if (nextEvent as DownloadingFinishedEvent != null)
                {
                    DownloadingFinishedEvent downloadingEvent = (DownloadingFinishedEvent)nextEvent;
                    BufferSize -= bufferGone;

                    if (BufferSize < 10)
                    {
                        CyclesWithTooLittle++;
                    }
                    else
                    {
                        CyclesWithTooLittle = 0;
                    }

                    if (CyclesWithTooLittle > 2)
                    {
                        server.SetSmallerVideoSize();
                        CyclesWithTooLittle = 0;
                    }
                    BufferSize = BufferSize < 0 ? 0 : BufferSize;

                    CurrentTime = downloadingEvent.Time;
                    BufferSize += CHUNK_LENGTH;

                    OnLogCreated(new LogEventArgs
                    {
                        Message = "Downloaded, time = " + Truncate(CurrentTime.ToString()) + ", buffer = " + Truncate(BufferSize.ToString()) +
                                  ", bandwidth = " + Bandwidth + ", size = " + server.VideoSize
                    });

                    /// jeżeli nadwyżka bufora jest duża, to zliczaj, jak długo jest taki stan. Jeżeli więcej niż dwa chunki, to zwiększ jakość obrazu
                    var surplus = (BufferSize - 30 > 0) ? BufferSize - 30 : 0;
                    if (surplus > 0)
                    {
                        CyclesWithTooMuch++;
                    }
                    else
                    {
                        CyclesWithTooMuch = 0;
                    }

                    if (CyclesWithTooMuch > 2)
                    {
                        server.SetBiggerVideoSize();
                        CyclesWithTooMuch = 0;
                    }

                    OnLogCreated(new LogEventArgs
                    {
                        Message = "Request, time = " + Truncate(CurrentTime.ToString()) + ", buffer = " + Truncate(BufferSize.ToString()) +
                                  ", bandwidth = " + Bandwidth + ", size = " + server.VideoSize
                    });

                    Events.Enqueue(new DownloadingFinishedEvent
                    {
                        Time = CHUNK_LENGTH * server.VideoSize / Bandwidth + CurrentTime + surplus
                    });
                }

                else if (nextEvent as MeasurementEvent != null)
                {
                    MeasurementEvent measurementEvent = (MeasurementEvent)nextEvent;
                    BufferSize -= bufferGone;
                    BufferSize  = BufferSize < 0 ? 0 : BufferSize;

                    CurrentTime = measurementEvent.Time;
                    YGraphValues.Add(BufferSize);
                    BandwidthValues.Add(Bandwidth);
                    SegmentSizeValues.Add(server.VideoSize);

                    Events.Enqueue(new MeasurementEvent
                    {
                        Time = CurrentTime + MeasurementSamplingRate
                    });
                }
            }
        }