mirror of
https://github.com/samsonjs/media.git
synced 2026-04-02 10:45:51 +00:00
Fix handling of widths/heights when choosing formats.
- Make HlsPlaylistParser treat non-positive dimensions as unknown. - Make HlsPlaylistParser parse floating point resolutions, because technically that's how they're spec'd. - Make VideoFormatSelectorUtil treat non-position dimensions as unknown. Issue: #461
This commit is contained in:
parent
059b80c1ab
commit
f474afbf5e
3 changed files with 16 additions and 8 deletions
|
|
@ -108,7 +108,7 @@ public final class VideoFormatSelectorUtil {
|
|||
// Keep track of the number of pixels of the selected format whose resolution is the
|
||||
// smallest to exceed the maximum size at which it can be displayed within the viewport.
|
||||
// We'll discard formats of higher resolution in a second pass.
|
||||
if (format.width != -1 && format.height != -1) {
|
||||
if (format.width > 0 && format.height > 0) {
|
||||
Point maxVideoSizeInViewport = getMaxVideoSizeInViewport(orientationMayChange,
|
||||
viewportWidth, viewportHeight, format.width, format.height);
|
||||
int videoPixels = format.width * format.height;
|
||||
|
|
@ -126,7 +126,7 @@ public final class VideoFormatSelectorUtil {
|
|||
// viewport.
|
||||
for (int i = selectedIndexList.size() - 1; i >= 0; i--) {
|
||||
Format format = formatWrappers.get(i).getFormat();
|
||||
if (format.width != -1 && format.height != -1
|
||||
if (format.width > 0 && format.height > 0
|
||||
&& format.width * format.height > maxVideoPixelsToRetain) {
|
||||
selectedIndexList.remove(i);
|
||||
}
|
||||
|
|
@ -150,7 +150,7 @@ public final class VideoFormatSelectorUtil {
|
|||
// Filtering format because it's HD.
|
||||
return false;
|
||||
}
|
||||
if (format.width != -1 && format.height != -1) {
|
||||
if (format.width > 0 && format.height > 0) {
|
||||
// TODO: Use MediaCodecUtil.isSizeAndRateSupportedV21 on API levels >= 21 if we know the
|
||||
// mimeType of the media samples within the container. Remove the assumption that we're
|
||||
// dealing with H.264.
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ import java.util.regex.Pattern;
|
|||
|
||||
public static String parseOptionalStringAttr(String line, Pattern pattern) {
|
||||
Matcher matcher = pattern.matcher(line);
|
||||
if (matcher.find() && matcher.groupCount() == 1) {
|
||||
if (matcher.find()) {
|
||||
return matcher.group(1);
|
||||
}
|
||||
return null;
|
||||
|
|
@ -59,7 +59,7 @@ import java.util.regex.Pattern;
|
|||
|
||||
public static boolean parseOptionalBooleanAttr(String line, Pattern pattern) {
|
||||
Matcher matcher = pattern.matcher(line);
|
||||
if (matcher.find() && matcher.groupCount() == 1) {
|
||||
if (matcher.find()) {
|
||||
return BOOLEAN_YES.equals(matcher.group(1));
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ public final class HlsPlaylistParser implements UriLoadable.Parser<HlsPlaylist>
|
|||
private static final Pattern CODECS_ATTR_REGEX =
|
||||
Pattern.compile(CODECS_ATTR + "=\"(.+?)\"");
|
||||
private static final Pattern RESOLUTION_ATTR_REGEX =
|
||||
Pattern.compile(RESOLUTION_ATTR + "=(\\d+x\\d+)");
|
||||
Pattern.compile(RESOLUTION_ATTR + "=(\\d+(\\.\\d+)?x\\d+(\\.\\d+)?)");
|
||||
private static final Pattern MEDIA_DURATION_REGEX =
|
||||
Pattern.compile(MEDIA_DURATION_TAG + ":([\\d.]+),");
|
||||
private static final Pattern MEDIA_SEQUENCE_REGEX =
|
||||
|
|
@ -168,8 +168,16 @@ public final class HlsPlaylistParser implements UriLoadable.Parser<HlsPlaylist>
|
|||
RESOLUTION_ATTR_REGEX);
|
||||
if (resolutionString != null) {
|
||||
String[] widthAndHeight = resolutionString.split("x");
|
||||
width = Integer.parseInt(widthAndHeight[0]);
|
||||
height = Integer.parseInt(widthAndHeight[1]);
|
||||
width = Math.round(Float.parseFloat(widthAndHeight[0]));
|
||||
if (width <= 0) {
|
||||
// Width was invalid.
|
||||
width = -1;
|
||||
}
|
||||
height = Math.round(Float.parseFloat(widthAndHeight[1]));
|
||||
if (height <= 0) {
|
||||
// Height was invalid.
|
||||
height = -1;
|
||||
}
|
||||
} else {
|
||||
width = -1;
|
||||
height = -1;
|
||||
|
|
|
|||
Loading…
Reference in a new issue