fi.helsinki.cs.ohtu.mpeg2
Class ProgramStream

java.lang.Object
  extended by fi.helsinki.cs.ohtu.mpeg2.ProgramStream
All Implemented Interfaces:
PackDirtiedListener

public class ProgramStream
extends java.lang.Object
implements PackDirtiedListener

Represents a MPEG-2 program stream.


Field Summary
private  boolean dirtyPack
           
(package private)  Pack pack
           
private  BitOutputStream stream
           
 
Constructor Summary
ProgramStream(BitOutputStream stream)
          Class constructor.
 
Method Summary
 void close()
          Closes the stream.
 Pack getActivePack()
          Gets the active pack, as previously set by #setActivePack().
 BitOutputStream getStream()
          Gets the underlying stream.
 void packDirtied(Pack pack)
          Used internally to make the stream re-emit the pack headers after changing some of the pack's fields.
 void setActivePack(Pack pack)
          Sets the active pack.
 void setStream(BitOutputStream stream)
          Sets the stream to write to.
 void writePacket(PESPacket packet)
          Writes a packet to the stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pack

Pack pack

dirtyPack

private boolean dirtyPack

stream

private BitOutputStream stream
Constructor Detail

ProgramStream

public ProgramStream(BitOutputStream stream)
Class constructor. Initially, there will be no active pack. Use #setActivePack() to change that.

Parameters:
stream - The bit stream to write the program stream data to.
Method Detail

getStream

public BitOutputStream getStream()
Gets the underlying stream.

Returns:
The stream.

setStream

public void setStream(BitOutputStream stream)
Sets the stream to write to. All future packs will be written to this stream.

Parameters:
stream - The new stream.

getActivePack

public Pack getActivePack()
Gets the active pack, as previously set by #setActivePack().

Returns:
The active pack.

setActivePack

public void setActivePack(Pack pack)
Sets the active pack. The active pack will the pack semantically containing all written packets. The pack headers are written when a PES packet is written for the first time after changing the pack. If the pack set is the currently active pack, nothing will happen.


writePacket

public void writePacket(PESPacket packet)
                 throws java.io.IOException
Writes a packet to the stream. If the pack has been changed after writing the previous packet, the currently active pack's headers will be written to the stream. To be changed in this context means both #setActivePack() usage and tampering with the fields in the pack used by the Pack class accessors. This must not be called when there is no active pack, eg. when the program stream has just been created but the active pack not yet set.

Parameters:
packet - The packet to write.
Throws:
java.io.IOException - Propagated from the underlying stream write.

close

public void close()
           throws java.io.IOException
Closes the stream. No more packets can be written to the stream after closing it. Also closes the underlying stream.

Throws:
java.io.IOException - Propagated from writing the end codes to the underlying stream.

packDirtied

public void packDirtied(Pack pack)
Used internally to make the stream re-emit the pack headers after changing some of the pack's fields. Called when something has changed in the Pack headers.

Specified by:
packDirtied in interface PackDirtiedListener
Parameters:
pack - The pack that has been changed.
See Also:
PackDirtiedListener.packDirtied(Pack)