|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfi.helsinki.cs.ohtu.mpeg2.AVPacketizer
public class AVPacketizer
Implements a packetizer for elementary streams of audio and video. Instances of this class are intended to be used with a multiplexer. The multiplexer pulls data from the packetizer instance.
Data is written into the packetizer with the
write
method an AccessUnit
at a time.
Conceptually the written access units are placed one after another to
form a stream of bytes. The stream is then broken into packets by the
packetize
method. By default access
units are not aligned to packet boundaries. Thus an access unit can
be split into two (or even more) packets. In some cases it desirable
to have some control on the splitting. The method
needPacketAlign
is
consulted on every access unit by the method
packetize
. When it returns true
,
the access unit will be placed to start at a packet boundary.
A sub-class of this class can insert a payload prefix by
overriding the
writePayloadPrefix
method.
The precise length of the prefix has to be returned by the method
getPayloadPrefixLength
.
The prefix might be useful in implementing sub-stream headers, for
instance.
Along with packetization, the class operates a decoder buffer
model. It is used by the isMuxable
method
to determine when a decoder is able to accept more input. The method
packetize
appends packetized data into
the decoder buffer (only virtually). The data are removed by the
method isMuxable
when they are declared
to have been decoded. The buffer must not overflow as it would cause
data to be lost (whether data-loss would really happen is a different
thing).
Nested Class Summary | |
---|---|
static class |
AVPacketizer.State
Represents the state of a packetizer. |
Field Summary | |
---|---|
private int |
auBytesLeft
|
private java.util.List<AccessUnit> |
aus
|
private boolean |
closed
|
private DecoderBuffer |
decbuf
|
private PacketizerListener |
listener
|
private java.lang.Long |
prevPts
|
private StreamID |
sid
|
private long |
tboff
|
private static int |
TS_INTERVAL
Number of clock ticks between forced PES timestamps |
Constructor Summary | |
---|---|
AVPacketizer(StreamID sid,
int bufsize)
Creates a new packetizer. |
Method Summary | |
---|---|
void |
close()
Closes this packetizer. |
void |
flush()
Flushes this packetizer, that is, notifies the data listener if data is available. |
int |
getBufferSize()
Gets the size of the decoder buffer. |
int |
getDesiredBuffering()
Returns the desired number of bytes in the decoding buffer for smooth playback and operation. |
long |
getNextDts()
Returns the decoding timestamp in the next generated packet. |
protected int |
getPayloadPrefixLength()
Returns the length for a payload prefix. |
AVPacketizer.State |
getState()
Returns the state of this packetizer. |
StreamID |
getStreamId()
Gets the stream id for the PES stream. |
boolean |
isMuxable(long pcr,
int maxSize)
Updates the decoder buffer model and returns whether the stream from this packetizer can be multiplexed. |
protected boolean |
needPacketAlign(AccessUnit au)
Gets whether the given access unit needs to be packet aligned. |
AudioVideoPESPacket |
packetize(int maxSize)
Generates a PES packet. |
void |
setPacketizerListener(PacketizerListener listener)
Sets the data availability listener for this packetizer. |
void |
setTimebaseOffset(long tboff)
Sets the timebase offset for this packetizer. |
void |
write(AccessUnit au)
Writes an access unit into this packetizer. |
protected void |
writePayloadPrefix(AudioVideoPESPacket avpkt,
int payloadSize)
Writes a payload prefix. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final int TS_INTERVAL
private final StreamID sid
private final DecoderBuffer decbuf
private final java.util.List<AccessUnit> aus
private PacketizerListener listener
private long tboff
private int auBytesLeft
private java.lang.Long prevPts
private boolean closed
Constructor Detail |
---|
public AVPacketizer(StreamID sid, int bufsize)
sid
- the stream id for the generated PES packetsbufsize
- the size of the decoder buffer, in bytesMethod Detail |
---|
protected boolean needPacketAlign(AccessUnit au)
This packetizer uses this method to get hints when to start
a new packet. The default implementation returns true
when an access unit is marked as discontinuous.
au
- the access unit for which packet alignment is checked
true
if packet aligned is neededprotected int getPayloadPrefixLength()
protected void writePayloadPrefix(AudioVideoPESPacket avpkt, int payloadSize)
getPayloadPrefixLength
.
avpkt
- the packet where to write the prefixpayloadSize
- the size of the payload data, in bytespublic AudioVideoPESPacket packetize(int maxSize)
maxSize
- the maximum number of bytes in the packetpublic long getNextDts()
public boolean isMuxable(long pcr, int maxSize)
pcr
- the current program clock referencemaxSize
- the maximum number of data bytes in a data packet
true
if the data can be multiplexedpublic AVPacketizer.State getState()
public void setTimebaseOffset(long tboff)
tboff
- the timebase offset, in ticks of the 90kHz clockpublic StreamID getStreamId()
public int getBufferSize()
public int getDesiredBuffering()
public void setPacketizerListener(PacketizerListener listener)
null
disables
data availability notifications.
listener
- the listener, or null
to
disable notificationspublic void write(AccessUnit au)
au
- the access unit to write
java.lang.IllegalStateException
- if the packetizer is closedpublic void flush()
public void close()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |