Example #1
0
        ///// <summary>
        ///// Function used to store raw data from kinect
        ///// </summary>
        ///// <param name="filePath">path of the recording file</param>
        ///// <param name="duration">duration of the recording in seconds</param>
        //public void RecordData(string filePath, TimeSpan duration)
        //{

        //    using (KStudioClient client = KStudio.CreateClient())
        //    {
        //        client.ConnectToService();

        //        KStudioEventStreamSelectorCollection streamCollection = new KStudioEventStreamSelectorCollection();
        //        streamCollection.Add(KStudioEventStreamDataTypeIds.Ir);
        //        streamCollection.Add(KStudioEventStreamDataTypeIds.Depth);
        //        streamCollection.Add(KStudioEventStreamDataTypeIds.Body);

        //        using (KStudioRecording recording = client.CreateRecording(filePath, streamCollection))
        //        {

        //            recording.StartTimed(duration);
        //            while (recording.State == KStudioRecordingState.Recording)
        //            {
        //                Thread.Sleep(500);
        //            }

        //            if (recording.State == KStudioRecordingState.Error)
        //            {
        //                throw new InvalidOperationException("Error: Recording failed!");
        //            }
        //        }

        //        client.DisconnectFromService();
        //    }
        //}

        /// <summary>
        /// Function used to store raw data from kinect
        /// </summary>
        /// <param name="filePath">path of the recording file</param>
        public void RecordData(string filePath)
        {
            _keepRecording = true;
            using (KStudioClient client = KStudio.CreateClient())
            {
                client.ConnectToService();

                KStudioEventStreamSelectorCollection streamCollection = new KStudioEventStreamSelectorCollection();
                streamCollection.Add(KStudioEventStreamDataTypeIds.Ir);
                streamCollection.Add(KStudioEventStreamDataTypeIds.Depth);
                streamCollection.Add(KStudioEventStreamDataTypeIds.Body);
                //streamCollection.Add(KStudioEventStreamDataTypeIds.CompressedColor);

                using (KStudioRecording recording = client.CreateRecording(filePath, streamCollection))
                {
                    recording.Start();


                    //stopRecording.WaitOne();
                    while (_keepRecording)
                    {
                        Thread.Sleep(500);
                    }
                    recording.Stop();

                    if (recording.State == KStudioRecordingState.Error)
                    {
                        throw new InvalidOperationException("Error: Recording failed!");
                    }
                }

                client.DisconnectFromService();
            }
        }
Example #2
0
        /// <summary>
        /// Records a new .xef file
        /// </summary>
        /// <param name="filePath">Full path to where the file should be saved to</param>
        private void RecordClip(string filePath)
        {
            using (KStudioClient client = KStudio.CreateClient())
            {
                client.ConnectToService();

                // Specify which streams should be recorded
                KStudioEventStreamSelectorCollection streamCollection = new KStudioEventStreamSelectorCollection();
                streamCollection.Add(KStudioEventStreamDataTypeIds.Ir);
                streamCollection.Add(KStudioEventStreamDataTypeIds.Depth);
                streamCollection.Add(KStudioEventStreamDataTypeIds.Body);
                streamCollection.Add(KStudioEventStreamDataTypeIds.BodyIndex);

                // Create the recording object
                using (KStudioRecording recording = client.CreateRecording(filePath, streamCollection))
                {
                    recording.StartTimed(this.duration);
                    while (recording.State == KStudioRecordingState.Recording)
                    {
                        Thread.Sleep(500);
                    }
                }

                client.DisconnectFromService();
            }

            // Update UI after the background recording task has completed
            this.isRecording = false;
            this.Dispatcher.BeginInvoke(new NoArgDelegate(UpdateState));
        }
        /// <summary>
        /// Function used to store raw data from kinect
        /// </summary>
        /// <param name="filePath">path of the recording file</param>
        /// <param name="duration">duration of the recording in seconds</param>
        public void RecordData(string filePath, TimeSpan duration)
        {
            using (KStudioClient client = KStudio.CreateClient())
            {
                client.ConnectToService();

                KStudioEventStreamSelectorCollection streamCollection = new KStudioEventStreamSelectorCollection();
                streamCollection.Add(KStudioEventStreamDataTypeIds.Ir);
                streamCollection.Add(KStudioEventStreamDataTypeIds.Depth);
                streamCollection.Add(KStudioEventStreamDataTypeIds.Body);

                using (KStudioRecording recording = client.CreateRecording(filePath, streamCollection))
                {
                    recording.StartTimed(duration);
                    while (recording.State == KStudioRecordingState.Recording)
                    {
                        Thread.Sleep(500);
                    }

                    if (recording.State == KStudioRecordingState.Error)
                    {
                        throw new InvalidOperationException("Error: Recording failed!");
                    }
                }

                client.DisconnectFromService();
            }
        }
        public Task RecordClip(string filePath, TimeSpan duration)
        {
            if (IsRecording || IsPlaying)
            {
                return(null);
            }

            if (duration == TimeSpan.Zero)
            {
                duration = _maxRecordingDuration;
            }

            _stopRequested = false;
            Task t = Task.Run(() =>
            {
                _recording = true;
                using (KStudioClient client = KStudio.CreateClient())
                {
                    client.ConnectToService();

                    KStudioEventStreamSelectorCollection streamCollection = new KStudioEventStreamSelectorCollection();
                    //streamCollection.Add(KStudioEventStreamDataTypeIds.Ir);
                    streamCollection.Add(KStudioEventStreamDataTypeIds.Depth);
                    streamCollection.Add(KStudioEventStreamDataTypeIds.Body);
                    streamCollection.Add(KStudioEventStreamDataTypeIds.BodyIndex);
                    streamCollection.Add(KStudioEventStreamDataTypeIds.UncompressedColor);

                    using (KStudioRecording recording = client.CreateRecording(filePath, streamCollection))
                    {
                        recording.StartTimed(duration);
                        while (recording.State == KStudioRecordingState.Recording)
                        {
                            if (_stopRequested)
                            {
                                recording.Stop();
                            }
                            Thread.Sleep(50);
                        }

                        if (recording.State == KStudioRecordingState.Error)
                        {
                            throw new InvalidOperationException("Error: Recording failed!");
                        }
                    }

                    client.DisconnectFromService();
                }
                Thread.Sleep(500);
                _recording = false;
            });

            return(t);
        }
        private void RecordClip(string filePath)
        {
            using (KStudioClient client = KStudio.CreateClient())
            {
                client.ConnectToService();

                KStudioEventStreamSelectorCollection streamCollection = new KStudioEventStreamSelectorCollection();

                if (FInputIRStream[0])
                {
                    streamCollection.Add(KStudioEventStreamDataTypeIds.Ir);
                }
                if (FInputDepthStream[0])
                {
                    streamCollection.Add(KStudioEventStreamDataTypeIds.Depth);
                }
                streamCollection.Add(KStudioEventStreamDataTypeIds.Body);
                streamCollection.Add(KStudioEventStreamDataTypeIds.BodyIndex);
                if (FInputRGBStream[0])
                {
                    streamCollection.Add(KStudioEventStreamDataTypeIds.UncompressedColor);
                }

                recordingBufferSizeMB = (uint)FInputRecordingBufferSizeMB[0];

                recording = client.CreateRecording(filePath, streamCollection, recordingBufferSizeMB, KStudioRecordingFlags.IgnoreOptionalStreams);
                using (recording)
                {
                    recording.PropertyChanged += Recording_PropertyChanged;
                    recording.Start();

                    FRecordBufferSizeMegabytes[0] = (uint)recording.BufferSizeMegabytes;

                    while ((recording.State == KStudioRecordingState.Recording) && (doRecord))
                    {
                        Thread.Sleep(100);
                        //recording reports no values :(
                        FRecordBufferInUseSizeMegabytes[0] = recording.BufferInUseSizeMegabytes;
                    }
                    recording.Stop();

                    //wait until the recording buffer is empty
                    while (recording.BufferInUseSizeMegabytes > 0)
                    {
                        Thread.Sleep(50);
                        FRecordBufferInUseSizeMegabytes[0] = recording.BufferInUseSizeMegabytes;
                    }

                    recording.PropertyChanged -= Recording_PropertyChanged;
                }
                client.DisconnectFromService();
            }
        }
Example #6
0
 /// <summary>
 /// 开始录制xef文件
 /// </summary>
 /// <param name="filePath">xef文件路径</param>
 public void StartRecordClip(object filePath)
 {
     try
     {
         using (KStudioClient client = KStudio.CreateClient())
         {
             client.ConnectToService();
             KStudioEventStreamSelectorCollection streamCollection = new KStudioEventStreamSelectorCollection();
             //streamCollection.Add(KStudioEventStreamDataTypeIds.Ir);
             streamCollection.Add(KStudioEventStreamDataTypeIds.Depth);
             streamCollection.Add(KStudioEventStreamDataTypeIds.Body);
             streamCollection.Add(KStudioEventStreamDataTypeIds.BodyIndex);
             //streamCollection.Add(KStudioEventStreamDataTypeIds.UncompressedColor);
             using (KStudioRecording recording = client.CreateRecording((string)filePath, streamCollection))
             {
                 recording.Start();
                 SharpAvi.IsCreateRecord = true;
                 SharpAvi.IsRecording    = true;
                 while (recording.State == KStudioRecordingState.Recording)
                 {
                     //Flag为1时调出循环,结束录像
                     if (_flag == 1)
                     {
                         break;
                     }
                 }
                 SharpAvi.IsStopRecord = true;
                 recording.Stop();
                 recording.Dispose();
             }
             client.DisconnectFromService();
             client.Dispose();
             _flag = 0;
         }
     }
     catch
     {
         _flag  = 0;
         _flag1 = 1;
         SharpAvi.IsStopRecord = true;
         MessageBox.Show("视频录制出现异常");
     }
 }
Example #7
0
        public void StartRecording(string filePath)
        {
            client = KStudio.CreateClient();

            client.ConnectToService();

            KStudioEventStreamSelectorCollection streamCollection = new KStudioEventStreamSelectorCollection();

            streamCollection.Add(KStudioEventStreamDataTypeIds.UncompressedColor);
            streamCollection.Add(KStudioEventStreamDataTypeIds.Depth);
            // The enum value for Audio is missing. The GUID below was taken from Kinect Studio.
            var Audio = new Guid(0x787c7abd, 0x9f6e, 0x4a85, 0x8d, 0x67, 0x63, 0x65, 0xff, 0x80, 0xcc, 0x69);

            streamCollection.Add(Audio);

            recording = client.CreateRecording(filePath, streamCollection, KStudioRecordingFlags.IgnoreOptionalStreams);
            recording.Start();

            LogConsole.WriteLine("File opened and recording ...");
        }
Example #8
0
        /// <summary>
        /// Records streams from the Kinect sensor to an event file
        /// </summary>
        /// <param name="client">KStudioClient which is connected to the Kinect service</param>
        /// <param name="filePath">Path to new event file which will be created for recording</param>
        /// <param name="duration">How long the recording should last before being stopped</param>
        /// <param name="streamNames">Collection of streams to include in the recording</param>
        public static void RecordClip(KStudioClient client, string filePath, TimeSpan duration, IEnumerable <string> streamNames)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }

            if (!client.IsServiceConnected)
            {
                throw new InvalidOperationException(Strings.ErrorNotConnected);
            }

            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath");
            }

            HashSet <Guid> streamDataTypeIds = new HashSet <Guid>();
            KStudioEventStreamSelectorCollection streamCollection = new KStudioEventStreamSelectorCollection();
            KStudioRecording recording = null;

            // decide which streams to record
            if (streamNames != null && streamNames.Count <string>() > 0)
            {
                streamDataTypeIds = StreamSupport.ConvertStreamsToGuids(streamNames);
                StreamSupport.VerifyStreamsForRecordAndPlayback(streamDataTypeIds);
            }
            else
            {
                if (Path.GetExtension(filePath).ToLower().Equals(Strings.XrfExtension))
                {
                    streamDataTypeIds.Add(KStudioEventStreamDataTypeIds.RawIr);
                }
                else
                {
                    streamDataTypeIds.Add(KStudioEventStreamDataTypeIds.Ir);
                    streamDataTypeIds.Add(KStudioEventStreamDataTypeIds.Depth);
                    streamDataTypeIds.Add(KStudioEventStreamDataTypeIds.Body);
                    streamDataTypeIds.Add(KStudioEventStreamDataTypeIds.BodyIndex);
                }
            }

            // verify streams are recordable by the Kinect sensor
            foreach (Guid stream in streamDataTypeIds)
            {
                KStudioEventStream eventStream = client.GetEventStream(stream, KStudioEventStreamSemanticIds.KinectDefaultSensorProducer);
                if (!eventStream.IsRecordable)
                {
                    throw new InvalidOperationException(string.Format(Strings.ErrorRecordingStreamNotSupported, StreamSupport.ConvertStreamGuidToString(stream)));
                }

                streamCollection.Add(stream);
            }

            // fix file extension, if necessary
            if (streamDataTypeIds.Contains(KStudioEventStreamDataTypeIds.RawIr) && Path.GetExtension(filePath).ToUpperInvariant().Equals(Strings.XefExtension.ToUpperInvariant()))
            {
                Path.ChangeExtension(filePath, Strings.XrfExtension);
            }

            // attempt to record streams for the specified duration
            try
            {
                recording = client.CreateRecording(filePath, streamCollection);
            }
            catch (Exception)
            {
                //K4W supports uncompressed and compressed color, so if we get an error, try recording the other type
                streamCollection = StreamSupport.CreateStreamCollection(streamDataTypeIds, true);
                recording        = client.CreateRecording(filePath, streamCollection);
            }

            using (recording)
            {
                recording.StartTimed(duration);
                while (recording.State == KStudioRecordingState.Recording)
                {
                    Thread.Sleep(500);
                }

                if (recording.State == KStudioRecordingState.Error)
                {
                    throw new InvalidOperationException(Strings.ErrorRecordingFailed);
                }
            }
        }
Example #9
0
        public void RecordClip()
        {
            //Console.WriteLine("the thing filepath is"+thing.FilePath);
            string xefname = filePath + MainWindow.textbox + ".xef";

            // Make sure to have enough disk space for the recording
            DriveInfo[] allDrives = DriveInfo.GetDrives();
            //const string c = @"G:\";
            try
            {
                foreach (DriveInfo d in allDrives)
                {
                    if (d.IsReady && d.Name == c)
                    {
                        long totfreespace = d.TotalFreeSpace;
                        if (totfreespace < minimum_size)
                        {
                            string size = (minimum_size / 1E9).ToString();
                            mes = "Not enough disk space to record Kinect video, Available memory less than "
                                  + size + " GB";
                            throw new System.ArgumentException(mes);
                        }
                    }
                }
            }
            catch (ArgumentException exx)
            {
                Console.WriteLine("{0} Exception caught.", exx);
                done = true;
                //act_rec.Reset();
                rec_error = true;

                if (exx.Message != mes)
                {
                    // Let's restart the Kinect video service
                    // This service once stopped does not seem to restart automatically
                    Process[] kstu = Process.GetProcessesByName("KStudioHostService");
                    ///  kstu[0].Kill(); // Kill the process
                    kstu = Process.GetProcessesByName("KinectService");
                    kstu[0].Kill();
                }

                while (MessageBox.Show(exx.Message, "ERROR", MessageBoxButton.OK,
                                       MessageBoxImage.Error) != MessageBoxResult.OK)
                {
                    Thread.Sleep(20);
                }

                // Reset the recording error before exiting
                rec_error = false;
                return;
            }

            // try
            //  {
            using (KStudioClient client = KStudio.CreateClient())
            {
                client.ConnectToService();

                KStudioEventStreamSelectorCollection streamCollection = new KStudioEventStreamSelectorCollection();
                streamCollection.Add(KStudioEventStreamDataTypeIds.Ir);
                streamCollection.Add(KStudioEventStreamDataTypeIds.Depth);
                streamCollection.Add(KStudioEventStreamDataTypeIds.Body);
                streamCollection.Add(KStudioEventStreamDataTypeIds.BodyIndex);
                streamCollection.Add(KStudioEventStreamDataTypeIds.UncompressedColor);
                //streamCollection.Add(KStudioEventStreamDataTypeIds.CompressedColor);

                try
                {
                    Console.WriteLine("now the filepath is " + filePath);
                    using (KStudioRecording recording = client.CreateRecording(filePath, streamCollection))
                    {
                        // Introduce a timer to make sure that the recording is never longer than expected
                        //  act_rec.Start();

                        //recording.StartTimed(duration);
                        recording.Start();

                        while (recording.Duration.TotalMilliseconds < dur && done == false)
                        {
                            Thread.Sleep(30);
                            //int si = (int)recording.BufferInUseSizeMegabytes;
                            // Console.WriteLine("Recording Buffer in Megabytes {0} ", si);
                        }

                        recording.Stop();
                        recording.Dispose();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("{0} Exception caught.", e);
                    done      = true;
                    rec_error = true;

                    while (MessageBox.Show("ERROR", e.Message, MessageBoxButton.OK, MessageBoxImage.Error) != MessageBoxResult.OK)
                    {
                        Thread.Sleep(20);
                    }


                    // Reset the recording error before exiting
                    rec_error = false;

                    return;
                }
                finally
                {
                    Thread.Sleep(100);
                    client.DisconnectFromService();
                }
            }

            // Make sure to reset the bool done variable once recording is done
        }
Example #10
0
        /// <summary>
        /// Records streams from the Kinect sensor to an event file
        /// </summary>
        /// <param name="client">KStudioClient which is connected to the Kinect service</param>
        /// <param name="filePath">Path to new event file which will be created for recording</param>
        /// <param name="duration">How long the recording should last before being stopped</param>
        /// <param name="streamNames">Collection of streams to include in the recording</param>
        public static void RecordClip(KStudioClient client, string filePath, TimeSpan duration, IEnumerable<string> streamNames)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }

            if (!client.IsServiceConnected)
            {
                throw new InvalidOperationException(Strings.ErrorNotConnected);
            }

            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath");
            }

            HashSet<Guid> streamDataTypeIds = new HashSet<Guid>();
            KStudioEventStreamSelectorCollection streamCollection = new KStudioEventStreamSelectorCollection();
            KStudioRecording recording = null;

            // decide which streams to record
            if (streamNames != null && streamNames.Count<string>() > 0)
            {
                streamDataTypeIds = StreamSupport.ConvertStreamsToGuids(streamNames);
                StreamSupport.VerifyStreamsForRecordAndPlayback(streamDataTypeIds);
            }
            else
            {
                if (Path.GetExtension(filePath).ToLower().Equals(Strings.XrfExtension))
                {
                    streamDataTypeIds.Add(KStudioEventStreamDataTypeIds.RawIr);
                }
                else
                {
                    streamDataTypeIds.Add(KStudioEventStreamDataTypeIds.Ir);
                    streamDataTypeIds.Add(KStudioEventStreamDataTypeIds.Depth);
                    streamDataTypeIds.Add(KStudioEventStreamDataTypeIds.Body);
                    streamDataTypeIds.Add(KStudioEventStreamDataTypeIds.BodyIndex);
                }
            }

            // verify streams are recordable by the Kinect sensor
            foreach (Guid stream in streamDataTypeIds)
            {
                KStudioEventStream eventStream = client.GetEventStream(stream, KStudioEventStreamSemanticIds.KinectDefaultSensorProducer);
                if (!eventStream.IsRecordable)
                {
                    throw new InvalidOperationException(string.Format(Strings.ErrorRecordingStreamNotSupported, StreamSupport.ConvertStreamGuidToString(stream)));
                }

                streamCollection.Add(stream);
            }

            // fix file extension, if necessary
            if (streamDataTypeIds.Contains(KStudioEventStreamDataTypeIds.RawIr) && Path.GetExtension(filePath).ToUpperInvariant().Equals(Strings.XefExtension.ToUpperInvariant()))
            {
                Path.ChangeExtension(filePath, Strings.XrfExtension);
            }

            // attempt to record streams for the specified duration
            try
            {
                recording = client.CreateRecording(filePath, streamCollection);
            }
            catch (Exception)
            {
                //K4W supports uncompressed and compressed color, so if we get an error, try recording the other type
                streamCollection = StreamSupport.CreateStreamCollection(streamDataTypeIds, true);
                recording = client.CreateRecording(filePath, streamCollection);
            }

            using (recording)
            {
                recording.StartTimed(duration);
                while (recording.State == KStudioRecordingState.Recording)
                {
                    Thread.Sleep(500);
                }

                if (recording.State == KStudioRecordingState.Error)
                {
                    throw new InvalidOperationException(Strings.ErrorRecordingFailed);
                }
            }
        }