static private VerifyStreamsForRecordAndPlayback ( IEnumerable |
||
streamGuids | IEnumerable |
Collection of Guids which represent KStudioEventStreamDataTypeIds |
리턴 | void |
/// <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); } } }
/// <summary> /// Plays an event file to the Kinect service /// </summary> /// <param name="client">KStudioClient which is connected to the Kinect service</param> /// <param name="filePath">Path to event file which is targeted for playback</param> /// <param name="streamNames">Collection of streams to include in the playback session</param> /// <param name="loopCount">Number of times the playback should be repeated before stopping</param> public static void PlaybackClip(KStudioClient client, string filePath, IEnumerable <string> streamNames, uint loopCount) { if (client == null) { throw new ArgumentNullException("client"); } if (!client.IsServiceConnected) { throw new InvalidOperationException(Strings.ErrorNotConnected); } if (string.IsNullOrEmpty(filePath)) { throw new ArgumentNullException("filePath"); } KStudioPlayback playback = null; // determine if all specified streams are valid for playback if (streamNames.Count <string>() > 0) { HashSet <Guid> playbackDataTypeIds = StreamSupport.ConvertStreamsToPlaybackGuids(streamNames); StreamSupport.VerifyStreamsForRecordAndPlayback(playbackDataTypeIds); Playback.VerifyStreamsForPlayback(client, filePath, playbackDataTypeIds); try { KStudioEventStreamSelectorCollection streams = StreamSupport.CreateStreamCollection(playbackDataTypeIds, false); playback = client.CreatePlayback(filePath, streams); } catch (Exception) { //K4W supports uncompressed and compressed color, so if we get an error, try playing the other type KStudioEventStreamSelectorCollection streams = StreamSupport.CreateStreamCollection(playbackDataTypeIds, true); playback = client.CreatePlayback(filePath, streams); } } else { playback = client.CreatePlayback(filePath); } // begin playback using (playback) { playback.EndBehavior = KStudioPlaybackEndBehavior.Stop; // this is the default behavior playback.Mode = KStudioPlaybackMode.TimingEnabled; // this is the default behavior playback.LoopCount = loopCount; playback.Start(); while (playback.State == KStudioPlaybackState.Playing) { Thread.Sleep(500); } if (playback.State == KStudioPlaybackState.Error) { throw new InvalidOperationException(Strings.ErrorPlaybackFailed); } } }