mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-09-29 07:12:24 +00:00
Added ip parameter to connect to the stream
This commit is contained in:
parent
385351e5ad
commit
c744353583
1 changed files with 62 additions and 13 deletions
|
@ -25,18 +25,20 @@ use ndilib::*;
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct Settings {
|
struct Settings {
|
||||||
stream_name: String,
|
stream_name: String,
|
||||||
|
ip: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Settings {
|
impl Default for Settings {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Settings {
|
Settings {
|
||||||
stream_name: String::from("Fixed ndi stream name"),
|
stream_name: String::from("Fixed ndi stream name"),
|
||||||
|
ip: String::from(""),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Metadata for the properties
|
// Metadata for the properties
|
||||||
static PROPERTIES: [Property; 1] = [
|
static PROPERTIES: [Property; 2] = [
|
||||||
Property::String(
|
Property::String(
|
||||||
"stream-name",
|
"stream-name",
|
||||||
"Sream Name",
|
"Sream Name",
|
||||||
|
@ -44,6 +46,13 @@ static PROPERTIES: [Property; 1] = [
|
||||||
None,
|
None,
|
||||||
PropertyMutability::ReadWrite,
|
PropertyMutability::ReadWrite,
|
||||||
),
|
),
|
||||||
|
Property::String(
|
||||||
|
"ip",
|
||||||
|
"Stream IP",
|
||||||
|
"Stream IP",
|
||||||
|
None,
|
||||||
|
PropertyMutability::ReadWrite,
|
||||||
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
// Stream-specific state, i.e. audio format configuration
|
// Stream-specific state, i.e. audio format configuration
|
||||||
|
@ -190,6 +199,22 @@ impl ObjectImpl<BaseSrc> for NdiSrc {
|
||||||
settings.stream_name = stream_name;
|
settings.stream_name = stream_name;
|
||||||
drop(settings);
|
drop(settings);
|
||||||
|
|
||||||
|
let _ =
|
||||||
|
element.post_message(&gst::Message::new_latency().src(Some(&element)).build());
|
||||||
|
},
|
||||||
|
Property::String("ip", ..) => {
|
||||||
|
let mut settings = self.settings.lock().unwrap();
|
||||||
|
let ip = value.get().unwrap();
|
||||||
|
gst_warning!(
|
||||||
|
self.cat,
|
||||||
|
obj: &element,
|
||||||
|
"Changing ip from {} to {}",
|
||||||
|
settings.ip,
|
||||||
|
ip
|
||||||
|
);
|
||||||
|
settings.ip = ip;
|
||||||
|
drop(settings);
|
||||||
|
|
||||||
let _ =
|
let _ =
|
||||||
element.post_message(&gst::Message::new_latency().src(Some(&element)).build());
|
element.post_message(&gst::Message::new_latency().src(Some(&element)).build());
|
||||||
}
|
}
|
||||||
|
@ -207,6 +232,11 @@ impl ObjectImpl<BaseSrc> for NdiSrc {
|
||||||
let settings = self.settings.lock().unwrap();
|
let settings = self.settings.lock().unwrap();
|
||||||
//TODO to_value supongo que solo funciona con numeros
|
//TODO to_value supongo que solo funciona con numeros
|
||||||
Ok(settings.stream_name.to_value())
|
Ok(settings.stream_name.to_value())
|
||||||
|
},
|
||||||
|
Property::UInt("ip", ..) => {
|
||||||
|
let settings = self.settings.lock().unwrap();
|
||||||
|
//TODO to_value supongo que solo funciona con numeros
|
||||||
|
Ok(settings.ip.to_value())
|
||||||
}
|
}
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
|
@ -260,22 +290,30 @@ impl BaseSrcImpl<BaseSrc> for NdiSrc {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut source: NDIlib_source_t = NDIlib_source_t{p_ndi_name: ptr::null(),
|
||||||
|
p_ip_address: ptr::null()};
|
||||||
|
|
||||||
|
// print!("{:?}", settings.stream_name);
|
||||||
|
// print!("{:?}", settings.ip);
|
||||||
|
|
||||||
//TODO default values
|
//TODO default values
|
||||||
let NDI_find_create_desc: NDIlib_find_create_t = Default::default();
|
let NDI_find_create_desc: NDIlib_find_create_t = Default::default();
|
||||||
let pNDI_find = NDIlib_find_create_v2(&NDI_find_create_desc);
|
let pNDI_find = NDIlib_find_create_v2(&NDI_find_create_desc);
|
||||||
|
let ip_ptr = CString::new(settings.ip.clone()).unwrap();
|
||||||
|
if (ip_ptr == CString::new("").unwrap()){
|
||||||
if pNDI_find.is_null() {
|
if pNDI_find.is_null() {
|
||||||
//println!("Cannot run NDI: NDIlib_find_create_v2 error.");
|
//println!("Cannot run NDI: NDIlib_find_create_v2 error.");
|
||||||
gst_element_error!(element, gst::CoreError::Negotiation, ["Cannot run NDI: NDIlib_find_create_v2 error"]);
|
gst_element_error!(element, gst::CoreError::Negotiation, ["Cannot run NDI: NDIlib_find_create_v2 error"]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut no_sources: u32 = 0;
|
let mut total_sources: u32 = 0;
|
||||||
let mut p_sources = ptr::null();
|
let mut p_sources = ptr::null();
|
||||||
//TODO Delete while. If not, will loop until a source it's available
|
//TODO Delete while. If not, will loop until a source it's available
|
||||||
//while no_sources == 0 {
|
//while total_sources == 0 {
|
||||||
// TODO Sleep 1s to wait for all sources
|
// TODO Sleep 1s to wait for all sources
|
||||||
thread::sleep(time::Duration::from_millis(2000));
|
thread::sleep(time::Duration::from_millis(2000));
|
||||||
p_sources = NDIlib_find_get_current_sources(pNDI_find, &mut no_sources as *mut u32);
|
p_sources = NDIlib_find_get_current_sources(pNDI_find, &mut total_sources as *mut u32);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
// We need at least one source
|
// We need at least one source
|
||||||
|
@ -286,36 +324,47 @@ impl BaseSrcImpl<BaseSrc> for NdiSrc {
|
||||||
//::std::process::exit(1);
|
//::std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut source: isize = -1;
|
let mut no_source: isize = -1;
|
||||||
for i in 0..no_sources as isize{
|
for i in 0..total_sources as isize{
|
||||||
if CStr::from_ptr((*p_sources.offset(i)).p_ndi_name)
|
if CStr::from_ptr((*p_sources.offset(i)).p_ndi_name)
|
||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
.into_owned() == settings.stream_name{
|
.into_owned() == settings.stream_name{
|
||||||
source = i;
|
no_source = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if source == -1 {
|
if no_source == -1 {
|
||||||
gst_element_error!(element, gst::CoreError::Negotiation, ["Stream name not found"]);
|
gst_element_error!(element, gst::CoreError::Negotiation, ["Stream name not found"]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
println!(
|
println!(
|
||||||
"no_source {}: Name '{}' Address '{}'",
|
"Total_sources {}: Name '{}' Address '{}'",
|
||||||
no_sources,
|
total_sources,
|
||||||
CStr::from_ptr((*p_sources.offset(source)).p_ndi_name)
|
CStr::from_ptr((*p_sources.offset(no_source)).p_ndi_name)
|
||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
.into_owned(),
|
.into_owned(),
|
||||||
CStr::from_ptr((*p_sources.offset(source)).p_ip_address)
|
CStr::from_ptr((*p_sources.offset(no_source)).p_ip_address)
|
||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
.into_owned()
|
.into_owned()
|
||||||
);
|
);
|
||||||
|
source = *p_sources.offset(no_source).clone();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
source.p_ip_address = ip_ptr.as_ptr();
|
||||||
|
println!(
|
||||||
|
"Address '{}'",
|
||||||
|
CStr::from_ptr(source.p_ip_address)
|
||||||
|
.to_string_lossy()
|
||||||
|
.into_owned()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// We now have at least one source, so we create a receiver to look at it.
|
// We now have at least one source, so we create a receiver to look at it.
|
||||||
// We tell it that we prefer YCbCr video since it is more efficient for us. If the source has an alpha channel
|
// We tell it that we prefer YCbCr video since it is more efficient for us. If the source has an alpha channel
|
||||||
// it will still be provided in BGRA
|
// it will still be provided in BGRA
|
||||||
let p_ndi_name = CString::new("Galicaster NDI Receiver").unwrap();
|
let p_ndi_name = CString::new("Galicaster NDI Receiver").unwrap();
|
||||||
let NDI_recv_create_desc = NDIlib_recv_create_v3_t {
|
let NDI_recv_create_desc = NDIlib_recv_create_v3_t {
|
||||||
source_to_connect_to: *p_sources.offset(source),
|
source_to_connect_to: source,
|
||||||
p_ndi_name: p_ndi_name.as_ptr(),
|
p_ndi_name: p_ndi_name.as_ptr(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue