org.red5.io.mp4
Class MP4Atom

java.lang.Object
  extended by org.red5.io.mp4.MP4Atom

public class MP4Atom
extends Object

The MP4Atom object represents the smallest information block of the MP4 file. It could contain other atoms as children. 01/29/2008 - Added support for avc1 atom (video sample) 02/05/2008 - Added stss - sync sample atom and stts - time to sample atom 10/2008 - Added pasp - pixel aspect ratio atom 10/2010 - Added ctts atom 11/2011 - Added wide, frma, chan, and terminator handling

Author:
Paul Gregoire ([email protected])

Nested Class Summary
static class MP4Atom.CompositionTimeSampleRecord
           
static class MP4Atom.Record
           
static class MP4Atom.TimeSampleRecord
           
 
Field Summary
protected  int avcLevel
           
protected  int avcProfile
           
protected  int balance
           
protected  List<MP4Atom> children
          The children of this atom.
protected  Vector<Long> chunks
          The decoding time to sample table.
protected  Vector<MP4Atom.CompositionTimeSampleRecord> comptimeToSamplesRecords
           
protected  Date creationTime
           
protected  long duration
           
protected  int entryCount
           
protected  MP4Descriptor esd_descriptor
           
protected  int fieldSize
           
protected  int flags
           
protected  int graphicsMode
           
protected  int handlerType
           
protected  int height
           
protected  Date modificationTime
           
protected  int opColorBlue
           
protected  int opColorGreen
           
protected  int opColorRed
           
protected  int qt_trackHeight
           
protected  int qt_trackWidth
           
protected  long readed
          The amount of bytes that are read from the mpeg stream.
protected  Vector<MP4Atom.Record> records
          The decoding time to sample table.
protected  int sampleCount
           
protected  Vector<Integer> samples
          The decoding time to sample table.
protected  int sampleSize
           
protected  long size
          The size of the atom.
protected  Vector<Integer> syncSamples
           
protected  int timeScale
           
protected  Vector<MP4Atom.TimeSampleRecord> timeToSamplesRecords
           
protected  long trackId
           
protected  int type
          The type of the atom.
protected  String uuid
          The user's extended type of the atom.
protected  int version
           
protected  int width
           
 
Constructor Summary
MP4Atom(long size, int type, String uuid, long readed)
           
 
Method Summary
 long create_audio_sample_entry_atom(MP4DataStream bitstream)
          Loads AudioSampleEntry atom from the input bitstream.
 long create_avc_config_atom(MP4DataStream bitstream)
          Loads AVCC atom from the input bitstream.
 long create_chan_atom(MP4DataStream bitstream)
          Loads Audio Channel Layout atom from the input bitstream.
 long create_chunk_large_offset_atom(MP4DataStream bitstream)
          Loads ChunkLargeOffset atom from the input bitstream.
 long create_chunk_offset_atom(MP4DataStream bitstream)
          Loads ChunkOffset atom from the input bitstream.
 long create_compact_sample_size_atom(MP4DataStream stream)
          Loads CompactSampleSize atom from the input stream.
 long create_composite_atom(MP4DataStream bitstream)
          Loads the composite atom from the input bitstream.
 long create_composition_time_to_sample_atom(MP4DataStream bitstream)
          Loads composition time to sample atom from the input bitstream.
 long create_esd_atom(MP4DataStream bitstream)
          Loads M4ESDAtom atom from the input bitstream.
 long create_full_atom(MP4DataStream bitstream)
          Loads the version of the full atom from the input bitstream.
 long create_handler_atom(MP4DataStream bitstream)
          Loads Handler atom from the input bitstream.
 long create_media_header_atom(MP4DataStream bitstream)
          Loads MediaHeader atom from the input bitstream.
 long create_meta_atom(MP4DataStream bitstream)
          Creates a meta data atom.
 long create_movie_header_atom(MP4DataStream bitstream)
          Loads MovieHeader atom from the input bitstream.
 long create_pasp_atom(MP4DataStream bitstream)
          Creates the PASP atom or Pixel Aspect Ratio.
 long create_sample_description_atom(MP4DataStream bitstream)
          Loads SampleDescription atom from the input bitstream.
 long create_sample_size_atom(MP4DataStream bitstream)
          Loads MP4SampleSizeAtom atom from the input bitstream.
 long create_sample_to_chunk_atom(MP4DataStream bitstream)
          Loads MP4SampleToChunkAtom atom from the input bitstream.
 long create_sound_media_header_atom(MP4DataStream bitstream)
          Loads MP4SoundMediaHeaderAtom atom from the input bitstream.
 long create_sync_sample_atom(MP4DataStream bitstream)
          Loads MP4SyncSampleAtom atom from the input bitstream.
 long create_time_to_sample_atom(MP4DataStream bitstream)
          Loads MP4TimeToSampleAtom atom from the input bitstream.
 long create_track_header_atom(MP4DataStream bitstream)
          Loads MP4TrackHeaderAtom atom from the input bitstream.
 long create_udta_atom(MP4DataStream bitstream)
          Creates a user data atom.
 long create_video_media_header_atom(MP4DataStream bitstream)
          Loads MP4VideoMediaHeaderAtom atom from the input bitstream.
 long create_video_sample_entry_atom(MP4DataStream bitstream)
          Loads MP4VideoSampleEntryAtom atom from the input bitstream.
 long create_visual_sample_entry_atom(MP4DataStream bitstream)
          Loads MP4VisualSampleEntryAtom atom from the input bitstream.
static MP4Atom createAtom(MP4DataStream bitstream)
          Constructs an Atom object from the data in the bitstream.
static Date createDate(long movieTime)
          Converts the time in seconds since midnight 1 Jan 1904 to the Date.
 int getAvcLevel()
           
 int getAvcProfile()
           
 int getChannelCount()
           
 List<MP4Atom> getChildren()
          Gets children from this atom.
 Vector<Long> getChunks()
           
 Vector<MP4Atom.CompositionTimeSampleRecord> getCompositionTimeToSamplesRecords()
           
 long getDuration()
           
 MP4Descriptor getEsd_descriptor()
          Returns the ESD descriptor.
 int getHandlerType()
          Gets the handler type.
 int getHeight()
           
 Vector<MP4Atom.Record> getRecords()
           
 Vector<Integer> getSamples()
           
 int getSampleSize()
           
 long getSize()
          Gets the size of this atom.
 Vector<Integer> getSyncSamples()
           
 int getTimeScale()
           
 Vector<MP4Atom.TimeSampleRecord> getTimeToSamplesRecords()
           
 int getType()
          Returns the type of this atom.
 byte[] getVideoConfigBytes()
           
 int getWidth()
           
static String intToType(int type)
          Convert the atom integer to a string.
 MP4Atom lookup(long type, int number)
          Lookups for a child atom with the specified type, skips the number children with the same type before finding a result.
 String toString()
          Returns the name of this atom.
static int typeToInt(String type)
          Convert the atom identifer to an integer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

size

protected long size
The size of the atom.


type

protected int type
The type of the atom.


uuid

protected String uuid
The user's extended type of the atom.


readed

protected long readed
The amount of bytes that are read from the mpeg stream.


children

protected List<MP4Atom> children
The children of this atom.


version

protected int version

flags

protected int flags

entryCount

protected int entryCount

chunks

protected Vector<Long> chunks
The decoding time to sample table.


handlerType

protected int handlerType

creationTime

protected Date creationTime

modificationTime

protected Date modificationTime

timeScale

protected int timeScale

duration

protected long duration

sampleSize

protected int sampleSize

sampleCount

protected int sampleCount

samples

protected Vector<Integer> samples
The decoding time to sample table.


fieldSize

protected int fieldSize

records

protected Vector<MP4Atom.Record> records
The decoding time to sample table.


syncSamples

protected Vector<Integer> syncSamples

timeToSamplesRecords

protected Vector<MP4Atom.TimeSampleRecord> timeToSamplesRecords

comptimeToSamplesRecords

protected Vector<MP4Atom.CompositionTimeSampleRecord> comptimeToSamplesRecords

balance

protected int balance

trackId

protected long trackId

qt_trackWidth

protected int qt_trackWidth

qt_trackHeight

protected int qt_trackHeight

graphicsMode

protected int graphicsMode

opColorRed

protected int opColorRed

opColorGreen

protected int opColorGreen

opColorBlue

protected int opColorBlue

width

protected int width

height

protected int height

avcLevel

protected int avcLevel

avcProfile

protected int avcProfile

esd_descriptor

protected MP4Descriptor esd_descriptor
Constructor Detail

MP4Atom

public MP4Atom(long size,
               int type,
               String uuid,
               long readed)
Method Detail

createAtom

public static final MP4Atom createAtom(MP4DataStream bitstream)
                                throws IOException
Constructs an Atom object from the data in the bitstream.

Parameters:
bitstream - the input bitstream
Returns:
the constructed atom.
Throws:
IOException

create_full_atom

public long create_full_atom(MP4DataStream bitstream)
                      throws IOException
Loads the version of the full atom from the input bitstream.

Parameters:
bitstream - the input bitstream
Returns:
the number of bytes which was being loaded.
Throws:
IOException

create_composite_atom

public long create_composite_atom(MP4DataStream bitstream)
                           throws IOException
Loads the composite atom from the input bitstream.

Parameters:
bitstream - the input bitstream
Returns:
the number of bytes which was being loaded.
Throws:
IOException

lookup

public MP4Atom lookup(long type,
                      int number)
Lookups for a child atom with the specified type, skips the number children with the same type before finding a result.

Parameters:
type - the type of the atom.
number - the number of atoms to skip
Returns:
the atom which was being searched.

getChannelCount

public int getChannelCount()

create_udta_atom

public long create_udta_atom(MP4DataStream bitstream)
                      throws IOException
Creates a user data atom.

Parameters:
bitstream -
Returns:
bytes read
Throws:
IOException

create_meta_atom

public long create_meta_atom(MP4DataStream bitstream)
                      throws IOException
Creates a meta data atom.

Parameters:
bitstream -
Returns:
bytes read
Throws:
IOException

create_audio_sample_entry_atom

public long create_audio_sample_entry_atom(MP4DataStream bitstream)
                                    throws IOException
Loads AudioSampleEntry atom from the input bitstream.

Parameters:
bitstream - the input bitstream
Returns:
the number of bytes which was being loaded.
Throws:
IOException

create_chunk_large_offset_atom

public long create_chunk_large_offset_atom(MP4DataStream bitstream)
                                    throws IOException
Loads ChunkLargeOffset atom from the input bitstream.

Parameters:
bitstream - the input bitstream
Returns:
the number of bytes which was being loaded.
Throws:
IOException

getChunks

public Vector<Long> getChunks()

create_chunk_offset_atom

public long create_chunk_offset_atom(MP4DataStream bitstream)
                              throws IOException
Loads ChunkOffset atom from the input bitstream.

Parameters:
bitstream - the input bitstream
Returns:
the number of bytes which was being loaded.
Throws:
IOException

create_handler_atom

public long create_handler_atom(MP4DataStream bitstream)
                         throws IOException
Loads Handler atom from the input bitstream.

Parameters:
bitstream - the input bitstream
Returns:
the number of bytes which was being loaded.
Throws:
IOException

getHandlerType

public int getHandlerType()
Gets the handler type.

Returns:
the handler type.

create_media_header_atom

public long create_media_header_atom(MP4DataStream bitstream)
                              throws IOException
Loads MediaHeader atom from the input bitstream.

Parameters:
bitstream - the input bitstream
Returns:
the number of bytes which was being loaded.
Throws:
IOException

getDuration

public long getDuration()

getTimeScale

public int getTimeScale()

create_movie_header_atom

public long create_movie_header_atom(MP4DataStream bitstream)
                              throws IOException
Loads MovieHeader atom from the input bitstream.

Parameters:
bitstream - the input bitstream
Returns:
the number of bytes which was being loaded.
Throws:
IOException

create_sample_description_atom

public long create_sample_description_atom(MP4DataStream bitstream)
                                    throws IOException
Loads SampleDescription atom from the input bitstream.

Parameters:
bitstream - the input bitstream
Returns:
the number of bytes which was being loaded.
Throws:
IOException

create_sample_size_atom

public long create_sample_size_atom(MP4DataStream bitstream)
                             throws IOException
Loads MP4SampleSizeAtom atom from the input bitstream.

Parameters:
bitstream - the input bitstream
Returns:
the number of bytes which was being loaded.
Throws:
IOException

getSamples

public Vector<Integer> getSamples()

getSampleSize

public int getSampleSize()

create_compact_sample_size_atom

public long create_compact_sample_size_atom(MP4DataStream stream)
                                     throws IOException
Loads CompactSampleSize atom from the input stream.

Parameters:
stream - the input stream
Returns:
the number of bytes which was being loaded.
Throws:
IOException

getRecords

public Vector<MP4Atom.Record> getRecords()

create_sample_to_chunk_atom

public long create_sample_to_chunk_atom(MP4DataStream bitstream)
                                 throws IOException
Loads MP4SampleToChunkAtom atom from the input bitstream.

Parameters:
bitstream - the input bitstream
Returns:
the number of bytes which was being loaded.
Throws:
IOException

getSyncSamples

public Vector<Integer> getSyncSamples()

create_sync_sample_atom

public long create_sync_sample_atom(MP4DataStream bitstream)
                             throws IOException
Loads MP4SyncSampleAtom atom from the input bitstream.

Parameters:
bitstream - the input bitstream
Returns:
the number of bytes which was being loaded.
Throws:
IOException

getTimeToSamplesRecords

public Vector<MP4Atom.TimeSampleRecord> getTimeToSamplesRecords()

create_time_to_sample_atom

public long create_time_to_sample_atom(MP4DataStream bitstream)
                                throws IOException
Loads MP4TimeToSampleAtom atom from the input bitstream.

Parameters:
bitstream - the input bitstream
Returns:
the number of bytes which was being loaded.
Throws:
IOException

create_sound_media_header_atom

public long create_sound_media_header_atom(MP4DataStream bitstream)
                                    throws IOException
Loads MP4SoundMediaHeaderAtom atom from the input bitstream.

Parameters:
bitstream - the input bitstream
Returns:
the number of bytes which was being loaded.
Throws:
IOException

create_track_header_atom

public long create_track_header_atom(MP4DataStream bitstream)
                              throws IOException
Loads MP4TrackHeaderAtom atom from the input bitstream.

Parameters:
bitstream - the input bitstream
Returns:
the number of bytes which was being loaded.
Throws:
IOException

create_video_media_header_atom

public long create_video_media_header_atom(MP4DataStream bitstream)
                                    throws IOException
Loads MP4VideoMediaHeaderAtom atom from the input bitstream.

Parameters:
bitstream - the input bitstream
Returns:
the number of bytes which was being loaded.
Throws:
IOException

create_visual_sample_entry_atom

public long create_visual_sample_entry_atom(MP4DataStream bitstream)
                                     throws IOException
Loads MP4VisualSampleEntryAtom atom from the input bitstream.

Parameters:
bitstream - the input bitstream
Returns:
the number of bytes which was being loaded.
Throws:
IOException

create_video_sample_entry_atom

public long create_video_sample_entry_atom(MP4DataStream bitstream)
                                    throws IOException
Loads MP4VideoSampleEntryAtom atom from the input bitstream.

Parameters:
bitstream - the input bitstream
Returns:
the number of bytes which was being loaded.
Throws:
IOException

getHeight

public int getHeight()

getWidth

public int getWidth()

getAvcLevel

public int getAvcLevel()

getAvcProfile

public int getAvcProfile()

getVideoConfigBytes

public byte[] getVideoConfigBytes()

create_avc_config_atom

public long create_avc_config_atom(MP4DataStream bitstream)
                            throws IOException
Loads AVCC atom from the input bitstream.
 8+ bytes ISO/IEC 14496-10 or 3GPP AVC decode config box
                          = long unsigned offset + long ASCII text string 'avcC'
                        -> 1 byte version = 8-bit hex version  (current = 1)
                        -> 1 byte H.264 profile = 8-bit unsigned stream profile
                        -> 1 byte H.264 compatible profiles = 8-bit hex flags
                        -> 1 byte H.264 level = 8-bit unsigned stream level
                        -> 1 1/2 nibble reserved = 6-bit unsigned value set to 63
                        -> 1/2 nibble NAL length = 2-bit length byte size type
                          - 1 byte = 0 ; 2 bytes = 1 ; 4 bytes = 3
                        -> 1 byte number of SPS = 8-bit unsigned total
                        -> 2+ bytes SPS length = short unsigned length
                        -> + SPS NAL unit = hexdump
                        -> 1 byte number of PPS = 8-bit unsigned total
                        -> 2+ bytes PPS length = short unsigned length
                        -> + PPS NAL unit = hexdump 
 

Parameters:
bitstream - the input bitstream
Returns:
the number of bytes which was being loaded.
Throws:
IOException

create_pasp_atom

public long create_pasp_atom(MP4DataStream bitstream)
                      throws IOException
Creates the PASP atom or Pixel Aspect Ratio. It is created by Quicktime when exporting an MP4 file. The atom is required for ipod's and acts as a container for the avcC atom in these cases.

Parameters:
bitstream - the input bitstream
Returns:
the number of bytes which was being loaded
Throws:
IOException

create_chan_atom

public long create_chan_atom(MP4DataStream bitstream)
                      throws IOException
Loads Audio Channel Layout atom from the input bitstream.

Parameters:
bitstream - the input bitstream
Returns:
the number of bytes which was being loaded.
Throws:
IOException

create_esd_atom

public long create_esd_atom(MP4DataStream bitstream)
                     throws IOException
Loads M4ESDAtom atom from the input bitstream.

Parameters:
bitstream - the input bitstream
Returns:
the number of bytes which was being loaded.
Throws:
IOException

getEsd_descriptor

public MP4Descriptor getEsd_descriptor()
Returns the ESD descriptor.


create_composition_time_to_sample_atom

public long create_composition_time_to_sample_atom(MP4DataStream bitstream)
                                            throws IOException
Loads composition time to sample atom from the input bitstream.

Parameters:
bitstream - the input bitstream
Returns:
the number of bytes which was being loaded.
Throws:
IOException

getCompositionTimeToSamplesRecords

public Vector<MP4Atom.CompositionTimeSampleRecord> getCompositionTimeToSamplesRecords()

createDate

public static final Date createDate(long movieTime)
Converts the time in seconds since midnight 1 Jan 1904 to the Date.

Parameters:
movieTime - the time in milliseconds since midnight 1 Jan 1904.
Returns:
the Date object.

typeToInt

public static int typeToInt(String type)
Convert the atom identifer to an integer.

Parameters:
type -
Returns:
atom type as an integer

intToType

public static String intToType(int type)
Convert the atom integer to a string.

Parameters:
type -
Returns:
atom type as a string

getChildren

public List<MP4Atom> getChildren()
Gets children from this atom.

Returns:
children from this atom.

getSize

public long getSize()
Gets the size of this atom.

Returns:
the size of this atom.

getType

public int getType()
Returns the type of this atom.


toString

public String toString()
Returns the name of this atom.

Overrides:
toString in class Object


Copyright © 2006-2012 The Red5 Project