Fixed issue when VOD-style period is present in a dynamic manifest

A VOD-style period in a dynamic manifest would result in a NullPointerException.
Also fix another issue in which an unrecognized mime type would also result in
NullPointerException.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=138075137
This commit is contained in:
cdrolle 2016-11-03 08:47:24 -07:00 committed by Oliver Woodman
parent aaf38adc26
commit d9421f4fb9
3 changed files with 18 additions and 8 deletions

View file

@ -424,12 +424,16 @@ public final class DashMediaSource implements MediaSource {
// not correspond to the start of a segment in both, but this is an edge case. // not correspond to the start of a segment in both, but this is an edge case.
DashSegmentIndex index = DashSegmentIndex index =
period.adaptationSets.get(videoAdaptationSetIndex).representations.get(0).getIndex(); period.adaptationSets.get(videoAdaptationSetIndex).representations.get(0).getIndex();
if (index != null) {
int segmentNum = index.getSegmentNum(defaultStartPositionInPeriodUs, periodDurationUs); int segmentNum = index.getSegmentNum(defaultStartPositionInPeriodUs, periodDurationUs);
windowDefaultStartPositionUs = windowDefaultStartPositionUs =
defaultStartPositionUs - defaultStartPositionInPeriodUs + index.getTimeUs(segmentNum); defaultStartPositionUs - defaultStartPositionInPeriodUs + index.getTimeUs(segmentNum);
} else { } else {
windowDefaultStartPositionUs = defaultStartPositionUs; windowDefaultStartPositionUs = defaultStartPositionUs;
} }
} else {
windowDefaultStartPositionUs = defaultStartPositionUs;
}
} }
long windowStartTimeMs = manifest.availabilityStartTime long windowStartTimeMs = manifest.availabilityStartTime
+ manifest.getPeriod(0).startMs + C.usToMs(currentStartTimeUs); + manifest.getPeriod(0).startMs + C.usToMs(currentStartTimeUs);

View file

@ -81,6 +81,9 @@ public interface SubtitleDecoderFactory {
} }
private Class<?> getDecoderClass(String mimeType) { private Class<?> getDecoderClass(String mimeType) {
if (mimeType == null) {
return null;
}
try { try {
switch (mimeType) { switch (mimeType) {
case MimeTypes.TEXT_VTT: case MimeTypes.TEXT_VTT:

View file

@ -84,7 +84,7 @@ public final class MimeTypes {
* @return Whether the top level type is audio. * @return Whether the top level type is audio.
*/ */
public static boolean isAudio(String mimeType) { public static boolean isAudio(String mimeType) {
return getTopLevelType(mimeType).equals(BASE_TYPE_AUDIO); return BASE_TYPE_AUDIO.equals(getTopLevelType(mimeType));
} }
/** /**
@ -94,7 +94,7 @@ public final class MimeTypes {
* @return Whether the top level type is video. * @return Whether the top level type is video.
*/ */
public static boolean isVideo(String mimeType) { public static boolean isVideo(String mimeType) {
return getTopLevelType(mimeType).equals(BASE_TYPE_VIDEO); return BASE_TYPE_VIDEO.equals(getTopLevelType(mimeType));
} }
/** /**
@ -104,7 +104,7 @@ public final class MimeTypes {
* @return Whether the top level type is text. * @return Whether the top level type is text.
*/ */
public static boolean isText(String mimeType) { public static boolean isText(String mimeType) {
return getTopLevelType(mimeType).equals(BASE_TYPE_TEXT); return BASE_TYPE_TEXT.equals(getTopLevelType(mimeType));
} }
/** /**
@ -114,7 +114,7 @@ public final class MimeTypes {
* @return Whether the top level type is application. * @return Whether the top level type is application.
*/ */
public static boolean isApplication(String mimeType) { public static boolean isApplication(String mimeType) {
return getTopLevelType(mimeType).equals(BASE_TYPE_APPLICATION); return BASE_TYPE_APPLICATION.equals(getTopLevelType(mimeType));
} }
@ -237,9 +237,12 @@ public final class MimeTypes {
* Returns the top-level type of {@code mimeType}. * Returns the top-level type of {@code mimeType}.
* *
* @param mimeType The mimeType whose top-level type is required. * @param mimeType The mimeType whose top-level type is required.
* @return The top-level type. * @return The top-level type, or null if the mimeType is null.
*/ */
private static String getTopLevelType(String mimeType) { private static String getTopLevelType(String mimeType) {
if (mimeType == null) {
return null;
}
int indexOfSlash = mimeType.indexOf('/'); int indexOfSlash = mimeType.indexOf('/');
if (indexOfSlash == -1) { if (indexOfSlash == -1) {
throw new IllegalArgumentException("Invalid mime type: " + mimeType); throw new IllegalArgumentException("Invalid mime type: " + mimeType);