コード例 #1
0
ファイル: PixelsMap.cs プロジェクト: ratsil/bethe.helpers
 public PixelsMap(MergingMethod stMergingMethod, Area stArea, Format ePixelFormat, bool bIsBTLBackground)
 {
     this.stMergingMethod = stMergingMethod;
     if (bIsBTLBackground)
     {
         if (stMergingMethod.eDeviceType == MergingDevice.CUDA)
         {
             _nIndexTriple = (byte)_nIndexTripleMax;
             System.Threading.Interlocked.Increment(ref _nIndexTripleMax);
         }
         else
         {
             _nIndexTriple        = byte.MaxValue;
             _nIndexTripleCurrent = byte.MaxValue;
         }
         (new Logger()).WriteDebug("background pixelmap created [tripindex=" + _nIndexTriple + "]");
     }
     if (!_ahMergingHash_CommandsQueue.ContainsKey(stMergingMethod.nHash))
     {
         _ahMergingHash_CommandsQueue.Add(stMergingMethod.nHash, new ThreadBufferQueue <Command>(0, false));
         System.Threading.Thread cThreadWorker = null;
         if (stMergingMethod.eDeviceType == MergingDevice.CUDA)
         {
             if (1 > Preferences.nCUDAVersion)
             {
                 throw new Exception("There is no CUDA version in preferences");
             }
             //cThreadWorker = new System.Threading.Thread(() => CUDAWorker(stMergingMethod.nHash));
             new CUDAWorkers(stMergingMethod.nHash);
         }
         else if (stMergingMethod.eDeviceType == MergingDevice.DisComExternal)
         {
             //cThreadWorker = new System.Threading.Thread(() => DisComExternalWorker(stMergingMethod.nHash));
             new DisComExternalWorkers(stMergingMethod.nHash);
         }
         if (null != cThreadWorker)
         {
             cThreadWorker.IsBackground = true;
             cThreadWorker.Priority     = System.Threading.ThreadPriority.AboveNormal;
             cThreadWorker.Start();
         }
     }
     _dtCreate      = DateTime.Now;
     _bTemp         = false;
     _bProcessing   = false;
     _bDisposed     = false;
     _nID           = 0;
     nAlphaConstant = byte.MaxValue;
     bKeepAlive     = false;
     _cException    = null;
     _ePixelFormat  = ePixelFormat;
     _stArea        = stArea;
     _nBytesQty     = (uint)(_stArea.nWidth * _stArea.nHeight * Math.Abs((int)((int)ePixelFormat / 100)) / 8);
     _cSyncRoot     = new object();
     _cTiming       = new helpers.Logger.Timings("pixelsmap");
     _cTiming.TurnOff();
 }
コード例 #2
0
ファイル: Chat.cs プロジェクト: ratsil/bethe.ingenie
        private void WorkerSMS(object cState)
        {
            _bWorkerSMSEnd = false;
            try
            {
                int            nCount;
                Queue <SMS>    aqSMSs   = null;
                Logger.Timings cTimings = new helpers.Logger.Timings("chat:WorkerSMS");
                while (!_bStopped)
                {
                    //if (DateTime.Now > dtNextTimeLog_WorkerSMS)
                    //{
                    //    (new Logger()).WriteNotice("WorkerSMS: I'm HERE! [hash:" + this.GetHashCode() + "]");
                    //    dtNextTimeLog_WorkerSMS = DateTime.Now.AddMinutes(1);
                    //}
                    try
                    {
                        lock (_aqSMSs)
                            nCount = _aqSMSs.Count;
                        if (5 >= nCount)
                        {
                            aqSMSs = GetSMSs(5);

                            if (!aqSMSs.IsNullOrEmpty())
                            {
                                lock (_aqSMSs)
                                {
                                    while (0 < aqSMSs.Count)
                                    {
                                        _aqSMSs.Enqueue(aqSMSs.Dequeue());
                                    }
                                }
                            }
                        }
                        MessagesRelease();
                    }
                    catch (Exception ex)
                    {
                        (new Logger()).WriteError(ex);
                    }

                    //GC.Collect
                    Thread.Sleep(500);
                }
                MessagesRelease();
                (new Logger()).WriteNotice("messages worker stopped");
            }
            catch (Exception ex)
            {
                (new Logger()).WriteError(ex);
            }
            _bWorkerSMSEnd = true;
        }
コード例 #3
0
 public override void Dispose()
 {
     lock (_oLockDispose)
     {
         if (_bDisposed)
         {
             return;
         }
         _bDisposed = true;
     }
     try
     {
         Logger.Timings cTimings = new helpers.Logger.Timings("composite:disposing");
         if (null != _aEffects)
         {
             lock (_aEffects)
             {
                 foreach (Effect cEff in _aEffects)
                 {
                     cEff.Dispose();
                 }
                 if (null != _aColumns)
                 {
                     _aColumns.Clear();
                     _aColumns = null;
                 }
                 if (null != _aLines)
                 {
                     _aLines.Clear();
                     _aLines = null;
                 }
             }
             if (0 < _aEffects.Count)
             {
                 cTimings.TotalRenew();
                 for (int nI = 0; nI < _aEffects.Count; nI++)
                 {
                     _aEffects[nI].Dispose();
                     _aEffects[nI] = null;
                 }
                 cTimings.Stop("composite dispose", "GC-mode: " + System.Runtime.GCSettings.LatencyMode + "; btl_queue:" + BTL.Baetylus.nCurrentDeviceBufferCount, 5);
                 (new Logger()).WriteDebug3("composite disposed: " + nID);
             }
         }
     }
     catch (Exception ex)
     {
         (new Logger()).WriteError(ex);
     }
     base.Dispose();
 }
コード例 #4
0
ファイル: PixelsMap.cs プロジェクト: ratsil/bethe.helpers
		public void Merge(List<PixelsMap> aPMs)
		{
            if (null == aPMs)
                throw new Exception("PixelsMap array is null");
            
            //ConsistencyCheck();
            if (0 < aPMs.Count)
            {
                List<PixelsMap> aPMsActual = new List<PixelsMap>();
				DisCom.MergeInfo cMergeInfo = new DisCom.MergeInfo();
				List<DisCom.LayerInfo> aLayerInfos = new List<DisCom.LayerInfo>();
				DisCom.LayerInfo cLayerInfo;

				cMergeInfo.nBackgroundSize = _stArea.nWidth * _stArea.nHeight;
				cMergeInfo.nBackgroundWidth = _stArea.nWidth;
				cMergeInfo.nBackgroundHight = _stArea.nHeight;
				cMergeInfo.nBackgroundAlphaType = (byte)eAlpha;

                for (int nIndx = 0; nIndx < aPMs.Count; nIndx++)
                {
					lock (aPMs[nIndx]._cSyncRoot)
					{
						if (aPMs[nIndx]._bDisposed)
							continue;
						aPMs[nIndx]._bProcessing = true;
					}
					cLayerInfo = aPMs[nIndx].Intersect(new Area(0, 0, _stArea.nWidth, _stArea.nHeight)); //не stBase т.к. нужны относительные координаты, а не абсолютные
					if (0 > (cLayerInfo.nBackgroundStop - cLayerInfo.nBackgroundStart))  //если пересечения FG и BG нет.....
					{
						aPMs[nIndx].Dispose();
						continue;
					}
                    aPMsActual.Add(aPMs[nIndx]);
					aLayerInfos.Add(cLayerInfo);
                }

                if (0 < aPMsActual.Count)
                {
					cMergeInfo.nLayersQty = (ushort)(aLayerInfos.Count + 1);
					cMergeInfo.aLayerInfos = aLayerInfos.ToArray();
#if CUDA
					if (bCUDA)
					{
						Command cCmd = new Command(Command.ID.Merge, this);
						cCmd.ahParameters.Add(typeof(List<PixelsMap>), aPMsActual);
						cCmd.ahParameters.Add(typeof(DisCom.MergeInfo), cMergeInfo);
						_aqCommands.Enqueue(cCmd);
						cCmd.cMRE.WaitOne();
						return;
					}
#endif

					List<byte[]> aDPs = new List<byte[]>();

					if (1 > _nID)
						throw new Exception("background PixelsMap have to be allocated for Merge");

					aDPs.Add(_aBytes);
					for (int nIndx = 0; nIndx < aPMsActual.Count; nIndx++)
						aDPs.Add(aPMsActual[nIndx]._aBytes);
					DisCom cDisCom = new DisCom();
					Logger.Timings cTiming = new helpers.Logger.Timings("BTL:pixelmap:");
					cDisCom.FrameMerge(cMergeInfo, aDPs);
					cTiming.Stop("merge > 35", 35);
					cDisCom.Dispose();

					for (int nIndx = 0; nIndx < aPMsActual.Count; nIndx++)
					{
						lock (aPMsActual[nIndx]._cSyncRoot)
							aPMsActual[nIndx]._bProcessing = false;
						aPMsActual[nIndx].Dispose();
					}
				}
            }
        }
コード例 #5
0
ファイル: Chat.cs プロジェクト: ratsil/bethe.ingenie
        private void Worker(object cState)
        {
            _bStopped   = false;
            _bWorkerEnd = false;
            try
            {
                (new Logger()).WriteDebug3("chat started");
                if (null == _cSMSChat)
                {
                    _bWorkerEnd = true;
                    return;
                }
                Logger.Timings       cTimings     = new helpers.Logger.Timings("chat:Worker");
                Queue <ChatInOut>    aqChatInOuts = null;
                DateTime             dtBase       = DateTime.Now;
                DBInteract           cDBI         = null;
                PlaylistItem         cCurrentPLI  = null;
                Queue <PlaylistItem> aqCU         = null;
                try
                {
                    cDBI = new DBInteract();

                    while (!_bStopped && null == cCurrentPLI)
                    {
                        //if (DateTime.Now > dtNextTimeLog_Worker)
                        //{
                        //    (new Logger()).WriteNotice("Worker: I'm HERE! [hash:" + this.GetHashCode() + "]");
                        //    dtNextTimeLog_Worker = DateTime.Now.AddMinutes(1);
                        //}
                        aqCU = cDBI.ComingUpGet(0, 1);
                        if (0 < aqCU.Count)
                        {
                            cCurrentPLI  = aqCU.Dequeue();
                            aqChatInOuts = cDBI.ChatInOutsGet(cCurrentPLI.cAsset);
                            //							aqChatInOuts = cDBI.ChatInOutsGet(helpers.replica.mam.Asset.Load(3261));
                            if (0 < aqChatInOuts.Count)
                            {
                                dtBase = cCurrentPLI.dtStartReal;
                            }
                            else
                            {
                                aqChatInOuts = null;
                            }
                        }
                        else
                        {
                            Thread.Sleep(300);
                        }
                    }
                }
                catch (Exception ex)
                {
                    (new Logger()).WriteError(ex);
                }


                // ==========================================================================================================
                //dtBase = DateTime.Now;
                //aqChatInOuts = new Queue<ChatInOut>();
                //aqChatInOuts.Enqueue(new ChatInOut(1176, new TimeRange(400, 900)));
                //aqChatInOuts.Enqueue(new ChatInOut(1176, new TimeRange(1300, 1600)));
                //aqChatInOuts.Enqueue(new ChatInOut(1176, new TimeRange(2200, 3500)));
                // ==========================================================================================================


                if (null == aqChatInOuts)
                {
                    aqChatInOuts = new Queue <ChatInOut>();
                    aqChatInOuts.Enqueue(new ChatInOut(-1, 1, int.MaxValue));
                }

                ChatInOut cChatInOut;
                DateTime  dtStop;
                int       nMSStartDelay;
                bool      bIsAir = cDBI.IsThereAnyStartedLiveBroadcast();
                (new Logger()).WriteDebug2("ChatLogStartAdd [isair=" + bIsAir + "][type=" + _cPreferences.eBroadcastType + "][release=" + _cPreferences.bMessagesRelease + "]");
                if (_cPreferences.bMessagesRelease && !(_cPreferences.eBroadcastType == Preferences.BroadcastType.linear && bIsAir) && !(_cPreferences.eBroadcastType == Preferences.BroadcastType.live && !bIsAir))
                {
                    bool bOk = cDBI.ChatLogStartAdd(DateTime.Now.AddSeconds(4));
                    (new Logger()).WriteNotice("ChatLogStartAdd - " + bOk);
                    _bChatWasAddedToLogsOnStart = true;
                }
                else
                {
                    _bChatWasAddedToLogsOnStart = false;
                }

                ThreadPool.QueueUserWorkItem(WorkerSMS);

                while (!_bStopped && 0 < aqChatInOuts.Count)
                {
                    //if (DateTime.Now > dtNextTimeLog_Worker)
                    //{
                    //    (new Logger()).WriteNotice("Worker: I'm HERE! [hash:" + this.GetHashCode() + "]");
                    //    dtNextTimeLog_Worker = DateTime.Now.AddMinutes(1);
                    //}
                    cChatInOut = aqChatInOuts.Dequeue();
                    if (TimeSpan.MaxValue > cChatInOut.cTimeRange.tsOut)
                    {
                        dtStop = dtBase.Add(cChatInOut.cTimeRange.tsOut);
                    }
                    else
                    {
                        dtStop = DateTime.MaxValue;
                    }

                    if (DateTime.Now > dtStop.AddSeconds(-20))
                    {
                        continue;
                    }

                    if (_cSMSChat.bReleased)
                    {
                        _cSMSChat.Init();
                    }
                    nMSStartDelay = (int)dtBase.Add(cChatInOut.cTimeRange.tsIn).Subtract(DateTime.Now).TotalMilliseconds;
                    if (0 < nMSStartDelay)
                    {
                        Thread.Sleep(nMSStartDelay);
                    }
                    _cSMSChat.Start();

                    //#if UNLIMIT
                    //while (!_bStopped)
                    //#else
                    //while (!_cSMSChat.IsChatTerminating)
                    //#endif
                    bool bNotFirst = false;
                    while (ChatMustGoOn())
                    {
                        //if (DateTime.Now > dtNextTimeLog_Worker)
                        //{
                        //    (new Logger()).WriteNotice("Worker: I'm HERE! [hash:" + this.GetHashCode() + "]");
                        //    dtNextTimeLog_Worker = DateTime.Now.AddMinutes(1);
                        //}
                        if (_cPreferences.eBroadcastType == Preferences.BroadcastType.linear && DateTime.Now > dtStop)
                        {
                            break;
                        }
                        if (4 > _cSMSChat.QueueLength)   //  4>
                        {
                            lock (_aqSMSs)
                            {
                                if (0 < _aqSMSs.Count)
                                {
                                    bNotFirst = true;
                                    _cSMSChat.MessagesAdd(_aqSMSs);
                                    _aqSMSs.Clear();
                                }
                                if (bNotFirst && 4 > _cSMSChat.QueueLength && _cPreferences.cRoll.nUseHistorySMS > 0)
                                {
                                    _cSMSChat.MessagesAdd(GetHistorySMSs(5));
                                }
                            }
                        }

                        //GC.Collect
                        Thread.Sleep(500);
                    }
                    (new Logger()).WriteDebug3("chat stopped" + (DateTime.MaxValue > dtStop ? ":" + dtStop.ToStr() : ""));
                    lock (_oLock)
                    {
                        if (null != _cSMSChat)
                        {
                            _cSMSChat.Stop();
                            _cSMSChat.Release();     // ушла в stop()
                        }
                    }
                    (new Logger()).WriteDebug4("return");
                }
            }
            catch (Exception ex)
            {
                (new Logger()).WriteError(ex);
                try
                {
                    _cSMSChat.Stop();
                    //_cSMSChat.Release();    ушла в stop()
                }
                catch (Exception ex1)
                {
                    (new Logger()).WriteError("catch: ", ex1);
                }
            }
            finally
            {
                _bWorkerEnd = true;
                try
                {
                    Stop();
                    //if (!_bStopped && null != Stopped)
                    //    Stopped(this);                     ушла в stop()
                    //_bStopped = true;                      ушла в stop()
                    (new Logger()).WriteNotice("chat worker stopped");
                }
                catch (Exception ex)
                {
                    (new Logger()).WriteError("finally: ", ex);
                }
            }
        }