org.jaudiotagger.audio.mp4.atom
Class Mp4BoxHeader

java.lang.Object
  extended by org.jaudiotagger.audio.mp4.atom.Mp4BoxHeader
Direct Known Subclasses:
NullPadding

public class Mp4BoxHeader
extends java.lang.Object

Everything in MP4s are held in boxes (formally known as atoms), they are held as a hierachial tree within the MP4.

We are most interested in boxes that are used to hold metadata, but we have to know about some other boxes as well in order to find them.

All boxes consist of a 4 byte box length (big Endian), and then a 4 byte identifier, this is the header which is model in this class.

The length includes the length of the box including the identifier and the length itself. Then they may contain data and/or sub boxes, if they contain subboxes they are known as a parent box. Parent boxes shouldn't really contain data, but sometimes they do.

Parent boxes length includes the length of their immediate sub boxes

This class is normally used by instantiating with the empty constructor, then use the update method to pass the header data which is used to read the identifier and the the size of the box


Field Summary
static java.lang.String CHARSET_UTF_8
           
protected  java.nio.ByteBuffer dataBuffer
           
private  long filePos
           
static int HEADER_LENGTH
           
private  java.lang.String id
           
static int IDENTIFIER_LENGTH
           
static int IDENTIFIER_POS
           
protected  int length
           
static java.util.logging.Logger logger
           
static int OFFSET_LENGTH
           
static int OFFSET_POS
           
 
Constructor Summary
Mp4BoxHeader()
          Construct empty header

Can be populated later with update method

Mp4BoxHeader(java.nio.ByteBuffer headerData)
          Construct header

Create header using headerdata, expected to find header at headerdata current position

Note after processing adjusts position to immediately after header

Mp4BoxHeader(java.lang.String id)
          Construct header to allow manual creation of header for writing to file

 
Method Summary
 int getDataLength()
           
 java.lang.String getEncoding()
           
 long getFilePos()
           
 java.nio.ByteBuffer getHeaderData()
           
 java.lang.String getId()
           
 int getLength()
           
static Mp4BoxHeader seekWithinLevel(java.nio.ByteBuffer data, java.lang.String id)
          Seek for box with the specified id starting from the current location of filepointer,

Note it won't find the box if it is contained with a level below the current level, nor if we are at a parent atom that also contains data and we havent yet processed the data.

static Mp4BoxHeader seekWithinLevel(java.io.RandomAccessFile raf, java.lang.String id)
          Seek for box with the specified id starting from the current location of filepointer,

Note it wont find the box if it is contained with a level below the current level, nor if we are at a parent atom that also contains data and we havent yet processed the data.

 void setFilePos(long filePos)
          Set location in file of the start of file header (i.e where the 4 byte length field starts)
 void setId(int length)
          Set the Id.
 void setLength(int length)
          Set the length.
 java.lang.String toString()
           
 void update(java.nio.ByteBuffer headerData)
          Create header using headerdata, expected to find header at headerdata current position

Note after processing adjusts position to immediately after header

 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

public static java.util.logging.Logger logger

OFFSET_POS

public static final int OFFSET_POS
See Also:
Constant Field Values

IDENTIFIER_POS

public static final int IDENTIFIER_POS
See Also:
Constant Field Values

OFFSET_LENGTH

public static final int OFFSET_LENGTH
See Also:
Constant Field Values

IDENTIFIER_LENGTH

public static final int IDENTIFIER_LENGTH
See Also:
Constant Field Values

HEADER_LENGTH

public static final int HEADER_LENGTH
See Also:
Constant Field Values

id

private java.lang.String id

length

protected int length

filePos

private long filePos

dataBuffer

protected java.nio.ByteBuffer dataBuffer

CHARSET_UTF_8

public static final java.lang.String CHARSET_UTF_8
See Also:
Constant Field Values
Constructor Detail

Mp4BoxHeader

public Mp4BoxHeader()
Construct empty header

Can be populated later with update method


Mp4BoxHeader

public Mp4BoxHeader(java.lang.String id)
Construct header to allow manual creation of header for writing to file

Parameters:
id -

Mp4BoxHeader

public Mp4BoxHeader(java.nio.ByteBuffer headerData)
Construct header

Create header using headerdata, expected to find header at headerdata current position

Note after processing adjusts position to immediately after header

Parameters:
headerData -
Method Detail

update

public void update(java.nio.ByteBuffer headerData)
Create header using headerdata, expected to find header at headerdata current position

Note after processing adjusts position to immediately after header

Parameters:
headerData -

getId

public java.lang.String getId()
Returns:
the box identifier

getLength

public int getLength()
Returns:
the length of the boxes data (includes the header size)

setLength

public void setLength(int length)
Set the length.

This will modify the databuffer accordingly

Parameters:
length -

setId

public void setId(int length)
Set the Id.

Allows you to manully create a header This will modify the databuffer accordingly

Parameters:
length -

getHeaderData

public java.nio.ByteBuffer getHeaderData()
Returns:
the 8 byte header buffer

getDataLength

public int getDataLength()
Returns:
the length of the data only (does not include the header size)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getEncoding

public java.lang.String getEncoding()
Returns:
UTF_8 (always used by Mp4)

seekWithinLevel

public static Mp4BoxHeader seekWithinLevel(java.io.RandomAccessFile raf,
                                           java.lang.String id)
                                    throws java.io.IOException
Seek for box with the specified id starting from the current location of filepointer,

Note it wont find the box if it is contained with a level below the current level, nor if we are at a parent atom that also contains data and we havent yet processed the data. It will work if we are at the start of a child box even if it not the required box as long as the box we are looking for is the same level (or the level above in some cases).

Parameters:
raf -
id -
Returns:
Throws:
java.io.IOException

seekWithinLevel

public static Mp4BoxHeader seekWithinLevel(java.nio.ByteBuffer data,
                                           java.lang.String id)
                                    throws java.io.IOException
Seek for box with the specified id starting from the current location of filepointer,

Note it won't find the box if it is contained with a level below the current level, nor if we are at a parent atom that also contains data and we havent yet processed the data. It will work if we are at the start of a child box even if it not the required box as long as the box we are looking for is the same level (or the level above in some cases).

Parameters:
data -
id -
Returns:
Throws:
java.io.IOException

getFilePos

public long getFilePos()
Returns:
location in file of the start of file header (i.e where the 4 byte length field starts)

setFilePos

public void setFilePos(long filePos)
Set location in file of the start of file header (i.e where the 4 byte length field starts)

Parameters:
filePos -