Skip to content

Commit

Permalink
Merge pull request #833 from insight-platform/810-support-videoframeb…
Browse files Browse the repository at this point in the history
…atch-data-in-the-buffer-adapter

Updating Client SDK to support batch processing
  • Loading branch information
placccebo authored Sep 3, 2024
2 parents ae95645 + 18951fa commit 8c24d31
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 67 deletions.
12 changes: 12 additions & 0 deletions docs/source/advanced_topics/10_client_sdk.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Sources ingest frames and their metadata to a running module.
import time
from savant_rs import init_jaeger_tracer
from savant_rs.primitives import VideoFrameBatch, VideoFrameContent
from savant.client import JaegerLogProvider, JpegSource, SourceBuilder
# Initialize Jaeger tracer to send metrics and logs to Jaeger.
Expand All @@ -84,6 +85,17 @@ Sources ingest frames and their metadata to a running module.
time.sleep(1) # Wait for the module to process the frame
result.logs().pretty_print()
# Send a batch to the module
src_jpeg = JpegSource('cam-2', 'data/AVG-TownCentre.jpeg')
batch = VideoFrameBatch()
frame, content = src_jpeg.build_frame()
frame.content = VideoFrameContent.internal(content)
batch.add(0, frame)
result = source((batch, 'topic')) # topic name to send a batch, can differ from `src_jpeg` source
print(result.status)
time.sleep(1) # Wait for the module to process the batch
result.logs().pretty_print()
Sink Example
^^^^^^^^^^^^
Expand Down
31 changes: 29 additions & 2 deletions savant/client/runner/sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
from dataclasses import dataclass, field
from typing import Optional

from savant_rs.primitives import EndOfStream, VideoFrame, VideoFrameContent
from savant_rs.primitives import (
EndOfStream,
VideoFrame,
VideoFrameBatch,
VideoFrameContent,
)

from savant.client.log_provider import LogProvider
from savant.client.runner import LogResult
Expand All @@ -17,8 +22,13 @@

@dataclass
class SinkResult(LogResult):
"""Result of receiving a message from ZeroMQ socket."""
"""Result of receiving a message from ZeroMQ socket.
frame_batch, frame_meta+frame_content, and eos are mutually exclusive.
"""

frame_batch: Optional[VideoFrameBatch]
"""Video frame batch."""
frame_meta: Optional[VideoFrame]
"""Video frame metadata."""
frame_content: Optional[bytes] = field(repr=False)
Expand Down Expand Up @@ -101,6 +111,22 @@ def _handle_message(self, zmq_message: ZeroMQMessage):
return SinkResult(
frame_meta=video_frame,
frame_content=content,
frame_batch=None,
eos=None,
trace_id=trace_id,
log_provider=self._log_provider,
)

if message.is_video_frame_batch():
video_frame_batch = message.as_video_frame_batch()
logger.debug(
'Received video frame batch with %s frames.',
len(video_frame_batch.frames),
)
return SinkResult(
frame_meta=None,
frame_content=None,
frame_batch=video_frame_batch,
eos=None,
trace_id=trace_id,
log_provider=self._log_provider,
Expand All @@ -112,6 +138,7 @@ def _handle_message(self, zmq_message: ZeroMQMessage):
return SinkResult(
frame_meta=None,
frame_content=None,
frame_batch=None,
eos=eos,
trace_id=trace_id,
log_provider=self._log_provider,
Expand Down
Loading

0 comments on commit 8c24d31

Please sign in to comment.