Class PacketBuffer
java.lang.Object
org.codice.alliance.video.stream.mpegts.netty.PacketBuffer
Buffers raw MPEG-TS packet data and writes the data to a temporary file so that the data written
is on a clean IDR boundary. If an IDR boundary cannot be found, the data will be eventually flush
on a arbitrary point to avoid memory exhaustion. This implementation is thread-safe.
NOTE: This implementation could probably be improved by using some kind of circular buffer with read and write pointers
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longAfter this number of milliseconds of no activity, the current frameset in memory will be considered complete. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidFlush all buffered data to disk and rotate.voidframeComplete(PacketBuffer.FrameType frameType) Tell the packet buffer that the recently written data represents a complete frame.longgetAge()Get the age (milliseconds) of the temporary data file.longGet the number of bytes that have been written to the temporary data file.longlongvoidreset()Clear all stored data and reset to the initial state.rotate(RolloverCondition rolloverCondition) If the rollover condition is not met, then the method will returnOptional.empty().voidsetMaxIncompleteFrameBytes(long maxIncompleteFrameBytes) voidsetOutputStreamFactory(OutputStreamFactory outputStreamFactory) voidsetTempFileGenerator(TempFileGenerator tempFileGenerator) toString()voidwrite(byte[] rawPacket) Write raw data into the buffer.
-
Field Details
-
ACTIVITY_TIMEOUT
public static final long ACTIVITY_TIMEOUTAfter this number of milliseconds of no activity, the current frameset in memory will be considered complete.
-
-
Constructor Details
-
PacketBuffer
public PacketBuffer()
-
-
Method Details
-
setTempFileGenerator
- Parameters:
tempFileGenerator- must be non-null
-
setOutputStreamFactory
- Parameters:
outputStreamFactory- must be non-null
-
setMaxIncompleteFrameBytes
public void setMaxIncompleteFrameBytes(long maxIncompleteFrameBytes) - Parameters:
maxIncompleteFrameBytes- must be non-null
-
toString
-
reset
public void reset()Clear all stored data and reset to the initial state. -
getAge
public long getAge()Get the age (milliseconds) of the temporary data file. Returns 0 if there is no file.- Returns:
- age in milliseconds
-
getByteCount
public long getByteCount()Get the number of bytes that have been written to the temporary data file.- Returns:
- bytes
-
write
public void write(byte[] rawPacket) Write raw data into the buffer. Empty or null values are handled. If the size of the incomplete frame data exceedsmaxIncompleteFrameBytes, then the current incomplete frame data will be push to the frame list as typePacketBuffer.FrameType.UNKNOWNand a flush to disk will be attempted.- Parameters:
rawPacket- may be null or empty
-
frameComplete
Tell the packet buffer that the recently written data represents a complete frame. A flush to disk will be attempted.- Parameters:
frameType- must be non-null
-
rotate
If the rollover condition is not met, then the method will returnOptional.empty(). If the rollover condition is met, then the method may return a temp file. The only reason a temp file may not be returned is when the condition istrueeven when no data has been written to file. The caller is responsible for deleting the temp file.- Parameters:
rolloverCondition- the rollover condition- Returns:
- an optional temp file
-
flushAndRotate
Flush all buffered data to disk and rotate. Will returnOptional.empty()if no data has been written to file. The caller is responsible for deleting the temp file.- Returns:
- an optional temp file
- Throws:
IOException
-
cancelTimer
public void cancelTimer() -
getLastSegmentStart
public long getLastSegmentStart() -
getLastSegmentEnd
public long getLastSegmentEnd()
-