Skip to content

Commit

Permalink
Don't read unused values
Browse files Browse the repository at this point in the history
  • Loading branch information
drewnoakes committed Apr 3, 2022
1 parent 70ae244 commit 17a4df8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 60 deletions.
12 changes: 7 additions & 5 deletions Source/com/drew/metadata/mp4/Mp4BoxHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions Source/com/drew/metadata/mp4/media/Mp4HintHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion Source/com/drew/metadata/mp4/media/Mp4MetaDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

public class Mp4MetaDescriptor extends TagDescriptor<Mp4MetaDirectory>
{

public Mp4MetaDescriptor(Mp4MetaDirectory directory)
{
super(directory);
Expand Down
39 changes: 11 additions & 28 deletions Source/com/drew/metadata/mp4/media/Mp4SoundHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.drew.metadata.mp4.Mp4MediaHandler;

import java.io.IOException;
import java.util.ArrayList;

public class Mp4SoundHandler extends Mp4MediaHandler<Mp4SoundDirectory>
{
Expand All @@ -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

Expand All @@ -70,29 +68,28 @@ 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

// 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
public void processMediaInformation(@NotNull SequentialReader reader) throws IOException
{
// 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

Expand All @@ -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<EntryCount> entries = new ArrayList<EntryCount>();
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;
}
}
}
31 changes: 7 additions & 24 deletions Source/com/drew/metadata/mp4/media/Mp4VideoHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -128,38 +127,22 @@ 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<EntryCount> entries = new ArrayList<EntryCount>((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) {
float frameRate = (float)context.timeScale / ((float)context.duration / sampleCount);
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;
}
}
}

0 comments on commit 17a4df8

Please sign in to comment.