Skip to content

sgnts.decorators.sink

Decorators for simplifying sink implementations.

single_pad(method)

Decorator for simple single-pad sinks.

Transforms the simpler signature::

def process(self, input_frame: TSFrame) -> None

Into the dict-based signature expected by TSSink::

def process(self, input_frames: dict[SinkPad, TSFrame]) -> None

Usage::

from sgnts.decorators import sink

class MySink(TSSink):
    @sink.single_pad
    def process(self, input_frame: TSFrame) -> None:
        # Process single input frame
        pass
Source code in src/sgnts/decorators/sink.py
def single_pad(
    method: Callable[[T, TSFrame], None],
) -> Callable[[T, dict[SinkPad, TSFrame]], None]:
    """Decorator for simple single-pad sinks.

    Transforms the simpler signature::

        def process(self, input_frame: TSFrame) -> None

    Into the dict-based signature expected by TSSink::

        def process(self, input_frames: dict[SinkPad, TSFrame]) -> None

    Usage::

        from sgnts.decorators import sink

        class MySink(TSSink):
            @sink.single_pad
            def process(self, input_frame: TSFrame) -> None:
                # Process single input frame
                pass
    """

    @wraps(method)
    def wrapper(
        self: T,
        input_frames: dict[SinkPad, TSFrame],
    ) -> None:
        assert len(self.sink_pads) == 1, (
            f"@sink.single_pad requires exactly one sink pad, "
            f"got {len(self.sink_pads)}"
        )
        return method(self, input_frames[self.sink_pads[0]])

    return wrapper