예제 #1
0
        public void RefreshVideoProfiles(VideoCaptureDeviceInfo item, VideoProfileKind kind)
        {
            var videoProfiles = new CollectionViewModel <MediaCaptureVideoProfile>();

            if (item != null)
            {
                IReadOnlyList <MediaCaptureVideoProfile> profiles;
                if (kind == VideoProfileKind.Unspecified)
                {
                    profiles = MediaCapture.FindAllVideoProfiles(item.Id);
                }
                else
                {
                    int index = (int)kind;
                    profiles = MediaCapture.FindKnownVideoProfiles(item.Id, (KnownVideoProfile)index);
                }
                foreach (var profile in profiles)
                {
                    videoProfiles.Add(profile);
                }
            }
            VideoProfiles = videoProfiles;

            // Select first item for convenience
            VideoProfiles.SelectFirstItemIfAny();
        }
예제 #2
0
        public async Task RefreshVideoCaptureFormatsAsync(VideoCaptureDeviceInfo item)
        {
            var formats = new CollectionViewModel <VideoCaptureFormatViewModel>();

            if (item != null)
            {
                IReadOnlyList <VideoCaptureFormat> formatsList;
                string profileId = VideoProfiles.SelectedItem?.uniqueId;
                if (string.IsNullOrEmpty(profileId))
                {
                    // Device doesn't support video profiles; fall back on flat list of capture formats.
                    formatsList = await DeviceVideoTrackSource.GetCaptureFormatsAsync(item.Id);
                }
                else
                {
                    // Enumerate formats for the specified profile only
                    formatsList = await DeviceVideoTrackSource.GetCaptureFormatsAsync(item.Id, profileId);
                }
                foreach (var format in formatsList)
                {
                    formats.Add(new VideoCaptureFormatViewModel
                    {
                        Format = format,
                        FormatEncodingDisplayName = FourCCToString(format.fourcc)
                    });
                }
            }
            VideoCaptureFormats = formats;

            // Select first item for convenience
            VideoCaptureFormats.SelectFirstItemIfAny();
        }
        public void RefreshVideoProfiles(VideoCaptureDeviceInfo item, VideoProfileKind kind)
        {
            var videoProfiles = new CollectionViewModel <MediaCaptureVideoProfile>();

            if (item != null)
            {
                IReadOnlyList <MediaCaptureVideoProfile> profiles;
                if (kind == VideoProfileKind.Unspecified)
                {
                    profiles = MediaCapture.FindAllVideoProfiles(item.Id);
                }
                else
                {
                    // VideoProfileKind and KnownVideoProfile are the same with the exception of
                    // `Unspecified` that takes value 0.
                    var profile = (KnownVideoProfile)((int)kind - 1);
                    profiles = MediaCapture.FindKnownVideoProfiles(item.Id, profile);
                }
                foreach (var profile in profiles)
                {
                    videoProfiles.Add(profile);
                }
            }
            VideoProfiles = videoProfiles;

            // Select first item for convenience
            VideoProfiles.SelectFirstItemIfAny();
        }
        public async Task AddVideoTrackFromDeviceAsync(string trackName)
        {
            await RequestMediaAccessAsync(StreamingCaptureMode.Video);

            // Create the source
            VideoCaptureDeviceInfo deviceInfo = VideoCaptureDevices.SelectedItem;

            if (deviceInfo == null)
            {
                throw new InvalidOperationException("No video capture device selected");
            }
            var deviceConfig = new LocalVideoDeviceInitConfig
            {
                videoDevice = new VideoCaptureDevice {
                    id = deviceInfo.Id
                },
            };
            VideoCaptureFormatViewModel formatInfo = VideoCaptureFormats.SelectedItem;

            if (formatInfo != null)
            {
                deviceConfig.width     = formatInfo.Format.width;
                deviceConfig.height    = formatInfo.Format.height;
                deviceConfig.framerate = formatInfo.Format.framerate;
            }
            if (deviceInfo.SupportsVideoProfiles)
            {
                MediaCaptureVideoProfile profile = VideoProfiles.SelectedItem;
                deviceConfig.videoProfileId   = profile?.Id;
                deviceConfig.videoProfileKind = SelectedVideoProfileKind;
            }
            var source = await DeviceVideoTrackSource.CreateAsync(deviceConfig);

            // FIXME - this leaks the source, never disposed

            // Crate the track
            var trackConfig = new LocalVideoTrackInitConfig
            {
                trackName = trackName,
            };
            var track = LocalVideoTrack.CreateFromSource(source, trackConfig);

            // FIXME - this probably leaks the track, never disposed

            SessionModel.Current.VideoTracks.Add(new VideoTrackViewModel
            {
                Source     = source,
                Track      = track,
                TrackImpl  = track,
                IsRemote   = false,
                DeviceName = deviceInfo.DisplayName
            });
            SessionModel.Current.LocalTracks.Add(new TrackViewModel(Symbol.Video)
            {
                DisplayName = deviceInfo.DisplayName
            });
        }
예제 #5
0
        public async void RefreshVideoProfiles(VideoCaptureDeviceInfo item, VideoProfileKind kind)
        {
            // Clear formats, which are profile-dependent. This ensures the former list doesn't
            // stay visible if the current profile kind is not supported (does not return any profile).
            VideoCaptureFormats.Clear();

            var videoProfiles = new CollectionViewModel <VideoProfile>();

            if (item != null)
            {
                IReadOnlyList <VideoProfile> profiles = await DeviceVideoTrackSource.GetCaptureProfilesAsync(item.Id, kind);

                foreach (var profile in profiles)
                {
                    videoProfiles.Add(profile);
                }
            }
            VideoProfiles = videoProfiles;

            // Select first item for convenience
            VideoProfiles.SelectFirstItemIfAny();
        }
예제 #6
0
        public async Task AddVideoTrackFromDeviceAsync(string trackName)
        {
            await RequestMediaAccessAsync(StreamingCaptureMode.Video);

            VideoCaptureDeviceInfo deviceInfo = VideoCaptureDevices.SelectedItem;

            if (deviceInfo == null)
            {
                throw new InvalidOperationException("No video capture device selected");
            }
            var settings = new LocalVideoTrackSettings
            {
                trackName   = trackName,
                videoDevice = new VideoCaptureDevice {
                    id = deviceInfo.Id
                },
            };
            VideoCaptureFormatViewModel formatInfo = VideoCaptureFormats.SelectedItem;

            if (formatInfo != null)
            {
                settings.width     = formatInfo.Format.width;
                settings.height    = formatInfo.Format.height;
                settings.framerate = formatInfo.Format.framerate;
            }
            var track = await LocalVideoTrack.CreateFromDeviceAsync(settings);

            SessionModel.Current.VideoTracks.Add(new VideoTrackViewModel
            {
                Track      = track,
                TrackImpl  = track,
                IsRemote   = false,
                DeviceName = deviceInfo.DisplayName
            });
            SessionModel.Current.LocalTracks.Add(new TrackViewModel(Symbol.Video)
            {
                DisplayName = deviceInfo.DisplayName
            });
        }
        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();
        }