Exemplo n.º 1
0
        private async void _onFrameArraved()
        {
            TimeSpan _lastTimeStamp = _startTime;

            while (_capturing)
            {
                QueryPerformanceCounter(out long start);
                using (var frame = _framePool.TryGetNextFrame())
                {
                    if (frame == null)
                    {
                        continue;
                    }
                    using (var bitmap = await SoftwareBitmap.CreateCopyFromSurfaceAsync(frame.Surface, BitmapAlphaMode.Premultiplied))
                    {
                        _processBitmap(bitmap, frame.SystemRelativeTime - _lastTimeStamp);
                        _lastTimeStamp = frame.SystemRelativeTime;
                    }
                }
                QueryPerformanceCounter(out long end);
                var spendTime = TimeSpan.FromTicks(end - start);
                if (spendTime < TimeSpan.FromMilliseconds(41))
                {
                    await Task.Delay((TimeSpan.FromMilliseconds(41) - spendTime).Milliseconds);
                }
            }
            _seesion.Dispose();
            _framePool.Dispose();
            _mediaEncoder.CloseVideoWriter();
        }