Exemple #1
0
        /// <summary>
        /// Resolves a video encoding properties instance based on the given arguments.
        /// </summary>
        /// <param name="controller">The video device controller.</param>
        /// <param name="mediaStreamType">The media stream type.</param>
        /// <param name="frameRate">The desired framerate.</param>
        /// <param name="width">The desired width in pixels.</param>
        /// <param name="height">The desired height in pixels.</param>
        /// <returns>A video encoding properties instance matching the given arguments or null if not found.</returns>
        public static VideoEncodingProperties FindVideoEncodingProperties(
            VideoDeviceController controller, MediaStreamType mediaStreamType,
            uint frameRate, uint width, uint height)
        {
            VideoEncodingProperties matchingProperties = null;

            if (controller != null)
            {
                IReadOnlyList <IMediaEncodingProperties> availableProperties =
                    controller.GetAvailableMediaStreamProperties(mediaStreamType);

                foreach (IMediaEncodingProperties properties in availableProperties)
                {
                    VideoEncodingProperties videoEncodingProperties = properties as VideoEncodingProperties;

                    if (videoEncodingProperties != null)
                    {
                        if (ResolveFrameRate(videoEncodingProperties) == frameRate &&
                            videoEncodingProperties.Width == width &&
                            videoEncodingProperties.Height == height)
                        {
                            matchingProperties = videoEncodingProperties;
                            break;
                        }
                    }
                }
            }

            return(matchingProperties);
        }
Exemple #2
0
        /// <summary>
        /// Resolves an instance of video encoding properties with the highest frame rate available
        /// matching the given media stream type.
        /// </summary>
        /// <param name="controller">The video device controller.</param>
        /// <param name="mediaStreamType">The media stream type.</param>
        /// <returns>An instance of video encoding properties with the highest frame rate available.</returns>
        public static VideoEncodingProperties ResolveVideoEncodingPropertiesWithHighestFrameRate(
            VideoDeviceController controller, MediaStreamType mediaStreamType)
        {
            VideoEncodingProperties propertiesWithHighestFrameRate = null;

            if (controller != null)
            {
                IReadOnlyList <IMediaEncodingProperties> availableProperties =
                    controller.GetAvailableMediaStreamProperties(mediaStreamType);
                uint highestFrameRate = 0;

                foreach (IMediaEncodingProperties properties in availableProperties)
                {
                    VideoEncodingProperties videoEncodingProperties = properties as VideoEncodingProperties;

                    if (videoEncodingProperties != null)
                    {
                        uint frameRate = ResolveFrameRate(videoEncodingProperties);

                        if (frameRate > highestFrameRate)
                        {
                            propertiesWithHighestFrameRate = videoEncodingProperties;
                            highestFrameRate = frameRate;
                        }
                    }
                }
            }

            return(propertiesWithHighestFrameRate);
        }
Exemple #3
0
        /// <summary>
        /// Resolves all the instances of video encoding properties with the highest frame rate
        /// available matching the given media stream type.
        /// </summary>
        /// <param name="controller">The video device controller.</param>
        /// <param name="mediaStreamType">The media stream type.</param>
        /// <returns>All the instances of video encoding properties with the highest frame rate available.</returns>
        public static IList <VideoEncodingProperties> ResolveAllVideoEncodingPropertiesWithHighestFrameRate(
            VideoDeviceController controller, MediaStreamType mediaStreamType)
        {
            uint highestFrameRate = ResolveHighestFrameRate(controller, mediaStreamType);
            IList <VideoEncodingProperties> listOfPropertiesWithHighestFrameRate = null;

            if (highestFrameRate > 0)
            {
                listOfPropertiesWithHighestFrameRate = new List <VideoEncodingProperties>();
                IReadOnlyList <IMediaEncodingProperties> availableProperties =
                    controller.GetAvailableMediaStreamProperties(mediaStreamType);

                foreach (IMediaEncodingProperties properties in availableProperties)
                {
                    VideoEncodingProperties videoEncodingProperties = properties as VideoEncodingProperties;

                    if (videoEncodingProperties != null)
                    {
                        uint frameRate = ResolveFrameRate(videoEncodingProperties);

                        if (frameRate == highestFrameRate)
                        {
                            listOfPropertiesWithHighestFrameRate.Add(videoEncodingProperties);
                        }
                    }
                }
            }

            return(listOfPropertiesWithHighestFrameRate);
        }
        /// <summary>
        /// Enumerate video preview formats and select the one
        /// whose dimensions are nearest to the input width/height.
        /// </summary>
        /// <returns>Selected format</returns>
        public static async Task <VideoEncodingProperties> SelectNearestPreviewResolutionAsync(this VideoDeviceController controller, double width, double height)
        {
            var formats = controller.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview);

            var format = (VideoEncodingProperties)formats.OrderBy((item) =>
            {
                var props = (VideoEncodingProperties)item;
                return(Math.Abs(props.Width - width) + Math.Abs(props.Height - height));
            }).First();

            await controller.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, format);

            return(format);
        }