forge
Explore
Log in

Don't you dare go Hollow

One ISO 639 table, the demuxer's, for both sides

Browse files at this commit

737b17126151d8b575be07aeca98712b696d4f2aAhmet Kaan GümüşParent: de38f6e
  • refactor
    • one ISO 639 table, the demuxer's, for both sides
Show full message
♻️ refactor(media): one ISO 639 table, the demuxer's, for both sides

The mux lane had carried its own copy of the demuxer's ISO 639-1 → 639-2
table because that one was private to its module. Make the demuxer's
`pub(crate)` and have the muxer read it, so the two can no longer drift;
the copies were byte-identical, all 183 entries, so nothing is dropped.
crates/engine/src/demux.rsmodified+1 -1
@@ -2370,7 +2370,7 @@ fn mkv_language(legacy: &str, bcp47: &str) -> String {
2370 /// from `iso-codes`' own `iso_639-2.json`, so a Kannada track is as readable as2370 /// from `iso-codes`' own `iso_639-2.json`, so a Kannada track is as readable as
2371 /// an English one.2371 /// an English one.
2372 #[rustfmt::skip]2372 #[rustfmt::skip]
2373-const ISO_639_1_TO_2: &[(&str, &str)] = &[2373+pub(crate) const ISO_639_1_TO_2: &[(&str, &str)] = &[
2374 ("aa", "aar"), ("ab", "abk"), ("ae", "ave"), ("af", "afr"),2374 ("aa", "aar"), ("ab", "abk"), ("ae", "ave"), ("af", "afr"),
2375 ("ak", "aka"), ("am", "amh"), ("an", "arg"), ("ar", "ara"),2375 ("ak", "aka"), ("am", "amh"), ("an", "arg"), ("ar", "ara"),
2376 ("as", "asm"), ("av", "ava"), ("ay", "aym"), ("az", "aze"),2376 ("as", "asm"), ("av", "ava"), ("ay", "aym"), ("az", "aze"),
crates/engine/src/mux.rsmodified+2 -62
@@ -174,7 +174,7 @@ fn colr_nclx(colour: ColorDescription) -> [u8; 11] {
174 /// `ptm`, silently, with a player's subtitle menu then offering a language174 /// `ptm`, silently, with a player's subtitle menu then offering a language
175 /// nobody speaks. Matroska's `Language` is raw UTF-8 beside that and may carry175 /// nobody speaks. Matroska's `Language` is raw UTF-8 beside that and may carry
176 /// a BCP-47 tag, so the tag is cut to its primary subtag here, mapped through176 /// a BCP-47 tag, so the tag is cut to its primary subtag here, mapped through
177-/// [`ISO_639_1_TO_2`] where it is two letters, and left `und` -- the code that177+/// [`crate::demux::ISO_639_1_TO_2`] where it is two letters, and left `und` -- the code that
178 /// says *undetermined* -- where nothing names it.178 /// says *undetermined* -- where nothing names it.
179 ///179 ///
180 /// Three lowercase letters are taken as they are: that is the code the field180 /// Three lowercase letters are taken as they are: that is the code the field
@@ -187,7 +187,7 @@ fn mp4_language(language: &str) -> String {
187 .unwrap_or_default()187 .unwrap_or_default()
188 .to_ascii_lowercase();188 .to_ascii_lowercase();
189 let code = match primary.len() {189 let code = match primary.len() {
190- 2 => ISO_639_1_TO_2190+ 2 => crate::demux::ISO_639_1_TO_2
191 .iter()191 .iter()
192 .find(|(two, _)| *two == primary)192 .find(|(two, _)| *two == primary)
193 .map(|(_, three)| *three),193 .map(|(_, three)| *three),
@@ -197,66 +197,6 @@ fn mp4_language(language: &str) -> String {
197 code.unwrap_or("und").to_owned()197 code.unwrap_or("und").to_owned()
198 }198 }
199 199
200-/// Every ISO 639-1 code and the 639-2 (terminology) one it names the same
201-/// language with -- what [`mp4_language`] maps a BCP-47 primary subtag through.
202-///
203-/// corner-cut: the same standard's table `crate::demux` reads a Matroska
204-/// `TrackEntry` through, carried here as well because that one is private to
205-/// its module and this file owns no other file's visibility. The two must not
206-/// drift, so a change belongs in both; the upgrade path is one table with
207-/// `pub(crate)` on it, and a muxer that calls the demuxer's. Whole standard and
208-/// not the languages a test happened to use, generated from `iso-codes`'
209-/// `iso_639-2.json` like that one.
210-#[rustfmt::skip]
211-const ISO_639_1_TO_2: &[(&str, &str)] = &[
212- ("aa", "aar"), ("ab", "abk"), ("ae", "ave"), ("af", "afr"),
213- ("ak", "aka"), ("am", "amh"), ("an", "arg"), ("ar", "ara"),
214- ("as", "asm"), ("av", "ava"), ("ay", "aym"), ("az", "aze"),
215- ("ba", "bak"), ("be", "bel"), ("bg", "bul"), ("bi", "bis"),
216- ("bm", "bam"), ("bn", "ben"), ("bo", "bod"), ("br", "bre"),
217- ("bs", "bos"), ("ca", "cat"), ("ce", "che"), ("ch", "cha"),
218- ("co", "cos"), ("cr", "cre"), ("cs", "ces"), ("cu", "chu"),
219- ("cv", "chv"), ("cy", "cym"), ("da", "dan"), ("de", "deu"),
220- ("dv", "div"), ("dz", "dzo"), ("ee", "ewe"), ("el", "ell"),
221- ("en", "eng"), ("eo", "epo"), ("es", "spa"), ("et", "est"),
222- ("eu", "eus"), ("fa", "fas"), ("ff", "ful"), ("fi", "fin"),
223- ("fj", "fij"), ("fo", "fao"), ("fr", "fra"), ("fy", "fry"),
224- ("ga", "gle"), ("gd", "gla"), ("gl", "glg"), ("gn", "grn"),
225- ("gu", "guj"), ("gv", "glv"), ("ha", "hau"), ("he", "heb"),
226- ("hi", "hin"), ("ho", "hmo"), ("hr", "hrv"), ("ht", "hat"),
227- ("hu", "hun"), ("hy", "hye"), ("hz", "her"), ("ia", "ina"),
228- ("id", "ind"), ("ie", "ile"), ("ig", "ibo"), ("ii", "iii"),
229- ("ik", "ipk"), ("io", "ido"), ("is", "isl"), ("it", "ita"),
230- ("iu", "iku"), ("ja", "jpn"), ("jv", "jav"), ("ka", "kat"),
231- ("kg", "kon"), ("ki", "kik"), ("kj", "kua"), ("kk", "kaz"),
232- ("kl", "kal"), ("km", "khm"), ("kn", "kan"), ("ko", "kor"),
233- ("kr", "kau"), ("ks", "kas"), ("ku", "kur"), ("kv", "kom"),
234- ("kw", "cor"), ("ky", "kir"), ("la", "lat"), ("lb", "ltz"),
235- ("lg", "lug"), ("li", "lim"), ("ln", "lin"), ("lo", "lao"),
236- ("lt", "lit"), ("lu", "lub"), ("lv", "lav"), ("mg", "mlg"),
237- ("mh", "mah"), ("mi", "mri"), ("mk", "mkd"), ("ml", "mal"),
238- ("mn", "mon"), ("mr", "mar"), ("ms", "msa"), ("mt", "mlt"),
239- ("my", "mya"), ("na", "nau"), ("nb", "nob"), ("nd", "nde"),
240- ("ne", "nep"), ("ng", "ndo"), ("nl", "nld"), ("nn", "nno"),
241- ("no", "nor"), ("nr", "nbl"), ("nv", "nav"), ("ny", "nya"),
242- ("oc", "oci"), ("oj", "oji"), ("om", "orm"), ("or", "ori"),
243- ("os", "oss"), ("pa", "pan"), ("pi", "pli"), ("pl", "pol"),
244- ("ps", "pus"), ("pt", "por"), ("qu", "que"), ("rm", "roh"),
245- ("rn", "run"), ("ro", "ron"), ("ru", "rus"), ("rw", "kin"),
246- ("sa", "san"), ("sc", "srd"), ("sd", "snd"), ("se", "sme"),
247- ("sg", "sag"), ("si", "sin"), ("sk", "slk"), ("sl", "slv"),
248- ("sm", "smo"), ("sn", "sna"), ("so", "som"), ("sq", "sqi"),
249- ("sr", "srp"), ("ss", "ssw"), ("st", "sot"), ("su", "sun"),
250- ("sv", "swe"), ("sw", "swa"), ("ta", "tam"), ("te", "tel"),
251- ("tg", "tgk"), ("th", "tha"), ("ti", "tir"), ("tk", "tuk"),
252- ("tl", "tgl"), ("tn", "tsn"), ("to", "ton"), ("tr", "tur"),
253- ("ts", "tso"), ("tt", "tat"), ("tw", "twi"), ("ty", "tah"),
254- ("ug", "uig"), ("uk", "ukr"), ("ur", "urd"), ("uz", "uzb"),
255- ("ve", "ven"), ("vi", "vie"), ("vo", "vol"), ("wa", "wln"),
256- ("wo", "wol"), ("xh", "xho"), ("yi", "yid"), ("yo", "yor"),
257- ("za", "zha"), ("zh", "zho"), ("zu", "zul"),
258-];
259-
260 const VIDEO_TRACK: u32 = 1;200 const VIDEO_TRACK: u32 = 1;
261 const AUDIO_TRACK: u32 = 2;201 const AUDIO_TRACK: u32 = 2;
262 202