fi.helsinki.cs.ohtu.mpeg2
Class Pack

java.lang.Object
  extended by fi.helsinki.cs.ohtu.mpeg2.Pack

public class Pack
extends java.lang.Object

Represents a pack in the program stream. A pack is a lump of PES packets which share a common PackHeader (mostly contains timing information). There can additionally be an optional system header for the pack, however this is not currently supported. For obvious performance reasons, instances of this class won't contain the actual PES packets in the semantic pack. They are written separately to the ProgramStream, which however handles writing the pack at the correct time in respect to them.


Field Summary
private  java.util.ArrayList<PackDirtiedListener> dirtiedListeners
           
private  PackHeader packHeader
           
private  SystemHeader systemHeader
           
 
Constructor Summary
Pack(double scr, int muxRate)
          Class constructor.
 
Method Summary
 void addDirtiedListener(PackDirtiedListener listener)
          Adds a dirtied listener.
 PackDirtiedListener[] getDirtiedListeners()
          Returns an array of all the dirtied listeners registered on this pack.
 int getProgramMuxRate()
          Gets the program mux rate.
 int getStuffingLength()
          Gets the stuffing length.
 double getSystemClockReference()
          Gets the system clock reference.
 SystemHeader getSystemHeader()
          Gets the system header for this pack, if there is one.
 void removeDirtiedListener(PackDirtiedListener listener)
          Removes the specified dirtied listener so that it no longer receives events from this pack.
 void setProgramMuxRate(int rate)
          Sets the program mux rate.
 void setStuffingLength(int length)
          Sets the stuffing length.
 void setSystemClockReference(double scr)
          Sets the system clock reference.
 void setSystemHeader(SystemHeader systemHeader)
          Sets a system header for this pack.
 void writeTo(BitOutputStream stream)
          Writes the pack to a bit stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

packHeader

private PackHeader packHeader

systemHeader

private SystemHeader systemHeader

dirtiedListeners

private java.util.ArrayList<PackDirtiedListener> dirtiedListeners
Constructor Detail

Pack

public Pack(double scr,
            int muxRate)
Class constructor. The resulting pack will specify the given clock reference and mux rate, and will have no stuffing. No system header will be included.

Parameters:
scr - The system clock reference, as in #setSystemClockReference().
muxRate - The mux rate, as in #setProgramMuxRate().
Method Detail

getSystemHeader

public SystemHeader getSystemHeader()
Gets the system header for this pack, if there is one.

Returns:
System header for this pack; null if none set

setSystemHeader

public void setSystemHeader(SystemHeader systemHeader)
Sets a system header for this pack. Value null removes previously set header.

Parameters:
systemHeader - System header for this pack

getSystemClockReference

public double getSystemClockReference()
Gets the system clock reference.

Returns:
The reference, in seconds. Will be non-negative.

setSystemClockReference

public void setSystemClockReference(double scr)
Sets the system clock reference. If a value higher than roughly 95000 seconds (26.5 hours) is specified, the value, as returned by getSystemClockReference() might be wrapped around (to the range [0..26.5 hours]).

Parameters:
scr - The reference, in seconds. Must be non-negative.

getProgramMuxRate

public int getProgramMuxRate()
Gets the program mux rate.

Returns:
The rate, in bytes/second. Will be in the range [50..50*2^22].

setProgramMuxRate

public void setProgramMuxRate(int rate)
Sets the program mux rate. The value is specified in bytes/second, but stored only with a precision of 50 bytes/second. Therefore all set values, as returned by #getProgramMuxRate() afterwards, are rounded down to the nearest multiple of 50.

Parameters:
rate - The new rate, in bytes/second. Must be in the range [50..50*2^22].

getStuffingLength

public int getStuffingLength()
Gets the stuffing length.

Returns:
The length. Will be in range [0..7].

setStuffingLength

public void setStuffingLength(int length)
Sets the stuffing length.

Parameters:
length - The new length. Must be in range [0..7].

addDirtiedListener

public final void addDirtiedListener(PackDirtiedListener listener)
Adds a dirtied listener.

Parameters:
listener - A class implementing the PackDirtiedListener interface to register as the listener.

getDirtiedListeners

public final PackDirtiedListener[] getDirtiedListeners()
Returns an array of all the dirtied listeners registered on this pack.

Returns:
All of this pack's dirtied listeners or an empty array if there are none.

removeDirtiedListener

public final void removeDirtiedListener(PackDirtiedListener listener)
Removes the specified dirtied listener so that it no longer receives events from this pack. If listener is null, nothing happens.

Parameters:
listener - The listener to remove.

writeTo

public void writeTo(BitOutputStream stream)
             throws java.io.IOException
Writes the pack to a bit stream.

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