Browse Source

remove condition (don't block)

main
Hendrik Langer 4 years ago
parent
commit
a6520ae595
  1. 9
      raspberry/roberto/camera/camera_pi_new.py

9
raspberry/roberto/camera/camera_pi_new.py

@ -3,22 +3,18 @@ import time
import picamera import picamera
from .base_camera import BaseCamera from .base_camera import BaseCamera
from threading import Condition
class StreamingOutput(object): class StreamingOutput(object):
def __init__(self): def __init__(self):
self.frame = None self.frame = None
self.buffer = io.BytesIO() self.buffer = io.BytesIO()
self.condition = Condition()
def write(self, buf): def write(self, buf):
if buf.startswith(b'\xff\xd8'): if buf.startswith(b'\xff\xd8'):
# New frame, copy the existing buffer's content and notify all # New frame, copy the existing buffer's content and notify all
# clients it's available # clients it's available
self.buffer.truncate() self.buffer.truncate()
with self.condition:
self.frame = self.buffer.getvalue() self.frame = self.buffer.getvalue()
self.condition.notify_all()
self.buffer.seek(0) self.buffer.seek(0)
return self.buffer.write(buf) return self.buffer.write(buf)
@ -38,9 +34,6 @@ class Camera(BaseCamera):
camera.start_recording(output, format='mjpeg') camera.start_recording(output, format='mjpeg')
while True: while True:
with output.condition:
output.condition.wait()
frame = output.frame
#yield b'--FRAME\r\n' #yield b'--FRAME\r\n'
yield frame yield output.frame
#yield b'\r\n' #yield b'\r\n'

Loading…
Cancel
Save