ConvertStreamsToGuids() static private method

Converts a collection of stream strings to DataTypeIDs (Guids)
static private ConvertStreamsToGuids ( IEnumerable streamNames ) : HashSet
streamNames IEnumerable Collection of strings to convert to Guids
return HashSet
示例#1
0
        /// <summary>
        /// Converts a collection of stream strings to DataTypeIDs (Guids) that can be played back to the Kinect sensor
        /// </summary>
        /// <param name="streamNames">Collection of strings to convert to Guids</param>
        /// <returns>Collection of Guids, which includes DataTypeIDs for each stream</returns>
        internal static HashSet <Guid> ConvertStreamsToPlaybackGuids(IEnumerable <string> streamNames)
        {
            if (streamNames == null)
            {
                throw new ArgumentNullException("streamNames");
            }

            if (streamNames.Count <string>() == 0)
            {
                throw new InvalidOperationException(Strings.ErrorNoStreams);
            }

            HashSet <Guid> streamGuids = StreamSupport.ConvertStreamsToGuids(streamNames);

            // remove body streams from the playback collection
            if (streamGuids.Contains(KStudioEventStreamDataTypeIds.Body))
            {
                Console.WriteLine(Strings.WarningIgnoreBodyDuringPlayback);
                streamGuids.Remove(KStudioEventStreamDataTypeIds.Body);
            }

            if (streamGuids.Contains(KStudioEventStreamDataTypeIds.BodyIndex))
            {
                Console.WriteLine(Strings.WarningIgnoreBodyIndexDuringPlayback);
                streamGuids.Remove(KStudioEventStreamDataTypeIds.BodyIndex);
            }

            return(streamGuids);
        }
示例#2
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);
                }
            }
        }