コード例 #1
0
        /// <summary>
        /// Handles body(skeleton)
        /// </summary>
        /// <param name="bodyCollectedCancelTokenSource">cancelTokenSource used to stop the task</param>
        private static void HandleBody(CancellationTokenSource bodyCollectedCancelTokenSource)
        {
            BodyFrameArrivedEventArgs e = null;
            String    frameNumber       = String.Empty;
            BodyFrame bodyFrame;

            while (true)
            {
                bodyFrame = null;
                if (bodyCollectedCancelTokenSource.IsCancellationRequested)
                {
                    break;
                }

                if (bodyFrameQueue.Count != 0)
                {
                    lock (FramesAndPaths.allFrameInfo)
                    {
                        if ((FramesAndPaths.allFrameInfo.allFrameFlag & 4) != 0)
                        {
                            continue;
                        }

                        try
                        {
                            e = bodyFrameQueue.Dequeue();
                        }
                        catch (InvalidOperationException)
                        {
                            continue;
                        }
                        try
                        {
                            bodyFrame = e.FrameReference.AcquireFrame();
                        }
                        catch (NullReferenceException)
                        {}

                        if (bodyFrame == null)
                        {
                            continue;
                        }

                        frameNumber = FramesAndPaths.allFrameInfo.frameNumber;
                        FramesAndPaths.allFrameInfo.allFrameFlag |= 4;

                        if ((FramesAndPaths.allFrameInfo.allFrameFlag ^ 31) == 0)
                        {
                            FramesAndPaths.allFrameInfo.allFrameFlag = 0;
                            FramesAndPaths.FrameNumberIncrement();
                            ++writtenCount;
                        }
                    }
                    StoreFramesData.Handle_BodyFrame(bodyFrame, frameNumber);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Handles color
        /// </summary>
        /// <param name="colorCollectedCancelTokenSource">cancelTokenSource used to stop the task</param>
        private static void HandleColor(CancellationTokenSource colorCollectedCancelTokenSource)
        {
            ColorFrameArrivedEventArgs e = null;
            String     frameNumber       = String.Empty;
            ColorFrame colorFrame;

            while (true)
            {
                colorFrame = null;
                // Whether task is requested to be canceled or not
                // 检查线程是否被请求中止
                if (colorCollectedCancelTokenSource.IsCancellationRequested)
                {
                    break;
                }

                // Queue not empty
                // 若队列不空
                if (colorFrameQueue.Count != 0)
                {
                    // Only one thread is allowed to access the global frame information object each time
                    // 加互斥锁, 一次只允许一个线程访问
                    lock (FramesAndPaths.allFrameInfo)
                    {
                        // The frame information has already been written to disk this round, continue
                        // 若本回写过, 则下一次循环
                        if ((FramesAndPaths.allFrameInfo.allFrameFlag & 1) != 0)
                        {
                            continue;
                        }
                        // Fetch a frame
                        try
                        {
                            e = colorFrameQueue.Dequeue();
                        }
                        catch (InvalidOperationException)
                        {
                            continue;
                        }
                        try
                        {
                            colorFrame = e.FrameReference.AcquireFrame();
                        }
                        catch (NullReferenceException)
                        { }

                        // Null frame, continue
                        if (colorFrame == null)
                        {
                            continue;
                        }
                        // Fetch global frame number
                        // 拿帧号
                        frameNumber = FramesAndPaths.allFrameInfo.frameNumber;

                        // Label current frame to be written this around
                        // 标记 rgb 帧已写
                        FramesAndPaths.allFrameInfo.allFrameFlag |= 1;

                        // All kinds of frame information have been written to disk
                        // 本回各种帧都已写完
                        if ((FramesAndPaths.allFrameInfo.allFrameFlag ^ 31) == 0)
                        {
                            // Set global flag to zero
                            // 全局flag置0
                            FramesAndPaths.allFrameInfo.allFrameFlag = 0;

                            // Increment the frame number
                            // frameNumber 增加
                            FramesAndPaths.FrameNumberIncrement();

                            // Increment the number of series of frames this program processes this second
                            ++writtenCount;
                        }
                    }
                    // Write to disk
                    // 写图
                    StoreFramesData.Handle_ColorFrame(colorFrame, frameNumber);
                }
            }
        }