<commit_before>﻿using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StreamKinect2
{
    internal class KinectDeviceDepthFrameSource : IDepthFrameSource
    {
        public event DepthFrameHandler DepthFrame;
        private DepthFrameReader depthFrameReader;
        private bool isRunning;

        public KinectDeviceDepthFrameSource(DepthFrameReader depthFrameReader)
        {
            this.depthFrameReader = depthFrameReader;
            this.depthFrameReader.FrameArrived += depthFrameReader_FrameArrived;
            this.isRunning = false;
        }

        private void depthFrameReader_FrameArrived(object sender, DepthFrameArrivedEventArgs e)
        {
            // TODO: handle depth frame
        }

        public bool IsRunning
        {
            get { return this.isRunning; }
        }

        public void Start()
        {
            this.isRunning = true;<commit_msg>KinectDevice: start work on wiring up source<commit_after>﻿using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StreamKinect2
{
    internal class KinectDeviceDepthFrameSource : IDepthFrameSource
    {
        public event DepthFrameHandler DepthFrame;

        private DepthFrameReader depthFrameReader;
        private bool isRunning;
        private FrameDescription depthFrameDescription;
        private DepthFrameHandlerArgs depthFrameArgs;

        public KinectDeviceDepthFrameSource(DepthFrameReader depthFrameReader)
        {
            this.depthFrameReader = depthFrameReader;
            this.depthFrameDescription = depthFrameReader.DepthFrameSource.FrameDescription;
            this.depthFrameReader.FrameArrived += depthFrameReader_FrameArrived;
            this.isRunning = false;

            this.depthFrameArgs = new DepthFrameHandlerArgs
            {
                Width = this.depthFrameDescription.Width,
                Height = this.depthFrameDescription.Height,
                FrameData = new UInt16[this.depthFrameDescription.Width * this.depthFrameDescription.Height],
            };
        }

        private void depthFrameReader_FrameArrived(object sender, DepthFrameArrivedEventArgs e)
        {
            using (DepthFrame depthFrame = e.FrameReference.AcquireFrame())
            {
                if (depthFrame != null)
                {
                    // the fastest way to process the body index data is to directly access 
                    // the underlying buffer
                    using (Microsoft.Kinect.KinectBuffer depthBuffer = depthFrame.LockImageBuffer())
                    {
                        // verify data and write the color data to the display bitmap
                        if ((this.depthFrameDescription.Width * this.depthFrameDescription.Height) == (depthBuffer.Size / this.depthFrameDescription.BytesPerPixel))
                        {
                            // Note: In order to see the full range of depth (including the less reliable far field depth)
                            // we are setting maxDepth to the extreme potential depth threshold
                            ushort maxDepth = ushort.MaxValue;

                            // If you wish to filter by reliable depth distance, uncomment the following line:
                            //// maxDepth = depthFrame.DepthMaxReliableDistance

                            this.ProcessDepthFrameData(depthBuffer.UnderlyingBuffer, depthBuffer.Size, depthFrame.DepthMinReliableDistance, maxDepth);
                        }
                    }
                }
            }
        }

        private void ProcessDepthFrameData(IntPtr depthFrameData, uint depthFrameDataSize, ushort minDepth, ushort maxDepth)
        {
            // depth frame data is a 16 bit value
            //ushort* frameData = (ushort*)depthFrameData;

            if (DepthFrame != null) {
                DepthFrame(this, depthFrameArgs);
            }
        }

        public bool IsRunning
        {
            get { return this.isRunning; }
        }

        public void Start()
        {
            this.isRunning = true;
{'fraction_non_alphanumeric': 0.0589190443052656, 'fraction_numerical': 0.0013917884481558804, 'mean_word_length': 1.9799585348997926, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4599277', 'n_tokens_mistral': 1029, 'n_tokens_neox': 993, 'n_words': 258}