public VideoPreviewViewmodel()
 {
     View = new VideoPreviewView {
         DataContext = this
     };
     _videoSources         = new ObservableCollection <string>(new[] { Common.Properties.Resources._none_ });
     _videoSource          = _videoSources.FirstOrDefault();
     CommandRefreshSources = new UICommand
     {
         ExecuteDelegate    = RefreshSources,
         CanExecuteDelegate = o => _ndiFindInstance != IntPtr.Zero
     };
     CommandGotoNdiWebsite = new UICommand {
         ExecuteDelegate = GotoNdiWebsite
     };
     CommandShowPopup = new UICommand {
         ExecuteDelegate = o => DisplayPopup = true
     };
     CommandHidePopup = new UICommand {
         ExecuteDelegate = o => DisplayPopup = false
     };
     InitNdiFind();
     if (_ndiFindInstance != IntPtr.Zero)
     {
         Task.Run(() =>
         {
             if (Ndi.NDIlib_find_wait_for_sources(_ndiFindInstance, 5000))
             {
                 Thread.Sleep(3000);
                 Application.Current?.Dispatcher.BeginInvoke((Action) delegate { RefreshSources(null); });
             }
         });
     }
 }
Exemple #2
0
        public VideoPreviewViewmodel()
        {
            View = new VideoPreviewView {
                DataContext = this
            };
            _videoSources         = new ObservableCollection <string>(new[] { Common.Properties.Resources._none_ });
            _videoSource          = _videoSources.FirstOrDefault();
            CommandRefreshSources = new UICommand
            {
                ExecuteDelegate    = RefreshSources,
                CanExecuteDelegate = o => _ndiFindInstance != IntPtr.Zero
            };
            CommandGotoNdiWebsite = new UICommand {
                ExecuteDelegate = GotoNdiWebsite
            };
            CommandShowPopup = new UICommand {
                ExecuteDelegate = o => DisplayPopup = true
            };
            CommandHidePopup = new UICommand {
                ExecuteDelegate = o => DisplayPopup = false
            };
            InitNdiFind();
            var sourcesPoolThread = new Thread(() =>
            {
                while (_ndiFindInstance != IntPtr.Zero)
                {
                    if (Ndi.NDIlib_find_wait_for_sources(_ndiFindInstance, int.MaxValue))
                    {
                        OnUiThread(() => RefreshSources(null));
                    }
                }
            })
            {
                Name         = "NDI source list pooling thread",
                Priority     = ThreadPriority.BelowNormal,
                IsBackground = true
            };

            sourcesPoolThread.Start();
        }
Exemple #3
0
        static VideoPreviewViewmodel()
        {
            Ndi.AddRuntimeDir();
            var findDesc = new NDIlib_find_create_t
            {
                p_groups           = IntPtr.Zero,
                show_local_sources = true,
                p_extra_ips        = IntPtr.Zero
            };

            NdiFindInstance = Ndi.NDIlib_find_create2(ref findDesc);
            var sourcesPoolThread = new Thread(() =>
            {
                try
                {
                    while (true)
                    {
                        if (Ndi.NDIlib_find_wait_for_sources(NdiFindInstance, int.MaxValue))
                        {
                            RefreshSources();
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            })
            {
                Name         = "NDI source list pooling thread",
                Priority     = ThreadPriority.BelowNormal,
                IsBackground = true
            };

            sourcesPoolThread.Start();
        }