Skip to content

Commit

Permalink
Merge pull request #4391 from kaltura/add-label
Browse files Browse the repository at this point in the history
Add label attribute support for DASH audio/text
  • Loading branch information
ojw28 authored Jul 12, 2018
2 parents 28bb3ba + cd9041c commit 41636ad
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,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 @@ -183,7 +188,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 @@ -238,7 +243,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 @@ -253,11 +258,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 @@ -313,7 +319,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 @@ -325,9 +331,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 @@ -338,11 +345,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 @@ -403,7 +412,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 @@ -443,7 +452,8 @@ public static Format createImageSampleFormat(
OFFSET_SAMPLE_RELATIVE,
initializationData,
drmInitData,
null);
null,
null);
}

// Generic.
Expand All @@ -459,14 +469,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 @@ -477,7 +487,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 @@ -506,7 +516,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 @@ -529,6 +541,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 @@ -561,6 +574,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 @@ -577,15 +591,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 @@ -601,7 +615,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 @@ -616,45 +630,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 @@ -780,6 +795,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 @@ -457,7 +458,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 @@ -507,7 +508,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 @@ -517,7 +518,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 @@ -528,7 +529,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 @@ -539,7 +540,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 @@ -295,7 +295,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 @@ -304,7 +304,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 @@ -322,7 +322,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

0 comments on commit 41636ad

Please sign in to comment.