## org.red5.io.mp4
Class MP4Atom

    java.lang.Object
      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

Author:
  Paul Gregoire (mondain@gmail.com)

Nested Class Summary
`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 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`
`static int` `MP4AudioSampleEntryAtomType` Constant, the type of the MP4 Atom.
`static int` `MP4AVCAtomType`
`static int` `MP4ChunkLargeOffsetAtomType` Constant, the type of the MP4 Atom.
`static int` `MP4ChunkOffsetAtomType` Constant, the type of the MP4 Atom.
`static int` `MP4CompactSampleSizeAtomType` Constant, the type of the MP4 Atom.
`static int` `MP4DataInformationAtomType` Constant, the type of the MP4 Atom.
`static int` `MP4ESDAtomType` Constant, the type of the MP4 Atom.
`static int` `MP4ExtendedAtomType` Constant, the type of the MP4 Atom.
`static int` `MP4HandlerAtomType` Constant, the type of the MP4 Atom.
`static int` `MP4MediaAtomType` Constant, the type of the MP4 Atom.
`static int` `MP4MediaHeaderAtomType` Constant, the type of the MP4 Atom.
`static int` `MP4MediaInformationAtomType` Constant, the type of the MP4 Atom.
`static int` `MP4MovieAtomType` Constant, the type of the MP4 Atom.
`static int` `MP4MovieDataType`
`static int` `MP4MovieHeaderAtomType` Constant, the type of the MP4 Atom.
`static int` `MP4PixelAspectAtomType`
`static int` `MP4SampleDescriptionAtomType` Constant, the type of the MP4 Atom.
`static int` `MP4SampleSizeAtomType` Constant, the type of the MP4 Atom.
`static int` `MP4SampleTableAtomType` Constant, the type of the MP4 Atom.
`static int` `MP4SampleToChunkAtomType` Constant, the type of the MP4 Atom.
`static int` `MP4SoundMediaHeaderAtomType` Constant, the type of the MP4 Atom.
`static int` `MP4SyncSampleAtomType`
`static int` `MP4TimeToSampleAtomType`
`static int` `MP4TrackAtomType` Constant, the type of the MP4 Atom.
`static int` `MP4TrackHeaderAtomType` Constant, the type of the MP4 Atom.
`static int` `MP4VideoMediaHeaderAtomType` Constant, the type of the MP4 Atom.
`static int` `MP4VideoSampleEntryAtomType`
`static int` `MP4VisualSampleEntryAtomType` Constant, the type of the MP4 Atom.
`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 readed 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_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_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_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_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()`
`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)`
`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)`

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

Field Detail

### MP4AudioSampleEntryAtomType

    public static final int MP4AudioSampleEntryAtomType

  Constant, the type of the MP4 Atom.

### MP4ChunkLargeOffsetAtomType

    public static final int MP4ChunkLargeOffsetAtomType

  Constant, the type of the MP4 Atom.

### MP4ChunkOffsetAtomType

    public static final int MP4ChunkOffsetAtomType

  Constant, the type of the MP4 Atom.

### MP4DataInformationAtomType

    public static final int MP4DataInformationAtomType

  Constant, the type of the MP4 Atom.

### MP4ESDAtomType

    public static final int MP4ESDAtomType

  Constant, the type of the MP4 Atom.

### MP4ExtendedAtomType

    public static final int MP4ExtendedAtomType

  Constant, the type of the MP4 Atom.

### MP4HandlerAtomType

    public static final int MP4HandlerAtomType

  Constant, the type of the MP4 Atom.

### MP4MediaAtomType

    public static final int MP4MediaAtomType

  Constant, the type of the MP4 Atom.

### MP4MediaHeaderAtomType

    public static final int MP4MediaHeaderAtomType

  Constant, the type of the MP4 Atom.

### MP4MediaInformationAtomType

    public static final int MP4MediaInformationAtomType

  Constant, the type of the MP4 Atom.

### MP4MovieAtomType

    public static final int MP4MovieAtomType

  Constant, the type of the MP4 Atom.

### MP4MovieHeaderAtomType

    public static final int MP4MovieHeaderAtomType

  Constant, the type of the MP4 Atom.

### MP4SampleDescriptionAtomType

    public static final int MP4SampleDescriptionAtomType

  Constant, the type of the MP4 Atom.

### MP4SampleSizeAtomType

    public static final int MP4SampleSizeAtomType

  Constant, the type of the MP4 Atom.

### MP4CompactSampleSizeAtomType

    public static final int MP4CompactSampleSizeAtomType

  Constant, the type of the MP4 Atom.

### MP4SampleTableAtomType

    public static final int MP4SampleTableAtomType

  Constant, the type of the MP4 Atom.

### MP4SampleToChunkAtomType

    public static final int MP4SampleToChunkAtomType

  Constant, the type of the MP4 Atom.

### MP4SoundMediaHeaderAtomType

    public static final int MP4SoundMediaHeaderAtomType

  Constant, the type of the MP4 Atom.

### MP4TrackAtomType

    public static final int MP4TrackAtomType

  Constant, the type of the MP4 Atom.

### MP4TrackHeaderAtomType

    public static final int MP4TrackHeaderAtomType

  Constant, the type of the MP4 Atom.

### MP4VideoMediaHeaderAtomType

    public static final int MP4VideoMediaHeaderAtomType

  Constant, the type of the MP4 Atom.

### MP4VisualSampleEntryAtomType

    public static final int MP4VisualSampleEntryAtomType

  Constant, the type of the MP4 Atom.

### MP4VideoSampleEntryAtomType

    public static final int MP4VideoSampleEntryAtomType

### MP4SyncSampleAtomType

    public static final int MP4SyncSampleAtomType

### MP4TimeToSampleAtomType

    public static final int MP4TimeToSampleAtomType

### MP4AVCAtomType

    public static final int MP4AVCAtomType

### MP4MovieDataType

    public static final int MP4MovieDataType

### MP4PixelAspectAtomType

    public static final int MP4PixelAspectAtomType

### 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 readed 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

### 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 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_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_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.

### 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)

### intToType

    public static String intToType(int type)

### 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-2010 The Red5 Project