public void UnregisterBWControllable(IBWControlContext context) { lock (_contextMap.SyncRoot) { _contextMap.Remove(context.GetBWControllable()); } }
public void UnregisterBWControllable(IBWControlContext context) { ResetBuckets(context); lock (this.SyncRoot) { _contextMap.Remove(context.GetBWControllable()); } }
public override bool Connect(IScope newScope, object[] parameters) { bool flag = base.Connect(newScope, parameters); if (flag && ((base.Scope != null) && (base.Scope.Context != null))) { this._bwContext = (base.Scope.GetService(typeof(IBWControlService)) as IBWControlService).RegisterBWControllable(this); } return(flag); }
public ITokenBucket GetVideoBucket(IBWControlContext context) { if (!(context is BWContext)) { return(null); } BWContext context2 = (BWContext)context; return(context2.buckets[1]); }
public ITokenBucket GetDataBucket(IBWControlContext context) { if (!(context is BWContext)) { return(null); } BWContext c = (BWContext)context; return(c.buckets[2]); }
public void ResetBuckets(IBWControlContext context) { if (context is BWContext) { BWContext context2 = (BWContext)context; for (int i = 0; i < 3; i++) { context2.buckets[i].Reset(); } } }
public void ResetBuckets(IBWControlContext context) { if (!(context is BWContext)) { return; } BWContext c = (BWContext)context; for (int i = 0; i < 3; i++) { c.buckets[i].Reset(); } }
public void DeferredClose() { lock (base.SyncRoot) { if (this._keepAliveJobName != null) { (base.Scope.GetService(typeof(ISchedulingService)) as ISchedulingService).RemoveScheduledJob(this._keepAliveJobName); this._keepAliveJobName = null; } if (!base.IsDisposed && !this.IsDisconnected) { this._state = 0; IStreamService scopeService = ScopeUtils.GetScopeService(base.Scope, typeof(IStreamService)) as IStreamService; if (scopeService != null) { lock (((ICollection)this._streams).SyncRoot) { IClientStream[] array = new IClientStream[this._streams.Count]; this._streams.Values.CopyTo(array, 0); foreach (IClientStream stream in array) { if (stream != null) { if (log.get_IsDebugEnabled()) { log.Debug("Closing stream: " + stream.StreamId); } scopeService.deleteStream(this, stream.StreamId); this._streamCount--; } } this._streams.Clear(); } } if (((this._bwContext != null) && (base.Scope != null)) && (base.Scope.Context != null)) { (base.Scope.GetService(typeof(IBWControlService)) as IBWControlService).UnregisterBWControllable(this._bwContext); this._bwContext = null; } base.Close(); this._rtmpServer.OnConnectionClose(this); this._rtmpNetworkStream.Close(); } } }
public override void Start() { // Ensure the play engine exists if (_engine == null) { IScope scope = this.Scope; if (scope != null) { ISchedulingService schedulingService = scope.GetService(typeof(ISchedulingService)) as ISchedulingService; IConsumerService consumerService = scope.GetService(typeof(IConsumerService)) as IConsumerService; IProviderService providerService = scope.GetService(typeof(IProviderService)) as IProviderService; _engine = new PlayEngine.Builder(this, schedulingService, consumerService, providerService).Build(); } else { if (log.IsErrorEnabled) { log.Error("Scope was null on start"); } } } // Create bw control service and register myself // Bandwidth control service should not be bound to a specific scope because it's designed to control // the bandwidth system-wide. _bwController = this.Scope.GetService(typeof(IBWControlService)) as IBWControlService; _bwContext = _bwController.RegisterBWControllable(this); //Set bandwidth members on the engine _engine.SetBandwidthController(_bwController, _bwContext); //Set buffer check interval _engine.BufferCheckInterval = _bufferCheckInterval; //Set underrun trigger _engine.UnderrunTrigger = _underrunTrigger; // Start playback engine _engine.Start(); // Notify subscribers on start NotifySubscriberStart(); }
public ITokenBucket GetDataBucket(IBWControlContext context) { if (!(context is BWContext)) return null; BWContext c = (BWContext)context; return c.buckets[2]; }
public void UpdateBWConfigure(IBWControlContext context) { // do nothing }
public void UpdateBWConfigure(IBWControlContext context) { if (!(context is BWContext)) return; BWContext c = (BWContext)context; IBWControllable bc = c.GetBWControllable(); lock (c) { if (bc.BandwidthConfiguration == null) { c.bwConfig = null; c.lastSchedule = -1; } else { long[] oldConfig = c.bwConfig; c.bwConfig = new long[4]; for (int i = 0; i < 4; i++) { c.bwConfig[i] = bc.BandwidthConfiguration.GetChannelBandwidth()[i]; } if (oldConfig == null) { // Initialize the last schedule timestamp if necessary c.lastSchedule = System.Environment.TickCount; long[] channelInitialBurst = bc.BandwidthConfiguration.GetChannelInitialBurst(); // Set the initial value to token resources as "defaultCapacity/2" for (int i = 0; i < 4; i++) { if (channelInitialBurst[i] >= 0) { c.tokenRc[i] = channelInitialBurst[i]; } else { c.tokenRc[i] = _defaultCapacity / 2; } } } else { // we have scheduled before, so migration of token is needed if (c.bwConfig[Constants.OverallChannel] >= 0 && oldConfig[Constants.OverallChannel] < 0) { c.tokenRc[Constants.OverallChannel] += c.tokenRc[Constants.AudioChannel] + c.tokenRc[Constants.VideoChannel] + c.tokenRc[Constants.DataChannel]; for (int i = 0; i < 3; i++) { c.tokenRc[i] = 0; } } else if (c.bwConfig[Constants.OverallChannel] < 0 && oldConfig[Constants.OverallChannel] >= 0) { for (int i = 0; i < 3; i++) { if (c.bwConfig[i] >= 0) { c.tokenRc[i] += c.tokenRc[Constants.OverallChannel]; break; } } c.tokenRc[Constants.OverallChannel] = 0; } } } } }
public void ResetBuckets(IBWControlContext context) { if (!(context is BWContext)) return; BWContext c = (BWContext)context; for (int i = 0; i < 3; i++) { c.buckets[i].Reset(); } }
/// <summary> /// Closes the connection. This will disconnect the client from the associated scope. /// </summary> public override void Close() { #if !SILVERLIGHT if (log.IsDebugEnabled) log.Debug(__Res.GetString(__Res.Rtmp_ConnectionClose, _connectionId)); #endif #if !FXCLIENT try { ReaderWriterLock.AcquireWriterLock(); if (_keepAliveJobName != null) { ISchedulingService service = this.Scope.GetService(typeof(ISchedulingService)) as ISchedulingService; service.RemoveScheduledJob(_keepAliveJobName); _keepAliveJobName = null; } } finally { ReaderWriterLock.ReleaseWriterLock(); } IStreamService streamService = ScopeUtils.GetScopeService(this.Scope, typeof(IStreamService)) as IStreamService; if (streamService != null) { foreach (IClientStream stream in _streams.Values) { if (stream != null) { #if !SILVERLIGHT if (log.IsDebugEnabled) log.Debug(string.Format("{0} Closing stream: {1}", _connectionId, stream.StreamId)); #endif streamService.deleteStream(this, stream.StreamId); _streamCount.Decrement(); } } _streams.Clear(); } #endif _channels.Clear(); try { ReaderWriterLock.AcquireWriterLock(); if (_bwContext != null && this.Scope != null && this.Scope.Context != null) { IBWControlService bwController = this.Scope.GetService(typeof(IBWControlService)) as IBWControlService; bwController.UnregisterBWControllable(_bwContext); _bwContext = null; } } finally { ReaderWriterLock.ReleaseWriterLock(); } base.Close(); _context.State = RtmpState.Disconnected; }
public void SetBandwidthController(IBWControlService bwController, IBWControlContext bwContext) { _bwController = bwController; _bwContext = bwContext; }
/// <summary> /// This method supports the infrastructure and is not intended to be used directly from your code. /// </summary> /// <param name="newScope"></param> /// <param name="parameters"></param> /// <returns></returns> public override bool Connect(IScope newScope, object[] parameters) { try { bool success = base.Connect(newScope, parameters); if (success) { try { ReaderWriterLock.AcquireWriterLock(); // XXX Bandwidth control service should not be bound to // a specific scope because it's designed to control // the bandwidth system-wide. if (Scope != null && Scope.Context != null) { IBWControlService bwController = Scope.GetService(typeof(IBWControlService)) as IBWControlService; _bwContext = bwController.RegisterBWControllable(this); } UnscheduleWaitForHandshakeJob(); } finally { ReaderWriterLock.ReleaseWriterLock(); } } return success; } catch (ClientRejectedException) { UnscheduleWaitForHandshakeJob(); throw; } }
public override void Start() { // Ensure the play engine exists if (_engine == null) { IScope scope = this.Scope; if (scope != null) { ISchedulingService schedulingService = scope.GetService(typeof(ISchedulingService)) as ISchedulingService; IConsumerService consumerService = scope.GetService(typeof(IConsumerService)) as IConsumerService; IProviderService providerService = scope.GetService(typeof(IProviderService)) as IProviderService; _engine = new PlayEngine.Builder(this, schedulingService, consumerService, providerService).Build(); } else { if (log.IsErrorEnabled) log.Error("Scope was null on start"); } } // Create bw control service and register myself // Bandwidth control service should not be bound to a specific scope because it's designed to control // the bandwidth system-wide. _bwController = this.Scope.GetService(typeof(IBWControlService)) as IBWControlService; _bwContext = _bwController.RegisterBWControllable(this); //Set bandwidth members on the engine _engine.SetBandwidthController(_bwController, _bwContext); //Set buffer check interval _engine.BufferCheckInterval = _bufferCheckInterval; //Set underrun trigger _engine.UnderrunTrigger = _underrunTrigger; // Start playback engine _engine.Start(); // Notify subscribers on start NotifySubscriberStart(); }
public void UpdateBWConfigure(IBWControlContext context) { }
public void ResetBuckets(IBWControlContext context) { }
public void ResetBuckets(IBWControlContext context) { // do nothing }
public ITokenBucket GetDataBucket(IBWControlContext context) { return(_dummyBucket); }
public void UpdateBWConfigure(IBWControlContext context) { if (context is BWContext) { BWContext context2 = (BWContext)context; IBWControllable bWControllable = context2.GetBWControllable(); lock (context2) { if (bWControllable.BandwidthConfiguration == null) { context2.bwConfig = null; context2.lastSchedule = -1L; } else { int num; long[] bwConfig = context2.bwConfig; context2.bwConfig = new long[4]; for (num = 0; num < 4; num++) { context2.bwConfig[num] = bWControllable.BandwidthConfiguration.GetChannelBandwidth()[num]; } if (bwConfig == null) { context2.lastSchedule = Environment.TickCount; long[] channelInitialBurst = bWControllable.BandwidthConfiguration.GetChannelInitialBurst(); for (num = 0; num < 4; num++) { if (channelInitialBurst[num] >= 0L) { context2.tokenRc[num] = channelInitialBurst[num]; } else { context2.tokenRc[num] = this._defaultCapacity / 2L; } } } else if ((context2.bwConfig[3] >= 0L) && (bwConfig[3] < 0L)) { context2.tokenRc[3] += (context2.tokenRc[0] + context2.tokenRc[1]) + context2.tokenRc[2]; for (num = 0; num < 3; num++) { context2.tokenRc[num] = 0.0; } } else if ((context2.bwConfig[3] < 0L) && (bwConfig[3] >= 0L)) { for (num = 0; num < 3; num++) { if (context2.bwConfig[num] >= 0L) { context2.tokenRc[num] += context2.tokenRc[3]; break; } } context2.tokenRc[3] = 0.0; } } } } }
public void UpdateBWConfigure(IBWControlContext context) { if (!(context is BWContext)) { return; } BWContext c = (BWContext)context; IBWControllable bc = c.GetBWControllable(); lock (c) { if (bc.BandwidthConfiguration == null) { c.bwConfig = null; c.lastSchedule = -1; } else { long[] oldConfig = c.bwConfig; c.bwConfig = new long[4]; for (int i = 0; i < 4; i++) { c.bwConfig[i] = bc.BandwidthConfiguration.GetChannelBandwidth()[i]; } if (oldConfig == null) { // Initialize the last schedule timestamp if necessary c.lastSchedule = System.Environment.TickCount; long[] channelInitialBurst = bc.BandwidthConfiguration.GetChannelInitialBurst(); // Set the initial value to token resources as "defaultCapacity/2" for (int i = 0; i < 4; i++) { if (channelInitialBurst[i] >= 0) { c.tokenRc[i] = channelInitialBurst[i]; } else { c.tokenRc[i] = _defaultCapacity / 2; } } } else { // we have scheduled before, so migration of token is needed if (c.bwConfig[Constants.OverallChannel] >= 0 && oldConfig[Constants.OverallChannel] < 0) { c.tokenRc[Constants.OverallChannel] += c.tokenRc[Constants.AudioChannel] + c.tokenRc[Constants.VideoChannel] + c.tokenRc[Constants.DataChannel]; for (int i = 0; i < 3; i++) { c.tokenRc[i] = 0; } } else if (c.bwConfig[Constants.OverallChannel] < 0 && oldConfig[Constants.OverallChannel] >= 0) { for (int i = 0; i < 3; i++) { if (c.bwConfig[i] >= 0) { c.tokenRc[i] += c.tokenRc[Constants.OverallChannel]; break; } } c.tokenRc[Constants.OverallChannel] = 0; } } } } }
public ITokenBucket GetDataBucket(IBWControlContext context) { return _dummyBucket; }
public ITokenBucket GetVideoBucket(IBWControlContext context) { return(this._dummyBucket); }