From 96086b7733fac4bc982c4ad77a7c0c1b823b637a Mon Sep 17 00:00:00 2001 From: kapodamy Date: Wed, 1 Apr 2020 15:09:54 -0300 Subject: [PATCH] code cleanup --- .../org/schabi/newpipe/streams/DataReader.java | 5 +++++ .../org/schabi/newpipe/streams/Mp4DashReader.java | 14 +++++--------- .../schabi/newpipe/streams/Mp4FromDashWriter.java | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/streams/DataReader.java b/app/src/main/java/org/schabi/newpipe/streams/DataReader.java index 75b55cd73..8c57d8978 100644 --- a/app/src/main/java/org/schabi/newpipe/streams/DataReader.java +++ b/app/src/main/java/org/schabi/newpipe/streams/DataReader.java @@ -69,6 +69,11 @@ public class DataReader { return primitive[0] << 24 | primitive[1] << 16 | primitive[2] << 8 | primitive[3]; } + public long readUnsignedInt() throws IOException { + long value = readInt(); + return value & 0xffffffffL; + } + public short readShort() throws IOException { primitiveRead(SHORT_SIZE); return (short) (primitive[0] << 8 | primitive[1]); diff --git a/app/src/main/java/org/schabi/newpipe/streams/Mp4DashReader.java b/app/src/main/java/org/schabi/newpipe/streams/Mp4DashReader.java index 0cfd856e1..b7efa038e 100644 --- a/app/src/main/java/org/schabi/newpipe/streams/Mp4DashReader.java +++ b/app/src/main/java/org/schabi/newpipe/streams/Mp4DashReader.java @@ -294,10 +294,6 @@ public class Mp4DashReader { - private long readUint() throws IOException { - return stream.readInt() & 0xffffffffL; - } - public static boolean hasFlag(int flags, int mask) { return (flags & mask) == mask; } @@ -317,7 +313,7 @@ public class Mp4DashReader { private Box readBox() throws IOException { Box b = new Box(); b.offset = stream.position(); - b.size = stream.readInt(); + b.size = stream.readUnsignedInt(); b.type = stream.readInt(); if (b.size == 1) { @@ -478,7 +474,7 @@ public class Mp4DashReader { private long parse_tfdt() throws IOException { int version = stream.read(); stream.skipBytes(3);// flags - return version == 0 ? readUint() : stream.readLong(); + return version == 0 ? stream.readUnsignedInt() : stream.readLong(); } private Trun parse_trun() throws IOException { @@ -551,7 +547,7 @@ public class Mp4DashReader { stream.skipBytes(2 * (version == 0 ? 4 : 8)); Mvhd obj = new Mvhd(); - obj.timeScale = readUint(); + obj.timeScale = stream.readUnsignedInt(); // chunkDuration stream.skipBytes(version == 0 ? 4 : 8); @@ -563,7 +559,7 @@ public class Mp4DashReader { // predefined stream.skipBytes(76); - obj.nextTrackId = readUint(); + obj.nextTrackId = stream.readUnsignedInt(); return obj; } @@ -582,7 +578,7 @@ public class Mp4DashReader { stream.skipBytes(4);// reserved - obj.duration = version == 0 ? readUint() : stream.readLong(); + obj.duration = version == 0 ? stream.readUnsignedInt() : stream.readLong(); stream.skipBytes(2 * 4);// reserved diff --git a/app/src/main/java/org/schabi/newpipe/streams/Mp4FromDashWriter.java b/app/src/main/java/org/schabi/newpipe/streams/Mp4FromDashWriter.java index 64e4534cb..67f68d3a7 100644 --- a/app/src/main/java/org/schabi/newpipe/streams/Mp4FromDashWriter.java +++ b/app/src/main/java/org/schabi/newpipe/streams/Mp4FromDashWriter.java @@ -46,7 +46,7 @@ public class Mp4FromDashWriter { private int overrideMainBrand = 0x00; - private ArrayList compatibleBrands = new ArrayList<>(5); + private final ArrayList compatibleBrands = new ArrayList<>(5); public Mp4FromDashWriter(SharpStream... sources) throws IOException { for (SharpStream src : sources) {