Allow selecting the receive color format in the source

This commit is contained in:
Sebastian Dröge 2021-10-01 10:17:57 +03:00
parent ce45f5a673
commit b98efea5aa
3 changed files with 61 additions and 1 deletions

View file

@ -36,6 +36,37 @@ pub enum TimestampMode {
ReceiveTime = 4, ReceiveTime = 4,
} }
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy, glib::GEnum)]
#[repr(u32)]
#[genum(type_name = "GstNdiRecvColorFormat")]
pub enum RecvColorFormat {
#[genum(name = "BGRX or BGRA", nick = "bgrx-bgra")]
BgrxBgra = 0,
#[genum(name = "UYVY or BGRA", nick = "uyvy-bgra")]
UyvyBgra = 1,
#[genum(name = "RGBX or RGBA", nick = "rgbx-rgba")]
RgbxRgba = 2,
#[genum(name = "UYVY or RGBA", nick = "uyvy-rgba")]
UyvyRgba = 3,
#[genum(name = "Fastest", nick = "fastest")]
Fastest = 4,
#[genum(name = "Best", nick = "best")]
Best = 5,
}
impl From<RecvColorFormat> for NDIlib_recv_color_format_e {
fn from(v: RecvColorFormat) -> Self {
match v {
RecvColorFormat::BgrxBgra => NDIlib_recv_color_format_BGRX_BGRA,
RecvColorFormat::UyvyBgra => NDIlib_recv_color_format_UYVY_BGRA,
RecvColorFormat::RgbxRgba => NDIlib_recv_color_format_RGBX_RGBA,
RecvColorFormat::UyvyRgba => NDIlib_recv_color_format_UYVY_RGBA,
RecvColorFormat::Fastest => NDIlib_recv_color_format_fastest,
RecvColorFormat::Best => NDIlib_recv_color_format_best,
}
}
}
fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> { fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
if !ndi::initialize() { if !ndi::initialize() {
return Err(glib::bool_error!("Cannot initialize NDI")); return Err(glib::bool_error!("Cannot initialize NDI"));

View file

@ -17,6 +17,7 @@ use crate::Buffer;
use crate::Receiver; use crate::Receiver;
use crate::ReceiverControlHandle; use crate::ReceiverControlHandle;
use crate::ReceiverItem; use crate::ReceiverItem;
use crate::RecvColorFormat;
use crate::TimestampMode; use crate::TimestampMode;
use crate::DEFAULT_RECEIVER_NDI_NAME; use crate::DEFAULT_RECEIVER_NDI_NAME;
@ -37,6 +38,7 @@ struct Settings {
max_queue_length: u32, max_queue_length: u32,
receiver_ndi_name: String, receiver_ndi_name: String,
bandwidth: ndisys::NDIlib_recv_bandwidth_e, bandwidth: ndisys::NDIlib_recv_bandwidth_e,
color_format: RecvColorFormat,
timestamp_mode: TimestampMode, timestamp_mode: TimestampMode,
} }
@ -50,6 +52,7 @@ impl Default for Settings {
timeout: 5000, timeout: 5000,
max_queue_length: 10, max_queue_length: 10,
bandwidth: ndisys::NDIlib_recv_bandwidth_highest, bandwidth: ndisys::NDIlib_recv_bandwidth_highest,
color_format: RecvColorFormat::UyvyBgra,
timestamp_mode: TimestampMode::ReceiveTimeTimecode, timestamp_mode: TimestampMode::ReceiveTimeTimecode,
} }
} }
@ -159,6 +162,14 @@ impl ObjectImpl for NdiSrc {
100, 100,
glib::ParamFlags::READWRITE, glib::ParamFlags::READWRITE,
), ),
glib::ParamSpec::new_enum(
"color-format",
"Color Format",
"Receive color format",
RecvColorFormat::static_type(),
RecvColorFormat::UyvyBgra as u32 as i32,
glib::ParamFlags::READWRITE,
),
glib::ParamSpec::new_enum( glib::ParamSpec::new_enum(
"timestamp-mode", "timestamp-mode",
"Timestamp Mode", "Timestamp Mode",
@ -275,6 +286,18 @@ impl ObjectImpl for NdiSrc {
); );
settings.bandwidth = bandwidth; settings.bandwidth = bandwidth;
} }
"color-format" => {
let mut settings = self.settings.lock().unwrap();
let color_format = value.get().unwrap();
gst_debug!(
CAT,
obj: obj,
"Changing color format from {:?} to {:?}",
settings.color_format,
color_format,
);
settings.color_format = color_format;
}
"timestamp-mode" => { "timestamp-mode" => {
let mut settings = self.settings.lock().unwrap(); let mut settings = self.settings.lock().unwrap();
let timestamp_mode = value.get().unwrap(); let timestamp_mode = value.get().unwrap();
@ -324,6 +347,10 @@ impl ObjectImpl for NdiSrc {
let settings = self.settings.lock().unwrap(); let settings = self.settings.lock().unwrap();
settings.bandwidth.to_value() settings.bandwidth.to_value()
} }
"color-format" => {
let settings = self.settings.lock().unwrap();
settings.color_format.to_value()
}
"timestamp-mode" => { "timestamp-mode" => {
let settings = self.settings.lock().unwrap(); let settings = self.settings.lock().unwrap();
settings.timestamp_mode.to_value() settings.timestamp_mode.to_value()
@ -432,6 +459,7 @@ impl BaseSrcImpl for NdiSrc {
&settings.receiver_ndi_name, &settings.receiver_ndi_name,
settings.connect_timeout, settings.connect_timeout,
settings.bandwidth, settings.bandwidth,
settings.color_format.into(),
settings.timestamp_mode, settings.timestamp_mode,
settings.timeout, settings.timeout,
settings.max_queue_length as usize, settings.max_queue_length as usize,

View file

@ -445,6 +445,7 @@ impl Receiver {
receiver_ndi_name: &str, receiver_ndi_name: &str,
connect_timeout: u32, connect_timeout: u32,
bandwidth: NDIlib_recv_bandwidth_e, bandwidth: NDIlib_recv_bandwidth_e,
color_format: NDIlib_recv_color_format_e,
timestamp_mode: TimestampMode, timestamp_mode: TimestampMode,
timeout: u32, timeout: u32,
max_queue_length: usize, max_queue_length: usize,
@ -465,7 +466,7 @@ impl Receiver {
// broken with interlaced content currently // broken with interlaced content currently
let recv = RecvInstance::builder(ndi_name, url_address, receiver_ndi_name) let recv = RecvInstance::builder(ndi_name, url_address, receiver_ndi_name)
.bandwidth(bandwidth) .bandwidth(bandwidth)
.color_format(NDIlib_recv_color_format_UYVY_BGRA) .color_format(color_format)
.allow_video_fields(true) .allow_video_fields(true)
.build(); .build();
let recv = match recv { let recv = match recv {