From 17a4df8d91b66dcaa66da0e46c9034a0d179d6a0 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Mon, 4 Apr 2022 07:53:30 +1000 Subject: [PATCH] Don't read unused values --- .../com/drew/metadata/mp4/Mp4BoxHandler.java | 12 +++--- .../metadata/mp4/media/Mp4HintHandler.java | 3 +- .../metadata/mp4/media/Mp4MetaDescriptor.java | 1 - .../metadata/mp4/media/Mp4SoundHandler.java | 39 ++++++------------- .../metadata/mp4/media/Mp4VideoHandler.java | 31 ++++----------- 5 files changed, 26 insertions(+), 60 deletions(-) diff --git a/Source/com/drew/metadata/mp4/Mp4BoxHandler.java b/Source/com/drew/metadata/mp4/Mp4BoxHandler.java index 1c8f700e2..1dbea800d 100644 --- a/Source/com/drew/metadata/mp4/Mp4BoxHandler.java +++ b/Source/com/drew/metadata/mp4/Mp4BoxHandler.java @@ -90,8 +90,7 @@ public Mp4Handler processBox(@NotNull String type, @Nullable byte[] payload, // ISO/IED 14496-12:2015 pg.7 - int version = reader.getUInt8(); - byte[] flags = reader.getBytes(3); + reader.skip(4); // one byte version, three bytes flags // ISO/IED 14496-12:2015 pg.30 @@ -195,7 +194,8 @@ private void processMovieHeader(@NotNull SequentialReader reader) throws IOExcep // ISO/IED 14496-12:2015 pg.23 short version = reader.getUInt8(); - byte[] flags = reader.getBytes(3); + + reader.skip(3); // flags long creationTime; long modificationTime; @@ -261,7 +261,8 @@ private void processMediaHeader(@NotNull SequentialReader reader, Mp4Context con // ISO/IED 14496-12:2015 pg.7 int version = reader.getUInt8(); - byte[] flags = reader.getBytes(3); + + reader.skip(3); // flags // ISO/IED 14496-12:2015 pg.29 @@ -292,7 +293,8 @@ private void processTrackHeader(@NotNull SequentialReader reader) throws IOExcep // ISO/IED 14496-12:2015 pg.7 int version = reader.getUInt8(); - byte[] flags = reader.getBytes(3); + + reader.skip(3); // flags // ISO/IED 14496-12:2005 pg.17-18 diff --git a/Source/com/drew/metadata/mp4/media/Mp4HintHandler.java b/Source/com/drew/metadata/mp4/media/Mp4HintHandler.java index 6cc210812..abd518ce6 100644 --- a/Source/com/drew/metadata/mp4/media/Mp4HintHandler.java +++ b/Source/com/drew/metadata/mp4/media/Mp4HintHandler.java @@ -59,8 +59,7 @@ protected void processMediaInformation(@NotNull SequentialReader reader) throws { // ISO/IED 14496-12:2015 pg.169 - int version = reader.getUInt8(); - byte[] flags = reader.getBytes(3); + reader.skip(4); // one byte version, three bytes flags int maxPduSize = reader.getUInt16(); int avgPduSize = reader.getUInt16(); diff --git a/Source/com/drew/metadata/mp4/media/Mp4MetaDescriptor.java b/Source/com/drew/metadata/mp4/media/Mp4MetaDescriptor.java index b3bc791f9..788742a2e 100644 --- a/Source/com/drew/metadata/mp4/media/Mp4MetaDescriptor.java +++ b/Source/com/drew/metadata/mp4/media/Mp4MetaDescriptor.java @@ -24,7 +24,6 @@ public class Mp4MetaDescriptor extends TagDescriptor { - public Mp4MetaDescriptor(Mp4MetaDirectory directory) { super(directory); diff --git a/Source/com/drew/metadata/mp4/media/Mp4SoundHandler.java b/Source/com/drew/metadata/mp4/media/Mp4SoundHandler.java index 84c0cf3d3..06aa9cbd1 100644 --- a/Source/com/drew/metadata/mp4/media/Mp4SoundHandler.java +++ b/Source/com/drew/metadata/mp4/media/Mp4SoundHandler.java @@ -29,7 +29,6 @@ import com.drew.metadata.mp4.Mp4MediaHandler; import java.io.IOException; -import java.util.ArrayList; public class Mp4SoundHandler extends Mp4MediaHandler { @@ -56,8 +55,7 @@ public void processSampleDescription(@NotNull SequentialReader reader) throws IO { // ISO/IED 14496-12:2015 pg.7 - int version = reader.getUInt8(); - byte[] flags = reader.getBytes(3); + reader.skip(4); // one byte version, three bytes flags // ISO/IED 14496-12:2015 pg.33 @@ -70,11 +68,11 @@ public void processSampleDescription(@NotNull SequentialReader reader) throws IO // ISO/IED 14496-12:2015 pg.161 reader.skip(8); // Reserved - int channelcount = reader.getUInt16(); - int samplesize = reader.getInt16(); + int channelCount = reader.getUInt16(); + int sampleSize = reader.getInt16(); reader.skip(2); // Pre-defined reader.skip(2); // Reserved - long samplerate = reader.getUInt32(); + long sampleRate = reader.getUInt32(); // ChannelLayout() // DownMix and/or DRC boxes // More boxes as needed @@ -82,8 +80,8 @@ public void processSampleDescription(@NotNull SequentialReader reader) throws IO // TODO review this Mp4Dictionary.setLookup(Mp4SoundDirectory.TAG_AUDIO_FORMAT, format, directory); - directory.setInt(Mp4SoundDirectory.TAG_NUMBER_OF_CHANNELS, channelcount); - directory.setInt(Mp4SoundDirectory.TAG_AUDIO_SAMPLE_SIZE, samplesize); + directory.setInt(Mp4SoundDirectory.TAG_NUMBER_OF_CHANNELS, channelCount); + directory.setInt(Mp4SoundDirectory.TAG_AUDIO_SAMPLE_SIZE, sampleSize); } @Override @@ -91,8 +89,7 @@ public void processMediaInformation(@NotNull SequentialReader reader) throws IOE { // ISO/IED 14496-12:2015 pg.7 - int version = reader.getUInt8(); - byte[] flags = reader.getBytes(3); + reader.skip(4); // one byte version, three bytes flags // ISO/IED 14496-12:2015 pg.159 @@ -109,31 +106,17 @@ protected void processTimeToSample(@NotNull SequentialReader reader, Mp4Context { // ISO/IED 14496-12:2015 pg.7 - int version = reader.getUInt8(); - byte[] flags = reader.getBytes(3); + reader.skip(4); // one byte version, three bytes flags // ISO/IED 14496-12:2015 pg.37 long entryCount = reader.getUInt32(); - ArrayList entries = new ArrayList(); - for (int i = 0; i < entryCount; i++) { - entries.add(new EntryCount(reader.getUInt32(), reader.getUInt32())); - } + + // skip entries (4 bytes sample count, 4 bytes sample delta, per entry) + reader.skip(entryCount * 8); if (context.timeScale != null) { directory.setDouble(Mp4SoundDirectory.TAG_AUDIO_SAMPLE_RATE, context.timeScale); } } - - static class EntryCount - { - long sampleCount; - long sampleDelta; - - public EntryCount(long sampleCount, long sampleDelta) - { - this.sampleCount = sampleCount; - this.sampleDelta = sampleDelta; - } - } } diff --git a/Source/com/drew/metadata/mp4/media/Mp4VideoHandler.java b/Source/com/drew/metadata/mp4/media/Mp4VideoHandler.java index e48eac08d..9fac9cd3e 100644 --- a/Source/com/drew/metadata/mp4/media/Mp4VideoHandler.java +++ b/Source/com/drew/metadata/mp4/media/Mp4VideoHandler.java @@ -111,8 +111,7 @@ public void processMediaInformation(@NotNull SequentialReader reader) throws IOE { // ISO/IED 14496-12:2015 pg.7 - int version = reader.getUInt8(); - byte[] flags = reader.getBytes(3); + reader.skip(4); // 1 byte header, 3 bytes flags // ISO/IED 14496-12:2015 pg.155 @@ -128,21 +127,17 @@ public void processTimeToSample(@NotNull SequentialReader reader, Mp4Context con { // ISO/IED 14496-12:2015 pg.7 - int version = reader.getUInt8(); - byte[] flags = reader.getBytes(3); + reader.skip(4); // 1 byte header, 3 bytes flags // ISO/IED 14496-12:2015 pg.37 - long entryCount = reader.getUInt32(); - ArrayList entries = new ArrayList((int)entryCount); - for (int i = 0; i < entryCount; i++) { - entries.add(new EntryCount(reader.getUInt32(), reader.getUInt32())); - } - float sampleCount = 0; - for (EntryCount ec : entries) { - sampleCount += ec.sampleCount; + long entryCount = reader.getUInt32(); + + for (int i = 0; i < entryCount; i++) { + sampleCount += reader.getUInt32(); + reader.skip(4); // sample delta } if (context.timeScale != null && context.duration != null) { @@ -150,16 +145,4 @@ public void processTimeToSample(@NotNull SequentialReader reader, Mp4Context con directory.setFloat(Mp4VideoDirectory.TAG_FRAME_RATE, frameRate); } } - - static class EntryCount - { - long sampleCount; - long sampleDelta; - - public EntryCount(long sampleCount, long sampleDelta) - { - this.sampleCount = sampleCount; - this.sampleDelta = sampleDelta; - } - } }