Ejemplo n.º 1
0
        protected virtual bool isTheExpected(LSLStreamInfoWrapper stream)
        {
            bool predicate = StreamName.Equals(stream.Name);

            predicate &= StreamType.Equals(stream.Type);

            return(predicate);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Callback method for the Resolver gets called each time the resolver misses a stream within its cache
        /// </summary>
        /// <param name="stream"></param>
        public virtual void AStreamGotLost(LSLStreamInfoWrapper stream)
        {
            if (!isTheExpected(stream))
            {
                return;
            }

            Debug.Log(string.Format("LSL Stream {0} Lost for {1}", stream.Name, name));

            OnStreamLost();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Callback method for the Resolver gets called each time the resolver found a stream
        /// </summary>
        /// <param name="stream"></param>
        public virtual void AStreamIsFound(LSLStreamInfoWrapper stream)
        {
            if (!isTheExpected(stream))
            {
                return;
            }

            Debug.Log(string.Format("LSL Stream {0} found for {1}", stream.Name, name));

            inlet            = new liblsl.StreamInlet(stream.Item);
            expectedChannels = stream.ChannelCount;

            OnStreamAvailable();
        }
Ejemplo n.º 4
0
        public bool IsStreamAvailable(out LSLStreamInfoWrapper info, string streamName = "", string streamType = "", string hostName = "")
        {
            var result = knownStreams.Where(i =>

                                            (streamName == "" || i.Name.Equals(streamName)) &&
                                            (streamType == "" || i.Type.Equals(streamType)) &&
                                            (hostName == "" || i.Type.Equals(hostName))
                                            );

            if (result.Any())
            {
                info = result.First();
                return(true);
            }
            else
            {
                info = null;
                return(false);
            }
        }
Ejemplo n.º 5
0
        private IEnumerator resolveContinuously()
        {
            while (resolve)
            {
                var results = resolver.results();

                foreach (var item in knownStreams)
                {
                    if (!results.Any(r => r.name().Equals(item.Name)))
                    {
                        if (onStreamLost.GetPersistentEventCount() > 0)
                        {
                            onStreamLost.Invoke(item);
                        }
                    }
                }

                // remove lost streams from cache
                knownStreams.RemoveAll(s => !results.Any(r => r.name().Equals(s.Name)));

                // add new found streams to the cache
                foreach (var item in results)
                {
                    if (!knownStreams.Any(s => s.Name == item.name() && s.Type == item.type()))
                    {
                        Debug.Log(string.Format("Found new Stream {0}", item.name()));

                        var newStreamInfo = new LSLStreamInfoWrapper(item);
                        knownStreams.Add(newStreamInfo);

                        if (onStreamFound.GetPersistentEventCount() > 0)
                        {
                            onStreamFound.Invoke(newStreamInfo);
                        }
                    }
                }

                yield return(new WaitForSecondsRealtime(0.1f));
            }
            yield return(null);
        }