Skip to content

Commit

Permalink
Merge pull request #128 from StanfordVL/feat/headless-mode
Browse files Browse the repository at this point in the history
Add support for remote streaming
  • Loading branch information
cgokmen authored Dec 25, 2023
2 parents 44c1d17 + b56aab1 commit ca19189
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
26 changes: 25 additions & 1 deletion omnigibson/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
import socket
import shutil
import tempfile
import atexit
Expand Down Expand Up @@ -75,7 +76,7 @@ def create_app():
# If multi_gpu is used, og.sim.render() will cause a segfault when called during on_contact callbacks,
# e.g. when an attachment joint is being created due to contacts (create_joint calls og.sim.render() internally).
gpu_id = None if gm.GPU_ID is None else int(gm.GPU_ID)
config_kwargs = {"headless": gm.HEADLESS, "multi_gpu": False}
config_kwargs = {"headless": gm.HEADLESS or bool(gm.REMOTE_STREAMING), "multi_gpu": False}
if gpu_id is not None:
config_kwargs["active_gpu"] = gpu_id
config_kwargs["physics_gpu"] = gpu_id
Expand All @@ -96,6 +97,29 @@ def create_app():
if os.name == "nt":
enable_extension("omni.kit.window.viewport")

# Default Livestream settings
if gm.REMOTE_STREAMING:
app.set_setting("/app/window/drawMouse", True)
app.set_setting("/app/livestream/proto", "ws")
app.set_setting("/app/livestream/websocket/framerate_limit", 120)
app.set_setting("/ngx/enabled", False)

hostname = socket.gethostname()

# Note: Only one livestream extension can be enabled at a time
if gm.REMOTE_STREAMING == "native":
# Enable Native Livestream extension
# Default App: Streaming Client from the Omniverse Launcher
enable_extension("omni.kit.livestream.native")
print(f"Now streaming on {hostname} via Omniverse Streaming Client")
elif gm.REMOTE_STREAMING == "webrtc":
# Enable WebRTC Livestream extension
# Default URL: http://localhost:8211/streaming/webrtc-client/
enable_extension("omni.services.streamclient.webrtc")
print(f"Now streaming on: http://{hostname}:8211/streaming/webrtc-client?server={hostname}")
else:
raise ValueError(f"Invalid REMOTE_STREAMING option {gm.REMOTE_STREAMING}. Must be one of None, native, webrtc.")

# If we're headless, suppress all warnings about GLFW
if gm.HEADLESS:
import omni.log
Expand Down
3 changes: 3 additions & 0 deletions omnigibson/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
# Whether to generate a headless or non-headless application upon OmniGibson startup
gm.HEADLESS = (os.getenv("OMNIGIBSON_HEADLESS", 'False').lower() in ('true', '1', 't'))

# Whether to enable remote streaming. None disables it, other valid options are "native", "webrtc".
gm.REMOTE_STREAMING = os.getenv("OMNIGIBSON_REMOTE_STREAMING", None)

# Whether only the viewport should be shown in the GUI or not (if not, other peripherals are additionally shown)
# CANNOT be set at runtime
gm.GUI_VIEWPORT_ONLY = False
Expand Down

0 comments on commit ca19189

Please sign in to comment.