Execute rustfmt

This commit is contained in:
rubenrua 2018-04-10 17:53:49 +02:00
parent 20b6ae5ff6
commit 98db99924e
2 changed files with 142 additions and 140 deletions

View file

@ -1,14 +1,12 @@
#![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() {
@ -31,17 +29,21 @@ fn main() {
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);
}
println!("no_source {}: Name '{}' Address '{}'",
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()
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.
@ -54,7 +56,6 @@ fn main() {
..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.");
@ -68,7 +69,6 @@ fn main() {
let tally_state: NDIlib_tally_t = Default::default();
NDIlib_recv_set_tally(pNDI_recv, &tally_state);
// 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.
@ -82,44 +82,47 @@ fn main() {
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);
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
);
},
println!("Tengo video {:?}", video_frame);
}
NDIlib_frame_type_audio => {
println!("Tengo audio {:?}",
audio_frame
);
},
println!("Tengo audio {:?}", audio_frame);
}
NDIlib_frame_type_metadata => {
println!("Tengo metadata {} '{}'",
println!(
"Tengo metadata {} '{}'",
metadata_frame.length,
CStr::from_ptr(metadata_frame.p_data).to_string_lossy().into_owned(),
CStr::from_ptr(metadata_frame.p_data)
.to_string_lossy()
.into_owned(),
);
},
}
NDIlib_frame_type_error => {
println!("Tengo error {} '{}'",
println!(
"Tengo error {} '{}'",
metadata_frame.length,
CStr::from_ptr(metadata_frame.p_data).to_string_lossy().into_owned(),
CStr::from_ptr(metadata_frame.p_data)
.to_string_lossy()
.into_owned(),
);
break;
},
}
_ => println!("Tengo {}", frame_type),
}
}
}
println!("Exit");
}

View file

@ -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,
@ -50,12 +48,11 @@ impl Default for 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 {
@ -67,12 +64,11 @@ impl Default for 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,
@ -118,16 +122,15 @@ impl Default for NDIlib_recv_create_v3_t {
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 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,
@ -194,14 +194,13 @@ impl Default for NDIlib_video_frame_v2_t {
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,
}
}
}