org.red5.io.mp4.impl

## Class MP4

- java.lang.Object
- - org.red5.io.mp4.impl.MP4

All Implemented Interfaces:
  IStreamableFile, IMP4

    public class MP4
    extends Object
    implements IMP4

A MP4Impl implements the MP4 api

Author:
  The Red5 Project (red5@osflash.org), Paul Gregoire, (mondain@gmail.com)

### Field Summary

Fields
`protected static org.slf4j.Logger` `log`

### Constructor Summary

Constructors
Constructor and Description
`MP4()` Default constructor, used by Spring so that parameters may be injected.
`MP4(File file)` Create MP4 from given file source.

### Method Summary

Methods
`void` `flushHeaders()` Flushes Header
`ITagWriter` `getAppendWriter()` Returns a Writer which is setup to append to the file.
`Map<?,?>` `getKeyFrameData()` Gets the keyframe data
`IMetaData<?,?>` `getMetaData()` Returns a map of the metadata
`ITagReader` `getReader()` Returns a reader to parse and read the tags inside the file.
`ITagWriter` `getWriter()` Returns a writer that creates a new file or truncates existing contents.
`boolean` `hasKeyFrameData()` Returns a boolean stating whether a mp4 has keyframedata
`boolean` `hasMetaData()` Returns a boolean stating whether the mp4 has metadata
`ITagReader` `readerFromNearestKeyFrame(int seekPoint)` Returns a Reader closest to the nearest keyframe
`void` `refreshHeaders()` Refreshes the headers.
`void` `setKeyFrameData(Map<?,?> keyframedata)` Sets the keyframe data of a mp4 file
`void` `setMetaData(IMetaData<?,?> meta)` Sets the metadata
`void` `setMetaService(IMetaService service)` Sets the MetaService through Spring
`ITagWriter` `writerFromNearestKeyFrame(int seekPoint)` Returns a Writer based on the nearest key frame

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### log

    protected static org.slf4j.Logger log

### Constructor Detail

#### MP4

    public MP4()

Default constructor, used by Spring so that parameters may be injected.

#### MP4

    public MP4(File file)

Create MP4 from given file source.

Parameters:
  `file` - File source

### Method Detail

#### hasMetaData

    public boolean hasMetaData()

Returns a boolean stating whether the mp4 has metadata

Specified by:
  `hasMetaData` in interface `IMP4`
Returns:
  boolean `true` if file has injected metadata, `false` otherwise

#### getMetaData

    public IMetaData<?,?> getMetaData()
                               throws FileNotFoundException

Returns a map of the metadata

Specified by:
  `getMetaData` in interface `IMP4`
Returns:
  metadata File metadata
Throws:
  `FileNotFoundException` - File not found

#### hasKeyFrameData

    public boolean hasKeyFrameData()

Returns a boolean stating whether a mp4 has keyframedata

Specified by:
  `hasKeyFrameData` in interface `IMP4`
Returns:
  boolean `true` if file has keyframe metadata, `false` otherwise

#### setKeyFrameData

    public void setKeyFrameData(Map<?,?> keyframedata)

Sets the keyframe data of a mp4 file

Specified by:
  `setKeyFrameData` in interface `IMP4`
Parameters:
  `keyframedata` - Keyframe metadata

#### getKeyFrameData

    public Map<?,?> getKeyFrameData()

Gets the keyframe data

Specified by:
  `getKeyFrameData` in interface `IMP4`
Returns:
  keyframedata Keyframe metadata

#### refreshHeaders

    public void refreshHeaders()
                        throws IOException

Refreshes the headers. Usually used after data is added to the mp4 file

Specified by:
  `refreshHeaders` in interface `IMP4`
Throws:
  `IOException` - Any I/O exception

#### flushHeaders

    public void flushHeaders()
                      throws IOException

Flushes Header

Specified by:
  `flushHeaders` in interface `IMP4`
Throws:
  `IOException` - Any I/O exception

#### getReader

    public ITagReader getReader()
                         throws IOException

Returns a reader to parse and read the tags inside the file.

Specified by:
  `getReader` in interface `IStreamableFile`
Returns:
  the reader Tag reader
Throws:
  `IOException` - I/O exception

#### readerFromNearestKeyFrame

    public ITagReader readerFromNearestKeyFrame(int seekPoint)

Returns a Reader closest to the nearest keyframe

Specified by:
  `readerFromNearestKeyFrame` in interface `IMP4`
Parameters:
  `seekPoint` - Point in file we are seeking around
Returns:
  reader Tag reader closest to that point

#### getWriter

    public ITagWriter getWriter()
                         throws IOException

Returns a writer that creates a new file or truncates existing contents.

Specified by:
  `getWriter` in interface `IStreamableFile`
Returns:
  the writer Tag writer
Throws:
  `IOException` - I/O exception

#### writerFromNearestKeyFrame

    public ITagWriter writerFromNearestKeyFrame(int seekPoint)

Returns a Writer based on the nearest key frame

Specified by:
  `writerFromNearestKeyFrame` in interface `IMP4`
Parameters:
  `seekPoint` - Point in file we are seeking around
Returns:
  writer Tag writer closest to that point

#### setMetaData

    public void setMetaData(IMetaData<?,?> meta)
                     throws IOException

Sets the metadata

Specified by:
  `setMetaData` in interface `IMP4`
Parameters:
  `meta` - Metadata object
Throws:
  `FileNotFoundException` - File not found
  `IOException` - Any other I/O exception

#### setMetaService

    public void setMetaService(IMetaService service)

Sets the MetaService through Spring

Specified by:
  `setMetaService` in interface `IMP4`
Parameters:
  `service` - Metadata service

#### getAppendWriter

    public ITagWriter getAppendWriter()
                               throws IOException

Description copied from interface: `IStreamableFile`
Returns a Writer which is setup to append to the file.

Specified by:
  `getAppendWriter` in interface `IStreamableFile`
Returns:
  the writer Tag writer used for append mode
Throws:
  `IOException` - I/O exception