Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ add_subdirectory(plugin_manager)
# Camera interface: Linux only, for its shared memory and the socket between processes
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
add_subdirectory(camera)
add_subdirectory(media_transport)
endif()

# Build OXR library (depends on oxr_utils for types)
Expand Down
3 changes: 3 additions & 0 deletions src/core/media_transport/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
add_subdirectory(cpp)
98 changes: 98 additions & 0 deletions src/core/media_transport/INTERFACE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<!--
SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
SPDX-License-Identifier: Apache-2.0
-->

# Network transport interface

This is the implemented native C++ contract, not the broader future media API.
The authoritative declarations are in [transport.hpp](cpp/inc/media_transport/transport.hpp).
Applications choose a provider library; their capture, encoding and display code
uses these interfaces without including the provider SDK.

## Responsibilities and classes

```text
Camera plugin → CameraReader → application encoder → Publisher
│
Transport implementation
│ network
Transport implementation
│
Application display/consumer ← DecodedFrame ← Subscriber
```

| Class / value | Responsibility |
| --- | --- |
| `Plugin` | Load an explicit absolute library path, check ABI, retain provider lifetime. |
| `Transport` | Factory for a `Publisher`, `Subscriber`, or `MessageSession`. |
| `Connection` | Provider endpoint URL and private authentication token. |
| `VideoConfig` | One track: dimensions, frame rate and target bitrate. |
| `Publisher` | Accept encoded frames and expose encoder feedback. |
| `EncodedFrame` | Owned Annex-B H.264 access unit, keyframe flag, frame ID and sender-monotonic microseconds. |
| `Feedback` | Keyframe request and optional target bitrate; the application controls the encoder. |
| `Subscriber` | Nonblocking newest-frame read, terminal status and local receive statistics. |
| `DecodedFrame` | Shared, tightly packed CPU RGBA pixels, dimensions/extent, optional sender frame ID and timestamp. |
| `MessageSession` | Bidirectional opaque bytes; see the [messaging interface](messages/INTERFACE.md). |

## Application flow

```cpp
namespace mt = isaaccapture::media_transport;
mt::Plugin provider(absolute_library_path);
auto publisher = provider.publisher(connection, video_config);
auto feedback = publisher->feedback(); // Apply to the application's encoder.
bool accepted = publisher->publish(std::move(encoded_frame));

// On the receiving machine:
auto subscriber = provider.subscriber(connection, publisher_identity, track_name);
const bool ended = subscriber->finished();
if (auto frame = subscriber->take()) {
consume(*frame);
} else if (ended) {
// Drain before ending: a final frame may remain after finished() becomes true.
}
```

Factories establish sessions and may block or throw. Call each session's methods
from one application thread. `publish` consumes its frame; `false` is local
rejection, not a remote delivery acknowledgement. The application owns encoder
adaptation and decides how to handle rejection. `take` returns empty when there is
no new frame; it does not wait. Provider failures throw. No automatic application
reconnect or durable replay is promised.

Sessions keep the provider loaded. Returned pixel leases remain valid after the
subscriber or loader is destroyed. Keep the `DecodedFrame` ownership while using
its pixels; never retain only its raw pointer. Plugin initialization exceptions
are translated before unloading the library. Provider destructors must not throw.

A timestamp received from another machine is not automatically comparable to the
local clock. Missing metadata remains absent. `ReceiveStats.received` and
`overwritten` count local reads and slot replacement, not network packet loss or
photon-to-photon latency.

## Implementing another provider

Implement `Transport`, `Publisher`, `Subscriber`, and `MessageSession`, then export
`isaac_media_transport_plugin_v2()` returning `PluginApi{2, create, destroy}`.
Build the application and provider with matching headers, compiler, standard
library and ABI settings. This is an experimental same-toolchain C++ boundary,
not a stable cross-compiler binary interface. Load only trusted libraries.

Keep SDK setup, sessions, callback threads and cleanup inside the provider. Keep
camera drivers, encoder configuration and presentation outside it. Validate
ownership, bounded queues, error paths and shutdown against the core tests.
Selecting only one provider must not require other providers' SDKs.

## Cameras, clients and future streams

The transport sees encoded video, not camera brands or Jetson models. The example
uses `CameraReader` and Jetson Multimedia API, with JetPack-specific encoder
handling for Orin and Thor. Its current input is one host-memory NV12 stream;
a camera backend is usable when it supplies that layout through CameraReader.
Device support requires that backend and compatible local dependencies.

Audio, tactile media, other codecs, GPU frame handles and capability negotiation
need explicit extensions with their own format, clock, ownership and recovery
contracts. Opaque messages can already carry small application-defined sensor or
control records; that is not an implemented audio or tactile streaming pipeline.
113 changes: 113 additions & 0 deletions src/core/media_transport/NATIVE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<!--
SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
SPDX-License-Identifier: Apache-2.0
-->

# Native media transport — implementation notes

Start with the [network interface](INTERFACE.md) and
[opaque messaging interface](messages/INTERFACE.md) for the public contracts.

The C++ interface in `cpp/inc/media_transport/transport.hpp` separates Media Bridge
applications from the SDK implementation. The sender owns CameraReader/NVENC; the
viewer owns SDL. Neither includes nor links LiveKit. A selected shared library
implements transport sessions. The initial provider is
`src/plugins/transport_livekit/cpp`, using the official unmodified SDK.

```text
Camera plugin → CameraReader → NVENC → Publisher interface
↓ loaded LiveKit plugin
network
↓ loaded LiveKit plugin
SDL window ← CPU RGBA frame ← Subscriber interface
```

## Contract

- `Connection` carries provider endpoint and token. Keep tokens private; the
examples read files generated from site bundles. The LiveKit provider requires TLS.
- A publisher is configured for one H.264 track with fixed dimensions, fps and
bitrate. `publish` consumes an owned Annex-B access unit, keyframe flag, frame ID
and sender-monotonic timestamp. Local acceptance is not a delivery guarantee.
- `feedback` returns keyframe requests and target bitrate; the sender applies
them to its encoder. The initial implementation does not implement frame-rate
adaptation, other codecs, reconnect, or an encoded-stream recovery protocol.
- A subscriber selects one publisher identity and track. `take` is nonblocking
and returns the newest available frame, or empty. Failures throw; `finished`
reports end-of-stream. Call a session's methods from one application thread.
- Decoded output is tightly packed **CPU RGBA**, with explicit dimensions, byte
extent and shared ownership. Sender frame ID/timestamp are optional; missing
metadata must not be fabricated. This timestamp is not host-clock qualified.
- The LiveKit provider has a one-frame SDK queue and one-frame application slot.
Its counters expose worker reads and slot overwrites, not all network/SDK drops.
- Sessions retain the provider instance. Retained frames retain that instance too,
so pixel buffers remain valid even after the subscriber and `Plugin` are gone.
Frames alias the SDK-owned buffer; the interface adds no full-frame pixel copy.

## Opaque messages

`Plugin::messages(Connection, MessageConfig)` creates a bidirectional session for
one explicit peer and topic. `send` accepts owned-by-caller binary bytes during a
synchronous call; implementations must not retain the caller's storage after it
returns. `take` transfers an owned message out of a bounded FIFO without waiting.
Use the session from one application thread; provider callbacks feed the
thread-safe `MessageInbox`. Sessions retain the plugin just as video sessions do.

Payloads are limited to 1–1024 bytes. Peer/topic limits are 256/128 bytes; empty
strings and embedded NUL are rejected. The inbox defaults to 64 packets, accepts
capacities 1–1024, and rejects newest on overflow. `accepted`, `dropped`, `filtered`
and `queued` expose local receive behavior; none is a network delivery counter.
Unknown senders/topics are filtered before payload copying. No payload schema,
clock domain, timestamp interpretation or actuator policy is imposed.

`Reliable` requests the provider's reliable channel and `Lossy` requests its lossy
channel. Neither promises durable delivery, recipient acknowledgement or replay.
Send may block/throw; it belongs outside capture and real-time control callbacks.
`finished` indicates terminal session end. The LiveKit provider uses stock
`publishData` and `onUserPacketReceived`, with video subscription disabled.

The experimental ABI is now v2 because adding a session factory changes the C++
vtable. Rebuild both sides of the plugin boundary; v1 libraries fail loading
rather than being invoked with an incompatible layout.

## Loading and building

`Plugin` loads an explicit absolute path with `RTLD_LOCAL` and validates the
`isaac_media_transport_plugin_v2` descriptor before calling its factory. This is
an **experimental same-toolchain C++ ABI**, not a stable cross-compiler plugin ABI.
Build providers with the matching header, compiler, standard library and ABI.
Load only trusted libraries: a native plugin executes code in the application.

`BUILD_TRANSPORT_LIVEKIT_NATIVE=ON` builds `isaac_transport_livekit_native` and
requires the SDK. With it OFF (the default), neither the core nor the examples
require LiveKit package discovery. The option is independent of `BUILD_PLUGINS`,
which controls the existing device-plugin executables. Build the selected provider
explicitly alongside the application, then pass its library via `--transport-plugin`.
The application has no hardcoded provider path or default fallback.

A new provider implements `Transport`, `Publisher`, `Subscriber`, and
`MessageSession`, and exports
its factory descriptor. Match the documented buffer, lifetime and error contracts.
Do not claim support for a different memory type by placing a GPU address in the
CPU frame field; GPU output needs an explicit future interface extension.

With `BUILD_TESTING=ON`, build `media_transport_loader_test` and
`media_transport_message_tests`, then run
`ctest --test-dir "$BUILD_DIR" -R '^media_transport_(native_lifetime|messages)$' --output-on-failure`.
The test uses a mock provider, requires no LiveKit SDK, and checks invalid paths,
ABI rejection, null factory results, and frames/messages surviving session/loader
destruction. Message tests also cover binary ownership, bounds, filtering, FIFO
overflow and concurrent producer/consumer use.

## Boundaries still to address

This milestone provides native video and opaque messages. It does not implement
the Python robot-control adapter or its plugin discovery/package installer.
Audio/tactile schemas, capability negotiation, production binary
packaging, and clock-qualified latency reporting remain subsequent work. Keep
those additions explicit rather than implying that this video subset is the
complete transport contract already under review.

Stock LiveKit reception still exposes CPU buffers. Plugin extraction does not
restore NVDEC/CUDA IPC or immediate playout. Compare timing only after equivalent
instrumentation is restored; frame delivery alone is not latency parity.
8 changes: 8 additions & 0 deletions src/core/media_transport/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
add_library(media_transport_native STATIC plugin.cpp messages.cpp)
set_target_properties(media_transport_native PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_compile_features(media_transport_native PUBLIC cxx_std_20)
target_include_directories(media_transport_native INTERFACE inc)
target_link_libraries(media_transport_native PRIVATE ${CMAKE_DL_LIBS})
add_library(media_transport::native ALIAS media_transport_native)
61 changes: 61 additions & 0 deletions src/core/media_transport/cpp/inc/media_transport/messages.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <cstddef>
#include <cstdint>
#include <deque>
#include <mutex>
#include <optional>
#include <string>
#include <vector>
namespace isaaccapture::media_transport
{
enum class Delivery
{
Reliable,
Lossy
};
inline constexpr std::size_t max_message_bytes = 1024;
struct MessageConfig
{
std::string peer, topic;
std::size_t capacity = 64;
};
struct Message
{
std::vector<std::uint8_t> payload;
std::string sender, topic;
Delivery delivery = Delivery::Reliable;
};
struct MessageStats
{
std::uint64_t accepted = 0, dropped = 0, filtered = 0;
std::size_t queued = 0;
};
void validate_payload(const std::vector<std::uint8_t>&, Delivery);
// Bounded FIFO for provider callbacks. Reject newest on overflow; counters never imply network loss.
class MessageInbox
{
public:
explicit MessageInbox(MessageConfig config);
void push(const std::string& sender, const std::string& topic, const std::vector<std::uint8_t>& payload, Delivery);
std::optional<Message> take();
MessageStats stats();

private:
MessageConfig config;
std::mutex mutex;
std::deque<Message> queue;
MessageStats counts;
};
class MessageSession
{
public:
virtual ~MessageSession() = default;
// Synchronous SDK submission; may block/throw. No recipient acknowledgement or replay guarantee.
virtual void send(const std::vector<std::uint8_t>& payload, Delivery) = 0;
virtual std::optional<Message> take() = 0;
virtual MessageStats stats() = 0;
virtual bool finished() = 0;
};
}
96 changes: 96 additions & 0 deletions src/core/media_transport/cpp/inc/media_transport/transport.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "messages.hpp"

#include <cstddef>
#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include <vector>
namespace isaaccapture::media_transport
{
struct Connection
{
std::string url, token;
};
struct VideoConfig
{
std::string track = "cam";
std::uint32_t width = 0, height = 0, fps = 30, bitrate = 4000000;
};
struct EncodedFrame
{
// Owns one Annex-B H.264 access unit. Timestamp uses the sender's monotonic clock.
std::vector<std::uint8_t> data;
std::uint64_t timestamp_us = 0;
std::uint32_t frame_id = 0;
bool keyframe = false;
};
struct Feedback
{
bool keyframe_requested = false;
std::optional<std::uint64_t> target_bitrate_bps;
};
struct DecodedFrame
{
// Tightly packed CPU RGBA. GPU handles require a future, explicit memory contract.
std::shared_ptr<const std::uint8_t> pixels;
std::size_t byte_size = 0;
int width = 0, height = 0;
std::optional<std::uint64_t> sender_timestamp_us;
std::optional<std::uint32_t> frame_id;
};
struct ReceiveStats
{
std::uint64_t received = 0, overwritten = 0;
std::string decoder;
};
class Publisher
{
public:
virtual ~Publisher() = default;
virtual Feedback feedback() = 0;
// Consumes the owned access unit; false indicates local rejection, not delivery status.
virtual bool publish(EncodedFrame frame) = 0;
};
class Subscriber
{
public:
virtual ~Subscriber() = default;
// Nonblocking newest-frame read; empty means no new frame. Errors throw.
virtual std::optional<DecodedFrame> take() = 0;
virtual bool finished() = 0;
virtual ReceiveStats stats() = 0;
};
class Transport
{
public:
virtual ~Transport() = default;
virtual std::unique_ptr<MessageSession> messages(const Connection&, const MessageConfig&) = 0;
virtual std::unique_ptr<Publisher> publisher(const Connection&, const VideoConfig&) = 0;
virtual std::unique_ptr<Subscriber> subscriber(const Connection&,
const std::string& publisher,
const std::string& track) = 0;
};
// Experimental same-toolchain C++ ABI, not a stable third-party binary interface.
struct PluginApi
{
std::uint32_t version;
Transport* (*create)();
void (*destroy)(Transport*);
};
using PluginEntry = const PluginApi* (*)();
class Plugin
{
public:
explicit Plugin(const std::string& library);
std::shared_ptr<MessageSession> messages(const Connection&, const MessageConfig&) const;
std::shared_ptr<Publisher> publisher(const Connection&, const VideoConfig&) const;
std::shared_ptr<Subscriber> subscriber(const Connection&, const std::string& publisher, const std::string& track) const;

private:
std::shared_ptr<Transport> transport;
};
}
Loading
Loading