Class to which the video output is written to. The buffer of this class is then read by StreamingHandler continuously.
| 150 | ############################# |
| 151 | |
| 152 | class StreamingOutput(object): |
| 153 | ''' |
| 154 | Class to which the video output is written to. |
| 155 | The buffer of this class is then read by StreamingHandler continuously. |
| 156 | ''' |
| 157 | def __init__(self): |
| 158 | self.frame = None |
| 159 | self.buffer = io.BytesIO() |
| 160 | self.condition = Condition() |
| 161 | |
| 162 | def write(self, buf): |
| 163 | if buf.startswith(b'\xff\xd8'): |
| 164 | # New frame, copy the existing buffer's content and notify all |
| 165 | # clients it's available |
| 166 | self.buffer.truncate() |
| 167 | with self.condition: |
| 168 | self.frame = self.buffer.getvalue() |
| 169 | self.condition.notify_all() |
| 170 | self.buffer.seek(0) |
| 171 | return self.buffer.write(buf) |
| 172 | |
| 173 | class StreamingHandler(server.BaseHTTPRequestHandler): |
| 174 | ''' |