/// <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); } } } } }
/// <summary> /// Clear all the hashtables /// </summary> public void Clear() { lock (this) { ActiveStreams.Clear(); RunningSet.Clear(); RestartTimes.Clear(); AddedFlags.Clear(); } }
/// <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); } }
/// <summary> /// Clear all "Added" flags. /// </summary> public void ClearStreamAddedFlags() { AddedFlags.Clear(); }
protected virtual void OnAddedFlags(AddedFlagsEventArgs e) { AddedFlags?.Invoke(this, e); }