Use Default Trait

The default values must be reviewed
This commit is contained in:
rubenrua 2018-04-10 17:49:21 +02:00
parent 8d99d47f81
commit 20b6ae5ff6
2 changed files with 98 additions and 45 deletions

View file

@ -18,11 +18,7 @@ fn main() {
}
//TODO valores por defecto
let NDI_find_create_desc = NDIlib_find_create_t {
show_local_sources: false,
p_groups: ptr::null(),
p_extra_ips: ptr::null()
};
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.");
@ -54,10 +50,8 @@ fn main() {
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,
allow_video_fields: true,
bandwidth: NDIlib_recv_bandwidth_e_NDIlib_recv_bandwidth_highest,
color_format: NDIlib_recv_color_format_e_NDIlib_recv_color_format_BGRX_BGRA,
p_ndi_name: p_ndi_name.as_ptr(), //ptr::null(),
p_ndi_name: p_ndi_name.as_ptr(),
..Default::default()
};
@ -71,10 +65,7 @@ fn main() {
NDIlib_find_destroy(pNDI_find);
// 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 {
on_program: true,
on_preview: true,
};
let tally_state: NDIlib_tally_t = Default::default();
NDIlib_recv_set_tally(pNDI_recv, &tally_state);
@ -92,39 +83,11 @@ fn main() {
loop {
let video_frame = NDIlib_video_frame_v2_t {
xres: 0,
yres: 0,
FourCC: 0,
frame_rate_N: 0,
frame_rate_D: 0,
picture_aspect_ratio: 0.0,
frame_format_type: 0,
timecode: 0,
p_data: ptr::null(),
line_stride_in_bytes: 0,
p_metadata: ptr::null(),
timestamp: 0,
};
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 audio_frame = NDIlib_audio_frame_v2_t {
sample_rate: 0,
no_channels: 0,
no_samples: 0,
timecode: 0,
p_data: ptr::null(),
channel_stride_in_bytes: 0,
p_metadata: ptr::null(),
timestamp: 0,
};
let metadata_frame = NDIlib_metadata_frame_t {
length: 0,
timecode: 0,
p_data: ptr::null(),
};
let frame_type = NDIlib_recv_capture_v2(pNDI_recv, &video_frame, &audio_frame, &metadata_frame, 1000);

View file

@ -1,5 +1,7 @@
#![allow(non_camel_case_types, non_upper_case_globals)]
use std::ptr;
#[link(name = "ndi")]
extern "C" {
pub fn NDIlib_initialize() -> bool;
@ -43,6 +45,17 @@ pub struct NDIlib_find_create_t {
pub p_extra_ips: *const ::std::os::raw::c_char,
}
impl Default for NDIlib_find_create_t {
fn default() -> Self {
NDIlib_find_create_t {
show_local_sources: true,
p_groups: ptr::null(),
p_extra_ips: ptr::null()
}
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct NDIlib_source_t {
@ -50,6 +63,15 @@ pub struct NDIlib_source_t {
pub p_ip_address: *const ::std::os::raw::c_char,
}
impl Default for NDIlib_source_t {
fn default() -> Self {
NDIlib_source_t {
p_ndi_name: ptr::null(),
p_ip_address: ptr::null()
}
}
}
//TODO review enum
pub type NDIlib_frame_type_e = i32;
@ -89,6 +111,18 @@ pub struct NDIlib_recv_create_v3_t {
pub p_ndi_name: *const ::std::os::raw::c_char,
}
impl Default for NDIlib_recv_create_v3_t {
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()
}
}
}
pub type NDIlib_recv_instance_t = *mut ::std::os::raw::c_void;
@ -99,6 +133,15 @@ pub struct NDIlib_tally_t {
pub on_preview: bool,
}
impl Default for NDIlib_tally_t {
fn default() -> Self {
NDIlib_tally_t {
on_program: false,
on_preview: false
}
}
}
#[repr(C)]
#[derive(Debug,Copy,Clone)]
pub struct NDIlib_metadata_frame_t {
@ -107,6 +150,19 @@ pub struct NDIlib_metadata_frame_t {
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()
}
}
}
#[repr(C)]
#[derive(Debug,Copy,Clone)]
pub struct NDIlib_video_frame_v2_t {
@ -124,6 +180,25 @@ pub struct NDIlib_video_frame_v2_t {
pub timestamp: i64,
}
impl Default for NDIlib_video_frame_v2_t {
fn default() -> Self {
NDIlib_video_frame_v2_t {
xres: 0,
yres: 0,
FourCC: 0,
frame_rate_N: 0,
frame_rate_D: 0,
picture_aspect_ratio: 0.0,
frame_format_type: 0,
timecode: 0, //NDIlib_send_timecode_synthesize,
p_data: ptr::null(),
line_stride_in_bytes: 0,
p_metadata: ptr::null(),
timestamp: 0
}
}
}
#[repr(C)]
#[derive(Debug,Copy,Clone)]
@ -137,3 +212,18 @@ pub struct NDIlib_audio_frame_v2_t {
pub p_metadata: *const ::std::os::raw::c_char,
pub timestamp: i64,
}
impl Default for NDIlib_audio_frame_v2_t {
fn default() -> Self {
NDIlib_audio_frame_v2_t {
sample_rate: 48000,
no_channels: 2,
no_samples: 0,
timecode: 0, //NDIlib_send_timecode_synthesize,
p_data: ptr::null(),
channel_stride_in_bytes: 0,
p_metadata: ptr::null(),
timestamp: 0
}
}
}