コード例 #1
0
        /// <summary>
        /// Add a source to hashtables, and possibly raise a SourceRestored event
        /// </summary>
        /// <param name="ssrc"></param>
        /// <param name="cname"></param>
        public void Add(uint ssrc, string cname)
        {
            String cnamekey = cname;             // + " " + name;

            lock (this)
            {
                if (!AddedFlags.ContainsKey(ssrc))
                {
                    AddedFlags.Add(ssrc, "true");
                }

                if (ActiveStreams.ContainsKey(cnamekey))
                {
                    ActiveStreams[cnamekey] = ssrc;
                }
                else
                {
                    ActiveStreams.Add(cnamekey, ssrc);
                }

                DateTime previousAddForCname = DateTime.Now;
                if (RestartTimes.ContainsKey(cnamekey))
                {
                    Debug.WriteLine("found previous restart time");
                    previousAddForCname = (DateTime)RestartTimes[cnamekey];
                    RestartTimes.Remove(cnamekey);
                }
                RestartTimes.Add(cnamekey, DateTime.Now);

                //Debug.WriteLine("SSRCManager.Add: " + cname +" "+Convert.ToString(ssrc));

                //if it was in our running set, update the RtpStream and raise event.
                if (RunningSet.ContainsKey(cnamekey))
                {
                    Debug.WriteLine("found item in running set:" + cnamekey);

                    uint old_ssrc = Convert.ToUInt32(RunningSet[cnamekey]);
                    RunningSet[cnamekey] = ssrc;

                    //Don't raise source restored if the last add came less then 3 seconds ago.
                    if (DateTime.Now - previousAddForCname > new TimeSpan(0, 0, 0, 3, 0))
                    {
                        //Debug.WriteLine("time qualifies stream for source restored:" + cname);
                        if ((raiseSourceRestored) && (OnSourceRestored != null))
                        {
                            //Debug.WriteLine("Ready to enqueue sourceRestored");
                            SourceData sd = new SourceData();
                            sd.old_ssrc = old_ssrc;
                            sd.new_ssrc = ssrc;
                            sd.cname    = cnamekey;
                            ThreadPool.QueueUserWorkItem(new WaitCallback(queueSourceRestored), sd);
                        }
                    }
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Clear all the hashtables
 /// </summary>
 public void Clear()
 {
     lock (this)
     {
         ActiveStreams.Clear();
         RunningSet.Clear();
         RestartTimes.Clear();
         AddedFlags.Clear();
     }
 }
コード例 #3
0
 /// <summary>
 /// Indicate whether stream added flags are set for all items in the running set.
 /// </summary>
 /// <returns></returns>
 public bool RunningSetAdded()
 {
     lock (this)
     {
         foreach (uint ssrc in RunningSet.Values)
         {
             if (!AddedFlags.ContainsKey(ssrc))
             {
                 return(false);
             }
         }
         return(true);
     }
 }
コード例 #4
0
 /// <summary>
 /// Clear all "Added" flags.
 /// </summary>
 public void ClearStreamAddedFlags()
 {
     AddedFlags.Clear();
 }
コード例 #5
0
 protected virtual void OnAddedFlags(AddedFlagsEventArgs e)
 {
     AddedFlags?.Invoke(this, e);
 }