mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-11-27 14:01:04 +00:00
Refactor unsafe blocks
This commit is contained in:
parent
1aaf429f9e
commit
c92d63ee88
3 changed files with 108 additions and 107 deletions
|
@ -73,7 +73,6 @@ lazy_static! {
|
|||
static mut id_receiver: i8 = 0;
|
||||
|
||||
fn connect_ndi(cat: gst::DebugCategory , element: &BaseSrc, ip: String, stream_name: String) -> i8{
|
||||
unsafe {
|
||||
gst_debug!(cat, obj: element, "Starting NDI connection...");
|
||||
|
||||
let mut receivers = hashmap_receivers.lock().unwrap();
|
||||
|
@ -106,6 +105,7 @@ fn connect_ndi(cat: gst::DebugCategory , element: &BaseSrc, ip: String, stream
|
|||
}
|
||||
|
||||
}
|
||||
unsafe {
|
||||
|
||||
if !NDIlib_initialize() {
|
||||
gst_element_error!(element, gst::CoreError::Negotiation, ["Cannot run NDI: NDIlib_initialize error"]);
|
||||
|
@ -217,7 +217,6 @@ fn connect_ndi(cat: gst::DebugCategory , element: &BaseSrc, ip: String, stream
|
|||
|
||||
fn stop_ndi(cat: gst::DebugCategory , element: &BaseSrc, id: i8) -> bool{
|
||||
gst_debug!(cat, obj: element, "Closing NDI connection...");
|
||||
unsafe{
|
||||
let mut receivers = hashmap_receivers.lock().unwrap();
|
||||
{
|
||||
let val = receivers.get_mut(&id).unwrap();
|
||||
|
@ -233,15 +232,16 @@ fn stop_ndi(cat: gst::DebugCategory , element: &BaseSrc, id: i8) -> bool{
|
|||
|
||||
let recv = &val.ndi_instance;
|
||||
let pNDI_recv = recv.recv;
|
||||
unsafe{
|
||||
NDIlib_recv_destroy(pNDI_recv);
|
||||
// ndi_struct.recv = None;
|
||||
NDIlib_destroy();
|
||||
}
|
||||
}
|
||||
receivers.remove(&id);
|
||||
gst_debug!(cat, obj: element, "Closed NDI connection");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Static plugin metdata that is directly stored in the plugin shared object and read by GStreamer
|
||||
// upon loading.
|
||||
|
|
|
@ -348,7 +348,6 @@ impl NdiAudioSrc {
|
|||
|
||||
fn fixate(&self, element: &BaseSrc, caps: gst::Caps) -> gst::Caps {
|
||||
//We need to set the correct caps resolution and framerate
|
||||
unsafe{
|
||||
let receivers = hashmap_receivers.lock().unwrap();
|
||||
let settings = self.settings.lock().unwrap();
|
||||
|
||||
|
@ -361,9 +360,10 @@ impl NdiAudioSrc {
|
|||
|
||||
let mut frame_type: NDIlib_frame_type_e = NDIlib_frame_type_e::NDIlib_frame_type_none;
|
||||
while frame_type != NDIlib_frame_type_e::NDIlib_frame_type_audio{
|
||||
unsafe{
|
||||
frame_type = NDIlib_recv_capture_v2(pNDI_recv, ptr::null(), &audio_frame, ptr::null(), 1000);
|
||||
}
|
||||
|
||||
}
|
||||
let mut caps = gst::Caps::truncate(caps);
|
||||
{
|
||||
let caps = caps.make_mut();
|
||||
|
@ -376,7 +376,7 @@ impl NdiAudioSrc {
|
|||
// Let BaseSrc fixate anything else for us. We could've alternatively have
|
||||
// called Caps::fixate() here
|
||||
element.parent_fixate(caps)
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
//Creates the audio buffers
|
||||
|
@ -401,7 +401,6 @@ impl NdiAudioSrc {
|
|||
}
|
||||
Some(ref info) => info.clone(),
|
||||
};
|
||||
unsafe{
|
||||
let receivers = hashmap_receivers.lock().unwrap();
|
||||
|
||||
let recv = &receivers.get(&_settings.id_receiver).unwrap().ndi_instance;
|
||||
|
@ -410,6 +409,7 @@ impl NdiAudioSrc {
|
|||
let pts: u64;
|
||||
let audio_frame: NDIlib_audio_frame_v2_t = Default::default();
|
||||
|
||||
unsafe{
|
||||
let time = ndi_struct.initial_timestamp;
|
||||
|
||||
let mut skip_frame = true;
|
||||
|
|
|
@ -364,7 +364,6 @@ impl NdiVideoSrc {
|
|||
|
||||
fn fixate(&self, element: &BaseSrc, caps: gst::Caps) -> gst::Caps {
|
||||
//We need to set the correct caps resolution and framerate
|
||||
unsafe{
|
||||
let receivers = hashmap_receivers.lock().unwrap();
|
||||
let settings = self.settings.lock().unwrap();
|
||||
|
||||
|
@ -376,8 +375,10 @@ impl NdiVideoSrc {
|
|||
|
||||
let mut frame_type: NDIlib_frame_type_e = NDIlib_frame_type_e::NDIlib_frame_type_none;
|
||||
while frame_type != NDIlib_frame_type_e::NDIlib_frame_type_video{
|
||||
unsafe{
|
||||
frame_type = NDIlib_recv_capture_v2(pNDI_recv, &video_frame, ptr::null(), ptr::null(), 1000);
|
||||
}
|
||||
}
|
||||
|
||||
let mut caps = gst::Caps::truncate(caps);
|
||||
{
|
||||
|
@ -394,7 +395,6 @@ impl NdiVideoSrc {
|
|||
let _ = element.post_message(&gst::Message::new_latency().src(Some(element)).build());
|
||||
element.parent_fixate(caps)
|
||||
}
|
||||
}
|
||||
|
||||
//Creates the video buffers
|
||||
fn create(
|
||||
|
@ -418,7 +418,7 @@ impl NdiVideoSrc {
|
|||
}
|
||||
Some(ref info) => info.clone(),
|
||||
};
|
||||
unsafe{
|
||||
// unsafe{
|
||||
let receivers = hashmap_receivers.lock().unwrap();
|
||||
|
||||
let recv = &receivers.get(&_settings.id_receiver).unwrap().ndi_instance;
|
||||
|
@ -427,6 +427,7 @@ impl NdiVideoSrc {
|
|||
let pts: u64;
|
||||
let video_frame: NDIlib_video_frame_v2_t = Default::default();
|
||||
|
||||
unsafe{
|
||||
let time = ndi_struct.initial_timestamp;
|
||||
|
||||
let mut skip_frame = true;
|
||||
|
|
Loading…
Reference in a new issue