From 0f9c301c3960d4afac4f217c036de90acdad9eec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Goran=20Meki=C4=87?= Date: Fri, 27 Nov 2026 02:02:46 +0100 Subject: [PATCH] Remove symphonia --- Cargo.lock | 422 +++++++++------------- Cargo.toml | 32 +- README.md | 2 +- src/audio_codec.rs | 790 +++++++++++++++++++++-------------------- src/hw/jack.rs | 7 +- src/track/streaming.rs | 2 +- 6 files changed, 594 insertions(+), 661 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5eb3463..b0247a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,17 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "aes" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + [[package]] name = "alsa" version = "0.12.1" @@ -9,7 +20,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3f93573e7ddb15145d27c58c0fa0a452faad9f5452ac17ed4554ea035ea9b71" dependencies = [ "alsa-sys", - "bitflags 2.13.2", + "bitflags", "cfg-if", "libc", ] @@ -79,12 +90,6 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b0cab808e4f26ab216811b4b759e85823f9630a4da86e90e207bdc99cf565d32" -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - [[package]] name = "bitflags" version = "2.13.2" @@ -97,6 +102,15 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" +[[package]] +name = "block-padding" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8894febbff9f758034a5b8e12d87918f56dfc64a8e1fe757d65e29041538d93" +dependencies = [ + "generic-array", +] + [[package]] name = "bumpalo" version = "3.20.4" @@ -115,6 +129,15 @@ version = "1.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "776dfebd015e2d8732c684a2c71003674ccb49457b539b9e82151ba38e96dd7c" +[[package]] +name = "cbc" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b52a9543ae338f279b96b0b9fed9c8093744685043739079ce85cd58f289a6" +dependencies = [ + "cipher", +] + [[package]] name = "cc" version = "1.11.3" @@ -137,12 +160,31 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + [[package]] name = "compcol" version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6f29da98742f258743e8bb44b09f0cc1cbca2591e709b1bb85ccd6e9111f431" +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + [[package]] name = "crossbeam-deque" version = "0.8.8" @@ -177,6 +219,25 @@ version = "0.8.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6" +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "ctr" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" +dependencies = [ + "cipher", +] + [[package]] name = "either" version = "1.19.0" @@ -199,17 +260,11 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "extended" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af9673d8203fcb076b19dfd17e38b3d4ae9f44959416ea532ce72415a6020365" - [[package]] name = "fearless_simd" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "629c9d6b6f30b5604089e0980f4d924a013aacb1654a6cdf5d3d852224f68651" +checksum = "6a7107516a8be9a4ffe92495f3dbfe04348be0ad18f17c67a1d846511f99e599" [[package]] name = "fearless_simd_macros" @@ -252,6 +307,16 @@ dependencies = [ "slab", ] +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + [[package]] name = "getrandom" version = "0.4.3" @@ -285,6 +350,16 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "inout" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" +dependencies = [ + "block-padding", + "generic-array", +] + [[package]] name = "itoa" version = "1.0.19" @@ -293,25 +368,23 @@ checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4" [[package]] name = "jack" -version = "0.13.5" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7811b07bcac5dafabf814ab52c4b0ca9b7948aa1e279f572f03aa6544d47d27" +checksum = "f3ce606a8f7242b40873816bc2af3605a17161700e13a4c666261ca178ae35d4" dependencies = [ - "bitflags 2.13.2", + "bitflags", "jack-sys", - "lazy_static", "libc", "log", ] [[package]] name = "jack-sys" -version = "0.5.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6013b7619b95a22b576dfb43296faa4ecbe40abbdb97dfd22ead520775fc86ab" +checksum = "2358f2a05f9b19a51d1b518d1596ffc92e645276b1927803d343d22fe9e9ff1e" dependencies = [ - "bitflags 1.3.2", - "lazy_static", + "bitflags", "libc", "libloading", "log", @@ -343,12 +416,12 @@ checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" [[package]] name = "libloading" -version = "0.7.4" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" +checksum = "a1832accd5a4ca2795ace4d05d15c4039be15b62d3b950eff99746a990e3cc10" dependencies = [ "cfg-if", - "winapi", + "windows-link", ] [[package]] @@ -397,17 +470,19 @@ dependencies = [ "nix", "num_cpus", "nvtree", + "oxideav-aac", "oxideav-basic", "oxideav-core", "oxideav-flac", "oxideav-mp3", + "oxideav-mp4", "oxideav-ogg", + "oxideav-vorbis", "rayon", "rtrb", "rubato", "serde", "serde_json", - "symphonia", "timestretch", "tokio", "toml", @@ -455,20 +530,20 @@ dependencies = [ [[package]] name = "mixosc" -version = "0.0.17" +version = "0.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4927c8f31a3b020c91722a47b9ad61ee70e5bd694f882eef34a8427bf9a2cb7d" +checksum = "3f1710e93b1bbe3268c124c63183a754638bc11b026105a604f26abc2393b492" dependencies = [ "tokio", ] [[package]] name = "nix" -version = "0.31.4" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bc81ce8148d3b4f3274da811f11cdd824ae661ee4ef732cdb229825cf5be7f7" +checksum = "77730ed34f01f4990cb2ea67fec715ecebc6fab9a6396cf83c5529b13f581bdc" dependencies = [ - "bitflags 2.13.2", + "bitflags", "cfg-if", "cfg_aliases", "libc", @@ -532,11 +607,20 @@ version = "1.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" +[[package]] +name = "oxideav-aac" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35453ffa827080f322dba5d2233879f008627d4ffb07c496c0c6fe3190b35048" +dependencies = [ + "oxideav-core", +] + [[package]] name = "oxideav-basic" -version = "0.0.11" +version = "0.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7969c668656223b44c2950e4d736fd870d70d3880bab6e5d27c92c3226fcbdc" +checksum = "746e07b5ad27b6dca4153647b981dd4f682872737fe7d1add44bdcefa9bacc00" dependencies = [ "oxideav-core", ] @@ -554,9 +638,9 @@ dependencies = [ [[package]] name = "oxideav-flac" -version = "0.0.12" +version = "0.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4cec9a2ebb660ce0b46e148f0339d1a529c7660cc167f13aaef7784f06b1220" +checksum = "a7b13c5a9dc0966579ba6db8046c86f8121b02304282f48653f307d317269b97" dependencies = [ "oxideav-core", "oxideav-id3", @@ -581,6 +665,18 @@ dependencies = [ "oxideav-core", ] +[[package]] +name = "oxideav-mp4" +version = "0.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7766473a510b620ddcd87ea772d2b8193c566d9069799bd362ea695bc9562bd" +dependencies = [ + "aes", + "cbc", + "ctr", + "oxideav-core", +] + [[package]] name = "oxideav-ogg" version = "0.1.9" @@ -590,6 +686,16 @@ dependencies = [ "oxideav-core", ] +[[package]] +name = "oxideav-vorbis" +version = "0.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b786a2c716843ab2a4509c03ce7836173384a59831e1c893b5492ac611d872b" +dependencies = [ + "oxideav-core", + "oxideav-ogg", +] + [[package]] name = "parking_lot" version = "0.12.5" @@ -693,15 +799,9 @@ version = "0.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" dependencies = [ - "bitflags 2.13.2", + "bitflags", ] -[[package]] -name = "regex-lite" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cab834c73d247e67f4fae452806d17d3c7501756d98c8808d7c9c7aa7d18f973" - [[package]] name = "rtrb" version = "0.4.1" @@ -855,192 +955,6 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe895eb47f22e2ddd4dabc02bce419d2e643c8e3b585c78158b349195bc24d82" -[[package]] -name = "symphonia" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7edef6a96b696d4e0cab5ee9ebb7ca155ed95f30a6b45bbb8b97d2727f02424" -dependencies = [ - "lazy_static", - "symphonia-bundle-flac", - "symphonia-bundle-mp3", - "symphonia-codec-aac", - "symphonia-codec-adpcm", - "symphonia-codec-alac", - "symphonia-codec-pcm", - "symphonia-codec-vorbis", - "symphonia-core", - "symphonia-format-isomp4", - "symphonia-format-mkv", - "symphonia-format-ogg", - "symphonia-format-riff", - "symphonia-metadata", -] - -[[package]] -name = "symphonia-bundle-flac" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6405d5c34ff6f8f7ca08a4101efe66d21e180f7322ef9359900a0e55698a7892" -dependencies = [ - "log", - "symphonia-common", - "symphonia-core", - "symphonia-metadata", -] - -[[package]] -name = "symphonia-bundle-mp3" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98ea5ffc8716bff677dfb3b01b420c7b758de901a72b8c330bf2040ab74b4add" -dependencies = [ - "lazy_static", - "log", - "symphonia-core", -] - -[[package]] -name = "symphonia-codec-aac" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5bf8e39552d34a3c4c98333370e62f48c92456d2e814f273b5c3ad7c4a5f45c" -dependencies = [ - "lazy_static", - "log", - "symphonia-common", - "symphonia-core", -] - -[[package]] -name = "symphonia-codec-adpcm" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445932ecb0c59362fde9c082dd63a75380650c5077fdb8b80b8cac850442a74c" -dependencies = [ - "log", - "symphonia-core", -] - -[[package]] -name = "symphonia-codec-alac" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "920a78f96f3cf62932d0c497959c0cc2100ef36b03c7ca1417b260f432a482d8" -dependencies = [ - "log", - "symphonia-common", - "symphonia-core", -] - -[[package]] -name = "symphonia-codec-pcm" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e04ba75686acbe43542fdd374571195f0530c0b7785ca25cc6840e9c6c4b6eea" -dependencies = [ - "log", - "symphonia-core", -] - -[[package]] -name = "symphonia-codec-vorbis" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73d90b4fcf796137cc683c538282804ff9629f8ad9dbfd881fcbba331ac4e986" -dependencies = [ - "log", - "symphonia-common", - "symphonia-core", -] - -[[package]] -name = "symphonia-common" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2acc3fcc18ec9b8cdd48614e259c4cf0d27b71d41e5d9b120b42c5adab12d7c4" -dependencies = [ - "log", - "symphonia-core", - "symphonia-metadata", -] - -[[package]] -name = "symphonia-core" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01c412864d599d4750d0c3d684d7e093ec05e5309681ef5252cc1096a437f6e0" -dependencies = [ - "bitflags 2.13.2", - "bytemuck", - "lazy_static", - "log", - "num-complex", - "rustfft", - "smallvec", -] - -[[package]] -name = "symphonia-format-isomp4" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e681a70e1870d34e02abf1dbc51e4267c3f1827801474e8870be8c689fc4dc3" -dependencies = [ - "log", - "symphonia-common", - "symphonia-core", - "symphonia-metadata", -] - -[[package]] -name = "symphonia-format-mkv" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d015c5c0558864665894b3f4cbd95e10abb01b9c868e751c72670f326a56360e" -dependencies = [ - "lazy_static", - "log", - "symphonia-common", - "symphonia-core", -] - -[[package]] -name = "symphonia-format-ogg" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b5495e7f7e3c7035328d82b6d6e377eef289bb0c4105bdeb557fc93a833f994" -dependencies = [ - "log", - "symphonia-common", - "symphonia-core", - "symphonia-metadata", -] - -[[package]] -name = "symphonia-format-riff" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ff70929083a8c1a5f6cd7c904b6071c7914ad04739b510c2f7239dfc9b7dabe" -dependencies = [ - "extended", - "log", - "symphonia-core", - "symphonia-metadata", -] - -[[package]] -name = "symphonia-metadata" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83713a97705d77bdef7cdbc0768fd6e5a54e4cd7e48d60a806ae85639e2c87c6" -dependencies = [ - "lazy_static", - "log", - "regex-lite", - "smallvec", - "symphonia-core", -] - [[package]] name = "syn" version = "2.0.119" @@ -1094,9 +1008,9 @@ dependencies = [ [[package]] name = "timestretch" -version = "0.16.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad484075af6caf97e09f3f869bed42c99ff4fea501f6df6ad65d5bb8c7186808" +checksum = "673a71577e4d5d7975f884d1a4722ac80d287de3ab0c3129ede7db36bde7496f" dependencies = [ "timestretch-core", ] @@ -1109,9 +1023,9 @@ checksum = "ffbbc9a0a366ab1e33dbb5edc124d0aa2f7a29f9cf05e16718490c460e50aae5" [[package]] name = "timestretch-core" -version = "0.16.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa8cb1cae3fd3788a7a9e704dd079d7dc56b00a8b2d0688e9be94130ebcbe1aa" +checksum = "01ee7084b5f066fff156d695a0fdc9d3b714b743f332e02814acb6645af88414" dependencies = [ "rustfft", "timestretch-accelerate", @@ -1147,9 +1061,9 @@ dependencies = [ [[package]] name = "toml" -version = "1.2.2+spec-1.1.0" +version = "1.2.3+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5426cb1b964690d913f6c5c1a1ae0b42f428ec506bb4d452876d7a209c9bca3b" +checksum = "26b1f26e9485c1fa43ee89fe76e9f3fb9e2e52bb227f8594b4d687496b83d073" dependencies = [ "indexmap", "serde_core", @@ -1171,9 +1085,9 @@ dependencies = [ [[package]] name = "toml_parser" -version = "1.1.6+spec-1.1.0" +version = "1.1.7+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6769c452d71ba30696c6b37770c439a9cc9110f47f7d5cdbeda79840ef5ea31" +checksum = "0bb28d6e049a9766c3bd91a8326e6179f5b132dec87906bb97018ef7a2f3431a" dependencies = [ "winnow", ] @@ -1251,6 +1165,12 @@ dependencies = [ "strength_reduce", ] +[[package]] +name = "typenum" +version = "1.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" + [[package]] name = "unicode-ident" version = "1.0.27" @@ -1274,6 +1194,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + [[package]] name = "visibility" version = "0.1.1" @@ -1335,28 +1261,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - [[package]] name = "windowfunctions" version = "0.1.1" diff --git a/Cargo.toml b/Cargo.toml index 05adca4..1ca3d18 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,22 +14,24 @@ categories = ["multimedia::audio"] [dependencies] num_cpus = "1.17.0" tokio = { version = "1.54.1", features = ["full"] } -oxideav-core = { version = "0.1.42", optional = true } -oxideav-basic = { version = "0.0.11", optional = true } -oxideav-flac = { version = "0.0.12", optional = true } -oxideav-mp3 = { version = "0.1.3", optional = true } +oxideav-core = { version = "0.1.43", optional = true } +oxideav-basic = { version = "0.0.12", optional = true } +oxideav-flac = { version = "0.0.13", optional = true } +oxideav-mp3 = { version = "0.1.4", optional = true } oxideav-ogg = { version = "0.1.9", optional = true } -symphonia = { version = "0.6.1", features = ["aac", "alac", "flac", "isomp4", "mp3", "ogg", "vorbis", "wav"], optional = true } +oxideav-vorbis = { version = "0.0.13", optional = true } +oxideav-aac = { version = "0.1.7", optional = true } +oxideav-mp4 = { version = "0.0.11", optional = true } tracing = { version = "0.1.44", features = ["release_max_level_debug"] } midly = { version = "0.5.3", optional = true } serde = { version = "1.0.229", features = ["derive"] } serde_json = "1.0.154" -toml = "1.2.1" +toml = "1.2.3" maolan-plugin-protocol = { version = "0.0.21", optional = true } -uuid = { version = "1.29.0", features = ["v4"] } -fearless_simd = { version = "1.2.0", features = ["force_support_fallback"] } +uuid = { version = "1.29.3", features = ["v4"] } +fearless_simd = { version = "1.3.0", features = ["force_support_fallback"] } fearless_simd_macros = "0.1" -arc-swap = "1.9.3" +arc-swap = "1.9.5" basedrop = "0.1.3" crossbeam-queue = "0.3" rtrb = "0.4.1" @@ -37,8 +39,8 @@ rayon = "1.12" rubato = "5.0.1" audioadapter = "5.0" audioadapter-buffers = "5.2" -timestretch = "0.16.0" -mixosc = { version = "0.0.17", optional = true, default-features = false } +timestretch = "0.17.0" +mixosc = { version = "0.0.18", optional = true, default-features = false } [dev-dependencies] tracing-subscriber = "0.3.23" @@ -51,7 +53,9 @@ audio = [ "dep:oxideav-flac", "dep:oxideav-mp3", "dep:oxideav-ogg", - "dep:symphonia", + "dep:oxideav-vorbis", + "dep:oxideav-aac", + "dep:oxideav-mp4", ] midi = ["dep:midly"] plugins = ["dep:maolan-plugin-protocol"] @@ -67,8 +71,8 @@ alsa = "0.12.1" nvtree = "0.0.6" [target.'cfg(unix)'.dependencies] -nix = { version = "0.31.3", features = ["ioctl", "poll"] } -jack = "0.13.5" +nix = { version = "0.32.0", features = ["ioctl", "poll"] } +jack = "0.14.0" libc = "0.2" [target.'cfg(target_os = "windows")'.dependencies] diff --git a/README.md b/README.md index 2a4971e..a561d12 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ features; the crate builds with `default = []`: | Feature | Enables | Dependencies | |---------|---------|--------------| -| `audio` | Audio file decode/encode (import, export, recording takes, freeze/bounce WAV) | `symphonia`, `oxideav-*` | +| `audio` | Audio file decode/encode (import, export, recording takes, freeze/bounce WAV) | `oxideav-*` | | `midi` | Standard MIDI File import/export (`.mid` clips and MIDI takes) | `midly` | | `plugins` | Out-of-process CLAP/VST3/LV2/AU plugin hosting, plugin graphs, plugin messages | `maolan-plugin-protocol` | | `mixosc` | OSC control-surface automation | `mixosc` | diff --git a/src/audio_codec.rs b/src/audio_codec.rs index 102a8d0..1761064 100644 --- a/src/audio_codec.rs +++ b/src/audio_codec.rs @@ -1,17 +1,9 @@ -use std::io::{self, Write}; -use std::path::{Path, PathBuf}; -use symphonia::core::codecs::CodecParameters as SymphoniaCodecParameters; -use symphonia::core::codecs::audio::{AudioCodecParameters, AudioDecoder, AudioDecoderOptions}; -use symphonia::core::errors::Error as SymphoniaError; -use symphonia::core::formats::probe::Hint; -use symphonia::core::formats::{FormatOptions, FormatReader, TrackType}; -use symphonia::core::io::MediaSourceStream; -use symphonia::core::meta::MetadataOptions; - use oxideav_core::{ - AudioFrame, CodecId, CodecParameters, Frame, MediaType, Packet, RuntimeContext, SampleFormat, - StreamInfo, TimeBase, + AudioFrame, CodecId, CodecParameters, Decoder, Demuxer, Frame, MediaType, Packet, + RuntimeContext, SampleFormat, StreamInfo, TimeBase, }; +use std::io::{self, Write}; +use std::path::{Path, PathBuf}; /// Export format selector and WAV bit-depth / dither types live in /// `wav_stream` (always compiled) so offline-bounce message types can use @@ -25,23 +17,11 @@ fn oxideav_err_to_io(e: oxideav_core::Error) -> io::Error { /// Decode an audio file to interleaved `f32` samples. /// -/// The format is auto-detected by the OxideAV demuxers/decoders: -/// `.wav`/PCM, `.flac`, `.mp3`, and Ogg-encapsulated FLAC (`.ogg`). -/// Files OxideAV cannot probe or decode fall back to Symphonia -/// (`.ogg`/Vorbis, `.m4a`/`.aac`/`.alac`, and friends). -/// Returns `(samples, channels, sample_rate)`. -/// All decode paths emit samples in the range `[-1.0, 1.0]`. +/// The format is auto-detected by OxideAV. Supported inputs include WAV/PCM, +/// FLAC, MP3, Ogg FLAC, Ogg Vorbis, and AAC-LC in ADTS or MP4/M4A containers. +/// Returns `(samples, channels, sample_rate)` with samples in `[-1.0, 1.0]`. pub fn decode_audio_to_f32_interleaved_sync(path: &Path) -> io::Result<(Vec, usize, u32)> { - match decode_with_oxideav(path) { - Ok(decoded) => Ok(decoded), - Err(oxideav_err) => decode_with_symphonia(path).map_err(|symphonia_err| { - io::Error::other(format!( - "Failed to decode '{}' with OxideAV ({oxideav_err}) \ - or Symphonia ({symphonia_err})", - path.display() - )) - }), - } + decode_with_oxideav(path) } /// Decode a WAV file preferentially, falling back to the general decoder. @@ -56,7 +36,7 @@ pub fn decode_audio_to_f32_interleaved_preferring_wav( } // --------------------------------------------------------------------------- -// Metadata probe + incremental streaming decode (Symphonia) +// Metadata probe + incremental streaming decode // --------------------------------------------------------------------------- /// Fast metadata probe result for an audio file. @@ -69,45 +49,27 @@ pub struct AudioFileInfo { } /// Probe sample rate, channel count and approximate frame count without -/// decoding. Works for every format Symphonia can probe (wav, flac, mp3, -/// ogg/vorbis, aac/alac in m4a/isomp4, ...). +/// decoding audio. pub fn probe_audio_file(path: &Path) -> io::Result { - let format = probe_format(path)?; - let track = format - .default_track(TrackType::Audio) - .or_else(|| format.tracks().first()) - .ok_or_else(|| { - io::Error::other(format!("No usable audio track in '{}'", path.display())) - })?; - let params: &AudioCodecParameters = track - .codec_params - .as_ref() - .and_then(SymphoniaCodecParameters::audio) - .ok_or_else(|| { - io::Error::other(format!("No usable audio track in '{}'", path.display())) - })?; - let sample_rate = params.sample_rate.unwrap_or(0); - if sample_rate == 0 { - return Err(io::Error::other(format!( - "No sample rate in '{}'", - path.display() - ))); - } - let channels = params.channels.as_ref().map(|c| c.count()).unwrap_or(0); + let demuxer = open_oxideav_demuxer(path)?; + let (_, stream) = first_audio_stream(&*demuxer, path)?; + let sample_rate = stream + .params + .sample_rate + .ok_or_else(|| io::Error::other(format!("No sample rate in '{}'", path.display())))?; + let channels = stream.params.channels.unwrap_or(0) as usize; if channels == 0 { return Err(io::Error::other(format!( "No channel count in '{}'", path.display() ))); } - let frames = track - .time_base - .and_then(|tb| { - track - .duration - .and_then(|duration| tb.calc_duration(duration)) - }) - .map(|time| (time.as_secs_f64() * f64::from(sample_rate)).round() as u64); + let frames = stream.duration.and_then(|duration| { + let seconds = + duration as f64 * stream.time_base.num() as f64 / stream.time_base.den() as f64; + (seconds.is_finite() && seconds >= 0.0) + .then(|| (seconds * f64::from(sample_rate)).round() as u64) + }); Ok(AudioFileInfo { sample_rate, channels, @@ -126,174 +88,68 @@ pub struct AudioMetadata { pub genre: Option, } -/// Read metadata tags from an audio file without decoding audio. -/// -/// Container tags (e.g. Vorbis comments, ID3v2) are preferred; track-level -/// tags (e.g. MP4 metadata) are used as a fallback. +/// Read container metadata tags without decoding audio. pub fn read_audio_metadata(path: &Path) -> io::Result { - use symphonia::core::meta::{RawValue, StandardTag}; - - fn raw_string(value: &RawValue) -> Option { - match value { - RawValue::String(s) => { - let s = s.trim(); - (!s.is_empty()).then(|| s.to_string()) - } - RawValue::UnsignedInt(v) => Some(v.to_string()), - _ => None, - } - } - - let mut format = probe_format(path)?; - let metadata = format.metadata(); - let Some(revision) = metadata.current() else { - return Err(io::Error::other(format!( - "No metadata in '{}'", - path.display() - ))); - }; + let demuxer = open_oxideav_demuxer(path)?; let mut meta = AudioMetadata::default(); - // Media-level tags first, then per-track tags as a fallback. - let mut tags: Vec<&symphonia::core::meta::Tag> = revision.media.tags.iter().collect(); - for track_meta in &revision.per_track { - tags.extend(track_meta.metadata.tags.iter()); - } - for tag in tags { - let (slot, value): (&mut Option, Option) = match tag.std.as_ref() { - Some(StandardTag::Artist(s)) | Some(StandardTag::Performer(s)) => { - (&mut meta.artist, Some(s.trim().to_string())) - } - Some(StandardTag::TrackTitle(s)) => (&mut meta.title, Some(s.trim().to_string())), - Some(StandardTag::Album(s)) => (&mut meta.album, Some(s.trim().to_string())), - Some(StandardTag::TrackNumber(n)) => (&mut meta.track_number, Some(n.to_string())), - Some(StandardTag::RecordingDate(s)) - | Some(StandardTag::ReleaseDate(s)) - | Some(StandardTag::OriginalReleaseDate(s)) => { - (&mut meta.date, Some(s.trim().to_string())) - } - Some(StandardTag::Genre(s)) => (&mut meta.genre, Some(s.trim().to_string())), - Some(_) => continue, - // Fall back to the raw key for tags Symphonia doesn't map. - None => { - let key = tag.raw.key.to_ascii_lowercase(); - let slot = match key.as_str() { - "artist" | "performer" => &mut meta.artist, - "title" | "tracktitle" => &mut meta.title, - "album" => &mut meta.album, - "tracknumber" | "track" => &mut meta.track_number, - "date" | "year" => &mut meta.date, - "genre" => &mut meta.genre, - _ => continue, - }; - (slot, raw_string(&tag.raw.value)) - } + for (key, value) in demuxer.metadata() { + let value = value.trim(); + if value.is_empty() { + continue; + } + let slot = match key.to_ascii_lowercase().as_str() { + "artist" | "performer" => &mut meta.artist, + "title" | "tracktitle" => &mut meta.title, + "album" => &mut meta.album, + "tracknumber" | "track" => &mut meta.track_number, + "date" | "year" => &mut meta.date, + "genre" => &mut meta.genre, + _ => continue, }; - if slot.is_none() - && let Some(value) = value - && !value.is_empty() - { - *slot = Some(value); + if slot.is_none() { + *slot = Some(value.to_string()); } } Ok(meta) } -fn probe_format(path: &Path) -> io::Result> { - let file = std::fs::File::open(path) - .map_err(|e| io::Error::other(format!("Failed to open '{}': {e}", path.display())))?; - let mss = MediaSourceStream::new(Box::new(file), Default::default()); - let mut hint = Hint::new(); - if let Some(ext) = path.extension().and_then(|e| e.to_str()) { - hint.with_extension(ext); - } - symphonia::default::get_probe() - .probe( - &hint, - mss, - FormatOptions::default(), - MetadataOptions::default(), - ) - .map_err(|e| { - io::Error::other(format!( - "Symphonia failed to probe format for '{}': {e}", - path.display() - )) - }) -} - -/// Parts of a probed + opened Symphonia audio stream: the format reader, the -/// audio decoder, the audio track id, channel count and sample rate. -type SymphoniaStreamParts = ( - Box, - Box, - u32, - usize, - u32, -); +type OxideavStreamParts = (Box, Box, u32, CodecParameters); /// Incremental audio decoder: probes once, then yields decoded interleaved /// `f32` chunks on demand. Used by the streaming clip producer thread so the /// audio thread never decodes whole files. pub struct StreamingDecoder { path: PathBuf, - format: Box, - decoder: Box, - track_id: u32, + demuxer: Box, + decoder: Box, + stream_index: u32, + params: CodecParameters, channels: usize, sample_rate: u32, - /// Pending decoded samples carried between chunk boundaries. pending: Vec, + flushed: bool, } impl StreamingDecoder { pub fn new(path: &Path) -> io::Result { - let (format, decoder, track_id, channels, sample_rate) = Self::open(path)?; + let (demuxer, decoder, stream_index, params) = open_oxideav_decoder(path)?; + let channels = params.channels.unwrap_or(1).max(1) as usize; + let sample_rate = params.sample_rate.unwrap_or(48_000); Ok(Self { path: path.to_path_buf(), - format, + demuxer, decoder, - track_id, + stream_index, + params, channels, sample_rate, pending: Vec::new(), + flushed: false, }) } - fn open(path: &Path) -> io::Result { - let format = probe_format(path)?; - let track = format - .default_track(TrackType::Audio) - .or_else(|| format.tracks().first()) - .ok_or_else(|| { - io::Error::other(format!("No usable audio track in '{}'", path.display())) - })?; - let codec_params: &AudioCodecParameters = track - .codec_params - .as_ref() - .and_then(SymphoniaCodecParameters::audio) - .ok_or_else(|| { - io::Error::other(format!("No usable audio track in '{}'", path.display())) - })?; - let channels = codec_params - .channels - .as_ref() - .map(|c| c.count()) - .unwrap_or(1); - let sample_rate = codec_params.sample_rate.unwrap_or(48_000); - let track_id = track.id; - let decoder = symphonia::default::get_codecs() - .make_audio_decoder(codec_params, &AudioDecoderOptions::default()) - .map_err(|e| { - io::Error::other(format!( - "Symphonia failed to create decoder for '{}': {e}", - path.display() - )) - })?; - Ok((format, decoder, track_id, channels, sample_rate)) - } - pub fn channels(&self) -> usize { - self.channels.max(1) + self.channels } pub fn sample_rate(&self) -> u32 { @@ -303,64 +159,38 @@ impl StreamingDecoder { /// Restart decoding from the beginning of the file. Used for seeks: the /// caller decodes and discards frames until the target position. pub fn reset(&mut self) -> io::Result<()> { - let (format, decoder, track_id, channels, sample_rate) = Self::open(&self.path)?; - self.format = format; + let (demuxer, decoder, stream_index, params) = open_oxideav_decoder(&self.path)?; + self.demuxer = demuxer; self.decoder = decoder; - self.track_id = track_id; - self.channels = channels; - self.sample_rate = sample_rate; + self.stream_index = stream_index; + self.params = params; self.pending.clear(); + self.flushed = false; Ok(()) } /// Decode and return up to `max_frames` interleaved frames. /// Returns `Ok(None)` at end of stream. pub fn next_chunk(&mut self, max_frames: usize) -> io::Result>> { - let channels = self.channels(); - let target = max_frames.saturating_mul(channels); + let target = max_frames.saturating_mul(self.channels); let mut out = std::mem::take(&mut self.pending); - if out.len() > target { - self.pending = out.split_off(target); - return Ok(Some(out)); - } - while out.len() < target { - let packet = match self.format.next_packet() { - Ok(Some(packet)) => packet, - Ok(None) => break, - Err(SymphoniaError::IoError(e)) - if e.kind() == std::io::ErrorKind::UnexpectedEof => - { - break; - } - Err(e) => { - return Err(io::Error::other(format!( - "Symphonia read error for '{}': {e}", - self.path.display() - ))); - } - }; - if packet.track_id != self.track_id { - continue; - } - match self.decoder.decode(&packet) { - Ok(decoded) => { - let mut packet_samples = Vec::new(); - decoded.copy_to_vec_interleaved(&mut packet_samples); - out.extend_from_slice(&packet_samples); - } - // Skip individual broken packets; fail only on IO-level errors. - Err(SymphoniaError::DecodeError(_)) => continue, - Err(SymphoniaError::IoError(e)) - if e.kind() == std::io::ErrorKind::UnexpectedEof => - { - break; + while out.len() < target && !self.flushed { + match self.demuxer.next_packet() { + Ok(packet) => { + if packet.stream_index != self.stream_index { + continue; + } + self.decoder + .send_packet(&packet) + .map_err(oxideav_err_to_io)?; + drain_decoder_frames(&mut *self.decoder, &self.params, &mut out)?; } - Err(e) => { - return Err(io::Error::other(format!( - "Symphonia decode error for '{}': {e}", - self.path.display() - ))); + Err(oxideav_core::Error::Eof) => { + self.decoder.flush().map_err(oxideav_err_to_io)?; + drain_decoder_frames(&mut *self.decoder, &self.params, &mut out)?; + self.flushed = true; } + Err(e) => return Err(oxideav_err_to_io(e)), } } if out.len() > target { @@ -375,16 +205,165 @@ impl StreamingDecoder { } // --------------------------------------------------------------------------- -// OxideAV decode (WAV/PCM, FLAC, MP3, Ogg-FLAC) +// OxideAV decode // --------------------------------------------------------------------------- -fn decode_with_oxideav(path: &Path) -> io::Result<(Vec, usize, u32)> { +struct AdtsDemuxer { + input: Box, + streams: Vec, + next: Option, + next_pts: i64, +} + +impl AdtsDemuxer { + fn open(mut input: Box) -> io::Result { + let (packet, params) = Self::read_packet(&mut input, 0)?; + let stream = StreamInfo { + index: 0, + time_base: TimeBase::new(1, params.sample_rate.unwrap_or(44_100) as i64), + duration: None, + start_time: Some(0), + params, + }; + Ok(Self { + input, + streams: vec![stream], + next: Some(packet), + next_pts: 1_024, + }) + } + + fn read_packet( + input: &mut dyn oxideav_core::ReadSeek, + pts: i64, + ) -> io::Result<(Packet, CodecParameters)> { + let mut header = [0_u8; 7]; + input.read_exact(&mut header)?; + let (adts, _) = oxideav_aac::adts::AdtsHeader::parse(&header) + .map_err(|e| io::Error::other(format!("Invalid ADTS header: {e}")))?; + let mut data = vec![0_u8; adts.aac_frame_length as usize]; + data[..7].copy_from_slice(&header); + input.read_exact(&mut data[7..])?; + let mut params = CodecParameters::audio(CodecId::new("aac")); + params.media_type = MediaType::Audio; + params.channels = Some(u16::from(adts.channel_configuration.max(1))); + params.sample_rate = Some(adts.sample_rate()); + params.sample_format = Some(SampleFormat::S16); + let mut packet = Packet::new(0, TimeBase::new(1, adts.sample_rate() as i64), data); + packet.pts = Some(pts); + packet.dts = Some(pts); + packet.duration = Some(1_024 * i64::from(adts.number_of_raw_data_blocks_in_frame)); + packet.flags.keyframe = true; + Ok((packet, params)) + } +} + +impl Demuxer for AdtsDemuxer { + fn format_name(&self) -> &str { + "adts" + } + + fn streams(&self) -> &[StreamInfo] { + &self.streams + } + + fn next_packet(&mut self) -> oxideav_core::Result { + if let Some(packet) = self.next.take() { + return Ok(packet); + } + match Self::read_packet(&mut *self.input, self.next_pts) { + Ok((packet, _)) => { + self.next_pts += packet.duration.unwrap_or(1_024); + Ok(packet) + } + Err(e) if e.kind() == io::ErrorKind::UnexpectedEof => Err(oxideav_core::Error::Eof), + Err(e) => Err(oxideav_core::Error::other(e.to_string())), + } + } +} + +struct RawAacDecoder { + inner: Box, + config: oxideav_aac::asc::AudioSpecificConfig, +} + +impl RawAacDecoder { + fn new(inner: Box, config: oxideav_aac::asc::AudioSpecificConfig) -> Self { + Self { inner, config } + } +} + +impl Decoder for RawAacDecoder { + fn codec_id(&self) -> &CodecId { + self.inner.codec_id() + } + + fn send_packet(&mut self, packet: &Packet) -> oxideav_core::Result<()> { + if !(1..=4).contains(&self.config.aot) { + return Err(oxideav_core::Error::unsupported(format!( + "AAC object type {} cannot be carried in ADTS", + self.config.aot + ))); + } + let frame_length = packet.data.len().saturating_add(7); + let header = oxideav_aac::adts::AdtsHeader { + mpeg_version_mpeg2: false, + protection_absent: true, + profile: self.config.aot - 1, + sampling_frequency_index: self.config.sampling_frequency_index, + channel_configuration: self.config.channel_configuration, + aac_frame_length: u16::try_from(frame_length) + .map_err(|_| oxideav_core::Error::invalid("AAC access unit is too large"))?, + adts_buffer_fullness: 0x7ff, + number_of_raw_data_blocks_in_frame: 1, + }; + let mut framed = Vec::with_capacity(frame_length); + framed.extend_from_slice( + &header + .write() + .map_err(|e| oxideav_core::Error::other(e.to_string()))?, + ); + framed.extend_from_slice(&packet.data); + let mut packet = packet.clone(); + packet.data = framed; + self.inner.send_packet(&packet) + } + + fn receive_frame(&mut self) -> oxideav_core::Result { + self.inner.receive_frame() + } + + fn flush(&mut self) -> oxideav_core::Result<()> { + self.inner.flush() + } + + fn reset(&mut self) -> oxideav_core::Result<()> { + self.inner.reset() + } + + fn output_params(&self) -> Option { + self.inner.output_params() + } + + fn output_params_generation(&self) -> u64 { + self.inner.output_params_generation() + } +} + +fn oxideav_runtime() -> RuntimeContext { let mut ctx = RuntimeContext::new(); oxideav_basic::register(&mut ctx); oxideav_flac::register(&mut ctx); oxideav_mp3::register(&mut ctx); oxideav_ogg::register(&mut ctx); + oxideav_vorbis::register(&mut ctx); + oxideav_aac::register(&mut ctx); + oxideav_mp4::register(&mut ctx); + ctx +} +fn open_oxideav_demuxer(path: &Path) -> io::Result> { + let ctx = oxideav_runtime(); let mut input: Box = Box::new( std::fs::File::open(path) .map_err(|e| io::Error::other(format!("Failed to open '{}': {e}", path.display())))?, @@ -393,37 +372,51 @@ fn decode_with_oxideav(path: &Path) -> io::Result<(Vec, usize, u32)> { .extension() .and_then(|e| e.to_str()) .map(str::to_ascii_lowercase); + if ext_hint.as_deref() == Some("aac") { + return Ok(Box::new(AdtsDemuxer::open(input)?)); + } let container = ctx .containers .probe_input(&mut *input, ext_hint.as_deref()) .map_err(oxideav_err_to_io)?; - let mut demuxer = ctx - .containers + ctx.containers .open_demuxer(&container, input, &ctx.codecs) - .map_err(oxideav_err_to_io)?; + .map_err(oxideav_err_to_io) +} - let (stream_index, params) = demuxer +fn first_audio_stream(demuxer: &dyn Demuxer, path: &Path) -> io::Result<(u32, StreamInfo)> { + demuxer .streams() .iter() - .enumerate() - .map(|(i, s)| (i as u32, &s.params)) - .find(|(_, p)| p.media_type == MediaType::Audio) - .ok_or_else(|| { - io::Error::other(format!("No usable audio track in '{}'", path.display())) - })?; - let params = params.clone(); - - let channels = params.channels.unwrap_or(1) as usize; - let sample_rate = params.sample_rate.unwrap_or(48_000); - // The MP3 demuxer leaves `sample_format` unset; its decoder always - // emits packed S16. Every other OxideAV decoder declares its format. - let format = params.sample_format.unwrap_or(SampleFormat::S16); - let mut decoder = ctx + .find(|stream| stream.params.media_type == MediaType::Audio) + .map(|stream| (stream.index, stream.clone())) + .ok_or_else(|| io::Error::other(format!("No usable audio track in '{}'", path.display()))) +} + +fn open_oxideav_decoder(path: &Path) -> io::Result { + let ctx = oxideav_runtime(); + let mut demuxer = open_oxideav_demuxer(path)?; + let (stream_index, stream) = first_audio_stream(&*demuxer, path)?; + let decoder = ctx .codecs - .first_decoder(¶ms) + .first_decoder(&stream.params) .map_err(oxideav_err_to_io)?; + let decoder = if stream.params.codec_id.as_str() == "aac" && !stream.params.extradata.is_empty() + { + let (config, _) = oxideav_aac::asc::AudioSpecificConfig::parse(&stream.params.extradata) + .map_err(|e| io::Error::other(format!("Invalid AAC configuration: {e}")))?; + Box::new(RawAacDecoder::new(decoder, config)) as Box + } else { + decoder + }; demuxer.set_active_streams(std::slice::from_ref(&stream_index)); + Ok((demuxer, decoder, stream_index, stream.params)) +} +fn decode_with_oxideav(path: &Path) -> io::Result<(Vec, usize, u32)> { + let (mut demuxer, mut decoder, stream_index, params) = open_oxideav_decoder(path)?; + let channels = params.channels.unwrap_or(1).max(1) as usize; + let sample_rate = params.sample_rate.unwrap_or(48_000); let mut samples = Vec::new(); loop { match demuxer.next_packet() { @@ -432,14 +425,14 @@ fn decode_with_oxideav(path: &Path) -> io::Result<(Vec, usize, u32)> { continue; } decoder.send_packet(&packet).map_err(oxideav_err_to_io)?; - drain_decoder_frames(&mut *decoder, format, channels, &mut samples)?; + drain_decoder_frames(&mut *decoder, ¶ms, &mut samples)?; } Err(oxideav_core::Error::Eof) => break, Err(e) => return Err(oxideav_err_to_io(e)), } } decoder.flush().map_err(oxideav_err_to_io)?; - drain_decoder_frames(&mut *decoder, format, channels, &mut samples)?; + drain_decoder_frames(&mut *decoder, ¶ms, &mut samples)?; if samples.is_empty() { return Err(io::Error::other(format!( @@ -454,12 +447,15 @@ fn decode_with_oxideav(path: &Path) -> io::Result<(Vec, usize, u32)> { /// Pull every decoded frame currently pending on `decoder` and append it /// to `out` as interleaved `f32`. fn drain_decoder_frames( - decoder: &mut dyn oxideav_core::Decoder, - format: SampleFormat, - channels: usize, + decoder: &mut dyn Decoder, + stream_params: &CodecParameters, out: &mut Vec, ) -> io::Result<()> { loop { + let output = decoder.output_params(); + let params = output.as_ref().unwrap_or(stream_params); + let format = params.sample_format.unwrap_or(SampleFormat::S16); + let channels = params.channels.unwrap_or(1).max(1) as usize; match decoder.receive_frame() { Ok(Frame::Audio(frame)) => { out.extend(unpack_audio_frame(&frame, format, channels)?); @@ -508,7 +504,7 @@ fn unpack_audio_frame( if end > plane.len() { return Err(io::Error::other("OxideAV frame plane is truncated")); } - out.push(sample_bytes_to_f32(&plane[start..end], format)); + out.push(sample_bytes_to_f32(&plane[start..end], format)?); } } } else { @@ -525,17 +521,18 @@ fn unpack_audio_frame( ))); } for chunk in plane[..total * bytes_per_sample].chunks_exact(bytes_per_sample) { - out.push(sample_bytes_to_f32(chunk, format)); + out.push(sample_bytes_to_f32(chunk, format)?); } } Ok(out) } -fn sample_bytes_to_f32(bytes: &[u8], format: SampleFormat) -> f32 { - match format { - SampleFormat::U8 => (bytes[0] as f32 - 128.0) / 128.0, - SampleFormat::S16 => { +fn sample_bytes_to_f32(bytes: &[u8], format: SampleFormat) -> io::Result { + let sample = match format { + SampleFormat::U8 | SampleFormat::U8P => (bytes[0] as f32 - 128.0) / 128.0, + SampleFormat::S8 => bytes[0] as i8 as f32 / i8::MAX as f32, + SampleFormat::S16 | SampleFormat::S16P => { f32::from(i16::from_le_bytes([bytes[0], bytes[1]])) / f32::from(i16::MAX) } SampleFormat::S24 => { @@ -547,114 +544,24 @@ fn sample_bytes_to_f32(bytes: &[u8], format: SampleFormat) -> f32 { ]); v as f32 / 8_388_607.0 } - SampleFormat::S32 => { + SampleFormat::S32 | SampleFormat::S32P => { i32::from_le_bytes([bytes[0], bytes[1], bytes[2], bytes[3]]) as f32 / i32::MAX as f32 } - SampleFormat::F32 => f32::from_le_bytes([bytes[0], bytes[1], bytes[2], bytes[3]]), - _ => 0.0, - } -} - -// --------------------------------------------------------------------------- -// Symphonia decode fallback (Ogg Vorbis, AAC, ALAC, MP4/M4A, ...) -// --------------------------------------------------------------------------- - -fn decode_with_symphonia(path: &Path) -> io::Result<(Vec, usize, u32)> { - let file = std::fs::File::open(path) - .map_err(|e| io::Error::other(format!("Failed to open '{}': {e}", path.display())))?; - let mss = MediaSourceStream::new(Box::new(file), Default::default()); - - let mut hint = Hint::new(); - if let Some(ext) = path.extension().and_then(|e| e.to_str()) { - hint.with_extension(ext); - } - - let format_opts = FormatOptions::default(); - let metadata_opts = MetadataOptions::default(); - let decoder_opts = AudioDecoderOptions::default(); - - let mut format: Box = symphonia::default::get_probe() - .probe(&hint, mss, format_opts, metadata_opts) - .map_err(|e| { - io::Error::other(format!( - "Symphonia failed to probe format for '{}': {e}", - path.display() - )) - })?; - - let track = format - .default_track(TrackType::Audio) - .or_else(|| format.tracks().first()) - .ok_or_else(|| { - io::Error::other(format!("No usable audio track in '{}'", path.display())) - })?; - - let codec_params: &AudioCodecParameters = track - .codec_params - .as_ref() - .and_then(SymphoniaCodecParameters::audio) - .ok_or_else(|| { - io::Error::other(format!("No usable audio track in '{}'", path.display())) - })?; - - let channels = codec_params - .channels - .as_ref() - .map(|c| c.count()) - .unwrap_or(1); - let sample_rate = codec_params.sample_rate.unwrap_or(48_000); - let track_id = track.id; - - let mut decoder = symphonia::default::get_codecs() - .make_audio_decoder(codec_params, &decoder_opts) - .map_err(|e| { - io::Error::other(format!( - "Symphonia failed to create decoder for '{}': {e}", - path.display() - )) - })?; - - let mut samples = Vec::new(); - - loop { - let packet = match format.next_packet() { - Ok(Some(packet)) => packet, - Ok(None) => break, - Err(SymphoniaError::IoError(e)) if e.kind() == std::io::ErrorKind::UnexpectedEof => { - break; - } - Err(e) => { - return Err(io::Error::other(format!( - "Symphonia read error for '{}': {e}", - path.display() - ))); - } - }; - - if packet.track_id != track_id { - continue; + SampleFormat::F32 | SampleFormat::F32P => { + f32::from_le_bytes([bytes[0], bytes[1], bytes[2], bytes[3]]) } - - let decoded = decoder.decode(&packet).map_err(|e| { - io::Error::other(format!( - "Symphonia decode error for '{}': {e}", - path.display() - )) - })?; - - let mut packet_samples = Vec::new(); - decoded.copy_to_vec_interleaved(&mut packet_samples); - samples.extend_from_slice(&packet_samples); - } - - if samples.is_empty() { - return Err(io::Error::other(format!( - "No samples decoded from '{}'", - path.display() - ))); - } - - Ok((samples, channels, sample_rate)) + SampleFormat::F64 | SampleFormat::F64P => f64::from_le_bytes( + bytes[..8] + .try_into() + .map_err(|_| io::Error::other("OxideAV frame contains a truncated F64 sample"))?, + ) as f32, + _ => { + return Err(io::Error::other(format!( + "Unsupported OxideAV sample format {format:?}" + ))); + } + }; + Ok(sample) } // --------------------------------------------------------------------------- @@ -1330,7 +1237,7 @@ mod tests { #[test] #[cfg_attr(miri, ignore = "Miri isolation does not support filesystem open")] - fn oxideav_fallback_decodes_flac_and_mp3() { + fn oxideav_decodes_flac_and_mp3() { let sample_rate = 44_100u32; let channels = 2usize; let frames = sample_rate as usize / 10; // 100 ms @@ -1362,7 +1269,7 @@ mod tests { ) .expect("encode test file"); - // Bypass Symphonia to exercise the OxideAV fallback directly. + // Exercise the OxideAV decoder directly. let (decoded, out_channels, out_rate) = decode_with_oxideav(&path).expect("oxideav decode"); std::fs::remove_file(&path).expect("remove temporary test file"); @@ -1377,6 +1284,121 @@ mod tests { } } + #[test] + #[cfg_attr(miri, ignore = "Miri isolation does not support filesystem open")] + fn oxideav_decodes_vorbis() { + let sample_rate = 44_100; + let pcm: Vec = (0..4_096) + .map(|i| { + 0.4 * (2.0 * std::f32::consts::PI * 440.0 * i as f32 / sample_rate as f32).sin() + }) + .collect(); + let config = oxideav_vorbis::oggfile::StreamEncoderConfig::new(sample_rate, 1); + let bytes = + oxideav_vorbis::oggfile::encode_pcm_to_ogg(&[pcm], &config).expect("encode Vorbis"); + let path = + std::env::temp_dir().join(format!("maolan_oxideav_vorbis_{}.ogg", std::process::id())); + std::fs::write(&path, bytes).expect("write Vorbis"); + let (decoded, channels, rate) = + decode_audio_to_f32_interleaved_sync(&path).expect("decode Vorbis"); + std::fs::remove_file(&path).expect("remove Vorbis"); + assert_eq!(channels, 1); + assert_eq!(rate, sample_rate); + assert!(decoded.iter().all(|sample| sample.is_finite())); + assert!(decoded.iter().any(|sample| sample.abs() > 0.1)); + } + + #[test] + #[cfg_attr(miri, ignore = "Miri isolation does not support filesystem open")] + fn oxideav_decodes_aac_adts() { + let sample_rate = 44_100; + let pcm: Vec = (0..4_096) + .map(|i| { + (12_000.0 + * (2.0 * std::f32::consts::PI * 440.0 * i as f32 / sample_rate as f32).sin()) + as i16 + }) + .collect(); + let mut encoder = + oxideav_aac::encoder::StreamEncoder::new(oxideav_aac::encoder::EncoderConfig { + sample_rate, + channels: 1, + bitrate: 128_000, + }) + .expect("create AAC encoder"); + let bytes = encoder.encode_all(&pcm).expect("encode AAC"); + let path = + std::env::temp_dir().join(format!("maolan_oxideav_aac_{}.aac", std::process::id())); + std::fs::write(&path, bytes).expect("write AAC"); + let (decoded, channels, rate) = + decode_audio_to_f32_interleaved_sync(&path).expect("decode AAC"); + std::fs::remove_file(&path).expect("remove AAC"); + assert_eq!(channels, 1); + assert_eq!(rate, sample_rate); + assert!(decoded.iter().all(|sample| sample.is_finite())); + assert!(decoded.iter().any(|sample| sample.abs() > 0.1)); + } + + #[test] + #[cfg_attr(miri, ignore = "Miri isolation does not support filesystem open")] + fn oxideav_decodes_aac_mp4() { + let sample_rate = 44_100; + let pcm = vec![0_i16; 4_096]; + let mut encoder = + oxideav_aac::encoder::StreamEncoder::new(oxideav_aac::encoder::EncoderConfig { + sample_rate, + channels: 1, + bitrate: 128_000, + }) + .expect("create AAC encoder"); + let adts = encoder.encode_all(&pcm).expect("encode AAC"); + let mut params = audio_codec_params("aac", 1, sample_rate, SampleFormat::S16, None); + params.extradata = vec![0x12, 0x08]; + let stream = StreamInfo { + index: 0, + time_base: TimeBase::new(1, sample_rate as i64), + duration: None, + start_time: Some(0), + params, + }; + let path = + std::env::temp_dir().join(format!("maolan_oxideav_aac_{}.m4a", std::process::id())); + let mut mux = oxideav_runtime() + .containers + .open_muxer( + "mp4", + Box::new(std::fs::File::create(&path).expect("create M4A")), + std::slice::from_ref(&stream), + ) + .expect("create MP4 muxer"); + mux.write_header().expect("write MP4 header"); + let mut offset = 0; + let mut pts = 0; + while offset < adts.len() { + let (header, _) = + oxideav_aac::adts::AdtsHeader::parse(&adts[offset..]).expect("parse ADTS"); + let frame_len = header.aac_frame_length as usize; + let mut packet = Packet::new( + 0, + stream.time_base, + adts[offset + 7..offset + frame_len].to_vec(), + ); + packet.pts = Some(pts); + packet.duration = Some(1_024); + mux.write_packet(&packet).expect("write AAC packet"); + offset += frame_len; + pts += 1_024; + } + mux.write_trailer().expect("write MP4 trailer"); + let (decoded, channels, rate) = + decode_audio_to_f32_interleaved_sync(&path).expect("decode M4A"); + std::fs::remove_file(&path).expect("remove M4A"); + assert_eq!(channels, 1); + assert_eq!(rate, sample_rate); + assert!(decoded.len() >= 4_096); + assert!(decoded.iter().all(|sample| sample.is_finite())); + } + #[test] #[cfg_attr(miri, ignore = "Miri isolation does not support filesystem open")] fn probe_audio_file_reports_wav_metadata() { diff --git a/src/hw/jack.rs b/src/hw/jack.rs index 33df743..e258ef3 100644 --- a/src/hw/jack.rs +++ b/src/hw/jack.rs @@ -667,7 +667,7 @@ impl JackRuntime { .into_iter() .filter_map(|name| { let port = client.port_by_name(&name)?; - let flags = port.flags(); + let flags = port.flags().ok()?; Some(JackPortInfo { name, kind, @@ -717,7 +717,10 @@ impl JackRuntime { let Some(port) = client.port_by_name(&source.name) else { continue; }; - for destination in port.get_connections() { + let Ok(destinations) = port.get_connections() else { + continue; + }; + for destination in destinations { if ports.iter().any(|port| port.name == destination) { connections.push(JackConnectionInfo { source: source.name.clone(), diff --git a/src/track/streaming.rs b/src/track/streaming.rs index ca21726..e0348a8 100644 --- a/src/track/streaming.rs +++ b/src/track/streaming.rs @@ -12,7 +12,7 @@ //! clip re-launch), it posts the requested absolute source frame to the //! producer. The producer restarts its incremental decoder from the //! beginning of the file and decodes-and-discards until the requested frame -//! (symphonia seeking is not used), then resumes pushing at the next free +//! (container seeking is not used), then resumes pushing at the next free //! slot in the rings without clearing them. The audio already buffered in //! the rings is therefore played once more before the new position lands — //! that latency is accepted for v1. Sequential playback (the common player