static private void WorkerEvents() { Tuple <EventDelegate, Effect> cEvent; Logger.Timings cTimings = new Logger.Timings("effect_WorkerEvents"); while (true) { try { cEvent = _aqEvents.Dequeue(); cTimings.TotalRenew(); cEvent.Item1(cEvent.Item2); (new Logger()).WriteDebug3("event sent e [hc = " + cEvent.Item2.nID + "][" + cEvent.Item1.Method.Name + "][events_queue=" + _aqEvents.nCount + "]"); //GC.Collect cTimings.Stop("work too long", "", 5); } catch (System.Threading.ThreadAbortException) { break; } catch (Exception ex) { (new Logger()).WriteError(ex); } } }
public void Close() { lock (_oCloseLock) { if (_bClosed) { return; } _bClosed = true; } (new Logger()).WriteDebug3("in " + GetHashCode()); Logger.Timings cTimings = new Logger.Timings("video:file:"); Baetylus.PixelsMapDispose(_cPMDuo, true); _aAudioMap = null; cTimings.Restart("pm disposing"); if (null != _cFile) { _cFile.Dispose(); } cTimings.Stop("close > 20", "file disposing", 20); (new Logger()).WriteDebug4("out"); }
public void CopyIn(IntPtr pSource, uint nBytesQty) { //(new Logger()).WriteDebug2("pixelmap copyin(ptr) cuda=" + bCUDA + "[bytes_qty=" + _nBytesQty + "]"); if (1 > nBytesQty) { throw new Exception("bytes qty must be more than zero"); } #if CUDA if (stMergingMethod.eDeviceType > 0) { Command cCmd = new Command(Command.ID.CopyIn, this); cCmd.ahParameters.Add(typeof(IntPtr), pSource); _nBytesQty = nBytesQty; _ahMergingHash_CommandsQueue[stMergingMethod.nHash].Enqueue(cCmd); cCmd.cMRE.WaitOne(); if (null != _cException) { throw _cException; } if (_nID == 0) { (new Logger()).WriteError(new Exception("got 0 in id after copy in")); } return; } #endif Logger.Timings cTimings = new Logger.Timings("btl:pixelsmap:copyin:"); if (null == _aBytes) { Allocate(); } cTimings.Restart("allocate"); Marshal.Copy(pSource, _aBytes.aBytes, 0, (int)nBytesQty); cTimings.Stop("copyin > 40ms", "marshal_copy", 40); }
override public void Dispose() { Logger.Timings cTimings = new Logger.Timings("btl:effect_v_a:dispose:"); if (null != _cEffectVideo) { _cEffectVideo.Dispose(); } if (null != _cEffectAudio) { _cEffectAudio.Dispose(); } base.Dispose(); cTimings.Stop("dispose >20ms [" + nID + "]", 20); }
protected Video() : base(EffectType.Video) { try { _oLock = new object(); (new Logger()).WriteDebug3("in"); _cFile = null; stArea = Baetylus.Helper.stCurrentBTLArea; cTimings = new Logger.Timings("btl:video"); } catch { Fail(); throw; } }
internal Animation(EffectType eType) : base(eType) { try { nLoopsQty = 1; nLoopCurrent = 0; bKeepAlive = true; nPixelAspectRatio = 0; _cTimings = new helpers.Logger.Timings("animation"); _bDisposed = false; _oLock = new object(); bTurnOffQueue = false; } catch { Fail(); throw; } }
private File() { _oWorkerLock = new object(); _oCloseLock = new object(); _oCacheLock = new object(); _sFolder = null; _aFiles = null; _bIsDirectory = null; nFrameCurrent = 0; nFramesTotal = 0; _stBitmapSize = Rectangle.Empty; stDimensionsResized = Size.Empty; bEOF = false; //_aCache = null; nQueueSize = Preferences.nQueueAnimationLength; _nQueueLength = -1; _bIsClosed = false; _bThreadJoined = false; _cTimings = new helpers.Logger.Timings("animation.file"); _cTimings2 = new helpers.Logger.Timings("animation.file.worker"); _bThAbort = false; }
private File() { _sFile = null; if (ffmpeg.net.File.Input.nCacheSizeCommon == 0) { ffmpeg.net.File.Input.nCacheSizeCommon = Preferences.nQueueFfmpegLength; ffmpeg.net.File.Input.nBlockSizeCommon = Preferences.nQueuePacketsLength; ffmpeg.net.File.Input.nDecodingThreads = Preferences.nDecodingThreads; ffmpeg.net.File.Input.sDebugFolder = Preferences.sDebugFolder; ffmpeg.net.File.Input.nFreezeTimeoutPacketsGetSeconds = (int)Preferences.tsNextFrameTimeout.TotalSeconds; } nFramesTotal = ulong.MaxValue; nFrameCurrentVideo = 0; nFrameCurrentAudio = 0; aAudioChannels = null; //комментарии в IAudio cTimings = new Logger.Timings("btl:video:file"); if (ffmpeg.net.File.Input.nBTLBufferOneThird < 1) { ffmpeg.net.File.Input.nBTLBufferOneThird = BTL.Baetylus.nBufferOneThird; ffmpeg.net.File.Input.nBTLBufferTwoThird = BTL.Baetylus.nBufferTwoThird; } }
private void GetAndSortNextPacket() { Logger.Timings cTimings = new Logger.Timings(); _nPacketIndx++; // logging IntPtr pPacket; AVPacket stPacket; if (!_bFileEnd) { pPacket = Functions.av_malloc((uint)Marshal.SizeOf(typeof(AVPacket))); cTimings.Restart("allocation"); if (_cFormatCtx.PacketRead(pPacket) >= 0 && Functions.av_dup_packet(pPacket) >= 0) { stPacket = (AVPacket)Marshal.PtrToStructure(pPacket, typeof(AVPacket)); if (stPacket.stream_index == _nVideoStreamIndx) { _aqVideoPackets.Enqueue(pPacket); _nTotalVideoPackets++; } else if (stPacket.stream_index == _nAudioStreamIndx) { _aqAudioPackets.Enqueue(pPacket); _nTotalAudioPackets++; } else { Functions.av_free_packet(pPacket); Functions.av_freep(ref pPacket); } } else _bFileEnd = true; } cTimings.Stop("packets: >20ms", 20); }
private void FrameDecodeAudio() { if (null == _cFormatAudioTarget) throw new NotImplementedException("null == cFormatTarget"); //UNDONE нужно доделать возвращение сырых пакетов Logger.Timings cTimings = new Logger.Timings(); int nBufferSizeSource; if(null == _cFrameAudio) _cFrameAudio = new Frame(_cFormatAudio, _cFormatAudio.nBufferSize); Frame cSamplesTarget = null; Frame cFrame; if (1 > _aqAudioFramesFree.Count) //ротация кадров { cFrame = new Frame(_cFormatAudioTarget, _cFormatAudioTarget.nBufferSize / _nFPS); cFrame.Disposing += new Frame.DisposingDelegate(cFrameAudio_Disposing); } else lock (_aqAudioFramesFree) cFrame = _aqAudioFramesFree.Dequeue(); int nBytesCapacity = 0; int nBytesOffset = 0; byte[] aPacketBytes; int nLength = 0; AVPacket stPacket; if (null != _aBytesRemainder) { Array.Copy(_aBytesRemainder, 0, cFrame.aBuffer, 0, _aBytesRemainder.Length); nBytesOffset += _aBytesRemainder.Length; _aBytesRemainder = null; } while (cFrame.nLength > nBytesOffset) { aPacketBytes = null; if (NULL == _pPacketAudioDub) { _pPacketAudioDub = Functions.avcodec_alloc_frame(); _stPacketAudio = (AVPacket)Marshal.PtrToStructure(_pPacketAudioDub, typeof(AVPacket)); } cTimings.Restart("allocation"); while (true) { // NOTE: the audio packet can contain several frames while (_stPacketAudio.size > 0) { nBufferSizeSource = _cFrameAudio.nLengthBuffer; Marshal.StructureToPtr(_stPacketAudio, _pPacketAudioDub, true); nLength = Functions.avcodec_decode_audio3(_cFormatAudio.pAVCodecContext, _cFrameAudio.aBuffer, ref nBufferSizeSource, _pPacketAudioDub); cTimings.CheckIn("decode"); if (nLength < 0) { _stPacketAudio.size = 0; break; } _stPacketAudio.data += nLength; _stPacketAudio.size -= nLength; nLength = nBufferSizeSource; if (nLength <= 0) continue; cTimings.Restart("frame"); _cFrameAudio.nLength = nLength; cSamplesTarget = _cFormatAudio.Transform(_cFormatAudioTarget, _cFrameAudio); aPacketBytes = cSamplesTarget.aBytes; cTimings.Restart("transform"); break; } if (null != aPacketBytes) break; if (NULL != _pPacketAudio) { Functions.av_free_packet(_pPacketAudio); Functions.av_freep(ref _pPacketAudio); cTimings.Restart("packet free"); } while (!_bFileEnd && 1 > _aqAudioPackets.Count) { lock (_cSyncRoot) GetAndSortNextPacket(); } if (_bFileEnd && 1 > _aqAudioPackets.Count) break; lock (_cSyncRoot) _pPacketAudio = _aqAudioPackets.Dequeue(); stPacket = (AVPacket)Marshal.PtrToStructure(_pPacketAudio, typeof(AVPacket)); _stPacketAudio.data = stPacket.data; _stPacketAudio.size = stPacket.size; cTimings.Restart("packets"); } if (null == aPacketBytes) throw new Exception("audio packet is null"); nBytesCapacity = aPacketBytes.Length; if (cFrame.nLength < nBytesOffset + aPacketBytes.Length) { nBytesCapacity = cFrame.nLength - nBytesOffset; _aBytesRemainder = new byte[aPacketBytes.Length - nBytesCapacity]; Array.Copy(aPacketBytes, nBytesCapacity, _aBytesRemainder, 0, _aBytesRemainder.Length); } Array.Copy(aPacketBytes, 0, cFrame.aBuffer, nBytesOffset, nBytesCapacity); nBytesOffset += nBytesCapacity; cTimings.Restart("accumulation"); } cTimings.Stop("frame:decode:audio: >40ms", 40); lock (_aqAudioFrames) _aqAudioFrames.Enqueue(cFrame); }
private void FrameDecodeVideo() { if (null == _cFormatVideoTarget) throw new NotImplementedException("null == cFormatTarget"); //UNDONE нужно доделать возвращение сырых пакетов Logger.Timings cTimings = new Logger.Timings(); int nVideoFrameFinished = 0; IntPtr pPacketNext = NULL; while (true) { while (NULL == pPacketNext) { while (1 > _aqVideoPackets.Count) { if (_bFileEnd) throw new Exception("file ended"); lock (_cSyncRoot) GetAndSortNextPacket(); } pPacketNext = _aqVideoPackets.Peek(); } cTimings.Restart("packets"); if (null == _cFrameVideo) _cFrameVideo = new Frame(_cFormatVideo, _cFormatVideo.nBufferSize); try { int nError = Functions.avcodec_decode_video2(_cFormatVideo.pAVCodecContext, _cFrameVideo.AVFrameGet(), ref nVideoFrameFinished, pPacketNext); Functions.av_free_packet(pPacketNext); Functions.av_freep(ref pPacketNext); } catch (Exception ex) { (new Logger()).WriteError(ex); } _aqVideoPackets.Dequeue(); cTimings.Restart("decode"); if (0 < nVideoFrameFinished) { Frame cFrame; if (1 > _aqVideoFramesFree.Count) //ротация кадров { cFrame = new Frame(_cFormatVideoTarget, _cFormatVideoTarget.nBufferSize); cFrame.Disposing += new Frame.DisposingDelegate(cFrameVideo_Disposing); } else lock (_aqVideoFramesFree) cFrame = _aqVideoFramesFree.Dequeue(); //Functions.avpicture_fill(_pAVFrameTarget, cFrame.aBytes, _cFormatVideoTarget.ePixelFormat, _cFormatVideoTarget.nWidth, _cFormatVideoTarget.nHeight); _cFormatVideo.Transform(_cFormatVideoTarget, _cFrameVideo, cFrame); // lock inside! lock (_aqVideoFrames) _aqVideoFrames.Enqueue(cFrame); if (_bDoWritingFrames) { if (null != cFrame) { byte[] aBytes = new byte[_cFormatVideoTarget.nBufferSize]; System.Runtime.InteropServices.Marshal.Copy(cFrame.p, aBytes, 0, (int)_cFormatVideoTarget.nBufferSize); lock (_aqWritingFrames) _aqWritingFrames.Enqueue(aBytes); } } cTimings.Restart("transform"); break; } } cTimings.Stop("frame:decode:video: >40ms", 40); }
public Frame FrameNextAudioGet() { if (null == _aqAudioFrames) return null; Frame cRetVal = null; Logger.Timings cTimings = new Logger.Timings(); if (!_bFileEnd) { DateTime dtTimedOut = DateTime.MaxValue; while (!_bFileEnd && 1 > _aqAudioFrames.Count) { if (DateTime.MaxValue == dtTimedOut) { try { dtTimedOut = DateTime.Now.Add(tsTimeout); } catch { dtTimedOut = DateTime.MaxValue.AddTicks(-1); } (new Logger()).WriteDebug("frame:next:audio: queue is empty"); //logging } System.Threading.Thread.Sleep(10); if (DateTime.Now > dtTimedOut) throw new TimeoutException("audio queue is empty"); } } cTimings.Restart("frame waiting"); lock (_aqAudioFrames) { if (0 < _aqAudioFrames.Count) cRetVal = _aqAudioFrames.Dequeue(); cTimings.CheckIn("dequeue"); // logging } cTimings.Stop("frame:next:audio: >20ms", 20); return cRetVal; }