mediaframe.mpeg1
Class DataBuffer

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

public final class DataBuffer
extends java.lang.Object

A DataBuffer object represents a data stream (container of the information data blocks). It contains methods for storing and reading the information from the stream.

Author:
Konstantin Belous

Field Summary
private  long _start_time
          The start time of the reading side.
private  long _time_stamp
          The time stamp of the current frame to read.
private  int currentFrameIndex
          The frame index of the current frame in the vector of the frames to read the data.
private  DataBlock currentReadBlock
          The current data block to read the data.
private  DataFrame currentReadFrame
          The current frame to read the data.
private  DataBlock currentWriteBlock
          The current data block to write the data.
private  DataFrame currentWriteFrame
          The current frame to write the data.
private  boolean EOF
          True, if the end of the file has been reached.
private  java.util.Vector Frames
          The vector of the frames.
private  int lastSize
          The size the last information word (0-4).
private  long lastWord
          The last 0-4 information bytes (the last information word).
private  MPEG_Reader reader
          The MPEG_reader object (reader of the mpeg stream).
private  int type
          The type of the stream (video or audio).
 
Constructor Summary
DataBuffer(int type, MPEG_Reader reader)
          Constructs a DataBuffer with the specified type and MPEG_reader.
 
Method Summary
 void addToStartTime(long wait)
          Adds the specified value to the start playing time.
 int getBufferPosition()
          Gets current position of the buffer.
 DataFrame getCurrentReadFrame()
          Gets the current frame to read.
 long getCurrentTime()
          Returns time in milliseconds callibrated from the start of the movie.
 void initReaderSide()
          Resets the reader's side to zero state.
 boolean isEOF()
          Returns end of file flag.
 void printPercent(int currentPercent)
          Prints the current "buffering" percent.
 DataBlock readNextBlock()
          Reads the next DataBlock from the movie's buffer.
 void registerNewFrame(DataFrame newFrame)
          Registers the new frame to read movie's data.
 void saveCurrentFrame()
          Saves the current frame into the buffer.
 void saveLastFrame()
          Saves the current frame into the buffer as a last frame in the movie file.
private  void setNewBlock()
          Adds the length of the block to the total amount of the readed bytes.
 void setStartTime(long time)
          Sets the start playing time to the specified value.
 void write(int Byte)
          Puts the next information byte into the buffer of movie's data.
 
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 (video or audio).

See Also:
io_tool.TYPE_AUDIO, io_tool.TYPE_VIDEO

Frames

private java.util.Vector Frames
The vector of the frames.


currentFrameIndex

private int currentFrameIndex
The frame index of the current frame in the vector of the frames to read the data.


currentWriteBlock

private DataBlock currentWriteBlock
The current data block to write the data.


currentReadBlock

private DataBlock currentReadBlock
The current data block to read the data.


currentWriteFrame

private DataFrame currentWriteFrame
The current frame to write the data.


currentReadFrame

private DataFrame currentReadFrame
The current frame to read the data.


EOF

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


reader

private MPEG_Reader reader
The MPEG_reader object (reader of the mpeg stream).


_time_stamp

private long _time_stamp
The time stamp of the current frame to read.


_start_time

private long _start_time
The start time of the reading side.


lastWord

private long lastWord
The last 0-4 information bytes (the last information word).


lastSize

private int lastSize
The size the last information word (0-4).

Constructor Detail

DataBuffer

public DataBuffer(int type,
                  MPEG_Reader reader)
Constructs a DataBuffer with the specified type and MPEG_reader.

Parameters:
type - the type of the DataBuffer (video or audio).
reader - the MPEG_reader object (reader of the mpeg stream).
Method Detail

initReaderSide

public void initReaderSide()
Resets the reader's side to zero state.


readNextBlock

public final DataBlock readNextBlock()
                              throws java.io.EOFException,
                                     java.lang.InterruptedException
Reads the next DataBlock from the movie's buffer. If necessary waits for the writer process for the next block of data and calls the method that starts the "rebuffering" process of the applet after the free buffer size is less then the min buffer size. Sets EOF flag to true value if the end of the file has been reached.

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

setNewBlock

private void setNewBlock()
Adds the length of the block to the total amount of the readed bytes. Starts the "rebuffering" process of the applet if the free buffer size is less then the min buffer size.


getCurrentReadFrame

public DataFrame getCurrentReadFrame()
Gets the current frame to read.

Returns:
the current frame to read.

write

public void write(int Byte)
Puts the next information byte into the buffer of movie's data.

Parameters:
Byte - the next information byte to put.

printPercent

public void printPercent(int currentPercent)
Prints the current "buffering" percent.

Parameters:
currentPercent - the current percent.

saveCurrentFrame

public void saveCurrentFrame()
Saves the current frame into the buffer. Gets the last 0-3 bytes from it and adds it to the list of frames.


saveLastFrame

public void saveLastFrame()
Saves the current frame into the buffer as a last frame in the movie file. Gets the last 0-3 bytes from it and adds it to the list of frames.


isEOF

public boolean isEOF()
Returns end of file flag.

Returns:
true, if the end of the file has been reached.

registerNewFrame

public void registerNewFrame(DataFrame newFrame)
Registers the new frame to read movie's data.

Parameters:
newFrame - the frame to register.

addToStartTime

public void addToStartTime(long wait)
Adds the specified value to the start playing time.

Parameters:
wait - the value to add.

setStartTime

public void setStartTime(long time)
Sets the start playing time to the specified value.

Parameters:
time - the start playing time value to set.

getCurrentTime

public long getCurrentTime()
Returns time in milliseconds callibrated from the start of the movie.

Returns:
current playing time in milliseconds.

getBufferPosition

public int getBufferPosition()
Gets current position of the buffer.

Returns:
current buffer position.