public void Play(MediaFrame frame) { if (!_isworking) { return; } lock (_queue) { if (_lastReceiveFrameTick < frame.nTimetick) { _lastReceiveFrameTick = frame.nTimetick; } if (frame.nIsAudio == 1 && IsAudioPlay) { _queue.Enqueue(frame); } if (frame.nIsAudio == 0 && IsVideoPlay) { if (hasKey || frame.nIsKeyFrame == 1) { _queue.Enqueue(frame); hasKey = true; } } if (!IsReadPlay) { _cache.Add(frame); } } }
private AQueue <int> InitQueue() { AQueue <int> queue = new AQueue <int>(); queue.Enqueue(1); queue.Enqueue(2); return(queue); }
private static void ThreadCompleted(TimerExecuter executer) { _ = _DEBUG; // bool flag = 1 == 0; lock (_queueCompleteThreads) { _queueCompleteThreads.Enqueue(executer); } }
public ObjectPool(T[] arr) { _min = arr.Length; _max = arr.Length; lock (_qIdle) { foreach (T @object in arr) { Item item = new Item(this, @object); _qIdle.Enqueue(item); _count++; } } }
private static void Thread1() { while (true) { bool flag = true; long tickCount = TickCount; lock (_dicTimers) { foreach (TimerInfo value in _dicTimers.Values) { lock (value.SyncObject) { if (!value.IsReady && !value.IsRuning && tickCount - value.LastEndTime > value.Interval) { value.IsReady = true; _queueTimers.Enqueue(value); } } } } long tickCount2 = TickCount; if (tickCount2 - tickCount < 5) { Thread.Sleep(5); } } }
public void Play(MediaFrame frame) { if (!_isworking) { return; } lock (_queue) { _queue.Enqueue(frame); } }
private void _Write(byte[] bs, int index, int count) { MemoryStream memoryStream = new MemoryStream(bs, index, count); memoryStream.Position = 0L; lock (_queueMS.GetLock()) { _queueMS.Enqueue(memoryStream); _size += count; } }
public override void Play(MediaFrame frame) { if (!_isworking) { return; } lock (_queue) { _queue.Enqueue(frame); } _lastMediaFrameTime = frame.NTimetick; }
protected virtual void NewMediaFrame(MediaFrame frame) { if (!EnabledFrameSequence) { //不排序 OnNewMediaFrame(frame); } else { //排序 if (frame.nIsAudio == 0) { _qVideoMediaFrame.Enqueue(frame); } else if (frame.nIsAudio == 1) { _qAudioMediaFrame.Enqueue(frame); } while (true) { if (_qVideoMediaFrame.Count > 0 && _qAudioMediaFrame.Count > 0) { var v = _qVideoMediaFrame.Peek(); var a = _qAudioMediaFrame.Peek(); if (v.nTimetick < a.nTimetick) { v = _qVideoMediaFrame.Dequeue(); OnNewMediaFrame(v); } else { a = _qAudioMediaFrame.Dequeue(); OnNewMediaFrame(a); } } else if (_qVideoMediaFrame.Count > 5) { var v = _qVideoMediaFrame.Dequeue(); OnNewMediaFrame(v); } else if (_qAudioMediaFrame.Count > 50) { var a = _qAudioMediaFrame.Dequeue(); OnNewMediaFrame(a); } else { break; } } } }
private MediaFrame AnalyzeNewFrame(PESPacket pes, bool isAudio) { MediaFrame result = null;; if (!isAudio) { var esdata = pes.PES_Packet_Data; if (_listVideoPES.Count > 0 && esdata[0] == 0 && esdata[1] == 0 && esdata[2] == 0 && esdata[3] == 1) { var stream = new MemoryStream(); foreach (var item in _listVideoPES) { stream.Write(item.PES_Packet_Data, 0, item.PES_Packet_Data.Length); } long tick = _listVideoPES.FirstOrDefault().GetVideoTimetick(); esdata = stream.ToArray(); var frame = CreateVideoMediaFrame(esdata, tick); if (frame != null) { result = frame; _queueFrame.Enqueue(frame); } _listVideoPES.Clear(); } _listVideoPES.Add(pes); } else { //不处理音频 //var esdata = pes.PES_Packet_Data; //if (_listAudioPES.Count > 0 && esdata[0] == 0xFF && (esdata[1] & 0xF0) == 0xF0) { // var stream = new MemoryStream(); // foreach (var item in _listAudioPES) { // stream.Write(item.PES_Packet_Data, 0, item.PES_Packet_Data.Length); // } // long tick = _listAudioPES.FirstOrDefault().GetAudioTimetick(); // esdata = stream.ToArray(); // var frame = CreateAudioMediaFrame(esdata, tick); // _queueFrame.Enqueue(frame); // _listAudioPES.Clear(); //} //_listAudioPES.Add(pes); } return(result); }
private static TimerExecuter GetIdleThread() { if (_queueIdleThreads.Count > 0) { return(_queueIdleThreads.Dequeue()); } while (_queueCompleteThreads.Count > 0) { TimerExecuter timerExecuter = _queueCompleteThreads.Peek(); timerExecuter = _queueCompleteThreads.Dequeue(); _queueIdleThreads.Enqueue(timerExecuter); } if (_queueIdleThreads.Count > 0) { return(_queueIdleThreads.Dequeue()); } if (_timerThreads.Count <= _maxThread) { return(CreateThread()); } return(null); }
private void Completed(DespatcheStateModel model) { if (!_isDisposed) { _isBeging = false; _lasyAsyncResult = null; lock (_lockObj) { if (_queueCompletedHandleInvoke == null) { _queueCompletedHandleInvoke = new AQueue <DespatcheStateModel>(); } _queueCompletedHandleInvoke.Enqueue(model); if (!_CompletedHandle_Invokeing) { model = _queueCompletedHandleInvoke.Dequeue(); _CompletedHandle_Invokeing = true; _CompletedHandle.BeginInvoke(model, _CompletedHandle_AsyncCallback, null); } } } }
private void PlayBackward(Stack <MediaFrame> stack) { Stack <MediaFrame> yuvStack = new Stack <MediaFrame>(); while (_queueRewindStack.Count > 3) { Thread.Sleep(10); } if (_PlayBackwardResetPos) { return; } while (stack != null && stack.Count > 0 && !_PlayBackwardResetPos) { var frame = _stackRewindFrame.Pop(); if (!CheckInit(frame)) { continue; } var bufferData = new byte[_yuvDataBuffer.Length]; byte[] yuv = _ffimp.VideoDec(frame.GetData(), bufferData); if (yuv != null) { var mf = new MediaFrame() { NTimetick = frame.NTimetick, Size = yuv.Length, }; mf.SetData(yuv); yuvStack.Push(mf); } } if (!_PlayBackwardResetPos) { _queueRewindStack.Enqueue(yuvStack); } }