diff --git a/Cargo.lock b/Cargo.lock index d5bde2a2e90..72b20648ffe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,22 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "ab_glyph" +version = "0.2.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01c0457472c38ea5bd1c3b5ada5e368271cb550be7a4ca4a0b4634e9913f6cc2" +dependencies = [ + "ab_glyph_rasterizer", + "owned_ttf_parser", +] + +[[package]] +name = "ab_glyph_rasterizer" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "366ffbaa4442f4684d91e2cd7c5ea7c4ed8add41959a31447066e279e432b618" + [[package]] name = "addr2line" version = "0.25.1" @@ -52,6 +68,19 @@ dependencies = [ "subtle", ] +[[package]] +name = "ahash" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" +dependencies = [ + "cfg-if", + "getrandom 0.3.4", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "aho-corasick" version = "1.1.5" @@ -98,6 +127,31 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "android-activity" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f2a1bb052857d5dd49572219344a7332b31b76405648eabac5bc68978251bcd" +dependencies = [ + "android-properties", + "bitflags 2.13.1", + "cc", + "jni 0.22.4", + "libc", + "log", + "ndk", + "ndk-context", + "ndk-sys", + "num_enum", + "thiserror 2.0.19", +] + +[[package]] +name = "android-properties" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04" + [[package]] name = "android_log-sys" version = "0.2.0" @@ -218,6 +272,12 @@ version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3fb67a6e08acf24fdeccbac2cb6ac4305825bd1f117462e0e6f2f193345ad56" +[[package]] +name = "as-raw-xcb-connection" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "175571dd1d178ced59193a6fc02dde1b972eb0bc56c892cde9beeceac5bf0f6b" + [[package]] name = "ash" version = "0.38.0+1.3.281" @@ -758,13 +818,22 @@ dependencies = [ "hybrid-array", ] +[[package]] +name = "block2" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c132eebf10f5cad5289222520a4a058514204aed6d791f1cf4fe8088b82d15f" +dependencies = [ + "objc2 0.5.2", +] + [[package]] name = "block2" version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdeb9d870516001442e364c5220d3574d2da8dc765554b4a617230d33fa58ef5" dependencies = [ - "objc2", + "objc2 0.6.4", ] [[package]] @@ -905,6 +974,32 @@ dependencies = [ "bytes", ] +[[package]] +name = "calloop" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b99da2f8558ca23c71f4fd15dc57c906239752dd27ff3c00a1d56b685b7cbfec" +dependencies = [ + "bitflags 2.13.1", + "log", + "polling", + "rustix 0.38.44", + "slab", + "thiserror 1.0.69", +] + +[[package]] +name = "calloop-wayland-source" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95a66a987056935f7efce4ab5668920b5d0dac4a7c99991a67395f13702ddd20" +dependencies = [ + "calloop", + "rustix 0.38.44", + "wayland-backend", + "wayland-client", +] + [[package]] name = "camino" version = "1.2.5" @@ -1244,6 +1339,15 @@ version = "0.4.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc14f565cf027a105f7a44ccf9e5b424348421a1d8952a8fc9d499d313107789" +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "console_error_panic_hook" version = "0.1.7" @@ -1341,6 +1445,30 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "core-graphics" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c07782be35f9e1140080c6b96f0d44b739e2278479f64e02fdab4e32dfd8b081" +dependencies = [ + "bitflags 1.3.2", + "core-foundation 0.9.4", + "core-graphics-types", + "foreign-types", + "libc", +] + +[[package]] +name = "core-graphics-types" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45390e6114f68f718cc7a830514a96f903cccd70d02a8f6d9f643ac4ba45afaf" +dependencies = [ + "bitflags 1.3.2", + "core-foundation 0.9.4", + "libc", +] + [[package]] name = "coreaudio-rs" version = "0.14.2" @@ -1362,7 +1490,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f77b11176c37874be37e8d691c946e31b2b8c357abce9526f6a99eb469e1028" dependencies = [ "alsa", - "block2", + "block2 0.6.2", "coreaudio-rs", "dasp_sample", "jni 0.22.4", @@ -1373,13 +1501,13 @@ dependencies = [ "ndk-context", "num-derive", "num-traits", - "objc2", + "objc2 0.6.4", "objc2-audio-toolbox", "objc2-avf-audio", "objc2-core-audio", "objc2-core-audio-types", "objc2-core-foundation", - "objc2-foundation", + "objc2-foundation 0.3.2", "web-sys", "windows", "windows-core", @@ -1588,6 +1716,12 @@ dependencies = [ "libloading 0.9.0", ] +[[package]] +name = "cursor-icon" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f27ae1dd37df86211c42e150270f82743308803d90a6f6e6651cd730d5e1732f" + [[package]] name = "curve25519-dalek" version = "5.0.0" @@ -1949,6 +2083,12 @@ dependencies = [ "x509-cert", ] +[[package]] +name = "dispatch" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b" + [[package]] name = "dispatch2" version = "0.3.1" @@ -1956,9 +2096,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e0e367e4e7da84520dedcac1901e4da967309406d1e51017ae1abfb97adbd38" dependencies = [ "bitflags 2.13.1", - "block2", + "block2 0.6.2", "libc", - "objc2", + "objc2 0.6.4", ] [[package]] @@ -2001,6 +2141,18 @@ dependencies = [ "litrs", ] +[[package]] +name = "downcast-rs" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" + +[[package]] +name = "dpi" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8b14ccef22fc6f5a8f4d7d768562a182c04ce9a3b3157b91390b52ddfdf1a76" + [[package]] name = "dtoa" version = "1.0.11" @@ -2631,6 +2783,16 @@ dependencies = [ "version_check", ] +[[package]] +name = "gethostname" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bd49230192a3797a9a4d6abe9b3eed6f7fa4c8a8a4947977c6f80025f92cbd8" +dependencies = [ + "rustix 1.1.4", + "windows-link", +] + [[package]] name = "getrandom" version = "0.2.17" @@ -4107,6 +4269,18 @@ dependencies = [ "url", ] +[[package]] +name = "libredox" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2026a5056764a10b2bf5d56488cba40da507f5493a6a429340e2004d9ed085fa" +dependencies = [ + "bitflags 2.13.1", + "libc", + "plain", + "redox_syscall 0.9.1", +] + [[package]] name = "libspa" version = "0.10.0" @@ -4262,6 +4436,15 @@ version = "2.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" +[[package]] +name = "memmap2" +version = "0.9.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1219ed1b7f229ee7104d281dd01d6802fe28bb6e95d292942c4daacdeb798c0" +dependencies = [ + "libc", +] + [[package]] name = "memoffset" version = "0.9.1" @@ -4339,7 +4522,7 @@ dependencies = [ name = "moq-audio" version = "0.0.16" dependencies = [ - "block2", + "block2 0.6.2", "bytes", "cpal", "dispatch2", @@ -4347,11 +4530,11 @@ dependencies = [ "hang", "moq-mux", "moq-net", - "objc2", + "objc2 0.6.4", "objc2-av-foundation", "objc2-core-audio-types", "objc2-core-media", - "objc2-foundation", + "objc2-foundation 0.3.2", "objc2-screen-capture-kit", "rand 0.10.2", "rubato", @@ -4422,12 +4605,14 @@ dependencies = [ "moq-token-cli", "moq-transcode", "moq-video", + "pollster", "rustls", "sd-notify", "tokio", "tower-http 0.7.0", "tracing", "url", + "winit", ] [[package]] @@ -4836,7 +5021,7 @@ version = "0.0.14" dependencies = [ "anyhow", "ashpd", - "block2", + "block2 0.6.2", "bytemuck", "bytes", "cudarc", @@ -4850,14 +5035,14 @@ dependencies = [ "moq-net", "moq-nvenc", "moq-vaapi", - "objc2", + "objc2 0.6.4", "objc2-av-foundation", "objc2-core-foundation", "objc2-core-graphics", "objc2-core-media", "objc2-core-video", - "objc2-foundation", - "objc2-metal", + "objc2-foundation 0.3.2", + "objc2-metal 0.3.2", "objc2-screen-capture-kit", "objc2-video-toolbox", "openh264", @@ -5060,6 +5245,7 @@ dependencies = [ "log", "ndk-sys", "num_enum", + "raw-window-handle", "thiserror 1.0.69", ] @@ -5113,7 +5299,7 @@ version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "569dfbdd2efd771b24ec9bb57f956e04d4fbfc72f62b2f11961723f9b3f4b020" dependencies = [ - "block2", + "block2 0.6.2", "dispatch2", "dlopen2", "ipnet", @@ -5124,10 +5310,10 @@ dependencies = [ "netlink-packet-core", "netlink-packet-route", "netlink-sys", - "objc2", + "objc2 0.6.4", "objc2-core-foundation", "objc2-core-wlan", - "objc2-foundation", + "objc2-foundation 0.3.2", "objc2-system-configuration", "once_cell", "plist", @@ -5516,6 +5702,22 @@ dependencies = [ "scuffle-workspace-hack", ] +[[package]] +name = "objc-sys" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb91bdd390c7ce1a8607f35f3ca7151b65afc0ff5ff3b34fa350f7d7c7e4310" + +[[package]] +name = "objc2" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46a785d4eeff09c14c487497c162e92766fbb3e4059a71840cecc03d9a50b804" +dependencies = [ + "objc-sys", + "objc2-encode", +] + [[package]] name = "objc2" version = "0.6.4" @@ -5525,6 +5727,22 @@ dependencies = [ "objc2-encode", ] +[[package]] +name = "objc2-app-kit" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4e89ad9e3d7d297152b17d39ed92cd50ca8063a89a9fa569046d41568891eff" +dependencies = [ + "bitflags 2.13.1", + "block2 0.5.1", + "libc", + "objc2 0.5.2", + "objc2-core-data", + "objc2-core-image 0.2.2", + "objc2-foundation 0.2.2", + "objc2-quartz-core 0.2.2", +] + [[package]] name = "objc2-audio-toolbox" version = "0.3.2" @@ -5533,11 +5751,11 @@ checksum = "6948501a91121d6399b79abaa33a8aa4ea7857fe019f341b8c23ad6e81b79b08" dependencies = [ "bitflags 2.13.1", "libc", - "objc2", + "objc2 0.6.4", "objc2-core-audio", "objc2-core-audio-types", "objc2-core-foundation", - "objc2-foundation", + "objc2-foundation 0.3.2", ] [[package]] @@ -5547,19 +5765,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "478ae33fcac9df0a18db8302387c666b8ef08a3e2d62b510ca4fc278a384b6c0" dependencies = [ "bitflags 2.13.1", - "block2", + "block2 0.6.2", "dispatch2", - "objc2", + "objc2 0.6.4", "objc2-avf-audio", "objc2-core-audio-types", "objc2-core-foundation", "objc2-core-graphics", - "objc2-core-image", + "objc2-core-image 0.3.2", "objc2-core-video", - "objc2-foundation", + "objc2-foundation 0.3.2", "objc2-image-io", "objc2-media-toolbox", - "objc2-quartz-core", + "objc2-quartz-core 0.3.2", ] [[package]] @@ -5569,8 +5787,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13a380031deed8e99db00065c45937da434ca987c034e13b87e4441f9e4090be" dependencies = [ "bitflags 2.13.1", - "objc2", - "objc2-foundation", + "objc2 0.6.4", + "objc2-foundation 0.3.2", +] + +[[package]] +name = "objc2-cloud-kit" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74dd3b56391c7a0596a295029734d3c1c5e7e510a4cb30245f8221ccea96b009" +dependencies = [ + "bitflags 2.13.1", + "block2 0.5.1", + "objc2 0.5.2", + "objc2-core-location", + "objc2-foundation 0.2.2", +] + +[[package]] +name = "objc2-contacts" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5ff520e9c33812fd374d8deecef01d4a840e7b41862d849513de77e44aa4889" +dependencies = [ + "block2 0.5.1", + "objc2 0.5.2", + "objc2-foundation 0.2.2", ] [[package]] @@ -5580,10 +5822,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1eebcea8b0dbff5f7c8504f3107c68fc061a3eb44932051c8cf8a68d969c3b2" dependencies = [ "dispatch2", - "objc2", + "objc2 0.6.4", "objc2-core-audio-types", "objc2-core-foundation", - "objc2-foundation", + "objc2-foundation 0.3.2", ] [[package]] @@ -5593,7 +5835,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a89f2ec274a0cf4a32642b2991e8b351a404d290da87bb6a9a9d8632490bd1c" dependencies = [ "bitflags 2.13.1", - "objc2", + "objc2 0.6.4", +] + +[[package]] +name = "objc2-core-data" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "617fbf49e071c178c0b24c080767db52958f716d9eabdf0890523aeae54773ef" +dependencies = [ + "bitflags 2.13.1", + "block2 0.5.1", + "objc2 0.5.2", + "objc2-foundation 0.2.2", ] [[package]] @@ -5603,10 +5857,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a180dd8642fa45cdb7dd721cd4c11b1cadd4929ce112ebd8b9f5803cc79d536" dependencies = [ "bitflags 2.13.1", - "block2", + "block2 0.6.2", "dispatch2", "libc", - "objc2", + "objc2 0.6.4", ] [[package]] @@ -5616,13 +5870,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e022c9d066895efa1345f8e33e584b9f958da2fd4cd116792e15e07e4720a807" dependencies = [ "bitflags 2.13.1", - "block2", + "block2 0.6.2", "dispatch2", "libc", - "objc2", + "objc2 0.6.4", "objc2-core-foundation", "objc2-io-surface", - "objc2-metal", + "objc2-metal 0.3.2", +] + +[[package]] +name = "objc2-core-image" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55260963a527c99f1819c4f8e3b47fe04f9650694ef348ffd2227e8196d34c80" +dependencies = [ + "block2 0.5.1", + "objc2 0.5.2", + "objc2-foundation 0.2.2", + "objc2-metal 0.2.2", ] [[package]] @@ -5631,8 +5897,20 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5d563b38d2b97209f8e861173de434bd0214cf020e3423a52624cd1d989f006" dependencies = [ - "objc2", - "objc2-foundation", + "objc2 0.6.4", + "objc2-foundation 0.3.2", +] + +[[package]] +name = "objc2-core-location" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "000cfee34e683244f284252ee206a27953279d370e309649dc3ee317b37e5781" +dependencies = [ + "block2 0.5.1", + "objc2 0.5.2", + "objc2-contacts", + "objc2-foundation 0.2.2", ] [[package]] @@ -5642,9 +5920,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05ec576860167a15dd9fce7fbee7512beb4e31f532159d3482d1f9c6caedf31d" dependencies = [ "bitflags 2.13.1", - "block2", + "block2 0.6.2", "dispatch2", - "objc2", + "objc2 0.6.4", "objc2-core-audio", "objc2-core-audio-types", "objc2-core-foundation", @@ -5658,12 +5936,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d425caf1df73233f29fd8a5c3e5edbc30d2d4307870f802d18f00d83dc5141a6" dependencies = [ "bitflags 2.13.1", - "block2", - "objc2", + "block2 0.6.2", + "objc2 0.6.4", "objc2-core-foundation", "objc2-core-graphics", "objc2-io-surface", - "objc2-metal", + "objc2-metal 0.3.2", ] [[package]] @@ -5673,9 +5951,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c71e34919aba0d701380d911702455038a8a3587467fe0141d6a71501e7ffe48" dependencies = [ "bitflags 2.13.1", - "objc2", + "objc2 0.6.4", "objc2-core-foundation", - "objc2-foundation", + "objc2-foundation 0.3.2", "objc2-security", "objc2-security-foundation", ] @@ -5686,6 +5964,19 @@ version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef25abbcd74fb2609453eb695bd2f860d389e457f67dc17cafc8b8cbc89d0c33" +[[package]] +name = "objc2-foundation" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ee638a5da3799329310ad4cfa62fbf045d5f56e3ef5ba4149e7452dcf89d5a8" +dependencies = [ + "bitflags 2.13.1", + "block2 0.5.1", + "dispatch", + "libc", + "objc2 0.5.2", +] + [[package]] name = "objc2-foundation" version = "0.3.2" @@ -5693,9 +5984,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3e0adef53c21f888deb4fa59fc59f7eb17404926ee8a6f59f5df0fd7f9f3272" dependencies = [ "bitflags 2.13.1", - "block2", + "block2 0.6.2", "libc", - "objc2", + "objc2 0.6.4", "objc2-core-foundation", ] @@ -5705,7 +5996,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32b0446e98cf4a784cc7a0177715ff317eeaa8463841c616cfc78aa4f953c4ea" dependencies = [ - "objc2", + "objc2 0.6.4", "objc2-core-foundation", "objc2-core-graphics", ] @@ -5727,22 +6018,46 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "180788110936d59bab6bd83b6060ffdfffb3b922ba1396b312ae795e1de9d81d" dependencies = [ "bitflags 2.13.1", - "objc2", + "objc2 0.6.4", "objc2-core-foundation", ] +[[package]] +name = "objc2-link-presentation" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1a1ae721c5e35be65f01a03b6d2ac13a54cb4fa70d8a5da293d7b0020261398" +dependencies = [ + "block2 0.5.1", + "objc2 0.5.2", + "objc2-app-kit", + "objc2-foundation 0.2.2", +] + [[package]] name = "objc2-media-toolbox" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "edd9fdde720df3da7046bb9097811000c1e7ab5cd579fa89d96b27d56781fb30" dependencies = [ - "objc2", + "objc2 0.6.4", "objc2-core-audio-types", "objc2-core-foundation", "objc2-core-media", ] +[[package]] +name = "objc2-metal" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0cba1276f6023976a406a14ffa85e1fdd19df6b0f737b063b95f6c8c7aadd6" +dependencies = [ + "bitflags 2.13.1", + "block2 0.5.1", + "objc2 0.5.2", + "objc2-foundation 0.2.2", +] + [[package]] name = "objc2-metal" version = "0.3.2" @@ -5750,11 +6065,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0125f776a10d00af4152d74616409f0d4a2053a6f57fa5b7d6aa2854ac04794" dependencies = [ "bitflags 2.13.1", - "block2", + "block2 0.6.2", "dispatch2", - "objc2", + "objc2 0.6.4", "objc2-core-foundation", - "objc2-foundation", + "objc2-foundation 0.3.2", +] + +[[package]] +name = "objc2-quartz-core" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e42bee7bff906b14b167da2bac5efe6b6a07e6f7c0a21a7308d40c960242dc7a" +dependencies = [ + "bitflags 2.13.1", + "block2 0.5.1", + "objc2 0.5.2", + "objc2-foundation 0.2.2", + "objc2-metal 0.2.2", ] [[package]] @@ -5764,11 +6092,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96c1358452b371bf9f104e21ec536d37a650eb10f7ee379fff67d2e08d537f1f" dependencies = [ "bitflags 2.13.1", - "objc2", + "objc2 0.6.4", "objc2-core-foundation", "objc2-core-graphics", - "objc2-foundation", - "objc2-metal", + "objc2-foundation 0.3.2", + "objc2-metal 0.3.2", ] [[package]] @@ -5778,16 +6106,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74b7c5390f477482f001bc354d6571a70db7e4f8d5288e860c45521fbce11394" dependencies = [ "bitflags 2.13.1", - "block2", + "block2 0.6.2", "dispatch2", "libc", - "objc2", + "objc2 0.6.4", "objc2-av-foundation", "objc2-core-foundation", "objc2-core-graphics", "objc2-core-media", - "objc2-foundation", - "objc2-uniform-type-identifiers", + "objc2-foundation 0.3.2", + "objc2-uniform-type-identifiers 0.3.2", ] [[package]] @@ -5797,7 +6125,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "709fe137109bd1e8b5a99390f77a7d8b2961dafc1a1c5db8f2e60329ad6d895a" dependencies = [ "bitflags 2.13.1", - "objc2", + "objc2 0.6.4", "objc2-core-foundation", ] @@ -5807,8 +6135,18 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef76382e9cedd18123099f17638715cc3d81dba3637d4c0d39ab69df2ef345a5" dependencies = [ - "objc2", - "objc2-foundation", + "objc2 0.6.4", + "objc2-foundation 0.3.2", +] + +[[package]] +name = "objc2-symbols" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a684efe3dec1b305badae1a28f6555f6ddd3bb2c2267896782858d5a78404dc" +dependencies = [ + "objc2 0.5.2", + "objc2-foundation 0.2.2", ] [[package]] @@ -5820,19 +6158,64 @@ dependencies = [ "bitflags 2.13.1", "dispatch2", "libc", - "objc2", + "objc2 0.6.4", "objc2-core-foundation", "objc2-security", ] +[[package]] +name = "objc2-ui-kit" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8bb46798b20cd6b91cbd113524c490f1686f4c4e8f49502431415f3512e2b6f" +dependencies = [ + "bitflags 2.13.1", + "block2 0.5.1", + "objc2 0.5.2", + "objc2-cloud-kit", + "objc2-core-data", + "objc2-core-image 0.2.2", + "objc2-core-location", + "objc2-foundation 0.2.2", + "objc2-link-presentation", + "objc2-quartz-core 0.2.2", + "objc2-symbols", + "objc2-uniform-type-identifiers 0.2.2", + "objc2-user-notifications", +] + +[[package]] +name = "objc2-uniform-type-identifiers" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44fa5f9748dbfe1ca6c0b79ad20725a11eca7c2218bceb4b005cb1be26273bfe" +dependencies = [ + "block2 0.5.1", + "objc2 0.5.2", + "objc2-foundation 0.2.2", +] + [[package]] name = "objc2-uniform-type-identifiers" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7902ac02859fc1f7045f8b598c63f1ae0cc7efeaa06a9bc9f3d9a3c955974fa4" dependencies = [ - "objc2", - "objc2-foundation", + "objc2 0.6.4", + "objc2-foundation 0.3.2", +] + +[[package]] +name = "objc2-user-notifications" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76cfcbf642358e8689af64cee815d139339f3ed8ad05103ed5eaf73db8d84cb3" +dependencies = [ + "bitflags 2.13.1", + "block2 0.5.1", + "objc2 0.5.2", + "objc2-core-location", + "objc2-foundation 0.2.2", ] [[package]] @@ -5842,14 +6225,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05bf9a3c14831a7d9641b0d81d87dd913ee238a012b2fde27db5a84b56f5df3e" dependencies = [ "bitflags 2.13.1", - "block2", - "objc2", + "block2 0.6.2", + "objc2 0.6.4", "objc2-core-foundation", "objc2-core-graphics", "objc2-core-media", "objc2-core-video", - "objc2-foundation", - "objc2-metal", + "objc2-foundation 0.3.2", + "objc2-metal 0.3.2", ] [[package]] @@ -5997,6 +6380,16 @@ dependencies = [ "paste", ] +[[package]] +name = "orbclient" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5df339f526ea9a60e371768d50efc2f2508c7203290731565d1f7a6f71d21747" +dependencies = [ + "libc", + "libredox", +] + [[package]] name = "ordered-float" version = "5.3.0" @@ -6016,6 +6409,15 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "owned_ttf_parser" +version = "0.25.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36820e9051aca1014ddc75770aab4d68bc1e9e632f0f5627c4086bc216fb583b" +dependencies = [ + "ttf-parser", +] + [[package]] name = "p256" version = "0.14.0" @@ -6089,7 +6491,7 @@ dependencies = [ "cfg-if", "libc", "petgraph", - "redox_syscall", + "redox_syscall 0.5.18", "smallvec", "windows-link", ] @@ -6316,6 +6718,20 @@ dependencies = [ "plotters-backend", ] +[[package]] +name = "polling" +version = "3.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d0e4f59085d47d8241c88ead0f274e8a0cb551f3625263c05eb8dd897c34218" +dependencies = [ + "cfg-if", + "concurrent-queue", + "hermit-abi", + "pin-project-lite", + "rustix 1.1.4", + "windows-sys 0.61.2", +] + [[package]] name = "pollster" version = "1.0.1" @@ -6916,10 +7332,10 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40d213455a5f1dc59214213c7330e074ddf8114c9a42411eb890c767357ce135" dependencies = [ - "objc2", + "objc2 0.6.4", "objc2-core-foundation", - "objc2-foundation", - "objc2-quartz-core", + "objc2-foundation 0.3.2", + "objc2-quartz-core 0.3.2", ] [[package]] @@ -6957,6 +7373,15 @@ dependencies = [ "yasna", ] +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + [[package]] name = "redox_syscall" version = "0.5.18" @@ -6966,6 +7391,15 @@ dependencies = [ "bitflags 2.13.1", ] +[[package]] +name = "redox_syscall" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07507be7b4a5f9f26eeb41eeaebb1f5a7ff29dfb29739facc21d35bf8b11c21e" +dependencies = [ + "bitflags 2.13.1", +] + [[package]] name = "ref-cast" version = "1.0.26" @@ -7402,6 +7836,19 @@ dependencies = [ "syn 2.0.119", ] +[[package]] +name = "sctk-adwaita" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6277f0217056f77f1d8f49f2950ac6c278c0d607c45f5ee99328d792ede24ec" +dependencies = [ + "ab_glyph", + "log", + "memmap2", + "smithay-client-toolkit", + "tiny-skia", +] + [[package]] name = "sctp-proto" version = "0.10.2" @@ -7968,6 +8415,40 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8e2fb0f499abb4d162f2bedad68f5ef91a1682b5a03596ddb67efd37768d100" +[[package]] +name = "smithay-client-toolkit" +version = "0.19.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3457dea1f0eb631b4034d61d4d8c32074caa6cd1ab2d59f2327bd8461e2c0016" +dependencies = [ + "bitflags 2.13.1", + "calloop", + "calloop-wayland-source", + "cursor-icon", + "libc", + "log", + "memmap2", + "rustix 0.38.44", + "thiserror 1.0.69", + "wayland-backend", + "wayland-client", + "wayland-csd-frame", + "wayland-cursor", + "wayland-protocols", + "wayland-protocols-wlr", + "wayland-scanner", + "xkeysym", +] + +[[package]] +name = "smol_str" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd538fb6910ac1099850255cf94a94df6551fbdd602454387d0adb2d1ca6dead" +dependencies = [ + "serde", +] + [[package]] name = "socket2" version = "0.5.10" @@ -8243,6 +8724,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "strict-num" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731" + [[package]] name = "strsim" version = "0.11.1" @@ -8573,6 +9060,31 @@ dependencies = [ "time-core", ] +[[package]] +name = "tiny-skia" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83d13394d44dae3207b52a326c0c85a8bf87f1541f23b0d143811088497b09ab" +dependencies = [ + "arrayref", + "arrayvec", + "bytemuck", + "cfg-if", + "log", + "tiny-skia-path", +] + +[[package]] +name = "tiny-skia-path" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c9e7fc0c2e86a30b117d0462aa261b72b7a99b7ebd7deb3a14ceda95c5bdc93" +dependencies = [ + "arrayref", + "bytemuck", + "strict-num", +] + [[package]] name = "tinystr" version = "0.8.3" @@ -9102,6 +9614,12 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "ttf-parser" +version = "0.25.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2df906b07856748fa3f6e0ad0cbaa047052d4a7dd609e231c4f72cee8c36f31" + [[package]] name = "tungstenite" version = "0.29.0" @@ -9579,6 +10097,103 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "wayland-backend" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "016ccf01d1c58b6f8999612813e17c9b2390f7d70671428869913310f83f54b8" +dependencies = [ + "cc", + "downcast-rs", + "rustix 1.1.4", + "scoped-tls", + "smallvec", + "wayland-sys", +] + +[[package]] +name = "wayland-client" +version = "0.31.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3c36a0f861ad76d0901f2800b46321410d9f73f2ea88aac0650d86c32688073" +dependencies = [ + "bitflags 2.13.1", + "rustix 1.1.4", + "wayland-backend", + "wayland-scanner", +] + +[[package]] +name = "wayland-csd-frame" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "625c5029dbd43d25e6aa9615e88b829a5cad13b2819c4ae129fdbb7c31ab4c7e" +dependencies = [ + "bitflags 2.13.1", + "cursor-icon", + "wayland-backend", +] + +[[package]] +name = "wayland-cursor" +version = "0.31.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a52d18780be9b1314328a3de5f930b73d2200112e3849ca6cb11822793fb34d" +dependencies = [ + "rustix 1.1.4", + "wayland-client", + "xcursor", +] + +[[package]] +name = "wayland-protocols" +version = "0.32.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23d0c813de3daa2ed6520af85a3bd49b0e722a3078506899aa9686fea58dc4b6" +dependencies = [ + "bitflags 2.13.1", + "wayland-backend", + "wayland-client", + "wayland-scanner", +] + +[[package]] +name = "wayland-protocols-plasma" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b6d8cf1eb2c1c31ed1f5643c88a6e53538129d4af80030c8cabd1f9fa884d91" +dependencies = [ + "bitflags 2.13.1", + "wayland-backend", + "wayland-client", + "wayland-protocols", + "wayland-scanner", +] + +[[package]] +name = "wayland-protocols-wlr" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb04e52f7836d7c7976c78ca0250d61e33873c34156a2a1fc9474828ec268234" +dependencies = [ + "bitflags 2.13.1", + "wayland-backend", + "wayland-client", + "wayland-protocols", + "wayland-scanner", +] + +[[package]] +name = "wayland-scanner" +version = "0.31.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "338e30461b3a2b67d70eb30a6d89f8e0c93a833e07d2ae89085cd070c4a00ac0" +dependencies = [ + "proc-macro2", + "quick-xml", + "quote", +] + [[package]] name = "wayland-sys" version = "0.31.11" @@ -9891,7 +10506,7 @@ dependencies = [ "ash", "bit-set", "bitflags 2.13.1", - "block2", + "block2 0.6.2", "bytemuck", "cfg-if", "cfg_aliases", @@ -9907,12 +10522,12 @@ dependencies = [ "naga", "naga-types", "ndk-sys", - "objc2", + "objc2 0.6.4", "objc2-core-foundation", "objc2-core-graphics", - "objc2-foundation", - "objc2-metal", - "objc2-quartz-core", + "objc2-foundation 0.3.2", + "objc2-metal 0.3.2", + "objc2-quartz-core 0.3.2", "once_cell", "ordered-float", "parking_lot", @@ -10382,6 +10997,58 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" +[[package]] +name = "winit" +version = "0.30.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6755fa58a9f8350bd1e472d4c3fcc25f824ec358933bba33306d0b63df5978d" +dependencies = [ + "ahash", + "android-activity", + "atomic-waker", + "bitflags 2.13.1", + "block2 0.5.1", + "bytemuck", + "calloop", + "cfg_aliases", + "concurrent-queue", + "core-foundation 0.9.4", + "core-graphics", + "cursor-icon", + "dpi", + "js-sys", + "libc", + "memmap2", + "ndk", + "objc2 0.5.2", + "objc2-app-kit", + "objc2-foundation 0.2.2", + "objc2-ui-kit", + "orbclient", + "percent-encoding", + "pin-project", + "raw-window-handle", + "redox_syscall 0.4.1", + "rustix 0.38.44", + "sctk-adwaita", + "smithay-client-toolkit", + "smol_str", + "tracing", + "unicode-segmentation", + "wasm-bindgen", + "wasm-bindgen-futures", + "wayland-backend", + "wayland-client", + "wayland-protocols", + "wayland-protocols-plasma", + "web-sys", + "web-time", + "windows-sys 0.52.0", + "x11-dl", + "x11rb", + "xkbcommon-dl", +] + [[package]] name = "winnow" version = "0.7.15" @@ -10480,6 +11147,38 @@ dependencies = [ "web-sys", ] +[[package]] +name = "x11-dl" +version = "2.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38735924fedd5314a6e548792904ed8c6de6636285cb9fec04d5b1db85c1516f" +dependencies = [ + "libc", + "once_cell", + "pkg-config", +] + +[[package]] +name = "x11rb" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9993aa5be5a26815fe2c3eacfc1fde061fc1a1f094bf1ad2a18bf9c495dd7414" +dependencies = [ + "as-raw-xcb-connection", + "gethostname", + "libc", + "libloading 0.8.9", + "once_cell", + "rustix 1.1.4", + "x11rb-protocol", +] + +[[package]] +name = "x11rb-protocol" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea6fc2961e4ef194dcbfe56bb845534d0dc8098940c7e5c012a258bfec6701bd" + [[package]] name = "x509-cert" version = "0.2.5" @@ -10510,6 +11209,31 @@ dependencies = [ "time", ] +[[package]] +name = "xcursor" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "163b33ed8786455e2fa5d72f554057ce3f3182425434f756cd39c99839d88e23" + +[[package]] +name = "xkbcommon-dl" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d039de8032a9a8856a6be89cea3e5d12fdd82306ab7c94d74e6deab2460651c5" +dependencies = [ + "bitflags 2.13.1", + "dlib", + "log", + "once_cell", + "xkeysym", +] + +[[package]] +name = "xkeysym" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9cc00251562a284751c9973bace760d86c0276c471b4be569fe6b068ee97a56" + [[package]] name = "xml-rs" version = "0.8.28" diff --git a/deny.toml b/deny.toml index 378e538f0ba..64dc5edf2b0 100644 --- a/deny.toml +++ b/deny.toml @@ -26,6 +26,13 @@ ignore = [ # needs Rust 1.92, above the 1.91 workspace MSRV. Build-time only. "RUSTSEC-2024-0436", + # ttf-parser is unmaintained, with no upgrade available. Reachable only via + # winit -> sctk-adwaita -> ab_glyph, which parses the system font used to + # draw Wayland client-side decorations for `moq play`. Dropping winit's + # `wayland-csd-adwaita` feature would remove it, at the cost of a titlebar + # on GNOME. Awaits sctk-adwaita migrating to skrifa. + "RUSTSEC-2026-0192", + ] [licenses] diff --git a/doc/bin/cli.md b/doc/bin/cli.md index 36db4c40067..274d9366c85 100644 --- a/doc/bin/cli.md +++ b/doc/bin/cli.md @@ -6,8 +6,8 @@ description: Command-line tools for MoQ media # FFmpeg / moq-cli `moq-cli` is a media router: it wires one endpoint onto a shared MoQ Origin. It -moves media into MoQ from a source, or out of MoQ to a sink, bridging stdin/stdout -(via FFmpeg), HLS, RTMP, SRT, and WebRTC. +moves media into MoQ from a source, out of MoQ to a sink, or plays a broadcast +locally, bridging stdin/stdout (via FFmpeg), HLS, RTMP, SRT, and WebRTC. ## Installation @@ -74,6 +74,7 @@ Each signal writes a numbered `/tmp/moq.heap.*.heap` profile for analysis with ``` moq [endpoint options] +moq play [playback options] ``` - **MoQ side** attaches the Origin to the network, and comes before the verb. At @@ -90,6 +91,7 @@ moq [endpoint options] run); see [Redundant Publishers](#redundant-publishers-11). - **`import`** routes media INTO MoQ (a source fills the Origin); **`export`** routes it OUT (a sink drains the Origin). The verb fixes the data direction. +- **`play`** subscribes to a broadcast and plays its audio and video locally. - **endpoint** is one subcommand: a container format (`avc3`, `fmp4`, `ts`, `flv` read from stdin on import; `fmp4`, `mkv`, `ts`, `flv` written to stdout on export), or a gateway (`hls`, `rtmp`, `srt`, `rtc`). For the bidirectional @@ -109,6 +111,69 @@ side and reject one if given. `moq import ` reads a container from stdin; `moq export ` writes one to stdout. +### Play a Broadcast + +Native playback is gated behind the `play` feature, which adds the platform +window, graphics, decoder, and speaker dependencies: + +```bash +cargo install moq-cli --no-default-features --features "iroh,quinn,websocket,play" +# or build from a checkout: +cargo build --release -p moq-cli --no-default-features --features "iroh,quinn,websocket,play" +# or run straight from that checkout: +cargo run -p moq-cli --no-default-features --features "iroh,quinn,websocket,play" -- \ + --client-connect https://relay.example.com/anon --broadcast my-stream.hang play +``` + +Drop the defaults on Linux, as above: the default `pipewire` feature links +libpipewire-0.3 at build time to give `import capture` a display source that +playback never uses. + +A Linux build still needs three system packages, whichever features are picked. +The speaker goes through cpal, which links ALSA, and `play` pulls in moq-video, +whose V4L2 camera capture is not behind a feature and whose bindgen wants +libclang. On Debian and Ubuntu: + +```bash +sudo apt install libasound2-dev libclang-dev libv4l-dev +``` + +macOS and Windows need nothing extra, so plain `--features play` is enough +there. + +Once built, play a broadcast with: + +```bash +moq --client-connect https://relay.example.com/anon --broadcast my-stream.hang play +``` + +`play` starts each media role as soon as the catalog offers a rendition it can +decode, independently of the other, and keeps following catalog updates until +both have started. Audio-only and video-only broadcasts play fine; playback ends +once every track it started has ended. It doesn't switch renditions afterwards, +so a publisher that replaces the one being played ends that role. + +Within a role it takes the first rendition it can decode, in track-name order, +which is arbitrary as a quality choice. Pass `--video-name` / `--audio-name` to +pick a specific rung of a ladder. Audio drives the video clock when both are +present. The window preserves the video's aspect ratio and can be closed with +Escape, the close button, or Ctrl-C. + +Playback decodes h264, h265, and av1 video, and opus and pcm audio, so +`--video-codec` / `--audio-codec` are rejected up front for anything else. +`--latency-max` controls how far a stalled media group may lag before it is +skipped and defaults to `500ms`. These flags all follow the `play` verb: + +```bash +moq --client-connect https://relay.example.com/anon --broadcast conference.hang \ + play --video-name hd --audio-name en --latency-max 250ms +``` + +Video decoding prefers the platform hardware backend and falls back to the +built-in software H.264 decoder. Rendering picks the best graphics API the +machine offers: Metal on macOS, and Vulkan ahead of D3D12 or OpenGL elsewhere. +Audio uses the system default output device through CoreAudio, WASAPI, or ALSA. + ### Publish a Video File Remux a file to MPEG-TS and pipe it in (`-c copy` avoids re-encoding): @@ -389,8 +454,9 @@ discovery. When omitted, it's auto-detected from the broadcast name suffix - `hangz` - the DEFLATE-compressed `catalog.json.z` catalog (opt-in; shares the `.hang` suffix and is never auto-detected) - `msf` - the MSF `catalog` track -Stdout exports can also select one rendition per media role before the sink -subcommand: +Stdout exports can also select one rendition per media role. The flags go before +the sink subcommand here; `play` takes the same four after its own verb (see +[Play a Broadcast](#play-a-broadcast)): ```bash moq --client-connect https://relay.example.com/anon --broadcast my-stream.hang \ @@ -400,7 +466,7 @@ moq --client-connect https://relay.example.com/anon --broadcast my-stream.hang \ - `--video-name ` picks the video rendition with that exact catalog name. - `--video-codec ` keeps only matching video renditions. - `--audio-name ` picks the audio rendition with that exact catalog name. -- `--audio-codec ` keeps only matching audio renditions. +- `--audio-codec ` keeps only matching audio renditions. With no selection flags, every matching rendition is kept. The `h264` and `h265` export sinks force the matching video codec, so use `export h264` / `export h265` diff --git a/rs/CLAUDE.md b/rs/CLAUDE.md index cc417a426d0..15c755b654c 100644 --- a/rs/CLAUDE.md +++ b/rs/CLAUDE.md @@ -169,7 +169,7 @@ Then `Config::load()?` (initializes tracing), build clients/servers via `.init() - **Local checks only compile the host's platform and target, and PR CI is Linux-only.** `#[cfg(target_os = "...")]` code for other platforms is invisible to them, and `cargo fmt` skips those modules too. Windows and Mac runners cost too much for a per-PR gate, so those platforms are manual: - - Windows (moq-video's Media Foundation and D3D11 backends): `just rs windows`, which must run ON Windows. You can't reproduce it elsewhere, since cross-compiling dies in openh264-sys2's vendored C++. + - Windows (moq-video's Media Foundation and D3D11 backends): `just rs windows`, which must run ON Windows. You can't reproduce it elsewhere, since cross-compiling dies in openh264-sys2's vendored C++. It names `moq-cli/play` explicitly, since that feature is what pulls in moq-video's wgpu renderer and moq-audio's cpal output; a default-feature build compiles neither. - macOS (moq-video's VideoToolbox and ScreenCaptureKit, moq-audio's system audio): `just rs macos`, which must run ON macOS. Scoped to moq-video + moq-audio, and needs `--all-features` because moq-audio's capture backend is off by default. - Linux: covered. `just rs ci` already runs `--all-features` in a dev shell carrying PipeWire and ALSA. VAAPI loads libva dynamically, so nvenc/nvdec/vaapi/pipewire all compile without libva installed. - wasm32 (moq-wasm): `just rs wasm`. The crate root is `#![cfg(target_arch = "wasm32")]`, so a host-target `cargo check --workspace` compiles it down to nothing and sees no errors at all. This one needs no special host (the Nix shell carries the target), so `just rs ci` and `just check-all` both run it, and `just check` adds it when the diff touches `rs/moq-wasm/`. It's a compile gate, distinct from the root `just wasm`, which builds the shippable `@moq/wasm` package. diff --git a/rs/justfile b/rs/justfile index 4c5c68b86f2..412ea00bd3a 100644 --- a/rs/justfile +++ b/rs/justfile @@ -142,10 +142,14 @@ fix-changed $FILES: # backend don't build on MSVC, while moq-video's Linux-only nvenc/nvdec defaults # are already no-ops off Linux. moq-gst is excluded because it links # GStreamer via pkg-config, which the Windows runner doesn't have. +# +# `moq-cli/play` is named explicitly because it's off by default and is what +# turns on moq-video's wgpu renderer and moq-audio's cpal output, neither of +# which any default-feature build compiles. # Compile the whole workspace on a Windows host. Must run ON Windows. windows *args: - cargo check --workspace --exclude moq-gst --all-targets {{ args }} + cargo check --workspace --exclude moq-gst --all-targets --features moq-cli/play {{ args }} # Runs the `#[cfg(target_os = "macos")]` code past the compiler: moq-video's # VideoToolbox encode/decode and its ScreenCaptureKit / AVFoundation capture, diff --git a/rs/moq-audio/src/decode/consumer.rs b/rs/moq-audio/src/decode/consumer.rs index 9191d5493ee..75b90b925af 100644 --- a/rs/moq-audio/src/decode/consumer.rs +++ b/rs/moq-audio/src/decode/consumer.rs @@ -14,7 +14,7 @@ use crate::{Error, Frame}; /// [`read`](Self::read) returns plain [`Frame`]s. pub struct Consumer { decoder: Decoder, - track: moq_mux::container::Consumer, + track: moq_mux::container::Consumer, resampler: Option, config: Config, resolved_sample_rate: u32, @@ -52,7 +52,11 @@ impl Consumer { .track(&name)? .subscribe(moq_net::track::Subscription::default().with_priority(hang::catalog::PRIORITY.audio)) .await?; - let mut track = moq_mux::container::Consumer::new(track, moq_mux::container::legacy::Wire); + // The catalog says how the track is framed, and it is not always the legacy + // wire: `moq import fmp4` publishes CMAF. Reading a moof+mdat fragment as a + // varint timestamp plus a payload decodes to garbage rather than failing. + let container = moq_mux::catalog::hang::Container::try_from(&catalog.container)?; + let mut track = moq_mux::container::Consumer::new(track, container); if let Some(latency) = config.latency_max { track = track.with_latency(latency); } @@ -164,4 +168,98 @@ mod tests { assert_eq!(pair[0], pair[1]); } } + + #[tokio::test] + async fn reads_the_container_the_catalog_declares() { + let mut broadcast = moq_net::broadcast::Info::new().produce(); + let track = broadcast.create_track("audio", hang::container::track_info()).unwrap(); + let subscriber = broadcast.consume(); + + let mut catalog = hang::catalog::AudioConfig::new(hang::catalog::AudioCodec::Pcm, 48_000, 1); + catalog.container = hang::catalog::Container::Loc; + + let mut producer = moq_mux::container::Producer::new(track, moq_mux::catalog::hang::Container::Loc); + let mut consumer = Consumer::new( + &subscriber, + &catalog, + "audio", + Config { + format: Format::F32, + ..Config::new() + }, + ) + .await + .unwrap(); + + let samples = [0.25f32, -0.5, 0.75, -1.0]; + let payload: Vec = samples.iter().flat_map(|sample| sample.to_le_bytes()).collect(); + producer + .write(moq_mux::container::Frame { + timestamp: Timestamp::ZERO, + duration: None, + payload: payload.into(), + keyframe: true, + }) + .unwrap(); + + let frame = consumer.read().await.unwrap().expect("decoded frame"); + assert_eq!( + Format::F32.as_interleaved_f32(&frame.data, 1).unwrap().as_ref(), + samples + ); + } + + /// The catalog picks the framing, not this crate. Hardcoding the legacy wire + /// read a CMAF fragment as a varint timestamp plus a payload, which handed the + /// codec garbage instead of failing, so anything published by `moq import + /// fmp4` was undecodable. + #[tokio::test] + async fn decodes_a_cmaf_framed_track() { + let input = Input { + format: Format::F32, + sample_rate: 48_000, + channels: 2, + }; + + // One real Opus packet, so a mis-framed read can't accidentally decode. + let mut encoder = Encoder::new(&crate::encode::Config::new(input.clone())).unwrap(); + let mut catalog = encoder.catalog(); + let pcm = vec![0.0f32; encoder.frame_size() * encoder.codec_channels() as usize]; + let packet = encoder.encode(&pcm).unwrap(); + + // Re-describe the same rendition as CMAF and publish it that way. + let muxer = moq_mux::container::fmp4::Muxer::audio(&catalog).unwrap(); + let init = muxer.init().unwrap().expect("an out-of-band codec has an init segment"); + catalog.container = hang::catalog::Container::Cmaf { init }; + + let mut broadcast = moq_net::broadcast::Info::new().produce(); + let subscriber = broadcast.consume(); + let track = broadcast.create_track("audio", hang::container::track_info()).unwrap(); + let container = moq_mux::catalog::hang::Container::try_from(&catalog.container).unwrap(); + let mut producer = moq_mux::container::Producer::new(track, container); + + let mut consumer = Consumer::new(&subscriber, &catalog, "audio", Config::new()) + .await + .unwrap(); + + producer + .write(moq_mux::container::Frame { + timestamp: Timestamp::ZERO, + payload: packet, + keyframe: true, + duration: None, + }) + .unwrap(); + producer.cut(None).unwrap(); + + // The whole packet decodes: one 20 ms Opus frame at 48 kHz, less the pre-skip + // trimmed off the first packet. Reading the fragment as legacy hands the codec + // a slice of the moof instead, which still decodes, just to a shorter buffer. + let frame = consumer.read().await.unwrap().expect("decoded frame"); + // `as_micros`, not `==`: the CMAF path carries the fmp4 timescale and + // `Timestamp`'s equality is structural, so the scales would have to match too. + assert_eq!(frame.timestamp.as_micros(), 0); + let samples = Format::F32.as_interleaved_f32(&frame.data, 2).unwrap(); + assert_eq!(samples.len(), (960 - 312) * 2); + } } diff --git a/rs/moq-audio/src/playback.rs b/rs/moq-audio/src/playback.rs index 5a3dbb9746b..4e3a45d8801 100644 --- a/rs/moq-audio/src/playback.rs +++ b/rs/moq-audio/src/playback.rs @@ -1,6 +1,9 @@ //! Play decoded PCM out a speaker, via [`cpal`] (CoreAudio / WASAPI / ALSA). //! -//! The playback counterpart to [`capture`](crate::capture), and where a +//! The playback counterpart to `capture`, and where a +// `capture` is deliberately not a doc link: the module is behind the +// off-by-default `capture` feature, so a link to it fails the `-D warnings` +// rustdoc build of a playback-only build (what `moq-cli`'s `play` enables). //! [`decode::Consumer`](crate::decode::Consumer) ends up: //! //! ```no_run diff --git a/rs/moq-cli/Cargo.toml b/rs/moq-cli/Cargo.toml index 7295a87cbe1..8f34fe87be2 100644 --- a/rs/moq-cli/Cargo.toml +++ b/rs/moq-cli/Cargo.toml @@ -40,6 +40,10 @@ capture = ["dep:moq-video", "dep:moq-audio", "moq-audio/capture"] # in moq-video and its codec dependencies. Enable with # `cargo build -p moq-cli --features transcode`. transcode = ["dep:moq-transcode", "dep:moq-video"] +# Native playback (`moq ... play`): decode into a wgpu window and a cpal +# speaker. Off by default because it pulls both graphics and audio device stacks +# into a binary that may only be routing containers or serving gateways. +play = ["dep:moq-video", "moq-video/render", "dep:moq-audio", "moq-audio/playback", "dep:pollster", "dep:winit"] # NVIDIA hardware codecs for `capture` (Linux), on by default. Each just turns on # the matching moq-video feature, and only bites when `capture` pulls in moq-video. # For a `capture` build with no CUDA dependencies, drop them, e.g. @@ -73,11 +77,13 @@ moq-srt = { workspace = true } moq-token-cli = { workspace = true } moq-transcode = { workspace = true, optional = true } moq-video = { workspace = true, optional = true } +pollster = { version = "1.0", optional = true } rustls = { version = "0.23", features = ["aws-lc-rs"], default-features = false } tokio = { workspace = true, features = ["full"] } tower-http = { version = "0.7", features = ["cors"] } tracing = "0.1" url = "2" +winit = { version = "0.30.13", optional = true } [target.'cfg(unix)'.dependencies] sd-notify = "0.5" diff --git a/rs/moq-cli/README.md b/rs/moq-cli/README.md index 6e413e17267..3e63955df08 100644 --- a/rs/moq-cli/README.md +++ b/rs/moq-cli/README.md @@ -19,7 +19,7 @@ Multi-arch images (`linux/amd64` and `linux/arm64`) are published to [Docker Hub ## Usage -`moq-cli` routes one endpoint onto a shared MoQ Origin: `moq `. The MoQ side (before the verb) is either `--client-connect ` (dial a relay) or `--server-bind ` (self-host). `import` moves media into MoQ, `export` moves it out. The endpoint is a container format (`fmp4`, `ts`, `flv`, ... read from stdin / written to stdout), or a gateway (`hls`, `rtmp`, `srt`, `rtc`). +`moq-cli` routes one endpoint onto a shared MoQ Origin: `moq `. The MoQ side (before the verb) is either `--client-connect ` (dial a relay) or `--server-bind ` (self-host). `import` moves media into MoQ, `export` moves it out. The endpoint is a container format (`fmp4`, `ts`, `flv`, ... read from stdin / written to stdout), or a gateway (`hls`, `rtmp`, `srt`, `rtc`). A build with the `play` feature can also render a broadcast locally with `moq play`. ### Publish to a remote relay @@ -35,6 +35,12 @@ moq --client-connect https://relay.example.com --broadcast my-stream.hang export ffplay - ``` +Play the broadcast in a native window and speaker (requires `--features play` when building): + +```bash +moq --client-connect https://relay.example.com --broadcast my-stream.hang play +``` + ### Self-host: publish into a local relay Hosts a MoQ server and publishes a single broadcast read from stdin into it. Useful for local testing without a separate relay process. diff --git a/rs/moq-cli/src/args.rs b/rs/moq-cli/src/args.rs index 3ade0ed7d38..533277b85c2 100644 --- a/rs/moq-cli/src/args.rs +++ b/rs/moq-cli/src/args.rs @@ -1,6 +1,7 @@ //! The unified moq-cli argument surface. //! -//! Grammar: `moq [endpoint opts]`. +//! Grammar: `moq [endpoint opts]`, plus +//! `moq play` for native playback. //! //! - The MoQ side (`--client-connect` / `--server-bind`, both optional, at least //! one) attaches the shared Origin to the MoQ network, and comes before the @@ -138,6 +139,9 @@ pub enum Command { /// Route media OUT OF MoQ to one sink. #[command(alias = "subscribe")] Export(Export), + /// Play a broadcast in a native window and speaker. + #[cfg(feature = "play")] + Play(crate::play::Args), /// Re-encode `--broadcast` into a lower ladder, published next to it and /// only encoded while watched (just-in-time). #[cfg(feature = "transcode")] @@ -371,4 +375,51 @@ mod tests { assert!(err.contains(flag[0]), "{err}"); } } + + #[cfg(feature = "play")] + #[test] + fn play_verb() { + let cli = Cli::try_parse_from([ + "moq", + "--client-connect", + "https://relay.example.com/anon", + "--broadcast", + "room.hang", + "play", + "--video-name", + "hd", + ]) + .unwrap(); + let Command::Play(play) = cli.command else { + panic!("expected play") + }; + assert_eq!(play.latency_max, Duration::from_millis(500)); + assert_eq!(play.select.video_name.as_deref(), Some("hd")); + assert!(cli.moq.validate().is_ok()); + assert!(play.validate().is_ok()); + } + + /// The selection flags are shared with the exports, which pass every codec + /// through. Playback has to decode, so it rejects the rest up front instead + /// of filtering the catalog down to a rendition that can't open. + #[cfg(feature = "play")] + #[test] + fn play_rejects_undecodable_codecs() { + for flag in [["--video-codec", "vp9"], ["--audio-codec", "aac"]] { + let cli = Cli::try_parse_from([ + "moq", + "--client-connect", + "https://relay.example.com/anon", + "play", + flag[0], + flag[1], + ]) + .unwrap(); + let Command::Play(play) = cli.command else { + panic!("expected play") + }; + let err = play.validate().unwrap_err().to_string(); + assert!(err.contains(flag[1]), "{err}"); + } + } } diff --git a/rs/moq-cli/src/main.rs b/rs/moq-cli/src/main.rs index 8d82112cc85..b3c84a806d6 100644 --- a/rs/moq-cli/src/main.rs +++ b/rs/moq-cli/src/main.rs @@ -1,14 +1,16 @@ //! moq-cli: a media router that wires one endpoint onto a shared MoQ Origin. //! -//! The binary is `moq`. See [`args`] for the `import`/`export` command grammar; -//! this module orchestrates the shared Origin and spawns the MoQ side plus the -//! selected endpoint. +//! The binary is `moq`. See [`args`] for the `import`/`export`/`play` command +//! grammar; this module orchestrates the shared Origin and spawns the MoQ side +//! plus the selected endpoint. mod args; #[cfg(feature = "capture")] mod devices; mod hls; mod moq; +#[cfg(feature = "play")] +mod play; mod publish; mod rtc; mod rtmp; @@ -104,6 +106,8 @@ async fn main() -> anyhow::Result<()> { match cli.command { Command::Import(import) => run_import(cli.moq, import, net).await, Command::Export(export) => run_export(cli.moq, export, net).await, + #[cfg(feature = "play")] + Command::Play(args) => run_play(cli.moq, args, net).await, #[cfg(feature = "transcode")] Command::Transcode(args) => transcode::run(cli.moq, args, net).await, Command::Token(_) => unreachable!("handled above, before the transport is bound"), @@ -118,6 +122,50 @@ async fn main() -> anyhow::Result<()> { } } +/// Attach the MoQ side so it fills the shared Origin: dial a relay, accept +/// inbound sessions, or both. Shared by every verb that consumes. +fn spawn_moq_consume( + moq: &MoqSide, + net: &Net, + origin: &moq_net::origin::Producer, + tasks: &mut JoinSet>, +) -> anyhow::Result<()> { + if moq.client.connect.is_some() + && let Some(reconnect) = net.client(moq.client.clone())?.consume(origin.clone()) + { + moq::notify_ready(); + tasks.spawn(async move { Ok(reconnect.closed().await?) }); + } + if let Some(web_bind) = moq.server.bind.clone() { + let server = net.server(moq.server.clone())?; + let certificates = server.certificates(); + moq::notify_ready(); + let origin = origin.clone(); + tasks.spawn(async move { Ok(server.serve_consume(origin).await?) }); + tasks.spawn(async move { web::run_web(&web_bind, certificates).await }); + } + Ok(()) +} + +/// Fill the shared Origin from MoQ, then play one broadcast locally. +/// +/// The playback event loop runs on this task's thread rather than a spawned one: +/// winit can only build an event loop on the process main thread, which is where +/// `#[tokio::main]` polls this future. +#[cfg(feature = "play")] +async fn run_play(moq: MoqSide, args: play::Args, net: Net) -> anyhow::Result<()> { + // Before anything dials: a codec we can't decode is a blank window otherwise. + args.validate()?; + + let origin = moq.origin()?; + let name = moq.broadcast.clone().unwrap_or_default(); + let mut tasks: JoinSet> = JoinSet::new(); + + spawn_moq_consume(&moq, &net, &origin, &mut tasks)?; + + play::run(origin.consume(), name, args, tasks) +} + /// Route one source INTO the shared Origin, exposing it to the MoQ network. async fn run_import(moq: MoqSide, import: Import, net: Net) -> anyhow::Result<()> { let origin = moq.origin()?; @@ -261,20 +309,7 @@ async fn run_export(moq: MoqSide, export: Export, net: Net) -> anyhow::Result<() } // MoQ side: fill the Origin. - if moq.client.connect.is_some() - && let Some(reconnect) = net.client(moq.client.clone())?.consume(origin.clone()) - { - moq::notify_ready(); - tasks.spawn(async move { Ok(reconnect.closed().await?) }); - } - if let Some(web_bind) = moq.server.bind.clone() { - let server = net.server(moq.server.clone())?; - let certificates = server.certificates(); - moq::notify_ready(); - let origin = origin.clone(); - tasks.spawn(async move { Ok(server.serve_consume(origin).await?) }); - tasks.spawn(async move { web::run_web(&web_bind, certificates).await }); - } + spawn_moq_consume(&moq, &net, &origin, &mut tasks)?; // Foreign side: the single sink. if let Some((format, max_latency, fragment_duration)) = export.sink.stdout() { diff --git a/rs/moq-cli/src/play.rs b/rs/moq-cli/src/play.rs new file mode 100644 index 00000000000..2e5a95eaa35 --- /dev/null +++ b/rs/moq-cli/src/play.rs @@ -0,0 +1,979 @@ +//! Native playback for a MoQ broadcast. + +use std::collections::VecDeque; +use std::sync::{Arc, Mutex}; +use std::time::{Duration, Instant}; + +use anyhow::Context; +use clap::Args as ClapArgs; +use hang::moq_net; +use moq_mux::catalog::{self, CatalogFormat, Stream}; +use moq_video::render::wgpu; +use winit::application::ApplicationHandler; +use winit::dpi::LogicalSize; +use winit::event::{ElementState, KeyEvent, WindowEvent}; +use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop, EventLoopProxy}; +use winit::keyboard::{Key, NamedKey}; +use winit::window::{Window, WindowId}; + +use crate::subscribe::{CatalogFormatArg, SelectArgs}; + +/// Decoded frames held for presentation, and the point at which the decoder is +/// made to wait. About a second at 30fps: enough to absorb a burst, few enough +/// that raw frames can't run away with memory. +const MAX_VIDEO_FRAMES: usize = 30; + +/// How early a frame may be shown rather than waiting another wakeup for it. +/// Under a display's frame interval, so it can't be seen, but enough that timer +/// slop doesn't push every frame a whole refresh late. +const VIDEO_EARLY_TOLERANCE: Duration = Duration::from_millis(2); + +/// How far ahead of the speaker the decoder may run before we make it wait. +/// `Sink::write` never blocks and drops whatever won't fit, so a burst (a +/// completed group arriving all at once) would otherwise lose its tail. Well +/// under the sink's own ceiling, and well over the ~50 ms it settles at. +const AUDIO_BUFFER_MAX: Duration = Duration::from_secs(1); + +/// Consecutive surface rebuilds before a frame is written off. A display change +/// or a resume costs one; without a ceiling, a surface that can never present +/// would redraw forever, since each retry is what schedules the next. +const MAX_PRESENT_RETRIES: u32 = 8; + +/// Give up waiting on the speaker to drain this long after the last sample. +/// A device that never opens reports its queue as full forever, and a truncated +/// tail beats hanging on the way out. +const AUDIO_DRAIN_MAX: Duration = Duration::from_secs(4); + +/// Play one MoQ broadcast through a native window and speaker. +#[derive(ClapArgs, Clone)] +pub struct Args { + /// Catalog format, detected from the broadcast suffix when omitted. + #[arg(long)] + pub catalog_format: Option, + + /// Maximum media buffering before skipping a stalled group. + #[arg(long, default_value = "500ms", value_parser = humantime::parse_duration)] + pub latency_max: Duration, + + /// Rendition selection by track name or codec. + #[command(flatten)] + pub select: SelectArgs, +} + +impl Args { + fn catalog_format(&self, broadcast: &str) -> CatalogFormat { + self.catalog_format + .map(Into::into) + .or_else(|| CatalogFormat::detect(broadcast)) + .unwrap_or_default() + } + + /// Reject a codec the local decoders can't open. + /// + /// The selection flags are shared with the stdout exports, which pass bytes + /// through and so accept every codec the catalog can name. Asking for one of + /// those here would filter the catalog down to a rendition that then fails to + /// decode, leaving a blank window rather than an error. + pub fn validate(&self) -> anyhow::Result<()> { + use crate::subscribe::{AudioCodecArg, VideoCodecArg}; + + anyhow::ensure!( + !matches!(self.select.video_codec, Some(VideoCodecArg::Vp8 | VideoCodecArg::Vp9)), + "`play` cannot decode vp8 or vp9; pass --video-codec h264, h265, or av1" + ); + anyhow::ensure!( + !matches!(self.select.audio_codec, Some(AudioCodecArg::Aac)), + "`play` cannot decode aac; pass --audio-codec opus or pcm" + ); + Ok(()) + } +} + +#[derive(Clone, Copy)] +struct Clock { + media: Duration, + wall: Instant, +} + +impl Clock { + fn now(self) -> Duration { + self.media.saturating_add(self.wall.elapsed()) + } +} + +enum Event { + Wake, + /// Stop now: Ctrl-C, or the transport is gone and there is nothing more coming. + Finished, + /// Every track reached its end. Present what is still queued, then stop. + Ended, + Failed(String), +} + +/// Run native playback on the calling thread until the window closes. +/// +/// Blocking is deliberate: winit only builds an event loop on the process main +/// thread, so this has to stay on the `#[tokio::main]` future rather than being +/// spawned. Media and transport run on tasks and talk to it through the proxy. +pub fn run( + origin: moq_net::origin::Consumer, + broadcast: String, + args: Args, + network: tokio::task::JoinSet>, +) -> anyhow::Result<()> { + let event_loop = EventLoop::::with_user_event() + .build() + .context("failed to create the playback event loop")?; + let proxy = event_loop.create_proxy(); + let video = Arc::new(Mutex::new(VecDeque::new())); + let audio_clock = Arc::new(Mutex::new(None)); + // Signals the decoder that the presenter took a frame, so it can hand over + // the next one instead of dropping it. + let drained = Arc::new(tokio::sync::Notify::new()); + + let media = tokio::spawn( + Media { + origin, + broadcast: broadcast.clone(), + args, + video: video.clone(), + audio_clock: audio_clock.clone(), + drained: drained.clone(), + proxy: proxy.clone(), + } + .run(), + ); + let network = tokio::spawn(watch_network(network, proxy.clone())); + let signal = tokio::spawn({ + let proxy = proxy.clone(); + async move { + if tokio::signal::ctrl_c().await.is_ok() { + let _ = proxy.send_event(Event::Finished); + } + } + }); + + let title = if broadcast.is_empty() { + "moq play".to_string() + } else { + format!("moq play: {broadcast}") + }; + let mut app = App::new(title, video, audio_clock, drained); + let result = event_loop.run_app(&mut app).context("playback event loop failed"); + media.abort(); + network.abort(); + signal.abort(); + result?; + + match app.error { + Some(err) => anyhow::bail!(err), + None => Ok(()), + } +} + +/// Wait for `broadcast` to be announced on `origin`, then subscribe to it. +/// +/// The wait is the whole point. Subscribing goes through +/// `origin::Consumer::request_broadcast`, which resolves `Unroutable` on the +/// spot when no session has registered a handler yet rather than waiting for +/// one, and the media task starts well before the first handshake lands. The +/// window is already up, so this shows as a black frame rather than as a hang. +async fn subscribe(origin: moq_net::origin::Consumer, broadcast: &str) -> anyhow::Result { + origin + .announced_broadcast(broadcast) + .await + .with_context(|| format!("origin closed before broadcast `{broadcast}` was announced"))?; + + Ok(moq_mux::Source::new(origin, broadcast)) +} + +async fn watch_network(mut tasks: tokio::task::JoinSet>, proxy: EventLoopProxy) { + while let Some(result) = tasks.join_next().await { + let event = match result { + Ok(Ok(())) => Event::Finished, + Ok(Err(err)) => Event::Failed(format!("MoQ transport failed: {err:#}")), + Err(err) if err.is_cancelled() => continue, + Err(err) => Event::Failed(format!("MoQ transport task failed: {err}")), + }; + let _ = proxy.send_event(event); + return; + } +} + +/// Everything the media task needs to fill the window and the speaker. +struct Media { + origin: moq_net::origin::Consumer, + broadcast: String, + args: Args, + video: Arc>>, + audio_clock: Arc>>, + drained: Arc, + proxy: EventLoopProxy, +} + +impl Media { + async fn run(self) { + let proxy = self.proxy.clone(); + let event = match self.play().await { + Ok(()) => Event::Ended, + Err(err) => Event::Failed(format!("{err:#}")), + }; + let _ = proxy.send_event(event); + } + + async fn play(self) -> anyhow::Result<()> { + let source = subscribe(self.origin.clone(), &self.broadcast).await?; + let broadcast = source + .broadcast() + .await + .context("failed to subscribe to the broadcast")?; + let catalog = catalog::Consumer::<()>::new(&broadcast, self.args.catalog_format(&self.broadcast)) + .await + .context("failed to subscribe to the catalog")?; + let mut catalogs = catalog.select(self.args.select.selection(None)); + let mut tasks = tokio::task::JoinSet::new(); + let mut video_started = false; + let mut audio_started = false; + // Set once the catalog track ends, which disarms the branch below: a stream + // that has returned `None` returns it forever, so polling it again spins. + let mut catalog_ended = false; + + loop { + // Audio and video end independently, so one track finishing is not the end + // of playback. Stop once every track that started has ended. + if tasks.is_empty() && (video_started || audio_started) { + return Ok(()); + } + + tokio::select! { + result = tasks.join_next(), if !tasks.is_empty() => { + joined(result.expect("guarded by is_empty"))?; + } + snapshot = catalogs.next(), if !catalog_ended && (!video_started || !audio_started) => { + let Some(snapshot) = snapshot.context("failed to read the catalog")? else { + anyhow::ensure!(video_started || audio_started, "the catalog contains no playable audio or video renditions"); + catalog_ended = true; + continue; + }; + + // Why nothing started, so a catalog this build can't play reports the + // reason instead of leaving a blank window up forever. The decoders are + // gated by platform and cargo feature (no AV1 without nvdec, say), so + // this covers gaps the codec flags can't be validated against up front. + let mut rejected = Vec::new(); + + if !video_started { + for (name, config) in snapshot.video.renditions { + // A rendition pointing at a broadcast we can't reach is that + // rendition's problem, not the catalog's: fall through to the + // next one like an unsupported codec does. + let rendition = match source.resolve(config.broadcast.as_ref()).await { + Ok(rendition) => rendition, + Err(err) => { + tracing::warn!(track = name, %err, "cannot resolve video rendition"); + rejected.push(format!("video `{name}`: {err}")); + continue; + } + }; + let mut decode = moq_video::decode::Config::new(); + decode.latency_max = Some(self.args.latency_max); + match moq_video::decode::Consumer::new(&rendition, &config, &name, decode).await { + Ok(consumer) => { + tracing::info!(track = name, decoder = consumer.name(), "playing video rendition"); + tasks.spawn(play_video( + consumer, + self.video.clone(), + self.drained.clone(), + self.proxy.clone(), + )); + video_started = true; + break; + } + Err(err) => { + tracing::warn!(track = name, %err, "cannot play video rendition"); + rejected.push(format!("video `{name}`: {err}")); + } + } + } + } + + if !audio_started { + for (name, config) in snapshot.audio.renditions { + let rendition = match source.resolve(config.broadcast.as_ref()).await { + Ok(rendition) => rendition, + Err(err) => { + tracing::warn!(track = name, %err, "cannot resolve audio rendition"); + rejected.push(format!("audio `{name}`: {err}")); + continue; + } + }; + let mut decode = moq_audio::decode::Config::new(); + decode.latency_max = Some(self.args.latency_max); + // The sink and the frame-duration math below both assume f32, + // so ask for it rather than inheriting the decoder default. + decode.format = moq_audio::Format::F32; + match moq_audio::decode::Consumer::new(&rendition, &config, &name, decode).await { + Ok(consumer) => { + tracing::info!(track = name, "playing audio rendition"); + tasks.spawn(play_audio(consumer, self.audio_clock.clone(), self.proxy.clone())); + audio_started = true; + break; + } + Err(err) => { + tracing::warn!(track = name, %err, "cannot play audio rendition"); + rejected.push(format!("audio `{name}`: {err}")); + } + } + } + } + + // Renditions on offer and not one of them playable, with nothing + // already running to fall back on. + anyhow::ensure!( + !tasks.is_empty() || rejected.is_empty(), + "no playable rendition in the catalog: {}", + rejected.join("; ") + ); + } + } + } + } +} + +fn joined(result: Result, tokio::task::JoinError>) -> anyhow::Result<()> { + match result { + Ok(result) => result, + Err(err) if err.is_cancelled() => Ok(()), + Err(err) => Err(err.into()), + } +} + +async fn play_video( + mut consumer: moq_video::decode::Consumer, + video: Arc>>, + drained: Arc, + proxy: EventLoopProxy, +) -> anyhow::Result<()> { + while let Some(frame) = consumer.read().await? { + // Wait for room rather than dropping the oldest. Audio is paced to real + // time, so during a catch-up burst the frames at the front are still ahead + // of the clock, and dropping them would blank the window until the clock + // reached whatever survived. The presentation clock is anchored to the wall + // clock, so the queue always drains and this always clears. + while video.lock().unwrap().len() >= MAX_VIDEO_FRAMES { + drained.notified().await; + } + + video.lock().unwrap().push_back(frame); + let _ = proxy.send_event(Event::Wake); + } + Ok(()) +} + +async fn play_audio( + mut consumer: moq_audio::decode::Consumer, + clock: Arc>>, + proxy: EventLoopProxy, +) -> anyhow::Result<()> { + let sample_rate = consumer.sample_rate(); + let channels = consumer.channels(); + let engine = moq_audio::playback::Engine::open(Default::default()).await?; + let mut sink = engine.sink(moq_audio::playback::Input { + format: moq_audio::Format::F32, + sample_rate, + channels, + })?; + + // One sample across every channel, the unit a write has to stay aligned to. + let stride = channels as usize * size_of::(); + // A second per write, so a frame longer than the sink can hold is paced in + // rather than handed over whole and truncated. An Opus packet caps at 120 ms, + // but a PCM one is only required to be sample-aligned, so it can be any length. + // Paired with the wait below this keeps the sink under two seconds, inside its + // own ceiling. + let chunk = (sample_rate as usize * stride).max(stride); + + while let Some(frame) = consumer.read().await? { + let samples = frame.data.len() / size_of::() / channels as usize; + let end = + timestamp(frame.timestamp).saturating_add(Duration::from_secs_f64(samples as f64 / sample_rate as f64)); + + for part in frame.data.chunks(chunk) { + // Let the speaker catch up before handing it more than it can hold. + if let Some(excess) = sink.buffered().checked_sub(AUDIO_BUFFER_MAX) { + tokio::time::sleep(excess).await; + } + sink.write(part)?; + } + + let previous = clock.lock().unwrap().replace(Clock { + media: end.saturating_sub(sink.buffered()), + wall: Instant::now(), + }); + // Only the very first sample needs a wake, to hand the render loop a clock + // to schedule against. After that the clock extrapolates from its wall + // anchor, so waking per 20 ms frame would just redraw the same picture. + if previous.is_none() { + let _ = proxy.send_event(Event::Wake); + } + } + + // The track ended, but the speaker is still a buffer behind. Play it out + // instead of cutting the tail off by dropping the sink. + let drain = async { + // A partial period is left to the device: waiting on the last few + // milliseconds costs a wakeup per iteration and can never fully settle. + while let Some(remaining) = sink.buffered().checked_sub(Duration::from_millis(10)) { + tokio::time::sleep(remaining.max(Duration::from_millis(10))).await; + } + }; + let _ = tokio::time::timeout(AUDIO_DRAIN_MAX, drain).await; + + Ok(()) +} + +fn timestamp(timestamp: hang::moq_net::Timestamp) -> Duration { + Duration::from_micros(timestamp.as_micros().min(u64::MAX as u128) as u64) +} + +struct App { + title: String, + video: Arc>>, + audio_clock: Arc>>, + drained: Arc, + video_clock: Option, + display: Option, + next_redraw: Option, + /// The media tasks are done. Keep presenting whatever they left queued, then + /// stop; exiting the moment the decoder hits EOF would cut the tail off. + ending: bool, + /// Consecutive presents that rebuilt the surface instead of showing a frame. + retries: u32, + error: Option, +} + +impl App { + fn new( + title: String, + video: Arc>>, + audio_clock: Arc>>, + drained: Arc, + ) -> Self { + Self { + title, + video, + audio_clock, + drained, + video_clock: None, + display: None, + next_redraw: None, + ending: false, + retries: 0, + error: None, + } + } + + fn redraw(&mut self) -> anyhow::Result<()> { + let Some(display) = self.display.as_mut() else { + return Ok(()); + }; + let mut video = self.video.lock().unwrap(); + let audio_clock = *self.audio_clock.lock().unwrap(); + + if self.video_clock.is_none() + && audio_clock.is_none() + && let Some(frame) = video.front() + { + self.video_clock = Some(Clock { + media: timestamp(frame.timestamp), + wall: Instant::now(), + }); + } + let clock = audio_clock.or(self.video_clock); + let now = clock.map(Clock::now); + let mut due = None; + while video.front().is_some_and(|frame| { + now.is_none_or(|now| timestamp(frame.timestamp) <= now.saturating_add(VIDEO_EARLY_TOLERANCE)) + }) { + due = video.pop_front(); + } + let next_timestamp = video.front().map(|frame| timestamp(frame.timestamp)); + let popped = due.is_some(); + drop(video); + + // Room in the queue, so the decoder can hand over whatever it held back. + if popped { + self.drained.notify_one(); + } + + if let Some(frame) = due { + display.render(&frame)?; + } + let presented = display.present()?; + + // `checked_add`: the wait comes from a wire timestamp, and adding a bogus + // one to an `Instant` panics rather than saturating. No deadline just means + // the next frame waits for a media wakeup instead. + self.next_redraw = match (clock, next_timestamp) { + (Some(clock), Some(next)) => Instant::now().checked_add(next.saturating_sub(clock.now())), + _ => None, + }; + + // A rebuilt surface still owes us the frame we just drew, and nothing else + // will ask for it: a stalled live stream has no next frame to trigger one, + // and an ending stream would exit first. Bounded, so a surface that can + // never present fails instead of looping. + match presented { + Presented::Shown => self.retries = 0, + // Giving up is a dropped frame, not a failure: the next one redraws. + // Retrying without a budget would spin, since each retry asks for the + // redraw that produces the next one. + Presented::Retry if self.retries >= MAX_PRESENT_RETRIES => { + tracing::warn!("gave up re-presenting after rebuilding the graphics surface"); + self.retries = 0; + } + Presented::Retry => { + self.retries += 1; + display.window.request_redraw(); + } + } + Ok(()) + } + + fn fail(&mut self, event_loop: &ActiveEventLoop, err: impl ToString) { + self.error = Some(err.to_string()); + event_loop.exit(); + } +} + +impl ApplicationHandler for App { + fn resumed(&mut self, event_loop: &ActiveEventLoop) { + if self.display.is_some() { + return; + } + match Display::new(event_loop, &self.title) { + // Draw once up front so the window is black while the broadcast is + // still resolving, rather than showing whatever was in the surface. + Ok(display) => { + display.window.request_redraw(); + self.display = Some(display); + } + Err(err) => self.fail(event_loop, err), + } + } + + fn user_event(&mut self, event_loop: &ActiveEventLoop, event: Event) { + match event { + Event::Wake => { + if let Some(display) = &self.display { + display.window.request_redraw(); + } + } + Event::Finished => event_loop.exit(), + Event::Ended => { + self.ending = true; + if let Some(display) = &self.display { + display.window.request_redraw(); + } + } + Event::Failed(err) => self.fail(event_loop, err), + } + } + + fn window_event(&mut self, event_loop: &ActiveEventLoop, window_id: WindowId, event: WindowEvent) { + if self + .display + .as_ref() + .is_none_or(|display| display.window.id() != window_id) + { + return; + } + match event { + WindowEvent::CloseRequested + | WindowEvent::KeyboardInput { + event: + KeyEvent { + logical_key: Key::Named(NamedKey::Escape), + state: ElementState::Pressed, + .. + }, + .. + } => event_loop.exit(), + WindowEvent::Resized(size) => { + if let Some(display) = self.display.as_mut() { + display.resize(size.width, size.height); + display.window.request_redraw(); + } + } + WindowEvent::RedrawRequested => { + if let Err(err) = self.redraw() { + self.fail(event_loop, err); + } + } + _ => {} + } + } + + fn about_to_wait(&mut self, event_loop: &ActiveEventLoop) { + // Nothing left to decode and nothing left to show. No window means nothing + // can drain the queue, so don't wait on it. + let drained = self.display.is_none() || self.video.lock().unwrap().is_empty(); + if self.ending && self.retries == 0 && self.next_redraw.is_none() && drained { + event_loop.exit(); + return; + } + + match self.next_redraw { + Some(deadline) if deadline <= Instant::now() => { + self.next_redraw = None; + if let Some(display) = &self.display { + display.window.request_redraw(); + } + } + Some(deadline) => event_loop.set_control_flow(ControlFlow::WaitUntil(deadline)), + None => event_loop.set_control_flow(ControlFlow::Wait), + } + } +} + +struct Display { + window: Arc, + /// Kept past setup so a lost surface can be rebuilt from it. + instance: wgpu::Instance, + surface: wgpu::Surface<'static>, + device: wgpu::Device, + queue: wgpu::Queue, + config: wgpu::SurfaceConfiguration, + renderer: moq_video::render::Renderer, + presenter: Presenter, + texture: Option<(wgpu::Texture, moq_video::Size)>, +} + +impl Display { + fn new(event_loop: &ActiveEventLoop, title: &str) -> anyhow::Result { + let window = Arc::new( + event_loop.create_window( + Window::default_attributes() + .with_title(title) + .with_inner_size(LogicalSize::new(960, 540)), + )?, + ); + let size = window.inner_size(); + let instance = wgpu::Instance::default(); + let surface = instance.create_surface(window.clone())?; + let adapter = pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions { + power_preference: wgpu::PowerPreference::HighPerformance, + force_fallback_adapter: false, + compatible_surface: Some(&surface), + apply_limit_buckets: false, + }))?; + let (device, queue) = pollster::block_on(adapter.request_device(&wgpu::DeviceDescriptor::default()))?; + let mut config = surface + .get_default_config(&adapter, size.width.max(1), size.height.max(1)) + .context("the graphics adapter cannot present to this window")?; + let caps = surface.get_capabilities(&adapter); + if let Some(format) = caps.formats.iter().copied().find(|format| !format.is_srgb()) { + config.format = format; + } + config.desired_maximum_frame_latency = 1; + surface.configure(&device, &config); + let renderer = moq_video::render::Renderer::new(&device, &queue, Default::default())?; + let presenter = Presenter::new(&device, config.format); + + Ok(Self { + window, + instance, + surface, + device, + queue, + config, + renderer, + presenter, + texture: None, + }) + } + + fn resize(&mut self, width: u32, height: u32) { + if width == 0 || height == 0 { + return; + } + self.config.width = width; + self.config.height = height; + self.surface.configure(&self.device, &self.config); + } + + fn render(&mut self, frame: &moq_video::Frame) -> anyhow::Result<()> { + self.texture = Some((self.renderer.render(frame)?, frame.size())); + Ok(()) + } + + fn present(&mut self) -> anyhow::Result { + use wgpu::CurrentSurfaceTexture; + + let (output, reconfigure) = match self.surface.get_current_texture() { + CurrentSurfaceTexture::Success(output) => (output, false), + CurrentSurfaceTexture::Suboptimal(output) => (output, true), + // The swapchain was busy, not broken. Ask again rather than waiting on a + // next frame that a stalled or ending stream may never produce. + CurrentSurfaceTexture::Timeout => return Ok(Presented::Retry), + // Nobody is looking, so there is nothing to retry for. Being shown again + // is itself a redraw. + CurrentSurfaceTexture::Occluded => return Ok(Presented::Shown), + CurrentSurfaceTexture::Outdated => { + self.surface.configure(&self.device, &self.config); + return Ok(Presented::Retry); + } + // Not just a stale configuration like `Outdated`: the surface itself is + // gone and has to be rebuilt before it can be configured again. A + // display change or a resume can do this, so it isn't fatal. + CurrentSurfaceTexture::Lost => { + self.surface = self + .instance + .create_surface(self.window.clone()) + .context("failed to rebuild the playback window's graphics surface")?; + self.surface.configure(&self.device, &self.config); + return Ok(Presented::Retry); + } + CurrentSurfaceTexture::Validation => anyhow::bail!("failed to acquire the playback window's next frame"), + }; + let target = output.texture.create_view(&Default::default()); + let mut encoder = self.device.create_command_encoder(&wgpu::CommandEncoderDescriptor { + label: Some("moq play present"), + }); + let viewport = self + .texture + .as_ref() + .map(|(_, size)| fit((self.config.width, self.config.height), (size.width, size.height))); + self.presenter.draw( + &self.device, + &mut encoder, + self.texture.as_ref().map(|(texture, _)| texture), + &target, + viewport, + ); + self.queue.submit([encoder.finish()]); + self.queue.present(output); + if reconfigure { + self.surface.configure(&self.device, &self.config); + } + Ok(Presented::Shown) + } +} + +/// Whether a present reached the screen, or recovered the surface and still owes +/// the caller a redraw. +#[derive(Clone, Copy)] +enum Presented { + Shown, + Retry, +} + +struct Presenter { + pipeline: wgpu::RenderPipeline, + layout: wgpu::BindGroupLayout, + sampler: wgpu::Sampler, +} + +impl Presenter { + fn new(device: &wgpu::Device, format: wgpu::TextureFormat) -> Self { + let layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { + label: Some("moq play texture layout"), + entries: &[ + wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStages::FRAGMENT, + ty: wgpu::BindingType::Texture { + sample_type: wgpu::TextureSampleType::Float { filterable: true }, + view_dimension: wgpu::TextureViewDimension::D2, + multisampled: false, + }, + count: None, + }, + wgpu::BindGroupLayoutEntry { + binding: 1, + visibility: wgpu::ShaderStages::FRAGMENT, + ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering), + count: None, + }, + ], + }); + let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { + label: Some("moq play pipeline layout"), + bind_group_layouts: &[Some(&layout)], + immediate_size: 0, + }); + let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { + label: Some("moq play shader"), + source: wgpu::ShaderSource::Wgsl( + "struct VertexOutput {\n\ + @builtin(position) position: vec4f,\n\ + @location(0) tex_coords: vec2f,\n\ + }\n\ + @group(0) @binding(0) var image: texture_2d;\n\ + @group(0) @binding(1) var image_sampler: sampler;\n\ + @vertex fn vs_main(@builtin(vertex_index) i: u32) -> VertexOutput {\n\ + var out: VertexOutput;\n\ + out.tex_coords = vec2f(f32((i << 1u) & 2u), f32(i & 2u));\n\ + out.position = vec4f(out.tex_coords * 2.0 - 1.0, 0.0, 1.0);\n\ + out.tex_coords.y = 1.0 - out.tex_coords.y;\n\ + return out;\n\ + }\n\ + @fragment fn fs_main(in: VertexOutput) -> @location(0) vec4f {\n\ + return textureSample(image, image_sampler, in.tex_coords);\n\ + }" + .into(), + ), + }); + let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + label: Some("moq play pipeline"), + layout: Some(&pipeline_layout), + vertex: wgpu::VertexState { + module: &shader, + entry_point: Some("vs_main"), + compilation_options: Default::default(), + buffers: &[], + }, + primitive: Default::default(), + depth_stencil: None, + multisample: Default::default(), + fragment: Some(wgpu::FragmentState { + module: &shader, + entry_point: Some("fs_main"), + compilation_options: Default::default(), + targets: &[Some(wgpu::ColorTargetState { + format, + blend: None, + write_mask: wgpu::ColorWrites::ALL, + })], + }), + multiview_mask: None, + cache: None, + }); + let sampler = device.create_sampler(&wgpu::SamplerDescriptor { + label: Some("moq play sampler"), + mag_filter: wgpu::FilterMode::Linear, + min_filter: wgpu::FilterMode::Linear, + ..Default::default() + }); + Self { + pipeline, + layout, + sampler, + } + } + + fn draw( + &self, + device: &wgpu::Device, + encoder: &mut wgpu::CommandEncoder, + source: Option<&wgpu::Texture>, + target: &wgpu::TextureView, + viewport: Option<(f32, f32, f32, f32)>, + ) { + let bind = source.map(|texture| { + let view = texture.create_view(&Default::default()); + device.create_bind_group(&wgpu::BindGroupDescriptor { + label: Some("moq play texture"), + layout: &self.layout, + entries: &[ + wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::TextureView(&view), + }, + wgpu::BindGroupEntry { + binding: 1, + resource: wgpu::BindingResource::Sampler(&self.sampler), + }, + ], + }) + }); + let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: Some("moq play present"), + color_attachments: &[Some(wgpu::RenderPassColorAttachment { + view: target, + depth_slice: None, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color::BLACK), + store: wgpu::StoreOp::Store, + }, + })], + depth_stencil_attachment: None, + timestamp_writes: None, + occlusion_query_set: None, + multiview_mask: None, + }); + if let (Some(bind), Some((x, y, width, height))) = (bind.as_ref(), viewport) { + pass.set_viewport(x, y, width, height, 0.0, 1.0); + pass.set_pipeline(&self.pipeline); + pass.set_bind_group(0, bind, &[]); + pass.draw(0..3, 0..1); + } + } +} + +fn fit(window: (u32, u32), video: (u32, u32)) -> (f32, f32, f32, f32) { + let scale = (window.0 as f32 / video.0 as f32).min(window.1 as f32 / video.1 as f32); + let width = video.0 as f32 * scale; + let height = video.1 as f32 * scale; + ( + (window.0 as f32 - width) / 2.0, + (window.1 as f32 - height) / 2.0, + width, + height, + ) +} + +#[cfg(test)] +mod tests { + use super::*; + + /// Subscribing before the announcement lands doesn't wait, it fails: with no + /// session yet there is no handler registered on the origin, and + /// `request_broadcast` resolves `Unroutable` immediately. The media task is + /// spawned right after the reconnect loop starts, so it gets there first. + #[tokio::test] + async fn subscribe_waits_for_the_announcement() { + tokio::time::pause(); + + let origin = moq_net::Origin::random().produce(); + let consumer = origin.consume(); + + // Resolving straight away, which is what the media task used to do. + let unannounced = moq_mux::Source::new(consumer.clone(), "room.hang").broadcast().await; + assert!(unannounced.is_err(), "expected an unroutable broadcast"); + + // Waiting first parks instead, for as long as it takes. + let mut waiting = std::pin::pin!(subscribe(consumer, "room.hang")); + let parked = tokio::time::timeout(Duration::from_secs(60), &mut waiting).await; + assert!(parked.is_err(), "expected to still be waiting on the announcement"); + + let _broadcast = origin + .create_broadcast("room.hang", moq_net::broadcast::Route::new().with_announce(true)) + .unwrap(); + waiting.await.unwrap(); + } + + #[test] + fn letterboxes_without_changing_aspect_ratio() { + let assert_near = |actual: (f32, f32, f32, f32), expected: (f32, f32, f32, f32)| { + for (actual, expected) in [actual.0, actual.1, actual.2, actual.3] + .into_iter() + .zip([expected.0, expected.1, expected.2, expected.3]) + { + assert!((actual - expected).abs() < 0.01, "{actual} != {expected}"); + } + }; + assert_near(fit((1000, 1000), (1920, 1080)), (0.0, 218.75, 1000.0, 562.5)); + assert_near(fit((1920, 1080), (1000, 1000)), (420.0, 0.0, 1080.0, 1080.0)); + } + + #[test] + fn clock_advances_from_its_media_anchor() { + let clock = Clock { + media: Duration::from_secs(10), + wall: Instant::now() - Duration::from_millis(20), + }; + assert!(clock.now() >= Duration::from_millis(10_020)); + } +} diff --git a/rs/moq-cli/src/subscribe.rs b/rs/moq-cli/src/subscribe.rs index f23c5c1cf37..603bf4cf393 100644 --- a/rs/moq-cli/src/subscribe.rs +++ b/rs/moq-cli/src/subscribe.rs @@ -70,6 +70,7 @@ impl From for VideoCodecKind { pub enum AudioCodecArg { Aac, Opus, + Pcm, } impl From for AudioCodecKind { @@ -77,12 +78,13 @@ impl From for AudioCodecKind { match value { AudioCodecArg::Aac => Self::AAC, AudioCodecArg::Opus => Self::Opus, + AudioCodecArg::Pcm => Self::Pcm, } } } -/// Rendition selection flags for the stdout container sinks. With no flags set, -/// every rendition is kept. +/// Rendition selection flags for stdout container sinks and native playback. +/// With no flags set, every rendition is kept. #[derive(clap::Args, Clone, Default)] pub struct SelectArgs { /// Pick the video rendition with this exact name. @@ -102,6 +104,32 @@ pub struct SelectArgs { pub audio_codec: Option, } +impl SelectArgs { + /// Build the rendition selection shared by stdout exports and native playback. + /// + /// `force` takes the place of `--video-codec`, for a sink whose format implies + /// one. Pass `None` to use the flag as given. + pub(crate) fn selection(&self, force: Option) -> select::Broadcast { + let mut video = select::Video::default(); + if let Some(name) = &self.video_name { + video = video.name(name); + } + if let Some(codec) = force.or_else(|| self.video_codec.map(Into::into)) { + video = video.codec(codec); + } + + let mut audio = select::Audio::default(); + if let Some(name) = &self.audio_name { + audio = audio.name(name); + } + if let Some(codec) = self.audio_codec { + audio = audio.codec(codec.into()); + } + + select::Broadcast::default().video(video).audio(audio) + } +} + /// The resolved stdout export settings (built from the `export` flags + format). #[derive(Clone)] pub struct SubscribeArgs { @@ -159,24 +187,7 @@ impl SubscribeArgs { (None, user) => user, }; - // Both roles stay opted in; criteria-free roles keep every rendition. - let mut video = select::Video::default(); - if let Some(name) = &self.select.video_name { - video = video.name(name); - } - if let Some(codec) = codec { - video = video.codec(codec); - } - - let mut audio = select::Audio::default(); - if let Some(name) = &self.select.audio_name { - audio = audio.name(name); - } - if let Some(codec) = self.select.audio_codec { - audio = audio.codec(codec.into()); - } - - Ok(select::Broadcast::default().video(video).audio(audio)) + Ok(self.select.selection(codec)) } } diff --git a/rs/moq-video/src/decode/consumer.rs b/rs/moq-video/src/decode/consumer.rs index 24be5d86058..e9e17174406 100644 --- a/rs/moq-video/src/decode/consumer.rs +++ b/rs/moq-video/src/decode/consumer.rs @@ -19,7 +19,7 @@ pub struct Consumer { /// so the codec would otherwise migrate between executor workers and /// unbalance the per-thread COM apartment the Windows backend opens. decoder: Sink, - track: moq_mux::container::Consumer, + track: moq_mux::container::Consumer, /// Frames a single access unit decoded to but `read` hasn't returned yet. /// One AU yields one frame in the low-delay path, but a backend may hand back /// more, so we buffer to keep `read` one-frame-per-call. @@ -42,7 +42,11 @@ impl Consumer { .track(&name)? .subscribe(moq_net::track::Subscription::default().with_priority(hang::catalog::PRIORITY.video)) .await?; - let mut track = moq_mux::container::Consumer::new(track, moq_mux::container::legacy::Wire); + // The catalog says how the track is framed, and it is not always the legacy + // wire: `moq import fmp4` publishes CMAF. Reading a moof+mdat fragment as a + // varint timestamp plus a payload decodes to garbage rather than failing. + let container = moq_mux::catalog::hang::Container::try_from(&catalog.container)?; + let mut track = moq_mux::container::Consumer::new(track, container); if let Some(latency) = config.latency_max { track = track.with_latency(latency); } @@ -78,3 +82,71 @@ impl Consumer { } } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::decode::Kind; + use crate::encode::{Codec, Config as EncodeConfig, Encoder, Kind as EncodeKind, Producer as EncodeProducer}; + + #[tokio::test] + async fn reads_cmaf_container_declared_by_catalog() { + let mut source_broadcast = moq_net::broadcast::Info::new().produce(); + let source_subscriber = source_broadcast.consume(); + let source_catalog = moq_mux::catalog::Producer::new(&mut source_broadcast).unwrap(); + let mut producer = EncodeProducer::new(source_broadcast, source_catalog, Codec::H264).unwrap(); + let mut encoder = Encoder::new(&EncodeConfig { + kind: EncodeKind::Software, + ..EncodeConfig::new(320, 240, 30) + }) + .unwrap(); + let rgba = vec![0x80u8; 320 * 240 * 4]; + for index in 0..2 { + encoder.keyframe(); + let surface = crate::Surface::rgba(&rgba, crate::Size::new(320, 240)).unwrap(); + let frame = crate::Frame::new(surface, moq_net::Timestamp::from_micros(index * 33_333).unwrap()); + producer.publish(&encoder.encode(&frame).unwrap()).unwrap(); + } + + let origin = moq_net::Origin::random().produce(); + let mut requests = origin.dynamic(); + let served = source_subscriber.clone(); + tokio::spawn(async move { + while let Ok(request) = requests.requested_broadcast().await { + request.accept(served.clone()); + } + }); + let catalog = moq_mux::catalog::Consumer::<()>::new(&source_subscriber, moq_mux::catalog::CatalogFormat::Hang) + .await + .unwrap(); + let source = moq_mux::Source::new(origin.consume(), "test"); + let mut export = moq_mux::container::fmp4::Export::new(source, catalog); + let init = export.next().await.unwrap().expect("CMAF init"); + let fragment = export.next().await.unwrap().expect("CMAF fragment"); + + let mut broadcast = moq_net::broadcast::Info::new().produce(); + let subscriber = broadcast.consume(); + let catalog = moq_mux::catalog::Producer::new(&mut broadcast).unwrap(); + let mut import = moq_mux::container::fmp4::Import::new(broadcast, catalog.reserve()); + import.decode(&init).unwrap(); + import.decode(&fragment).unwrap(); + + let snapshot = catalog.snapshot(); + let (name, config) = snapshot.video.renditions.iter().next().expect("video rendition"); + assert!(matches!(config.container, hang::catalog::Container::Cmaf { .. })); + let mut consumer = Consumer::new( + &subscriber, + config, + name, + Config { + kind: Kind::Software, + ..Config::new() + }, + ) + .await + .unwrap(); + + let frame = consumer.read().await.unwrap().expect("decoded frame"); + assert_eq!(frame.size(), crate::Size::new(320, 240)); + } +} diff --git a/uv.lock b/uv.lock index 3c3a8dfc788..e3cc3563451 100644 --- a/uv.lock +++ b/uv.lock @@ -103,7 +103,7 @@ source = { editable = "py/moq-ffi" } [[package]] name = "moq-rs" -version = "0.4.1" +version = "0.4.2" source = { editable = "py/moq-rs" } dependencies = [ { name = "moq-ffi" },