org.jaudiotagger.audio.mp4
Class Mp4TagWriter

java.lang.Object
  extended by org.jaudiotagger.audio.mp4.Mp4TagWriter

public class Mp4TagWriter
extends java.lang.Object

Writes metadata from mp4, the metadata tags are held under the ilst atom as shown below

When writing changes the size of all the atoms upto ilst has to be recalculated, then if the size of the metadata is increased the size of the free atom (below meta) should be reduced accordingly or vice versa. If the size of the metadata has increased by more than the size of the free atom then the size of meta, udta and moov should be recalculated and the top level free atom reduced accordingly If there is not enough space even if using both of the free atoms, then the mdat atom has to be shifted down accordingly to make space, and the stco atom has to have its offsets to mdat chunks table adjusted accordingly. Exceptions are that the meta/udta/ilst do not currently exist, in which udta/meta/ilst are created. Note it is valid to have meta/ilst without udta but this is less common so we always try to write files according to the Apple/iTunes specification. *

 |--- ftyp
 |--- moov
 |......|
 |......|----- mvdh
 |......|----- trak
 |......|----- udta
 |..............|
 |..............|-- meta
 |....................|
 |....................|-- hdlr
 |....................|-- ilst
 |....................|.. ..|
 |....................|.....|---- @nam (Optional for each metadatafield)
 |....................|.....|.......|-- data
 |....................|.....|....... ecetera
 |....................|.....|---- ---- (Optional for reverse dns field)
 |....................|.............|-- mean
 |....................|.............|-- name
 |....................|.............|-- data
 |....................|................ ecetere
 |....................|-- free
 |--- free
 |--- mdat
 


Field Summary
static java.util.logging.Logger logger
           
private  Mp4TagCreator tc
           
 
Constructor Summary
Mp4TagWriter()
           
 
Method Summary
private  void adjustSizeOfMoovHeader(Mp4BoxHeader moovHeader, java.nio.ByteBuffer moovBuffer, int sizeAdjustment, Mp4BoxHeader udtaHeader, Mp4BoxHeader metaHeader)
          When the size of the metadata has changed and it cant be compensated for by free atom we have to adjust the size of the size field upto the moovheader level for the udta atom and its child meta atom.
private  void checkFileWrittenCorrectly(java.io.RandomAccessFile rafTemp, Mp4BoxHeader mdatHeader, java.nio.channels.FileChannel fileWriteChannel, Mp4StcoBox stco)
          Check File Written Correctly
private  void createMetadataAtoms(Mp4BoxHeader moovHeader, java.nio.ByteBuffer moovBuffer, int sizeAdjustment, Mp4BoxHeader udtaHeader, Mp4BoxHeader metaHeader)
           
 void delete(java.io.RandomAccessFile raf, java.io.RandomAccessFile rafTemp)
          Delete the tag

 void write(Tag tag, java.io.RandomAccessFile raf, java.io.RandomAccessFile rafTemp)
          Write tag to rafTemp file
private  void writeMetadataSameSize(java.nio.ByteBuffer rawIlstData, long oldIlstSize, long startIstWithinFile, java.nio.channels.FileChannel fileReadChannel, java.nio.channels.FileChannel fileWriteChannel)
          Replace the ilst metadata

Because it is the same size as the original data nothing else has to be modified

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

Field Detail

logger

public static java.util.logging.Logger logger

tc

private Mp4TagCreator tc
Constructor Detail

Mp4TagWriter

public Mp4TagWriter()
Method Detail

writeMetadataSameSize

private void writeMetadataSameSize(java.nio.ByteBuffer rawIlstData,
                                   long oldIlstSize,
                                   long startIstWithinFile,
                                   java.nio.channels.FileChannel fileReadChannel,
                                   java.nio.channels.FileChannel fileWriteChannel)
                            throws CannotWriteException,
                                   java.io.IOException
Replace the ilst metadata

Because it is the same size as the original data nothing else has to be modified

Parameters:
rawIlstData -
oldIlstSize -
startIstWithinFile -
fileReadChannel -
fileWriteChannel -
Throws:
CannotWriteException
java.io.IOException

adjustSizeOfMoovHeader

private void adjustSizeOfMoovHeader(Mp4BoxHeader moovHeader,
                                    java.nio.ByteBuffer moovBuffer,
                                    int sizeAdjustment,
                                    Mp4BoxHeader udtaHeader,
                                    Mp4BoxHeader metaHeader)
                             throws java.io.IOException
When the size of the metadata has changed and it cant be compensated for by free atom we have to adjust the size of the size field upto the moovheader level for the udta atom and its child meta atom.

Parameters:
moovHeader -
moovBuffer -
sizeAdjustment - can be negative or positive *
udtaHeader -
metaHeader -
Throws:
java.io.IOException

createMetadataAtoms

private void createMetadataAtoms(Mp4BoxHeader moovHeader,
                                 java.nio.ByteBuffer moovBuffer,
                                 int sizeAdjustment,
                                 Mp4BoxHeader udtaHeader,
                                 Mp4BoxHeader metaHeader)
                          throws java.io.IOException
Throws:
java.io.IOException

write

public void write(Tag tag,
                  java.io.RandomAccessFile raf,
                  java.io.RandomAccessFile rafTemp)
           throws CannotWriteException,
                  java.io.IOException
Write tag to rafTemp file

Parameters:
tag - tag data
raf - current file
rafTemp - temporary file for writing
Throws:
CannotWriteException
java.io.IOException

checkFileWrittenCorrectly

private void checkFileWrittenCorrectly(java.io.RandomAccessFile rafTemp,
                                       Mp4BoxHeader mdatHeader,
                                       java.nio.channels.FileChannel fileWriteChannel,
                                       Mp4StcoBox stco)
                                throws CannotWriteException,
                                       java.io.IOException
Check File Written Correctly

Parameters:
rafTemp -
mdatHeader -
fileWriteChannel -
stco -
Throws:
CannotWriteException
java.io.IOException

delete

public void delete(java.io.RandomAccessFile raf,
                   java.io.RandomAccessFile rafTemp)
            throws java.io.IOException
Delete the tag

This is achieved by writing an empty ilst atom

Parameters:
raf -
rafTemp -
Throws:
java.io.IOException