mirror of
https://github.com/haileys/bark
synced 2025-03-17 07:07:00 +00:00
add format config option
This commit is contained in:
parent
613c1c8dc8
commit
55fee19af2
2 changed files with 46 additions and 2 deletions
|
@ -1,8 +1,11 @@
|
|||
use std::env;
|
||||
use std::fmt::Display;
|
||||
use std::net::SocketAddr;
|
||||
use std::path::Path;
|
||||
use std::str::FromStr;
|
||||
|
||||
use serde::Deserialize;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Config {
|
||||
|
@ -18,6 +21,39 @@ pub struct Source {
|
|||
#[serde(default)]
|
||||
input: Device,
|
||||
delay_ms: Option<u64>,
|
||||
format: Option<Format>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum Format {
|
||||
S16LE,
|
||||
F32LE,
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
#[error("unknown format")]
|
||||
pub struct UnknownFormat;
|
||||
|
||||
impl FromStr for Format {
|
||||
type Err = UnknownFormat;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"s16le" => Ok(Format::S16LE),
|
||||
"f32le" => Ok(Format::F32LE),
|
||||
_ => Err(UnknownFormat),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Format {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Format::S16LE => write!(f, "s16le"),
|
||||
Format::F32LE => write!(f, "f32le"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Default)]
|
||||
|
@ -33,9 +69,13 @@ pub struct Device {
|
|||
buffer: Option<u64>,
|
||||
}
|
||||
|
||||
fn set_env<T: ToString>(name: &str, value: T) {
|
||||
env::set_var(name, value.to_string());
|
||||
}
|
||||
|
||||
fn set_env_option<T: ToString>(name: &str, value: Option<T>) {
|
||||
if let Some(value) = value {
|
||||
env::set_var(name, value.to_string());
|
||||
set_env(name, value)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,6 +85,7 @@ pub fn load_into_env(config: &Config) {
|
|||
set_env_option("BARK_SOURCE_INPUT_DEVICE", config.source.input.device.as_ref());
|
||||
set_env_option("BARK_SOURCE_INPUT_PERIOD", config.source.input.period);
|
||||
set_env_option("BARK_SOURCE_INPUT_BUFFER", config.source.input.buffer);
|
||||
set_env_option("BARK_SOURCE_FORMAT", config.source.format.as_ref());
|
||||
set_env_option("BARK_RECEIVE_OUTPUT_DEVICE", config.receive.output.device.as_ref());
|
||||
set_env_option("BARK_RECEIVE_OUTPUT_PERIOD", config.receive.output.period);
|
||||
set_env_option("BARK_RECEIVE_OUTPUT_BUFFER", config.receive.output.buffer);
|
||||
|
|
|
@ -11,7 +11,7 @@ use bark_protocol::types::{TimestampMicros, AudioPacketHeader, SessionId, Receiv
|
|||
use crate::audio::config::{DeviceOpt, DEFAULT_PERIOD, DEFAULT_BUFFER};
|
||||
use crate::audio::input::Input;
|
||||
use crate::socket::{Socket, SocketOpt, ProtocolSocket};
|
||||
use crate::{stats, time};
|
||||
use crate::{stats, time, config};
|
||||
use crate::RunError;
|
||||
|
||||
#[derive(StructOpt)]
|
||||
|
@ -37,6 +37,9 @@ pub struct StreamOpt {
|
|||
default_value = "20",
|
||||
)]
|
||||
pub delay_ms: u64,
|
||||
|
||||
#[structopt(long, env = "BARK_SOURCE_FORMAT")]
|
||||
pub format: config::Format,
|
||||
}
|
||||
|
||||
pub fn run(opt: StreamOpt) -> Result<(), RunError> {
|
||||
|
|
Loading…
Add table
Reference in a new issue