private IStreamCoder getStreamCoder(int streamIndex)
{
// if the coder does not exists, get it
IStreamCoder coder = mCoders.get(streamIndex);
if (coder == null)
{
// test valid stream index
int numStreams = getContainer().getNumStreams();
if (streamIndex < 0 || streamIndex >= numStreams)
throw new RuntimeException("invalid stream index");
// estabish all streams in the container, informing listeners of
// new streams without needing to wait for a packet for each
// stream to show up
for(int i = 0; i < numStreams; i++)
{
coder = mCoders.get(i);
if (coder == null)
{
// now get the coder for the given stream index
IStream stream = getContainer().getStream(i);
try
{
coder = stream.getStreamCoder();
// put the coder into the coder map, event if it not a supported
// type so that on further reads it will find the coder but choose
// not decode unsupported types
mCoders.put(i, coder);
// and release our coder to the list
coder = null;
super.onAddStream(new AddStreamEvent(this, i));
}
finally
{
if (coder != null) coder.delete();
if (stream != null)
stream.delete();
}
}
}
}
coder = mCoders.get(streamIndex);
IStream stream = getContainer().getStream(streamIndex);
try
{
ICodec.Type type = coder.getCodecType();
// if the coder is not open, open it
// NOTE: MediaReader currently supports audio & video streams
if (!coder.isOpen()
&& (type == ICodec.Type.CODEC_TYPE_AUDIO || type == ICodec.Type.CODEC_TYPE_VIDEO))
{
if (coder.open() < 0)
throw new RuntimeException("could not open coder for stream: "
+ streamIndex);
mOpenedStreams.add(stream);
super.onOpenCoder(new OpenCoderEvent(this, stream.getIndex()));
stream = null;