Commit e2059eab by olly Committed by Oliver Woodman

Enhance copyWithManifestFormatInfo to handle muxed manifest formats

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=204470264
parent 450448b2
......@@ -1086,15 +1086,35 @@ public final class Format implements Parcelable {
return this;
}
int trackType = MimeTypes.getTrackType(sampleMimeType);
// Use manifest value only.
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;
String language = this.language;
if ((trackType == C.TRACK_TYPE_TEXT || trackType == C.TRACK_TYPE_AUDIO)
&& manifestFormat.language != null) {
language = manifestFormat.language;
}
// Prefer sample format values, but fill in from manifest if missing.
String codecs = this.codecs == null ? manifestFormat.codecs : this.codecs;
int bitrate = this.bitrate == NO_VALUE ? manifestFormat.bitrate : this.bitrate;
float frameRate = this.frameRate == NO_VALUE ? manifestFormat.frameRate : this.frameRate;
String codecs = this.codecs;
if (codecs == null) {
// The manifest format may be muxed, so filter only codecs of this format's type. If we still
// have more than one codec then we're unable to uniquely identify which codec to fill in.
String codecsOfType = Util.getCodecsOfType(manifestFormat.codecs, trackType);
if (Util.splitCodecs(codecsOfType).length == 1) {
codecs = codecsOfType;
}
}
float frameRate = this.frameRate;
if (frameRate == NO_VALUE && trackType == C.TRACK_TYPE_VIDEO) {
frameRate = manifestFormat.frameRate;
}
// Merge manifest and sample format values.
@C.SelectionFlags int selectionFlags = this.selectionFlags | manifestFormat.selectionFlags;
DrmInitData drmInitData =
......@@ -1273,6 +1293,8 @@ public final class Format implements Parcelable {
+ ", "
+ sampleMimeType
+ ", "
+ codecs
+ ", "
+ bitrate
+ ", "
+ language
......@@ -1384,6 +1406,9 @@ public final class Format implements Parcelable {
if (format.bitrate != Format.NO_VALUE) {
builder.append(", bitrate=").append(format.bitrate);
}
if (format.codecs != null) {
builder.append(", codecs=").append(format.codecs);
}
if (format.width != Format.NO_VALUE && format.height != Format.NO_VALUE) {
builder.append(", res=").append(format.width).append("x").append(format.height);
}
......
......@@ -167,7 +167,7 @@ public final class MimeTypes {
if (codecs == null) {
return null;
}
String[] codecList = Util.split(codecs, ",");
String[] codecList = Util.splitCodecs(codecs);
for (String codec : codecList) {
String mimeType = getMediaMimeType(codec);
if (mimeType != null && isVideo(mimeType)) {
......@@ -187,7 +187,7 @@ public final class MimeTypes {
if (codecs == null) {
return null;
}
String[] codecList = Util.split(codecs, ",");
String[] codecList = Util.splitCodecs(codecs);
for (String codec : codecList) {
String mimeType = getMediaMimeType(codec);
if (mimeType != null && isAudio(mimeType)) {
......
......@@ -1062,10 +1062,10 @@ public final class Util {
* {@code trackType}.
*/
public static String getCodecsOfType(String codecs, int trackType) {
if (TextUtils.isEmpty(codecs)) {
String[] codecArray = splitCodecs(codecs);
if (codecArray.length == 0) {
return null;
}
String[] codecArray = split(codecs.trim(), "(\\s*,\\s*)");
StringBuilder builder = new StringBuilder();
for (String codec : codecArray) {
if (trackType == MimeTypes.getTrackTypeOfCodec(codec)) {
......@@ -1079,6 +1079,19 @@ public final class Util {
}
/**
* Splits a codecs sequence string, as defined in RFC 6381, into individual codec strings.
*
* @param codecs A codec sequence string, as defined in RFC 6381.
* @return The split codecs, or an array of length zero if the input was empty.
*/
public static String[] splitCodecs(String codecs) {
if (TextUtils.isEmpty(codecs)) {
return new String[0];
}
return split(codecs.trim(), "(\\s*,\\s*)");
}
/**
* Converts a sample bit depth to a corresponding PCM encoding constant.
*
* @param bitDepth The bit depth. Supported values are 8, 16, 24 and 32.
......
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