Add language to Format (+other misc fix).

This commit is contained in:
Oliver Woodman 2014-07-28 14:29:21 +01:00
parent bb5cfd52c5
commit b3277c666b
3 changed files with 40 additions and 9 deletions

View file

@ -280,14 +280,20 @@ public abstract class MediaCodecTrackRenderer extends TrackRenderer {
@Override @Override
protected void onDisabled() { protected void onDisabled() {
releaseCodec();
format = null; format = null;
drmInitData = null; drmInitData = null;
if (openedDrmSession) { try {
drmSessionManager.close(); releaseCodec();
openedDrmSession = false; } finally {
try {
if (openedDrmSession) {
drmSessionManager.close();
openedDrmSession = false;
}
} finally {
source.disable(trackIndex);
}
} }
source.disable(trackIndex);
} }
protected void releaseCodec() { protected void releaseCodec() {

View file

@ -71,6 +71,14 @@ public class Format {
*/ */
public final int bitrate; public final int bitrate;
/**
* The language of the format. Can be null if unknown.
* <p>
* The language codes are two-letter lowercase ISO language codes (such as "en") as defined by
* ISO 639-1.
*/
public final String language;
/** /**
* The average bandwidth in bytes per second. * The average bandwidth in bytes per second.
* *
@ -90,6 +98,21 @@ public class Format {
*/ */
public Format(String id, String mimeType, int width, int height, int numChannels, public Format(String id, String mimeType, int width, int height, int numChannels,
int audioSamplingRate, int bitrate) { int audioSamplingRate, int bitrate) {
this(id, mimeType, width, height, numChannels, audioSamplingRate, bitrate, null);
}
/**
* @param id The format identifier.
* @param mimeType The format mime type.
* @param width The width of the video in pixels, or -1 for non-video formats.
* @param height The height of the video in pixels, or -1 for non-video formats.
* @param numChannels The number of audio channels, or -1 for non-audio formats.
* @param audioSamplingRate The audio sampling rate in Hz, or -1 for non-audio formats.
* @param bitrate The average bandwidth of the format in bits per second.
* @param language The language of the format.
*/
public Format(String id, String mimeType, int width, int height, int numChannels,
int audioSamplingRate, int bitrate, String language) {
this.id = Assertions.checkNotNull(id); this.id = Assertions.checkNotNull(id);
this.mimeType = mimeType; this.mimeType = mimeType;
this.width = width; this.width = width;
@ -97,6 +120,7 @@ public class Format {
this.numChannels = numChannels; this.numChannels = numChannels;
this.audioSamplingRate = audioSamplingRate; this.audioSamplingRate = audioSamplingRate;
this.bitrate = bitrate; this.bitrate = bitrate;
this.language = language;
this.bandwidth = bitrate / 8; this.bandwidth = bitrate / 8;
} }

View file

@ -140,6 +140,7 @@ public class MediaPresentationDescriptionParser extends DefaultHandler {
throws XmlPullParserException, IOException { throws XmlPullParserException, IOException {
String mimeType = xpp.getAttributeValue(null, "mimeType"); String mimeType = xpp.getAttributeValue(null, "mimeType");
String language = xpp.getAttributeValue(null, "lang");
int contentType = parseAdaptationSetTypeFromMimeType(mimeType); int contentType = parseAdaptationSetTypeFromMimeType(mimeType);
int id = -1; int id = -1;
@ -160,7 +161,7 @@ public class MediaPresentationDescriptionParser extends DefaultHandler {
parseAdaptationSetType(xpp.getAttributeValue(null, "contentType"))); parseAdaptationSetType(xpp.getAttributeValue(null, "contentType")));
} else if (isStartTag(xpp, "Representation")) { } else if (isStartTag(xpp, "Representation")) {
Representation representation = parseRepresentation(xpp, contentId, baseUrl, periodStartMs, Representation representation = parseRepresentation(xpp, contentId, baseUrl, periodStartMs,
periodDurationMs, mimeType, segmentBase); periodDurationMs, mimeType, language, segmentBase);
contentType = checkAdaptationSetTypeConsistency(contentType, contentType = checkAdaptationSetTypeConsistency(contentType,
parseAdaptationSetTypeFromMimeType(representation.format.mimeType)); parseAdaptationSetTypeFromMimeType(representation.format.mimeType));
representations.add(representation); representations.add(representation);
@ -230,8 +231,8 @@ public class MediaPresentationDescriptionParser extends DefaultHandler {
// Representation parsing. // Representation parsing.
private Representation parseRepresentation(XmlPullParser xpp, String contentId, Uri baseUrl, private Representation parseRepresentation(XmlPullParser xpp, String contentId, Uri baseUrl,
long periodStartMs, long periodDurationMs, String mimeType, SegmentBase segmentBase) long periodStartMs, long periodDurationMs, String mimeType, String language,
throws XmlPullParserException, IOException { SegmentBase segmentBase) throws XmlPullParserException, IOException {
String id = xpp.getAttributeValue(null, "id"); String id = xpp.getAttributeValue(null, "id");
int bandwidth = parseInt(xpp, "bandwidth"); int bandwidth = parseInt(xpp, "bandwidth");
int audioSamplingRate = parseInt(xpp, "audioSamplingRate"); int audioSamplingRate = parseInt(xpp, "audioSamplingRate");
@ -257,7 +258,7 @@ public class MediaPresentationDescriptionParser extends DefaultHandler {
} while (!isEndTag(xpp, "Representation")); } while (!isEndTag(xpp, "Representation"));
Format format = new Format(id, mimeType, width, height, numChannels, audioSamplingRate, Format format = new Format(id, mimeType, width, height, numChannels, audioSamplingRate,
bandwidth); bandwidth, language);
return Representation.newInstance(periodStartMs, periodDurationMs, contentId, -1, format, return Representation.newInstance(periodStartMs, periodDurationMs, contentId, -1, format,
segmentBase); segmentBase);
} }