/// <summary>
        /// Helper method to obtain a device Id that supports a Video Profile.
        /// If no Video Profile is found we return empty string indicating that there isn't a device on
        /// the desired panel with a supported Video Profile.
        /// </summary>
        /// <param name="panel">Contains Device Enumeration information regarding camera panel we are looking for</param>
        /// <returns>Device Information Id string</returns>
        public async Task <string> GetVideoProfileSupportedDeviceIdAsync(Windows.Devices.Enumeration.Panel panel)
        {
            string deviceId = string.Empty;

            // Find all video capture devices
            await LogStatusToOutputBox("Looking for all video capture devices");

            DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            await LogStatusToOutputBox(string.Format(CultureInfo.InvariantCulture, "Number of video capture devices found: {0}", devices.Count.ToString()));

            // Loop through devices looking for device that supports Video Profile
            foreach (var device in devices)
            {
                // Check if the device on the requested panel supports Video Profile
                if (MediaCapture.IsVideoProfileSupported(device.Id) && device.EnclosureLocation.Panel == panel)
                {
                    // We've located a device that supports Video Profiles on expected panel
                    deviceId = device.Id;
                    break;
                }
            }

            return(deviceId);
        }
Example #2
0
        async Task <bool> HasCamera(Feature feature)
        {
            var list = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            foreach (var device in list)
            {
                if (MediaCapture.IsVideoProfileSupported(device.Id))
                {
                    if (feature == Feature.Camera)
                    {
                        return(true);
                    }

                    switch (device.EnclosureLocation.Panel)
                    {
                    case Panel.Front:
                        if (feature == Feature.CameraFront)
                        {
                            return(true);
                        }
                        break;

                    case Panel.Back:
                        if (feature == Feature.CameraBack)
                        {
                            return(true);
                        }
                        break;
                    }
                }
            }
            return(false);
        }
Example #3
0
 public VideoCaptureDeviceInfo(string id, string displayName)
 {
     Id          = id;
     DisplayName = displayName;
     if (!string.IsNullOrWhiteSpace(Id))
     {
         SupportsVideoProfiles = MediaCapture.IsVideoProfileSupported(Id);
     }
     else
     {
         SupportsVideoProfiles = false;
     }
 }
Example #4
0
    private static async Task <DeviceInformation> GetBestVideoDevice()
    {
        DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

        foreach (var device in devices)
        {
            if (MediaCapture.IsVideoProfileSupported(device.Id) && device.EnclosureLocation.Panel == Panel.Back)
            {
                return(device);
            }
        }

        return(null);
    }
Example #5
0
 private void VideoCaptureDevices_SelectionChanged()
 {
     CanCreateTrack = (VideoCaptureDevices.SelectedItem != null);
     if (MediaCapture.IsVideoProfileSupported(VideoCaptureDevices.SelectedItem.Id))
     {
         // Refresh the video profiles, which wil automatically refresh the video capture
         // formats associated with the selected profile.
         RefreshVideoProfiles(VideoCaptureDevices.SelectedItem, SelectedVideoProfileKind);
     }
     else
     {
         _ = RefreshVideoCaptureFormatsAsync(VideoCaptureDevices.SelectedItem);
     }
 }
Example #6
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            Log($"Found {devices.Count} VideoCapture devices");

            foreach (var device in devices)
            {
                Log($"DeviceClass.VideoCapture");
                Log($"  Name = {device.Name}");
                Log($"  ID = {device.Id}");
                Log($"  Video Profiles Supported = {MediaCapture.IsVideoProfileSupported(device.Id)}");
            }

            await StartPreviewAsync();
        }
        private async Task <MediaCaptureInitializationSettings> getMediaCaptureSettingsAsync(Panel panel, int width, int height, int frameRate)
        {
            string deviceId = string.Empty;

            // Finds all video capture devices
            DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            foreach (var device in devices)
            {
                // Check if the device on the requested panel supports Video Profile
                if (MediaCapture.IsVideoProfileSupported(device.Id) && device.EnclosureLocation.Panel == panel)
                {
                    // We've located a device that supports Video Profiles on expected panel
                    deviceId = device.Id;
                    break;
                }
            }
            MediaCaptureInitializationSettings mediaInitSettings = new MediaCaptureInitializationSettings {
                VideoDeviceId        = deviceId,
                StreamingCaptureMode = StreamingCaptureMode.Video
            };

            if (deviceId != String.Empty)
            {
                IReadOnlyList <MediaCaptureVideoProfile> profiles = MediaCapture.FindAllVideoProfiles(deviceId);

                var match = (from profile in profiles
                             from desc in profile.SupportedRecordMediaDescription
                             where desc.Width == width && desc.Height == height && Math.Round(desc.FrameRate) == frameRate
                             select new { profile, desc }).FirstOrDefault();

                if (match != null)
                {
                    mediaInitSettings.VideoProfile           = match.profile;
                    mediaInitSettings.RecordMediaDescription = match.desc;
                }
                else
                {
                    // Could not locate rofile, use default video recording profile (or none if device not found)
                    mediaInitSettings.VideoProfile = profiles[0];
                }
            }
            return(mediaInitSettings);
        }
        public async Task RefreshVideoCaptureFormatsAsync(VideoCaptureDeviceInfo item)
        {
            var formats = new CollectionViewModel <VideoCaptureFormatViewModel>();

            if (item != null)
            {
                if (MediaCapture.IsVideoProfileSupported(item.Id))
                {
                    foreach (var desc in VideoProfiles.SelectedItem?.SupportedRecordMediaDescription)
                    {
                        var formatVM = new VideoCaptureFormatViewModel();
                        formatVM.Format.width     = desc.Width;
                        formatVM.Format.height    = desc.Height;
                        formatVM.Format.framerate = desc.FrameRate;
                        //formatVM.Format.fourcc = desc.Subtype; // TODO: string => FOURCC
                        formatVM.FormatEncodingDisplayName = desc.Subtype;
                        formats.Add(formatVM);
                    }
                }
                else
                {
                    // Device doesn't support video profiles; fall back on flat list of capture formats.
                    List <VideoCaptureFormat> formatsList = await PeerConnection.GetVideoCaptureFormatsAsync(item.Id);

                    foreach (var format in formatsList)
                    {
                        formats.Add(new VideoCaptureFormatViewModel
                        {
                            Format = format,
                            FormatEncodingDisplayName = FourCCToString(format.fourcc)
                        });
                    }
                }
            }
            VideoCaptureFormats = formats;

            // Select first item for convenience
            VideoCaptureFormats.SelectFirstItemIfAny();
        }
        private async Task <DeviceInformation> FindCameraDeviceByDeviceNameAsync(string deviceName)
        {
            Debug.WriteLine("Find the device: {0}", new object[] { deviceName });

            // Finds all video capture devices.
            DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            foreach (var device in devices)
            {
                Debug.WriteLine("MediaCapture.IsVideoProfileSupported(device.Id): {0}", MediaCapture.IsVideoProfileSupported(device.Id));
                Debug.WriteLine("deviceName.Equals(device.Name, StringComparison.OrdinalIgnoreCase): {0}", deviceName.Equals(device.Name, StringComparison.OrdinalIgnoreCase));

                // Check if the device has the requested device name.
                if (deviceName.Equals(device.Name, StringComparison.OrdinalIgnoreCase))
                {
                    return(device);
                }
            }

            return(null);
        }
Example #10
0
        private async Task InitializeWithCameraDevice(DeviceInformation cameraDevice)
        {
            if (_mediaCapture == null)
            {
                _cameraDevice = cameraDevice;
                _mediaCapture = new MediaCapture();

                var settings = new MediaCaptureInitializationSettings {
                    VideoDeviceId = _cameraDevice.Id
                };

                try
                {
                    await _mediaCapture.InitializeAsync(settings);

                    var b = MediaCapture.IsVideoProfileSupported(_cameraDevice.Id);

                    // get highest resolution for preview
                    var resolutions = _mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo).Select(x => x as VideoEncodingProperties);
                    var resolution  = resolutions.Where(r => r != null).OrderByDescending(r => r.Height * r.Width).FirstOrDefault();

                    if (resolution != null)
                    {
                        await _mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, resolution);
                    }
                }
                catch
                {
                    _mediaCapture.Dispose();
                    _mediaCapture = null;
                    return;
                }

                if (!App.IsXbox() && (_cameraDevice.EnclosureLocation == null || _cameraDevice.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front))
                {
                    _captureElement.FlowDirection = FlowDirection.RightToLeft;
                }
                else
                {
                    _captureElement.FlowDirection = FlowDirection.LeftToRight;
                }

                _captureElement.Source = _mediaCapture;

                await _mediaCapture.StartPreviewAsync();

                await SetPreviewRotationAsync();

                var definition = new FaceDetectionEffectDefinition();
                // definition.SynchronousDetectionEnabled = false;
                // definition.DetectionMode = FaceDetectionMode.HighPerformance;

                _faceDetectionEffect = (await _mediaCapture.AddVideoEffectAsync(definition, MediaStreamType.VideoPreview)) as FaceDetectionEffect;
                _faceDetectionEffect.FaceDetected += FaceDetectionEffect_FaceDetected;

                _faceDetectionEffect.DesiredDetectionInterval = TimeSpan.FromMilliseconds(100);
                _faceDetectionEffect.Enabled = true;

                _initialized = true;
            }
        }