Exemplo n.º 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();
            }
        }
        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();
            }
        }
Exemplo n.º 4
0
        public void StopRecording()
        {
            if (recording != null)
            {
                recording.Stop();
                recording.Dispose();
                recording = null;
            }
            if (client != null)
            {
                client.DisconnectFromService();
                client.Dispose();
                client = null;
            }

            LogConsole.WriteLine("Recording stopped");
        }
Exemplo n.º 5
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("视频录制出现异常");
     }
 }
Exemplo n.º 6
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
        }