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));
        }
Example #3
0
 /// <summary>
 /// 播放xef视频
 /// </summary>
 /// <param name="filePath">xef视频路径</param>
 public void PlaybackClip(object filePath)
 {
     ///以前的方法,不能加骨骼上去
     #region
     using (KStudioClient PlayClient = KStudio.CreateClient())
     {
         PlayClient.ConnectToService();
         using (KStudioPlayback playback = PlayClient.CreatePlayback((string)filePath))
         {
             playback.LoopCount = 0;
             playback.Start();
             Flag2 = 0;
             while (playback.State == KStudioPlaybackState.Playing)
             {
             }
             if (playback.State == KStudioPlaybackState.Error)
             {
                 Flag2 = 1;
                 throw new InvalidOperationException("Error: Playback failed!");
             }
             Flag2 = 1;
             playback.Stop();
             playback.Dispose();
         }
         PlayClient.DisconnectFromService();
         System.Windows.Forms.MessageBox.Show("回放结束");
     }
     #endregion
 }
Example #4
0
        public void GetVideoBitmapTest()
        {
            string[] files = Directory.GetFiles("C:\\KStudioRepo", "*.xef");
            using (KStudioClient client = KStudio.CreateClient()) {
                client.ConnectToService();
                using (KStudioPlayback playback = client.CreatePlayback(files[0])) {
                    playback.Start();
                    VideoStream stream = VideoStream.Instance;
                    Assert.IsNotNull(stream);

                    while (playback.State == KStudioPlaybackState.Playing)
                    {
                        System.Threading.Thread.Sleep(500);
                        VFrame frame = (VFrame)stream.GetFrame();
                        if (frame == null)
                        {
                            continue;
                        }
                        WriteableBitmap bmp = frame.GetBitmap();
                        Assert.IsNotNull(bmp);
                    }

                    Assert.AreNotEqual(playback.State, KStudioPlaybackState.Error);
                }
            }
        }
        /// <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();
            }
        }
        private void PlayClip(string filePath, bool startpaused)
        {
            using (KStudioClient client = KStudio.CreateClient())
            {
                client.ConnectToService();

                KStudioPlaybackFlags flags = KStudioPlaybackFlags.IgnoreOptionalStreams;
                try
                {
                    playback = client.CreatePlayback(filePath, flags);
                }
                catch (Exception ex)
                {
                    FLogger.Log(LogType.Debug, ex.ToString());
                }
                using (playback)
                {
                    playback.PropertyChanged += Playback_PropertyChanged;
                    playback.StateChanged    += Playback_StateChanged;

                    playback.LoopCount              = 0;
                    playback.InPointByRelativeTime  = TimeSpan.FromSeconds(FInputInPoint[0]);
                    playback.OutPointByRelativeTime = TimeSpan.FromSeconds(Math.Min(FInputOutPoint[0], playback.Duration.TotalSeconds));
                    var kStudioMetadata = playback.GetMetadata(KStudioMetadataType.Public);

                    if (startpaused)
                    {
                        playback.StartPaused();
                    }
                    else
                    {
                        playback.Start();
                    };

                    FRecordTotalDuration[0] = playback.Duration.TotalSeconds;

                    while ((playback.State == KStudioPlaybackState.Playing) || (playback.State == KStudioPlaybackState.Paused) && (doPlay))
                    {
                        if (doStep)
                        {
                            if ((playback.State == KStudioPlaybackState.Playing))
                            {
                                playback.Pause();
                            }
                            if (playback.State == KStudioPlaybackState.Paused)
                            {
                                playback.StepOnce();
                                Thread.Sleep(20);
                            }
                            doStep = false;
                        }
                        Thread.Sleep(20);
                    }
                    playback.Stop();
                }

                playback = null;
                client.DisconnectFromService();
            }
        }
Example #7
0
        /// <summary>
        /// Plays back a .xef file to the Kinect sensor
        /// </summary>
        /// <param name="filePath">Full path to the .xef file that should be played back to the sensor</param>
        private void PlaybackClip(string filePath)
        {
            using (KStudioClient client = KStudio.CreateClient())
            {
                client.ConnectToService();

                // Create the playback object
                using (KStudioPlayback playback = client.CreatePlayback(filePath))
                {
                    playback.LoopCount = this.loopCount;
                    playback.Start();

                    while (playback.State == KStudioPlaybackState.Playing)
                    {
                        Thread.Sleep(500);
                    }
                }

                client.DisconnectFromService();
            }

            // Update the UI after the background playback task has completed
            this.isPlaying = false;
            this.Dispatcher.BeginInvoke(new NoArgDelegate(UpdateState));
        }
Example #8
0
        public static void PlaybackClip(string filePath, uint loopCount)
        {
            using (KStudioClient client = KStudio.CreateClient())
            {
                client.ConnectToService();

                using (KStudioPlayback playback = client.CreatePlayback(filePath))
                {
                    playback.LoopCount = loopCount;
                    playback.Start();

                    while (playback.State == KStudioPlaybackState.Playing)
                    {
                        Thread.Sleep(500);
                    }

                    if (playback.State == KStudioPlaybackState.Error)
                    {
                        throw new InvalidOperationException("Error: Playback failed!");
                    }
                }

                client.DisconnectFromService();
            }
        }
Example #9
0
        public void VFrameTest_LT_1Sec()
        {
            string[] files = Directory.GetFiles("C:\\KStudioRepo", "*.xef");
            Array.Sort(files);
            using (KStudioClient client = KStudio.CreateClient()) {
                client.ConnectToService();
                var broken = false;
                using (KStudioPlayback playback = client.CreatePlayback(files[0])) {
                    //Console.WriteLine("Playing: {0}", files[0]);
                    playback.Start();
                    Stopwatch time = new Stopwatch();

                    VideoStream stream = VideoStream.Instance;

                    while (playback.State == KStudioPlaybackState.Playing)
                    {
                        time.Start();
                        BaseFrame frame = stream.GetFrame();
                        if (time.ElapsedMilliseconds > (1 * 1000))
                        {
                            if (frame == null)
                            {
                                broken = true;
                                System.DateTime now = DateTime.Now;
                                //System.Diagnostics.////Debug.WriteLine("Failed at: {0}:{1}:{2}:{3}", now.Hour, now.Minute, now.Second, now.Millisecond);
                            }
                        }
                        Thread.Sleep(150);
                    }
                }

                client.DisconnectFromService();
                Assert.IsFalse(broken, "The frame should not be null after 1 second");
            }
        }
Example #10
0
        public void PlaybackClip()
        {
            using (KStudioClient client = KStudio.CreateClient())
            {
                client.ConnectToService();

                using (KStudioPlayback playback = client.CreatePlayback(filePath))
                {
                    playback.LoopCount = loopCount;
                    playback.Start();

                    while (done == false && playback.State == KStudioPlaybackState.Playing)
                    {
                        Thread.Sleep(30);
                    }

                    if (playback.State == KStudioPlaybackState.Error)
                    {
                        throw new InvalidOperationException("Error: Playback failed!");
                    }

                    playback.Stop();
                    // Reset the value of done
                    done = false;
                }

                client.DisconnectFromService();
            }
        }
        public void GetDepthArrayTest()
        {
            string[] files = Directory.GetFiles("C:\\KStudioRepo", "*.xef");
            using (KStudioClient client = KStudio.CreateClient()) {
                client.ConnectToService();
                using (KStudioPlayback playback = client.CreatePlayback(files[0])) {
                    playback.Start();
                    DepthStream stream = DepthStream.Instance;
                    Assert.IsNotNull(stream);

                    while (playback.State == KStudioPlaybackState.Playing)
                    {
                        System.Threading.Thread.Sleep(500);
                        DFrame frame = (DFrame)stream.GetFrame();
                        if (frame != null)
                        {
                            //ushort[] testArr = frame.GetDepthArray();
                            //System.Diagnostics.////Debug.WriteLine("Test Arr length : " + testArr.Length);
                            //Assert.IsNotNull(testArr);
                        }
                    }

                    Assert.AreNotEqual(playback.State, KStudioPlaybackState.Error);
                }
                client.DisconnectFromService();
            }
        }
Example #12
0
        private void PlayClip(string filePath)
        {
            using (KStudioClient client = KStudio.CreateClient())
            {
                client.ConnectToService();


                KStudioPlaybackFlags flags = KStudioPlaybackFlags.IgnoreOptionalStreams;
                playback = client.CreatePlayback(filePath, flags);
                using (playback)
                {
                    playback.PropertyChanged += Recording_PropertyChanged;
                    playback.StateChanged    += Playback_StateChanged;
                    playback.LoopCount        = 10000;
                    playback.Start();

                    FRecordTotalDuration[0] = playback.Duration.TotalSeconds;

                    while ((playback.State == KStudioPlaybackState.Playing) || (playback.State == KStudioPlaybackState.Paused) && (doPlay))
                    {
                        Thread.Sleep(50);
                    }
                    playback.Stop();
                }
                client.DisconnectFromService();
            }
        }
        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();
            }
        }
        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);
        }
Example #15
0
        /// <summary>
        /// Playback a list of clips
        /// </summary>
        /// <param name="filename">ObservableCollection of VideoModel objects that contains Filename of the clip to be played.</param>
        private void PlaybackClip(ObservableCollection <VideoModel> videos)
        {
            using (KStudioClient client = KStudio.CreateClient())
            {
                client.ConnectToService();
                KStudioEventStreamSelectorCollection streamCollection = new KStudioEventStreamSelectorCollection();
                VideoModel video;
                int        i = 0;

                while (i < videos.Count)
                {
                    video = videos[i];

                    if (!string.IsNullOrEmpty(video.Filename))
                    {
                        _status = "Playing " + video.Filename + " - " + (i + 1) + "/" + videos.Count;

                        using (KStudioPlayback playback = client.CreatePlayback(video.Filename))
                        {
                            _isPlaying = true;
                            _stop      = false;

                            // We can use playback.StartPaused() and SeekRelativeTime to start the clip at
                            // a specific time.
                            playback.Start();


                            while (playback.State == KStudioPlaybackState.Playing)
                            {
                                Thread.Sleep(150);

                                if (_stop)
                                {
                                    playback.Stop();
                                    break;
                                }
                            }

                            _isPlaying = false;

                            if (_stop)
                            {
                                return;
                            }
                        }
                    }
                    i++;
                }
                client.DisconnectFromService();
            }
        }
Example #16
0
        private void Play()
        {
            using (KStudioClient client = KStudio.CreateClient())
            {
                client.ConnectToService();


                for (int f = 0; f < fileNames.Length; f++)
                {
                    string[] nameAndLoop = fileNames[f].Split(',');
                    Dispatcher.InvokeAsync(new Action(() => this.statusBox.Text = "Playing" + nameAndLoop[0]));

                    double loopCount = 0, timeSleept = 0;

                    try
                    {
                        playback = client.CreatePlayback(nameAndLoop[0]);
                        if (nameAndLoop.Length > 1)
                        {
                            loopCount = Double.Parse(nameAndLoop[1]);
                        }
                        else
                        {
                            loopCount = 1;
                        }

                        lock (playback)
                        {
                            playback.LoopCount   = (uint)loopCount;
                            playback.EndBehavior = KStudioPlaybackEndBehavior.Stop;
                            playback.Start();
                        }

                        while (playback != null && playback.State == KStudioPlaybackState.Playing)
                        {
                            Thread.Sleep(100);
                            timeSleept += 100;
                        }
                        if (playback != null && timeSleept < playback.Duration.TotalMilliseconds)
                        {
                            MessageBox.Show("Due to an unknown failure the playback has stopped.");
                            break;
                        }
                    }
                    catch (ThreadAbortException t) {
                        Console.WriteLine(t.ToString());
                    }
                }
            }
        }
Example #17
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 #18
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 #19
0
        public void startPlayback(string filePath)
        {
            uint loopCount = 100;

            new System.Threading.Thread(() =>
            {
                using (_client = KStudio.CreateClient())
                {
                    _client.ConnectToService();

                    try
                    {
                        using (_playback = _client.CreatePlayback(filePath))
                        {
                            _playback.LoopCount = loopCount;
                            _playback.Start();

                            while (_playback.State == KStudioPlaybackState.Playing || _playback.State == KStudioPlaybackState.Paused)
                            {
                                System.Threading.Thread.Sleep(500);
                            }
                            _playback.Dispose();
                            _playback = null;
                        }
                        _client.DisconnectFromService();
                    }
                    catch (NullReferenceException)
                    {
                        Debug.WriteLine("Don't know why");
                    }
                    catch (ArgumentException)
                    {
                        Debug.WriteLine("Don't know why");
                    }
                    catch (InvalidOperationException)
                    {
                        Debug.WriteLine("Same video can't be loaded at the same time");
                    }
                }
            }).Start();
        }
Example #20
0
        /// <summary>
        /// Edits file or stream-level metadata
        /// </summary>
        /// <param name="filePath">Path of file which contains metadata to edit</param>
        /// <param name="key">Key of metadata item to alter</param>
        /// <param name="value">New value to set for the metadata item</param>
        /// <param name="streamName">String which represents the stream to alter metadata for</param>
        /// <param name="updatePersonalMetadata">Value which indicates if personal metadata should be altered (default is public)</param>
        /// <param name="updateStreamMetadata">Value which indicates if stream metadata should be altered (default is file)</param>
        /// <returns>String containing updated contents of the target metadata object</returns>
        private string EditMetadata(string filePath, string key, object value, string streamName, bool updatePersonalMetadata, bool updateStreamMetadata)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath");
            }

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

            string metadataText = string.Empty;

            using (KStudioClient client = KStudio.CreateClient())
            {
                if (filePath.ToUpperInvariant().StartsWith(Strings.ConsoleClipRepository.ToUpperInvariant()))
                {
                    client.ConnectToService();
                }

                KStudioMetadataType type = KStudioMetadataType.Public;
                if (updatePersonalMetadata)
                {
                    type = KStudioMetadataType.PersonallyIdentifiableInformation;
                }

                if (updateStreamMetadata)
                {
                    metadataText = Metadata.UpdateStreamMetadata(client, filePath, streamName, type, key, value);
                }
                else
                {
                    metadataText = Metadata.UpdateFileMetadata(client, filePath, type, key, value);
                }
            }

            return(metadataText);
        }
Example #21
0
        public void OpenRecording(string filePath)
        {
            client = KStudio.CreateClient();

            client.ConnectToService();

            KStudioEventStreamSelectorCollection streamCollection = new KStudioEventStreamSelectorCollection();

            streamCollection.Add(KStudioEventStreamDataTypeIds.UncompressedColor);
            streamCollection.Add(KStudioEventStreamDataTypeIds.Depth);
            Guid Audio = new Guid(0x787c7abd, 0x9f6e, 0x4a85, 0x8d, 0x67, 0x63, 0x65, 0xff, 0x80, 0xcc, 0x69);

            streamCollection.Add(Audio);

            playback = client.CreatePlayback(filePath, streamCollection);
            playback.StateChanged += KStudioClient_Playback_StateChanged;
            playback.Start();

            OnKinectAvailabilityChanged(this, true);

            LogConsole.WriteLine("Recording opened and playing ...");
        }
        /// <summary>
        /// Playback a clip
        /// </summary>
        /// <param name="filename">Path/name of the clip to be played.</param>
        private void PlaybackClip(string filename)
        {
            using (KStudioClient client = KStudio.CreateClient())
            {
                client.ConnectToService();

                KStudioEventStreamSelectorCollection streamCollection = new KStudioEventStreamSelectorCollection();

                using (KStudioPlayback playback = client.CreatePlayback(filename))
                {
                    // If the clip should not be evaluated from the begining.
                    // It should start paused.
                    if (_initialTime.Milliseconds > 0)
                    {
                        playback.StartPaused();
                        playback.SeekByRelativeTime(_initialTime);
                        playback.Resume();
                    }
                    else
                    {
                        playback.Start();
                    }

                    while (playback.State == KStudioPlaybackState.Playing && !finished)
                    {
                        Thread.Sleep(150);
                    }

                    // Finished the read of frames for calibration.
                    if (finished)
                    {
                        playback.Stop();
                    }
                }

                client.DisconnectFromService();
            }
        }
        public Task PlayClip(string filePath, uint loopCount = 0)
        {
            if (IsRecording || IsPlaying)
            {
                return(null);
            }

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

                    using (KStudioPlayback playback = client.CreatePlayback(filePath))
                    {
                        playback.LoopCount = loopCount;
                        playback.Start();
                        while (playback.State == KStudioPlaybackState.Playing)
                        {
                            if (_stopRequested)
                            {
                                playback.Stop();
                            }
                            Thread.Sleep(50);
                        }
                    }

                    client.DisconnectFromService();
                }
                Thread.Sleep(100);
                _playing = false;
            });

            return(t);
        }
Example #24
0
        /// <summary>
        /// Records a new .xef file and saves body data to a .txt 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();

                KStudioEventStreamSelectorCollection streamCollection = new KStudioEventStreamSelectorCollection
                {
                    KStudioEventStreamDataTypeIds.Ir,
                    KStudioEventStreamDataTypeIds.Depth,
                    KStudioEventStreamDataTypeIds.Body,
                    KStudioEventStreamDataTypeIds.BodyIndex,
                    KStudioEventStreamDataTypeIds.UncompressedColor
                };

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

                client.DisconnectFromService();
            }

            if (this.trackedBodies.Count > 0)
            {
                this.SaveBodiesToFile(this.trackedBodies);
            }

            // Update UI after the background recording task has completed
            this.isRecording = false;
            this.Dispatcher.BeginInvoke(new NoArgDelegate(UpdateState));
        }
Example #25
0
        /// <summary>
        /// Run
        /// </summary>
        private void Run()
        {
            client.ConnectToService();

            using (KStudioPlayback play = client.CreatePlayback(path))
            {
                play.EndBehavior = KStudioPlaybackEndBehavior.Stop;
                play.Mode        = KStudioPlaybackMode.TimingEnabled;
                play.LoopCount   = loop;
                play.Start();

                while (play.State.Equals(KStudioPlaybackState.Playing) || play.State.Equals(KStudioPlaybackState.Paused))
                {
                    Thread.Sleep(33);

                    if (isPause && !play.State.Equals(KStudioPlaybackState.Paused))
                    {
                        play.Pause();
                    }

                    if (!isPause && play.State.Equals(KStudioPlaybackState.Paused))
                    {
                        play.Resume();
                    }

                    if (play.State.Equals(KStudioPlaybackState.Error))
                    {
                        throw new InvalidOperationException("KStudioPlayback Error");
                    }
                }

                play.Stop();
            }

            client.DisconnectFromService();
        }
Example #26
0
 public void ReplayForever()
 {
     try
     {
         using (KStudioClient client = KStudio.CreateClient())
         {
             client.ConnectToService();
             while (true)
             {
                 KStudioPlayback playback = client.CreatePlayback(this.replayFilePath);
                 playback.LoopCount = 0;
                 playback.Start();
                 this.isReplaying = true;
                 while (playback.State == KStudioPlaybackState.Playing)
                 {
                     Thread.Sleep(500);
                 }
             }
             client.DisconnectFromService();
         }
     } catch (Exception e) {
         logCallback("ReplayForever exception: " + e.Message);
     }
 }
Example #27
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 #28
0
        /// <summary>
        /// Handles all command-line arguments
        /// </summary>
        /// <param name="args">Arguments array</param>
        /// <returns>CommandLineResult to indicate if the operation was successful or not</returns>
        private CommandLineResult ProcessCommandLine(string[] args)
        {
            string        logFile                        = string.Empty;
            List <string> streamList                     = new List <string>();
            bool          updatePersonalMetadata         = false;
            uint          loopCount                      = 0;
            Dictionary <string, List <string> > commands = new Dictionary <string, List <string> >();

            try
            {
                if (args == null)
                {
                    return(CommandLineResult.Succeeded);
                }

                if (args.Length == 0)
                {
                    return(CommandLineResult.Succeeded);
                }

                // gather commands and support parameters
                for (int i = 0; i < args.Length; i++)
                {
                    string arg = args[i];
                    if (this.IsArgument(arg))
                    {
                        string key = arg.Substring(1).ToUpperInvariant();

                        if (!commands.ContainsKey(key))
                        {
                            commands.Add(key, new List <string>());

                            for (int j = i + 1; j < args.Length; j++)
                            {
                                string param = args[j];
                                if (!this.IsArgument(param))
                                {
                                    commands[key].Add(param);
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }
                }

                // process all command args
                if (commands.ContainsKey("?") || commands.ContainsKey(Strings.Command_Help))
                {
                    this.RunCommandLine();
                    this.ShowCommandLineHelp();
                    return(CommandLineResult.SucceededExit);
                }

                // -log <filename>
                if (commands.ContainsKey(Strings.Command_Log))
                {
                    if (commands[Strings.Command_Log].Count != 1)
                    {
                        Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Log));
                        return(CommandLineResult.Invalid);
                    }

                    logFile = commands[Strings.Command_Log][0];
                }

                // -loop <count>
                if (commands.ContainsKey(Strings.Command_Loop))
                {
                    if (commands[Strings.Command_Loop].Count != 1)
                    {
                        Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Loop));
                        return(CommandLineResult.Invalid);
                    }

                    if (!uint.TryParse(commands[Strings.Command_Loop][0], out loopCount))
                    {
                        Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Loop));
                        return(CommandLineResult.Invalid);
                    }
                }

                // -pii
                if (commands.ContainsKey(Strings.Command_PII))
                {
                    updatePersonalMetadata = true;
                }

                // -stream <stream1> <stream2> <stream3> ...
                if (commands.ContainsKey(Strings.Command_Stream))
                {
                    if (commands[Strings.Command_Stream].Count == 0)
                    {
                        Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Stream));
                        return(CommandLineResult.Invalid);
                    }

                    streamList = commands[Strings.Command_Stream];
                }

                // -view <filename>
                if (commands.ContainsKey(Strings.Command_View))
                {
                    this.RunCommandLine();
                    if (commands[Strings.Command_View].Count != 1)
                    {
                        Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_View));
                        return(CommandLineResult.Invalid);
                    }

                    string fileInfo = string.Empty;
                    string filePath = commands[Strings.Command_View][0];
                    this.CheckFile(filePath);
                    Console.WriteLine(Strings.WaitForViewFile);

                    using (KStudioClient client = KStudio.CreateClient())
                    {
                        if (filePath.ToUpperInvariant().StartsWith(Strings.ConsoleClipRepository.ToUpperInvariant()))
                        {
                            client.ConnectToService();
                        }

                        using (KStudioEventFile eventFile = client.OpenEventFile(filePath))
                        {
                            FileData data = new FileData(eventFile);
                            fileInfo = data.GetFileDataAsText();
                            Console.WriteLine(fileInfo);
                        }
                    }

                    if (!string.IsNullOrEmpty(logFile))
                    {
                        Logger.Start(logFile, true);
                        Logger.Log(fileInfo);
                        Logger.Stop();
                    }

                    Console.WriteLine(Strings.Done);
                    return(CommandLineResult.SucceededExit);
                }

                // -compare <filename1> <filename2>
                if (commands.ContainsKey(Strings.Command_Compare))
                {
                    this.RunCommandLine();
                    if (commands[Strings.Command_Compare].Count != 2)
                    {
                        Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Compare));
                        return(CommandLineResult.Invalid);
                    }

                    string fileInfo = string.Empty;
                    string file1    = commands[Strings.Command_Compare][0];
                    string file2    = commands[Strings.Command_Compare][1];
                    this.CheckFile(file1);
                    this.CheckFile(file2);
                    Console.WriteLine(Strings.WaitForCompareFiles);

                    using (KStudioClient client = KStudio.CreateClient())
                    {
                        if (file1.ToUpperInvariant().StartsWith(Strings.ConsoleClipRepository.ToUpperInvariant()) || file2.ToUpperInvariant().StartsWith(Strings.ConsoleClipRepository.ToUpperInvariant()))
                        {
                            client.ConnectToService();
                        }

                        using (KStudioEventFile eventFile1 = client.OpenEventFile(file1))
                            using (KStudioEventFile eventFile2 = client.OpenEventFile(file2))
                            {
                                FileData        fileData1   = new FileData(eventFile1);
                                FileData        fileData2   = new FileData(eventFile2);
                                CompareFileData compareData = new CompareFileData(fileData1, fileData2);
                                fileInfo = compareData.GetCompareFileDataAsText();
                                Console.WriteLine(fileInfo);
                            }
                    }

                    if (!string.IsNullOrEmpty(logFile))
                    {
                        Logger.Start(logFile, true);
                        Logger.Log(fileInfo);
                        Logger.Stop();
                    }

                    Console.WriteLine(Strings.Done);
                    return(CommandLineResult.SucceededExit);
                }

                // -update <filename> <metadata key> <metadata value>
                if (commands.ContainsKey(Strings.Command_Update))
                {
                    this.RunCommandLine();
                    if (commands[Strings.Command_Update].Count != 3)
                    {
                        Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Update));
                        return(CommandLineResult.Invalid);
                    }

                    string filePath = commands[Strings.Command_Update][0];
                    string key      = commands[Strings.Command_Update][1];
                    object value    = commands[Strings.Command_Update][2];
                    this.CheckFile(filePath);
                    string metadataText = string.Empty;

                    if (streamList.Count > 0)
                    {
                        // update stream metadata
                        foreach (string streamName in streamList)
                        {
                            Console.WriteLine(string.Format(CultureInfo.CurrentCulture, Strings.UpdatingStreamMetadata, streamName));
                            metadataText = this.EditMetadata(filePath, key, value, streamName, updatePersonalMetadata, true);
                            Console.WriteLine(metadataText);
                        }
                    }
                    else
                    {
                        // update file metadata
                        Console.WriteLine(Strings.UpdatingFileMetadata);
                        metadataText = this.EditMetadata(filePath, key, value, string.Empty, updatePersonalMetadata, false);
                        Console.WriteLine(metadataText);
                    }

                    Console.WriteLine(Strings.Done);
                    return(CommandLineResult.SucceededExit);
                }

                // -remove <filename> <metadata key>
                if (commands.ContainsKey(Strings.Command_Remove))
                {
                    this.RunCommandLine();
                    if (commands[Strings.Command_Remove].Count != 2)
                    {
                        Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Remove));
                        return(CommandLineResult.Invalid);
                    }

                    string filePath = commands[Strings.Command_Remove][0];
                    string key      = commands[Strings.Command_Remove][1];
                    this.CheckFile(filePath);
                    string metadataText = string.Empty;

                    if (streamList.Count > 0)
                    {
                        // update stream metadata
                        foreach (string streamName in streamList)
                        {
                            Console.WriteLine(string.Format(CultureInfo.CurrentCulture, Strings.UpdatingStreamMetadata, streamName));
                            metadataText = this.EditMetadata(filePath, key, null, streamName, updatePersonalMetadata, true);
                            Console.WriteLine(metadataText);
                        }
                    }
                    else
                    {
                        // update file metadata
                        Console.WriteLine(Strings.UpdatingFileMetadata);
                        metadataText = this.EditMetadata(filePath, key, null, string.Empty, updatePersonalMetadata, false);
                        Console.WriteLine(metadataText);
                    }

                    Console.WriteLine(Strings.Done);
                    return(CommandLineResult.SucceededExit);
                }

                // -play <filename>
                if (commands.ContainsKey(Strings.Command_Play))
                {
                    this.RunCommandLine();
                    if (commands[Strings.Command_Play].Count != 1)
                    {
                        Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Play));
                        return(CommandLineResult.Invalid);
                    }

                    string filePath = commands[Strings.Command_Play][0];
                    this.CheckFile(filePath);

                    using (KStudioClient client = KStudio.CreateClient())
                    {
                        Console.WriteLine(Strings.WaitToConnect);
                        client.ConnectToService();

                        Console.WriteLine(Strings.StartPlayback);
                        Playback.PlaybackClip(client, filePath, streamList, loopCount);
                        Console.WriteLine(Strings.StopPlayback);

                        client.DisconnectFromService();
                    }

                    Console.WriteLine(Strings.Done);
                    return(CommandLineResult.SucceededExit);
                }

                // -record <filename> <duration>
                if (commands.ContainsKey(Strings.Command_Record))
                {
                    this.RunCommandLine();
                    if (commands[Strings.Command_Record].Count != 2)
                    {
                        Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Record));
                        return(CommandLineResult.Invalid);
                    }

                    string filePath = commands[Strings.Command_Record][0];
                    this.CheckDirectory(filePath);

                    double time = 0;
                    if (!double.TryParse(commands[Strings.Command_Record][1], out time))
                    {
                        Console.Error.WriteLine(string.Format(Strings.ErrorInvalidArgs, Strings.Command_Record));
                        return(CommandLineResult.Invalid);
                    }

                    TimeSpan duration = TimeSpan.FromSeconds(time);
                    string   errorMsg = string.Empty;
                    string   fileInfo = string.Empty;

                    using (KStudioClient client = KStudio.CreateClient())
                    {
                        Console.WriteLine(Strings.WaitToConnect);
                        client.ConnectToService();

                        Console.WriteLine(Strings.StartRecording);
                        Recording.RecordClip(client, filePath, duration, streamList);
                        Console.WriteLine(Strings.StopRecording);

                        using (KStudioEventFile eventFile = client.OpenEventFile(filePath))
                        {
                            FileData fileData = new FileData(eventFile);
                            fileInfo = fileData.GetFileDataAsText();
                            Console.WriteLine(fileInfo);
                        }

                        client.DisconnectFromService();
                    }

                    if (!string.IsNullOrEmpty(logFile))
                    {
                        Logger.Start(logFile, true);
                        Logger.Log(fileInfo);
                        Logger.Stop();
                    }

                    Console.WriteLine(Strings.Done);
                    return(CommandLineResult.SucceededExit);
                }
            }
            catch (Exception ex)
            {
                string errorMsg = string.Format(Strings.ErrorPrepend, ex.Message);
                Console.Error.WriteLine(errorMsg);
                return(CommandLineResult.Failed);
            }

            return(CommandLineResult.Invalid);
        }