diff --git a/crates/client/Cargo.toml b/crates/client/Cargo.toml index 7c6b93d..83aa850 100644 --- a/crates/client/Cargo.toml +++ b/crates/client/Cargo.toml @@ -10,21 +10,22 @@ tokio.workspace = true quinn = { workspace = true, features = ["rustls-ring", "platform-verifier"] } gpui-kit = { version = "0.11.0", features = ["syntect"] } -ec-opus = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" } -ec-core = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" } -ec-probe = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" } -ec-mp4 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" } -ec-matroska = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" } -ec-ogg = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" } -ec-h264 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" } -ec-vp8 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" } -ec-aac = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" } -ec-mp3 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" } -ec-vorbis = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" } -ec-flac = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" } -ec-h265 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" } -ec-vp9 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" } -ec-av1 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" } +ec-opus = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" } +ec-core = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" } +ec-probe = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" } +ec-mp4 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" } +ec-matroska = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" } +ec-ogg = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" } +ec-h264 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" } +ec-vp8 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" } +ec-aac = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" } +ec-mp3 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" } +ec-vorbis = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" } +ec-flac = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" } +ec-h265 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" } +ec-hw = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" } +ec-vp9 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" } +ec-av1 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" } ureq = "3.5.2" bytes = "1.12.2" tracing = "0.1.44" @@ -39,8 +40,6 @@ rtrb = "0.4.1" pipewire = { version = "0.10.1", features = ["v0_3_49"] } ksni = "0.3.7" ashpd = { version = "0.14.3", default-features = false, features = ["tokio", "screencast"] } -ec-hw = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" } -ec-va = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" } [target.'cfg(target_os = "windows")'.dependencies] wasapi = "0.27.0" diff --git a/crates/client/src/lib.rs b/crates/client/src/lib.rs index c1efbf0..1e4467b 100644 --- a/crates/client/src/lib.rs +++ b/crates/client/src/lib.rs @@ -17,7 +17,10 @@ pub mod voice; pub const NAME: &str = "Yumush"; pub fn config_file(name: &str) -> Option { - dirs::config_dir().map(|dir| dir.join("yumush").join(name)) + std::env::var_os("YUMUSH_CONFIG_DIR") + .map(PathBuf::from) + .or_else(|| dirs::config_dir().map(|dir| dir.join("yumush"))) + .map(|dir| dir.join(name)) } const CLIENT_CONFIG_FILE_CONTENT: &str = include_str!(concat!( diff --git a/crates/client/src/media/decode.rs b/crates/client/src/media/decode.rs index 87d64c5..65f6e65 100644 --- a/crates/client/src/media/decode.rs +++ b/crates/client/src/media/decode.rs @@ -146,8 +146,7 @@ pub enum VideoDecoder { H265(Box), Vp9(Box), Av1(Box), - #[cfg(target_os = "linux")] - Hardware(Box), + Hardware(Box, ec_hw::Codec), } impl VideoDecoder { @@ -172,8 +171,7 @@ impl VideoDecoder { pub fn engine(&self) -> Engine { match self { - #[cfg(target_os = "linux")] - VideoDecoder::Hardware(_) => Engine::Hardware, + VideoDecoder::Hardware(..) => Engine::Hardware, _ => Engine::Software, } } @@ -253,8 +251,7 @@ impl VideoDecoder { Vec::new() } }, - #[cfg(target_os = "linux")] - VideoDecoder::Hardware(decoder) => { + VideoDecoder::Hardware(decoder, _) => { if let Err(error) = decoder.decode(&packet.data, packet.pts.unwrap_or(0)) { warn!("video packet skipped: {error}"); return Vec::new(); @@ -275,8 +272,7 @@ impl VideoDecoder { drain_h265(decoder, 0.0) } VideoDecoder::Vp8(_) | VideoDecoder::Vp9(_) | VideoDecoder::Av1(_) => Vec::new(), - #[cfg(target_os = "linux")] - VideoDecoder::Hardware(decoder) => { + VideoDecoder::Hardware(decoder, _) => { let _ = decoder.flush(); hardware_pictures(decoder) } @@ -290,13 +286,15 @@ impl VideoDecoder { VideoDecoder::H265(decoder) => **decoder = ec_h265::Decoder::new(), VideoDecoder::Vp9(decoder) => **decoder = ec_vp9::decode::Decoder::new(), VideoDecoder::Av1(decoder) => **decoder = av1_decoder(), - #[cfg(target_os = "linux")] - VideoDecoder::Hardware(decoder) => decoder.reset(), + VideoDecoder::Hardware(decoder, codec) => { + if let Ok(fresh) = ec_hw::HwDecoder::open(*codec) { + **decoder = fresh; + } + } } } } -#[cfg(target_os = "linux")] fn hardware(codec: Codec) -> Option { let codec = match codec { Codec::H264 => ec_hw::Codec::H264, @@ -305,14 +303,8 @@ fn hardware(codec: Codec) -> Option { Codec::Av1 => ec_hw::Codec::Av1, Codec::Vp8 => return None, }; - let display = ec_va::open().ok()?; - let decoder = ec_hw::Decoder::new(&display, codec).ok()?; - Some(VideoDecoder::Hardware(Box::new(decoder))) -} - -#[cfg(not(target_os = "linux"))] -fn hardware(_: Codec) -> Option { - None + let decoder = ec_hw::HwDecoder::open(codec).ok()?; + Some(VideoDecoder::Hardware(Box::new(decoder), codec)) } pub(crate) fn software(codec: Codec) -> Option { @@ -384,13 +376,12 @@ fn vp9_picture(picture: ec_vp9::decode::Picture) -> Picture { } } -#[cfg(target_os = "linux")] -fn hardware_pictures(decoder: &mut ec_hw::Decoder) -> Vec<(f64, Picture)> { - std::iter::from_fn(|| decoder.next_frame()) - .filter_map(|frame| { - let pts = Timestamp::new(frame.timestamp, TimeBase::MILLIS).as_secs_f64(); - let i420 = frame.to_i420().ok()?; - Some(( +fn hardware_pictures(decoder: &mut ec_hw::HwDecoder) -> Vec<(f64, Picture)> { + std::iter::from_fn(|| decoder.next_frame().transpose()) + .filter_map(Result::ok) + .map(|(timestamp, i420)| { + let pts = Timestamp::new(timestamp, TimeBase::MILLIS).as_secs_f64(); + ( pts, Picture { y: i420.y, @@ -401,7 +392,7 @@ fn hardware_pictures(decoder: &mut ec_hw::Decoder) -> Vec<(f64, Picture)> { width: i420.width, height: i420.height, }, - )) + ) }) .collect() } diff --git a/crates/client/src/share/encode.rs b/crates/client/src/share/encode.rs index ae139f0..fe0e27d 100644 --- a/crates/client/src/share/encode.rs +++ b/crates/client/src/share/encode.rs @@ -130,22 +130,13 @@ fn report(result: Result) -> Option { .ok() } -#[cfg(target_os = "linux")] mod hardware { use common::share::Codec; - use ec_va::CapReport; - use ec_va::caps::{Entrypoint, Profile}; use super::{Settings, report}; use crate::share::convert::I420; - const PAIRS: [(Codec, Profile); 3] = [ - (Codec::H264, Profile::H264High), - (Codec::H265, Profile::HEVCMain), - (Codec::Av1, Profile::AV1Profile0), - ]; - - pub struct Encoder(ec_hw::Encoder); + pub struct Encoder(ec_hw::HwEncoder); impl Encoder { pub fn encode( @@ -169,25 +160,30 @@ mod hardware { } } + fn codec(codec: ec_hw::Codec) -> Option { + match codec { + ec_hw::Codec::H264 => Some(Codec::H264), + ec_hw::Codec::H265 => Some(Codec::H265), + ec_hw::Codec::Av1 => Some(Codec::Av1), + ec_hw::Codec::Vp9 => None, + } + } + pub fn probe() -> Vec<(Codec, u32)> { - let Ok(display) = ec_va::open() else { - return Vec::new(); - }; - let Ok(caps) = CapReport::probe(&display) else { - return Vec::new(); - }; - PAIRS - .into_iter() - .filter(|(_, profile)| caps.supports(*profile, Entrypoint::EncSlice)) - .map(|(codec, profile)| { - let height = caps - .entry(profile, Entrypoint::EncSlice) - .and_then(|entry| entry.surfaces.as_ref()) - .and_then(|surfaces| surfaces.max_height) - .unwrap_or(super::DEFAULT_MAX_HEIGHT); - (codec, height) - }) - .collect() + let mut found: Vec<(Codec, u32)> = Vec::new(); + for capability in ec_hw::capabilities() { + if capability.direction != ec_hw::Direction::Encode { + continue; + } + let Some(codec) = codec(capability.codec) else { + continue; + }; + match found.iter_mut().find(|(known, _)| *known == codec) { + Some((_, height)) => *height = (*height).max(capability.max_height), + None => found.push((codec, capability.max_height)), + } + } + found } pub fn open(settings: &Settings) -> Option { @@ -197,37 +193,14 @@ mod hardware { Codec::Av1 => ec_hw::EncCodec::Av1, Codec::Vp8 | Codec::Vp9 => return None, }; - let display = ec_va::open().ok()?; let mut config = ec_hw::EncoderConfig::new(codec, settings.width, settings.height); config.framerate = (settings.fps, 1); config.bitrate = settings.bitrate; config.gop_size = settings.gop; config.rate_control = ec_hw::RateControlMode::ConstantBitrate; - report(ec_hw::Encoder::new(&display, config)).map(Encoder) - } -} - -#[cfg(not(target_os = "linux"))] -mod hardware { - use common::share::Codec; - - use super::Settings; - use crate::share::convert::I420; - - pub enum Encoder {} - - impl Encoder { - pub fn encode(&mut self, _: I420, _: u32, _: bool) -> Option<(Vec, bool)> { - match *self {} - } - } - - pub fn probe() -> Vec<(Codec, u32)> { - Vec::new() - } - - pub fn open(_: &Settings) -> Option { - None + let encoder = report(ec_hw::HwEncoder::open(config, None))?; + tracing::info!(backend = ?encoder.backend(), ?codec, "share hardware encoder opened"); + Some(Encoder(encoder)) } } diff --git a/harness/codec.sh b/harness/codec.sh index d887260..53f68d6 100755 --- a/harness/codec.sh +++ b/harness/codec.sh @@ -2,7 +2,7 @@ set -euo pipefail cd "$(dirname "$0")" ./ui.sh click 600 400 -./ui.sh click 172 981; sleep 0.8; ./ui.sh click "$1" 835; sleep 0.5; ./ui.sh click 600 400 +./ui.sh click 172 981; sleep 0.8; ./ui.sh click "$1" 882; sleep 0.5; ./ui.sh click 600 400 ./ui.sh click 144 980; sleep 2; ./ui.sh click 144 980; sleep 3 ./ui.sh click 1740 28; sleep 6 ./ui.sh click 1020 1000 right; sleep 0.6; ./ui.sh click 1087 598; sleep 2.5 diff --git a/harness/win.sh b/harness/win.sh new file mode 100755 index 0000000..e0f5523 --- /dev/null +++ b/harness/win.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +set -euo pipefail +SHOTS="${HARNESS_STATE:-/tmp/claude-1000/yumush-harness}/shots" +mkdir -p "$SHOTS" +monitor() { podman exec yumush-win sh -c "printf '%s\n' \"$1\" | nc -q1 -U /run/shm/monitor.sock >/dev/null"; } +ssh_win() { ssh -i ~/vm/yumush-win/id_ed25519 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=10 -o LogLevel=ERROR -p 2222 yumush@127.0.0.1 "$@"; } +case "$1" in + shot) + monitor "screendump /tmp/win.ppm"; sleep 0.5 + podman cp yumush-win:/tmp/win.ppm "$SHOTS/win.ppm" + magick "$SHOTS/win.ppm" "$SHOTS/${2:-win}.png"; echo "$SHOTS/${2:-win}.png";; + click) + ssh_win "schtasks /create /f /tn yumush_click /sc once /st 00:00 /it /ru yumush /tr 'powershell -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File C:\\Users\\yumush\\click.ps1 $2 $3 ${4:-left}' 2>&1 | Out-Null; schtasks /run /tn yumush_click | Out-Null";; + key) monitor "sendkey $2";; + type) for ((i=0; i<${#2}; i++)); do c="${2:i:1}"; case "$c" in [A-Z]) monitor "sendkey shift-${c,,}";; " ") monitor "sendkey spc";; ".") monitor "sendkey dot";; *) monitor "sendkey $c";; esac; done;; + run) + ssh_win "schtasks /create /f /tn yumush_$2 /sc once /st 00:00 /it /ru yumush /tr \"$3\" | Out-Null; schtasks /run /tn yumush_$2";; + ssh) shift; ssh_win "$@";; +esac +sleep "${UI_DELAY:-0.3}"