Print metadata recv

This commit is contained in:
rubenrua 2018-04-05 09:56:38 +02:00
parent 864e9b4520
commit ef508c39d1

View file

@ -23,6 +23,17 @@ extern "C" {
p_instance: NDIlib_recv_instance_t,
p_tally: *const NDIlib_tally_t,
) -> bool;
pub fn NDIlib_recv_send_metadata(
p_instance: NDIlib_recv_instance_t,
p_metadata: *const NDIlib_metadata_frame_t,
) -> bool;
pub fn NDIlib_recv_capture_v2(
p_instance: NDIlib_recv_instance_t,
p_video_data: *const NDIlib_video_frame_v2_t,
p_audio_data: *const NDIlib_audio_frame_v2_t,
p_metadata: *const NDIlib_metadata_frame_t,
timeout_in_ms: u32,
) -> NDIlib_frame_type_e;
}
pub type NDIlib_find_instance_t = *mut ::std::os::raw::c_void;
@ -44,23 +55,32 @@ pub struct NDIlib_source_t {
//TODO review enum
pub type NDIlib_frame_type_e = i32;
pub const NDIlib_frame_type_none: NDIlib_frame_type_e = 0;
pub const NDIlib_frame_type_video: NDIlib_frame_type_e = 1;
pub const NDIlib_frame_type_audio: NDIlib_frame_type_e = 2;
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_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 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)]
@ -87,7 +107,38 @@ pub struct NDIlib_tally_t {
pub struct NDIlib_metadata_frame_t {
pub length: ::std::os::raw::c_int,
pub timecode: i64,
pub p_data: *mut ::std::os::raw::c_char,
pub p_data: *const ::std::os::raw::c_char,
}
#[repr(C)]
#[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,
pub FourCC: u32, //TODO enum
pub frame_rate_N: ::std::os::raw::c_int,
pub frame_rate_D: ::std::os::raw::c_int,
pub picture_aspect_ratio: ::std::os::raw::c_float,
pub frame_format_type: u32, //TODO enum
pub timecode: i64,
pub p_data: *const ::std::os::raw::c_char,
pub line_stride_in_bytes: ::std::os::raw::c_int,
pub p_metadata: *const ::std::os::raw::c_char,
pub timestamp: i64,
}
#[repr(C)]
#[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,
pub no_samples: ::std::os::raw::c_int,
pub timecode: i64,
pub p_data: *const ::std::os::raw::c_float,
pub channel_stride_in_bytes: ::std::os::raw::c_int,
pub p_metadata: *const ::std::os::raw::c_char,
pub timestamp: i64,
}
@ -163,15 +214,64 @@ fn main() {
// 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.
/*
NDIlib_metadata_frame_t enable_hw_accel;
enable_hw_accel.p_data = "<ndi_hwaccel enabled=\"true\"/>";
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 {
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 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);
match frame_type {
NDIlib_frame_type_metadata => {
println!("Tengo 3 {} '{}'",
metadata_frame.length,
CStr::from_ptr(metadata_frame.p_data).to_string_lossy().into_owned(),
);
},
_ => println!("Tengo {}", frame_type),
}
}
}
println!("Hello, world!");