Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add label attribute support for DASH audio/text #4391

Merged
merged 1 commit into from
Jul 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ public final class Format implements Parcelable {
/** The language, or null if unknown or not applicable. */
public final @Nullable String language;

/**
* The label, or null if unknown or not applicable.
*/
public final String label;

/**
* The Accessibility channel, or {@link #NO_VALUE} if not known or applicable.
*/
Expand All @@ -185,7 +190,7 @@ public static Format createVideoContainerFormat(
return new Format(id, containerMimeType, sampleMimeType, codecs, bitrate, NO_VALUE, width,
height, frameRate, NO_VALUE, NO_VALUE, null, NO_VALUE, null, NO_VALUE, NO_VALUE, NO_VALUE,
NO_VALUE, NO_VALUE, selectionFlags, null, NO_VALUE, OFFSET_SAMPLE_RELATIVE,
initializationData, null, null);
initializationData, null, null, null);
}

public static Format createVideoSampleFormat(
Expand Down Expand Up @@ -240,7 +245,7 @@ public static Format createVideoSampleFormat(
return new Format(id, null, sampleMimeType, codecs, bitrate, maxInputSize, width, height,
frameRate, rotationDegrees, pixelWidthHeightRatio, projectionData, stereoMode,
colorInfo, NO_VALUE, NO_VALUE, NO_VALUE, NO_VALUE, NO_VALUE, 0, null, NO_VALUE,
OFFSET_SAMPLE_RELATIVE, initializationData, drmInitData, null);
OFFSET_SAMPLE_RELATIVE, initializationData, drmInitData, null, null);
}

// Audio.
Expand All @@ -255,11 +260,12 @@ public static Format createAudioContainerFormat(
int sampleRate,
List<byte[]> initializationData,
@C.SelectionFlags int selectionFlags,
@Nullable String language) {
@Nullable String language,
@Nullable String label) {
return new Format(id, containerMimeType, sampleMimeType, codecs, bitrate, NO_VALUE, NO_VALUE,
NO_VALUE, NO_VALUE, NO_VALUE, NO_VALUE, null, NO_VALUE, null, channelCount, sampleRate,
NO_VALUE, NO_VALUE, NO_VALUE, selectionFlags, language, NO_VALUE, OFFSET_SAMPLE_RELATIVE,
initializationData, null, null);
initializationData, null, null, label);
}

public static Format createAudioSampleFormat(
Expand Down Expand Up @@ -315,7 +321,7 @@ public static Format createAudioSampleFormat(
return new Format(id, null, sampleMimeType, codecs, bitrate, maxInputSize, NO_VALUE, NO_VALUE,
NO_VALUE, NO_VALUE, NO_VALUE, null, NO_VALUE, null, channelCount, sampleRate, pcmEncoding,
encoderDelay, encoderPadding, selectionFlags, language, NO_VALUE, OFFSET_SAMPLE_RELATIVE,
initializationData, drmInitData, metadata);
initializationData, drmInitData, metadata, null);
}

// Text.
Expand All @@ -327,9 +333,10 @@ public static Format createTextContainerFormat(
@Nullable String codecs,
int bitrate,
@C.SelectionFlags int selectionFlags,
@Nullable String language) {
@Nullable String language,
@Nullable String label) {
return createTextContainerFormat(id, containerMimeType, sampleMimeType, codecs, bitrate,
selectionFlags, language, NO_VALUE);
selectionFlags, language, NO_VALUE, label);
}

public static Format createTextContainerFormat(
Expand All @@ -340,11 +347,13 @@ public static Format createTextContainerFormat(
int bitrate,
@C.SelectionFlags int selectionFlags,
@Nullable String language,
int accessibilityChannel) {
int accessibilityChannel,
@Nullable String label
) {
return new Format(id, containerMimeType, sampleMimeType, codecs, bitrate, NO_VALUE, NO_VALUE,
NO_VALUE, NO_VALUE, NO_VALUE, NO_VALUE, null, NO_VALUE, null, NO_VALUE, NO_VALUE,
NO_VALUE, NO_VALUE, NO_VALUE, selectionFlags, language, accessibilityChannel,
OFFSET_SAMPLE_RELATIVE, null, null, null);
OFFSET_SAMPLE_RELATIVE, null, null, null, label);
}

public static Format createTextSampleFormat(
Expand Down Expand Up @@ -405,7 +414,7 @@ public static Format createTextSampleFormat(
return new Format(id, null, sampleMimeType, codecs, bitrate, NO_VALUE, NO_VALUE, NO_VALUE,
NO_VALUE, NO_VALUE, NO_VALUE, null, NO_VALUE, null, NO_VALUE, NO_VALUE, NO_VALUE, NO_VALUE,
NO_VALUE, selectionFlags, language, accessibilityChannel, subsampleOffsetUs,
initializationData, drmInitData, null);
initializationData, drmInitData, null, null);
}

// Image.
Expand Down Expand Up @@ -445,7 +454,8 @@ public static Format createImageSampleFormat(
OFFSET_SAMPLE_RELATIVE,
initializationData,
drmInitData,
null);
null,
null);
}

// Generic.
Expand All @@ -461,14 +471,14 @@ public static Format createContainerFormat(
return new Format(id, containerMimeType, sampleMimeType, codecs, bitrate, NO_VALUE, NO_VALUE,
NO_VALUE, NO_VALUE, NO_VALUE, NO_VALUE, null, NO_VALUE, null, NO_VALUE, NO_VALUE, NO_VALUE,
NO_VALUE, NO_VALUE, selectionFlags, language, NO_VALUE, OFFSET_SAMPLE_RELATIVE, null, null,
null);
null, null);
}

public static Format createSampleFormat(
@Nullable String id, @Nullable String sampleMimeType, long subsampleOffsetUs) {
return new Format(id, null, sampleMimeType, null, NO_VALUE, NO_VALUE, NO_VALUE, NO_VALUE,
NO_VALUE, NO_VALUE, NO_VALUE, null, NO_VALUE, null, NO_VALUE, NO_VALUE, NO_VALUE, NO_VALUE,
NO_VALUE, 0, null, NO_VALUE, subsampleOffsetUs, null, null, null);
NO_VALUE, 0, null, NO_VALUE, subsampleOffsetUs, null, null, null, null);
}

public static Format createSampleFormat(
Expand All @@ -479,7 +489,7 @@ public static Format createSampleFormat(
@Nullable DrmInitData drmInitData) {
return new Format(id, null, sampleMimeType, codecs, bitrate, NO_VALUE, NO_VALUE, NO_VALUE,
NO_VALUE, NO_VALUE, NO_VALUE, null, NO_VALUE, null, NO_VALUE, NO_VALUE, NO_VALUE, NO_VALUE,
NO_VALUE, 0, null, NO_VALUE, OFFSET_SAMPLE_RELATIVE, null, drmInitData, null);
NO_VALUE, 0, null, NO_VALUE, OFFSET_SAMPLE_RELATIVE, null, drmInitData, null, null);
}

/* package */ Format(
Expand Down Expand Up @@ -508,7 +518,9 @@ public static Format createSampleFormat(
long subsampleOffsetUs,
@Nullable List<byte[]> initializationData,
@Nullable DrmInitData drmInitData,
@Nullable Metadata metadata) {
@Nullable Metadata metadata,
@Nullable String label
) {
this.id = id;
this.containerMimeType = containerMimeType;
this.sampleMimeType = sampleMimeType;
Expand All @@ -531,6 +543,7 @@ public static Format createSampleFormat(
this.encoderPadding = encoderPadding == Format.NO_VALUE ? 0 : encoderPadding;
this.selectionFlags = selectionFlags;
this.language = language;
this.label = label;
this.accessibilityChannel = accessibilityChannel;
this.subsampleOffsetUs = subsampleOffsetUs;
this.initializationData = initializationData == null ? Collections.<byte[]>emptyList()
Expand Down Expand Up @@ -563,6 +576,7 @@ public static Format createSampleFormat(
encoderPadding = in.readInt();
selectionFlags = in.readInt();
language = in.readString();
label = in.readString();
accessibilityChannel = in.readInt();
subsampleOffsetUs = in.readLong();
int initializationDataSize = in.readInt();
Expand All @@ -579,15 +593,15 @@ public Format copyWithMaxInputSize(int maxInputSize) {
height, frameRate, rotationDegrees, pixelWidthHeightRatio, projectionData, stereoMode,
colorInfo, channelCount, sampleRate, pcmEncoding, encoderDelay, encoderPadding,
selectionFlags, language, accessibilityChannel, subsampleOffsetUs, initializationData,
drmInitData, metadata);
drmInitData, metadata, label);
}

public Format copyWithSubsampleOffsetUs(long subsampleOffsetUs) {
return new Format(id, containerMimeType, sampleMimeType, codecs, bitrate, maxInputSize, width,
height, frameRate, rotationDegrees, pixelWidthHeightRatio, projectionData, stereoMode,
colorInfo, channelCount, sampleRate, pcmEncoding, encoderDelay, encoderPadding,
selectionFlags, language, accessibilityChannel, subsampleOffsetUs, initializationData,
drmInitData, metadata);
drmInitData, metadata, label);
}

public Format copyWithContainerInfo(
Expand All @@ -603,7 +617,7 @@ public Format copyWithContainerInfo(
height, frameRate, rotationDegrees, pixelWidthHeightRatio, projectionData, stereoMode,
colorInfo, channelCount, sampleRate, pcmEncoding, encoderDelay, encoderPadding,
selectionFlags, language, accessibilityChannel, subsampleOffsetUs, initializationData,
drmInitData, metadata);
drmInitData, metadata, label);
}

@SuppressWarnings("ReferenceEquality")
Expand All @@ -618,45 +632,46 @@ public Format copyWithManifestFormatInfo(Format manifestFormat) {
float frameRate = this.frameRate == NO_VALUE ? manifestFormat.frameRate : this.frameRate;
@C.SelectionFlags int selectionFlags = this.selectionFlags | manifestFormat.selectionFlags;
String language = this.language == null ? manifestFormat.language : this.language;
DrmInitData drmInitData =
DrmInitData.createSessionCreationData(manifestFormat.drmInitData, this.drmInitData);
String label = this.label == null ? manifestFormat.label : this.label;
DrmInitData drmInitData =
DrmInitData.createSessionCreationData(manifestFormat.drmInitData, this.drmInitData);
return new Format(id, containerMimeType, sampleMimeType, codecs, bitrate, maxInputSize, width,
height, frameRate, rotationDegrees, pixelWidthHeightRatio, projectionData, stereoMode,
colorInfo, channelCount, sampleRate, pcmEncoding, encoderDelay, encoderPadding,
selectionFlags, language, accessibilityChannel, subsampleOffsetUs, initializationData,
drmInitData, metadata);
drmInitData, metadata, label);
}

public Format copyWithGaplessInfo(int encoderDelay, int encoderPadding) {
return new Format(id, containerMimeType, sampleMimeType, codecs, bitrate, maxInputSize, width,
height, frameRate, rotationDegrees, pixelWidthHeightRatio, projectionData, stereoMode,
colorInfo, channelCount, sampleRate, pcmEncoding, encoderDelay, encoderPadding,
selectionFlags, language, accessibilityChannel, subsampleOffsetUs, initializationData,
drmInitData, metadata);
drmInitData, metadata, label);
}

public Format copyWithDrmInitData(@Nullable DrmInitData drmInitData) {
return new Format(id, containerMimeType, sampleMimeType, codecs, bitrate, maxInputSize, width,
height, frameRate, rotationDegrees, pixelWidthHeightRatio, projectionData, stereoMode,
colorInfo, channelCount, sampleRate, pcmEncoding, encoderDelay, encoderPadding,
selectionFlags, language, accessibilityChannel, subsampleOffsetUs, initializationData,
drmInitData, metadata);
drmInitData, metadata, label);
}

public Format copyWithMetadata(@Nullable Metadata metadata) {
return new Format(id, containerMimeType, sampleMimeType, codecs, bitrate, maxInputSize, width,
height, frameRate, rotationDegrees, pixelWidthHeightRatio, projectionData, stereoMode,
colorInfo, channelCount, sampleRate, pcmEncoding, encoderDelay, encoderPadding,
selectionFlags, language, accessibilityChannel, subsampleOffsetUs, initializationData,
drmInitData, metadata);
drmInitData, metadata, label);
}

public Format copyWithRotationDegrees(int rotationDegrees) {
return new Format(id, containerMimeType, sampleMimeType, codecs, bitrate, maxInputSize, width,
height, frameRate, rotationDegrees, pixelWidthHeightRatio, projectionData, stereoMode,
colorInfo, channelCount, sampleRate, pcmEncoding, encoderDelay, encoderPadding,
selectionFlags, language, accessibilityChannel, subsampleOffsetUs, initializationData,
drmInitData, metadata);
drmInitData, metadata, label);
}

/**
Expand Down Expand Up @@ -782,6 +797,9 @@ public static String toLogString(Format format) {
if (format.language != null) {
builder.append(", language=").append(format.language);
}
if (format.label != null) {
builder.append(", label=").append(format.label);
}
return builder.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ protected AdaptationSet parseAdaptationSet(XmlPullParser xpp, String baseUrl,
int audioSamplingRate = parseInt(xpp, "audioSamplingRate", Format.NO_VALUE);
String language = xpp.getAttributeValue(null, "lang");
String drmSchemeType = null;
String label = xpp.getAttributeValue(null, "label");
ArrayList<SchemeData> drmSchemeDatas = new ArrayList<>();
ArrayList<Descriptor> inbandEventStreams = new ArrayList<>();
ArrayList<Descriptor> accessibilityDescriptors = new ArrayList<>();
Expand Down Expand Up @@ -285,7 +286,7 @@ protected AdaptationSet parseAdaptationSet(XmlPullParser xpp, String baseUrl,
} else if (XmlPullParserUtil.isStartTag(xpp, "Representation")) {
RepresentationInfo representationInfo = parseRepresentation(xpp, baseUrl, mimeType, codecs,
width, height, frameRate, audioChannels, audioSamplingRate, language,
selectionFlags, accessibilityDescriptors, segmentBase);
selectionFlags, accessibilityDescriptors, segmentBase, label);
contentType = checkContentTypeConsistency(contentType,
getContentType(representationInfo.format));
representationInfos.add(representationInfo);
Expand Down Expand Up @@ -451,7 +452,7 @@ protected RepresentationInfo parseRepresentation(XmlPullParser xpp, String baseU
int adaptationSetHeight, float adaptationSetFrameRate, int adaptationSetAudioChannels,
int adaptationSetAudioSamplingRate, String adaptationSetLanguage,
@C.SelectionFlags int adaptationSetSelectionFlags,
List<Descriptor> adaptationSetAccessibilityDescriptors, SegmentBase segmentBase)
List<Descriptor> adaptationSetAccessibilityDescriptors, SegmentBase segmentBase, String label)
throws XmlPullParserException, IOException {
String id = xpp.getAttributeValue(null, "id");
int bandwidth = parseInt(xpp, "bandwidth", Format.NO_VALUE);
Expand Down Expand Up @@ -501,7 +502,7 @@ protected RepresentationInfo parseRepresentation(XmlPullParser xpp, String baseU

Format format = buildFormat(id, mimeType, width, height, frameRate, audioChannels,
audioSamplingRate, bandwidth, adaptationSetLanguage, adaptationSetSelectionFlags,
adaptationSetAccessibilityDescriptors, codecs, supplementalProperties);
adaptationSetAccessibilityDescriptors, codecs, supplementalProperties, label);
segmentBase = segmentBase != null ? segmentBase : new SingleSegmentBase();

return new RepresentationInfo(format, baseUrl, segmentBase, drmSchemeType, drmSchemeDatas,
Expand All @@ -511,7 +512,7 @@ protected RepresentationInfo parseRepresentation(XmlPullParser xpp, String baseU
protected Format buildFormat(String id, String containerMimeType, int width, int height,
float frameRate, int audioChannels, int audioSamplingRate, int bitrate, String language,
@C.SelectionFlags int selectionFlags, List<Descriptor> accessibilityDescriptors,
String codecs, List<Descriptor> supplementalProperties) {
String codecs, List<Descriptor> supplementalProperties, String label) {
String sampleMimeType = getSampleMimeType(containerMimeType, codecs);
if (sampleMimeType != null) {
if (MimeTypes.AUDIO_E_AC3.equals(sampleMimeType)) {
Expand All @@ -522,7 +523,7 @@ protected Format buildFormat(String id, String containerMimeType, int width, int
bitrate, width, height, frameRate, null, selectionFlags);
} else if (MimeTypes.isAudio(sampleMimeType)) {
return Format.createAudioContainerFormat(id, containerMimeType, sampleMimeType, codecs,
bitrate, audioChannels, audioSamplingRate, null, selectionFlags, language);
bitrate, audioChannels, audioSamplingRate, null, selectionFlags, language, label);
} else if (mimeTypeIsRawText(sampleMimeType)) {
int accessibilityChannel;
if (MimeTypes.APPLICATION_CEA608.equals(sampleMimeType)) {
Expand All @@ -533,7 +534,7 @@ protected Format buildFormat(String id, String containerMimeType, int width, int
accessibilityChannel = Format.NO_VALUE;
}
return Format.createTextContainerFormat(id, containerMimeType, sampleMimeType, codecs,
bitrate, selectionFlags, language, accessibilityChannel);
bitrate, selectionFlags, language, accessibilityChannel, label);
}
}
return Format.createContainerFormat(id, containerMimeType, sampleMimeType, codecs, bitrate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ private static HlsMasterPlaylist parseMasterPlaylist(LineIterator iterator, Stri
String sampleMimeType = codecs != null ? MimeTypes.getMediaMimeType(codecs) : null;
format = Format.createAudioContainerFormat(id, MimeTypes.APPLICATION_M3U8, sampleMimeType,
codecs, Format.NO_VALUE, Format.NO_VALUE, Format.NO_VALUE, null, selectionFlags,
language);
language, id);
if (uri == null) {
muxedAudioFormat = format;
} else {
Expand All @@ -297,7 +297,7 @@ private static HlsMasterPlaylist parseMasterPlaylist(LineIterator iterator, Stri
break;
case TYPE_SUBTITLES:
format = Format.createTextContainerFormat(id, MimeTypes.APPLICATION_M3U8,
MimeTypes.TEXT_VTT, null, Format.NO_VALUE, selectionFlags, language);
MimeTypes.TEXT_VTT, null, Format.NO_VALUE, selectionFlags, language, id);
subtitles.add(new HlsMasterPlaylist.HlsUrl(uri, format));
break;
case TYPE_CLOSED_CAPTIONS:
Expand All @@ -315,7 +315,7 @@ private static HlsMasterPlaylist parseMasterPlaylist(LineIterator iterator, Stri
muxedCaptionFormats = new ArrayList<>();
}
muxedCaptionFormats.add(Format.createTextContainerFormat(id, null, mimeType, null,
Format.NO_VALUE, selectionFlags, language, accessibilityChannel));
Format.NO_VALUE, selectionFlags, language, accessibilityChannel, id));
break;
default:
// Do nothing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ private static class QualityLevelParser extends ElementParser {
private static final String KEY_FOUR_CC = "FourCC";
private static final String KEY_TYPE = "Type";
private static final String KEY_LANGUAGE = "Language";
private static final String KEY_NAME = "Name";
private static final String KEY_MAX_WIDTH = "MaxWidth";
private static final String KEY_MAX_HEIGHT = "MaxHeight";

Expand Down Expand Up @@ -637,12 +638,14 @@ public void parseStartTag(XmlPullParser parser) throws ParserException {
CodecSpecificDataUtil.buildAacLcAudioSpecificConfig(samplingRate, channels));
}
String language = (String) getNormalizedAttribute(KEY_LANGUAGE);
String label = (String) getNormalizedAttribute(KEY_NAME);
format = Format.createAudioContainerFormat(id, MimeTypes.AUDIO_MP4, sampleMimeType, null,
bitrate, channels, samplingRate, codecSpecificData, 0, language);
bitrate, channels, samplingRate, codecSpecificData, 0, language, label);
} else if (type == C.TRACK_TYPE_TEXT) {
String language = (String) getNormalizedAttribute(KEY_LANGUAGE);
String label = (String) getNormalizedAttribute(KEY_NAME);
format = Format.createTextContainerFormat(id, MimeTypes.APPLICATION_MP4, sampleMimeType,
null, bitrate, 0, language);
null, bitrate, 0, language, label);
} else {
format = Format.createContainerFormat(id, MimeTypes.APPLICATION_MP4, sampleMimeType, null,
bitrate, 0, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ private String buildAudioChannelString(Format format) {
}

private String buildLanguageString(Format format) {
if ( !TextUtils.isEmpty(format.label) ){
return format.label;
}
String language = format.language;
return TextUtils.isEmpty(language) || C.LANGUAGE_UNDETERMINED.equals(language)
? ""
Expand Down