txlyre 7 luni în urmă
părinte
comite
0c2c5cd247
1 a modificat fișierele cu 12 adăugiri și 10 ștergeri
  1. 12 10
      main.py

+ 12 - 10
main.py

@@ -240,16 +240,17 @@ def sample(source, source_type, multiplier=1):
     return data
 
 
-def video2_extractor(q, data):
-    data = extract_lsbs(data)
-    data = whiten(data)
+def video2_extractor(q, q2):
+    while True:
+        data = extract_lsbs(q2.get())
+        data = whiten(data)
 
-    logger.info(f"Sample ready: {len(data)}b.")
+        logger.info(f"Sample ready: {len(data)}b.")
 
-    q.put(data)
+        q.put(data)
 
 
-def video2_sampler(q, source):
+def video2_sampler(q, q2, source):
     with Device.from_id(abs(int(source))) as device:
         device.set_format(
             1,
@@ -263,9 +264,7 @@ def video2_sampler(q, source):
             new = time.monotonic()
 
             if new - last > 10:
-                threading.Thread(
-                    target=video2_extractor, args=(q, bytes(frame))
-                ).start()
+                q2.put(bytes(frame))
 
                 last = new
 
@@ -355,7 +354,10 @@ if __name__ == "__main__":
     )
 
     if args.source_type == "linuxvideo":
-        threading.Thread(target=video2_sampler, args=(q, args.source)).start()
+        q2 = queue.Queue()
+
+        threading.Thread(target=video2_sampler, args=(q, 12, args.source)).start()
+        threading.Thread(target=video2_extractor, args=(q, q2)).start()
     else:
         threading.Thread(
             target=puller, args=(q, args.source, args.source_type, args.multiplier)