Fix / improve format merging

1. Prefer label and language values in the manifest to those in
   the media. This is particularly helpful if the sample format
   contains "und" as the language.
2. Copy label when deriving formats in HlsSampleStreamWrapper
3. When there's only one variant in HlsSampleStreamWrapper, use
   the regular copyWithManifestFormatInfo. This allows more
   information to be retained from the sample format.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=204340008
This commit is contained in:
olly 2018-07-12 12:06:40 -07:00 committed by Oliver Woodman
parent a26bb350ee
commit 18ab4b9112
3 changed files with 26 additions and 9 deletions

View File

@ -1041,6 +1041,7 @@ public final class Format implements Parcelable {
public Format copyWithContainerInfo( public Format copyWithContainerInfo(
@Nullable String id, @Nullable String id,
@Nullable String label,
@Nullable String sampleMimeType, @Nullable String sampleMimeType,
@Nullable String codecs, @Nullable String codecs,
int bitrate, int bitrate,
@ -1084,15 +1085,21 @@ public final class Format implements Parcelable {
// No need to copy from ourselves. // No need to copy from ourselves.
return this; return this;
} }
// Use manifest value only.
String id = manifestFormat.id; String id = manifestFormat.id;
// Prefer manifest values, but fill in from sample format if missing.
String label = manifestFormat.label != null ? manifestFormat.label : this.label;
String language = manifestFormat.language != null ? manifestFormat.language : this.language;
// Prefer sample format values, but fill in from manifest if missing.
String codecs = this.codecs == null ? manifestFormat.codecs : this.codecs; String codecs = this.codecs == null ? manifestFormat.codecs : this.codecs;
int bitrate = this.bitrate == NO_VALUE ? manifestFormat.bitrate : this.bitrate; int bitrate = this.bitrate == NO_VALUE ? manifestFormat.bitrate : this.bitrate;
float frameRate = this.frameRate == NO_VALUE ? manifestFormat.frameRate : this.frameRate; float frameRate = this.frameRate == NO_VALUE ? manifestFormat.frameRate : this.frameRate;
@C.SelectionFlags int selectionFlags = this.selectionFlags | manifestFormat.selectionFlags; // Merge manifest and sample format values.
String language = this.language == null ? manifestFormat.language : this.language; @C.SelectionFlags int selectionFlags = this.selectionFlags | manifestFormat.selectionFlags;
String label = this.label == null ? manifestFormat.label : this.label;
DrmInitData drmInitData = DrmInitData drmInitData =
DrmInitData.createSessionCreationData(manifestFormat.drmInitData, this.drmInitData); DrmInitData.createSessionCreationData(manifestFormat.drmInitData, this.drmInitData);
return new Format( return new Format(
id, id,
label, label,

View File

@ -948,8 +948,12 @@ import java.util.List;
Format sampleFormat = sampleQueues[i].getUpstreamFormat(); Format sampleFormat = sampleQueues[i].getUpstreamFormat();
if (i == primaryExtractorTrackIndex) { if (i == primaryExtractorTrackIndex) {
Format[] formats = new Format[chunkSourceTrackCount]; Format[] formats = new Format[chunkSourceTrackCount];
for (int j = 0; j < chunkSourceTrackCount; j++) { if (chunkSourceTrackCount == 1) {
formats[j] = deriveFormat(chunkSourceTrackGroup.getFormat(j), sampleFormat, true); formats[0] = sampleFormat.copyWithManifestFormatInfo(chunkSourceTrackGroup.getFormat(0));
} else {
for (int j = 0; j < chunkSourceTrackCount; j++) {
formats[j] = deriveFormat(chunkSourceTrackGroup.getFormat(j), sampleFormat, true);
}
} }
trackGroups[i] = new TrackGroup(formats); trackGroups[i] = new TrackGroup(formats);
primaryTrackGroupIndex = i; primaryTrackGroupIndex = i;
@ -997,7 +1001,8 @@ import java.util.List;
} }
/** /**
* Derives a track format using master playlist and sample format information. * Derives a track sample format from the corresponding format in the master playlist, and a
* sample format that may have been obtained from a chunk belonging to a different track.
* *
* @param playlistFormat The format information obtained from the master playlist. * @param playlistFormat The format information obtained from the master playlist.
* @param sampleFormat The format information obtained from the samples. * @param sampleFormat The format information obtained from the samples.
@ -1019,6 +1024,7 @@ import java.util.List;
} }
return sampleFormat.copyWithContainerInfo( return sampleFormat.copyWithContainerInfo(
playlistFormat.id, playlistFormat.id,
playlistFormat.label,
mimeType, mimeType,
codecs, codecs,
bitrate, bitrate,

View File

@ -43,11 +43,11 @@ public class DefaultTrackNameProvider implements TrackNameProvider {
} else if (trackType == C.TRACK_TYPE_AUDIO) { } else if (trackType == C.TRACK_TYPE_AUDIO) {
trackName = trackName =
joinWithSeparator( joinWithSeparator(
buildLanguageString(format), buildLabelString(format),
buildAudioChannelString(format), buildAudioChannelString(format),
buildBitrateString(format)); buildBitrateString(format));
} else { } else {
trackName = buildLanguageString(format); trackName = buildLabelString(format);
} }
return trackName.length() == 0 ? resources.getString(R.string.exo_track_unknown) : trackName; return trackName.length() == 0 ? resources.getString(R.string.exo_track_unknown) : trackName;
} }
@ -87,7 +87,11 @@ public class DefaultTrackNameProvider implements TrackNameProvider {
} }
} }
private String buildLanguageString(Format format) { private String buildLabelString(Format format) {
if (!TextUtils.isEmpty(format.label)) {
return format.label;
}
// Fall back to using the language.
String language = format.language; String language = format.language;
return TextUtils.isEmpty(language) || C.LANGUAGE_UNDETERMINED.equals(language) return TextUtils.isEmpty(language) || C.LANGUAGE_UNDETERMINED.equals(language)
? "" ? ""