Esempio n. 1
0
        /// <summary>
        /// Select streams by framerate
        /// </summary>
        /// <param name="compare">The comparison to use</param>
        /// <param name="framerate">The framerate to compare with</param>
        /// <returns></returns>
        public StreamSelector Select(StreamCompare compare, double framerate)
        {
            StreamSelector selector = new StreamSelector();

            foreach (StreamDescription desc in StreamDescriptions)
            {
                if (compare == StreamCompare.GreaterThan)
                {
                    if (desc.Resolution.Framerate > framerate)
                    {
                        selector.AddStream(desc);
                    }
                }
                else if (compare == StreamCompare.LessThan)
                {
                    if (desc.Resolution.Framerate < framerate)
                    {
                        selector.AddStream(desc);
                    }
                }
                else if (compare == StreamCompare.EqualTo)
                {
                    if (desc.Resolution.Framerate == framerate)
                    {
                        selector.AddStream(desc);
                    }
                }
            }

            return(selector);
        }
Esempio n. 2
0
        /// <summary>
        /// Select streams by resolution
        /// </summary>
        /// <param name="compare">The comparison to use</param>
        /// <param name="width">The width to compare with</param>
        /// <param name="height">The height to compare with</param>
        /// <returns></returns>
        public StreamSelector Select(StreamCompare compare, int width, int height)
        {
            StreamSelector selector = new StreamSelector();

            foreach (StreamDescription desc in StreamDescriptions)
            {
                if (compare == StreamCompare.GreaterThan)
                {
                    if (desc.Resolution.Width > width && desc.Resolution.Height > height)
                    {
                        selector.AddStream(desc);
                    }
                }
                else if (compare == StreamCompare.LessThan)
                {
                    if (desc.Resolution.Width < width && desc.Resolution.Height < height)
                    {
                        selector.AddStream(desc);
                    }
                }
                else if (compare == StreamCompare.EqualTo)
                {
                    if (desc.Resolution.Width == width && desc.Resolution.Height == height)
                    {
                        selector.AddStream(desc);
                    }
                }
            }

            return(selector);
        }
        /// <summary>
        /// Initializes the camera
        /// </summary>
        /// <returns></returns>
        public async Task Initialize()
        {
            lock (stateLock)
            {
                State = CameraState.Initializing;
            }

#if CAN_USE_UWP_TYPES
            try
            {
                var frameSourceGroups = await MediaFrameSourceGroup.FindAllAsync();

                StreamSelector = new StreamSelector();

                foreach (var sourceGroup in frameSourceGroups)
                {
                    string name = sourceGroup.DisplayName;
                    string id   = sourceGroup.Id;

                    foreach (var sourceInfo in sourceGroup.SourceInfos)
                    {
                        switch (CaptureMode)
                        {
                        case CaptureMode.Continuous:
                        case CaptureMode.SingleLowLatency:
                        {
                            if ((sourceInfo.MediaStreamType == MediaStreamType.VideoRecord || sourceInfo.MediaStreamType == MediaStreamType.VideoPreview) && sourceInfo.SourceKind == MediaFrameSourceKind.Color)
                            {
                                foreach (var setting in sourceInfo.VideoProfileMediaDescription)
                                {
                                    StreamDescriptionInternal desc = new StreamDescriptionInternal()
                                    {
                                        SourceName = sourceInfo.DeviceInformation.Name,
                                        SourceId   = sourceInfo.Id,
                                        Resolution = new CameraResolution()
                                        {
                                            Width = setting.Width, Height = setting.Height, Framerate = setting.FrameRate
                                        },
                                        FrameSourceInfo  = sourceInfo,
                                        FrameSourceGroup = sourceGroup,
                                        CameraType       = GetCameraType(sourceInfo.SourceKind)
                                    };

                                    StreamSelector.AddStream(desc);
                                }
                            }

                            break;
                        }

                        case CaptureMode.Single:
                        {
                            if (sourceInfo.MediaStreamType == MediaStreamType.Photo && sourceInfo.SourceKind == MediaFrameSourceKind.Color)
                            {
                                foreach (var setting in sourceInfo.VideoProfileMediaDescription)
                                {
                                    StreamDescriptionInternal desc = new StreamDescriptionInternal()
                                    {
                                        SourceName = sourceInfo.DeviceInformation.Name,
                                        SourceId   = sourceInfo.Id,
                                        Resolution = new CameraResolution()
                                        {
                                            Width = setting.Width, Height = setting.Height, Framerate = setting.FrameRate
                                        },
                                        FrameSourceInfo  = sourceInfo,
                                        FrameSourceGroup = sourceGroup,
                                        CameraType       = GetCameraType(sourceInfo.SourceKind)
                                    };

                                    StreamSelector.AddStream(desc);
                                }
                            }

                            break;
                        }
                        }
                    }
                }

                lock (stateLock)
                {
                    State = CameraState.Initialized;
                    OnCameraInitialized?.Invoke(this, true);
                }
            }
            catch
            {
                OnCameraInitialized?.Invoke(this, false);
            }
#else
            await Task.CompletedTask;
#endif
        }