mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-02-17 05:15:14 +00:00
Execute rustfmt
This commit is contained in:
parent
20b6ae5ff6
commit
98db99924e
2 changed files with 142 additions and 140 deletions
|
@ -1,125 +1,128 @@
|
|||
#![allow(non_upper_case_globals, non_snake_case)]
|
||||
|
||||
|
||||
pub mod ndilib;
|
||||
|
||||
use std::ptr;
|
||||
use std::ffi::{CString, CStr};
|
||||
use std::ffi::{CStr, CString};
|
||||
|
||||
use ndilib::*;
|
||||
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
if !NDIlib_initialize() {
|
||||
//TODO delete exits
|
||||
println!("Cannot run NDI: NDIlib_initialize error.");
|
||||
::std::process::exit(1);
|
||||
}
|
||||
if !NDIlib_initialize() {
|
||||
//TODO delete exits
|
||||
println!("Cannot run NDI: NDIlib_initialize error.");
|
||||
::std::process::exit(1);
|
||||
}
|
||||
|
||||
//TODO valores por defecto
|
||||
let NDI_find_create_desc: NDIlib_find_create_t = Default::default();
|
||||
let pNDI_find = NDIlib_find_create_v2(&NDI_find_create_desc);
|
||||
if pNDI_find.is_null() {
|
||||
println!("Cannot run NDI: NDIlib_find_create_v2 error.");
|
||||
::std::process::exit(1);
|
||||
}
|
||||
//TODO valores por defecto
|
||||
let NDI_find_create_desc: NDIlib_find_create_t = Default::default();
|
||||
let pNDI_find = NDIlib_find_create_v2(&NDI_find_create_desc);
|
||||
if pNDI_find.is_null() {
|
||||
println!("Cannot run NDI: NDIlib_find_create_v2 error.");
|
||||
::std::process::exit(1);
|
||||
}
|
||||
|
||||
let mut no_sources: u32 = 0;
|
||||
let mut p_sources = ptr::null();
|
||||
while no_sources == 0 {
|
||||
p_sources = NDIlib_find_get_current_sources(pNDI_find, &mut no_sources as *mut u32);
|
||||
}
|
||||
let mut no_sources: u32 = 0;
|
||||
let mut p_sources = ptr::null();
|
||||
while no_sources == 0 {
|
||||
p_sources = NDIlib_find_get_current_sources(pNDI_find, &mut no_sources as *mut u32);
|
||||
}
|
||||
|
||||
// We need at least one source
|
||||
if p_sources.is_null() {
|
||||
println!("Error getting NDIlib_find_get_current_sources.");
|
||||
::std::process::exit(1);
|
||||
}
|
||||
|
||||
// We need at least one source
|
||||
if p_sources.is_null() {
|
||||
println!("Error getting NDIlib_find_get_current_sources.");
|
||||
::std::process::exit(1);
|
||||
}
|
||||
println!(
|
||||
"no_source {}: Name '{}' Address '{}'",
|
||||
no_sources,
|
||||
CStr::from_ptr((*p_sources).p_ndi_name)
|
||||
.to_string_lossy()
|
||||
.into_owned(),
|
||||
CStr::from_ptr((*p_sources).p_ip_address)
|
||||
.to_string_lossy()
|
||||
.into_owned()
|
||||
);
|
||||
|
||||
println!("no_source {}: Name '{}' Address '{}'",
|
||||
no_sources,
|
||||
CStr::from_ptr((*p_sources).p_ndi_name).to_string_lossy().into_owned(),
|
||||
CStr::from_ptr((*p_sources).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 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
|
||||
let p_ndi_name = CString::new("Galicaster NDI Receiver").unwrap();
|
||||
let NDI_recv_create_desc = NDIlib_recv_create_v3_t {
|
||||
source_to_connect_to: *p_sources,
|
||||
p_ndi_name: p_ndi_name.as_ptr(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
// 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
|
||||
// it will still be provided in BGRA
|
||||
let p_ndi_name = CString::new("Galicaster NDI Receiver").unwrap();
|
||||
let NDI_recv_create_desc = NDIlib_recv_create_v3_t {
|
||||
source_to_connect_to: *p_sources,
|
||||
p_ndi_name: p_ndi_name.as_ptr(),
|
||||
..Default::default()
|
||||
};
|
||||
let pNDI_recv = NDIlib_recv_create_v3(&NDI_recv_create_desc);
|
||||
if pNDI_recv.is_null() {
|
||||
println!("Cannot run NDI: NDIlib_recv_create_v3 error.");
|
||||
::std::process::exit(1);
|
||||
}
|
||||
|
||||
// Destroy the NDI finder. We needed to have access to the pointers to p_sources[0]
|
||||
NDIlib_find_destroy(pNDI_find);
|
||||
|
||||
let pNDI_recv = NDIlib_recv_create_v3(&NDI_recv_create_desc);
|
||||
if pNDI_recv.is_null() {
|
||||
println!("Cannot run NDI: NDIlib_recv_create_v3 error.");
|
||||
::std::process::exit(1);
|
||||
}
|
||||
// We are now going to mark this source as being on program output for tally purposes (but not on preview)
|
||||
let tally_state: NDIlib_tally_t = Default::default();
|
||||
NDIlib_recv_set_tally(pNDI_recv, &tally_state);
|
||||
|
||||
// Destroy the NDI finder. We needed to have access to the pointers to p_sources[0]
|
||||
NDIlib_find_destroy(pNDI_find);
|
||||
// Enable Hardwqre Decompression support if this support has it. Please read the caveats in the documentation
|
||||
// regarding this. There are times in which it might reduce the performance although on small stream numbers
|
||||
// it almost always yields the same or better performance.
|
||||
let data = CString::new("<ndi_hwaccel enabled=\"true\"/>").unwrap();
|
||||
let enable_hw_accel = NDIlib_metadata_frame_t {
|
||||
length: data.to_bytes().len() as i32,
|
||||
timecode: 0,
|
||||
p_data: data.as_ptr(),
|
||||
};
|
||||
|
||||
// We are now going to mark this source as being on program output for tally purposes (but not on preview)
|
||||
let tally_state: NDIlib_tally_t = Default::default();
|
||||
NDIlib_recv_set_tally(pNDI_recv, &tally_state);
|
||||
NDIlib_recv_send_metadata(pNDI_recv, &enable_hw_accel);
|
||||
|
||||
loop {
|
||||
let video_frame: NDIlib_video_frame_v2_t = Default::default();
|
||||
let audio_frame: NDIlib_audio_frame_v2_t = Default::default();
|
||||
let metadata_frame: NDIlib_metadata_frame_t = Default::default();
|
||||
|
||||
// Enable Hardwqre Decompression support if this support has it. Please read the caveats in the documentation
|
||||
// regarding this. There are times in which it might reduce the performance although on small stream numbers
|
||||
// it almost always yields the same or better performance.
|
||||
let data = CString::new("<ndi_hwaccel enabled=\"true\"/>").unwrap();
|
||||
let enable_hw_accel = NDIlib_metadata_frame_t {
|
||||
length: data.to_bytes().len() as i32,
|
||||
timecode: 0,
|
||||
p_data: data.as_ptr(),
|
||||
};
|
||||
|
||||
NDIlib_recv_send_metadata(pNDI_recv, &enable_hw_accel);
|
||||
|
||||
loop {
|
||||
|
||||
let video_frame: NDIlib_video_frame_v2_t = Default::default();
|
||||
let audio_frame: NDIlib_audio_frame_v2_t = Default::default();
|
||||
let metadata_frame: NDIlib_metadata_frame_t = Default::default();
|
||||
|
||||
|
||||
let frame_type = NDIlib_recv_capture_v2(pNDI_recv, &video_frame, &audio_frame, &metadata_frame, 1000);
|
||||
|
||||
|
||||
match frame_type {
|
||||
NDIlib_frame_type_video => {
|
||||
println!("Tengo video {:?}",
|
||||
video_frame
|
||||
);
|
||||
},
|
||||
NDIlib_frame_type_audio => {
|
||||
println!("Tengo audio {:?}",
|
||||
audio_frame
|
||||
);
|
||||
},
|
||||
NDIlib_frame_type_metadata => {
|
||||
println!("Tengo metadata {} '{}'",
|
||||
metadata_frame.length,
|
||||
CStr::from_ptr(metadata_frame.p_data).to_string_lossy().into_owned(),
|
||||
);
|
||||
},
|
||||
NDIlib_frame_type_error => {
|
||||
println!("Tengo error {} '{}'",
|
||||
metadata_frame.length,
|
||||
CStr::from_ptr(metadata_frame.p_data).to_string_lossy().into_owned(),
|
||||
);
|
||||
break;
|
||||
},
|
||||
_ => println!("Tengo {}", frame_type),
|
||||
}
|
||||
|
||||
}
|
||||
let frame_type = NDIlib_recv_capture_v2(
|
||||
pNDI_recv,
|
||||
&video_frame,
|
||||
&audio_frame,
|
||||
&metadata_frame,
|
||||
1000,
|
||||
);
|
||||
|
||||
match frame_type {
|
||||
NDIlib_frame_type_video => {
|
||||
println!("Tengo video {:?}", video_frame);
|
||||
}
|
||||
NDIlib_frame_type_audio => {
|
||||
println!("Tengo audio {:?}", audio_frame);
|
||||
}
|
||||
NDIlib_frame_type_metadata => {
|
||||
println!(
|
||||
"Tengo metadata {} '{}'",
|
||||
metadata_frame.length,
|
||||
CStr::from_ptr(metadata_frame.p_data)
|
||||
.to_string_lossy()
|
||||
.into_owned(),
|
||||
);
|
||||
}
|
||||
NDIlib_frame_type_error => {
|
||||
println!(
|
||||
"Tengo error {} '{}'",
|
||||
metadata_frame.length,
|
||||
CStr::from_ptr(metadata_frame.p_data)
|
||||
.to_string_lossy()
|
||||
.into_owned(),
|
||||
);
|
||||
break;
|
||||
}
|
||||
_ => println!("Tengo {}", frame_type),
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("Exit");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,9 +15,7 @@ extern "C" {
|
|||
pub fn NDIlib_recv_create_v3(
|
||||
p_create_settings: *const NDIlib_recv_create_v3_t,
|
||||
) -> NDIlib_recv_instance_t;
|
||||
pub fn NDIlib_find_destroy(
|
||||
p_instance: NDIlib_find_instance_t,
|
||||
);
|
||||
pub fn NDIlib_find_destroy(p_instance: NDIlib_find_instance_t);
|
||||
pub fn NDIlib_recv_set_tally(
|
||||
p_instance: NDIlib_recv_instance_t,
|
||||
p_tally: *const NDIlib_tally_t,
|
||||
|
@ -47,15 +45,14 @@ pub struct NDIlib_find_create_t {
|
|||
|
||||
impl Default for NDIlib_find_create_t {
|
||||
fn default() -> Self {
|
||||
NDIlib_find_create_t {
|
||||
NDIlib_find_create_t {
|
||||
show_local_sources: true,
|
||||
p_groups: ptr::null(),
|
||||
p_extra_ips: ptr::null()
|
||||
p_extra_ips: ptr::null(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct NDIlib_source_t {
|
||||
|
@ -64,15 +61,14 @@ pub struct NDIlib_source_t {
|
|||
}
|
||||
|
||||
impl Default for NDIlib_source_t {
|
||||
fn default() -> Self {
|
||||
NDIlib_source_t {
|
||||
fn default() -> Self {
|
||||
NDIlib_source_t {
|
||||
p_ndi_name: ptr::null(),
|
||||
p_ip_address: ptr::null()
|
||||
p_ip_address: ptr::null(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//TODO review enum
|
||||
pub type NDIlib_frame_type_e = i32;
|
||||
pub const NDIlib_frame_type_none: NDIlib_frame_type_e = 0;
|
||||
|
@ -82,27 +78,35 @@ pub const NDIlib_frame_type_metadata: NDIlib_frame_type_e = 3;
|
|||
pub const NDIlib_frame_type_error: NDIlib_frame_type_e = 4;
|
||||
pub const NDIlib_frame_type_status_change: NDIlib_frame_type_e = 100;
|
||||
|
||||
|
||||
pub type NDIlib_recv_bandwidth_e = i32;
|
||||
pub const NDIlib_recv_bandwidth_e_NDIlib_recv_bandwidth_metadata_only: NDIlib_recv_bandwidth_e = -10;
|
||||
pub const NDIlib_recv_bandwidth_e_NDIlib_recv_bandwidth_metadata_only: NDIlib_recv_bandwidth_e =
|
||||
-10;
|
||||
pub const NDIlib_recv_bandwidth_e_NDIlib_recv_bandwidth_audio_only: NDIlib_recv_bandwidth_e = 10;
|
||||
pub const NDIlib_recv_bandwidth_e_NDIlib_recv_bandwidth_lowest: NDIlib_recv_bandwidth_e = 0;
|
||||
pub const NDIlib_recv_bandwidth_e_NDIlib_recv_bandwidth_highest: NDIlib_recv_bandwidth_e = 100;
|
||||
|
||||
|
||||
pub type NDIlib_recv_color_format_e = u32;
|
||||
pub const NDIlib_recv_color_format_e_NDIlib_recv_color_format_BGRX_BGRA: NDIlib_recv_color_format_e = 0;
|
||||
pub const NDIlib_recv_color_format_e_NDIlib_recv_color_format_UYVY_BGRA: NDIlib_recv_color_format_e = 1;
|
||||
pub const NDIlib_recv_color_format_e_NDIlib_recv_color_format_RGBX_RGBA: NDIlib_recv_color_format_e = 2;
|
||||
pub const NDIlib_recv_color_format_e_NDIlib_recv_color_format_UYVY_RGBA: NDIlib_recv_color_format_e = 3;
|
||||
pub const NDIlib_recv_color_format_e_NDIlib_recv_color_format_fastest: NDIlib_recv_color_format_e = 100;
|
||||
pub const NDIlib_recv_color_format_e_NDIlib_recv_color_format_e_BGRX_BGRA: NDIlib_recv_color_format_e = 0;
|
||||
pub const NDIlib_recv_color_format_e_NDIlib_recv_color_format_e_UYVY_BGRA: NDIlib_recv_color_format_e = 1;
|
||||
pub const NDIlib_recv_color_format_e_NDIlib_recv_color_format_e_RGBX_RGBA: NDIlib_recv_color_format_e = 2;
|
||||
pub const NDIlib_recv_color_format_e_NDIlib_recv_color_format_e_UYVY_RGBA: NDIlib_recv_color_format_e = 3;
|
||||
pub const NDIlib_recv_color_format_e_NDIlib_recv_color_format_BGRX_BGRA:
|
||||
NDIlib_recv_color_format_e = 0;
|
||||
pub const NDIlib_recv_color_format_e_NDIlib_recv_color_format_UYVY_BGRA:
|
||||
NDIlib_recv_color_format_e = 1;
|
||||
pub const NDIlib_recv_color_format_e_NDIlib_recv_color_format_RGBX_RGBA:
|
||||
NDIlib_recv_color_format_e = 2;
|
||||
pub const NDIlib_recv_color_format_e_NDIlib_recv_color_format_UYVY_RGBA:
|
||||
NDIlib_recv_color_format_e = 3;
|
||||
pub const NDIlib_recv_color_format_e_NDIlib_recv_color_format_fastest: NDIlib_recv_color_format_e =
|
||||
100;
|
||||
pub const NDIlib_recv_color_format_e_NDIlib_recv_color_format_e_BGRX_BGRA:
|
||||
NDIlib_recv_color_format_e = 0;
|
||||
pub const NDIlib_recv_color_format_e_NDIlib_recv_color_format_e_UYVY_BGRA:
|
||||
NDIlib_recv_color_format_e = 1;
|
||||
pub const NDIlib_recv_color_format_e_NDIlib_recv_color_format_e_RGBX_RGBA:
|
||||
NDIlib_recv_color_format_e = 2;
|
||||
pub const NDIlib_recv_color_format_e_NDIlib_recv_color_format_e_UYVY_RGBA:
|
||||
NDIlib_recv_color_format_e = 3;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug,Copy,Clone)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct NDIlib_recv_create_v3_t {
|
||||
pub source_to_connect_to: NDIlib_source_t,
|
||||
pub color_format: NDIlib_recv_color_format_e,
|
||||
|
@ -112,22 +116,21 @@ pub struct NDIlib_recv_create_v3_t {
|
|||
}
|
||||
|
||||
impl Default for NDIlib_recv_create_v3_t {
|
||||
fn default() -> Self {
|
||||
fn default() -> Self {
|
||||
NDIlib_recv_create_v3_t {
|
||||
source_to_connect_to: Default::default(),
|
||||
allow_video_fields: true,
|
||||
bandwidth: NDIlib_recv_bandwidth_e_NDIlib_recv_bandwidth_highest,
|
||||
color_format: NDIlib_recv_color_format_e_NDIlib_recv_color_format_UYVY_BGRA,
|
||||
p_ndi_name: ptr::null()
|
||||
p_ndi_name: ptr::null(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type NDIlib_recv_instance_t = *mut ::std::os::raw::c_void;
|
||||
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug,Copy,Clone)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct NDIlib_tally_t {
|
||||
pub on_program: bool,
|
||||
pub on_preview: bool,
|
||||
|
@ -137,34 +140,31 @@ impl Default for NDIlib_tally_t {
|
|||
fn default() -> Self {
|
||||
NDIlib_tally_t {
|
||||
on_program: false,
|
||||
on_preview: false
|
||||
on_preview: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug,Copy,Clone)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct NDIlib_metadata_frame_t {
|
||||
pub length: ::std::os::raw::c_int,
|
||||
pub timecode: i64,
|
||||
pub timecode: i64,
|
||||
pub p_data: *const ::std::os::raw::c_char,
|
||||
}
|
||||
|
||||
|
||||
impl Default for NDIlib_metadata_frame_t {
|
||||
fn default() -> Self {
|
||||
NDIlib_metadata_frame_t {
|
||||
length: 0,
|
||||
timecode: 0, //NDIlib_send_timecode_synthesize,
|
||||
p_data: ptr::null()
|
||||
p_data: ptr::null(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug,Copy,Clone)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct NDIlib_video_frame_v2_t {
|
||||
pub xres: ::std::os::raw::c_int,
|
||||
pub yres: ::std::os::raw::c_int,
|
||||
|
@ -190,18 +190,17 @@ impl Default for NDIlib_video_frame_v2_t {
|
|||
frame_rate_D: 0,
|
||||
picture_aspect_ratio: 0.0,
|
||||
frame_format_type: 0,
|
||||
timecode: 0, //NDIlib_send_timecode_synthesize,
|
||||
timecode: 0, //NDIlib_send_timecode_synthesize,
|
||||
p_data: ptr::null(),
|
||||
line_stride_in_bytes: 0,
|
||||
p_metadata: ptr::null(),
|
||||
timestamp: 0
|
||||
timestamp: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug,Copy,Clone)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct NDIlib_audio_frame_v2_t {
|
||||
pub sample_rate: ::std::os::raw::c_int,
|
||||
pub no_channels: ::std::os::raw::c_int,
|
||||
|
@ -223,7 +222,7 @@ impl Default for NDIlib_audio_frame_v2_t {
|
|||
p_data: ptr::null(),
|
||||
channel_stride_in_bytes: 0,
|
||||
p_metadata: ptr::null(),
|
||||
timestamp: 0
|
||||
timestamp: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue