/// <summary> /// Returns the set of encoding sources. Key is cname, value is ssrc. /// </summary> /// <returns></returns> public Hashtable GetRunningSetSSRCs() { lock (this) { return((Hashtable)RunningSet.Clone()); } }
public bool IsChecked(String cname) { if (RunningSet.ContainsKey(cname)) { return(true); } return(false); }
/// <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); } } } } }
public static Contracts.Set ToContract(this ISet set, int number) { return(set switch { FinishedSet finishedSet => new Contracts.Set(number, true, RedTeamScore: finishedSet.RedTeamScore, BlueTeamScore: finishedSet.BlueTeamScore), RunningSet runningSet => new Contracts.Set(number, false, RedTeamScore: runningSet.RedTeamScore, BlueTeamScore: runningSet.BlueTeamScore), _ => throw new ArgumentOutOfRangeException(nameof(set)) });
/// <summary> /// Clear all the hashtables /// </summary> public void Clear() { lock (this) { ActiveStreams.Clear(); RunningSet.Clear(); RestartTimes.Clear(); AddedFlags.Clear(); } }
/// <summary> /// Remove cname from running set. To support change to audio source while encoding. /// </summary> /// <param name="cname"></param> /// <returns></returns> public bool RemoveFromSnapshot(string cname) { lock (this) { if (RunningSet.ContainsKey(cname)) { RunningSet.Remove(cname); } else { return(false); } } return(true); }
/// <summary> /// Add cname to running set. To support change to audio source while encoding. /// </summary> /// <param name="cname"></param> /// <returns></returns> public bool AddToSnapshot(string cname) { lock (this) { if (ActiveStreams.ContainsKey(cname)) { RunningSet.Add(cname, ActiveStreams[cname]); } else { return(false); } } return(true); }
/// <summary> /// Store one cname as the current running set. /// Return false if the stream is not there. /// In case of a problem, leave the existing running set alone. /// </summary> /// <param name="cname"></param> /// <returns></returns> public bool ReplaceRunningSet(string cname) { lock (this) { if (ActiveStreams.ContainsKey(cname)) { RunningSet.Clear(); RunningSet.Add(cname, ActiveStreams[cname]); } else { return(false); } } return(true); }
/// <summary> /// Store the current checked items list in a new running set hash. /// Return false if one of the streams is gone. /// </summary> /// <param name="cnameList"></param> /// <returns></returns> public bool SnapshotRunningSet(ArrayList cnameList) { lock (this) { RunningSet.Clear(); foreach (String cname in cnameList) { if (ActiveStreams.ContainsKey(cname)) { RunningSet.Add(cname, ActiveStreams[cname]); } else { RunningSet.Clear(); return(false); } } } return(true); }
/// <summary> /// verify that a ssrc seems stable before raising OnSourceRestored /// This was to work around a pathological analog video driver issue /// which caused sources to toggle on and off. We think the issue has /// been fixed now, so the wait time has been removed. /// We'll leave it on the thread pool since the restart does take some /// time to complete. /// </summary> /// <param name="o"></param> private void queueSourceRestored(object o) { string cname = ((SourceData)o).cname; uint old_ssrc = ((SourceData)o).old_ssrc; uint new_ssrc = ((SourceData)o).new_ssrc; if ((!RunningSet.Contains(cname)) || (!RestartTimes.Contains(cname))) { return; } if (Convert.ToUInt32(RunningSet[cname]) != new_ssrc) { return; } if ((raiseSourceRestored) && (OnSourceRestored != null)) { StreamRestoredEventArgs ea = new StreamRestoredEventArgs(new_ssrc, old_ssrc, cname, payload); OnSourceRestored(ea); //raise event } }
public void ClearRunningSet() { RunningSet.Clear(); }