I want to decode datagram packets that contains H264 video with mediaDecoder. (the packets are sent from rtsp server over rtp)
I suppose I'm doing something wrong cause i'm getting -1 (that means no such buffer is currently available) from dequeueInputBuffer()
I'm searching for days but can't find suitable solution.
what is the mean of this result? what i'm doing wrong?
here is my code. please help me to get it working.
private void decodeVideo() {
new Thread(new Runnable() {
@Override
public void run() {
MediaCodec codec = MediaCodec.createDecoderByType("video/avc");
MediaFormat mediaFormat = MediaFormat.createVideoFormat(
"video/avc", 640, 480);
MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();
codec.configure(mediaFormat, mHolder.getSurface(), null, 0);
codec.start();
ByteBuffer[] inputBuffers = codec.getInputBuffers();
ByteBuffer[] outputBuffers = codec.getOutputBuffers();
while (flag) {
int inputBufferIndex = codec.dequeueInputBuffer(10000);
if (inputBufferIndex >= 0) {
while (mPackets.size() <= 0) {
try {
Log.d(TAG, "nopackets");
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Log.d(TAG, "now I have packets!");
DatagramPacket currentDatagram = mPackets.remove();
inputBuffers[inputBufferIndex] = ByteBuffer
.wrap(currentDatagram.getData());
codec.queueInputBuffer(inputBufferIndex, 0,
currentDatagram.getData().length, 10000, 0);
}
int outputBufferIndex = codec.dequeueOutputBuffer(info,
10000);
if (outputBufferIndex >= 0) {
codec.releaseOutputBuffer(outputBufferIndex, true);
} else if (outputBufferIndex == MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED) {
outputBuffers = codec.getOutputBuffers();
} else if (outputBufferIndex == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {
// Subsequent data will conform to new format.
MediaFormat format = codec.getOutputFormat();
}
}
codec.stop();
codec.release();
codec = null;
}
}).start();
}
thank you for giving your time.