fi.helsinki.cs.ohtu.mpeg2
Class AudioStream

java.lang.Object
  extended by fi.helsinki.cs.ohtu.mpeg2.ElementaryStream
      extended by fi.helsinki.cs.ohtu.mpeg2.AudioStream

public class AudioStream
extends ElementaryStream

Represents an elementary stream of MPEG audio data. This class provides a relatively high-level interface to write audio streams. The class collects sequential audio frames together and generates timestamps for them. The data are then delivered to packetizers.


Field Summary
private  boolean closed
           
private  boolean discont
           
private  double duration
           
private  boolean firstAu
           
private  java.util.List<AVPacketizer> packers
           
private  long ptsBase
           
 
Constructor Summary
AudioStream()
          Creates a new AudioStream instance.
AudioStream(long pts)
          Creates a new AudioStream instance with given initial PTS.
 
Method Summary
 void close()
          Closes this ElementaryStream.
private  byte[] encodeFrame(AudioFrame frame)
          Encodes an audio frame in an array of bytes.
 void flush()
          Flushes buffered data, if any, to the packetizers.
 AVPacketizer getPacketizer(int asid)
          Creates a new packetizer for this AudioStream.
 AVPacketizer getPacketizer(int asid, int decoderBuffer)
          Creates a packetizer for this AudioStream.
 long getPts()
          Returns the current PTS.
 void releasePacketizer(AVPacketizer esp)
          Releases a packetizer for this ElementaryStream.
 void setPts(double pts)
          Sets the presentation timestamp (PTS) for the next access unit.
 void setPts(long pts)
          Sets the presentation timestamp (PTS) for the next access unit.
 void write(AudioFrame frame)
          Writes an audio frame into this AudioStream and updates the PTS accordingly.
 void write(AudioFrame frame, long pts)
          Writes an audio frame with given PTS into this AudioStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ptsBase

private long ptsBase

duration

private double duration

firstAu

private boolean firstAu

discont

private boolean discont

closed

private boolean closed

packers

private java.util.List<AVPacketizer> packers
Constructor Detail

AudioStream

public AudioStream(long pts)
Creates a new AudioStream instance with given initial PTS.

Parameters:
pts - the PTS for the first access unit

AudioStream

public AudioStream()
Creates a new AudioStream instance. The PTS defaults to zero.

Method Detail

getPts

public long getPts()
Returns the current PTS.

Returns:
the current PTS, in ticks of the 90kHz clock

setPts

public void setPts(long pts)
Sets the presentation timestamp (PTS) for the next access unit.

Parameters:
pts - the PTS, in ticks of the 90kHz clock

setPts

public void setPts(double pts)
Sets the presentation timestamp (PTS) for the next access unit.

Parameters:
pts - the PTS, in seconds

write

public void write(AudioFrame frame,
                  long pts)
Writes an audio frame with given PTS into this AudioStream. The PTS will be used as a time base for the following audio frames.

Parameters:
frame - the audio frame to write
pts - the PTs for the audio frame

write

public void write(AudioFrame frame)
Writes an audio frame into this AudioStream and updates the PTS accordingly.

Parameters:
frame - the audio frame to write

getPacketizer

public AVPacketizer getPacketizer(int asid,
                                  int decoderBuffer)
Creates a packetizer for this AudioStream. Audio stream number, asid, defines the stream id for audio packets. decoderBuffer defines how much audio data can be waiting to be decoded at the audio decoder at any moment. The lower the number the lower the resource demands. However, low buffer sizes make it difficult to maintain smooth playback.

Parameters:
asid - the stream number for the packetized stream, in range [0, 32]
decoderBuffer - the size of the audio decoder buffer, in bytes; has to be at least 3072
Returns:
the packetizer

getPacketizer

public AVPacketizer getPacketizer(int asid)
Creates a new packetizer for this AudioStream. The audio decoder buffer defaults to 4KiB.

Specified by:
getPacketizer in class ElementaryStream
Parameters:
asid - the stream number for the packetized stream, in range [0, 32]
Returns:
the packetizer
See Also:
getPacketizer(int, int)

releasePacketizer

public void releasePacketizer(AVPacketizer esp)
Description copied from class: ElementaryStream
Releases a packetizer for this ElementaryStream. After releasing the packetizer will not receive more data from this stream.

Specified by:
releasePacketizer in class ElementaryStream
Parameters:
esp - the packetizer to release

flush

public void flush()
Description copied from class: ElementaryStream
Flushes buffered data, if any, to the packetizers.

Specified by:
flush in class ElementaryStream

close

public void close()
Description copied from class: ElementaryStream
Closes this ElementaryStream. After this call no more data shall be written into this stream.

Overrides:
close in class ElementaryStream

encodeFrame

private byte[] encodeFrame(AudioFrame frame)
Encodes an audio frame in an array of bytes.

Parameters:
frame - the audio frame to be encoded
Returns:
the coded array of bytes