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 1644 additions and 0 deletions
/*
* 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;
import com.coremedia.iso.IsoTypeReader;
import com.coremedia.iso.IsoTypeWriter;
import com.googlecode.mp4parser.FullContainerBox;
import java.nio.ByteBuffer;
/**
* The Item Protection Box provides an array of item protection information, for use by the Item Information Box.
*
* @see com.coremedia.iso.boxes.ItemProtectionBox
*/
public class ItemProtectionBox extends FullContainerBox {
public static final String TYPE = "ipro";
public ItemProtectionBox() {
super(TYPE);
}
public SchemeInformationBox getItemProtectionScheme() {
if (!getBoxes(SchemeInformationBox.class).isEmpty()) {
return getBoxes(SchemeInformationBox.class).get(0);
} else {
return null;
}
}
@Override
public void _parseDetails(ByteBuffer content) {
parseVersionAndFlags(content);
IsoTypeReader.readUInt16(content);
parseChildBoxes(content);
}
@Override
protected void getContent(ByteBuffer byteBuffer) {
writeVersionAndFlags(byteBuffer);
IsoTypeWriter.writeUInt16(byteBuffer, getBoxes().size());
writeChildBoxes(byteBuffer);
}
}
/*
* 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;
import com.coremedia.iso.IsoTypeReader;
import com.coremedia.iso.IsoTypeWriter;
import com.coremedia.iso.Utf8;
import com.googlecode.mp4parser.AbstractFullBox;
import java.nio.ByteBuffer;
/**
* List of keywords according to 3GPP 26.244.
*/
public class KeywordsBox extends AbstractFullBox {
public static final String TYPE = "kywd";
private String language;
private String[] keywords;
public KeywordsBox() {
super(TYPE);
}
public String getLanguage() {
return language;
}
public String[] getKeywords() {
return keywords;
}
public void setLanguage(String language) {
this.language = language;
}
public void setKeywords(String[] keywords) {
this.keywords = keywords;
}
protected long getContentSize() {
long contentSize = 7;
for (String keyword : keywords) {
contentSize += 1 + Utf8.utf8StringLengthInBytes(keyword) + 1;
}
return contentSize;
}
@Override
public void _parseDetails(ByteBuffer content) {
parseVersionAndFlags(content);
language = IsoTypeReader.readIso639(content);
int keywordCount = IsoTypeReader.readUInt8(content);
keywords = new String[keywordCount];
for (int i = 0; i < keywordCount; i++) {
IsoTypeReader.readUInt8(content);
keywords[i] = IsoTypeReader.readString(content);
}
}
@Override
protected void getContent(ByteBuffer byteBuffer) {
writeVersionAndFlags(byteBuffer);
IsoTypeWriter.writeIso639(byteBuffer, language);
IsoTypeWriter.writeUInt8(byteBuffer, keywords.length);
for (String keyword : keywords) {
IsoTypeWriter.writeUInt8(byteBuffer, Utf8.utf8StringLengthInBytes(keyword) + 1);
byteBuffer.put(Utf8.convert(keyword));
}
}
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("KeywordsBox[language=").append(getLanguage());
for (int i = 0; i < keywords.length; i++) {
buffer.append(";keyword").append(i).append("=").append(keywords[i]);
}
buffer.append("]");
return buffer.toString();
}
}
/*
* 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;
import com.coremedia.iso.IsoTypeReader;
import com.coremedia.iso.IsoTypeWriter;
import com.googlecode.mp4parser.AbstractContainerBox;
import com.googlecode.mp4parser.util.ByteBufferByteChannel;
import java.io.IOException;
import java.nio.ByteBuffer;
/**
* A common base structure to contain general metadata. See ISO/IEC 14496-12 Ch. 8.44.1.
*/
public class MetaBox extends AbstractContainerBox {
private int version = 0;
private int flags = 0;
public static final String TYPE = "meta";
public MetaBox() {
super(TYPE);
}
@Override
public long getContentSize() {
if (isMp4Box()) {
// it's a fullbox
return 4 + super.getContentSize();
} else {
// it's an apple metabox
return super.getContentSize();
}
}
@Override
public long getNumOfBytesToFirstChild() {
if (isMp4Box()) {
// it's a fullbox
return 12;
} else {
// it's an apple metabox
return 8;
}
}
@Override
public void _parseDetails(ByteBuffer content) {
int pos = content.position();
content.get(new byte[4]);
String isHdlr = IsoTypeReader.read4cc(content);
if ("hdlr".equals(isHdlr)) {
// this is apple bullshit - it's NO FULLBOX
content.position(pos);
version = -1;
flags = -1;
} else {
content.position(pos);
version = IsoTypeReader.readUInt8(content);
flags = IsoTypeReader.readUInt24(content);
}
while (content.remaining() >= 8) {
try {
boxes.add(boxParser.parseBox(new ByteBufferByteChannel(content), this));
} catch (IOException e) {
throw new RuntimeException("Sebastian needs to fix 7518765283");
}
}
if (content.remaining() > 0) {
throw new RuntimeException("Sebastian needs to fix it 90732r26537");
}
}
@Override
protected void getContent(ByteBuffer byteBuffer) {
if (isMp4Box()) {
IsoTypeWriter.writeUInt8(byteBuffer, version);
IsoTypeWriter.writeUInt24(byteBuffer, flags);
}
writeChildBoxes(byteBuffer);
}
public boolean isMp4Box() {
return version != -1 && flags != -1;
}
public void setMp4Box(boolean mp4) {
if (mp4) {
version = 0;
flags = 0;
} else {
version = -1;
flags = -1;
}
}
}
/*
* Copyright 2011 Sebastian Annies, Hamburg, Germany
*
* 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;
import java.nio.ByteBuffer;
/**
* Streams other than visual and audio (e.g., timed metadata streams) may use a
* Null Media Header Box.
*/
public class NullMediaHeaderBox extends AbstractMediaHeaderBox {
public NullMediaHeaderBox() {
super("nmhd");
}
@Override
protected long getContentSize() {
return 4;
}
@Override
public void _parseDetails(ByteBuffer content) {
parseVersionAndFlags(content);
}
@Override
protected void getContent(ByteBuffer byteBuffer) {
writeVersionAndFlags(byteBuffer);
}
}
/*
* 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;
import com.coremedia.iso.IsoTypeReader;
import com.coremedia.iso.IsoTypeWriter;
import com.googlecode.mp4parser.AbstractFullBox;
import java.nio.ByteBuffer;
/**
* Describes the format of media access units in PDCF files.
*/
public final class OmaDrmAccessUnitFormatBox extends AbstractFullBox {
public static final String TYPE = "odaf";
private boolean selectiveEncryption;
private byte allBits;
private int keyIndicatorLength;
private int initVectorLength;
protected long getContentSize() {
return 7;
}
public OmaDrmAccessUnitFormatBox() {
super("odaf");
}
public boolean isSelectiveEncryption() {
return selectiveEncryption;
}
public int getKeyIndicatorLength() {
return keyIndicatorLength;
}
public int getInitVectorLength() {
return initVectorLength;
}
public void setInitVectorLength(int initVectorLength) {
this.initVectorLength = initVectorLength;
}
public void setKeyIndicatorLength(int keyIndicatorLength) {
this.keyIndicatorLength = keyIndicatorLength;
}
public void setAllBits(byte allBits) {
this.allBits = allBits;
selectiveEncryption = (allBits & 0x80) == 0x80;
}
@Override
public void _parseDetails(ByteBuffer content) {
parseVersionAndFlags(content);
allBits = (byte) IsoTypeReader.readUInt8(content);
selectiveEncryption = (allBits & 0x80) == 0x80;
keyIndicatorLength = IsoTypeReader.readUInt8(content);
initVectorLength = IsoTypeReader.readUInt8(content);
}
@Override
protected void getContent(ByteBuffer byteBuffer) {
writeVersionAndFlags(byteBuffer);
IsoTypeWriter.writeUInt8(byteBuffer, allBits);
IsoTypeWriter.writeUInt8(byteBuffer, keyIndicatorLength);
IsoTypeWriter.writeUInt8(byteBuffer, initVectorLength);
}
}
/*
* 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;
import com.coremedia.iso.IsoFile;
import com.coremedia.iso.IsoTypeReader;
import com.googlecode.mp4parser.AbstractBox;
import java.nio.ByteBuffer;
/**
* The Original Format Box contains the four-character-code of the original untransformed sample description.
* See ISO/IEC 14496-12 for details.
*
* @see ProtectionSchemeInformationBox
*/
public class OriginalFormatBox extends AbstractBox {
public static final String TYPE = "frma";
private String dataFormat = " ";
public OriginalFormatBox() {
super("frma");
}
public String getDataFormat() {
return dataFormat;
}
public void setDataFormat(String dataFormat) {
assert dataFormat.length() == 4;
this.dataFormat = dataFormat;
}
protected long getContentSize() {
return 4;
}
@Override
public void _parseDetails(ByteBuffer content) {
dataFormat = IsoTypeReader.read4cc(content);
}
@Override
protected void getContent(ByteBuffer byteBuffer) {
byteBuffer.put(IsoFile.fourCCtoBytes(dataFormat));
}
public String toString() {
return "OriginalFormatBox[dataFormat=" + getDataFormat() + "]";
}
}
/*
* 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;
import com.coremedia.iso.IsoTypeReader;
import com.coremedia.iso.IsoTypeWriter;
import com.coremedia.iso.Utf8;
import com.googlecode.mp4parser.AbstractFullBox;
import java.nio.ByteBuffer;
/**
* Used to give information about the performer. Mostly used in confunction with music files.
* See 3GPP 26.234 for details.
*/
public class PerformerBox extends AbstractFullBox {
public static final String TYPE = "perf";
private String language;
private String performer;
public PerformerBox() {
super(TYPE);
}
public String getLanguage() {
return language;
}
public String getPerformer() {
return performer;
}
public void setLanguage(String language) {
this.language = language;
}
public void setPerformer(String performer) {
this.performer = performer;
}
protected long getContentSize() {
return 6 + Utf8.utf8StringLengthInBytes(performer) + 1;
}
@Override
protected void getContent(ByteBuffer byteBuffer) {
writeVersionAndFlags(byteBuffer);
IsoTypeWriter.writeIso639(byteBuffer, language);
byteBuffer.put(Utf8.convert(performer));
byteBuffer.put((byte) 0);
}
@Override
public void _parseDetails(ByteBuffer content) {
parseVersionAndFlags(content);
language = IsoTypeReader.readIso639(content);
performer = IsoTypeReader.readString(content);
}
public String toString() {
return "PerformerBox[language=" + getLanguage() + ";performer=" + getPerformer() + "]";
}
}
package com.coremedia.iso.boxes;
import com.coremedia.iso.IsoTypeReader;
import com.coremedia.iso.IsoTypeWriter;
import com.googlecode.mp4parser.AbstractFullBox;
import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
public class ProgressiveDownloadInformationBox extends AbstractFullBox {
List<Entry> entries = Collections.emptyList();
public ProgressiveDownloadInformationBox() {
super("pdin");
}
@Override
protected long getContentSize() {
return 4 + entries.size() * 8;
}
@Override
protected void getContent(ByteBuffer byteBuffer) {
writeVersionAndFlags(byteBuffer);
for (Entry entry : entries) {
IsoTypeWriter.writeUInt32(byteBuffer, entry.getRate());
IsoTypeWriter.writeUInt32(byteBuffer, entry.getInitialDelay());
}
}
public List<Entry> getEntries() {
return entries;
}
public void setEntries(List<Entry> entries) {
this.entries = entries;
}
@Override
public void _parseDetails(ByteBuffer content) {
parseVersionAndFlags(content);
entries = new LinkedList<Entry>();
while (content.remaining() >= 8) {
Entry entry = new Entry(IsoTypeReader.readUInt32(content), IsoTypeReader.readUInt32(content));
entries.add(entry);
}
}
public static class Entry {
long rate;
long initialDelay;
public Entry(long rate, long initialDelay) {
this.rate = rate;
this.initialDelay = initialDelay;
}
public long getRate() {
return rate;
}
public void setRate(long rate) {
this.rate = rate;
}
public long getInitialDelay() {
return initialDelay;
}
public void setInitialDelay(long initialDelay) {
this.initialDelay = initialDelay;
}
@Override
public String toString() {
return "Entry{" +
"rate=" + rate +
", initialDelay=" + initialDelay +
'}';
}
}
@Override
public String toString() {
return "ProgressiveDownloadInfoBox{" +
"entries=" + entries +
'}';
}
}
\ No newline at end of file
/*
* 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;
import com.googlecode.mp4parser.AbstractContainerBox;
/**
* The <code>ProtectionSchemeInformationBox</code> contains all the information required both
* to understand the encryption transform applied and its parameters, and also to find other
* information such as the kind and location of the key management system. It also documents the
* the original (unencrypted) format of the media. The <code>ProtectionSchemeInformationBox</code>
* is a container box. It is mandatory in a sample entry that uses a code idicating a
* protected stream.
*
* @see com.coremedia.iso.boxes.odf.OmaDrmKeyManagenentSystemBox
* @see com.coremedia.iso.boxes.sampleentry.AudioSampleEntry#TYPE_ENCRYPTED
* @see com.coremedia.iso.boxes.sampleentry.VisualSampleEntry#TYPE_ENCRYPTED
*/
public class ProtectionSchemeInformationBox extends AbstractContainerBox {
public static final String TYPE = "sinf";
public ProtectionSchemeInformationBox() {
super(TYPE);
}
}
/*
* 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;
import com.coremedia.iso.IsoFile;
import com.coremedia.iso.IsoTypeReader;
import com.coremedia.iso.IsoTypeWriter;
import com.coremedia.iso.Utf8;
import com.googlecode.mp4parser.AbstractFullBox;
import java.nio.ByteBuffer;
/**
* Contained a the <code>UserDataBox</code> and containing information about the media's rating. E.g.
* PG13or FSK16.
*/
public class RatingBox extends AbstractFullBox {
public static final String TYPE = "rtng";
private String ratingEntity;
private String ratingCriteria;
private String language;
private String ratingInfo;
public RatingBox() {
super(TYPE);
}
public void setRatingEntity(String ratingEntity) {
this.ratingEntity = ratingEntity;
}
public void setRatingCriteria(String ratingCriteria) {
this.ratingCriteria = ratingCriteria;
}
public void setLanguage(String language) {
this.language = language;
}
public void setRatingInfo(String ratingInfo) {
this.ratingInfo = ratingInfo;
}
public String getLanguage() {
return language;
}
/**
* Gets a four-character code that indicates the rating entity grading the asset, e.g., 'BBFC'. The values of this
* field should follow common names of worldwide movie rating systems, such as those mentioned in
* [http://www.movie-ratings.net/, October 2002].
*
* @return the rating organization
*/
public String getRatingEntity() {
return ratingEntity;
}
/**
* Gets the four-character code that indicates which rating criteria are being used for the corresponding rating
* entity, e.g., 'PG13'.
*
* @return the actual rating
*/
public String getRatingCriteria() {
return ratingCriteria;
}
public String getRatingInfo() {
return ratingInfo;
}
protected long getContentSize() {
return 15 + Utf8.utf8StringLengthInBytes(ratingInfo);
}
@Override
public void _parseDetails(ByteBuffer content) {
parseVersionAndFlags(content);
ratingEntity = IsoTypeReader.read4cc(content);
ratingCriteria = IsoTypeReader.read4cc(content);
language = IsoTypeReader.readIso639(content);
ratingInfo = IsoTypeReader.readString(content);
}
@Override
protected void getContent(ByteBuffer byteBuffer) {
writeVersionAndFlags(byteBuffer);
byteBuffer.put(IsoFile.fourCCtoBytes(ratingEntity));
byteBuffer.put(IsoFile.fourCCtoBytes(ratingCriteria));
IsoTypeWriter.writeIso639(byteBuffer, language);
byteBuffer.put(Utf8.convert(ratingInfo));
byteBuffer.put((byte) 0);
}
public String toString() {
StringBuilder buffer = new StringBuilder();
buffer.append("RatingBox[language=").append(getLanguage());
buffer.append("ratingEntity=").append(getRatingEntity());
buffer.append(";ratingCriteria=").append(getRatingCriteria());
buffer.append(";language=").append(getLanguage());
buffer.append(";ratingInfo=").append(getRatingInfo());
buffer.append("]");
return buffer.toString();
}
}
/*
* 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;
import com.coremedia.iso.IsoTypeReader;
import com.coremedia.iso.IsoTypeWriter;
import com.googlecode.mp4parser.AbstractFullBox;
import java.nio.ByteBuffer;
/**
*
*/
public class RecordingYearBox extends AbstractFullBox {
public static final String TYPE = "yrrc";
int recordingYear;
public RecordingYearBox() {
super(TYPE);
}
protected long getContentSize() {
return 6;
}
public int getRecordingYear() {
return recordingYear;
}
public void setRecordingYear(int recordingYear) {
this.recordingYear = recordingYear;
}
@Override
public void _parseDetails(ByteBuffer content) {
parseVersionAndFlags(content);
recordingYear = IsoTypeReader.readUInt16(content);
}
@Override
protected void getContent(ByteBuffer byteBuffer) {
writeVersionAndFlags(byteBuffer);
IsoTypeWriter.writeUInt16(byteBuffer, recordingYear);
}
}
/*
* 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;
import com.coremedia.iso.IsoTypeReader;
import com.coremedia.iso.IsoTypeWriter;
import com.googlecode.mp4parser.AbstractFullBox;
import java.nio.ByteBuffer;
import java.util.LinkedList;
import java.util.List;
import static com.googlecode.mp4parser.util.CastUtils.l2i;
/*
aligned(8) class SampleAuxiliaryInformationOffsetsBox
extends FullBox(saio, version, flags)
{
if (flags & 1) {
unsigned int(32) aux_info_type;
unsigned int(32) aux_info_type_parameter;
}
unsigned int(32) entry_count;
if ( version == 0 )
{
unsigned int(32) offset[ entry_count ];
}
else
{
unsigned int(64) offset[ entry_count ];
}
}
*/
public class SampleAuxiliaryInformationOffsetsBox extends AbstractFullBox {
public static final String TYPE = "saio";
private List<Long> offsets = new LinkedList<Long>();
private long auxInfoType;
private long auxInfoTypeParameter;
public SampleAuxiliaryInformationOffsetsBox() {
super(TYPE);
}
@Override
protected long getContentSize() {
return 8 + (getVersion() == 0 ? 4 * offsets.size() : 8 * offsets.size()) + ((getFlags() & 1) == 1 ? 8 : 0);
}
@Override
protected void getContent(ByteBuffer byteBuffer) {
writeVersionAndFlags(byteBuffer);
if ((getFlags() & 1) == 1) {
IsoTypeWriter.writeUInt32(byteBuffer, auxInfoType);
IsoTypeWriter.writeUInt32(byteBuffer, auxInfoTypeParameter);
}
IsoTypeWriter.writeUInt32(byteBuffer, offsets.size());
for (Long offset : offsets) {
if (getVersion() == 0) {
IsoTypeWriter.writeUInt32(byteBuffer, offset);
} else {
IsoTypeWriter.writeUInt64(byteBuffer, offset);
}
}
}
@Override
public void _parseDetails(ByteBuffer content) {
parseVersionAndFlags(content);
if ((getFlags() & 1) == 1) {
auxInfoType = IsoTypeReader.readUInt32(content);
auxInfoTypeParameter = IsoTypeReader.readUInt32(content);
}
int entryCount = l2i(IsoTypeReader.readUInt32(content));
offsets.clear();
for (int i = 0; i < entryCount; i++) {
if (getVersion() == 0) {
offsets.add(IsoTypeReader.readUInt32(content));
} else {
offsets.add(IsoTypeReader.readUInt64(content));
}
}
}
public long getAuxInfoType() {
return auxInfoType;
}
public void setAuxInfoType(long auxInfoType) {
this.auxInfoType = auxInfoType;
}
public long getAuxInfoTypeParameter() {
return auxInfoTypeParameter;
}
public void setAuxInfoTypeParameter(long auxInfoTypeParameter) {
this.auxInfoTypeParameter = auxInfoTypeParameter;
}
public List<Long> getOffsets() {
return offsets;
}
public void setOffsets(List<Long> offsets) {
this.offsets = offsets;
}
}
/*
* 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;
import com.coremedia.iso.IsoFile;
import com.coremedia.iso.IsoTypeReader;
import com.coremedia.iso.IsoTypeWriter;
import com.googlecode.mp4parser.AbstractFullBox;
import java.nio.ByteBuffer;
import java.util.LinkedList;
import java.util.List;
import static com.googlecode.mp4parser.util.CastUtils.l2i;
public class SampleAuxiliaryInformationSizesBox extends AbstractFullBox {
public static final String TYPE = "saiz";
private int defaultSampleInfoSize;
private List<Short> sampleInfoSizes = new LinkedList<Short>();
private int sampleCount;
private String auxInfoType;
private String auxInfoTypeParameter;
public SampleAuxiliaryInformationSizesBox() {
super(TYPE);
}
@Override
protected long getContentSize() {
int size = 4;
if ((getFlags() & 1) == 1) {
size += 8;
}
size += 5;
size += defaultSampleInfoSize == 0 ? sampleInfoSizes.size() : 0;
return size;
}
@Override
protected void getContent(ByteBuffer byteBuffer) {
writeVersionAndFlags(byteBuffer);
if ((getFlags() & 1) == 1) {
byteBuffer.put(IsoFile.fourCCtoBytes(auxInfoType));
byteBuffer.put(IsoFile.fourCCtoBytes(auxInfoTypeParameter));
}
IsoTypeWriter.writeUInt8(byteBuffer, defaultSampleInfoSize);
if (defaultSampleInfoSize == 0) {
IsoTypeWriter.writeUInt32(byteBuffer, sampleInfoSizes.size());
for (short sampleInfoSize : sampleInfoSizes) {
IsoTypeWriter.writeUInt8(byteBuffer, sampleInfoSize);
}
} else {
IsoTypeWriter.writeUInt32(byteBuffer, sampleCount);
}
}
@Override
public void _parseDetails(ByteBuffer content) {
parseVersionAndFlags(content);
if ((getFlags() & 1) == 1) {
auxInfoType = IsoTypeReader.read4cc(content);
auxInfoTypeParameter = IsoTypeReader.read4cc(content);
}
defaultSampleInfoSize = (short) IsoTypeReader.readUInt8(content);
sampleCount = l2i(IsoTypeReader.readUInt32(content));
sampleInfoSizes.clear();
if (defaultSampleInfoSize == 0) {
for (int i = 0; i < sampleCount; i++) {
sampleInfoSizes.add((short) IsoTypeReader.readUInt8(content));
}
}
}
public String getAuxInfoType() {
return auxInfoType;
}
public void setAuxInfoType(String auxInfoType) {
this.auxInfoType = auxInfoType;
}
public String getAuxInfoTypeParameter() {
return auxInfoTypeParameter;
}
public void setAuxInfoTypeParameter(String auxInfoTypeParameter) {
this.auxInfoTypeParameter = auxInfoTypeParameter;
}
public int getDefaultSampleInfoSize() {
return defaultSampleInfoSize;
}
public void setDefaultSampleInfoSize(int defaultSampleInfoSize) {
assert defaultSampleInfoSize <= 255;
this.defaultSampleInfoSize = defaultSampleInfoSize;
}
public List<Short> getSampleInfoSizes() {
return sampleInfoSizes;
}
public void setSampleInfoSizes(List<Short> sampleInfoSizes) {
this.sampleInfoSizes = sampleInfoSizes;
}
public int getSampleCount() {
return sampleCount;
}
public void setSampleCount(int sampleCount) {
this.sampleCount = sampleCount;
}
@Override
public String toString() {
return "SampleAuxiliaryInformationSizesBox{" +
"defaultSampleInfoSize=" + defaultSampleInfoSize +
", sampleCount=" + sampleCount +
", auxInfoType='" + auxInfoType + '\'' +
", auxInfoTypeParameter='" + auxInfoTypeParameter + '\'' +
'}';
}
}
/*
* 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;
import com.googlecode.mp4parser.AbstractContainerBox;
/**
* The Scheme Information Box is a container box that is only interpreted by the scheme beeing used.
* Any information the encryption system needs is stored here. The content of this box is a series of
* boxexes whose type annd format are defined by the scheme declared in the {@link com.coremedia.iso.boxes.SchemeTypeBox}.
*/
public class SchemeInformationBox extends AbstractContainerBox {
public static final String TYPE = "schi";
public SchemeInformationBox() {
super(TYPE);
}
}
/*
* 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;
import com.coremedia.iso.IsoFile;
import com.coremedia.iso.IsoTypeReader;
import com.coremedia.iso.IsoTypeWriter;
import com.coremedia.iso.Utf8;
import com.googlecode.mp4parser.AbstractFullBox;
import java.nio.ByteBuffer;
/**
* The Scheme Type Box identifies the protection scheme. Resides in a Protection Scheme Information Box or
* an SRTP Process Box.
*
* @see com.coremedia.iso.boxes.SchemeInformationBox
*/
public class SchemeTypeBox extends AbstractFullBox {
public static final String TYPE = "schm";
String schemeType = " ";
long schemeVersion;
String schemeUri = null;
public SchemeTypeBox() {
super(TYPE);
}
public String getSchemeType() {
return schemeType;
}
public long getSchemeVersion() {
return schemeVersion;
}
public String getSchemeUri() {
return schemeUri;
}
public void setSchemeType(String schemeType) {
assert schemeType != null && schemeType.length() == 4 : "SchemeType may not be null or not 4 bytes long";
this.schemeType = schemeType;
}
public void setSchemeVersion(int schemeVersion) {
this.schemeVersion = schemeVersion;
}
public void setSchemeUri(String schemeUri) {
this.schemeUri = schemeUri;
}
protected long getContentSize() {
return 12 + (((getFlags() & 1) == 1) ? Utf8.utf8StringLengthInBytes(schemeUri) + 1 : 0);
}
@Override
public void _parseDetails(ByteBuffer content) {
parseVersionAndFlags(content);
schemeType = IsoTypeReader.read4cc(content);
schemeVersion = IsoTypeReader.readUInt32(content);
if ((getFlags() & 1) == 1) {
schemeUri = IsoTypeReader.readString(content);
}
}
@Override
protected void getContent(ByteBuffer byteBuffer) {
writeVersionAndFlags(byteBuffer);
byteBuffer.put(IsoFile.fourCCtoBytes(schemeType));
IsoTypeWriter.writeUInt32(byteBuffer, schemeVersion);
if ((getFlags() & 1) == 1) {
byteBuffer.put(Utf8.convert(schemeUri));
}
}
public String toString() {
StringBuilder buffer = new StringBuilder();
buffer.append("Schema Type Box[");
buffer.append("schemeUri=").append(schemeUri).append("; ");
buffer.append("schemeType=").append(schemeType).append("; ");
buffer.append("schemeVersion=").append(schemeUri).append("; ");
buffer.append("]");
return buffer.toString();
}
}
package com.coremedia.iso.boxes;
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;
import static com.googlecode.mp4parser.util.CastUtils.l2i;
/**
* aligned(8) class SubSampleInformationBox
* extends FullBox('subs', version, 0) {
* unsigned int(32) entry_count;
* int i,j;
* for (i=0; i < entry_count; i++) {
* unsigned int(32) sample_delta;
* unsigned int(16) subsample_count;
* if (subsample_count > 0) {
* for (j=0; j < subsample_count; j++) {
* if(version == 1)
* {
* unsigned int(32) subsample_size;
* }
* else
* {
* unsigned int(16) subsample_size;
* }
* unsigned int(8) subsample_priority;
* unsigned int(8) discardable;
* unsigned int(32) reserved = 0;
* }
* }
* }
* }
*/
public class SubSampleInformationBox extends AbstractFullBox {
public static final String TYPE = "subs";
private long entryCount;
private List<SampleEntry> entries = new ArrayList<SampleEntry>();
public SubSampleInformationBox() {
super(TYPE);
}
public List<SampleEntry> getEntries() {
return entries;
}
public void setEntries(List<SampleEntry> entries) {
this.entries = entries;
entryCount = entries.size();
}
@Override
protected long getContentSize() {
long entries = 8 + ((4 + 2) * entryCount);
int subsampleEntries = 0;
for (SampleEntry sampleEntry : this.entries) {
subsampleEntries += sampleEntry.getSubsampleCount() * (((getVersion() == 1) ? 4 : 2) + 1 + 1 + 4);
}
return entries + subsampleEntries;
}
@Override
public void _parseDetails(ByteBuffer content) {
parseVersionAndFlags(content);
entryCount = IsoTypeReader.readUInt32(content);
for (int i = 0; i < entryCount; i++) {
SampleEntry sampleEntry = new SampleEntry();
sampleEntry.setSampleDelta(IsoTypeReader.readUInt32(content));
int subsampleCount = IsoTypeReader.readUInt16(content);
for (int j = 0; j < subsampleCount; j++) {
SampleEntry.SubsampleEntry subsampleEntry = new SampleEntry.SubsampleEntry();
subsampleEntry.setSubsampleSize(getVersion() == 1 ? IsoTypeReader.readUInt32(content) : IsoTypeReader.readUInt16(content));
subsampleEntry.setSubsamplePriority(IsoTypeReader.readUInt8(content));
subsampleEntry.setDiscardable(IsoTypeReader.readUInt8(content));
subsampleEntry.setReserved(IsoTypeReader.readUInt32(content));
sampleEntry.addSubsampleEntry(subsampleEntry);
}
entries.add(sampleEntry);
}
}
@Override
protected void getContent(ByteBuffer byteBuffer) {
writeVersionAndFlags(byteBuffer);
IsoTypeWriter.writeUInt32(byteBuffer, entries.size());
for (SampleEntry sampleEntry : entries) {
IsoTypeWriter.writeUInt32(byteBuffer, sampleEntry.getSampleDelta());
IsoTypeWriter.writeUInt16(byteBuffer, sampleEntry.getSubsampleCount());
List<SampleEntry.SubsampleEntry> subsampleEntries = sampleEntry.getSubsampleEntries();
for (SampleEntry.SubsampleEntry subsampleEntry : subsampleEntries) {
if (getVersion() == 1) {
IsoTypeWriter.writeUInt32(byteBuffer, subsampleEntry.getSubsampleSize());
} else {
IsoTypeWriter.writeUInt16(byteBuffer, l2i(subsampleEntry.getSubsampleSize()));
}
IsoTypeWriter.writeUInt8(byteBuffer, subsampleEntry.getSubsamplePriority());
IsoTypeWriter.writeUInt8(byteBuffer, subsampleEntry.getDiscardable());
IsoTypeWriter.writeUInt32(byteBuffer, subsampleEntry.getReserved());
}
}
}
@Override
public String toString() {
return "SubSampleInformationBox{" +
"entryCount=" + entryCount +
", entries=" + entries +
'}';
}
public static class SampleEntry {
private long sampleDelta;
private int subsampleCount;
private List<SubsampleEntry> subsampleEntries = new ArrayList<SubsampleEntry>();
public long getSampleDelta() {
return sampleDelta;
}
public void setSampleDelta(long sampleDelta) {
this.sampleDelta = sampleDelta;
}
public int getSubsampleCount() {
return subsampleCount;
}
public void setSubsampleCount(int subsampleCount) {
this.subsampleCount = subsampleCount;
}
public List<SubsampleEntry> getSubsampleEntries() {
return subsampleEntries;
}
public void addSubsampleEntry(SubsampleEntry subsampleEntry) {
subsampleEntries.add(subsampleEntry);
subsampleCount++;
}
public static class SubsampleEntry {
private long subsampleSize;
private int subsamplePriority;
private int discardable;
private long reserved;
public long getSubsampleSize() {
return subsampleSize;
}
public void setSubsampleSize(long subsampleSize) {
this.subsampleSize = subsampleSize;
}
public int getSubsamplePriority() {
return subsamplePriority;
}
public void setSubsamplePriority(int subsamplePriority) {
this.subsamplePriority = subsamplePriority;
}
public int getDiscardable() {
return discardable;
}
public void setDiscardable(int discardable) {
this.discardable = discardable;
}
public long getReserved() {
return reserved;
}
public void setReserved(long reserved) {
this.reserved = reserved;
}
@Override
public String toString() {
return "SubsampleEntry{" +
"subsampleSize=" + subsampleSize +
", subsamplePriority=" + subsamplePriority +
", discardable=" + discardable +
", reserved=" + reserved +
'}';
}
}
@Override
public String toString() {
return "SampleEntry{" +
"sampleDelta=" + sampleDelta +
", subsampleCount=" + subsampleCount +
", subsampleEntries=" + subsampleEntries +
'}';
}
}
}
package com.coremedia.iso.boxes;
import java.nio.ByteBuffer;
public class SubtitleMediaHeaderBox extends AbstractMediaHeaderBox {
public static final String TYPE = "sthd";
public SubtitleMediaHeaderBox() {
super(TYPE);
}
protected long getContentSize() {
return 4;
}
@Override
public void _parseDetails(ByteBuffer content) {
parseVersionAndFlags(content);
}
@Override
protected void getContent(ByteBuffer byteBuffer) {
writeVersionAndFlags(byteBuffer);
}
public String toString() {
return "SubtitleMediaHeaderBox";
}
}
/*
* 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;
import com.coremedia.iso.IsoTypeReader;
import com.coremedia.iso.IsoTypeWriter;
import com.coremedia.iso.Utf8;
import com.googlecode.mp4parser.AbstractFullBox;
import java.nio.ByteBuffer;
/**
* <code>
* Box Type: 'titl'<br>
* Container: {@link UserDataBox} ('udta')<br>
* Mandatory: No<br>
* Quantity: Zero or one<br><br>
* </code>
* <p/>
* Title for the media.
*/
public class TitleBox extends AbstractFullBox {
public static final String TYPE = "titl";
private String language;
private String title;
public TitleBox() {
super(TYPE);
}
public String getLanguage() {
return language;
}
public String getTitle() {
return title;
}
/**
* Sets the 3-letter ISO-639 language for this title.
*
* @param language 3-letter ISO-639 code
*/
public void setLanguage(String language) {
this.language = language;
}
public void setTitle(String title) {
this.title = title;
}
protected long getContentSize() {
return 7 + Utf8.utf8StringLengthInBytes(title);
}
protected void getContent(ByteBuffer byteBuffer) {
writeVersionAndFlags(byteBuffer);
IsoTypeWriter.writeIso639(byteBuffer, language);
byteBuffer.put(Utf8.convert(title));
byteBuffer.put((byte) 0);
}
@Override
public void _parseDetails(ByteBuffer content) {
parseVersionAndFlags(content);
language = IsoTypeReader.readIso639(content);
title = IsoTypeReader.readString(content);
}
public String toString() {
return "TitleBox[language=" + getLanguage() + ";title=" + getTitle() + "]";
}
}
/*
* 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;
import com.googlecode.mp4parser.AbstractContainerBox;
/**
* <code>
* Box Type: 'tref'<br>
* Container: {@link TrackBox} ('trak')<br>
* Mandatory: No<br>
* Quantity: Zero or one<br><br>
* </code>
* This box provides a reference from the containing track to another track in the presentation. These references
* are typed. A 'hint' reference links from the containing hint track to the media data that it hints. A content
* description reference 'cdsc' links a descriptive or metadata track to the content which it describes.
* Exactly one Track Reference Box can be contained within the Track Box.
* If this box is not present, the track is not referencing any other track in any way. The reference array is sized
* to fill the reference type box.
*/
public class TrackReferenceBox extends AbstractContainerBox {
public static final String TYPE = "tref";
public TrackReferenceBox() {
super(TYPE);
}
}
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