forge
Explore
Log in

Don't you dare go Hollow

Encode shares through vulkan or va-api with ec-hw

Browse files at this commit

fd75e8c361be35474bfc59e2cd767c5a384399adAhmet Kaan GümüşParent: 55b5cdf
  • feat
    • encode shares through vulkan or va-api with ec-hw
Show full message
✨ feat: encode shares through vulkan or va-api with ec-hw

ec-hw now builds on every OS and picks Vulkan first, then VA-API on
Linux, with software H.264 as the last fallback. Hardware decode goes
through the cross-platform HwDecoder. Adds YUMUSH_CONFIG_DIR so test
clients on Windows can keep separate accounts, and a Windows VM helper
for the harness.
crates/client/Cargo.tomlmodified+16 -17
@@ -10,21 +10,22 @@ tokio.workspace = true
10 quinn = { workspace = true, features = ["rustls-ring", "platform-verifier"] }10 quinn = { workspace = true, features = ["rustls-ring", "platform-verifier"] }
11 11
12 gpui-kit = { version = "0.11.0", features = ["syntect"] }12 gpui-kit = { version = "0.11.0", features = ["syntect"] }
13-ec-opus = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" }13+ec-opus = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" }
14-ec-core = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" }14+ec-core = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" }
15-ec-probe = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" }15+ec-probe = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" }
16-ec-mp4 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" }16+ec-mp4 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" }
17-ec-matroska = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" }17+ec-matroska = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" }
18-ec-ogg = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" }18+ec-ogg = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" }
19-ec-h264 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" }19+ec-h264 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" }
20-ec-vp8 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" }20+ec-vp8 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" }
21-ec-aac = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" }21+ec-aac = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" }
22-ec-mp3 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" }22+ec-mp3 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" }
23-ec-vorbis = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" }23+ec-vorbis = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" }
24-ec-flac = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" }24+ec-flac = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" }
25-ec-h265 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" }25+ec-h265 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" }
26-ec-vp9 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" }26+ec-hw = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" }
27-ec-av1 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" }27+ec-vp9 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" }
28+ec-av1 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "274b9cb95d91511f24b2ddf82e02073ee31a0568" }
28 ureq = "3.5.2"29 ureq = "3.5.2"
29 bytes = "1.12.2"30 bytes = "1.12.2"
30 tracing = "0.1.44"31 tracing = "0.1.44"
@@ -39,8 +40,6 @@ rtrb = "0.4.1"
39 pipewire = { version = "0.10.1", features = ["v0_3_49"] }40 pipewire = { version = "0.10.1", features = ["v0_3_49"] }
40 ksni = "0.3.7"41 ksni = "0.3.7"
41 ashpd = { version = "0.14.3", default-features = false, features = ["tokio", "screencast"] }42 ashpd = { version = "0.14.3", default-features = false, features = ["tokio", "screencast"] }
42-ec-hw = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" }
43-ec-va = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9953355c2c468d9c357fdebbec67345ea006d173" }
44 43
45 [target.'cfg(target_os = "windows")'.dependencies]44 [target.'cfg(target_os = "windows")'.dependencies]
46 wasapi = "0.27.0"45 wasapi = "0.27.0"
crates/client/src/lib.rsmodified+4 -1
@@ -17,7 +17,10 @@ pub mod voice;
17 pub const NAME: &str = "Yumush";17 pub const NAME: &str = "Yumush";
18 18
19 pub fn config_file(name: &str) -> Option<PathBuf> {19 pub fn config_file(name: &str) -> Option<PathBuf> {
20- dirs::config_dir().map(|dir| dir.join("yumush").join(name))20+ std::env::var_os("YUMUSH_CONFIG_DIR")
21+ .map(PathBuf::from)
22+ .or_else(|| dirs::config_dir().map(|dir| dir.join("yumush")))
23+ .map(|dir| dir.join(name))
21 }24 }
22 25
23 const CLIENT_CONFIG_FILE_CONTENT: &str = include_str!(concat!(26 const CLIENT_CONFIG_FILE_CONTENT: &str = include_str!(concat!(
crates/client/src/media/decode.rsmodified+18 -27
@@ -146,8 +146,7 @@ pub enum VideoDecoder {
146 H265(Box<ec_h265::Decoder>),146 H265(Box<ec_h265::Decoder>),
147 Vp9(Box<ec_vp9::decode::Decoder>),147 Vp9(Box<ec_vp9::decode::Decoder>),
148 Av1(Box<ec_av1::stream::StreamDecoder>),148 Av1(Box<ec_av1::stream::StreamDecoder>),
149- #[cfg(target_os = "linux")]149+ Hardware(Box<ec_hw::HwDecoder>, ec_hw::Codec),
150- Hardware(Box<ec_hw::Decoder>),
151 }150 }
152 151
153 impl VideoDecoder {152 impl VideoDecoder {
@@ -172,8 +171,7 @@ impl VideoDecoder {
172 171
173 pub fn engine(&self) -> Engine {172 pub fn engine(&self) -> Engine {
174 match self {173 match self {
175- #[cfg(target_os = "linux")]174+ VideoDecoder::Hardware(..) => Engine::Hardware,
176- VideoDecoder::Hardware(_) => Engine::Hardware,
177 _ => Engine::Software,175 _ => Engine::Software,
178 }176 }
179 }177 }
@@ -253,8 +251,7 @@ impl VideoDecoder {
253 Vec::new()251 Vec::new()
254 }252 }
255 },253 },
256- #[cfg(target_os = "linux")]254+ VideoDecoder::Hardware(decoder, _) => {
257- VideoDecoder::Hardware(decoder) => {
258 if let Err(error) = decoder.decode(&packet.data, packet.pts.unwrap_or(0)) {255 if let Err(error) = decoder.decode(&packet.data, packet.pts.unwrap_or(0)) {
259 warn!("video packet skipped: {error}");256 warn!("video packet skipped: {error}");
260 return Vec::new();257 return Vec::new();
@@ -275,8 +272,7 @@ impl VideoDecoder {
275 drain_h265(decoder, 0.0)272 drain_h265(decoder, 0.0)
276 }273 }
277 VideoDecoder::Vp8(_) | VideoDecoder::Vp9(_) | VideoDecoder::Av1(_) => Vec::new(),274 VideoDecoder::Vp8(_) | VideoDecoder::Vp9(_) | VideoDecoder::Av1(_) => Vec::new(),
278- #[cfg(target_os = "linux")]275+ VideoDecoder::Hardware(decoder, _) => {
279- VideoDecoder::Hardware(decoder) => {
280 let _ = decoder.flush();276 let _ = decoder.flush();
281 hardware_pictures(decoder)277 hardware_pictures(decoder)
282 }278 }
@@ -290,13 +286,15 @@ impl VideoDecoder {
290 VideoDecoder::H265(decoder) => **decoder = ec_h265::Decoder::new(),286 VideoDecoder::H265(decoder) => **decoder = ec_h265::Decoder::new(),
291 VideoDecoder::Vp9(decoder) => **decoder = ec_vp9::decode::Decoder::new(),287 VideoDecoder::Vp9(decoder) => **decoder = ec_vp9::decode::Decoder::new(),
292 VideoDecoder::Av1(decoder) => **decoder = av1_decoder(),288 VideoDecoder::Av1(decoder) => **decoder = av1_decoder(),
293- #[cfg(target_os = "linux")]289+ VideoDecoder::Hardware(decoder, codec) => {
294- VideoDecoder::Hardware(decoder) => decoder.reset(),290+ if let Ok(fresh) = ec_hw::HwDecoder::open(*codec) {
291+ **decoder = fresh;
292+ }
293+ }
295 }294 }
296 }295 }
297 }296 }
298 297
299-#[cfg(target_os = "linux")]
300 fn hardware(codec: Codec) -> Option<VideoDecoder> {298 fn hardware(codec: Codec) -> Option<VideoDecoder> {
301 let codec = match codec {299 let codec = match codec {
302 Codec::H264 => ec_hw::Codec::H264,300 Codec::H264 => ec_hw::Codec::H264,
@@ -305,14 +303,8 @@ fn hardware(codec: Codec) -> Option<VideoDecoder> {
305 Codec::Av1 => ec_hw::Codec::Av1,303 Codec::Av1 => ec_hw::Codec::Av1,
306 Codec::Vp8 => return None,304 Codec::Vp8 => return None,
307 };305 };
308- let display = ec_va::open().ok()?;306+ let decoder = ec_hw::HwDecoder::open(codec).ok()?;
309- let decoder = ec_hw::Decoder::new(&display, codec).ok()?;307+ Some(VideoDecoder::Hardware(Box::new(decoder), codec))
310- Some(VideoDecoder::Hardware(Box::new(decoder)))
311-}
312-
313-#[cfg(not(target_os = "linux"))]
314-fn hardware(_: Codec) -> Option<VideoDecoder> {
315- None
316 }308 }
317 309
318 pub(crate) fn software(codec: Codec) -> Option<VideoDecoder> {310 pub(crate) fn software(codec: Codec) -> Option<VideoDecoder> {
@@ -384,13 +376,12 @@ fn vp9_picture(picture: ec_vp9::decode::Picture) -> Picture {
384 }376 }
385 }377 }
386 378
387-#[cfg(target_os = "linux")]379+fn hardware_pictures(decoder: &mut ec_hw::HwDecoder) -> Vec<(f64, Picture)> {
388-fn hardware_pictures(decoder: &mut ec_hw::Decoder) -> Vec<(f64, Picture)> {380+ std::iter::from_fn(|| decoder.next_frame().transpose())
389- std::iter::from_fn(|| decoder.next_frame())381+ .filter_map(Result::ok)
390- .filter_map(|frame| {382+ .map(|(timestamp, i420)| {
391- let pts = Timestamp::new(frame.timestamp, TimeBase::MILLIS).as_secs_f64();383+ let pts = Timestamp::new(timestamp, TimeBase::MILLIS).as_secs_f64();
392- let i420 = frame.to_i420().ok()?;384+ (
393- Some((
394 pts,385 pts,
395 Picture {386 Picture {
396 y: i420.y,387 y: i420.y,
@@ -401,7 +392,7 @@ fn hardware_pictures(decoder: &mut ec_hw::Decoder) -> Vec<(f64, Picture)> {
401 width: i420.width,392 width: i420.width,
402 height: i420.height,393 height: i420.height,
403 },394 },
404- ))395+ )
405 })396 })
406 .collect()397 .collect()
407 }398 }
crates/client/src/share/encode.rsmodified+27 -54
@@ -130,22 +130,13 @@ fn report<T, E: std::fmt::Debug>(result: Result<T, E>) -> Option<T> {
130 .ok()130 .ok()
131 }131 }
132 132
133-#[cfg(target_os = "linux")]
134 mod hardware {133 mod hardware {
135 use common::share::Codec;134 use common::share::Codec;
136- use ec_va::CapReport;
137- use ec_va::caps::{Entrypoint, Profile};
138 135
139 use super::{Settings, report};136 use super::{Settings, report};
140 use crate::share::convert::I420;137 use crate::share::convert::I420;
141 138
142- const PAIRS: [(Codec, Profile); 3] = [139+ pub struct Encoder(ec_hw::HwEncoder);
143- (Codec::H264, Profile::H264High),
144- (Codec::H265, Profile::HEVCMain),
145- (Codec::Av1, Profile::AV1Profile0),
146- ];
147-
148- pub struct Encoder(ec_hw::Encoder);
149 140
150 impl Encoder {141 impl Encoder {
151 pub fn encode(142 pub fn encode(
@@ -169,25 +160,30 @@ mod hardware {
169 }160 }
170 }161 }
171 162
163+ fn codec(codec: ec_hw::Codec) -> Option<Codec> {
164+ match codec {
165+ ec_hw::Codec::H264 => Some(Codec::H264),
166+ ec_hw::Codec::H265 => Some(Codec::H265),
167+ ec_hw::Codec::Av1 => Some(Codec::Av1),
168+ ec_hw::Codec::Vp9 => None,
169+ }
170+ }
171+
172 pub fn probe() -> Vec<(Codec, u32)> {172 pub fn probe() -> Vec<(Codec, u32)> {
173- let Ok(display) = ec_va::open() else {173+ let mut found: Vec<(Codec, u32)> = Vec::new();
174- return Vec::new();174+ for capability in ec_hw::capabilities() {
175- };175+ if capability.direction != ec_hw::Direction::Encode {
176- let Ok(caps) = CapReport::probe(&display) else {176+ continue;
177- return Vec::new();177+ }
178- };178+ let Some(codec) = codec(capability.codec) else {
179- PAIRS179+ continue;
180- .into_iter()180+ };
181- .filter(|(_, profile)| caps.supports(*profile, Entrypoint::EncSlice))181+ match found.iter_mut().find(|(known, _)| *known == codec) {
182- .map(|(codec, profile)| {182+ Some((_, height)) => *height = (*height).max(capability.max_height),
183- let height = caps183+ None => found.push((codec, capability.max_height)),
184- .entry(profile, Entrypoint::EncSlice)184+ }
185- .and_then(|entry| entry.surfaces.as_ref())185+ }
186- .and_then(|surfaces| surfaces.max_height)186+ found
187- .unwrap_or(super::DEFAULT_MAX_HEIGHT);
188- (codec, height)
189- })
190- .collect()
191 }187 }
192 188
193 pub fn open(settings: &Settings) -> Option<Encoder> {189 pub fn open(settings: &Settings) -> Option<Encoder> {
@@ -197,37 +193,14 @@ mod hardware {
197 Codec::Av1 => ec_hw::EncCodec::Av1,193 Codec::Av1 => ec_hw::EncCodec::Av1,
198 Codec::Vp8 | Codec::Vp9 => return None,194 Codec::Vp8 | Codec::Vp9 => return None,
199 };195 };
200- let display = ec_va::open().ok()?;
201 let mut config = ec_hw::EncoderConfig::new(codec, settings.width, settings.height);196 let mut config = ec_hw::EncoderConfig::new(codec, settings.width, settings.height);
202 config.framerate = (settings.fps, 1);197 config.framerate = (settings.fps, 1);
203 config.bitrate = settings.bitrate;198 config.bitrate = settings.bitrate;
204 config.gop_size = settings.gop;199 config.gop_size = settings.gop;
205 config.rate_control = ec_hw::RateControlMode::ConstantBitrate;200 config.rate_control = ec_hw::RateControlMode::ConstantBitrate;
206- report(ec_hw::Encoder::new(&display, config)).map(Encoder)201+ let encoder = report(ec_hw::HwEncoder::open(config, None))?;
207- }202+ tracing::info!(backend = ?encoder.backend(), ?codec, "share hardware encoder opened");
208-}203+ Some(Encoder(encoder))
209-
210-#[cfg(not(target_os = "linux"))]
211-mod hardware {
212- use common::share::Codec;
213-
214- use super::Settings;
215- use crate::share::convert::I420;
216-
217- pub enum Encoder {}
218-
219- impl Encoder {
220- pub fn encode(&mut self, _: I420, _: u32, _: bool) -> Option<(Vec<u8>, bool)> {
221- match *self {}
222- }
223- }
224-
225- pub fn probe() -> Vec<(Codec, u32)> {
226- Vec::new()
227- }
228-
229- pub fn open(_: &Settings) -> Option<Encoder> {
230- None
231 }204 }
232 }205 }
233 206
harness/codec.shmodified+1 -1
@@ -2,7 +2,7 @@
2 set -euo pipefail2 set -euo pipefail
3 cd "$(dirname "$0")"3 cd "$(dirname "$0")"
4 ./ui.sh click 600 4004 ./ui.sh click 600 400
5-./ui.sh click 172 981; sleep 0.8; ./ui.sh click "$1" 835; sleep 0.5; ./ui.sh click 600 4005+./ui.sh click 172 981; sleep 0.8; ./ui.sh click "$1" 882; sleep 0.5; ./ui.sh click 600 400
6 ./ui.sh click 144 980; sleep 2; ./ui.sh click 144 980; sleep 36 ./ui.sh click 144 980; sleep 2; ./ui.sh click 144 980; sleep 3
7 ./ui.sh click 1740 28; sleep 67 ./ui.sh click 1740 28; sleep 6
8 ./ui.sh click 1020 1000 right; sleep 0.6; ./ui.sh click 1087 598; sleep 2.58 ./ui.sh click 1020 1000 right; sleep 0.6; ./ui.sh click 1087 598; sleep 2.5
harness/win.shadded+20 -0
@@ -0,0 +1,20 @@
1+#!/usr/bin/env bash
2+set -euo pipefail
3+SHOTS="${HARNESS_STATE:-/tmp/claude-1000/yumush-harness}/shots"
4+mkdir -p "$SHOTS"
5+monitor() { podman exec yumush-win sh -c "printf '%s\n' \"$1\" | nc -q1 -U /run/shm/monitor.sock >/dev/null"; }
6+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 "$@"; }
7+case "$1" in
8+ shot)
9+ monitor "screendump /tmp/win.ppm"; sleep 0.5
10+ podman cp yumush-win:/tmp/win.ppm "$SHOTS/win.ppm"
11+ magick "$SHOTS/win.ppm" "$SHOTS/${2:-win}.png"; echo "$SHOTS/${2:-win}.png";;
12+ click)
13+ 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";;
14+ key) monitor "sendkey $2";;
15+ 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;;
16+ run)
17+ 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";;
18+ ssh) shift; ssh_win "$@";;
19+esac
20+sleep "${UI_DELAY:-0.3}"