Skip to content

Conversation

@raiden-staging
Copy link
Contributor

@raiden-staging raiden-staging commented Dec 1, 2025

Live streaming features, to capture+broadcast the session, added to the server. Handles :

  • Internal stream :
    • creates and exposes livestream from within the kernel image container
  • Stream to remote :
    • feeds live stream to rtmp(s) url

Tested on local ✅

remote_stream_videoframe_646

Internal stream

curl -X POST http://localhost:444/stream/start \
  -H "Content-Type: application/json" \
  -d '{}'
{
  "id": "default",
  "mode": "internal",
  "ingest_url": "rtmp://127.0.0.1:1935/live/default",
  "playback_url": "rtmp://127.0.0.1:1935/live/default",
  "secure_playback_url": "rtmps://127.0.0.1:1936/live/default",
  "started_at": "2025-12-01T12:55:00Z",
  "is_streaming": true
}

Feed to remote stream

curl -X POST http://localhost:444/stream/start \
  -H "Content-Type: application/json" \
  -d '{
        "id": "remote-demo",
        "mode": "remote",
        "target_url": "rtmps://live.cloudflare.com:443/live/streamkeyxxxxxxxxxxx"
      }'
{
  "id": "remote-demo",
  "mode": "remote",
  "ingest_url": "rtmps://...",
  "playback_url": "rtmps://...",
  "secure_playback_url": null,
  "started_at": "2025-12-01T12:57:00Z",
  "is_streaming": true
}

List active streams

curl http://localhost:444/stream/list
[
  {
    "id": "default",
    "mode": "internal",
    "ingest_url": "rtmp://127.0.0.1:1935/live/default",
    "playback_url": "rtmp://127.0.0.1:1935/live/default",
    "secure_playback_url": "rtmps://127.0.0.1:1936/live/default",
    "started_at": "2025-12-01T12:55:00Z",
    "is_streaming": true
  }
]

Stop a stream

To stop a specific stream (for example, id = "remote-demo"), include the id in the body:

curl -X POST http://localhost:444/stream/stop \
  -H "Content-Type: application/json" \
  -d '{"id": "remote-demo"}'
{}

Note

Introduces live streaming with an FFmpeg-based streamer, an internal RTMP/RTMPS server, and new /stream start/stop/list APIs, plus config and wiring across the server.

  • API/Backend:
    • Add endpoints: POST /stream/start, POST /stream/stop, GET /stream/list with models StartStreamRequest, StopStreamRequest, StreamInfo (OpenAPI + generated client/server).
    • Implement ApiService streaming handlers; integrate stream.Manager, FFmpegStreamerFactory, and InternalServer; include stream shutdown in Shutdown.
  • Streaming Infrastructure (lib/stream):
    • New FFmpegStreamer (screen capture ➝ RTMP), StreamManager, and RTMPServer (RTMP/RTMPS with optional self-signed TLS); shared Params, Metadata, and interfaces.
  • Server Wiring (cmd/api/main):
    • Initialize stream defaults, streamer factory, manager, and RTMP(S) server; auto-generate TLS if none provided.
  • Config:
    • Add RTMP_LISTEN_ADDR, RTMPS_LISTEN_ADDR, RTMPS_CERT_PATH, RTMPS_KEY_PATH; validation and tests updated.
  • Tests/Tooling/Deps:
    • Unit tests for stream lifecycle and API wiring; regenerate OAPI; add dependency github.com/notedit/rtmp.

Written by Cursor Bugbot for commit ea0f9ba. This will update automatically on new commits. Configure here.

…and interfaces

implement process lifecycle, platform capture args, and scale-to-zero integration
wire stream manager and ffmpeg streamer into api service
add rtmp/rtmps config options and validation
implement start/stop/list endpoints, stream manager registration, rtmp server with rtmps tls support and ensure streams/rtmp are stopped on shutdown
…Test; refactor api tests to use unified stream setup
default request host to 127.0.0.1 on empty input and add rtmp dependency
…layback urls; add rtmp config defaults and tidy struct field formatting
@mesa-dot-dev
Copy link

mesa-dot-dev bot commented Dec 1, 2025

Mesa Description

TL;DR

Added live streaming capabilities to the server, enabling session capture and broadcast both internally and to remote RTMP(S) destinations.

Why we made these changes

To provide users with the ability to capture and broadcast their kernel image sessions, supporting both local internal access and broader distribution via remote streaming.

What changed?

  • Introduced new API endpoints (/stream/start, /stream/list, /stream/stop) for managing live streams.
  • Implemented two distinct streaming modes:
    • Internal stream: Creates and exposes a livestream from within the kernel image container.
    • Stream to remote: Feeds the live stream to a specified RTMP(S) URL.
  • The server now handles the lifecycle of these live streams, from initiation to termination.

Validation

Tested on local ✅

Internal stream

curl -X POST http://localhost:444/stream/start \
  -H "Content-Type: application/json" \
  -d '{}'
{
  "id": "default",
  "mode": "internal",
  "ingest_url": "rtmp://127.0.0.1:1935/live/default",
  "playback_url": "rtmp://127.0.0.1:1935/live/default",
  "secure_playback_url": "rtmps://127.0.0.1:1936/live/default",
  "started_at": "2025-12-01T12:55:00Z",
  "is_streaming": true
}

Feed to remote stream

curl -X POST http://localhost:444/stream/start \
  -H "Content-Type: application/json" \
  -d '{
        "id": "remote-demo",
        "mode": "remote",
        "target_url": "rtmps://live.cloudflare.com:443/live/streamkeyxxxxxxxxxxx"
      }'
{
  "id": "remote-demo",
  "mode": "remote",
  "ingest_url": "rtmps://...",
  "playback_url": "rtmps://...",
  "secure_playback_url": null,
  "started_at": "2025-12-01T12:57:00Z",
  "is_streaming": true
}

List active streams

curl http://localhost:444/stream/list
[
  {
    "id": "default",
    "mode": "internal",
    "ingest_url": "rtmp://127.0.0.1:1935/live/default",
    "playback_url": "rtmp://127.0.0.1:1935/live/default",
    "secure_playback_url": "rtmps://127.0.0.1:1936/live/default",
    "started_at": "2025-12-01T12:55:00Z",
    "is_streaming": true
  }
]

Stop a stream

To stop a specific stream (for example, id = "remote-demo"), include the id in the body:

curl -X POST http://localhost:444/stream/stop \
  -H "Content-Type: application/json" \
  -d '{"id": "remote-demo"}'
{}

Description generated by Mesa. Update settings

Copy link

@mesa-dot-dev mesa-dot-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performed full review of 3dfcec2...ea0f9ba

Analysis

  1. Process Management: The FFmpeg streaming component doesn't properly log errors when terminating processes (SIGINT/SIGKILL), potentially hindering debugging of failed terminations. The implementation also has platform-specific assumptions that may cause issues in cross-platform environments.

  2. Race Conditions: The RTMP server has potential race conditions in its Start() method where the mutex is released before starting accept loops, and the acceptLoop checks for context cancellation after error handling, potentially generating unnecessary error logs during shutdown.

  3. Silent Failure Modes: The self-signed certificate generation falls back silently with just logging, meaning RTMPS could be unavailable without clear indication. Similarly, there are "magic numbers" like the 250ms startup detection timeout that lack documentation or configurability.

  4. Resource Management Gaps: When handling existing streams that aren't actively streaming, the code deregisters and continues without properly ensuring the old FFmpeg process is terminated, potentially causing resource leaks.

  5. Security Limitations: The internal RTMP server lacks authentication/authorization, and the self-signed TLS certificates only include "localhost" in DNSNames, limiting RTMPS connections unnecessarily without configuration options.

Tip

Help

Slash Commands:

  • /review - Request a full code review
  • /review latest - Review only changes since the last review
  • /describe - Generate PR description. This will update the PR body or issue comment depending on your configuration
  • /help - Get help with Mesa commands and configuration options

13 files reviewed | 0 comments | Edit Agent SettingsRead Docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant