Add audio to the pipeline even if the stream source it's already in use for video

FIXME: Whith this commit it's possible to add more streams for the same source if the pipeline has an audio source for that source.
This commit is contained in:
Daniel Vilar 2018-08-14 16:47:58 +02:00
parent 8bf4f8f935
commit ba45931830
2 changed files with 28 additions and 5 deletions

View file

@ -36,6 +36,8 @@ use gst_plugin::base_src::*;
use std::collections::HashMap;
use std::sync::Mutex;
use gst::GstObjectExt;
// Plugin entry point that should register all elements provided by this plugin,
// and everything else that this plugin might provide (e.g. typefinders or device providers).
fn plugin_init(plugin: &gst::Plugin) -> bool {
@ -64,11 +66,31 @@ lazy_static! {
fn connect_ndi(cat: gst::DebugCategory , element: &BaseSrc, ip: String, stream_name: String) -> bool{
unsafe {
gst_debug!(cat, obj: element, "Starting NDI connection...");
let mut map = hashmap_receivers.lock().unwrap();
//FIXME It's possible to connect more than one source if an audiosrc is active
let mut audio = false;
if (element.get_name().contains("ndiaudiosrc")){
audio = true;
}
if (map.contains_key(&stream_name) || map.contains_key(&ip)){
println!("Already connected to {}{}", ip, stream_name);
return false;
if (map.contains_key(&stream_name)){
let recv = map.get(&stream_name).unwrap();
audio = recv.audio;
}
else if (map.contains_key(&ip)){
let recv = map.get(&ip).unwrap();
audio = recv.audio;
}
if (audio){
println!("We already have an source, but we need to add an audio source to the pipeline. So we need to reutilize the source...");
return true;
}
else{
println!("Already connected to {}{}", ip, stream_name);
return false;
}
}
if !NDIlib_initialize() {
@ -163,8 +185,8 @@ fn connect_ndi(cat: gst::DebugCategory , element: &BaseSrc, ip: String, stream
NDIlib_recv_send_metadata(pNDI_recv, &enable_hw_accel);
map.insert(source_name.clone(), NdiInstance{recv: pNDI_recv});
map.insert(source_ip.clone(), NdiInstance{recv: pNDI_recv});
map.insert(source_name.clone(), NdiInstance{recv: pNDI_recv, audio: audio});
map.insert(source_ip.clone(), NdiInstance{recv: pNDI_recv, audio: audio});
// let start = SystemTime::now();
// let since_the_epoch = start.duration_since(UNIX_EPOCH)

View file

@ -152,6 +152,7 @@ pub type NDIlib_recv_instance_t = *mut ::std::os::raw::c_void;
//Rust wrapper around *mut ::std::os::raw::c_void
pub struct NdiInstance {
pub recv: NDIlib_recv_instance_t,
pub audio: bool,
}
unsafe impl ::std::marker::Send for NdiInstance {}