Add Rust client library fro GstD with examples#338
Add Rust client library fro GstD with examples#338
Conversation
| @@ -0,0 +1,211 @@ | |||
| /* | |||
| * This file is part of GStreamer Daemon | |||
| * Copyright 2015-2022 Ridgerun, LLC (http://www.ridgerun.com) | |||
There was a problem hiding this comment.
Change to:
Copyright 2015-2026 RidgeRun, LLC (http://www.ridgerun.com)
Apply this to all the files in the PR
| install: false) | ||
| endforeach | ||
|
|
||
| subdir('rust') |
There was a problem hiding this comment.
Add a README inside examples/libgstc/rust/ explaining what each example does and how to run them
e9fd940 to
1caf51e
Compare
| println!("Pipeline set to playing!"); | ||
|
|
||
| println!("Press enter to stop the pipeline..."); | ||
| let (tx, rx) = mpsc::channel::<()>(); |
There was a problem hiding this comment.
I honestly think mpsc is overkill here. I'd recommend a simple Atomic boolean for the exit flag.
|
|
||
| let abs_path = PathBuf::from(&video) | ||
| .canonicalize() | ||
| .unwrap_or_else(|_| PathBuf::from(video)); |
There was a problem hiding this comment.
Prefer borrowing here PathBuf::from(&video)
| println!("Pipeline set to playing!"); | ||
|
|
||
| println!("Press enter to stop the pipeline..."); | ||
| let (tx, rx) = mpsc::channel::<()>(); |
| if bus_message.status == Status::OK { | ||
| println!("received!"); | ||
| } else if bus_message.status == Status::BUS_TIMEOUT { | ||
| println!("timeout!"); | ||
| eprintln!("EOS not received, file may be unreadable"); | ||
| } else { | ||
| println!("error!"); | ||
| eprintln!( | ||
| "An error occurred waiting for EOS: {}", | ||
| bus_message.status.0 | ||
| ); | ||
| } |
There was a problem hiding this comment.
Prefer matching here.
| @@ -0,0 +1,45 @@ | |||
| /* | |||
There was a problem hiding this comment.
I don't like this example name. Maybe wait_on_bus or something like that.
| use std::fmt; | ||
|
|
||
| #[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
| pub struct Status(pub i32); |
There was a problem hiding this comment.
Why a struct and not an enum? An enum is the more intuitive option here.
| } | ||
|
|
||
| pub(crate) struct Transport { | ||
| settings: ConnectionSettings, |
There was a problem hiding this comment.
I suggest we make this public so the client can read our settings.
| if self.stream.is_none() { | ||
| let stream = self.open_socket()?; | ||
| self.stream = Some(stream); | ||
| } |
There was a problem hiding this comment.
To me, this overprotection is an antipattern. If this happens, this is an error and we don't want to silence it. Why would the stream be closed? If we opened with keep_connection_open the stream should be open, if not, something went wrong and we should react accordingly.
| if timeout_ms < 0 { | ||
| stream | ||
| .set_read_timeout(None) | ||
| .map_err(|_| Status::SOCKET_ERROR)?; | ||
| } else { | ||
| stream | ||
| .set_read_timeout(Some(Duration::from_millis(timeout_ms as u64))) | ||
| .map_err(|_| Status::SOCKET_ERROR)?; | ||
| } |
There was a problem hiding this comment.
Please refactor this to set the timeout instead of duplicating all the code.
| rust_enabled = add_languages('rust', required : false) | ||
|
|
||
| if rust_enabled | ||
| subdir('gstc') | ||
| else | ||
| message('Rust compiler not found; skipping libgstc Rust API') | ||
| endif |
There was a problem hiding this comment.
Please follow the same pattern we use with python.
The ConnectionSettings are accesible through some helper methods in client.rs.
No description provided.