Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions isoparser/src/main/java/org/mp4parser/boxes/apple/TimeCodeBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class TimeCodeBox extends AbstractBox implements SampleEntry, Container {
int numberOfFrames;
int reserved1;
int reserved2;
long flags;
long lFlags; // Timecode flags
int dataReferenceIndex;
byte[] rest = new byte[0];

Expand All @@ -51,7 +51,7 @@ public TimeCodeBox() {

@Override
protected long getContentSize() {
return 8 + 4 + 4 + 4 + 4 + 1 + 3 + rest.length;
return 8 + 4 + 4 + 4 + 4 + 1 + 1 + rest.length;

}

Expand All @@ -60,11 +60,11 @@ protected void getContent(ByteBuffer bb) {
bb.put(new byte[]{0, 0, 0, 0, 0, 0});
IsoTypeWriter.writeUInt16(bb, dataReferenceIndex);
bb.putInt(reserved1);
IsoTypeWriter.writeUInt32(bb, flags);
IsoTypeWriter.writeUInt32(bb, lFlags);
bb.putInt(timeScale);
bb.putInt(frameDuration);
IsoTypeWriter.writeUInt8(bb, numberOfFrames);
IsoTypeWriter.writeUInt24(bb, reserved2);
IsoTypeWriter.writeUInt8(bb, reserved2);
bb.put(rest);

}
Expand All @@ -75,12 +75,12 @@ protected void _parseDetails(ByteBuffer content) {
((Buffer)content).position(6);// ignore 6 reserved bytes;
dataReferenceIndex = IsoTypeReader.readUInt16(content); // 8
reserved1 = content.getInt();
flags = IsoTypeReader.readUInt32(content);
lFlags = IsoTypeReader.readUInt32(content);

timeScale = content.getInt();
frameDuration = content.getInt();
numberOfFrames = IsoTypeReader.readUInt8(content);
reserved2 = IsoTypeReader.readUInt24(content);
reserved2 = IsoTypeReader.readUInt8(content);
rest = new byte[content.remaining()];
content.get(rest);
}
Expand All @@ -102,7 +102,7 @@ public String toString() {
", numberOfFrames=" + numberOfFrames +
", reserved1=" + reserved1 +
", reserved2=" + reserved2 +
", flags=" + flags +
", lFlags=" + lFlags +
'}';
}

Expand Down Expand Up @@ -146,12 +146,12 @@ public void setReserved2(int reserved2) {
this.reserved2 = reserved2;
}

public long getFlags() {
return flags;
public long getLFlags() {
return lFlags;
}

public void setFlags(long flags) {
this.flags = flags;
public void setLFlags(long lFlags) {
this.lFlags = lFlags;
}

public byte[] getRest() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2008 CoreMedia AG, Hamburg
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.mp4parser.boxes.apple;

import org.mp4parser.boxes.iso14496.part12.TrackBox;
import org.mp4parser.support.AbstractContainerBox;

/**
* <h1>4cc = "{@value #TYPE}"</h1>
* <code>
* Box Type: 'tmcd'<br>
* Container: {@link TrackBox} ('gmhd')<br>
* Mandatory: No<br>
* Quantity: Zero or one<br><br>
* </code>
* This box is a container for the 'tcmi' box.
*/
public class TimeCodeContainerBox extends AbstractContainerBox {
public static final String TYPE = "tmcd";

public TimeCodeContainerBox() {
super(TYPE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
/*
* Copyright 2009 castLabs GmbH, Berlin
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.mp4parser.boxes.apple;

import org.mp4parser.support.AbstractFullBox;
import org.mp4parser.tools.IsoTypeReader;
import org.mp4parser.tools.IsoTypeWriter;

import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;

/**
* <h1>4cc = "{@value #TYPE}"</h1>
* See <a href="https://developer.apple.com/documentation/quicktime-file-format/timecode_media_information_atom">Apple Quicktime Format</a>
*/
public class TimeCodeMediaInformationBox extends AbstractFullBox {
public static final String TYPE = "tcmi";

private int textFont; // A 16-bit integer that indicates the font to use.
private int textFace; // A 16-bit integer that indicates the font’s style.
private int textSize; // A 16-bit integer that specifies the point size of the time code text.
private int reserved; // A 16-bit integer that is reserved for use by Apple.
private int textColorR; // A 48-bit RGB color value for the timecode text - red.
private int textColorG; // A 48-bit RGB color value for the timecode text - green.
private int textColorB; // A 48-bit RGB color value for the timecode text - blue.
private int backgroundColorR; // A 48-bit RGB background color for the timecode text - red.
private int backgroundColorG; // A 48-bit RGB background color for the timecode text - green.
private int backgroundColorB; // A 48-bit RGB background color for the timecode text - blue.
private String fontName; // A Pascal string specifying the name of the timecode text’s font.

public TimeCodeMediaInformationBox() {
super(TYPE);
}


protected long getContentSize() {
return 12 + 2 + 2 + 2 + 2 + 48 + 48 + 1 + fontName.length();
}

@Override
public void _parseDetails(ByteBuffer content) {
parseVersionAndFlags(content);
textFont = IsoTypeReader.readUInt16(content);
textFace = IsoTypeReader.readUInt16(content);
textSize = IsoTypeReader.readUInt16(content);
reserved = IsoTypeReader.readUInt16(content);
textColorR = IsoTypeReader.readUInt16(content);
textColorG = IsoTypeReader.readUInt16(content);
textColorB = IsoTypeReader.readUInt16(content);
backgroundColorR = IsoTypeReader.readUInt16(content);
backgroundColorG = IsoTypeReader.readUInt16(content);
backgroundColorB = IsoTypeReader.readUInt16(content);
int length = IsoTypeReader.readUInt8(content);
byte[] fontNameBytes = new byte[length];
content.get(fontNameBytes);
fontName = new String(fontNameBytes, StandardCharsets.UTF_8);
}

@Override
protected void getContent(ByteBuffer byteBuffer) {
writeVersionAndFlags(byteBuffer);
IsoTypeWriter.writeUInt16(byteBuffer, textFont);
IsoTypeWriter.writeUInt16(byteBuffer, textFace);
IsoTypeWriter.writeUInt16(byteBuffer, textSize);
IsoTypeWriter.writeUInt16(byteBuffer, reserved);
IsoTypeWriter.writeUInt16(byteBuffer, textColorR);
IsoTypeWriter.writeUInt16(byteBuffer, textColorG);
IsoTypeWriter.writeUInt16(byteBuffer, textColorB);
IsoTypeWriter.writeUInt16(byteBuffer, backgroundColorR);
IsoTypeWriter.writeUInt16(byteBuffer, backgroundColorG);
IsoTypeWriter.writeUInt16(byteBuffer, backgroundColorB);
IsoTypeWriter.writeUInt8(byteBuffer, fontName.length());
byteBuffer.put(fontName.getBytes(StandardCharsets.UTF_8), 0, fontName.length());
}

public int getTextFont() {
return textFont;
}

public void setTextFont(int textFont) {
this.textFont = textFont;
}

public int getTextFace() {
return textFace;
}

public void setTextFace(int textFace) {
this.textFace = textFace;
}

public int getTextSize() {
return textSize;
}

public void setTextSize(int textSize) {
this.textSize = textSize;
}

public int getReserved() {
return reserved;
}

public void setReserved(int reserved) {
this.reserved = reserved;
}

public int getTextColorR() {
return textColorR;
}

public void setTextColorR(int textColorR) {
this.textColorR = textColorR;
}

public int getTextColorG() {
return textColorG;
}

public void setTextColorG(int textColorG) {
this.textColorG = textColorG;
}

public int getTextColorB() {
return textColorB;
}

public void setTextColorB(int textColorB) {
this.textColorB = textColorB;
}

public int getBackgroundColorR() {
return backgroundColorR;
}

public void setBackgroundColorR(int backgroundColorR) {
this.backgroundColorR = backgroundColorR;
}

public int getBackgroundColorG() {
return backgroundColorG;
}

public void setBackgroundColorG(int backgroundColorG) {
this.backgroundColorG = backgroundColorG;
}

public int getBackgroundColorB() {
return backgroundColorB;
}

public void setBackgroundColorB(int backgroundColorB) {
this.backgroundColorB = backgroundColorB;
}

public String getFontName() {
return fontName;
}

public void setFontName(String fontName) {
this.fontName = fontName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,14 @@ protected int getContentSize() {
}
}
}
return (int) Math.ceil(((double) sizeInBits) / 8);

int requiredBytes = (int) Math.ceil(((double) sizeInBits) / 8);

if (sizeOfInstance > requiredBytes) {
return sizeOfInstance;
} else {
return requiredBytes;
}
}

public ByteBuffer serialize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class TrackReferenceTypeBox extends AbstractBox {
// 'hind' this track depends on the referenced hint track, i.e., it should only be used if the referenced hint track is used.
// 'vdep' this track contains auxiliary depth video information for the referenced video track
// 'vplx' this track contains auxiliary parallax video information for the referenced video track
// 'tmcd' this track uses time code information in the referenced track

public TrackReferenceTypeBox(String type) {
super(type);
Expand Down
5 changes: 4 additions & 1 deletion isoparser/src/main/resources/isoparser2-default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ amf0=org.mp4parser.boxes.adobe.ActionMessageFormat0SampleEntryBox

esds=org.mp4parser.boxes.iso14496.part14.ESDescriptorBox

tmcd=org.mp4parser.boxes.apple.TimeCodeBox
stsd-tmcd=org.mp4parser.boxes.apple.TimeCodeBox
gmhd-tmcd=org.mp4parser.boxes.apple.TimeCodeContainerBox
tcmi=org.mp4parser.boxes.apple.TimeCodeMediaInformationBox
sidx=org.mp4parser.boxes.iso14496.part12.SegmentIndexBox

sbgp=org.mp4parser.boxes.samplegrouping.SampleToGroupBox
Expand Down Expand Up @@ -234,6 +236,7 @@ cdsc=org.mp4parser.boxes.iso14496.part12.TrackReferenceTypeBox(type)
hind=org.mp4parser.boxes.iso14496.part12.TrackReferenceTypeBox(type)
vdep=org.mp4parser.boxes.iso14496.part12.TrackReferenceTypeBox(type)
vplx=org.mp4parser.boxes.iso14496.part12.TrackReferenceTypeBox(type)
tref-tmcd=org.mp4parser.boxes.iso14496.part12.TrackReferenceTypeBox(type)


rtp\ =org.mp4parser.boxes.iso14496.part12.HintSampleEntry(type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.net.URLDecoder;
import java.nio.channels.Channels;
import java.nio.charset.StandardCharsets;

/**
* Tests ISO Roundtrip.
Expand All @@ -34,7 +36,7 @@ public class RoundTripTest extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
defaultTestFileDir = this.getClass().getProtectionDomain().getCodeSource().getLocation().getFile();
defaultTestFileDir = URLDecoder.decode(this.getClass().getProtectionDomain().getCodeSource().getLocation().getFile(), StandardCharsets.UTF_8.name());
/* Logger.getLogger("").setLevel(Level.ALL);
Handler[] handlers = Logger.getLogger("").getHandlers();
for (Handler handler : handlers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import java.io.FileInputStream;
import java.io.IOException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;

import org.junit.Before;
import org.junit.Test;
Expand All @@ -24,7 +26,7 @@ public class SkippingBoxTest {

@Before
public void setup() throws IOException {
FileInputStream fis = new FileInputStream(PathTest.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/test.m4p");
FileInputStream fis = new FileInputStream(URLDecoder.decode(PathTest.class.getProtectionDomain().getCodeSource().getLocation().getFile(), StandardCharsets.UTF_8.name()) + "/test.m4p");
isoFile = new IsoFile(fis.getChannel(), new PropertyBoxParserImpl().skippingBoxes("mdat", "mvhd"));
fis.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@

import java.io.FileInputStream;
import java.io.IOException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;

public class PathTest {
IsoFile isoFile;

@Before
public void setup() throws IOException {
isoFile = new IsoFile(new FileInputStream(PathTest.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/multiTrack.3gp").getChannel());
isoFile = new IsoFile(new FileInputStream(URLDecoder.decode(PathTest.class.getProtectionDomain().getCodeSource().getLocation().getFile(), StandardCharsets.UTF_8.name()) + "/multiTrack.3gp").getChannel());
}


Expand Down
Loading