private void ReplaceCurrentVersion() { OutputContextVersion contextToClose = null; lock (this) { if (_pendingContext != null) { contextToClose = _currentContext; _currentContext = _pendingContext; _pendingContext = null; } } if (contextToClose != null) { contextToClose.Dispose(); } }
public bool PrepareVersion(UpdateVersionContext update, OutputSetup setup, IBitrateController bitrateController) { if (bitrateController != null && _bitrateController == null) { bitrateController.InitOutput(_reader); } _bitrateController = bitrateController; update.RuntimeConfig.Add(this, setup); var last = _currentContext; bool sameConfig = last != null && last.ContextSetup.Equals(setup); if (!sameConfig) { Core.LogInfo($"Change {Name}: {last?.ContextSetup} >> {setup}"); } int version = update.Version; update.AddDeploy(() => { lock (this) { if (sameConfig) { _pendingContext = new OutputContextVersion { Version = last.Version, MaxVersion = version, ContextSetup = setup, Context = last.Context.AddRef() }; } else { _pendingContext = new OutputContextVersion { Version = last == null ? version - 1 : version, // we assume that this output is just added - so accept previous version from the output queue MaxVersion = version, ContextSetup = setup, Context = new RefCounted <OutputContext>(new OutputContext()), WaitForIFrame = 125 // in case fps=60 -> gop = 120. we add 5. }; if (_currentContext != null && _currentContext.Context != null) { _currentContext.Context.Instance.Interrupt(); } } } if (!_continueProcessing) { _continueProcessing = true; _thread.Start(); } }); return(!sameConfig); }