mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Handle invalid language codes in Boxes.java
When an invalid language code is give, write default value instead of throwing. This behaviour aligns with `MediaMuxer`. PiperOrigin-RevId: 686066088
This commit is contained in:
parent
5a827829b0
commit
643e16ca8f
1 changed files with 8 additions and 3 deletions
|
|
@ -1853,16 +1853,21 @@ import org.checkerframework.checker.nullness.qual.PolyNull;
|
||||||
return BoxUtils.wrapIntoBox("dOps", contents);
|
return BoxUtils.wrapIntoBox("dOps", contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Packs a three-letter language code into a short, packing 3x5 bits. */
|
/**
|
||||||
|
* Packs a three-letter language code into a short, packing 3x5 bits.
|
||||||
|
*
|
||||||
|
* <p>A default value 0 is returned if the {@code code} is not recognized.
|
||||||
|
*/
|
||||||
private static short languageCodeFromString(@Nullable String code) {
|
private static short languageCodeFromString(@Nullable String code) {
|
||||||
|
short defaultLanguageCode = 0;
|
||||||
if (code == null) {
|
if (code == null) {
|
||||||
return 0;
|
return defaultLanguageCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] bytes = Util.getUtf8Bytes(code);
|
byte[] bytes = Util.getUtf8Bytes(code);
|
||||||
|
|
||||||
if (bytes.length != 3) {
|
if (bytes.length != 3) {
|
||||||
throw new IllegalArgumentException("Non-length-3 language code: " + code);
|
return defaultLanguageCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take only last 5 bits of each letter.
|
// Take only last 5 bits of each letter.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue