mediaframe.mpeg1
Class MPEG_Reader

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

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

The MPEG_Reader class consists of two buffers, one for video and one for audio. It starts the "MPEG_Reader" thread and fills these buffers. It starts rebuffering and calls endOfBuffer method of the applet after the (re-)buffering process is finished.


Field Summary
private  boolean _eof
          True if the end of the movie has been reached.
private  java.io.InputStream _in
          The input stream with the movie data.
private  long _long
          The 4 bytes buffer for the input data.
private  long _read_time
          The time stamp of the last readed frame.
private  java.lang.Thread _thread
          The "MPEG_Reader" thread object.
private  int _waiting
          The number of threads which waits the writer side.
private  DataBuffer audioBuffer
          The DataBuffer for audio stream.
static int BUFFERING
          Constanta, the "buffering" state of the reader.
static int CLOSED
          Constanta, the "closed" state of the reader.
 int contentLength
          The length of the movie file.
private  int initBufferSize
          Equals to the initial value of the maxBufferSize.
 long lastPrintedTime
          Last time when the "(re)-buffering" percent was printed.
 int loadBytes
          The number of bytes loaded into the buffer.
static long MASK
          4 bytes mask (0xffffffff).
 int maxBufferSize
          The number of bytes that should be put into the buffer before the movie playback could start.
 int minBufferSize
          The minimum number of bytes in the buffer before the "re-buffering" starts.
private  java.lang.Thread moribund
          The "MPEG_Reader" thread that is being stopped.
 int printedPercent
          Last printed "(re)-buffering" percent value.
static int READING
          Constanta, the "reading" state of the reader.
static int REBUFFERING
          Constanta, the "re-buffering" state of the reader.
 int reBufferingSize
          The number of bytes that should be put into the buffer during the "rebuffering" process.
private  int state
          Current state of the reader.
private  DataBuffer videoBuffer
          The DataBuffer for video stream.
 MPEG1 videoPlayer
          The reference to the main applet object.
 
Constructor Summary
MPEG_Reader(MPEG1 videoPlayer, java.io.InputStream in, int maxBufferSize, int minBufferSize, int contentLength)
          Constructs a MPEG_Reader object with the specified parameters and starts the "MPEG_Reader" thread.
 
Method Summary
 void close()
          Closes the input stream.
 void endOfBuffering()
          Invoked when the reader ends buffering and is ready to play the movie.
 void endOfReBuffering()
          Invoked when the reader ends the "re-buffering" process and is ready to play the movie.
 DataBuffer getAudioBuffer()
          Gets the audio buffer instance.
 int getState()
          Returns the state of the reader.
 DataBuffer getVideoBuffer()
          Gets the video buffer instance.
 boolean isEOF()
          Returns true if the end of the movie has been reached.
 void join()
          Waits until the "MPEG_Reader" thread is dead.
 void notify_reader()
          Notifies the reader side about the next portion of data.
 void read_element()
          Reads the current frame (audio or video) into the buffer.
 void read_to_long()
          Reads one byte from the input stream into 4 bytes buffer.
 void run()
          Start point and main loop of the "MPEG_Reader" thread.
 void startRebuffering()
          Starts the "re-buffering" process.
 void stop()
          Stops the "MPEG_Reader" thread.
 void wait_for_read()
          Waits the writer for the next block of data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MASK

public static final long MASK
4 bytes mask (0xffffffff).

See Also:
Constant Field Values

loadBytes

public int loadBytes
The number of bytes loaded into the buffer.


BUFFERING

public static final int BUFFERING
Constanta, the "buffering" state of the reader.

See Also:
Constant Field Values

REBUFFERING

public static final int REBUFFERING
Constanta, the "re-buffering" state of the reader.

See Also:
Constant Field Values

READING

public static final int READING
Constanta, the "reading" state of the reader.

See Also:
Constant Field Values

CLOSED

public static final int CLOSED
Constanta, the "closed" state of the reader.

See Also:
Constant Field Values

state

private int state
Current state of the reader.


maxBufferSize

public int maxBufferSize
The number of bytes that should be put into the buffer before the movie playback could start.


minBufferSize

public int minBufferSize
The minimum number of bytes in the buffer before the "re-buffering" starts.


reBufferingSize

public int reBufferingSize
The number of bytes that should be put into the buffer during the "rebuffering" process.


initBufferSize

private int initBufferSize
Equals to the initial value of the maxBufferSize.


contentLength

public int contentLength
The length of the movie file.


printedPercent

public int printedPercent
Last printed "(re)-buffering" percent value.


lastPrintedTime

public long lastPrintedTime
Last time when the "(re)-buffering" percent was printed.


videoPlayer

public MPEG1 videoPlayer
The reference to the main applet object.


audioBuffer

private DataBuffer audioBuffer
The DataBuffer for audio stream.


videoBuffer

private DataBuffer videoBuffer
The DataBuffer for video stream.


_long

private long _long
The 4 bytes buffer for the input data.


_eof

private boolean _eof
True if the end of the movie has been reached.


_waiting

private int _waiting
The number of threads which waits the writer side.


_thread

private volatile java.lang.Thread _thread
The "MPEG_Reader" thread object.


_in

private java.io.InputStream _in
The input stream with the movie data.


_read_time

private long _read_time
The time stamp of the last readed frame.


moribund

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

Constructor Detail

MPEG_Reader

public MPEG_Reader(MPEG1 videoPlayer,
                   java.io.InputStream in,
                   int maxBufferSize,
                   int minBufferSize,
                   int contentLength)
Constructs a MPEG_Reader object with the specified parameters and starts the "MPEG_Reader" thread.

Parameters:
videoPlayer - the reference to the main applet object.
in - the input stream with the movie data.
maxBufferSize - the number of bytes that should be put into the buffer before the movie playback could start.
minBufferSize - the minimum number of bytes in the buffer before the "re-buffering" starts.
contentLength - the length of the movie file.
Method Detail

read_element

public void read_element()
                  throws java.lang.Exception
Reads the current frame (audio or video) into the buffer.

Throws:
java.lang.Exception - if an error occurs.

read_to_long

public void read_to_long()
                  throws java.lang.Exception
Reads one byte from the input stream into 4 bytes buffer.

Throws:
java.lang.Exception - if an error occurs.

run

public void run()
Start point and main loop of the "MPEG_Reader" thread.

Calls the method that reads the frames until the end of the movie file is reached or this thread is stopped.

Specified by:
run in interface java.lang.Runnable

wait_for_read

public void wait_for_read()
                   throws java.lang.InterruptedException
Waits the writer for the next block of data.

Throws:
java.lang.InterruptedException - if another process interrupts this process.

notify_reader

public void notify_reader()
Notifies the reader side about the next portion of data.


stop

public void stop()
Stops the "MPEG_Reader" thread.


join

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


close

public void close()
Closes the input stream.


endOfBuffering

public void endOfBuffering()
Invoked when the reader ends buffering and is ready to play the movie.


startRebuffering

public void startRebuffering()
Starts the "re-buffering" process.


endOfReBuffering

public void endOfReBuffering()
Invoked when the reader ends the "re-buffering" process and is ready to play the movie.


getAudioBuffer

public DataBuffer getAudioBuffer()
Gets the audio buffer instance.

Returns:
the audio buffer instance.

getVideoBuffer

public DataBuffer getVideoBuffer()
Gets the video buffer instance.

Returns:
the video buffer instance.

isEOF

public boolean isEOF()
Returns true if the end of the movie has been reached.

Returns:
true if the end of the movie has been reached.

getState

public int getState()
Returns the state of the reader.

Returns:
current state of the reader.