示例#1
0
文件: SapClient.cs 项目: bbc/sdp-test
            public override bool Equals(object obj)
            {
                AnnouncementIdentifier other = obj as AnnouncementIdentifier;

                if (other == null)
                {
                    return(false);
                }

                return((other._interface == this._interface) &&
                       (other._address == this._address) &&
                       (other._hash == this._hash));
            }
示例#2
0
文件: SapClient.cs 项目: bbc/sdp-test
        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));
            }
        }
示例#3
0
文件: SapClient.cs 项目: bbc/sdp-test
        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));
            }
        }