Esempio n. 1
0
        /// <summary>
        /// Load the entire data of a single camera.
        /// </summary>
        /// <param name="cameraId"> Camera id of the camera whose file will be loaded </param>
        private void loadCameraFile(int cameraId)
        {
            string       filename = null;
            BinaryReader reader   = null;

            try
            {
                filename = SkelRecorder.getCameraFilename(_sessionTimestamp, cameraId);
                Console.Write("Loading camera file " + filename + "...");
                reader = new BinaryReader(File.Open(filename, FileMode.Open));

                int parsedCameraId = reader.ReadInt32();
                if (cameraId != parsedCameraId)
                {
                    throw new InvalidOperationException("Camera file #" + cameraId +
                                                        " contains an illegal header: " + parsedCameraId);
                }

                try
                {
                    // Read entire camera file to memory
                    while (reader.BaseStream.Position != reader.BaseStream.Length)
                    {
                        SkelJointsData jointsData =
                            fetchNextSkeletonFromCameraFile(reader, cameraId);
                        _camRecordedFrames[cameraId].AddLast(jointsData);
                    }
                }
                catch (System.IO.EndOfStreamException)
                {
                    // This could happen if the recording crashed or a debug session was stopped ungracefully.
                    // The recording could still be valid so don't crash, we try to replay what we can.
                    Console.WriteLine("Warning: Recording ended unexpectedly.");
                }

                reader.Close();
                reader.Dispose();
            }
            catch (FileNotFoundException e)
            {
                Console.Error.Write("Error: Camera file " + filename + " not found");
                Console.Error.Write("Details: " + e);
                Environment.Exit(1);
            }
            catch (IOException e)
            {
                Console.Error.Write("Error: IO Exception during openning of camera file " + filename);
                Console.Error.Write("Details: " + e);
                Environment.Exit(1);
            }
        }