mirror of
https://github.com/This-null/flexcam.git
synced 2026-09-03 07:53:51 +08:00
Android (Kotlin/CameraX) MJPEG server + Python desktop app (pywebview UI) feeding OBS Virtual Camera. Hybrid USB/WiFi with auto-connect and failover, front/back switch, auto-rotate, foreground service, tray, Discord rich presence, 10 languages, and a prebuilt APK.
29 lines
785 B
Python
29 lines
785 B
Python
class MjpegParser:
|
|
SOI = b"\xff\xd8"
|
|
EOI = b"\xff\xd9"
|
|
|
|
def __init__(self):
|
|
self._buf = bytearray()
|
|
self._ready = []
|
|
|
|
def feed(self, chunk: bytes) -> None:
|
|
self._buf.extend(chunk)
|
|
while True:
|
|
start = self._buf.find(self.SOI)
|
|
if start < 0:
|
|
if len(self._buf) > 2:
|
|
del self._buf[:-1]
|
|
return
|
|
end = self._buf.find(self.EOI, start + 2)
|
|
if end < 0:
|
|
if start > 0:
|
|
del self._buf[:start]
|
|
return
|
|
end += 2
|
|
self._ready.append(bytes(self._buf[start:end]))
|
|
del self._buf[:end]
|
|
|
|
def frames(self):
|
|
while self._ready:
|
|
yield self._ready.pop(0)
|