public void Should_Enqueue_Two_Items_And_Peek_First_Item_Test() { int expectedValue = 1; int expectedCount = 2; AQueue <int> queue = InitQueue(); Assert.AreEqual(queue.Peek(), expectedValue); Assert.AreEqual(queue.Count, expectedCount); }
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 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 PlayThread() { bool _needBuffer = BuffTime > 0; bool _needSleep = false; while (_isworking) { lock (_queue) { if (_queue.Count > 0 && !_needBuffer && !_isPaused) { var frame = _queue.Dequeue(); if (_firstFrameTime == 0) { _firstFrameTime = frame.nTimetick; } if (_startPlayTick == 0) { _startPlayTick = Environment.TickCount; } if (frame.nIsAudio == 0) { if (_firstVideoFrameTime == 0) { _firstVideoFrameTime = frame.nTimetick; } } else if (frame.nIsAudio == 1 && (_vp.IsPlaying || _IgnoreVideoPlay) && ForwardPlay) { if (_firstAudioFrameTime == 0) { _firstAudioFrameTime = frame.nTimetick; } } if (_firstVideoFrameTime != 0) { _vp.SyncPlayTime(_firstVideoFrameTime + (int)((Environment.TickCount - _startPlayTick) * 1)); } if (_firstAudioFrameTime != 0) { _ap.SyncPlayTime(_firstAudioFrameTime + (int)((Environment.TickCount - _startPlayTick) * 1)); } if (frame.nIsAudio == 0) { _vp.Play(frame); } else if (frame.nIsAudio == 1 && (_vp.IsPlaying || _IgnoreVideoPlay) && ForwardPlay) { _ap.Play(frame); } _needSleep = false; } else { if (!_isPaused) { if (_firstVideoFrameTime != 0) { _vp.SyncPlayTime(_firstVideoFrameTime + (int)((Environment.TickCount - _startPlayTick) * 1)); } if (_firstAudioFrameTime != 0) { _ap.SyncPlayTime(_firstAudioFrameTime + (int)((Environment.TickCount - _startPlayTick) * 1)); } if (_queue.Count > 0 && _needBuffer) { var mf = _queue.Peek(); if (_lastReceiveFrameTick - mf.nTimetick > BuffTime * 1000) { _needBuffer = false; } } } _needSleep = true; } } if (_needSleep) { Thread.Sleep(10); } } }