fi.helsinki.cs.ohtu.mpeg2.video
Class MacroblockHeader

java.lang.Object
  extended by fi.helsinki.cs.ohtu.mpeg2.video.MacroblockHeader

public class MacroblockHeader
extends java.lang.Object

Represents the continuous purely header fields in a MPEG-2 macroblock. The class intentionally contains very little logic, as the actual value for most of the fields is best derived with knowledge of the actual macroblock data (presence and type of motion vectors foremost). Therefore, the logic is best placed in the layer which also contains the data (unlike this pure header).


Field Summary
private  int addressIncrement
           
private  java.lang.Boolean dctType
           
private  java.lang.Integer motionType
           
private  UnsignedIntegerField quantizerScaleCode
           
 
Constructor Summary
MacroblockHeader()
          Constructs a macroblock header instance.
 
Method Summary
 int getAddressIncrement()
          Gets the address increment.
 int getMotionType()
          Returns the specified motion type.
 int getQuantizerScaleCode()
          Gets the specified override quantizer scale code.
 boolean hasDCTType()
          Determines if the type of DCT used is specified.
 boolean hasMotionType()
          Determines if the macroblock specifies a motion type.
 boolean hasQuantizerScaleCode()
          Determines if the macroblock specifies an override quantizer scale code.
 boolean isDCTTypeField()
          Determines if the specified DCT type is field-based.
 boolean isDCTTypeFrame()
          Determines if the specified DCT type is frame-based.
 void setAddressIncrement(int addressIncrement)
          Sets the address increment.
 void setDCTTypeField()
          Sets the macroblock to specify a field-based DCT type.
 void setDCTTypeFrame()
          Sets the macroblock to specify a frame-based DCT type.
 void setMotionType(int motionType)
          Sets the macroblock to specify a given (field or frame) motion type.
 void setQuantizerScaleCode(int quantizerScaleCode)
          Sets the macroblock to specify an override quantizer scale code.
 void unsetDCTType()
          Unsets any DCT type specification previously set by setDCTTypeField() and/or setDCTTypeFrame().
 void unsetMotionType()
          Unsets any motion type previously set by setMotionType().
 void unsetQuantizerScaleCode()
          Unsets any override quantizer scale code previously set by setQuantizerScaleCode().
 void writeTo(BitOutputStream stream, int[] type)
          Writes the header to a bit-by-bit output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

addressIncrement

private int addressIncrement

motionType

private java.lang.Integer motionType

dctType

private java.lang.Boolean dctType

quantizerScaleCode

private UnsignedIntegerField quantizerScaleCode
Constructor Detail

MacroblockHeader

public MacroblockHeader()
Constructs a macroblock header instance. The resulting instance will have an address increment of 1, no motion type specified, no dct type specified and no quantizer scale code override.

Method Detail

getAddressIncrement

public int getAddressIncrement()
Gets the address increment.

Returns:
The increment. Will be positive.

setAddressIncrement

public void setAddressIncrement(int addressIncrement)
Sets the address increment.

Parameters:
addressIncrement - The increment to set. Must be positive.

hasMotionType

public boolean hasMotionType()
Determines if the macroblock specifies a motion type.

Returns:
true if a motion type is specified, false if not.

getMotionType

public int getMotionType()
Returns the specified motion type.

Returns:
The type. Will be in {1, 2, 3}.

setMotionType

public void setMotionType(int motionType)
Sets the macroblock to specify a given (field or frame) motion type.

Parameters:
motionType - The encoded value of the motion type to specify. Must be in {1, 2, 3}.

unsetMotionType

public void unsetMotionType()
Unsets any motion type previously set by setMotionType(). The macroblock will no longer specify any motion type.


hasDCTType

public boolean hasDCTType()
Determines if the type of DCT used is specified.

Returns:
true if a dct type is specified, false if not.

isDCTTypeField

public boolean isDCTTypeField()
Determines if the specified DCT type is field-based.

Returns:
true if field-based, false if frame-based.

isDCTTypeFrame

public boolean isDCTTypeFrame()
Determines if the specified DCT type is frame-based.

Returns:
true if frame-based, false if field-based.

setDCTTypeField

public void setDCTTypeField()
Sets the macroblock to specify a field-based DCT type.


setDCTTypeFrame

public void setDCTTypeFrame()
Sets the macroblock to specify a frame-based DCT type.


unsetDCTType

public void unsetDCTType()
Unsets any DCT type specification previously set by setDCTTypeField() and/or setDCTTypeFrame(). The macroblock will no longer specify any DCT type.


hasQuantizerScaleCode

public boolean hasQuantizerScaleCode()
Determines if the macroblock specifies an override quantizer scale code.

Returns:
true if a scale code is specified, false if not.

getQuantizerScaleCode

public int getQuantizerScaleCode()
Gets the specified override quantizer scale code.

Returns:
The code. Only the lowest 5 bits will be meaningful.

setQuantizerScaleCode

public void setQuantizerScaleCode(int quantizerScaleCode)
Sets the macroblock to specify an override quantizer scale code.

Parameters:
quantizerScaleCode - The scale code to set. Must fit into 5 bits as an unsigned integer.

unsetQuantizerScaleCode

public void unsetQuantizerScaleCode()
Unsets any override quantizer scale code previously set by setQuantizerScaleCode(). The macroblock will no longer specify any override quantizer scale code.


writeTo

public void writeTo(BitOutputStream stream,
                    int[] type)
             throws java.io.IOException
Writes the header to a bit-by-bit output stream.

Parameters:
stream - the stream to write to.
type - The macroblock type VLC code. Should be derived from the actual macroblock contents by the macroblock high-level logic at the time of writing (depending on both the header fields and the actual macroblock data contents). For example, a VLC code implying backwards motion should only be supplied if there actually is a backwards motion vector.
Throws:
java.io.IOException - Propagated from the stream write.