Skip to content

Commit

Permalink
Ensure normalized language code is used everywhere and update documen…
Browse files Browse the repository at this point in the history
…tation.

Issue:#2867
PiperOrigin-RevId: 231385677
  • Loading branch information
tonihei authored and ojw28 committed Jan 29, 2019
1 parent 6983f92 commit ef8335f
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,7 @@ private 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";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -932,7 +932,7 @@ public static Format createSampleFormat(
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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ final class DvbSubtitleInfo {
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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ public void addTrackSelection(
* 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();
Expand Down Expand Up @@ -524,7 +524,7 @@ public void addAudioLanguagesToSelection(String... languages) {
* 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ public ParametersBuilder setViewportSize(
/**
* 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) {
Expand Down Expand Up @@ -430,6 +432,8 @@ public ParametersBuilder setAllowAudioMixedSampleRateAdaptiveness(
/**
* 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) {
Expand Down Expand Up @@ -2313,8 +2317,7 @@ protected static boolean formatHasNoLanguage(Format format) {
* 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,10 @@ public static void writeBoolean(Parcel parcel, boolean value) {
}

/**
* 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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public void testPlaylistWithClosedCaption() throws IOException {
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
Expand Down

0 comments on commit ef8335f

Please sign in to comment.