Skip to content

Send data and manage buffers

A streaming session accepts text and typed runtime dictionaries. remotemedia.control.Data builds several of those dictionaries; a worker receives the separate RuntimeData type. Convert at the boundary with Data.as_runtime_data() when calling native send_input().

Run the round trips

Use the MS2 native profile, then run:

python examples/python/data_buffers.py

The complete example checks eight payload kinds through a native PassThrough session and retains an audio view after closing it. This is data transport validation; it does not decode a file or display an image.

Kind Input used by the example Output contract checked
Text Python str Text in the data output queue
JSON Data.from_json({...}) Dictionary with type: json and value
Binary Data.from_buffer(bytes) Buffer export with unchanged bytes
Audio Contiguous NumPy float32, 24,000 Hz, one channel Samples, rate, channels; read-only memoryview
Tensor Raw float32 bytes, shape [2, 3], runtime dtype code 0 Byte contents, shape and dtype preserved
Video Packed 2 × 2 Rgb24, codec=None Pixel bytes and dimensions
Image Raw format with pixel_format: Rgb24 Pixel bytes and dimensions
File Path, filename, MIME type Reference metadata; no file read or upload

Tensor dtype codes belong to the runtime wire type, not NumPy's numeric dtype IDs. Audio channel layout, video pixel layout, shape and byte length must agree. The example's one-dimensional audio is mono; do not relabel a stereo buffer as mono or change only its sample-rate metadata to resample it.

Keep the owner alive

This excerpt creates an audio wrapper without first converting its samples to a list:

import numpy as np
from remotemedia.control import Data

samples = np.zeros(480, dtype=np.float32)
audio = Data.from_audio_numpy(samples, sample_rate=24000, channels=1)
payload = audio.as_runtime_data()
assert payload["samples"] is samples

That identity check describes the Python wrapper. It does not prove that the native host, IPC transport, downstream node, codec, or device makes no copies. Keep input owners alive and do not mutate them while the runtime may still borrow them.

In the tested native profile, audio output is an owning read-only memoryview. np.asarray(value["samples"]) exposes a read-only view; the returned owner keeps the data valid after session close. Use np.array(view, copy=True) when you need a detached writable array. tensor.tobytes() in the example is also an intentional copy.

Request and inspect a copy policy

await session.send_input(payload, require_zero_copy=True) applies a strict policy at that input operation. A Python list of audio samples requires materialization: the example deliberately receives BufferError and checks the copy report. A strict input request is not a promise of zero copies throughout an arbitrary graph.

PipelineBufferConfig(policy=...) provides session-level policy and retention limits in builds that expose it. Preflight and node support can reject a graph or operation. Use the copy and performance reports to identify the boundary and reason; do not infer zero-copy support from an accepted NumPy array alone.

Next

Use session control for live taps and injection, or Python nodes to process RuntimeData inside a worker.