private void FindThreadProc() { // the size of an NDIlib.source_t, for pointer offsets int SourceSizeInBytes = Marshal.SizeOf(typeof(NDIlib.source_t)); while (!_exitThread) { // Wait up to 500ms sources to change if (NDIlib.find_wait_for_sources(_findInstancePtr, 500)) { uint NumSources = 0; IntPtr SourcesPtr = NDIlib.find_get_current_sources(_findInstancePtr, ref NumSources); // convert each unmanaged ptr into a managed NDIlib.source_t for (int i = 0; i < NumSources; i++) { // source ptr + (index * size of a source) IntPtr p = IntPtr.Add(SourcesPtr, (i * SourceSizeInBytes)); // marshal it to a managed source and assign to our list NDIlib.source_t src = (NDIlib.source_t)Marshal.PtrToStructure(p, typeof(NDIlib.source_t)); // .Net doesn't handle marshaling UTF-8 strings properly String name = UTF.Utf8ToString(src.p_ndi_name); // Add it to the list if not already in the list. // We don't have to remove because NDI applications remember any sources seen during each run. // They might be selected and come back when the connection is restored. if (!_sourceList.Any(item => item.Name == name)) { _sourceList.Add(new Source(src)); } } } } }
// Construct from NDIlib.source_t public Source(NDIlib.source_t source_t) { Name = UTF.Utf8ToString(source_t.p_ndi_name); }
// Construct from NDIlib.source_t public Source(NDIlib.source_t source_t) { Name = UTF.Utf8ToString(source_t.p_ndi_name); _ipAddress = UTF.Utf8ToString(source_t.p_ip_address); }
private void FindThreadProc() { // the size of an NDIlib.source_t, for pointer offsets int SourceSizeInBytes = Marshal.SizeOf(typeof(NDIlib.source_t)); while (!_exitThread) { // Wait up to 500ms sources to change if (NDIlib.find_wait_for_sources(_findInstancePtr, 500)) { uint NumSources = 0; IntPtr SourcesPtr = NDIlib.find_get_current_sources(_findInstancePtr, ref NumSources); // ここでソースリストを初期化しておく //_sourceList.Clear(); // convert each unmanaged ptr into a managed NDIlib.source_t for (int i = 0; i < NumSources; i++) { // source ptr + (index * size of a source) IntPtr p = IntPtr.Add(SourcesPtr, (i * SourceSizeInBytes)); // marshal it to a managed source and assign to our list NDIlib.source_t src = (NDIlib.source_t)Marshal.PtrToStructure(p, typeof(NDIlib.source_t)); // .Net doesn't handle marshaling UTF-8 strings properly String name = UTF.Utf8ToString(src.p_ndi_name); // Add it to the list if not already in the list. // We don't have to remove because NDI applications remember any sources seen during each run. // They might be selected and come back when the connection is restored. if (!_sourceList.Any(item => item.Name == name)) { // VLCが入っていなければ追加しない if (name.Contains("VLC") == true) { _sourceList.Add(new Source(src)); } } } // ソースリストから要らないソースを除いておく //foreach (var item in _sourceList) //{ // bool exclusion_flag = true; // for (int i = 0; i < NumSources; i++) // { // IntPtr p = IntPtr.Add(SourcesPtr, (i * SourceSizeInBytes)); // NDIlib.source_t src = (NDIlib.source_t)Marshal.PtrToStructure(p, typeof(NDIlib.source_t)); // String name = UTF.Utf8ToString(src.p_ndi_name); // if (item.Name == name) // { // exclusion_flag = false; // break; // } // } // if (exclusion_flag == true) // { // _sourceList.Remove(item); // break; // } //} } } }