From b3277c666b14651023b42eecb3ce5e436d62af33 Mon Sep 17 00:00:00 2001 From: Oliver Woodman Date: Mon, 28 Jul 2014 14:29:21 +0100 Subject: [PATCH] Add language to Format (+other misc fix). --- .../exoplayer/MediaCodecTrackRenderer.java | 16 +++++++++---- .../android/exoplayer/chunk/Format.java | 24 +++++++++++++++++++ .../MediaPresentationDescriptionParser.java | 9 +++---- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer/MediaCodecTrackRenderer.java b/library/src/main/java/com/google/android/exoplayer/MediaCodecTrackRenderer.java index 99a8bee91e..ca9f0f6a80 100644 --- a/library/src/main/java/com/google/android/exoplayer/MediaCodecTrackRenderer.java +++ b/library/src/main/java/com/google/android/exoplayer/MediaCodecTrackRenderer.java @@ -280,14 +280,20 @@ public abstract class MediaCodecTrackRenderer extends TrackRenderer { @Override protected void onDisabled() { - releaseCodec(); format = null; drmInitData = null; - if (openedDrmSession) { - drmSessionManager.close(); - openedDrmSession = false; + try { + releaseCodec(); + } finally { + try { + if (openedDrmSession) { + drmSessionManager.close(); + openedDrmSession = false; + } + } finally { + source.disable(trackIndex); + } } - source.disable(trackIndex); } protected void releaseCodec() { diff --git a/library/src/main/java/com/google/android/exoplayer/chunk/Format.java b/library/src/main/java/com/google/android/exoplayer/chunk/Format.java index 875956c0ee..3482d160fc 100644 --- a/library/src/main/java/com/google/android/exoplayer/chunk/Format.java +++ b/library/src/main/java/com/google/android/exoplayer/chunk/Format.java @@ -71,6 +71,14 @@ public class Format { */ public final int bitrate; + /** + * The language of the format. Can be null if unknown. + *

+ * 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. * @@ -90,6 +98,21 @@ public class Format { */ public Format(String id, String mimeType, int width, int height, int numChannels, 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.mimeType = mimeType; this.width = width; @@ -97,6 +120,7 @@ public class Format { this.numChannels = numChannels; this.audioSamplingRate = audioSamplingRate; this.bitrate = bitrate; + this.language = language; this.bandwidth = bitrate / 8; } diff --git a/library/src/main/java/com/google/android/exoplayer/dash/mpd/MediaPresentationDescriptionParser.java b/library/src/main/java/com/google/android/exoplayer/dash/mpd/MediaPresentationDescriptionParser.java index 3bf9666006..2bd53d998b 100644 --- a/library/src/main/java/com/google/android/exoplayer/dash/mpd/MediaPresentationDescriptionParser.java +++ b/library/src/main/java/com/google/android/exoplayer/dash/mpd/MediaPresentationDescriptionParser.java @@ -140,6 +140,7 @@ public class MediaPresentationDescriptionParser extends DefaultHandler { throws XmlPullParserException, IOException { String mimeType = xpp.getAttributeValue(null, "mimeType"); + String language = xpp.getAttributeValue(null, "lang"); int contentType = parseAdaptationSetTypeFromMimeType(mimeType); int id = -1; @@ -160,7 +161,7 @@ public class MediaPresentationDescriptionParser extends DefaultHandler { parseAdaptationSetType(xpp.getAttributeValue(null, "contentType"))); } else if (isStartTag(xpp, "Representation")) { Representation representation = parseRepresentation(xpp, contentId, baseUrl, periodStartMs, - periodDurationMs, mimeType, segmentBase); + periodDurationMs, mimeType, language, segmentBase); contentType = checkAdaptationSetTypeConsistency(contentType, parseAdaptationSetTypeFromMimeType(representation.format.mimeType)); representations.add(representation); @@ -230,8 +231,8 @@ public class MediaPresentationDescriptionParser extends DefaultHandler { // Representation parsing. private Representation parseRepresentation(XmlPullParser xpp, String contentId, Uri baseUrl, - long periodStartMs, long periodDurationMs, String mimeType, SegmentBase segmentBase) - throws XmlPullParserException, IOException { + long periodStartMs, long periodDurationMs, String mimeType, String language, + SegmentBase segmentBase) throws XmlPullParserException, IOException { String id = xpp.getAttributeValue(null, "id"); int bandwidth = parseInt(xpp, "bandwidth"); int audioSamplingRate = parseInt(xpp, "audioSamplingRate"); @@ -257,7 +258,7 @@ public class MediaPresentationDescriptionParser extends DefaultHandler { } while (!isEndTag(xpp, "Representation")); Format format = new Format(id, mimeType, width, height, numChannels, audioSamplingRate, - bandwidth); + bandwidth, language); return Representation.newInstance(periodStartMs, periodDurationMs, contentId, -1, format, segmentBase); }