Example #1
0
    void CreateNdiFind()
    {
        var opt = new NDIlib.find_create_t {
            show_local_sources = true
        };

        _ndiFind = NDIlib.find_create_v2(ref opt);
    }
Example #2
0
    void Start()
    {
        var findOptions = new NDIlib.find_create_t {
            show_local_sources = true
        };

        _findInstance = NDIlib.find_create_v2(ref findOptions);
    }
Example #3
0
        public Finder(bool showLocalSources = false, String[] groups = null, String[] extraIps = null)
        {
            if (!NDIlib.initialize())
            {
                if (!NDIlib.is_supported_CPU())
                {
                    throw new InvalidOperationException("CPU incompatible with NDI.");
                }
                else
                {
                    throw new InvalidOperationException("Unable to initialize NDI.");
                }
            }

            //BindingOperations.EnableCollectionSynchronization(_sourceList, _sourceLock);

            IntPtr groupsNamePtr = IntPtr.Zero;

            // make a flat list of groups if needed
            if (groups != null)
            {
                StringBuilder flatGroups = new StringBuilder();
                foreach (String group in groups)
                {
                    flatGroups.Append(group);
                    if (group != groups.Last())
                    {
                        flatGroups.Append(',');
                    }
                }

                groupsNamePtr = UTF.StringToUtf8(flatGroups.ToString());
            }

            // This is also optional.
            // The list of additional IP addresses that exist that we should query for
            // sources on. For instance, if you want to find the sources on a remote machine
            // that is not on your local sub-net then you can put a comma seperated list of
            // those IP addresses here and those sources will be available locally even though
            // they are not mDNS discoverable. An example might be "12.0.0.8,13.0.12.8".
            // When none is specified (IntPtr.Zero) the registry is used.
            // Create a UTF-8 buffer from our string
            // Must use Marshal.FreeHGlobal() after use!
            // IntPtr extraIpsPtr = NDI.Common.StringToUtf8("12.0.0.8,13.0.12.8")
            IntPtr extraIpsPtr = IntPtr.Zero;

            // make a flat list of ip addresses as comma separated strings
            if (extraIps != null)
            {
                StringBuilder flatIps = new StringBuilder();
                foreach (String ipStr in extraIps)
                {
                    flatIps.Append(ipStr);
                    if (ipStr != groups.Last())
                    {
                        flatIps.Append(',');
                    }
                }

                extraIpsPtr = UTF.StringToUtf8(flatIps.ToString());
            }

            // how we want our find to operate
            NDIlib.find_create_t findDesc = new NDIlib.find_create_t()
            {
                p_groups           = groupsNamePtr,
                show_local_sources = showLocalSources,
                p_extra_ips        = extraIpsPtr
            };

            // create our find instance
            _findInstancePtr = NDIlib.find_create_v2(ref findDesc);

            // free our UTF-8 buffer if we created one
            if (groupsNamePtr != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(groupsNamePtr);
            }

            if (extraIpsPtr != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(extraIpsPtr);
            }

            // start up a thread to update on
            _findThread = new Thread(FindThreadProc)
            {
                IsBackground = true, Name = "NdiFindThread"
            };
            _findThread.Start();
        }