First commit

This commit is contained in:
2025-03-11 13:05:11 +01:00
commit 9ce295f085
14 changed files with 2491 additions and 0 deletions

27
queue.py Normal file
View File

@@ -0,0 +1,27 @@
from heapdict import heapdict
import time
import threading
class FrameQueue():
def __init__(self):
self.heap = heapdict()
self.age_interval = 5 # seconds
def push(self, frame, priority):
timestamp = time.time() # microsecond resolution
self.heap[timestamp] = (priority, timestamp, frame)
def pop(self):
p, f = self.heap.popitem()
self.age()
return f[2]
def age(self):
current_time = time.time()
for key in list(self.heap.keys()):
if current_time - key > self.age_interval:
self.heap[key][0] -= 1
def is_empty(self):
return len(self.heap) == 0