-
Notifications
You must be signed in to change notification settings - Fork 9
feat(vdo): Add safe Rust bindings for VDO API #223
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
Merged
guoxe
merged 31 commits into
AxisCommunications:main
from
vsem-azamat:feature/vdo-completion
Jul 3, 2026
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
2326701
feat(vdo): Add safe Rust bindings for VDO API
vsem-azamat 864abce
Merge remote-tracking branch 'upstream/main' into HEAD
apljungquist 2ca25d9
fix(vdo): Address all PR #223 review feedback
vsem-azamat 05638be
refactor(vdo): Replace glob imports with qualified paths and add expe…
vsem-azamat b89acc0
fix(vdo): Address code review and security audit findings
vsem-azamat 87a708d
style(vdo): Apply rustfmt
vsem-azamat 9f98b9e
fix(vdo): Fix soundness hole in file_descriptor() API
vsem-azamat 76ed6e4
docs(vdo): Separate Safety and Panics sections in unsafe fn docs
vsem-azamat b616613
fix(vdo): Rewrite Send safety comments without GLib assumption
vsem-azamat e5bdfa9
refactor(vdo): Remove redundant RunningStream::stop() method
vsem-azamat adb1eb9
refactor(vdo): Use NonNull::new instead of assert + new_unchecked
vsem-azamat 6a5579c
fix(vdo): Match error codes as i32 to avoid wrapping negative GError …
vsem-azamat 6274dae
fix(vdo): Use == GFALSE for gboolean checks instead of != GTRUE
vsem-azamat e8500d3
fix(vdo): Track stream started state to avoid stopping unstarted streams
vsem-azamat a617cd7
fix(vdo): Fix buffer leak in StreamBuffer::unref() on error
vsem-azamat 756af0d
fix(vdo): Log StreamBuffer Drop failures even without GError
vsem-azamat 35ae417
refactor(vdo): Minor code review cleanups
vsem-azamat a6ba015
fix(vdo): Use correct types for VdoFormat and fix Send safety comments
vsem-azamat 824eeff
fix(vdo): Revert format to set_u32 - VDO API expects uint32
vsem-azamat f4337d8
f: consistent cfg
apljungquist 8618568
Proper tests module and cfg
apljungquist fdf2314
update checksums
apljungquist 52edcd3
fix `make check_docs`
apljungquist 5f9a469
don't attempt to run vdo tests on host
apljungquist 73cf845
Merge branch 'main' into feature/vdo-completion
vsem-azamat 7489918
address review comments
vsem-azamat b2ccc73
update checksums
vsem-azamat ef3ca6a
document fd lifetime assumption
vsem-azamat 17f0d26
remove file_descriptor until there is a consumer
vsem-azamat f4c9497
update checksums
vsem-azamat db02c34
update checksums
vsem-azamat 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
|
apljungquist marked this conversation as resolved.
|
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 |
|---|---|---|
| @@ -1,20 +1,113 @@ | ||
| //! This application is a basic VDO type of application. | ||
| //! VDO Example Application | ||
| //! | ||
| //! The application starts a VDO stream and illustrates how to continuously capture frames from the | ||
| //! VDO service, access the received buffer contents, as well as the frame metadata. | ||
| //! This application demonstrates the VDO (Video Capture) API by capturing | ||
| //! frames from the camera in various formats. | ||
| //! | ||
| //! # Arguments | ||
| //! | ||
| //! - `format`: A string describing the video compression format. | ||
| //! Possible values are `h264` (default), `h265`, `jpeg`, `nv12`, and `y800`. | ||
| //! - `frames`: An integer specifying the number of captured frames. | ||
| //! - `output`: The output filename. | ||
| //! | ||
| use log::info; | ||
| //! It tests: | ||
| //! - Stream creation with different formats (YUV, JPEG, H.264) | ||
| //! - Frame capture and metadata access | ||
| //! - Proper resource cleanup | ||
|
|
||
| // These format tests run on the device as an ACAP application rather than as | ||
| // unit tests because they require access to actual camera hardware via the VDO API. | ||
|
|
||
| use log::{error, info}; | ||
| use vdo::{Error, Resolution, StreamBuilder, VdoFormat}; | ||
|
|
||
| fn capture_format(name: &str, format: VdoFormat, num_frames: usize) -> Result<(), Error> { | ||
| info!("=== Testing {} format ===", name); | ||
|
|
||
| let stream = StreamBuilder::new() | ||
| .channel(0) | ||
| .format(format) | ||
| .resolution(Resolution::Exact { | ||
| width: 640, | ||
| height: 480, | ||
| }) | ||
| .framerate(15) | ||
| .build()?; | ||
|
|
||
| info!("{}: Stream created successfully", name); | ||
|
|
||
| // Get stream info | ||
| if let Ok(stream_info) = stream.info() { | ||
| info!("{}: Stream info:", name); | ||
| stream_info.dump(); | ||
| } | ||
|
|
||
| let running = stream.start()?; | ||
| info!("{}: Stream started", name); | ||
|
|
||
| for i in 0..num_frames { | ||
| let buffer = running.next_buffer()?; | ||
| let size = buffer.size(); | ||
| let seq = buffer.sequence_number(); | ||
| let ts = buffer.timestamp(); | ||
|
|
||
| info!( | ||
| "{}: Frame {}: {} bytes, seq={}, timestamp={}us", | ||
| name, i, size, seq, ts | ||
| ); | ||
|
|
||
| // For JPEG, verify magic bytes | ||
| if format == VdoFormat::VDO_FORMAT_JPEG { | ||
| let data = buffer.as_slice()?; | ||
| if data.len() >= 2 && data[0] == 0xFF && data[1] == 0xD8 { | ||
| info!("{}: Frame {} has valid JPEG header", name, i); | ||
| } else { | ||
| error!("{}: Frame {} has INVALID JPEG header!", name, i); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| drop(running); | ||
| info!("{}: Stream stopped successfully", name); | ||
| info!(""); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| fn main() { | ||
| acap_logging::init_logger(); | ||
| unsafe { assert!(!vdo_sys::vdo_map_new().is_null()) }; | ||
| info!("vdo map created"); | ||
| todo!("Implement the real example") | ||
|
|
||
| info!("VDO Example Application starting..."); | ||
| info!("Testing VDO safe Rust bindings"); | ||
| info!(""); | ||
|
|
||
| // Test YUV (most portable format) | ||
| match capture_format("YUV", VdoFormat::VDO_FORMAT_YUV, 5) { | ||
| Ok(()) => info!("YUV test: PASSED"), | ||
| Err(e) => error!("YUV test: FAILED - {}", e), | ||
| } | ||
|
|
||
| // Test JPEG | ||
| match capture_format("JPEG", VdoFormat::VDO_FORMAT_JPEG, 5) { | ||
| Ok(()) => info!("JPEG test: PASSED"), | ||
| Err(e) => error!("JPEG test: FAILED - {}", e), | ||
| } | ||
|
|
||
| // Test H.264 | ||
| match capture_format("H.264", VdoFormat::VDO_FORMAT_H264, 10) { | ||
| Ok(()) => info!("H.264 test: PASSED"), | ||
| Err(e) => error!("H.264 test: FAILED - {}", e), | ||
| } | ||
|
|
||
| // Test H.265 (might not be supported on all platforms) | ||
| match capture_format("H.265", VdoFormat::VDO_FORMAT_H265, 5) { | ||
| Ok(()) => info!("H.265 test: PASSED"), | ||
| Err(e) => { | ||
| if let Error::Vdo(ref vdo_err) = e { | ||
| if vdo_err.code_name() == "VDO_ERROR_NOT_SUPPORTED" { | ||
| info!("H.265 test: SKIPPED (not supported on this platform)"); | ||
| } else { | ||
| error!("H.265 test: FAILED - {}", e); | ||
| } | ||
| } else { | ||
| error!("H.265 test: FAILED - {}", e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| info!(""); | ||
| info!("VDO Example Application completed!"); | ||
| } |
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,25 @@ | ||
| [package] | ||
| name = "vdo" | ||
| version = "0.0.0" | ||
| edition.workspace = true | ||
| license = "MIT" | ||
| description = "Safe Rust bindings for the VDO (Video Capture) API" | ||
|
|
||
| [dependencies] | ||
| vdo-sys = { workspace = true } | ||
| log = { workspace = true } | ||
| glib = { workspace = true } | ||
| glib-sys = { workspace = true } | ||
| gobject-sys = { workspace = true } | ||
| thiserror = { workspace = true } | ||
|
|
||
| [features] | ||
| device-tests = [] | ||
|
|
||
| [dev-dependencies] | ||
| anyhow = { workspace = true } | ||
| env_logger = { workspace = true } | ||
| expect-test = { workspace = true } | ||
|
|
||
| [[example]] | ||
| name = "basic" |
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,45 @@ | ||
| //! Basic example of using VDO to capture video frames. | ||
| //! | ||
| //! This example creates a video stream, captures a few frames, and prints | ||
| //! information about each frame. | ||
|
|
||
| use vdo::{Resolution, StreamBuilder, VdoFormat}; | ||
|
|
||
| fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
| // Initialize logging (optional) | ||
| env_logger::init(); | ||
|
|
||
| println!("Creating video stream..."); | ||
|
|
||
| // Create a stream with YUV format (most portable across platforms) | ||
| let stream = StreamBuilder::new() | ||
| .channel(0) | ||
| .format(VdoFormat::VDO_FORMAT_YUV) | ||
| .resolution(Resolution::Exact { | ||
| width: 640, | ||
| height: 480, | ||
| }) | ||
| .framerate(15) | ||
| .build()?; | ||
|
|
||
| println!("Starting stream..."); | ||
| let running = stream.start()?; | ||
|
|
||
| println!("Capturing frames..."); | ||
| for i in 0..10 { | ||
| let buffer = running.next_buffer()?; | ||
| println!( | ||
| "Frame {}: {} bytes, seq={}, timestamp={}us", | ||
| i, | ||
| buffer.size(), | ||
| buffer.sequence_number(), | ||
| buffer.timestamp() | ||
| ); | ||
| } | ||
|
|
||
| println!("Stopping stream..."); | ||
| drop(running); | ||
|
|
||
| println!("Done!"); | ||
| Ok(()) | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.