private void FixedFrameRate_Click(object sender, EventArgs e) { if (FixedFrameRate.Text == "固定帧率接收") //1024*512的bmp图片全速接收时能到64帧,数据速率大概是100.6M字节/秒,基本达到千兆网实际传输速度上限 { //实际应用中可能用不着这么高的帧率,所以可以用个定时器定时触发,限定一下帧率. FixedFrameRate.Text = "停止接收"; //这里timer设置的是40ms,实测帧率为21帧左右.设置30ms帧率能到32 FrameRateTimer.Start(); } else { FixedFrameRate.Text = "固定帧率接收"; FrameRateTimer.Stop(); } }
public void Update(int millisecs) { if (AnimationType == SpriteAnimationType.SingleFrame) { if (Completed == false) { Completed = true; } return; } //update frame rate timer FrameRateTimer.Update(millisecs); if (FrameRateTimer.Completed) { //are we at end of animation strip if (FrameCellIndex == (FrameCount - 1)) { //act according to the animation type if (AnimationType == SpriteAnimationType.NonLooping_ResetBackToStartingFrame) { //no reset of timer as this is where animation stops FrameCellIndex = 0; Completed = true; } else if (AnimationType == SpriteAnimationType.NonLooping_PauseOnEndFrame) { Completed = true; } else if (AnimationType == SpriteAnimationType.LoopingAnimation) { //reset back to cell zero and continue FrameCellIndex = 0; FrameRateTimer.Reset(); } } else { //keep going FrameCellIndex += 1; FrameRateTimer.Reset(); } } }
public void Reset() { FrameCellIndex = 0; Completed = false; FrameRateTimer.Reset(); }
// Handle attach to frame rate timer private void AttachToFrameRateTimer(int framesPerSecond) { lock (s_frameRateTimers) { FrameRateTimer timer; // Get static frame rate timer for given frames per second creating it if needed if (!s_frameRateTimers.TryGetValue(framesPerSecond, out timer)) { // Create a new frame rate timer which includes a high-precision timer for frame processing timer = new FrameRateTimer(framesPerSecond); // Add timer state for given rate to static collection s_frameRateTimers.Add(framesPerSecond, timer); } // Increment reference count and attach instance method "StartFramePublication" to static timer event list timer.AddReference(StartFramePublication); m_attachedToFrameRateTimer = true; } }
// Handle attach to frame rate timer private void AttachToFrameRateTimer(int framesPerSecond, int processingInterval) { Tuple<int, int> key = new Tuple<int, int>(Math.Min(framesPerSecond, 1000), processingInterval); lock (s_frameRateTimers) { if (!m_attachedToFrameRateTimer) { FrameRateTimer timer; // Get static frame rate timer for given frames per second creating it if needed if (!s_frameRateTimers.TryGetValue(key, out timer)) { // Create a new frame rate timer which includes a high-precision timer for frame processing timer = new FrameRateTimer(key.Item1, key.Item2); // Add timer state for given rate to static collection s_frameRateTimers.Add(key, timer); } // Increment reference count and attach instance method "StartFramePublication" to static timer event list timer.AddReference(StartFramePublication); m_attachedToFrameRateTimer = true; } } }