mediaframe.mpeg1
Class MPEG_video

java.lang.Object
  |
  +--mediaframe.mpeg1.MPEG_video
All Implemented Interfaces:
java.lang.Runnable

public class MPEG_video
extends java.lang.Object
implements java.lang.Runnable

The MPEG_video class implements the video decoder of the MPEG bit stream.

Author:
Joerg Anders

Field Summary
private  int ak_idx
          The index of the frame coming into being.
private  int Asp_ratio
          The aspect ratio used by the MPEG standard given in the sequence headerr.
static int B_TYPE
          B FRAME frame type constanta.
private  int back_idx
          The index of the frame for backward prediction.
private  motion_data Backward
          The object of class "motion_data" to notice and compute the backward motion values.
private  int backward_f
          The the size of the motion data for backward prediction.
private  int backward_f_code
          The motion code value for backward prediction.
private  int backward_r_size
          The size of residual value for backward prediction.
private  int Bit_rate
          The bit rate specified in the sequence header.
private  boolean Broken_Link
          The Broken Link value specified in the group of pictures header.
private  boolean Closed_Group
          The Closed Group value specified in the group of pictures header.
private  int col_y_incr
          The increment for the luminance line, equals to pixel_per_col_line - 8.
private  boolean const_param
          True if the constrained parameter flag was set in the sequence header and false otherwise.
private  int dct_dc_cb_past
          The value of past DC (cb) value.
private  int dct_dc_cr_past
          The value of past DC (cr) value.
private  int dct_dc_y_past
          The value of past DC (y) value.
private  int[] dct_recon
          The values before IDCT transformation.
private  boolean Drop_Flag
          The Drop Flag value specified in the group of pictures header.
private  int error_count
          The current amount of printed video errors.
private static int EXT_START_CODE
          MPEG VIDEO layer constanta.
private  int forw_f_code
          The motion code value for forward prediction.
private  motion_data Forward
          The object of class "motion_data" to notice and compute the forward motion values.
private  int forward_f
          The the size of the motion data for forward prediction.
private  int forward_r_size
          The size of residual value for forward prediction.
private  int Frame_nr
          The frame number in the movie.
private  int Frame_nr_offset
          The first frame number of last group of pictures.
private  boolean Full_pel_back_vector
          Equals true if full pixel accuracy is used for backward prediction, equals false if half pixel accuracy is used.
private  boolean Full_pel_forw_vector
          Equals true if full pixel accuracy is used for forward prediction, equals false if half pixel accuracy is used.
private static int GOP_START_CODE
          MPEG video layer constanta.
private  int Height
          The height in pixels of the movie data.
private  int Hour
          The Hour time value specified in the group of pictures header.
private  Huffmann Huf
          The VLC (Hufmann) decoder.
static int I_TYPE
          I FRAME frame type constanta.
private  IDCT idct
          An IDCT object to tranform the DCT coefficients.
private  int[] intramatrix
          The default intramatrix.
private  boolean lum_block
          False if in the current macroblock hasn't had any luminance blocks.
private  int lum_y_incr
          The increment for the luminance line, equals to pixel_per_lum_line - 8.
private  int macro_block_address
          The actual MB address.
private  boolean macro_block_intra
          True if a macro block is for intra coded frames.
private  boolean macro_block_motion_backward
          True if motion vector for backward prediction exists.
private  boolean macro_block_motion_forward
          True if motion vector for forward prediction exists.
private  boolean macro_block_pattern
          True if a coded block pattern supplied.
private  boolean macro_block_quant
          True if a new quantization factor is supplied.
private  int mb_column
          The actual column position of the macro block.
private  int mb_height
          The macroblock height.
private  int mb_row
          The actual row position of the macro block.
private  int mb_width
          The macroblock width.
private  int Minute
          The Minute time value specified in the group of pictures header.
private  java.lang.Thread moribund
          The "Video Decoder" thread that is being stopped.
private  int motion_horiz_back_code
          The motion code value of horizontal part for backward prediction.
private  int motion_horiz_back_r
          The motion residual value of horizontal part for backward prediction.
private  int motion_horiz_forw_code
          The motion code value of horizontal part for forward prediction.
private  int motion_horiz_forw_r
          The motion residual value of horizontal part for forward prediction.
private  int motion_verti_back_code
          The motion code value of vertical part for backward prediction.
private  int motion_verti_back_r
          The motion residual value of vertical part for backward prediction.
private  int motion_verti_forw_code
          The motion code value of vertical part for forward prediction.
private  int motion_verti_forw_r
          The motion residual value of vertical part for forward prediction.
private  io_tool mpeg_stream
          The input movie's data bit stream.
private  int[] non_intramatrix
          A quantization matrix for non intra frames.
private  int[] nullmatrix
          A matrix of zeros.
static int P_TYPE
          P FRAME frame type constanta.
private  int past_intra_address
          The past MB address.
private  int[][][] Pel_buffer
          The "Pel_buffer" is a main feature of the video scanner. 3 frames are stored at: Pel_buffer[0] Pel_buffer[1] Pel_buffer[2] The frame at index "ak_idx" is the frame coming into being.
private  int[] pel1
          The array to grab the referred area from predicted frame.
private  int[] pel2
          The array to grab the referred area from predicted frame.
private  int Pic_rate
          The frame rate code used by the MPEG standard given in the sequence header.
private  int Pic_Type
          The type of the frame (I, B, or P).
private  int Pict_Count
          The Pict Count value specified in the group of pictures header.
private static int PICTURE_START_CODE
          MPEG video layer constanta.
private  int pixel_per_col_line
          The number of pixels per colour line.
private  int pixel_per_lum_line
          The number of pixels per luminance line.
private  MPEG1 Player
          The reference to the applet.
private  int pred_idx
          The index of the frame for forward prediction.
private  boolean quant_matrix
          True if the quantizer matrix (intra or nonintra) should be loaded from MPEG stream.
private  int Quant_scale
          The quantization factor.
private  int Second
          The Second time value specified in the group of pictures header.
private static int SEQ_END_CODE
          MPEG video layer constanta.
private static int SEQ_START_CODE
          MPEG video layer constanta.
private static int SLICE_MAX_START_CODE
          MPEG video layer constanta.
private static int SLICE_MIN_START_CODE
          MPEG video layer constanta.
private  int Temp_ref
          The display order of the picture in the group of pictures.
private static int USER_START_CODE
          MPEG VIDEO layer constanta.
private  int VBV_buffer
          The vbv buffer size specified in the sequence header.
private  int VBV_Delay
          The VBV delay value of the frame.
private  java.lang.Thread video_thread
          The "Video Decoder" thread object.
private  int Width
          The width in pixels of the movie data.
private  int[] zigzag
          The reverse zigzag scan order.
 
Constructor Summary
(package private) MPEG_video(MPEG1 play, io_tool tool)
          Constructs a MPEG_video object, notices the parameters, inits "non_intra" and "null" matrixes and creates an VLC (Hufmann) decoder object.
 
Method Summary
private  void correct_col_pixel(int nr)
          The method "correct_col_pixel" is called in predicted macro blocks.
private  void correct_lum_pixel(int nr)
          The method "correct_lum_pixel" is called in predicted macro blocks.
 void join()
          Waits until the "Video Decoder" thread is dead.
private  void Parse_Block(int nr)
          The method "Parse_Block" parses a block according to ISO 11172-2.
private  void Parse_group_of_pictures()
          The method "Parse_group_of_pictures" parses the group of pictures according to ISO 11172-2.
private  void Parse_macroblock(int b_nr)
          The method "Parse_macroblock" parses a macroblock according to ISO 11172-2.
private  void Parse_picture()
          The method "Parse_picture" parses a picture according to ISO 11172-2.
private  void Parse_sequence_header()
          The method "Parse_sequence_header" parses the sequence header according to ISO 11172-2.
private  void Parse_slice()
          The method "Parse_slice" parses a slice according to ISO 11172-2.
 void run()
          The method "run" parses the MPEG video stream according to ISO 11172-2 and performs some initial steps.
private  void set_col_pixel(int nr)
          The method "set_col_pixel" takes the re-transformed chrominance values and places them at the appropriate position.
private  void set_dct_diff(int dct_diff, int dct_size)
          The method "set_dct_diff" computes the DCT difference according to ISO 11172-2.
private  void set_lum_pixel(int nr)
          The method "set_lum_pixel" takes the re-transformed luminance values and places them at the appropriate position.
 void start()
          Starts the "Video Decoder" thread.
 void stop()
          Stops the "Video Decoder" thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mpeg_stream

private io_tool mpeg_stream
The input movie's data bit stream.


Huf

private Huffmann Huf
The VLC (Hufmann) decoder.


nullmatrix

private int[] nullmatrix
A matrix of zeros.


intramatrix

private int[] intramatrix
The default intramatrix.


zigzag

private final int[] zigzag
The reverse zigzag scan order.


idct

private IDCT idct
An IDCT object to tranform the DCT coefficients.


dct_recon

private int[] dct_recon
The values before IDCT transformation.


non_intramatrix

private int[] non_intramatrix
A quantization matrix for non intra frames.


lum_block

private boolean lum_block
False if in the current macroblock hasn't had any luminance blocks.


dct_dc_cr_past

private int dct_dc_cr_past
The value of past DC (cr) value.


dct_dc_cb_past

private int dct_dc_cb_past
The value of past DC (cb) value.


dct_dc_y_past

private int dct_dc_y_past
The value of past DC (y) value.


Pel_buffer

private int[][][] Pel_buffer
The "Pel_buffer" is a main feature of the video scanner. 3 frames are stored at:
				Pel_buffer[0]
				Pel_buffer[1]
				Pel_buffer[2]
The frame at index "ak_idx" is the frame coming into being. The frame at index "pred_idx" is the frame for forward prediction. The frame at index "back_idx" is the frame for backward prediction. The method "Parse_Picture" administers the values of these 3 variables. The index in second dimension determins whether the information is:
		luminance   information 	-	Pel_buffer[?][0]
		chrominance information (cr)	-	Pel_buffer[?][1]
 		chrominance information	(cb)	-	Pel_buffer[?][2]
 


ak_idx

private int ak_idx
The index of the frame coming into being.


pred_idx

private int pred_idx
The index of the frame for forward prediction.


back_idx

private int back_idx
The index of the frame for backward prediction.


Player

private MPEG1 Player
The reference to the applet.


SEQ_END_CODE

private static final int SEQ_END_CODE
MPEG video layer constanta.

See Also:
Constant Field Values

SEQ_START_CODE

private static final int SEQ_START_CODE
MPEG video layer constanta.

See Also:
Constant Field Values

GOP_START_CODE

private static final int GOP_START_CODE
MPEG video layer constanta.

See Also:
Constant Field Values

PICTURE_START_CODE

private static final int PICTURE_START_CODE
MPEG video layer constanta.

See Also:
Constant Field Values

SLICE_MIN_START_CODE

private static final int SLICE_MIN_START_CODE
MPEG video layer constanta.

See Also:
Constant Field Values

SLICE_MAX_START_CODE

private static final int SLICE_MAX_START_CODE
MPEG video layer constanta.

See Also:
Constant Field Values

EXT_START_CODE

private static final int EXT_START_CODE
MPEG VIDEO layer constanta.

See Also:
Constant Field Values

USER_START_CODE

private static final int USER_START_CODE
MPEG VIDEO layer constanta.

See Also:
Constant Field Values

I_TYPE

public static final int I_TYPE
I FRAME frame type constanta.

See Also:
Constant Field Values

P_TYPE

public static final int P_TYPE
P FRAME frame type constanta.

See Also:
Constant Field Values

B_TYPE

public static final int B_TYPE
B FRAME frame type constanta.

See Also:
Constant Field Values

Width

private int Width
The width in pixels of the movie data.


Height

private int Height
The height in pixels of the movie data.


Asp_ratio

private int Asp_ratio
The aspect ratio used by the MPEG standard given in the sequence headerr.


Pic_rate

private int Pic_rate
The frame rate code used by the MPEG standard given in the sequence header.


mb_width

private int mb_width
The macroblock width.


mb_height

private int mb_height
The macroblock height.


Bit_rate

private int Bit_rate
The bit rate specified in the sequence header.


VBV_buffer

private int VBV_buffer
The vbv buffer size specified in the sequence header.


const_param

private boolean const_param
True if the constrained parameter flag was set in the sequence header and false otherwise.


quant_matrix

private boolean quant_matrix
True if the quantizer matrix (intra or nonintra) should be loaded from MPEG stream.


Hour

private int Hour
The Hour time value specified in the group of pictures header.


Minute

private int Minute
The Minute time value specified in the group of pictures header.


Second

private int Second
The Second time value specified in the group of pictures header.


Pict_Count

private int Pict_Count
The Pict Count value specified in the group of pictures header.


Drop_Flag

private boolean Drop_Flag
The Drop Flag value specified in the group of pictures header.


Closed_Group

private boolean Closed_Group
The Closed Group value specified in the group of pictures header.


Broken_Link

private boolean Broken_Link
The Broken Link value specified in the group of pictures header.


Temp_ref

private int Temp_ref
The display order of the picture in the group of pictures.


Pic_Type

private int Pic_Type
The type of the frame (I, B, or P).


Frame_nr_offset

private int Frame_nr_offset
The first frame number of last group of pictures.


Frame_nr

private int Frame_nr
The frame number in the movie.


VBV_Delay

private int VBV_Delay
The VBV delay value of the frame.


Full_pel_forw_vector

private boolean Full_pel_forw_vector
Equals true if full pixel accuracy is used for forward prediction, equals false if half pixel accuracy is used.


forw_f_code

private int forw_f_code
The motion code value for forward prediction.


forward_f

private int forward_f
The the size of the motion data for forward prediction.


forward_r_size

private int forward_r_size
The size of residual value for forward prediction.


motion_horiz_forw_code

private int motion_horiz_forw_code
The motion code value of horizontal part for forward prediction.


motion_horiz_forw_r

private int motion_horiz_forw_r
The motion residual value of horizontal part for forward prediction.


motion_verti_forw_code

private int motion_verti_forw_code
The motion code value of vertical part for forward prediction.


motion_verti_forw_r

private int motion_verti_forw_r
The motion residual value of vertical part for forward prediction.


Full_pel_back_vector

private boolean Full_pel_back_vector
Equals true if full pixel accuracy is used for backward prediction, equals false if half pixel accuracy is used.


backward_f_code

private int backward_f_code
The motion code value for backward prediction.


backward_f

private int backward_f
The the size of the motion data for backward prediction.


backward_r_size

private int backward_r_size
The size of residual value for backward prediction.


motion_horiz_back_code

private int motion_horiz_back_code
The motion code value of horizontal part for backward prediction.


motion_horiz_back_r

private int motion_horiz_back_r
The motion residual value of horizontal part for backward prediction.


motion_verti_back_code

private int motion_verti_back_code
The motion code value of vertical part for backward prediction.


motion_verti_back_r

private int motion_verti_back_r
The motion residual value of vertical part for backward prediction.


Quant_scale

private int Quant_scale
The quantization factor.


macro_block_address

private int macro_block_address
The actual MB address.


past_intra_address

private int past_intra_address
The past MB address.


mb_row

private int mb_row
The actual row position of the macro block.


mb_column

private int mb_column
The actual column position of the macro block.


macro_block_motion_forward

private boolean macro_block_motion_forward
True if motion vector for forward prediction exists.


macro_block_motion_backward

private boolean macro_block_motion_backward
True if motion vector for backward prediction exists.


macro_block_pattern

private boolean macro_block_pattern
True if a coded block pattern supplied.


macro_block_quant

private boolean macro_block_quant
True if a new quantization factor is supplied.


macro_block_intra

private boolean macro_block_intra
True if a macro block is for intra coded frames.


pel1

private int[] pel1
The array to grab the referred area from predicted frame.


pel2

private int[] pel2
The array to grab the referred area from predicted frame.


Forward

private motion_data Forward
The object of class "motion_data" to notice and compute the forward motion values.


Backward

private motion_data Backward
The object of class "motion_data" to notice and compute the backward motion values.


pixel_per_lum_line

private int pixel_per_lum_line
The number of pixels per luminance line.


pixel_per_col_line

private int pixel_per_col_line
The number of pixels per colour line.


lum_y_incr

private int lum_y_incr
The increment for the luminance line, equals to pixel_per_lum_line - 8.


col_y_incr

private int col_y_incr
The increment for the luminance line, equals to pixel_per_col_line - 8.


video_thread

private volatile java.lang.Thread video_thread
The "Video Decoder" thread object.


error_count

private int error_count
The current amount of printed video errors.


moribund

private volatile java.lang.Thread moribund
The "Video Decoder" thread that is being stopped.

Constructor Detail

MPEG_video

MPEG_video(MPEG1 play,
           io_tool tool)
Constructs a MPEG_video object, notices the parameters, inits "non_intra" and "null" matrixes and creates an VLC (Hufmann) decoder object.

Parameters:
play - the reference to the applet.
tool - the input movie's data bit stream.
Method Detail

start

public void start()
Starts the "Video Decoder" thread.


stop

public void stop()
Stops the "Video Decoder" thread.


join

public void join()
Waits until the "Video Decoder" thread is dead.


run

public void run()
The method "run" parses the MPEG video stream according to ISO 11172-2 and performs some initial steps. This method is called by the JRE after the "Video Decoder" thread is started.

Specified by:
run in interface java.lang.Runnable

Parse_sequence_header

private void Parse_sequence_header()
                            throws java.lang.InterruptedException,
                                   java.io.EOFException
The method "Parse_sequence_header" parses the sequence header according to ISO 11172-2.

Throws:
java.lang.InterruptedException - if another process interrupts the current process.
java.io.EOFException - if the end of the file has been reached.

Parse_group_of_pictures

private void Parse_group_of_pictures()
                              throws java.lang.InterruptedException,
                                     java.io.EOFException
The method "Parse_group_of_pictures" parses the group of pictures according to ISO 11172-2.

Throws:
java.lang.InterruptedException - if another process interrupts the current process.
java.io.EOFException - if the end of the file has been reached.

Parse_picture

private void Parse_picture()
                    throws java.lang.InterruptedException,
                           java.io.EOFException
The method "Parse_picture" parses a picture according to ISO 11172-2.

Throws:
java.lang.InterruptedException - if another process interrupts the current process.
java.io.EOFException - if the end of the file has been reached.

Parse_slice

private final void Parse_slice()
                        throws java.lang.InterruptedException,
                               java.io.EOFException
The method "Parse_slice" parses a slice according to ISO 11172-2. It determines quantization scale and the macroblock address of the first macro block of the slice.

Throws:
java.lang.InterruptedException - if another process interrupts the current process.
java.io.EOFException - if the end of the file has been reached.

Parse_macroblock

private final void Parse_macroblock(int b_nr)
                             throws java.lang.InterruptedException,
                                    java.io.EOFException
The method "Parse_macroblock" parses a macroblock according to ISO 11172-2. It is one of the most complex methods because of the great variety of the constitution of a macroblock. The constitution and existence of the the most information fields depends on the constitution and existence of information fields before.

Furthermore the decoding process is controlled by this method. In some situations some variables must be reset to some default values or in case of skipped macroblocks implizit values must be applied.

Bear in mind that some variables used in this method are member (class) variables for later reference!

Parameters:
b_nr - the macroblock number in slice.
Throws:
java.lang.InterruptedException - if another process interrupts the current process.
java.io.EOFException - if the end of the file has been reached.

Parse_Block

private final void Parse_Block(int nr)
                        throws java.lang.InterruptedException,
                               java.io.EOFException
The method "Parse_Block" parses a block according to ISO 11172-2. Thereby the DC and AC coefficients are reconstructed and placed into the "dct_recon" field in de-"zigzag"-ed order. After that the IDCT routine is called. The method counts the coefficients and calls a sparse IDCT method if the coefficient count is 1.

Parameters:
nr - the block number (0..6) in macroblock.
Throws:
java.lang.InterruptedException - if another process interrupts the current process.
java.io.EOFException - if the end of the file has been reached.

set_dct_diff

private void set_dct_diff(int dct_diff,
                          int dct_size)
The method "set_dct_diff" computes the DCT difference according to ISO 11172-2. It sets "dct_recon[0]".

Parameters:
dct_diff - the difference of the DC coefficient
dct_size - the size of the DC coefficient.

set_lum_pixel

private void set_lum_pixel(int nr)
The method "set_lum_pixel" takes the re-transformed luminance values and places them at the appropriate position. Note that the variables:
 			pixel_per_lum_line
			mb_row
			mb_column
 
are computed in "run()" as soon it was possible.


set_col_pixel

private void set_col_pixel(int nr)
The method "set_col_pixel" takes the re-transformed chrominance values and places them at the appropriate position.

Note that the variables:
 			pixel_per_col_line
			mb_row
			mb_column
 
are computed in "run()" as soon it was possible.

Parameters:
nr - the block number (0..6) in macroblock.

correct_lum_pixel

private void correct_lum_pixel(int nr)
The method "correct_lum_pixel" is called in predicted macro blocks. Because the values in "dct_recon" are motion compensation information the task of this method is to correct the already supplied (copied) luminance values.

Note that the variables:
 			pixel_per_lum_line
			lum_y_incr
			mb_row
			mb_column
 
are computed in "run()" as soon it was possible.

Parameters:
nr - the block number (0..6) in macroblock.

correct_col_pixel

private void correct_col_pixel(int nr)
The method "correct_col_pixel" is called in predicted macro blocks. Because the values in "dct_recon" are motion compensation information the task of this method is to correct the already supplied (copied) chrominance values.

Note that the variables:
 			pixel_per_col_line
			col_y_incr
			mb_row
			mb_column
 
are computed in "run()" as soon it was possible.

Parameters:
nr - the block number (0..6) in macroblock.