-
Notifications
You must be signed in to change notification settings - Fork 226
Capture: crate & core abstractions #1348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
+1,400
−0
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| livekit-capture: minor | ||
| --- | ||
|
|
||
| Add a `livekit-capture` crate with the core abstractions for capturing video and publishing it to a LiveKit track. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| [package] | ||
| name = "livekit-capture" | ||
| description = "Encoded video ingest helpers for LiveKit" | ||
| version = "0.1.0" | ||
| readme = "README.md" | ||
| license.workspace = true | ||
| edition.workspace = true | ||
| repository.workspace = true | ||
|
|
||
| [dependencies] | ||
| bytes = { workspace = true } | ||
| livekit = { workspace = true } | ||
| schemars = { workspace = true, optional = true } | ||
| serde = { workspace = true, features = ["derive"], optional = true } | ||
| thiserror = { workspace = true } | ||
| tokio = { workspace = true, features = ["sync"] } | ||
|
|
||
| [dev-dependencies] | ||
| tokio = { workspace = true, features = ["rt", "time", "macros"] } | ||
|
|
||
| [features] | ||
| default = [] | ||
| serde = ["dep:serde"] | ||
| schemars = ["dep:schemars", "serde"] | ||
|
|
||
| # Async convenience wrappers for blocking source construction when using | ||
| # a tokio runtime. | ||
| tokio = ["tokio/rt"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # LiveKit Capture | ||
|
|
||
| > [!IMPORTANT] | ||
| > This crate is currently in Developer Preview mode and not ready for production use. | ||
| > There may be bugs, and APIs and configuration options are subject to change during this period. | ||
|
|
||
| This crate provides video capture sources and the pumps that publish them | ||
| with the LiveKit [Rust SDK](../livekit/README.md). Implement one small trait | ||
| to add a source. The application runs and supervises every source the same | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "implement one small trait to stream video from a device source" ? |
||
| way. | ||
|
|
||
| ## Source and pump | ||
|
|
||
| Two concepts make up the crate. Video reaches a LiveKit track in one of two | ||
| forms, so the source and the pump each have two variants. | ||
|
|
||
| **A source** produces video, one blocking call at a time. Implement one of | ||
| these two traits: | ||
|
|
||
| - A `pixel::PixelVideoSource` produces raw `VideoFrame`s — from a camera, for | ||
| example. The WebRTC encoder encodes them. | ||
| - An `encoded::EncodedVideoSource` produces access units that are already | ||
| encoded — from an encoding pipeline, for example. The SDK sends them to the | ||
| wire without re-encoding (passthrough). When frames are encoded upstream, | ||
| this removes an extra decode and encode step and lowers latency. | ||
|
|
||
| **A pump** connects one source to an RTC video source: | ||
| `pixel::PixelVideoPump<S>` or `encoded::EncodedVideoPump<S>`. It builds the | ||
| matching RTC video source, derives the publish options, and runs the capture | ||
| loop. Spawn a pump onto a dedicated thread and it becomes a | ||
| `pump::RunningPump`. Both pump kinds spawn into the same type, so an | ||
| application supervises them the same way. Stop a running pump from any | ||
| thread through its stop handle. | ||
|
|
||
| Sources block, so the pumps run synchronous code on plain threads. | ||
|
|
||
| ## Publishing a track | ||
|
|
||
| A pump supplies the RTC source and the publish options, so publication is the | ||
| same for either path. | ||
|
|
||
| ```rust | ||
| let pump = PixelVideoPump::new(MyVideoSource::new(config).await?); | ||
|
|
||
| let track = LocalVideoTrack::create_video_track("my-source", pump.rtc_source()); | ||
| let options = pump.publish_options(); | ||
| room.local_participant().publish_track(LocalTrack::Video(track), options).await?; | ||
|
|
||
| let running = pump.spawn()?; | ||
|
|
||
| // On shutdown: | ||
| let stats = running.stop_and_join_async().await?; | ||
| ``` | ||
|
|
||
| ## Adding a source | ||
|
|
||
| Implement `pixel::PixelVideoSource` for raw frames or | ||
| `encoded::EncodedVideoSource` for pre-encoded access units. A source is | ||
| constructed from its own config struct and is driven by the matching pump — | ||
| no other integration is needed. | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a really cool crate!