Skip to content

Conversation

@pschroedl
Copy link
Collaborator

Reverts the revert of BYOC: Add Streaming
#3804

@github-actions github-actions bot added go Pull requests that update Go code AI Issues and PR related to the AI-video branch. labels Nov 10, 2025
@pschroedl
Copy link
Collaborator Author

Per @ad-astra-video :
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.

@pschroedl
Copy link
Collaborator Author

Original PR for reference/comments : #3727

@codecov
Copy link

codecov bot commented Nov 10, 2025

Codecov Report

❌ Patch coverage is 36.21943% with 965 lines in your changes missing coverage. Please review.
✅ Project coverage is 32.35002%. Comparing base (0e49665) to head (d81c375).
⚠️ Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
server/job_stream.go 40.67623% 517 Missing and 62 partials ⚠️
server/job_rpc.go 44.69697% 124 Missing and 22 partials ⚠️
server/ai_live_video.go 0.00000% 108 Missing ⚠️
core/external_capabilities.go 4.81928% 79 Missing ⚠️
core/livepeernode.go 0.00000% 37 Missing ⚠️
core/ai_orchestrator.go 0.00000% 7 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       #3807         +/-   ##
===================================================
+ Coverage   31.67941%   32.35002%   +0.67061%     
===================================================
  Files            159         160          +1     
  Lines          38978       40306       +1328     
===================================================
+ Hits           12348       13039        +691     
- Misses         25735       26275        +540     
- Partials         895         992         +97     
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.11040% <72.72727%> (+2.50152%) ⬆️
server/rpc.go 68.86228% <0.00000%> (+0.07440%) ⬆️
core/ai_orchestrator.go 30.53735% <0.00000%> (+0.01103%) ⬆️
core/livepeernode.go 50.53763% <0.00000%> (-12.54962%) ⬇️
core/external_capabilities.go 25.89286% <4.81928%> (-61.60714%) ⬇️
server/ai_live_video.go 13.20475% <0.00000%> (+13.20475%) ⬆️
server/job_rpc.go 41.63474% <44.69697%> (+10.95627%) ⬆️
server/job_stream.go 40.67623% <40.67623%> (ø)

... and 5 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 0e49665...d81c375. 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.11040% <72.72727%> (+2.50152%) ⬆️
server/rpc.go 68.86228% <0.00000%> (+0.07440%) ⬆️
core/ai_orchestrator.go 30.53735% <0.00000%> (+0.01103%) ⬆️
core/livepeernode.go 50.53763% <0.00000%> (-12.54962%) ⬇️
core/external_capabilities.go 25.89286% <4.81928%> (-61.60714%) ⬇️
server/ai_live_video.go 13.20475% <0.00000%> (+13.20475%) ⬆️
server/job_rpc.go 41.63474% <44.69697%> (+10.95627%) ⬆️
server/job_stream.go 40.67623% <40.67623%> (ø)

... and 5 files with indirect coverage changes

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

@j0sh
Copy link
Collaborator

j0sh commented Nov 13, 2025

Leaving a note here, review is still in progress and will finish up within the next few days


//kick the second Orchestrator
go func() {
time.Sleep(200 * time.Millisecond)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I recommend using synctest for all timing dependent tests, it makes things run much faster and we don't really want to make the test suite slower than it already is. It'll also surface some types of concurrency issues as long as the tests are run with-race (not sure if they already are, but if not, also recommended)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I tried and could not get synctest to work. I don't know how to get it to work with the httptest server seems like. If this is mandatory can I ask I look at converting in a follow up PR?

That said, I was able to remove most of the time.Sleep instances in job_stream_test.go. Tests in job_stream_test.go takes 500-600 milliseconds to run locally.

I also ran the two most important tests using -race and added some locks around updates in liveParams. Not sure all the locks will catch actual race errors but better safe than have to deep dive into it. These two tests were added to continue to use -race detector in test.sh as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Update: got all tests in job_stream_test.go to work with synctest. Ran all locally with count=10 successfully with go test -timeout 30s -run _BYOC$ github.com/livepeer/go-livepeer/server -count=10


// startStreamProcessingFunc is an alias for startStreamProcessing that can be overridden in tests
// to avoid starting up actual stream processing
var startStreamProcessingFunc = startStreamProcessing
Copy link
Collaborator

Choose a reason for hiding this comment

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

FWIW, we have the same pattern in discovery and it's been horrible for test correctness, I've been trying to unwind our use of that so we can have cleaner tests that pass more reliably.

If it's not easy to override whatever the blocker is here then I'd suggest putting startStreamProcessingFunc in some struct that can be set on a per-test basis with startStreamProcessing as the default for normal use.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was able to get around this by making sure to pass no URL to the trickle URLs for subscriber/publisher/data channels.

@rickstaa rickstaa requested a review from j0sh November 24, 2025 21:21
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