Skip to content
Snippets Groups Projects
Commit 02733524 authored by Leo Ma's avatar Leo Ma
Browse files

Add new files for mp4 parser


Signed-off-by: default avatarLeo Ma <begeekmyfriend@gmail.com>
parent 4b67a064
No related branches found
No related tags found
No related merge requests found
Showing
with 1230 additions and 0 deletions
package com.coremedia.iso.boxes.apple;
/**
* Beats per minute.
*/
public final class AppleTempBox extends AbstractAppleMetaDataBox {
public static final String TYPE = "tmpo";
public AppleTempBox() {
super(TYPE);
appleDataBox = AppleDataBox.getUint16AppleDataBox();
}
public int getTempo() {
return appleDataBox.getData()[1];
}
public void setTempo(int tempo) {
appleDataBox = new AppleDataBox();
appleDataBox.setVersion(0);
appleDataBox.setFlags(21);
appleDataBox.setFourBytes(new byte[4]);
appleDataBox.setData(new byte[]{0, (byte) (tempo & 0xFF)});
}
}
\ No newline at end of file
package com.coremedia.iso.boxes.apple;
/**
*
*/
public final class AppleTrackAuthorBox extends AbstractAppleMetaDataBox {
public static final String TYPE = "\u00a9wrt";
public AppleTrackAuthorBox() {
super(TYPE);
appleDataBox = AppleDataBox.getStringAppleDataBox();
}
}
\ No newline at end of file
package com.coremedia.iso.boxes.apple;
/**
*
*/
public final class AppleTrackNumberBox extends AbstractAppleMetaDataBox {
public static final String TYPE = "trkn";
public AppleTrackNumberBox() {
super(TYPE);
}
/**
* @param track the actual track number
* @param of number of tracks overall
*/
public void setTrackNumber(byte track, byte of) {
appleDataBox = new AppleDataBox();
appleDataBox.setVersion(0);
appleDataBox.setFlags(0);
appleDataBox.setFourBytes(new byte[4]);
appleDataBox.setData(new byte[]{0, 0, 0, track, 0, of, 0, 0});
}
public byte getTrackNumber() {
return appleDataBox.getData()[3];
}
public byte getNumberOfTracks() {
return appleDataBox.getData()[5];
}
public void setNumberOfTracks(byte numberOfTracks) {
byte[] content = appleDataBox.getData();
content[5] = numberOfTracks;
appleDataBox.setData(content);
}
public void setTrackNumber(byte trackNumber) {
byte[] content = appleDataBox.getData();
content[3] = trackNumber;
appleDataBox.setData(content);
}
}
\ No newline at end of file
package com.coremedia.iso.boxes.apple;
/**
*
*/
public final class AppleTrackTitleBox extends AbstractAppleMetaDataBox {
public static final String TYPE = "\u00a9nam";
public AppleTrackTitleBox() {
super(TYPE);
appleDataBox = AppleDataBox.getStringAppleDataBox();
}
}
package com.coremedia.iso.boxes.apple;
/**
* Tv Episode.
*/
public class AppleTvEpisodeBox extends AbstractAppleMetaDataBox {
public static final String TYPE = "tves";
public AppleTvEpisodeBox() {
super(TYPE);
appleDataBox = AppleDataBox.getUint32AppleDataBox();
}
}
\ No newline at end of file
package com.coremedia.iso.boxes.apple;
/**
* Tv Episode.
*/
public class AppleTvEpisodeNumberBox extends AbstractAppleMetaDataBox {
public static final String TYPE = "tven";
public AppleTvEpisodeNumberBox() {
super(TYPE);
appleDataBox = AppleDataBox.getStringAppleDataBox();
}
}
\ No newline at end of file
package com.coremedia.iso.boxes.apple;
/**
* Tv Season.
*/
public final class AppleTvSeasonBox extends AbstractAppleMetaDataBox {
public static final String TYPE = "tvsn";
public AppleTvSeasonBox() {
super(TYPE);
appleDataBox = AppleDataBox.getUint32AppleDataBox();
}
}
\ No newline at end of file
package com.coremedia.iso.boxes.apple;
import com.googlecode.mp4parser.AbstractContainerBox;
/**
*
*/
public final class AppleWaveBox extends AbstractContainerBox {
public static final String TYPE = "wave";
public AppleWaveBox() {
super(TYPE);
}
}
package com.coremedia.iso.boxes.dece;
import com.coremedia.iso.IsoTypeReader;
import com.coremedia.iso.IsoTypeWriter;
import com.googlecode.mp4parser.AbstractFullBox;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
/**
* aligned(8) class TrickPlayBox
* extends FullBox(trik, version=0, flags=0)
* {
* for (i=0; I < sample_count; i++) {
* unsigned int(2) pic_type;
* unsigned int(6) dependency_level;
* }
* }
*/
public class TrickPlayBox extends AbstractFullBox {
public static final String TYPE = "trik";
private List<Entry> entries = new ArrayList<Entry>();
public TrickPlayBox() {
super(TYPE);
}
public void setEntries(List<Entry> entries) {
this.entries = entries;
}
public List<Entry> getEntries() {
return entries;
}
public static class Entry {
public Entry() {
}
public Entry(int value) {
this.value = value;
}
private int value;
public int getPicType() {
return (value >> 6) & 0x03;
}
public void setPicType(int picType) {
value = value & (0xff >> 3);
value = (picType & 0x03) << 6 | value;
}
public int getDependencyLevel() {
return value & 0x3f;
}
public void setDependencyLevel(int dependencyLevel) {
value = (dependencyLevel & 0x3f) | value;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append("Entry");
sb.append("{picType=").append(getPicType());
sb.append(",dependencyLevel=").append(getDependencyLevel());
sb.append('}');
return sb.toString();
}
}
@Override
protected long getContentSize() {
return 4 + entries.size();
}
@Override
public void _parseDetails(ByteBuffer content) {
parseVersionAndFlags(content);
while (content.remaining() > 0) {
entries.add(new Entry(IsoTypeReader.readUInt8(content)));
}
}
@Override
protected void getContent(ByteBuffer byteBuffer) {
writeVersionAndFlags(byteBuffer);
for (Entry entry : entries) {
IsoTypeWriter.writeUInt8(byteBuffer, entry.value);
}
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append("TrickPlayBox");
sb.append("{entries=").append(entries);
sb.append('}');
return sb.toString();
}
}
/*
* 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 com.coremedia.iso.boxes.fragment;
import com.googlecode.mp4parser.AbstractContainerBox;
/**
* aligned(8) class MovieExtendsBox extends Box('mvex'){
* }
*/
public class MovieExtendsBox extends AbstractContainerBox {
public static final String TYPE = "mvex";
public MovieExtendsBox() {
super(TYPE);
}
}
/*
* 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 com.coremedia.iso.boxes.fragment;
import com.coremedia.iso.IsoTypeReader;
import com.coremedia.iso.IsoTypeWriter;
import com.googlecode.mp4parser.AbstractFullBox;
import java.nio.ByteBuffer;
/**
* aligned(8) class MovieExtendsHeaderBox extends FullBox('mehd', version, 0) {
* if (version==1) {
* unsigned int(64) fragment_duration;
* } else { // version==0
* unsigned int(32) fragment_duration;
* }
* }
*/
public class MovieExtendsHeaderBox extends AbstractFullBox {
public static final String TYPE = "mehd";
private long fragmentDuration;
public MovieExtendsHeaderBox() {
super(TYPE);
}
@Override
protected long getContentSize() {
return getVersion() == 1 ? 12 : 8;
}
@Override
public void _parseDetails(ByteBuffer content) {
parseVersionAndFlags(content);
fragmentDuration = getVersion() == 1 ? IsoTypeReader.readUInt64(content) : IsoTypeReader.readUInt32(content);
}
@Override
protected void getContent(ByteBuffer byteBuffer) {
writeVersionAndFlags(byteBuffer);
if (getVersion() == 1) {
IsoTypeWriter.writeUInt64(byteBuffer, fragmentDuration);
} else {
IsoTypeWriter.writeUInt32(byteBuffer, fragmentDuration);
}
}
public long getFragmentDuration() {
return fragmentDuration;
}
public void setFragmentDuration(long fragmentDuration) {
this.fragmentDuration = fragmentDuration;
}
}
/*
* 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 com.coremedia.iso.boxes.fragment;
import com.googlecode.mp4parser.AbstractContainerBox;
import com.coremedia.iso.boxes.Box;
import com.coremedia.iso.boxes.SampleDependencyTypeBox;
import com.googlecode.mp4parser.annotations.DoNotParseDetail;
import java.util.ArrayList;
import java.util.List;
/**
* aligned(8) class MovieFragmentBox extends Box(moof){
* }
*/
public class MovieFragmentBox extends AbstractContainerBox {
public static final String TYPE = "moof";
public MovieFragmentBox() {
super(TYPE);
}
public List<Long> getSyncSamples(SampleDependencyTypeBox sdtp) {
List<Long> result = new ArrayList<Long>();
final List<SampleDependencyTypeBox.Entry> sampleEntries = sdtp.getEntries();
long i = 1;
for (SampleDependencyTypeBox.Entry sampleEntry : sampleEntries) {
if (sampleEntry.getSampleDependsOn() == 2) {
result.add(i);
}
i++;
}
return result;
}
@DoNotParseDetail
public long getOffset() {
Box b = this;
long offset = 0;
while (b.getParent() != null) {
for (Box box : b.getParent().getBoxes()) {
if (b == box) {
break;
}
offset += box.getSize();
}
b = b.getParent();
}
return offset;
}
public int getTrackCount() {
return getBoxes(TrackFragmentBox.class, false).size();
}
/**
* Returns the track numbers associated with this <code>MovieBox</code>.
*
* @return the tracknumbers (IDs) of the tracks in their order of appearance in the file
*/
public long[] getTrackNumbers() {
List<TrackFragmentBox> trackBoxes = this.getBoxes(TrackFragmentBox.class, false);
long[] trackNumbers = new long[trackBoxes.size()];
for (int trackCounter = 0; trackCounter < trackBoxes.size(); trackCounter++) {
TrackFragmentBox trackBoxe = trackBoxes.get(trackCounter);
trackNumbers[trackCounter] = trackBoxe.getTrackFragmentHeaderBox().getTrackId();
}
return trackNumbers;
}
public List<TrackFragmentHeaderBox> getTrackFragmentHeaderBoxes() {
return getBoxes(TrackFragmentHeaderBox.class, true);
}
public List<TrackRunBox> getTrackRunBoxes() {
return getBoxes(TrackRunBox.class, true);
}
}
/*
* 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 com.coremedia.iso.boxes.fragment;
import com.coremedia.iso.IsoTypeReader;
import com.coremedia.iso.IsoTypeWriter;
import com.googlecode.mp4parser.AbstractFullBox;
import java.nio.ByteBuffer;
/**
* aligned(8) class MovieFragmentHeaderBox
* extends FullBox('mfhd', 0, 0){
* unsigned int(32) sequence_number;
* }
*/
public class MovieFragmentHeaderBox extends AbstractFullBox {
public static final String TYPE = "mfhd";
private long sequenceNumber;
public MovieFragmentHeaderBox() {
super(TYPE);
}
protected long getContentSize() {
return 8;
}
@Override
protected void getContent(ByteBuffer byteBuffer) {
writeVersionAndFlags(byteBuffer);
IsoTypeWriter.writeUInt32(byteBuffer, sequenceNumber);
}
@Override
public void _parseDetails(ByteBuffer content) {
parseVersionAndFlags(content);
sequenceNumber = IsoTypeReader.readUInt32(content);
}
public long getSequenceNumber() {
return sequenceNumber;
}
public void setSequenceNumber(long sequenceNumber) {
this.sequenceNumber = sequenceNumber;
}
@Override
public String toString() {
return "MovieFragmentHeaderBox{" +
"sequenceNumber=" + sequenceNumber +
'}';
}
}
/*
* 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 com.coremedia.iso.boxes.fragment;
import com.googlecode.mp4parser.AbstractContainerBox;
/**
* aligned(8) class MovieFragmentRandomAccessBox
* extends Box('mfra')
* {
* }
*/
public class MovieFragmentRandomAccessBox extends AbstractContainerBox {
public static final String TYPE = "mfra";
public MovieFragmentRandomAccessBox() {
super(TYPE);
}
}
/*
* 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 com.coremedia.iso.boxes.fragment;
import com.coremedia.iso.IsoTypeReader;
import com.coremedia.iso.IsoTypeWriter;
import com.googlecode.mp4parser.AbstractFullBox;
import java.nio.ByteBuffer;
/**
* aligned(8) class MovieFragmentRandomAccessOffsetBox
* extends FullBox('mfro', version, 0) {
* unsigned int(32) size;
* }
*/
public class MovieFragmentRandomAccessOffsetBox extends AbstractFullBox {
public static final String TYPE = "mfro";
private long mfraSize;
public MovieFragmentRandomAccessOffsetBox() {
super(TYPE);
}
protected long getContentSize() {
return 8;
}
@Override
public void _parseDetails(ByteBuffer content) {
parseVersionAndFlags(content);
mfraSize = IsoTypeReader.readUInt32(content);
}
@Override
protected void getContent(ByteBuffer byteBuffer) {
writeVersionAndFlags(byteBuffer);
IsoTypeWriter.writeUInt32(byteBuffer, mfraSize);
}
public long getMfraSize() {
return mfraSize;
}
public void setMfraSize(long mfraSize) {
this.mfraSize = mfraSize;
}
}
/*
* 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 com.coremedia.iso.boxes.fragment;
import com.googlecode.mp4parser.boxes.mp4.objectdescriptors.BitReaderBuffer;
import com.googlecode.mp4parser.boxes.mp4.objectdescriptors.BitWriterBuffer;
import java.io.IOException;
import java.nio.ByteBuffer;
/**
* bit(6) reserved=0;
* unsigned int(2) sample_depends_on;
* unsigned int(2) sample_is_depended_on;
* unsigned int(2) sample_has_redundancy;
* bit(3) sample_padding_value;
* bit(1) sample_is_difference_sample;
* // i.e. when 1 signals a non-key or non-sync sample
* unsigned int(16) sample_degradation_priority;
*/
public class SampleFlags {
private int reserved;
private int sampleDependsOn;
private int sampleIsDependedOn;
private int sampleHasRedundancy;
private int samplePaddingValue;
private boolean sampleIsDifferenceSample;
private int sampleDegradationPriority;
public SampleFlags() {
}
public SampleFlags(ByteBuffer bb) {
BitReaderBuffer brb = new BitReaderBuffer(bb);
reserved = brb.readBits(6);
sampleDependsOn = brb.readBits(2);
sampleIsDependedOn = brb.readBits(2);
sampleHasRedundancy = brb.readBits(2);
samplePaddingValue = brb.readBits(3);
sampleIsDifferenceSample = brb.readBits(1) == 1;
sampleDegradationPriority = brb.readBits(16);
}
public void getContent(ByteBuffer os) {
BitWriterBuffer bitWriterBuffer = new BitWriterBuffer(os);
bitWriterBuffer.writeBits(reserved, 6);
bitWriterBuffer.writeBits(sampleDependsOn, 2);
bitWriterBuffer.writeBits(sampleIsDependedOn, 2);
bitWriterBuffer.writeBits(sampleHasRedundancy, 2);
bitWriterBuffer.writeBits(samplePaddingValue, 3);
bitWriterBuffer.writeBits(this.sampleIsDifferenceSample ? 1 : 0, 1);
bitWriterBuffer.writeBits(sampleDegradationPriority, 16);
}
public int getReserved() {
return reserved;
}
public void setReserved(int reserved) {
this.reserved = reserved;
}
/**
* @see #setSampleDependsOn(int)
*/
public int getSampleDependsOn() {
return sampleDependsOn;
}
/**
* sample_depends_on takes one of the following four values:
* <pre>
* 0: the dependency of this sample is unknown;
* 1: this sample does depend on others (not an I picture);
* 2: this sample does not depend on others (I picture);
* 3: reserved
* </pre>
*
*/
public void setSampleDependsOn(int sampleDependsOn) {
this.sampleDependsOn = sampleDependsOn;
}
/**
* @see #setSampleIsDependedOn(int)
*/
public int getSampleIsDependedOn() {
return sampleIsDependedOn;
}
/**
* sample_is_depended_on takes one of the following four values:
* <pre>
* 0: the dependency of other samples on this sample is unknown;
* 1: other samples may depend on this one (not disposable);
* 2: no other sample depends on this one (disposable);
* 3: reserved
* </pre>
*
*/
public void setSampleIsDependedOn(int sampleIsDependedOn) {
this.sampleIsDependedOn = sampleIsDependedOn;
}
/**
* @see #setSampleHasRedundancy(int)
*/
public int getSampleHasRedundancy() {
return sampleHasRedundancy;
}
/**
* sample_has_redundancy takes one of the following four values:
* <pre>
* 0: it is unknown whether there is redundant coding in this sample;
* 1: there is redundant coding in this sample;
* 2: there is no redundant coding in this sample;
* 3: reserved
* </pre>
*/
public void setSampleHasRedundancy(int sampleHasRedundancy) {
this.sampleHasRedundancy = sampleHasRedundancy;
}
public int getSamplePaddingValue() {
return samplePaddingValue;
}
public void setSamplePaddingValue(int samplePaddingValue) {
this.samplePaddingValue = samplePaddingValue;
}
public boolean isSampleIsDifferenceSample() {
return sampleIsDifferenceSample;
}
public void setSampleIsDifferenceSample(boolean sampleIsDifferenceSample) {
this.sampleIsDifferenceSample = sampleIsDifferenceSample;
}
public int getSampleDegradationPriority() {
return sampleDegradationPriority;
}
public void setSampleDegradationPriority(int sampleDegradationPriority) {
this.sampleDegradationPriority = sampleDegradationPriority;
}
@Override
public String toString() {
return "SampleFlags{" +
"reserved=" + reserved +
", sampleDependsOn=" + sampleDependsOn +
", sampleHasRedundancy=" + sampleHasRedundancy +
", samplePaddingValue=" + samplePaddingValue +
", sampleIsDifferenceSample=" + sampleIsDifferenceSample +
", sampleDegradationPriority=" + sampleDegradationPriority +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SampleFlags that = (SampleFlags) o;
if (reserved != that.reserved) return false;
if (sampleDegradationPriority != that.sampleDegradationPriority) return false;
if (sampleDependsOn != that.sampleDependsOn) return false;
if (sampleHasRedundancy != that.sampleHasRedundancy) return false;
if (sampleIsDependedOn != that.sampleIsDependedOn) return false;
if (sampleIsDifferenceSample != that.sampleIsDifferenceSample) return false;
if (samplePaddingValue != that.samplePaddingValue) return false;
return true;
}
@Override
public int hashCode() {
int result = reserved;
result = 31 * result + sampleDependsOn;
result = 31 * result + sampleIsDependedOn;
result = 31 * result + sampleHasRedundancy;
result = 31 * result + samplePaddingValue;
result = 31 * result + (sampleIsDifferenceSample ? 1 : 0);
result = 31 * result + sampleDegradationPriority;
return result;
}
}
/*
* 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 com.coremedia.iso.boxes.fragment;
import com.coremedia.iso.IsoFile;
import com.coremedia.iso.IsoTypeReader;
import com.coremedia.iso.IsoTypeWriter;
import com.googlecode.mp4parser.AbstractBox;
import com.googlecode.mp4parser.annotations.DoNotParseDetail;
import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
/**
* This box identifies the specifications to which this file complies. <br>
* Each brand is a printable four-character code, registered with ISO, that
* identifies a precise specification.
*/
public class SegmentTypeBox extends AbstractBox {
public static final String TYPE = "styp";
private String majorBrand;
private long minorVersion;
private List<String> compatibleBrands = Collections.emptyList();
public SegmentTypeBox() {
super(TYPE);
}
public SegmentTypeBox(String majorBrand, long minorVersion, List<String> compatibleBrands) {
super(TYPE);
this.majorBrand = majorBrand;
this.minorVersion = minorVersion;
this.compatibleBrands = compatibleBrands;
}
protected long getContentSize() {
return 8 + compatibleBrands.size() * 4;
}
@Override
public void _parseDetails(ByteBuffer content) {
majorBrand = IsoTypeReader.read4cc(content);
minorVersion = IsoTypeReader.readUInt32(content);
int compatibleBrandsCount = content.remaining() / 4;
compatibleBrands = new LinkedList<String>();
for (int i = 0; i < compatibleBrandsCount; i++) {
compatibleBrands.add(IsoTypeReader.read4cc(content));
}
}
@Override
protected void getContent(ByteBuffer byteBuffer) {
byteBuffer.put(IsoFile.fourCCtoBytes(majorBrand));
IsoTypeWriter.writeUInt32(byteBuffer, minorVersion);
for (String compatibleBrand : compatibleBrands) {
byteBuffer.put(IsoFile.fourCCtoBytes(compatibleBrand));
}
}
/**
* Gets the brand identifier.
*
* @return the brand identifier
*/
public String getMajorBrand() {
return majorBrand;
}
/**
* Sets the major brand of the file used to determine an appropriate reader.
*
* @param majorBrand the new major brand
*/
public void setMajorBrand(String majorBrand) {
this.majorBrand = majorBrand;
}
/**
* Sets the "informative integer for the minor version of the major brand".
*
* @param minorVersion the version number of the major brand
*/
public void setMinorVersion(int minorVersion) {
this.minorVersion = minorVersion;
}
/**
* Gets an informative integer for the minor version of the major brand.
*
* @return an informative integer
* @see SegmentTypeBox#getMajorBrand()
*/
public long getMinorVersion() {
return minorVersion;
}
/**
* Gets an array of 4-cc brands.
*
* @return the compatible brands
*/
public List<String> getCompatibleBrands() {
return compatibleBrands;
}
public void setCompatibleBrands(List<String> compatibleBrands) {
this.compatibleBrands = compatibleBrands;
}
@DoNotParseDetail
public String toString() {
StringBuilder result = new StringBuilder();
result.append("SegmentTypeBox[");
result.append("majorBrand=").append(getMajorBrand());
result.append(";");
result.append("minorVersion=").append(getMinorVersion());
for (String compatibleBrand : compatibleBrands) {
result.append(";");
result.append("compatibleBrand=").append(compatibleBrand);
}
result.append("]");
return result.toString();
}
}
/*
* 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 com.coremedia.iso.boxes.fragment;
import com.coremedia.iso.IsoTypeReader;
import com.coremedia.iso.IsoTypeWriter;
import com.googlecode.mp4parser.AbstractFullBox;
import java.nio.ByteBuffer;
/**
* aligned(8) class TrackExtendsBox extends FullBox('trex', 0, 0){
* unsigned int(32) track_ID;
* unsigned int(32) default_sample_description_index;
* unsigned int(32) default_sample_duration;
* unsigned int(32) default_sample_size;
* unsigned int(32) default_sample_flags
* }
*/
public class TrackExtendsBox extends AbstractFullBox {
public static final String TYPE = "trex";
private long trackId;
private long defaultSampleDescriptionIndex;
private long defaultSampleDuration;
private long defaultSampleSize;
private SampleFlags defaultSampleFlags;
public TrackExtendsBox() {
super(TYPE);
}
@Override
protected long getContentSize() {
return 5 * 4 + 4;
}
@Override
protected void getContent(ByteBuffer byteBuffer) {
writeVersionAndFlags(byteBuffer);
IsoTypeWriter.writeUInt32(byteBuffer, trackId);
IsoTypeWriter.writeUInt32(byteBuffer, defaultSampleDescriptionIndex);
IsoTypeWriter.writeUInt32(byteBuffer, defaultSampleDuration);
IsoTypeWriter.writeUInt32(byteBuffer, defaultSampleSize);
defaultSampleFlags.getContent(byteBuffer);
}
@Override
public void _parseDetails(ByteBuffer content) {
parseVersionAndFlags(content);
trackId = IsoTypeReader.readUInt32(content);
defaultSampleDescriptionIndex = IsoTypeReader.readUInt32(content);
defaultSampleDuration = IsoTypeReader.readUInt32(content);
defaultSampleSize = IsoTypeReader.readUInt32(content);
defaultSampleFlags = new SampleFlags(content);
}
public long getTrackId() {
return trackId;
}
public long getDefaultSampleDescriptionIndex() {
return defaultSampleDescriptionIndex;
}
public long getDefaultSampleDuration() {
return defaultSampleDuration;
}
public long getDefaultSampleSize() {
return defaultSampleSize;
}
public SampleFlags getDefaultSampleFlags() {
return defaultSampleFlags;
}
public String getDefaultSampleFlagsStr() {
return defaultSampleFlags.toString();
}
public void setTrackId(long trackId) {
this.trackId = trackId;
}
public void setDefaultSampleDescriptionIndex(long defaultSampleDescriptionIndex) {
this.defaultSampleDescriptionIndex = defaultSampleDescriptionIndex;
}
public void setDefaultSampleDuration(long defaultSampleDuration) {
this.defaultSampleDuration = defaultSampleDuration;
}
public void setDefaultSampleSize(long defaultSampleSize) {
this.defaultSampleSize = defaultSampleSize;
}
public void setDefaultSampleFlags(SampleFlags defaultSampleFlags) {
this.defaultSampleFlags = defaultSampleFlags;
}
}
/*
* 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 com.coremedia.iso.boxes.fragment;
import com.coremedia.iso.IsoTypeReader;
import com.coremedia.iso.IsoTypeWriter;
import com.googlecode.mp4parser.AbstractFullBox;
import java.nio.ByteBuffer;
public class TrackFragmentBaseMediaDecodeTimeBox extends AbstractFullBox {
public static final String TYPE = "tfdt";
private long baseMediaDecodeTime;
public TrackFragmentBaseMediaDecodeTimeBox() {
super(TYPE);
}
@Override
protected long getContentSize() {
return getVersion() == 0 ? 8 : 12;
}
@Override
protected void getContent(ByteBuffer byteBuffer) {
writeVersionAndFlags(byteBuffer);
if (getVersion() == 1) {
IsoTypeWriter.writeUInt64(byteBuffer, baseMediaDecodeTime);
} else {
IsoTypeWriter.writeUInt32(byteBuffer, baseMediaDecodeTime);
}
}
@Override
public void _parseDetails(ByteBuffer content) {
parseVersionAndFlags(content);
if (getVersion() == 1) {
baseMediaDecodeTime = IsoTypeReader.readUInt64(content);
} else {
baseMediaDecodeTime = IsoTypeReader.readUInt32(content);
}
}
public long getBaseMediaDecodeTime() {
return baseMediaDecodeTime;
}
public void setBaseMediaDecodeTime(long baseMediaDecodeTime) {
this.baseMediaDecodeTime = baseMediaDecodeTime;
}
@Override
public String toString() {
return "TrackFragmentBaseMediaDecodeTimeBox{" +
"baseMediaDecodeTime=" + baseMediaDecodeTime +
'}';
}
}
/*
* 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 com.coremedia.iso.boxes.fragment;
import com.googlecode.mp4parser.AbstractContainerBox;
import com.coremedia.iso.boxes.Box;
/**
* aligned(8) class TrackFragmentBox extends Box('traf'){
* }
*/
public class TrackFragmentBox extends AbstractContainerBox {
public static final String TYPE = "traf";
public TrackFragmentBox() {
super(TYPE);
}
public TrackFragmentHeaderBox getTrackFragmentHeaderBox() {
for (Box box : getBoxes()) {
if (box instanceof TrackFragmentHeaderBox) {
return (TrackFragmentHeaderBox) box;
}
}
return null;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment