public abstract class CodestreamWriter extends Object
Data may be written to the bit stream in sumulation mode. When in simulation mode no data is written to the bit stream but the resulting number of bytes is calculated and returned (although it is not accounted in the bit stream). This can be used in rate control loops.
Implementing classes should write the header of the bit stream before writing any packets. The bit stream header should be written with the aid of the HeaderEncoder class.
HeaderEncoder
Modifier and Type | Field and Description |
---|---|
protected int |
maxBytes
The maximum number of bytes that can be written to the
bit stream
|
protected int |
ndata
The number of bytes already written to the bit stream
|
Modifier | Constructor and Description |
---|---|
protected |
CodestreamWriter(int mb)
Allocates this object and initializes the maximum numner of
bytes.
|
Modifier and Type | Method and Description |
---|---|
abstract void |
close()
Closes the underlying resource (file, stream, network connection,
etc.).
|
abstract void |
commitBitstreamHeader(HeaderEncoder he)
Writes the header data to the bit stream, if it has not been already
done.
|
abstract int |
getLength()
Returns the current length of the entire bit stream.
|
abstract int |
getMaxAvailableBytes()
Returns the number of bytes remaining available in the bit stream.
|
abstract int |
getOffLastROIPkt()
Gives the offset of the end of last packet containing ROI information
|
abstract int |
writePacketBody(byte[] body,
int blen,
boolean sim,
boolean roiInPkt,
int roiLen)
Writes a packet body to the bit stream and returns the number of bytes
used by this body .If in simulation mode then no data is written to the
bit stream but the number of bytes is calculated.
|
abstract int |
writePacketHead(byte[] head,
int hlen,
boolean sim,
boolean sop,
boolean eph)
Writes a packet head to the bit stream and returns the number of bytes
used by this header.
|
protected int ndata
protected int maxBytes
protected CodestreamWriter(int mb)
mb
- The maximum number of bytes that can be written to
the bit stream.public abstract int getMaxAvailableBytes()
public abstract int getLength()
public abstract int writePacketHead(byte[] head, int hlen, boolean sim, boolean sop, boolean eph) throws IOException
If the length of the data that is to be written to the bit stream is more than the space left (as returned by getMaxAvailableBytes()) only the data that does not exceed the allowed length is written, the rest is discarded. However the value returned by the method is the total length of the packet, as if all of it was written to the bit stream.
If the bit stream header has not been commited yet and 'sim' is false, then the bit stream header is automatically commited (see commitBitstreamHeader() method) before writting the packet.
head
- The packet head data.hlen
- The number of bytes in the packet head.sim
- Simulation mode flag. If true nothing is written to the bit
stream, but the number of bytes that would be written is returned.sop
- Start of packet header marker flag. This flag indicates
whether or not SOP markers should be written. If true, SOP markers
should be written, if false, they should not.eph
- End of Packet Header marker flag. This flag indicates
whether or not EPH markers should be written. If true, EPH markers
should be written, if false, they should not.IOException
- If an I/O error occurs while writing to the
output stream.commitBitstreamHeader(jj2000.j2k.codestream.writer.HeaderEncoder)
public abstract int writePacketBody(byte[] body, int blen, boolean sim, boolean roiInPkt, int roiLen) throws IOException
If the length of the data that is to be written to the bit stream is more than the space left (as returned by getMaxAvailableBytes()) only the data that does not exceed the allowed length is written, the rest is discarded. However the value returned by the method is the total length of the packet body , as if all of it was written to the bit stream.
body
- The packet body data.blen
- The number of bytes in the packet body.sim
- Simulation mode flag. If true nothing is written to the bit
stream, but the number of bytes that would be written is returned.roiInPkt
- Whether or not there is ROI information in this packetroiLen
- Number of byte to read in packet body to get all the ROI
informationIOException
- If an I/O error occurs while writing to
the output stream.commitBitstreamHeader(jj2000.j2k.codestream.writer.HeaderEncoder)
public abstract void close() throws IOException
IOException
- If an I/O error occurs while closing the
resource.public abstract void commitBitstreamHeader(HeaderEncoder he) throws IOException
IOException
- If an I/O error occurs while writing the data.IllegalArgumentException
- If this method has already been
called.public abstract int getOffLastROIPkt()
Copyright © 2014. All rights reserved.