Ensure normalized language code is used everywhere and update documentation.

Issue:#2867
PiperOrigin-RevId: 231385677
This commit is contained in:
tonihei 2019-01-29 12:59:29 +00:00 committed by Oliver Woodman
parent 6983f92ffd
commit ef8335fc50
7 changed files with 15 additions and 13 deletions

View file

@ -536,9 +536,7 @@ public final class C {
*/
public static final int SELECTION_FLAG_AUTOSELECT = 1 << 2; // 4
/**
* Represents an undetermined language as an ISO 639 alpha-3 language code.
*/
/** Represents an undetermined language as an ISO 639-2 language code. */
public static final String LANGUAGE_UNDETERMINED = "und";
/**

View file

@ -159,7 +159,7 @@ public final class Format implements Parcelable {
@C.SelectionFlags
public final int selectionFlags;
/** The language, or null if unknown or not applicable. */
/** The language as ISO 639-2/T three-letter code, or null if unknown or not applicable. */
public final @Nullable String language;
/**
@ -932,7 +932,7 @@ public final class Format implements Parcelable {
this.encoderDelay = encoderDelay == Format.NO_VALUE ? 0 : encoderDelay;
this.encoderPadding = encoderPadding == Format.NO_VALUE ? 0 : encoderPadding;
this.selectionFlags = selectionFlags;
this.language = language;
this.language = Util.normalizeLanguageCode(language);
this.accessibilityChannel = accessibilityChannel;
this.subsampleOffsetUs = subsampleOffsetUs;
this.initializationData =

View file

@ -100,7 +100,7 @@ public interface TsPayloadReader {
public final byte[] initializationData;
/**
* @param language The ISO 639-2 three character language.
* @param language The ISO 639-2 three-letter language code.
* @param type The subtitling type.
* @param initializationData The composition and ancillary page ids.
*/

View file

@ -495,7 +495,7 @@ public final class DownloadHelper {
* used instead. Must not be called until after preparation completes.
*
* @param languages A list of audio languages for which tracks should be added to the download
* selection, as ISO 639-2/T tags.
* selection, as ISO 639-1 two-letter or ISO 639-2 three-letter codes.
*/
public void addAudioLanguagesToSelection(String... languages) {
assertPreparedWithMedia();
@ -524,7 +524,7 @@ public final class DownloadHelper {
* selected for downloading if no track with one of the specified {@code languages} is
* available.
* @param languages A list of text languages for which tracks should be added to the download
* selection, as ISO 639-2/T tags.
* selection, as ISO 639-1 two-letter or ISO 639-2 three-letter codes.
*/
public void addTextLanguagesToSelection(
boolean selectUndeterminedTextLanguage, String... languages) {

View file

@ -365,6 +365,8 @@ public class DefaultTrackSelector extends MappingTrackSelector {
/**
* See {@link Parameters#preferredAudioLanguage}.
*
* @param preferredAudioLanguage Preferred audio language as an ISO 639-1 two-letter or ISO
* 639-2 three-letter code.
* @return This builder.
*/
public ParametersBuilder setPreferredAudioLanguage(String preferredAudioLanguage) {
@ -430,6 +432,8 @@ public class DefaultTrackSelector extends MappingTrackSelector {
/**
* See {@link Parameters#preferredTextLanguage}.
*
* @param preferredTextLanguage Preferred text language as an ISO 639-1 two-letter or ISO 639-2
* three-letter code.
* @return This builder.
*/
public ParametersBuilder setPreferredTextLanguage(String preferredTextLanguage) {
@ -2313,8 +2317,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
* null.
*/
protected static boolean formatHasLanguage(Format format, @Nullable String language) {
return language != null
&& TextUtils.equals(language, Util.normalizeLanguageCode(format.language));
return language != null && TextUtils.equals(language, format.language);
}
private static List<Integer> getViewportFilteredTrackIndices(TrackGroup group, int viewportWidth,

View file

@ -418,9 +418,10 @@ public final class Util {
}
/**
* Returns a normalized RFC 639-2/T code for {@code language}.
* Returns a normalized ISO 639-2/T code for {@code language}.
*
* @param language A case-insensitive ISO 639 alpha-2 or alpha-3 language code.
* @param language A case-insensitive ISO 639-1 two-letter or ISO 639-2 three-letter language
* code.
* @return The all-lowercase normalized code, or null if the input was null, or {@code
* language.toLowerCase()} if the language could not be normalized.
*/

View file

@ -225,7 +225,7 @@ public class HlsMasterPlaylistParserTest {
Format closedCaptionFormat = playlist.muxedCaptionFormats.get(0);
assertThat(closedCaptionFormat.sampleMimeType).isEqualTo(MimeTypes.APPLICATION_CEA708);
assertThat(closedCaptionFormat.accessibilityChannel).isEqualTo(4);
assertThat(closedCaptionFormat.language).isEqualTo("es");
assertThat(closedCaptionFormat.language).isEqualTo("spa");
}
@Test