Skip to content

Conversation

@ad-astra-video
Copy link
Collaborator

@ad-astra-video ad-astra-video commented Sep 2, 2025

What does this pull request do? Explain your changes. (required)

Adds configurable streaming for BYOC entrypoint to go-livepeer. Uses trickle protocol to handle streaming for similar entrypoints and outputs from go-livepeer as live-video-to-video.

Streams can be any or a mix of the following:

  • video ingress via WHIP (with Gateway) or RTMP (with MediaMTX)
  • video egress via RTMP (with MediaMTX) or WHEP (with mediamtx)
  • SSE data output

Control and Events channels are created for every stream.

Streams are created with a POST request to /ai/stream/start that will start the stream and reserve the capacity with an Orchestrator that is providing the BYOC capability. If video ingress is enabled, the client should then start a stream with WHIP or RTMP to the provided ingress URLs provided in the response. URLs for egress video, data, updates (control) and events are also included in the response as well as the stream_id. The stream_id is an integral part of the URLs provided to interact with the stream and is combined with a provided stream name in the /ai/stream/start request.

Streams are stopped with a POST request to /ai/stream/stop. Orchestrators and Gateways track payment balance and the Gateway adjusts to the Orchestrators provided balance in new JobTokens provided at each payment interval every minute. Orchestrators will shutdown a stream when payment balance is zero.

Specific updates (required)

  • Add job_stream.go and job_stream_test.go
  • refactor job_rpc.go to reuse stream setup where made sense
  • updates go routines to ignore to enable tests to pass in common/testutil.go.

How did you test each of these updates (required)

Used byoc-stream to test end to end: https://github.com/ad-astra-video/livepeer-app-pipelines/tree/main/byoc-stream
Added tests to job_stream_test.go and some additional tests to job_rpc_test.go.

Does this pull request close any open issues?

Checklist:

@github-actions github-actions bot added go Pull requests that update Go code AI Issues and PR related to the AI-video branch. labels Sep 2, 2025
@codecov
Copy link

codecov bot commented Sep 2, 2025

Codecov Report

❌ Patch coverage is 48.92183% with 758 lines in your changes missing coverage. Please review.
✅ Project coverage is 33.04596%. Comparing base (5629cca) to head (229effe).
⚠️ Report is 88 commits behind head on master.

Files with missing lines Patch % Lines
server/job_stream.go 55.83864% 341 Missing and 75 partials ⚠️
server/job_rpc.go 50.95057% 101 Missing and 28 partials ⚠️
core/external_capabilities.go 4.81928% 79 Missing ⚠️
server/ai_live_video.go 30.55556% 69 Missing and 6 partials ⚠️
core/livepeernode.go 0.00000% 37 Missing ⚠️
core/ai_orchestrator.go 0.00000% 7 Missing ⚠️
common/testutil.go 0.00000% 6 Missing ⚠️
server/rpc.go 0.00000% 4 Missing ⚠️
server/ai_mediaserver.go 72.72727% 2 Missing and 1 partial ⚠️
core/accounting.go 91.30435% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@                 Coverage Diff                 @@
##              master       #3727         +/-   ##
===================================================
+ Coverage   31.67056%   33.04596%   +1.37540%     
===================================================
  Files            159         160          +1     
  Lines          38951       40250       +1299     
===================================================
+ Hits           12336       13301        +965     
- Misses         25722       25906        +184     
- Partials         893        1043        +150     
Files with missing lines Coverage Δ
server/ai_process.go 2.01913% <ø> (ø)
core/accounting.go 94.73684% <91.30435%> (-0.71771%) ⬇️
server/ai_mediaserver.go 9.53912% <72.72727%> (+2.93024%) ⬆️
server/rpc.go 68.86228% <0.00000%> (+0.07440%) ⬆️
common/testutil.go 15.87302% <0.00000%> (-1.67084%) ⬇️
core/ai_orchestrator.go 30.40629% <0.00000%> (-0.25160%) ⬇️
core/livepeernode.go 50.53763% <0.00000%> (-12.54962%) ⬇️
server/ai_live_video.go 32.93769% <30.55556%> (+32.93769%) ⬆️
core/external_capabilities.go 25.89286% <4.81928%> (-61.60714%) ⬇️
server/job_rpc.go 44.88491% <50.95057%> (+14.20644%) ⬆️
... and 1 more

... and 4 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5629cca...229effe. Read the comment docs.

Files with missing lines Coverage Δ
server/ai_process.go 2.01913% <ø> (ø)
core/accounting.go 94.73684% <91.30435%> (-0.71771%) ⬇️
server/ai_mediaserver.go 9.53912% <72.72727%> (+2.93024%) ⬆️
server/rpc.go 68.86228% <0.00000%> (+0.07440%) ⬆️
common/testutil.go 15.87302% <0.00000%> (-1.67084%) ⬇️
core/ai_orchestrator.go 30.40629% <0.00000%> (-0.25160%) ⬇️
core/livepeernode.go 50.53763% <0.00000%> (-12.54962%) ⬇️
server/ai_live_video.go 32.93769% <30.55556%> (+32.93769%) ⬆️
core/external_capabilities.go 25.89286% <4.81928%> (-61.60714%) ⬇️
server/job_rpc.go 44.88491% <50.95057%> (+14.20644%) ⬆️
... and 1 more

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pschroedl pschroedl self-requested a review October 27, 2025 15:24

//start payment monitoring
go func() {
stream, _ := h.node.ExternalCapabilities.Streams[orchJob.Req.ID]
Copy link
Collaborator

Choose a reason for hiding this comment

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

this accesses ExternalCapabilities.Streams map directly without holding the capm mutex. any concurrent map access will throw panics when streams are added/removed unless we acquire the lock first. I think we should follow a pattern similar to how StreamExists() is used - adding a helper GetStream(streamID) could be useful for this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just noticed that we're re-using this - we should probably re-capture each time instead of re-using stream

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed in e9a4c9d

}

clog.Infof(ctx, "Insufficient balance, stopping stream %s for sender %s", orchJob.Req.ID, orchJob.Sender)
_, exists := h.node.ExternalCapabilities.Streams[orchJob.Req.ID]
Copy link
Collaborator

Choose a reason for hiding this comment

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

see previous

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed in e9a4c9d


//check if stream still exists
// if not, send stop to worker and exit monitoring
stream, exists := h.node.ExternalCapabilities.Streams[orchJob.Req.ID]
Copy link
Collaborator

Choose a reason for hiding this comment

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

here too ;)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed in e9a4c9d

priceInfo := sess.OrchestratorInfo.PriceInfo
var paymentProcessor *LivePaymentProcessor
if priceInfo != nil && priceInfo.PricePerUnit != 0 {
if priceInfo != nil && priceInfo.PricePerUnit != 0 && sess.OrchestratorInfo.AuthToken != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

please add comment documenting why we're using sess.OrchestratorInfo.AuthToken check here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See 17357af

@pschroedl
Copy link
Collaborator

Pending passing checks/tests 👍 Code LGTM.

@pschroedl pschroedl merged commit 88807fa into livepeer:master Nov 5, 2025
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Issues and PR related to the AI-video branch. go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants