feat: update wivrn config to new spec

This commit is contained in:
Gabriele Musco 2024-03-05 07:55:24 +01:00
parent 03de81d2fb
commit 65dcded5c7
No known key found for this signature in database
GPG key ID: 1068D795C80E51DE
4 changed files with 52 additions and 54 deletions

View file

@ -79,8 +79,6 @@ pub struct WivrnConfEncoder {
pub encoder: Encoder,
pub codec: Codec,
#[serde(skip_serializing_if = "Option::is_none")]
pub bitrate: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub width: Option<f32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub height: Option<f32>,
@ -97,11 +95,10 @@ impl Default for WivrnConfEncoder {
Self {
encoder: Encoder::X264,
codec: Codec::H264,
bitrate: None,
width: None,
height: None,
offset_x: None,
offset_y: None,
width: Some(1.0),
height: Some(1.0),
offset_x: Some(0.0),
offset_y: Some(0.0),
group: None,
}
}
@ -111,6 +108,8 @@ impl Default for WivrnConfEncoder {
pub struct WivrnConfig {
#[serde(skip_serializing_if = "Option::is_none")]
pub scale: Option<[f32; 2]>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bitrate: Option<u32>,
pub encoders: Vec<WivrnConfEncoder>,
}
@ -118,16 +117,8 @@ impl Default for WivrnConfig {
fn default() -> Self {
Self {
scale: Some([0.8, 0.8]),
encoders: vec![WivrnConfEncoder {
encoder: Encoder::X264,
codec: Codec::H264,
bitrate: Some(100000000),
width: Some(1.0),
height: Some(1.0),
offset_x: Some(0.0),
offset_y: Some(0.0),
group: None,
}],
bitrate: Some(50000000),
encoders: vec![WivrnConfEncoder::default()],
}
}
}
@ -167,7 +158,7 @@ mod tests {
assert_eq!(conf.encoders.len(), 1);
assert_eq!(conf.encoders.get(0).unwrap().encoder, Encoder::X264);
assert_eq!(conf.encoders.get(0).unwrap().codec, Codec::H264);
assert_eq!(conf.encoders.get(0).unwrap().bitrate, Some(100000000));
assert_eq!(conf.bitrate, Some(100000000));
assert_eq!(conf.encoders.get(0).unwrap().width, Some(1.0));
assert_eq!(conf.encoders.get(0).unwrap().height, Some(1.0));
assert_eq!(conf.encoders.get(0).unwrap().offset_x, Some(0.0));

View file

@ -22,7 +22,6 @@ pub struct WivrnEncoderModel {
pub enum WivrnEncoderModelMsg {
EncoderChanged(u32),
CodecChanged(u32),
BitrateChanged(Option<u32>),
WidthChanged(Option<f32>),
HeightChanged(Option<f32>),
OffsetXChanged(Option<f32>),
@ -85,33 +84,6 @@ impl AsyncFactoryComponent for WivrnEncoderModel {
}
}
) -> adw::ComboRow,
add: bitrate_row = &number_entry_row(
"Bitrate (Mbps)",
&self.encoder_conf.bitrate
.and_then(|n| if let Some(mbits) = bits_to_mbits(n) {
Some(mbits.to_string())
} else {
None
})
.unwrap_or_default(),
false,
{
let sender = sender.clone();
move |row| {
let txt = row.text();
sender.input(Self::Input::BitrateChanged(
if txt.is_empty() {
None
} else {
match txt.parse::<u32>() {
Ok(bits) => bits_from_mbits(bits),
Err(e) => None,
}
}
));
}
}
) -> adw::EntryRow,
add: width_row = &spin_row(
"Width",
None,
@ -203,9 +175,6 @@ impl AsyncFactoryComponent for WivrnEncoderModel {
Self::Input::CodecChanged(idx) => {
self.encoder_conf.codec = Codec::as_vec().get(idx as usize).unwrap().clone();
}
Self::Input::BitrateChanged(val) => {
self.encoder_conf.bitrate = val;
}
Self::Input::WidthChanged(val) => {
self.encoder_conf.width = val;
}

View file

@ -1,7 +1,13 @@
use super::factories::wivrn_encoder_group_factory::{WivrnEncoderModel, WivrnEncoderModelInit};
use super::{
factories::wivrn_encoder_group_factory::{WivrnEncoderModel, WivrnEncoderModelInit},
util::bits_from_mbits,
};
use crate::{
file_builders::wivrn_config::{dump_wivrn_config, get_wivrn_config, WivrnConfig},
ui::preference_rows::spin_row,
ui::{
preference_rows::{number_entry_row, spin_row},
util::bits_to_mbits,
},
};
use adw::prelude::*;
use relm4::{factory::AsyncFactoryVecDeque, prelude::*};
@ -17,6 +23,8 @@ pub struct WivrnConfEditor {
pub scalex_row: Option<adw::SpinRow>,
#[tracker::do_not_track]
pub scaley_row: Option<adw::SpinRow>,
#[tracker::do_not_track]
bitrate_row: Option<adw::EntryRow>,
}
#[derive(Debug)]
@ -101,6 +109,24 @@ impl SimpleComponent for WivrnConfEditor {
move |_| {}
) -> adw::SpinRow,
},
add: bitrategrp = &adw::PreferencesGroup {
set_title: "Bitrate",
add: bitrate_row = &number_entry_row(
"Bitrate (Mbps)",
&model.conf.bitrate
.and_then(|n| if let Some(mbits) = bits_to_mbits(n) {
Some(mbits.to_string())
} else {
None
})
.unwrap_or_default(),
false,
{
let sender = sender.clone();
move |_| {}
}
) -> adw::EntryRow,
},
add: encodersrgp = &adw::PreferencesGroup {
set_title: "Encoders",
adw::ActionRow {
@ -133,8 +159,18 @@ impl SimpleComponent for WivrnConfEditor {
Self::Input::Save => {
let x = self.scalex_row.as_ref().unwrap().adjustment().value();
let y = self.scaley_row.as_ref().unwrap().adjustment().value();
Some([x as f32, y as f32]);
self.conf.scale = Some([x as f32, y as f32]);
self.conf.bitrate = {
let txt = self.bitrate_row.as_ref().unwrap().text();
if txt.is_empty() {
None
} else {
match txt.parse::<u32>() {
Ok(mbits) => bits_from_mbits(mbits),
Err(_) => None,
}
}
};
self.conf.encoders = self
.encoder_models
.as_ref()
@ -180,6 +216,7 @@ impl SimpleComponent for WivrnConfEditor {
win: None,
scalex_row: None,
scaley_row: None,
bitrate_row: None,
tracker: 0,
};
@ -187,6 +224,7 @@ impl SimpleComponent for WivrnConfEditor {
model.scalex_row = Some(widgets.scalex_row.clone());
model.scaley_row = Some(widgets.scaley_row.clone());
model.bitrate_row = Some(widgets.bitrate_row.clone());
let mut encoder_models: AsyncFactoryVecDeque<WivrnEncoderModel> =
AsyncFactoryVecDeque::new(widgets.pref_page.clone(), sender.input_sender());

View file

@ -1,10 +1,10 @@
{
"scale": [0.8, 0.8],
"bitrate": 100000000,
"encoders": [
{
"encoder": "x264",
"codec": "h264",
"bitrate": 100000000,
"width": 1.0,
"height": 1.0,
"offset_x": 0.0,