mirror of
https://github.com/samsonjs/media.git
synced 2026-04-05 11:15:46 +00:00
Fix Util.inferContentTypeForExtension to handle .ism (smooth streaming)
This method was introduced in 754eb1527a
as a replacement for Util.inferContentType(String) but it incorrectly
didn't return TYPE_SS when passed "ism" or "isml".
PiperOrigin-RevId: 445217167
This commit is contained in:
parent
8da8c5e781
commit
bec9431856
2 changed files with 25 additions and 11 deletions
|
|
@ -158,7 +158,7 @@ public final class Util {
|
|||
|
||||
// https://docs.microsoft.com/en-us/azure/media-services/previous/media-services-deliver-content-overview#URLs
|
||||
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_DASH_FORMAT_EXTENSION = "format=mpd-time-csf";
|
||||
|
||||
|
|
@ -1841,20 +1841,24 @@ public final class Util {
|
|||
return C.TYPE_RTSP;
|
||||
}
|
||||
|
||||
@Nullable String path = uri.getPath();
|
||||
if (path == null) {
|
||||
@Nullable String lastPathSegment = uri.getLastPathSegment();
|
||||
if (lastPathSegment == null) {
|
||||
return C.TYPE_OTHER;
|
||||
}
|
||||
int lastDotIndex = path.lastIndexOf('.');
|
||||
int lastDotIndex = lastPathSegment.lastIndexOf('.');
|
||||
if (lastDotIndex >= 0) {
|
||||
@C.ContentType
|
||||
int contentType = inferContentTypeForExtension(path.substring(lastDotIndex + 1));
|
||||
int contentType = inferContentTypeForExtension(lastPathSegment.substring(lastDotIndex + 1));
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Matcher ismMatcher = ISM_PATH_PATTERN.matcher(path);
|
||||
Matcher ismMatcher = ISM_PATH_PATTERN.matcher(checkNotNull(uri.getPath()));
|
||||
if (ismMatcher.matches()) {
|
||||
@Nullable String extensions = ismMatcher.group(2);
|
||||
if (extensions != null) {
|
||||
|
|
@ -1886,12 +1890,18 @@ public final class Util {
|
|||
* @return The content type.
|
||||
*/
|
||||
public static @ContentType int inferContentTypeForExtension(String fileExtension) {
|
||||
if (Ascii.equalsIgnoreCase("mpd", fileExtension)) {
|
||||
return C.TYPE_DASH;
|
||||
} else if (Ascii.equalsIgnoreCase("m3u8", fileExtension)) {
|
||||
return C.TYPE_HLS;
|
||||
fileExtension = Ascii.toLowerCase(fileExtension);
|
||||
switch (fileExtension) {
|
||||
case "mpd":
|
||||
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 {
|
|||
public void inferContentType_extensionAsPath() {
|
||||
assertThat(Util.inferContentType(".m3u8")).isEqualTo(C.TYPE_HLS);
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -199,6 +201,8 @@ public class UtilTest {
|
|||
public void inferContentTypeForExtension() {
|
||||
assertThat(Util.inferContentTypeForExtension("m3u8")).isEqualTo(C.TYPE_HLS);
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue