Пример #1
0
 private void OnTimeOut(object state)
 {
     lock (_sessionData)
     {
         SdpSession  session     = state as SdpSession;
         SessionData sessionData = null;
         _sessionData.TryGetValue(session, out sessionData);
         if (sessionData != null)
         {
             if (sessionData.TimeOutTime > DateTime.Now)
             {
                 return;
             }
             sessionData.Timer.Dispose();
             _sessionData.Remove(session);
             _announcements.Remove(sessionData.Id);
             SynchronizationContextPost(o =>
             {
                 lock (Sessions)
                 {
                     Sessions.Remove(sessionData.Session);
                 }
             });
         }
     }
 }
Пример #2
0
        internal void OnSessionDelete(NetworkInterfaceHandler interfaceHandler, Origin origin)
        {
            lock (_sessionData)
            {
                SdpSession          session             = new SdpSession(origin, interfaceHandler.NetworkInterface);
                SessionData         sessionData         = null;
                SessionAnnouncement sessionAnnouncement = null;
                if (_sessionData.TryGetValue(session, out sessionData))
                {
                    sessionAnnouncement = sessionData.Session;
                }

                if (sessionData != null)
                {
                    if (origin.IsUpdateOrEqual(sessionAnnouncement.SessionDescription.Origin))
                    {
                        sessionData.Timer.Dispose();
                        _sessionData.Remove(session);
                        _announcements.Remove(sessionData.Id);
                        SynchronizationContextPost(o =>
                        {
                            lock (Sessions)
                            {
                                Sessions.Remove(sessionData.Session);
                            }
                        });
                    }
                }
            }
        }
Пример #3
0
        public override bool Equals(object obj)
        {
            SdpSession session = obj as SdpSession;

            if (session == null)
            {
                return(false);
            }
            return(GetInterfaceIndex(NetworkInterface).Equals(GetInterfaceIndex(NetworkInterface)) && SessionDescription.Origin.IsSameSession(session.SessionDescription.Origin));
        }
Пример #4
0
        public override int CompareTo(Session o)
        {
            SdpSession other = o as SdpSession;

            if (GetInterfaceIndex(NetworkInterface) == GetInterfaceIndex(other.NetworkInterface))
            {
                if (SessionDescription.Origin.SessionID == other.SessionDescription.Origin.SessionID)
                {
                    return(string.Format("{0} {1} {2} {3}", SessionDescription.Origin.UserName, SessionDescription.Origin.NetworkType, SessionDescription.Origin.AddressType, SessionDescription.Origin.Address)
                           .CompareTo(string.Format("{0} {1} {2} {3}", other.SessionDescription.Origin.UserName, other.SessionDescription.Origin.NetworkType, other.SessionDescription.Origin.AddressType, other.SessionDescription.Origin.Address)));
                }
                else
                {
                    return(SessionDescription.Origin.SessionID.CompareTo(other.SessionDescription.Origin.SessionID));
                }
            }
            else
            {
                return(GetInterfaceIndex(NetworkInterface).CompareTo(GetInterfaceIndex(other.NetworkInterface)));
            }
        }
Пример #5
0
 internal void OnInterfaceDisable(NetworkInterfaceHandler networkInterfaceHandler)
 {
     lock (_sessionData)
     {
         var removedSessions = _sessionData.Where(s => s.Key.NetworkInterface == networkInterfaceHandler.NetworkInterface).ToList();
         foreach (var pair in removedSessions)
         {
             SdpSession  session     = pair.Key;
             SessionData sessionData = pair.Value;
             sessionData.Timer.Dispose();
             _sessionData.Remove(session);
             _announcements.Remove(sessionData.Id);
             SynchronizationContextPost(o =>
             {
                 lock (Sessions)
                 {
                     Sessions.Remove(sessionData.Session);
                 }
             });
         }
     }
 }
Пример #6
0
        internal void OnSessionDelete(NetworkInterfaceHandler interfaceHandler, Origin origin)
        {
            lock (_sessionData)
            {
                SdpSession session = new SdpSession(origin, interfaceHandler.NetworkInterface);
                SessionData sessionData = null;
                SessionAnnouncement sessionAnnouncement = null;
                if (_sessionData.TryGetValue(session, out sessionData))
                {
                    sessionAnnouncement = sessionData.Session;
                }

                if (sessionData != null)
                {
                    if (origin.IsUpdateOrEqual(sessionAnnouncement.SessionDescription.Origin))
                    {
                        sessionData.Timer.Dispose();
                        _sessionData.Remove(session);
                        _announcements.Remove(sessionData.Id);
                        SynchronizationContextPost(o =>
                        {
                            lock (Sessions)
                            {
                                Sessions.Remove(sessionData.Session);
                            }
                        });
                    }
                }
            }
        }
Пример #7
0
        internal void OnSessionAnnounce(NetworkInterfaceHandler interfaceHandler, Announcement announcement)
        {
            lock (_sessionData)
            {
                AnnouncementIdentifier id = new AnnouncementIdentifier(interfaceHandler.NetworkInterface, announcement);
                SessionData sessionData = null;

                bool knownAnnouncement = _announcements.TryGetValue(id, out sessionData);
                if (!knownAnnouncement)
                {
                    announcement.Decompress();

                    Stream stream = new MemoryStream(announcement.Payload.Array, announcement.Payload.Offset, announcement.Payload.Count);
                    SessionDescription description = SessionDescription.Load(stream);
                    description.SetReadOnly();

                    SdpSession session = new SdpSession(description, interfaceHandler.NetworkInterface);
                    SessionAnnouncement sessionAnnouncement = null;
                    if (_sessionData.TryGetValue(session, out sessionData))
                    {
                        sessionAnnouncement = sessionData.Session;
                    }

                    if (sessionData != null)
                    {
                        if (description.IsUpdateOf(sessionAnnouncement.SessionDescription))
                        {
                            sessionAnnouncement = new SessionAnnouncement(description, interfaceHandler.NetworkInterface);
                            SessionAnnouncement oldAnnouncement = sessionData.Session;
                            sessionData.Session = sessionAnnouncement;
                            _announcements.Remove(sessionData.Id);
                            sessionData.Id = id;
                            SynchronizationContextPost(o =>
                            {
                                lock (Sessions)
                                {
                                    Sessions.Replace(oldAnnouncement, sessionAnnouncement);
                                }
                            });
                        }
                    }
                    else
                    {
                        sessionAnnouncement = new SessionAnnouncement(description, interfaceHandler.NetworkInterface);
                        sessionData = new SessionData()
                        {
                            Session = sessionAnnouncement,
                            Timer = new Timer(OnTimeOut, session, System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite),
                            Id = id
                        };
                        _sessionData.Add(session, sessionData);
                        _announcements.Add(id, sessionData);
                        SynchronizationContextPost(o =>
                        {
                            lock (Sessions)
                            {
                                Sessions.Add(sessionAnnouncement);
                            }
                        });
                    }
                }
                sessionData.TimeOutTime = DateTime.Now + DefaultTimeOut;
                sessionData.Timer.Change(DefaultTimeOut, TimeSpan.FromMilliseconds(-1));
            }
        }
Пример #8
0
        internal void OnSessionAnnounce(NetworkInterfaceHandler interfaceHandler, Announcement announcement)
        {
            lock (_sessionData)
            {
                AnnouncementIdentifier id          = new AnnouncementIdentifier(interfaceHandler.NetworkInterface, announcement);
                SessionData            sessionData = null;

                bool knownAnnouncement = _announcements.TryGetValue(id, out sessionData);
                if (!knownAnnouncement)
                {
                    announcement.Decompress();

                    Stream             stream      = new MemoryStream(announcement.Payload.Array, announcement.Payload.Offset, announcement.Payload.Count);
                    SessionDescription description = SessionDescription.Load(stream);
                    description.SetReadOnly();

                    SdpSession          session             = new SdpSession(description, interfaceHandler.NetworkInterface);
                    SessionAnnouncement sessionAnnouncement = null;
                    if (_sessionData.TryGetValue(session, out sessionData))
                    {
                        sessionAnnouncement = sessionData.Session;
                    }

                    if (sessionData != null)
                    {
                        if (description.IsUpdateOf(sessionAnnouncement.SessionDescription))
                        {
                            sessionAnnouncement = new SessionAnnouncement(description, interfaceHandler.NetworkInterface);
                            SessionAnnouncement oldAnnouncement = sessionData.Session;
                            sessionData.Session = sessionAnnouncement;
                            _announcements.Remove(sessionData.Id);
                            sessionData.Id = id;
                            SynchronizationContextPost(o =>
                            {
                                lock (Sessions)
                                {
                                    Sessions.Replace(oldAnnouncement, sessionAnnouncement);
                                }
                            });
                        }
                    }
                    else
                    {
                        sessionAnnouncement = new SessionAnnouncement(description, interfaceHandler.NetworkInterface);
                        sessionData         = new SessionData()
                        {
                            Session = sessionAnnouncement,
                            Timer   = new Timer(OnTimeOut, session, System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite),
                            Id      = id
                        };
                        _sessionData.Add(session, sessionData);
                        _announcements.Add(id, sessionData);
                        SynchronizationContextPost(o =>
                        {
                            lock (Sessions)
                            {
                                Sessions.Add(sessionAnnouncement);
                            }
                        });
                    }
                }
                sessionData.TimeOutTime = DateTime.Now + DefaultTimeOut;
                sessionData.Timer.Change(DefaultTimeOut, TimeSpan.FromMilliseconds(-1));
            }
        }