Esempio n. 1
0
        private void PopulateVideoDeviceProperties(MediaStreamType streamType, ComboBox comboBox, bool showFrameRate = true)
        {
            // query all properties of the specified video stream type
            IEnumerable <StreamPropertiesHelper> allStreamProperties =
                mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(streamType)
                .Select(x => new StreamPropertiesHelper(x));

            // order them by resolution then frame rate
            allStreamProperties = allStreamProperties
                                  .OrderByDescending(x => x.Height * x.Width)
                                  .ThenByDescending(x => x.FrameRate);

            // populate the combo box with the entries
            foreach (var property in allStreamProperties)
            {
                var comboBoxItem = new ComboBoxItem();
                comboBoxItem.Content = property.GetFriendlyName(showFrameRate);
                comboBoxItem.Tag     = property;
                comboBox.Items.Add(comboBoxItem);
            }

            var settings = AppSettingsContainer.GetCachedSettings();

            comboBox.SelectedItem = WebcamComboBox.Items.Where(x => (x as ComboBoxItem).Content.ToString() == settings.WebcamQuality).FirstOrDefault();
        }
Esempio n. 2
0
        private AppSettings GetCurrentSettings()
        {
            try
            {
                var quality       = AppSettingsContainer.ParseEnumValue <VideoEncodingQuality>((string)QualityComboBox.SelectedItem);
                var frameRate     = uint.Parse(((string)FrameRateComboBox.SelectedItem).Replace("fps", ""));
                var useSourceSize = UseCaptureItemSizeCheckBox.IsChecked.Value;
                var adaptBitrate  = AdaptBitrateCheckBox.IsChecked.Value;
                var webcamQuality = (WebcamComboBox.SelectedItem as ComboBoxItem).Content.ToString();

                return(new AppSettings
                {
                    Quality = quality,
                    FrameRate = frameRate,
                    UseSourceSize = useSourceSize,
                    AudioDeviceId = (AudioDeviceComboBox.SelectedItem as ComboBoxItem).Tag.ToString(),
                    WebcamDeviceId = (WebcamDeviceComboBox.SelectedItem as ComboBoxItem).Tag.ToString(),
                    WebcamQuality = webcamQuality,
                    AdaptBitrate = adaptBitrate,
                    StorageFolder = storageFolder.Path,
                    WebcamExposure = (long)ExposureSlider.Value,
                    WebcamWhiteBalance = (uint)WbSlider.Value,
                    WebcamExposureAuto = ExposureAutoCheckBox.IsChecked.HasValue ? ExposureAutoCheckBox.IsChecked.Value : true,
                    WebcamWhiteBalanceAuto = WbAutoCheckBox.IsChecked.HasValue ? WbAutoCheckBox.IsChecked.Value : true
                });
            }
            catch
            {
                return(new AppSettings());
            }
        }
Esempio n. 3
0
        private async Task LoadSettings()
        {
            var settings = AppSettingsContainer.GetCachedSettings();

            // load quality settings
            var names = new List <string>
            {
                nameof(VideoEncodingQuality.HD1080p),
                nameof(VideoEncodingQuality.HD720p),
                nameof(VideoEncodingQuality.Uhd2160p)
            };

            QualityComboBox.ItemsSource   = names;
            QualityComboBox.SelectedIndex = names.IndexOf(settings.Quality.ToString());

            var frameRates = new List <string> {
                "15fps", "30fps", "60fps"
            };

            FrameRateComboBox.ItemsSource   = frameRates;
            FrameRateComboBox.SelectedIndex = frameRates.IndexOf($"{settings.FrameRate}fps");

            UseCaptureItemSizeCheckBox.IsChecked = settings.UseSourceSize;
            AdaptBitrateCheckBox.IsChecked       = settings.AdaptBitrate;

            // load default storage path
            if (!string.IsNullOrEmpty(settings.StorageFolder))
            {
                try
                {
                    storageFolder = await StorageFolder.GetFolderFromPathAsync(settings.StorageFolder);

                    FolderName.Text = settings.StorageFolder;
                }
                catch
                {
                    var dialog = new MessageDialog(
                        "Previous storage directory does not exist anymore. Please select a new directory.",
                        "Directory not found or not enough permissions");

                    await dialog.ShowAsync();
                }
            }

            // set first webcam device
            WebcamDeviceComboBox.SelectedItem = WebcamDeviceComboBox.Items.Where(x => (x as ComboBoxItem).Tag.ToString() == settings.WebcamDeviceId).FirstOrDefault();
            AudioDeviceComboBox.SelectedItem  = AudioDeviceComboBox.Items.Where(x => (x as ComboBoxItem).Tag.ToString() == settings.AudioDeviceId).FirstOrDefault();
        }
Esempio n. 4
0
        private async void WebcamComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                var selectedItem = (sender as ComboBox).SelectedItem as ComboBoxItem;
                if (selectedItem == null)
                {
                    return;
                }

                var encodingProperties = (selectedItem.Tag as StreamPropertiesHelper).EncodingProperties;
                await mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoRecord, encodingProperties);

                SetExposureControls();
                SetWhiteBalanceControl();

                // load settings
                var settings = AppSettingsContainer.GetCachedSettings();

                if (ExposureAutoCheckBox.Visibility == Visibility.Visible && ExposureSlider.Visibility == Visibility.Visible)
                {
                    ExposureSlider.Value           = settings.WebcamExposure;
                    ExposureAutoCheckBox.IsChecked = settings.WebcamExposureAuto;
                }

                if (WbSlider.Visibility == Visibility.Visible)
                {
                    WbSlider.Value = settings.WebcamWhiteBalance;
                }

                if (WbAutoCheckBox.Visibility == Visibility.Visible)
                {
                    WbAutoCheckBox.IsChecked = settings.WebcamWhiteBalanceAuto;
                }
            }
            catch (Exception ex)
            {
                var msg = new MessageDialog("The device is not ready.");
                await msg.ShowAsync();
            }
        }
Esempio n. 5
0
        public void CacheCurrentSettings()
        {
            var settings = GetCurrentSettings();

            AppSettingsContainer.CacheSettings(settings);
        }