private void Connect(string sourceName) { if (string.IsNullOrEmpty(sourceName) || _ndiSources == null || !_ndiSources.ContainsKey(sourceName)) { return; } NDIlib_source_t source = _ndiSources[sourceName]; NDIlib_recv_create_t recvDescription = new NDIlib_recv_create_t() { source_to_connect_to = source, color_format = NDIlib_recv_color_format_e.NDIlib_recv_color_format_e_BGRX_BGRA, bandwidth = NDIlib_recv_bandwidth_e.NDIlib_recv_bandwidth_lowest }; _ndiReceiveInstance = Ndi.NDIlib_recv_create(ref recvDescription); if (_ndiReceiveInstance != IntPtr.Zero) { // start up a thread to receive on _ndiReceiveThread = new Thread(ReceiveThreadProc) { IsBackground = true, Name = "Newtek Ndi video preview plugin receive thread" }; _ndiReceiveThread.Start(); } }
private void RefreshSources(object obj) { if (_ndiFindInstance != IntPtr.Zero) { int numSources = 0; var ndi_sources = Ndi.NDIlib_find_get_current_sources(_ndiFindInstance, ref numSources); if (numSources > 0) { int SourceSizeInBytes = System.Runtime.InteropServices.Marshal.SizeOf(typeof(NDIlib_source_t)); Dictionary <string, NDIlib_source_t> sources = new Dictionary <string, NDIlib_source_t>(); for (int i = 0; i < numSources; i++) { IntPtr p = IntPtr.Add(ndi_sources, (i * SourceSizeInBytes)); NDIlib_source_t src = (NDIlib_source_t)System.Runtime.InteropServices.Marshal.PtrToStructure(p, typeof(NDIlib_source_t)); var ndiName = Ndi.Utf8ToString(src.p_ndi_name); sources.Add(ndiName, src); Debug.WriteLine($"Added source name:{Ndi.Utf8ToString(src.p_ndi_name)} address :{Ndi.Utf8ToString(src.p_ip_address)}"); } // removing non-existing sources var notExistingSources = _videoSources.Where(s => !(sources.ContainsKey(s) || s == Common.Properties.Resources._none_)).ToArray(); foreach (var source in notExistingSources) { _videoSources.Remove(source); } //adding new sources foreach (var source in sources) { if (!_videoSources.Contains(source.Key)) { _videoSources.Add(source.Key); } } _ndiSources = sources; } } }