コード例 #1
0
        public IAsyncAction SetVideoDeviceAsync(DtoMediaDevice device)
        {
            _videoDevice = device;
            var settings = ApplicationData.Current.LocalSettings;

            if (device != null)
            {
                settings.Values[MediaSettingsIds.VideoDeviceSettings] = device.Id;
                ETWEventLogger.Instance.LogEvent("Video Device Selected",
                                                 "name = " + device.Name,
                                                 DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString());

                var  selectedVideoDevice       = device.FromDto();
                int  preferredCaptureWidth     = (int)settings.Values[MediaSettingsIds.PreferredVideoCaptureWidth];
                int  preferredCaptureHeight    = (int)settings.Values[MediaSettingsIds.PreferredVideoCaptureHeight];
                int  preferredCaptureFrameRate = (int)settings.Values[MediaSettingsIds.PreferredVideoCaptureFrameRate];
                bool isCapabilityValid         = false;
                if (selectedVideoDevice != null)
                {
                    var getTask = selectedVideoDevice.GetVideoCaptureCapabilities().AsTask();
                    getTask.Wait();
                    var capabilities = getTask.Result;
                    foreach (var capability in capabilities)
                    {
                        if (capability.FrameRate == preferredCaptureFrameRate &&
                            capability.Height == preferredCaptureHeight &&
                            capability.Width == preferredCaptureWidth)
                        {
                            isCapabilityValid = true;
                        }
                    }
                }
                if (!isCapabilityValid)
                {
                    preferredCaptureWidth = 640;
                    settings.Values[MediaSettingsIds.PreferredVideoCaptureWidth] = preferredCaptureWidth;
                    preferredCaptureHeight = 480;
                    settings.Values[MediaSettingsIds.PreferredVideoCaptureHeight] = preferredCaptureHeight;
                    preferredCaptureFrameRate = 30;
                    settings.Values[MediaSettingsIds.PreferredVideoCaptureFrameRate] = preferredCaptureFrameRate;
                }
                WebRTC.SetPreferredVideoCaptureFormat(preferredCaptureWidth, preferredCaptureHeight,
                                                      preferredCaptureFrameRate);
            }
            else
            {
                settings.Values.Remove(MediaSettingsIds.VideoDeviceSettings);
            }
            OnVideoDeviceSelectionChanged?.Invoke();
            return(Task.CompletedTask.AsAsyncAction());
        }
コード例 #2
0
        public IAsyncOperation <DtoMediaDevices> GetVideoCaptureDevicesAsync()
        {
            RtcManager.Instance.EnsureRtcIsInitialized();
            var            media                 = RtcManager.Instance.Media;
            var            settings              = ApplicationData.Current.LocalSettings;
            var            videoCaptureDevices   = media.GetVideoCaptureDevices().ToArray().ToDto();
            DtoMediaDevice preferredVideoCapture = null;

            // Search for previously selected video capture device and mark as preferred if found.
            // Otherwise try to select first available device.
            if (settings.Values.ContainsKey(MediaSettingsIds.VideoDeviceSettings))
            {
                var selectedVideoCaptureDevice = Array.Find(
                    videoCaptureDevices.Devices,
                    it => it.Id == (string)settings.Values[MediaSettingsIds.VideoDeviceSettings]);
                if (selectedVideoCaptureDevice != null)
                {
                    // Previously selected video recording device found, mark as preferred.
                    selectedVideoCaptureDevice.IsPreferred = true;
                    preferredVideoCapture = selectedVideoCaptureDevice;
                    _videoDevice          = selectedVideoCaptureDevice;
                }
            }

            if (preferredVideoCapture == null)
            {
                // Previously selected video recording device is not found anymore,
                // probably removed.
                if (videoCaptureDevices.Devices.Length > 0)
                {
                    settings.Values[MediaSettingsIds.VideoDeviceSettings] = videoCaptureDevices.Devices[0].Id;
                    videoCaptureDevices.Devices[0].IsPreferred            = true;
                    _videoDevice = videoCaptureDevices.Devices[0];
                    OnVideoDeviceSelectionChanged?.Invoke();
                }
                else
                {
                    ApplicationData.Current.LocalSettings.Values.Remove(MediaSettingsIds.VideoDeviceSettings);
                    _videoDevice = null;
                    OnVideoDeviceSelectionChanged?.Invoke();
                }
            }
            return(Task.FromResult(videoCaptureDevices).AsAsyncOperation());
        }