Binary uplink takes audio chunks beside image frames (openpanel VS4)
This commit is contained in:
@@ -55,7 +55,7 @@ from fluksio.flow.devices import (
|
||||
presence,
|
||||
)
|
||||
from fluksio.flow.events import event_bus
|
||||
from fluksio.flow.messages import flow_of, qualify
|
||||
from fluksio.flow.messages import MEDIA_FAMILIES, DType, flow_of, qualify
|
||||
from fluksio.flow.pipeline import ValidationIssue
|
||||
from fluksio.flow.runs import RunRejected
|
||||
from fluksio.flow.schemas import (
|
||||
@@ -1322,8 +1322,9 @@ def media_frames(
|
||||
return frames
|
||||
|
||||
|
||||
#: What a device may say a frame is.
|
||||
_IMAGE_TYPE = re.compile(r"^image/[\w.+-]+$")
|
||||
#: What a device may say a frame is: a media type, parameters allowed
|
||||
#: (``audio/L16;rate=16000``).
|
||||
_MEDIA_TYPE = re.compile(r"^[\w.+-]+/[\w.+-]+(;[\w.+-]+=[\w.+-]+)*$")
|
||||
|
||||
|
||||
def parse_frame(data: bytes) -> tuple[dict[str, Any], bytes] | None:
|
||||
@@ -1353,8 +1354,8 @@ FRAME_REFUSALS = {
|
||||
"not_a_device": "only a device sends frames",
|
||||
"no_engine": "the engine is not running",
|
||||
"not_wired": "it names no message one of the device's ports publishes",
|
||||
"not_image": "the port it names is not wired as an image",
|
||||
"media_type": "its media type is not an image type",
|
||||
"not_media": "the port it names is not wired as an image or audio",
|
||||
"media_type": "its media type does not match its port",
|
||||
"too_large": "it is larger than MAX_FRAME_BYTES",
|
||||
"undeclared": "no flow declares its message",
|
||||
"refused": "its message refused the value",
|
||||
@@ -1370,8 +1371,8 @@ def ingest_frame(app: Any, device: DeviceDef, data: bytes) -> str:
|
||||
The same frame over HTTP is two requests, each authenticated: the upload,
|
||||
then the publish. Here the socket was authenticated once, at its
|
||||
handshake, and the frame is held and published in one step. Only a
|
||||
message one of the device's own ``in`` ports is wired to, as an ``image``,
|
||||
and the value is credited to the device node holding that port, as an
|
||||
message one of the device's own ``in`` ports is wired to, as an ``image``
|
||||
or an ``audio`` chunk, and the value is credited to the device node holding that port, as an
|
||||
HTTP publish is. The frame is named after that message.
|
||||
"""
|
||||
cap = settings.MAX_FRAME_BYTES
|
||||
@@ -1397,10 +1398,12 @@ def ingest_frame(app: Any, device: DeviceDef, data: bytes) -> str:
|
||||
)
|
||||
if binding is None:
|
||||
return "not_wired"
|
||||
if binding.dtype != "image":
|
||||
return "not_image"
|
||||
if binding.dtype not in (DType.IMAGE, DType.AUDIO):
|
||||
return "not_media"
|
||||
media_type = str(header.get("media_type") or "")
|
||||
if not _IMAGE_TYPE.match(media_type):
|
||||
if not _MEDIA_TYPE.match(media_type) or not media_type.startswith(
|
||||
MEDIA_FAMILIES[DType(binding.dtype)]
|
||||
):
|
||||
return "media_type"
|
||||
reference = store.put([payload], name=name, media_type=media_type, volatile=True)
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user