Commit 18ab4b91 by olly Committed by Oliver Woodman

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
parent a26bb350
...@@ -1041,6 +1041,7 @@ public final class Format implements Parcelable { ...@@ -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 { ...@@ -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;
// Merge manifest and sample format values.
@C.SelectionFlags int selectionFlags = this.selectionFlags | manifestFormat.selectionFlags; @C.SelectionFlags int selectionFlags = this.selectionFlags | manifestFormat.selectionFlags;
String language = this.language == null ? manifestFormat.language : this.language;
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,
......
...@@ -948,9 +948,13 @@ import java.util.List; ...@@ -948,9 +948,13 @@ 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];
if (chunkSourceTrackCount == 1) {
formats[0] = sampleFormat.copyWithManifestFormatInfo(chunkSourceTrackGroup.getFormat(0));
} else {
for (int j = 0; j < chunkSourceTrackCount; j++) { for (int j = 0; j < chunkSourceTrackCount; j++) {
formats[j] = deriveFormat(chunkSourceTrackGroup.getFormat(j), sampleFormat, true); formats[j] = deriveFormat(chunkSourceTrackGroup.getFormat(j), sampleFormat, true);
} }
}
trackGroups[i] = new TrackGroup(formats); trackGroups[i] = new TrackGroup(formats);
primaryTrackGroupIndex = i; primaryTrackGroupIndex = i;
} else { } else {
...@@ -997,7 +1001,8 @@ import java.util.List; ...@@ -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; ...@@ -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,
......
...@@ -43,11 +43,11 @@ public class DefaultTrackNameProvider implements TrackNameProvider { ...@@ -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 { ...@@ -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)
? "" ? ""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment