Commit bec94318 by ibaker Committed by Ian Baker

Fix Util.inferContentTypeForExtension to handle .ism (smooth streaming)

This method was introduced in https://github.com/google/ExoPlayer/commit/754eb1527af9ff4211b7e164d2af6b46530f328c
as a replacement for Util.inferContentType(String) but it incorrectly
didn't return TYPE_SS when passed "ism" or "isml".

PiperOrigin-RevId: 445217167
parent 8da8c5e7
...@@ -158,7 +158,7 @@ public final class Util { ...@@ -158,7 +158,7 @@ public final class Util {
// https://docs.microsoft.com/en-us/azure/media-services/previous/media-services-deliver-content-overview#URLs // https://docs.microsoft.com/en-us/azure/media-services/previous/media-services-deliver-content-overview#URLs
private static final Pattern ISM_PATH_PATTERN = private static final Pattern ISM_PATH_PATTERN =
Pattern.compile(".*\\.isml?(?:/(manifest(.*))?)?", Pattern.CASE_INSENSITIVE); Pattern.compile("(?:.*\\.)?isml?(?:/(manifest(.*))?)?", Pattern.CASE_INSENSITIVE);
private static final String ISM_HLS_FORMAT_EXTENSION = "format=m3u8-aapl"; private static final String ISM_HLS_FORMAT_EXTENSION = "format=m3u8-aapl";
private static final String ISM_DASH_FORMAT_EXTENSION = "format=mpd-time-csf"; private static final String ISM_DASH_FORMAT_EXTENSION = "format=mpd-time-csf";
...@@ -1841,20 +1841,24 @@ public final class Util { ...@@ -1841,20 +1841,24 @@ public final class Util {
return C.TYPE_RTSP; return C.TYPE_RTSP;
} }
@Nullable String path = uri.getPath(); @Nullable String lastPathSegment = uri.getLastPathSegment();
if (path == null) { if (lastPathSegment == null) {
return C.TYPE_OTHER; return C.TYPE_OTHER;
} }
int lastDotIndex = path.lastIndexOf('.'); int lastDotIndex = lastPathSegment.lastIndexOf('.');
if (lastDotIndex >= 0) { if (lastDotIndex >= 0) {
@C.ContentType @C.ContentType
int contentType = inferContentTypeForExtension(path.substring(lastDotIndex + 1)); int contentType = inferContentTypeForExtension(lastPathSegment.substring(lastDotIndex + 1));
if (contentType != C.TYPE_OTHER) { if (contentType != C.TYPE_OTHER) {
// If contentType is TYPE_SS that indicates the extension is .ism or .isml and shows the ISM
// URI is missing the "/manifest" suffix, which contains the information used to
// disambiguate between Smooth Streaming, HLS and DASH below - so we can just return TYPE_SS
// here without further checks.
return contentType; return contentType;
} }
} }
Matcher ismMatcher = ISM_PATH_PATTERN.matcher(path); Matcher ismMatcher = ISM_PATH_PATTERN.matcher(checkNotNull(uri.getPath()));
if (ismMatcher.matches()) { if (ismMatcher.matches()) {
@Nullable String extensions = ismMatcher.group(2); @Nullable String extensions = ismMatcher.group(2);
if (extensions != null) { if (extensions != null) {
...@@ -1886,12 +1890,18 @@ public final class Util { ...@@ -1886,12 +1890,18 @@ public final class Util {
* @return The content type. * @return The content type.
*/ */
public static @ContentType int inferContentTypeForExtension(String fileExtension) { public static @ContentType int inferContentTypeForExtension(String fileExtension) {
if (Ascii.equalsIgnoreCase("mpd", fileExtension)) { fileExtension = Ascii.toLowerCase(fileExtension);
return C.TYPE_DASH; switch (fileExtension) {
} else if (Ascii.equalsIgnoreCase("m3u8", fileExtension)) { case "mpd":
return C.TYPE_HLS; return C.TYPE_DASH;
case "m3u8":
return C.TYPE_HLS;
case "ism":
case "isml":
return C.TYPE_SS;
default:
return C.TYPE_OTHER;
} }
return C.TYPE_OTHER;
} }
/** /**
......
...@@ -174,6 +174,8 @@ public class UtilTest { ...@@ -174,6 +174,8 @@ public class UtilTest {
public void inferContentType_extensionAsPath() { public void inferContentType_extensionAsPath() {
assertThat(Util.inferContentType(".m3u8")).isEqualTo(C.TYPE_HLS); assertThat(Util.inferContentType(".m3u8")).isEqualTo(C.TYPE_HLS);
assertThat(Util.inferContentType(".mpd")).isEqualTo(C.TYPE_DASH); assertThat(Util.inferContentType(".mpd")).isEqualTo(C.TYPE_DASH);
assertThat(Util.inferContentType(".ism")).isEqualTo(C.TYPE_SS);
assertThat(Util.inferContentType(".isml")).isEqualTo(C.TYPE_SS);
assertThat(Util.inferContentType(".mp4")).isEqualTo(C.TYPE_OTHER); assertThat(Util.inferContentType(".mp4")).isEqualTo(C.TYPE_OTHER);
} }
...@@ -199,6 +201,8 @@ public class UtilTest { ...@@ -199,6 +201,8 @@ public class UtilTest {
public void inferContentTypeForExtension() { public void inferContentTypeForExtension() {
assertThat(Util.inferContentTypeForExtension("m3u8")).isEqualTo(C.TYPE_HLS); assertThat(Util.inferContentTypeForExtension("m3u8")).isEqualTo(C.TYPE_HLS);
assertThat(Util.inferContentTypeForExtension("mpd")).isEqualTo(C.TYPE_DASH); assertThat(Util.inferContentTypeForExtension("mpd")).isEqualTo(C.TYPE_DASH);
assertThat(Util.inferContentTypeForExtension("ism")).isEqualTo(C.TYPE_SS);
assertThat(Util.inferContentTypeForExtension("isml")).isEqualTo(C.TYPE_SS);
assertThat(Util.inferContentTypeForExtension("mp4")).isEqualTo(C.TYPE_OTHER); assertThat(Util.inferContentTypeForExtension("mp4")).isEqualTo(C.TYPE_OTHER);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment