mediaframe.mpeg1
Class io_tool

java.lang.Object
  |
  +--mediaframe.mpeg1.io_tool

public class io_tool
extends java.lang.Object

The io_tool class implements the functionality for accessing to the input movie's data stream as a bit stream. It contains methods for reading, skiping, matching with the pattern, giving "back" next/previous "n" bits from/to the data stream.


Field Summary
private  int _type
          The type of the stream to read (audio/video).
(package private)  int bit_pos
          The bit-"pointer", contains the number of the current bit in the bit shift register.
private  int BlockPos
          The byte-"pointer", contains the number of the current byte in the data block.
private  int BlockSize
          The size of the current data block in bytes.
private  DataBuffer buffer
          The current DataBuffer with the movie's data to read.
private  long[] Data
          The movie's data of the current data block.
private  boolean eof
          True if the end of the file has been reached.
private  long longword
          The bit shift register.
static int TYPE_AUDIO
          The Audio type of the input stream.
static int TYPE_VIDEO
          The Video type of the input stream.
 
Constructor Summary
io_tool(int type, DataBuffer buffer)
          Constructs an io_tool object with the specified values.
 
Method Summary
 int get_bits(int n)
          The method "get_bits" gets the next "n" bits from shift register interprets them as integer and returns this integer value.
private  void get_long()
          The method "get_long" grabs "bytes" from data input stream into the shift register "longword".
 DataBuffer getBuffer()
          Gets the current DataBuffer with the movie's data for reading.
 boolean is_eof()
          Returns the end of the file flag value.
 boolean next_bits(int pattern, int n)
          The method "next_bits" checks whether the next "n" bits match the "pattern".
 void next_start_code()
          The method "next_start_code" aligns the bit "pointer" to the next byte and tries to find the next MPEG start code.
private  void nextBlock()
          Gets next block of movie's data from the buffer and stores it't data into the local variables.
 int peek_bits(int n)
          The method "peek_bits" is like get_bits except it leaves the bits in the shift register.
 void skip_bits(int n)
          The method "skip_bits" skips the next "n" bits from shift register.
 void skip(long n)
          The method "skip(long n)" skips over n bytes but takes into account that some of them are already in shift register.
 void unget_bits(int n)
          The method "unget_bits" gives "n" bits back to the IO system.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_type

private int _type
The type of the stream to read (audio/video).


TYPE_AUDIO

public static final int TYPE_AUDIO
The Audio type of the input stream.

See Also:
Constant Field Values

TYPE_VIDEO

public static final int TYPE_VIDEO
The Video type of the input stream.

See Also:
Constant Field Values

bit_pos

int bit_pos
The bit-"pointer", contains the number of the current bit in the bit shift register.


longword

private long longword
The bit shift register.


eof

private boolean eof
True if the end of the file has been reached.


buffer

private DataBuffer buffer
The current DataBuffer with the movie's data to read.


Data

private long[] Data
The movie's data of the current data block.


BlockSize

private int BlockSize
The size of the current data block in bytes.


BlockPos

private int BlockPos
The byte-"pointer", contains the number of the current byte in the data block.

Constructor Detail

io_tool

public io_tool(int type,
               DataBuffer buffer)
Constructs an io_tool object with the specified values.

Parameters:
type - the type of the input stream.
buffer - the buffer with the movie's data.
Method Detail

getBuffer

public final DataBuffer getBuffer()
Gets the current DataBuffer with the movie's data for reading.

Returns:
the current DataBuffer object.

is_eof

public final boolean is_eof()
Returns the end of the file flag value.

Returns:
True if the end of the file has been reached.

skip

public final void skip(long n)
                throws java.lang.InterruptedException,
                       java.io.EOFException
The method "skip(long n)" skips over n bytes but takes into account that some of them are already in shift register.

Parameters:
n - the number of bytes to skip.
Throws:
java.lang.InterruptedException - raises if another process interrupts the current process.
java.io.EOFException - raises if the end of the file has been reached.

get_long

private final void get_long()
                     throws java.lang.InterruptedException,
                            java.io.EOFException
The method "get_long" grabs "bytes" from data input stream into the shift register "longword".

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

get_bits

public final int get_bits(int n)
                   throws java.lang.InterruptedException,
                          java.io.EOFException
The method "get_bits" gets the next "n" bits from shift register interprets them as integer and returns this integer value.

Parameters:
n - the amount of bits to get.
Returns:
the next "n" bits from shift register.
Throws:
java.lang.InterruptedException - raises if another process interrupts the current process.
java.io.EOFException - raises if the end of the file has been reached.

skip_bits

public final void skip_bits(int n)
                     throws java.lang.InterruptedException,
                            java.io.EOFException
The method "skip_bits" skips the next "n" bits from shift register. This method created because too much time was being wasted doing the math in get_bits when the result was just going to be thrown out.

Parameters:
n - the amount of bits to skip.
Throws:
java.lang.InterruptedException - raises if another process interrupts the current process.
java.io.EOFException - raises if the end of the file has been reached.

next_bits

public final boolean next_bits(int pattern,
                               int n)
                        throws java.lang.InterruptedException,
                               java.io.EOFException
The method "next_bits" checks whether the next "n" bits match the "pattern". If so it returns true; otherwise false.

Parameters:
pattern - the pattern to match.
n - the number of bits in the pattern.
Returns:
true if the next "n" bits match the "pattern".
Throws:
java.lang.InterruptedException - raises if another process interrupts the current process.
java.io.EOFException - raises if the end of the file has been reached.

peek_bits

public final int peek_bits(int n)
                    throws java.lang.InterruptedException,
                           java.io.EOFException
The method "peek_bits" is like get_bits except it leaves the bits in the shift register. Use it when you want to read the same bits more than once.

Parameters:
n - the number of bits to get.
Returns:
the next "n" bits from shift register.
Throws:
java.lang.InterruptedException - raises if another process interrupts the current process.
java.io.EOFException - raises if the end of the file has been reached.

unget_bits

public final void unget_bits(int n)
The method "unget_bits" gives "n" bits back to the IO system. Because "n" is always less than 32 this can be performed by a simple correction of the bit "pointer".

Parameters:
n - the number of bits to unget.

next_start_code

public final void next_start_code()
                           throws java.lang.InterruptedException,
                                  java.io.EOFException
The method "next_start_code" aligns the bit "pointer" to the next byte and tries to find the next MPEG start code. Because (only) start codes are made of a 24-bit ONE the method searches such a pattern. (see also: ISO 11172-2)

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

nextBlock

private final void nextBlock()
                      throws java.io.EOFException,
                             java.lang.InterruptedException
Gets next block of movie's data from the buffer and stores it't data into the local variables.

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