Package org.red5.io.flv.impl
Class FLVReader
- java.lang.Object
-
- org.red5.io.flv.impl.FLVReader
-
- All Implemented Interfaces:
IKeyFrameDataAnalyzer,IoConstants,ITagReader
public class FLVReader extends Object implements IoConstants, ITagReader, IKeyFrameDataAnalyzer
A Reader is used to read the contents of a FLV file. NOTE: This class is not implemented as threading-safe. The caller should make sure the threading-safety.- Author:
- The Red5 Project, Dominick Accattato (daccattato@gmail.com), Luke Hubbard, Codegent Ltd (luke@codegent.com), Paul Gregoire, (mondain@gmail.com)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.red5.io.flv.IKeyFrameDataAnalyzer
IKeyFrameDataAnalyzer.KeyFrameMeta
-
-
Field Summary
-
Fields inherited from interface org.red5.io.IoConstants
AVC_PACKET_TYPE_END_OF_SEQUENCE, AVC_PACKET_TYPE_NALU, AVC_PACKET_TYPE_SEQUENCE_HEADER, FLAG_CODEC_H263, FLAG_CODEC_SCREEN, FLAG_CODEC_VP6, FLAG_FORMAT_ADPCM, FLAG_FORMAT_MP3, FLAG_FORMAT_NELLYMOSER, FLAG_FORMAT_NELLYMOSER_8_KHZ, FLAG_FORMAT_RAW, FLAG_FRAMETYPE_DISPOSABLE, FLAG_FRAMETYPE_GENERATED_KEYFRAME, FLAG_FRAMETYPE_INFO, FLAG_FRAMETYPE_INTERFRAME, FLAG_FRAMETYPE_KEYFRAME, FLAG_RATE_11_KHZ, FLAG_RATE_22_KHZ, FLAG_RATE_44_KHZ, FLAG_RATE_48_KHZ, FLAG_RATE_5_5_KHZ, FLAG_SIZE_16_BIT, FLAG_SIZE_8_BIT, FLAG_TYPE_MONO, FLAG_TYPE_STEREO, INFO_PACKET_SEEK_END, INFO_PACKET_SEEK_START, MASK_SOUND_FORMAT, MASK_SOUND_RATE, MASK_SOUND_SIZE, MASK_SOUND_TYPE, MASK_VIDEO_CODEC, MASK_VIDEO_FRAMETYPE, TYPE_AUDIO, TYPE_ENCRYPTED, TYPE_ENCRYPTED_AUDIO, TYPE_ENCRYPTED_METADATA, TYPE_ENCRYPTED_VIDEO, TYPE_METADATA, TYPE_VIDEO
-
-
Constructor Summary
Constructors Constructor Description FLVReader(File f)Creates FLV reader from file input stream.FLVReader(File f, boolean generateMetadata)Creates FLV reader from file input stream, sets up metadata generation flag.FLVReader(FileChannel channel)Creates FLV reader from file channel.FLVReader(org.apache.mina.core.buffer.IoBuffer buffer, boolean generateMetadata)Accepts mapped file bytes to construct internal members.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description IKeyFrameDataAnalyzer.KeyFrameMetaanalyzeKeyFrames()Key frames analysis may be used as a utility method so synchronize it.voidclose()Closes the reader and free any allocated memory.voiddecodeHeader()Decode the header of the stream;intgetAudioCodecId()static intgetBufferSize()Getter for buffer size.static StringgetBufferType()Getter for buffer type (auto, direct or heap).longgetBytesRead()Returns the amount of bytes readlonggetDuration()Return length in secondsstatic intgetDuration(File flvFile)Returns the last tag's timestamp as the files duration.IStreamableFilegetFile()Return the file that is loaded.org.apache.mina.core.buffer.IoBuffergetFileData()Returns the file buffer.intgetOffset()Returns the offet lengthlonggetTotalBytes()Get the total readable bytes in a file or ByteBuffer.intgetVideoCodecId()booleanhasMoreTags()Returns a boolean stating whether the FLV has more tagsbooleanhasVideo()Check if the reader also has video tags.voidposition(long pos)Put the current position to pos.ITagreadTag()Returns a Tag objectstatic voidsetBufferSize(int bufferSize)Setter for property 'bufferSize'.static voidsetBufferType(String bufferType)Setter for buffer type.voidsetKeyFrameCache(IKeyFrameMetaCache keyframeCache)
-
-
-
Constructor Detail
-
FLVReader
public FLVReader(File f) throws IOException
Creates FLV reader from file input stream.- Parameters:
f- File- Throws:
IOException- on error
-
FLVReader
public FLVReader(File f, boolean generateMetadata) throws IOException
Creates FLV reader from file input stream, sets up metadata generation flag.- Parameters:
f- File input streamgenerateMetadata-trueif metadata generation required,falseotherwise- Throws:
IOException- on error
-
FLVReader
public FLVReader(FileChannel channel) throws IOException
Creates FLV reader from file channel.- Parameters:
channel- file channel- Throws:
IOException- on error
-
FLVReader
public FLVReader(org.apache.mina.core.buffer.IoBuffer buffer, boolean generateMetadata)Accepts mapped file bytes to construct internal members.- Parameters:
generateMetadata-trueif metadata generation required,falseotherwisebuffer- IoBuffer
-
-
Method Detail
-
setKeyFrameCache
public void setKeyFrameCache(IKeyFrameMetaCache keyframeCache)
-
getTotalBytes
public long getTotalBytes()
Get the total readable bytes in a file or ByteBuffer.- Specified by:
getTotalBytesin interfaceITagReader- Returns:
- Total readable bytes
-
hasVideo
public boolean hasVideo()
Check if the reader also has video tags.- Specified by:
hasVideoin interfaceITagReader- Returns:
- has video
-
getBufferType
public static String getBufferType()
Getter for buffer type (auto, direct or heap).- Returns:
- Value for property 'bufferType'
-
setBufferType
public static void setBufferType(String bufferType)
Setter for buffer type.- Parameters:
bufferType- Value to set for property 'bufferType'
-
getBufferSize
public static int getBufferSize()
Getter for buffer size.- Returns:
- Value for property 'bufferSize'
-
setBufferSize
public static void setBufferSize(int bufferSize)
Setter for property 'bufferSize'.- Parameters:
bufferSize- Value to set for property 'bufferSize'
-
getFileData
public org.apache.mina.core.buffer.IoBuffer getFileData()
Returns the file buffer.- Returns:
- File contents as byte buffer
-
decodeHeader
public void decodeHeader()
Decode the header of the stream;- Specified by:
decodeHeaderin interfaceITagReader
-
getFile
public IStreamableFile getFile()
Return the file that is loaded.- Specified by:
getFilein interfaceITagReader- Returns:
- the file to be loaded
-
getOffset
public int getOffset()
Returns the offet length- Specified by:
getOffsetin interfaceITagReader- Returns:
- int
-
getBytesRead
public long getBytesRead()
Returns the amount of bytes read- Specified by:
getBytesReadin interfaceITagReader- Returns:
- long
-
getDuration
public long getDuration()
Return length in seconds- Specified by:
getDurationin interfaceITagReader- Returns:
- length in seconds
-
getVideoCodecId
public int getVideoCodecId()
-
getAudioCodecId
public int getAudioCodecId()
-
hasMoreTags
public boolean hasMoreTags()
Returns a boolean stating whether the FLV has more tags- Specified by:
hasMoreTagsin interfaceITagReader- Returns:
- boolean
-
readTag
public ITag readTag()
Returns a Tag object- Specified by:
readTagin interfaceITagReader- Returns:
- Tag
-
close
public void close()
Closes the reader and free any allocated memory.- Specified by:
closein interfaceITagReader
-
analyzeKeyFrames
public IKeyFrameDataAnalyzer.KeyFrameMeta analyzeKeyFrames()
Key frames analysis may be used as a utility method so synchronize it.- Specified by:
analyzeKeyFramesin interfaceIKeyFrameDataAnalyzer- Returns:
- Keyframe metadata
-
position
public void position(long pos)
Put the current position to pos. The caller must ensure the pos is a valid one (eg. not sit in the middle of a frame).- Specified by:
positionin interfaceITagReader- Parameters:
pos- New position in file. PassLong.MAX_VALUEto seek to end of file.
-
getDuration
public static int getDuration(File flvFile)
Returns the last tag's timestamp as the files duration.- Parameters:
flvFile- FLV file- Returns:
- duration
-
-