Skip to content

Commit

Permalink
Merge pull request #1290 from pedroSG94/fix-decode-illegalstate
Browse files Browse the repository at this point in the history
update get input/uoput buffer on decoders
  • Loading branch information
pedroSG94 authored Oct 2, 2023
2 parents a5a0cf9 + 6667540 commit 173b283
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,6 @@ public double getTime() {
protected abstract void finished();

private void decode() {
ByteBuffer[] inputBuffers = codec.getInputBuffers();
ByteBuffer[] outputBuffers = codec.getOutputBuffers();
startTs = System.nanoTime() / 1000;
long sleepTime = 0;
long accumulativeTs = 0;
Expand All @@ -228,8 +226,13 @@ private void decode() {
int inIndex = codec.dequeueInputBuffer(10000);
int sampleSize = 0;
if (inIndex >= 0) {
ByteBuffer buffer = inputBuffers[inIndex];
sampleSize = extractor.readSampleData(buffer, 0);
ByteBuffer input;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
input = codec.getInputBuffer(inIndex);
} else {
input = codec.getInputBuffers()[inIndex];
}
sampleSize = extractor.readSampleData(input, 0);

long ts = System.nanoTime() / 1000 - startTs;
long extractorTs = extractor.getSampleTime();
Expand All @@ -248,7 +251,13 @@ private void decode() {
int outIndex = codec.dequeueOutputBuffer(bufferInfo, 10000);
if (outIndex >= 0) {
if (!sleep(sleepTime / 1000)) return;
boolean render = decodeOutput(outputBuffers[outIndex]);
ByteBuffer output;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
output = codec.getOutputBuffer(outIndex);
} else {
output = codec.getOutputBuffers()[outIndex];
}
boolean render = decodeOutput(output);
codec.releaseOutputBuffer(outIndex, render && bufferInfo.size != 0);
} else if ((bufferInfo.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0 || sampleSize < 0) {
Log.i(TAG, "end of file");
Expand Down

0 comments on commit 173b283

Please sign in to comment.