-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
172 additions
and
103 deletions.
There are no files selected for viewing
This file contains 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 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,11 @@ | ||
use cfg_aliases::cfg_aliases; | ||
fn main() { | ||
println!( | ||
"cargo:rustc-env=LOG_INDEX_DIR={}", | ||
std::env::var("OUT_DIR").unwrap() | ||
); | ||
cfg_aliases! { | ||
hardware: { all(target_os = "linux", not(feature = "mock")) }, | ||
mock: { any(not(target_os = "linux"), feature = "mock") }, | ||
} | ||
} |
This file contains 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 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,21 @@ | ||
( | ||
tasks: [ | ||
( | ||
id: "src", | ||
type: "cu_gstreamer::CuDefaultGStreamer", | ||
config: { // my webcam produces mjpeg, this is just to emulate a more embedded format like NV12 | ||
"pipeline": "v4l2src device=/dev/video0 ! image/jpeg, width=1920, height=1080 ! jpegdec ! videoconvert ! video/x-raw, format=NV12 ! appsink name=copper", | ||
"caps": "video/x-raw, format=NV12, width=1920, height=1080", | ||
}, | ||
), | ||
( id: "tester", | ||
type: "GStreamerTester" | ||
), | ||
], | ||
cnx: [ | ||
(src: "src", dst: "tester", msg: "cu_gstreamer::CuGstBuffer"), | ||
], | ||
logging: ( | ||
enable_task_logging: false | ||
) | ||
) |
This file contains 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,83 @@ | ||
use cu29::prelude::*; | ||
use cu29_helpers::basic_copper_setup; | ||
use cu_gstreamer::CuGstBuffer; | ||
use rerun::{ChannelDatatype, ColorModel, Image, RecordingStream, RecordingStreamBuilder}; | ||
use std::path::PathBuf; | ||
use std::thread::sleep; | ||
use std::time::Duration; | ||
|
||
struct GStreamerTester { | ||
rec: RecordingStream, | ||
} | ||
|
||
impl Freezable for GStreamerTester {} | ||
|
||
impl<'cl> CuSinkTask<'cl> for GStreamerTester { | ||
type Input = input_msg!('cl, CuGstBuffer); | ||
|
||
fn new(_config: Option<&ComponentConfig>) -> CuResult<Self> | ||
where | ||
Self: Sized, | ||
{ | ||
let rec = RecordingStreamBuilder::new("Camera B&W Viz") | ||
.spawn() | ||
.unwrap(); | ||
Ok(Self { rec }) | ||
} | ||
|
||
fn process(&mut self, _clock: &RobotClock, msg: Self::Input) -> CuResult<()> { | ||
if msg.payload().is_none() { | ||
debug!("Skipped"); | ||
return Ok(()); | ||
} | ||
// Get the buffer's memory (zero-copy access) | ||
let data = msg.payload().unwrap().map_readable().unwrap(); | ||
println!("Received buffer: {} bytes", data.len()); | ||
let width = 1920; | ||
let height = 1080; | ||
let y_plane_size = width * height; | ||
let grey_image = &data[0..y_plane_size]; | ||
|
||
// Rerun stuff | ||
let image = Image::from_color_model_and_bytes( | ||
grey_image.to_vec(), | ||
[width as u32, height as u32], | ||
ColorModel::L, | ||
ChannelDatatype::U8, | ||
); | ||
self.rec.log("camera/image", &image).unwrap(); | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[copper_runtime(config = "tests/copperconfig.ron")] | ||
struct GStreamerTestApp {} | ||
|
||
#[test] | ||
fn end_2_end() { | ||
let logger_path = "/tmp/caterpillar.copper"; | ||
let copper_ctx = basic_copper_setup(&PathBuf::from(logger_path), None, true, None) | ||
.expect("Failed to setup logger."); | ||
debug!("Logger created at {}.", logger_path); | ||
debug!("Creating application... "); | ||
let mut application = GStreamerTestAppBuilder::new() | ||
.with_context(&copper_ctx) | ||
.build() | ||
.expect("Failed to create runtime."); | ||
|
||
debug!("Running..."); | ||
application | ||
.start_all_tasks() | ||
.expect("Failed to start tasks."); | ||
for _ in 0..1000 { | ||
application | ||
.run_one_iteration() | ||
.expect("Failed to run application."); | ||
sleep(Duration::from_millis(100)); // avoid zapping through 1000 buffers before the first image arrived | ||
} | ||
application | ||
.stop_all_tasks() | ||
.expect("Failed to start tasks."); | ||
|
||
debug!("End of program."); | ||
} |