public void ScreenReceived(IPPacket p)
        {
            p.Read(out int l, out bool s);
            byte[] arr = new byte[l];
            p.Read(ref arr, out s);

            _syncContext.Post(o =>
            {
                var stream = new MemoryStream(arr);
                var bmp    = (Bitmap)Image.FromStream(stream);
                Display    = bmp;
            }, null);
        }
Esempio n. 2
0
        public void AudioReceived(IPPacket p)
        {
            if (_audioStream == null || IsBufferNearlyFull)
            {
                return;
            }

            p.Read(out int frames, out bool s);
            p.Read(out int l, out s);
            byte[] arr = new byte[l];
            p.Read(ref arr, out s);

            _syncContext.Post(o =>
            {
                arr = _decoder.Decode(arr, frames, out l);
                _audioStream.AddSamples(arr, 0, l);
                //_audioStream.BufferedDuration.Print();

                if (_audioStream.BufferedDuration.TotalSeconds < 0.01f)
                {
                    PauseAudio();
                }
                else if (_audioStream.BufferedDuration.TotalSeconds > fullSpeed)
                {
                    PlayAudio();
                }

                _playbackRate += Math.Min(1, Math.Max(0.75f, (float)_audioStream.BufferedDuration.TotalSeconds / fullSpeed));
                reads++;

                _speedControl.PlaybackRate = _playbackRate / reads;
                //_speedControl.PlaybackRate.Print();

                if (reads > 20)
                {
                    reads         /= 2;
                    _playbackRate /= 2;
                }
            }, null);
        }