mirror of
https://github.com/mii443/maudio-router.git
synced 2025-08-23 00:15:37 +00:00
config loading
This commit is contained in:
@ -1,3 +1,5 @@
|
|||||||
|
use std::io::Read;
|
||||||
|
|
||||||
use crate::args::Run;
|
use crate::args::Run;
|
||||||
|
|
||||||
fn reshape_audio_data<T>(input: &[T], channels: usize) -> Vec<Vec<T>>
|
fn reshape_audio_data<T>(input: &[T], channels: usize) -> Vec<Vec<T>>
|
||||||
@ -28,6 +30,25 @@ where
|
|||||||
output
|
output
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(args: Run) {
|
pub fn run(run: Run) {
|
||||||
|
let config = std::path::Path::new(&run.config);
|
||||||
|
|
||||||
}
|
if !config.exists() {
|
||||||
|
eprintln!("Config file does not exists.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut buf = String::default();
|
||||||
|
let mut config = if let Ok(config) = std::fs::File::open(&config) {
|
||||||
|
config
|
||||||
|
} else {
|
||||||
|
eprintln!("Cannot open config file.");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
config.read_to_string(&mut buf).unwrap();
|
||||||
|
|
||||||
|
let config: crate::config::Config = serde_yaml::from_str(&buf).unwrap();
|
||||||
|
|
||||||
|
println!("{:?}", config);
|
||||||
|
}
|
||||||
|
@ -1,52 +1,52 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
struct RoutesConfig {
|
pub struct Config {
|
||||||
routes: Routes,
|
pub routes: Routes,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
struct Routes {
|
pub struct Routes {
|
||||||
input: Vec<Input>,
|
pub input: Vec<Input>,
|
||||||
output: Vec<Output>,
|
pub output: Vec<Output>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
struct Input {
|
pub struct Input {
|
||||||
name: String,
|
pub name: String,
|
||||||
virtual_device: String,
|
pub virtual_device: String,
|
||||||
device: Device,
|
pub device: Device,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
struct Output {
|
pub struct Output {
|
||||||
name: String,
|
pub name: String,
|
||||||
input: OutputInput,
|
pub input: OutputInput,
|
||||||
device: Device,
|
pub device: Device,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
struct OutputInput {
|
pub struct OutputInput {
|
||||||
virtual_device: String,
|
pub virtual_device: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
enum Device {
|
pub enum Device {
|
||||||
Local { local: LocalDevice },
|
Local { local: LocalDevice },
|
||||||
Remote { remote: RemoteDevice },
|
Remote { remote: RemoteDevice },
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
struct LocalDevice {
|
pub struct LocalDevice {
|
||||||
name: String,
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
struct RemoteDevice {
|
pub struct RemoteDevice {
|
||||||
address: String,
|
pub address: String,
|
||||||
port: u16,
|
pub port: u16,
|
||||||
protocol: String,
|
pub protocol: String,
|
||||||
buffer: usize,
|
pub buffer: usize,
|
||||||
channels: u8,
|
pub channels: u8,
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user