|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfi.helsinki.cs.ohtu.mpeg2.ElementaryStream
fi.helsinki.cs.ohtu.mpeg2.VideoStream
public class VideoStream
Represents a stream of MPEG-2 video. Instances of VideoStream
collect together the pieces a MPEG-2 video and provide the data for
packetization. This class makes basic consistency checks for the
written data. The checking is rather light and cannot be used for
validation. In other words, garbage in, garbage out. The checking
can be disabled.
For an overall picture and details of MPEG-2 video, please see the ISO 13818-2.
Nested Class Summary | |
---|---|
private static class |
VideoStream.VideoAccessUnit
Represents an access unit of a video stream. |
private static class |
VideoStream.VideoPacketizer
Implements the packetizer for video streams. |
private static class |
VideoStream.VideoState
Video state, used to track video access unit generation |
Field Summary | |
---|---|
private int |
blockCount
|
private int |
blocks
|
private int |
blocksCoded
|
private boolean |
checkEnabled
|
private boolean |
closed
|
private boolean |
discont
|
private long |
dtsBase
|
private boolean |
firstAu
|
private SequenceHeader.FrameRateCode |
frameRate
|
private int |
frames
|
private PictureHeader.CodingType |
frameType
|
private boolean |
mbIntra
|
private boolean |
mbMvBackward
|
private boolean |
mbMvForward
|
private boolean |
mbPattern
|
private java.util.List<VideoStream.VideoPacketizer> |
packers
|
private long |
ptsBase
|
private VideoStream.VideoState |
state
|
private BitOutputStream |
videoBits
|
private java.io.ByteArrayOutputStream |
videoBytes
|
Constructor Summary | |
---|---|
VideoStream()
Creates a new VideoStream instance. |
Method Summary | |
---|---|
void |
close()
Closes this ElementaryStream . |
private void |
decodeMblkType(int[] mblktype)
Decodes a variable length code representing a macroblock type. |
private void |
finishAu()
Finishes building an access unit and delivers it to the packetizers. |
void |
flush()
Flushes buffered data, if any, to the packetizers. |
boolean |
getChecking()
Gets whether video structure checking is enabled. |
long |
getDts()
Gets the current decoding timestamp. |
private float |
getFrameDuration(SequenceHeader.FrameRateCode frameRate)
Returns duration of a single frame for given frame rate. |
AVPacketizer |
getPacketizer(int vsid)
Creates a new packetizer for this VideoStream . |
AVPacketizer |
getPacketizer(int vsid,
int decoderBuffer)
Creates a new packetizer for this VideoStream . |
AVPacketizer |
getPacketizer(int vsid,
int decoderBuffer,
boolean alignIFrames)
Creates a packetizer for this VideoStream . |
long |
getPts()
Gets the current presentation timestamp. |
void |
releasePacketizer(AVPacketizer esp)
Releases a packetizer for this ElementaryStream . |
private void |
resetVideoAUBuilder()
Resets the buffer used to collect data for an access unit. |
void |
setChecking(boolean checkEnabled)
Sets whether video structure checking is enabled. |
void |
setPtsDts(double pts,
double dts)
Sets the presentation and decoding timestamps. |
void |
setPtsDts(long pts,
long dts)
Sets the presentation and decoding timestamps. |
private int |
vlcToInt(int[] vlc)
Converts a variable length coded value to an integer. |
void |
write(Block block)
Writes a block. |
void |
write(MacroblockHeader mblkhdr,
int[] mblktype)
Writes a macroblock header. |
void |
write(MotionVector mv,
MotionVector.Predictors preds)
Writes a motion vector. |
void |
write(PictureHeader pichdr,
PictureCodingExtensionHeader pcehdr)
Writes picture headers. |
void |
write(PictureHeader pichdr,
PictureCodingExtensionHeader pcehdr,
long pts,
long dts)
Writes picture headers. |
void |
write(SequenceHeader seqhdr,
SequenceExtensionHeader sexhdr)
Writes sequence headers. |
void |
write(SliceHeader sheader)
Writes a slice header. |
void |
writeCodedBlockPattern(boolean[] blockCoded)
Writes a pattern for which blocks have been coded. |
void |
writeEnd()
Writes a sequence end code. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final java.util.List<VideoStream.VideoPacketizer> packers
private long ptsBase
private long dtsBase
private boolean closed
private boolean checkEnabled
private VideoStream.VideoState state
private java.io.ByteArrayOutputStream videoBytes
private BitOutputStream videoBits
private boolean discont
private boolean firstAu
private int blockCount
private int blocks
private int blocksCoded
private boolean mbPattern
private boolean mbMvForward
private boolean mbMvBackward
private boolean mbIntra
private SequenceHeader.FrameRateCode frameRate
private int frames
private PictureHeader.CodingType frameType
Constructor Detail |
---|
public VideoStream()
VideoStream
instance. Stream checking is
enabled by default. The first allowed write operation is writing
of sequence headers.
Method Detail |
---|
public long getPts()
public long getDts()
public boolean getChecking()
true
if checking is enabledpublic void setChecking(boolean checkEnabled)
checkEnabled
- true
if checking is enabledpublic void setPtsDts(long pts, long dts)
pts
- the PTS, in ticks of the 90kHz clockdts
- the DTS, in ticks of the 90kHz clockpublic void setPtsDts(double pts, double dts)
pts
- the PTS, in secondsdts
- the DTS, in secondspublic void write(SequenceHeader seqhdr, SequenceExtensionHeader sexhdr)
seqhdr
- the sequence header to writesexhdr
- the sequence extension header to write
IllegalStateExpection
- if sequence headers were not expectedpublic void write(PictureHeader pichdr, PictureCodingExtensionHeader pcehdr)
pichdr
- the picture header to writepcehdr
- the picture coding extension header to write
java.lang.IllegalStateException
- if picture headers were not expectedpublic void write(PictureHeader pichdr, PictureCodingExtensionHeader pcehdr, long pts, long dts)
pichdr
- the picture header to writepcehdr
- the picture coding extension header to writepts
- the presentation timestamp for the picturedts
- the decoding timestamp for the picturewrite(PictureHeader, PictureCodingExtensionHeader)
public void write(SliceHeader sheader)
sheader
- the slice header to writepublic void write(MacroblockHeader mblkhdr, int[] mblktype)
mblkhdr
- the macroblock header to writemblktype
- the type of the macroblock
java.lang.IllegalStateException
- if a macroblock header
was not expectedwrite(Block)
,
write(MotionVector, MotionVector.Predictors)
,
writeCodedBlockPattern(boolean[])
public void write(Block block)
block
- the block to write
java.lang.IllegalStateException
- if a block was not expectedpublic void write(MotionVector mv, MotionVector.Predictors preds)
mv
- the motion vector to writepreds
- the motion vector predictors to update
java.lang.IllegalStateException
- if a motion vector was not expectedpublic void writeCodedBlockPattern(boolean[] blockCoded)
blockCoded
- the pattern of coded blocks
java.lang.IllegalStateException
- if a coded block pattern was
not expectedpublic void writeEnd()
java.lang.IllegalStateException
- if not called after
writing picture datapublic AVPacketizer getPacketizer(int vsid, int decoderBuffer, boolean alignIFrames)
VideoStream
. Video stream
number, vsid
, defines the stream id for video packets.
decoderBuffer
defines how much video data can be waiting
to be decoded at the video decoder at any moment. A lower number
means lower resource demands at the decoder but it makes it more
difficult to maintain smooth playback. Besides, an access unit
has to completely fit into the buffer. alignIFrames
specifies whether access units containing I-frames should start
at the start of a new packet. Some formats require it.
vsid
- the stream number for the packetized stream,
in range [0, 16]decoderBuffer
- the size of the video decoder buffer, in bytes;
has to be at least 32768alignIFrames
- true
if I-frames should be packet-aligned
public AVPacketizer getPacketizer(int vsid, int decoderBuffer)
VideoStream
.
I-frame packet alignment is disabled.
vsid
- the stream number for the packetized video stream,
in range [0, 16]decoderBuffer
- the size of the video decoder buffer,
in bytes; has to be at least 32768
getPacketizer(int, int, boolean)
public AVPacketizer getPacketizer(int vsid)
VideoStream
.
The video decoder buffer defaults to 46KiB. I-frames are not
packet aligned.
getPacketizer
in class ElementaryStream
vsid
- the stream number for the packetized video stream,
in range [0, 16]
getPacketizer(int, int, boolean)
public void releasePacketizer(AVPacketizer esp)
ElementaryStream
ElementaryStream
.
After releasing the packetizer will not receive more
data from this stream.
releasePacketizer
in class ElementaryStream
esp
- the packetizer to releasepublic void flush()
ElementaryStream
flush
in class ElementaryStream
public void close()
ElementaryStream
ElementaryStream
. After this call
no more data shall be written into this stream.
close
in class ElementaryStream
private void finishAu()
private void resetVideoAUBuilder()
private float getFrameDuration(SequenceHeader.FrameRateCode frameRate)
frameRate
- the frame rate
private int vlcToInt(int[] vlc)
vlc
- the variable length code to be converted
private void decodeMblkType(int[] mblktype)
VideoStream
instance accordingly.
mblktype
- the macroblock type in variable length code
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |