Commit a7d78594 by eguven Committed by Oliver Woodman

Shared super class for LibflacAudioTrackRenderer and LibopusAudioTrackRenderer.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=120225655
parent a760c9bf
...@@ -17,6 +17,7 @@ package com.google.android.exoplayer.ext.flac; ...@@ -17,6 +17,7 @@ package com.google.android.exoplayer.ext.flac;
import com.google.android.exoplayer.DecoderInputBuffer; import com.google.android.exoplayer.DecoderInputBuffer;
import com.google.android.exoplayer.util.extensions.SimpleDecoder; import com.google.android.exoplayer.util.extensions.SimpleDecoder;
import com.google.android.exoplayer.util.extensions.SimpleOutputBuffer;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.List; import java.util.List;
...@@ -25,21 +26,23 @@ import java.util.List; ...@@ -25,21 +26,23 @@ import java.util.List;
* Flac decoder. * Flac decoder.
*/ */
/* package */ final class FlacDecoder extends /* package */ final class FlacDecoder extends
SimpleDecoder<DecoderInputBuffer, FlacOutputBuffer, FlacDecoderException> { SimpleDecoder<DecoderInputBuffer, SimpleOutputBuffer, FlacDecoderException> {
private final int maxOutputBufferSize; private final int maxOutputBufferSize;
private final FlacJni decoder; private final FlacJni decoder;
/** /**
* Creates a Flac decoder. * Creates a Flac decoder.
* *
* @param numInputBuffers The number of input buffers. * @param numInputBuffers The number of input buffers.
* @param numOutputBuffers The number of output buffers. * @param numOutputBuffers The number of output buffers.
* @param initializationData Codec-specific initialization data. * @param initializationData Codec-specific initialization data. It should contain only one entry
* which is the flac file header.
* @throws FlacDecoderException Thrown if an exception occurs when initializing the decoder. * @throws FlacDecoderException Thrown if an exception occurs when initializing the decoder.
*/ */
public FlacDecoder(int numInputBuffers, int numOutputBuffers, List<byte[]> initializationData) public FlacDecoder(int numInputBuffers, int numOutputBuffers, List<byte[]> initializationData)
throws FlacDecoderException { throws FlacDecoderException {
super(new DecoderInputBuffer[numInputBuffers], new FlacOutputBuffer[numOutputBuffers]); super(new DecoderInputBuffer[numInputBuffers], new SimpleOutputBuffer[numOutputBuffers]);
if (initializationData.size() != 1) { if (initializationData.size() != 1) {
throw new FlacDecoderException("Wrong number of initialization data"); throw new FlacDecoderException("Wrong number of initialization data");
} }
...@@ -63,18 +66,13 @@ import java.util.List; ...@@ -63,18 +66,13 @@ import java.util.List;
} }
@Override @Override
public FlacOutputBuffer createOutputBuffer() { public SimpleOutputBuffer createOutputBuffer() {
return new FlacOutputBuffer(this); return new SimpleOutputBuffer(this);
}
@Override
protected void releaseOutputBuffer(FlacOutputBuffer buffer) {
super.releaseOutputBuffer(buffer);
} }
@Override @Override
public FlacDecoderException decode(DecoderInputBuffer inputBuffer, public FlacDecoderException decode(DecoderInputBuffer inputBuffer,
FlacOutputBuffer outputBuffer, boolean reset) { SimpleOutputBuffer outputBuffer, boolean reset) {
if (reset) { if (reset) {
decoder.flush(); decoder.flush();
} }
......
...@@ -15,10 +15,12 @@ ...@@ -15,10 +15,12 @@
*/ */
package com.google.android.exoplayer.ext.flac; package com.google.android.exoplayer.ext.flac;
import com.google.android.exoplayer.util.extensions.AudioDecoderException;
/** /**
* Thrown when an Flac decoder error occurs. * Thrown when an Flac decoder error occurs.
*/ */
public final class FlacDecoderException extends Exception { public final class FlacDecoderException extends AudioDecoderException {
/* package */ FlacDecoderException(String message) { /* package */ FlacDecoderException(String message) {
super(message); super(message);
......
...@@ -18,6 +18,7 @@ package com.google.android.exoplayer.ext.opus; ...@@ -18,6 +18,7 @@ package com.google.android.exoplayer.ext.opus;
import com.google.android.exoplayer.C; import com.google.android.exoplayer.C;
import com.google.android.exoplayer.DecoderInputBuffer; import com.google.android.exoplayer.DecoderInputBuffer;
import com.google.android.exoplayer.util.extensions.SimpleDecoder; import com.google.android.exoplayer.util.extensions.SimpleDecoder;
import com.google.android.exoplayer.util.extensions.SimpleOutputBuffer;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
...@@ -27,7 +28,7 @@ import java.util.List; ...@@ -27,7 +28,7 @@ import java.util.List;
* JNI wrapper for the libopus Opus decoder. * JNI wrapper for the libopus Opus decoder.
*/ */
/* package */ final class OpusDecoder extends /* package */ final class OpusDecoder extends
SimpleDecoder<DecoderInputBuffer, OpusOutputBuffer, OpusDecoderException> { SimpleDecoder<DecoderInputBuffer, SimpleOutputBuffer, OpusDecoderException> {
/** /**
* Whether the underlying libopus library is available. * Whether the underlying libopus library is available.
...@@ -77,7 +78,7 @@ import java.util.List; ...@@ -77,7 +78,7 @@ import java.util.List;
*/ */
public OpusDecoder(int numInputBuffers, int numOutputBuffers, int initialInputBufferSize, public OpusDecoder(int numInputBuffers, int numOutputBuffers, int initialInputBufferSize,
List<byte[]> initializationData) throws OpusDecoderException { List<byte[]> initializationData) throws OpusDecoderException {
super(new DecoderInputBuffer[numInputBuffers], new OpusOutputBuffer[numOutputBuffers]); super(new DecoderInputBuffer[numInputBuffers], new SimpleOutputBuffer[numOutputBuffers]);
byte[] headerBytes = initializationData.get(0); byte[] headerBytes = initializationData.get(0);
if (headerBytes.length < 19) { if (headerBytes.length < 19) {
throw new OpusDecoderException("Header size is too small."); throw new OpusDecoderException("Header size is too small.");
...@@ -139,18 +140,13 @@ import java.util.List; ...@@ -139,18 +140,13 @@ import java.util.List;
} }
@Override @Override
public OpusOutputBuffer createOutputBuffer() { public SimpleOutputBuffer createOutputBuffer() {
return new OpusOutputBuffer(this); return new SimpleOutputBuffer(this);
}
@Override
protected void releaseOutputBuffer(OpusOutputBuffer buffer) {
super.releaseOutputBuffer(buffer);
} }
@Override @Override
public OpusDecoderException decode(DecoderInputBuffer inputBuffer, public OpusDecoderException decode(DecoderInputBuffer inputBuffer,
OpusOutputBuffer outputBuffer, boolean reset) { SimpleOutputBuffer outputBuffer, boolean reset) {
if (reset) { if (reset) {
opusReset(nativeDecoderContext); opusReset(nativeDecoderContext);
// When seeking to 0, skip number of samples as specified in opus header. When seeking to // When seeking to 0, skip number of samples as specified in opus header. When seeking to
......
...@@ -15,10 +15,12 @@ ...@@ -15,10 +15,12 @@
*/ */
package com.google.android.exoplayer.ext.opus; package com.google.android.exoplayer.ext.opus;
import com.google.android.exoplayer.util.extensions.AudioDecoderException;
/** /**
* Thrown when an Opus decoder error occurs. * Thrown when an Opus decoder error occurs.
*/ */
public final class OpusDecoderException extends Exception { public final class OpusDecoderException extends AudioDecoderException {
/* package */ OpusDecoderException(String message) { /* package */ OpusDecoderException(String message) {
super(message); super(message);
......
...@@ -59,13 +59,10 @@ public final class VpxOutputBuffer extends OutputBuffer { ...@@ -59,13 +59,10 @@ public final class VpxOutputBuffer extends OutputBuffer {
/* package */ void initForRgbFrame(int width, int height) { /* package */ void initForRgbFrame(int width, int height) {
this.width = width; this.width = width;
this.height = height; this.height = height;
this.yuvPlanes = null;
int minimumRgbSize = width * height * 2; int minimumRgbSize = width * height * 2;
if (data == null || data.capacity() < minimumRgbSize) { initData(minimumRgbSize);
data = ByteBuffer.allocateDirect(minimumRgbSize);
yuvPlanes = null;
}
data.position(0);
data.limit(minimumRgbSize);
} }
/** /**
...@@ -76,13 +73,12 @@ public final class VpxOutputBuffer extends OutputBuffer { ...@@ -76,13 +73,12 @@ public final class VpxOutputBuffer extends OutputBuffer {
this.width = width; this.width = width;
this.height = height; this.height = height;
this.colorspace = colorspace; this.colorspace = colorspace;
int yLength = yStride * height; int yLength = yStride * height;
int uvLength = uvStride * ((height + 1) / 2); int uvLength = uvStride * ((height + 1) / 2);
int minimumYuvSize = yLength + (uvLength * 2); int minimumYuvSize = yLength + (uvLength * 2);
if (data == null || data.capacity() < minimumYuvSize) { initData(minimumYuvSize);
data = ByteBuffer.allocateDirect(minimumYuvSize);
}
data.limit(minimumYuvSize);
if (yuvPlanes == null) { if (yuvPlanes == null) {
yuvPlanes = new ByteBuffer[3]; yuvPlanes = new ByteBuffer[3];
} }
...@@ -104,4 +100,12 @@ public final class VpxOutputBuffer extends OutputBuffer { ...@@ -104,4 +100,12 @@ public final class VpxOutputBuffer extends OutputBuffer {
yuvStrides[2] = uvStride; yuvStrides[2] = uvStride;
} }
private void initData(int size) {
if (data == null || data.capacity() < size) {
data = ByteBuffer.allocateDirect(size);
}
data.position(0);
data.limit(size);
}
} }
/* /*
* Copyright (C) 2014 The Android Open Source Project * Copyright (C) 2016 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -13,44 +13,15 @@ ...@@ -13,44 +13,15 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.google.android.exoplayer.ext.opus; package com.google.android.exoplayer.util.extensions;
import com.google.android.exoplayer.util.extensions.OutputBuffer;
import java.nio.ByteBuffer;
/** /**
* Buffer for {@link OpusDecoder} output. * Thrown when a decoder error occurs.
*/ */
public final class OpusOutputBuffer extends OutputBuffer { public class AudioDecoderException extends Exception {
private final OpusDecoder owner;
public ByteBuffer data;
/* package */ OpusOutputBuffer(OpusDecoder owner) {
this.owner = owner;
}
/* package */ void init(int size) {
if (data == null || data.capacity() < size) {
data = ByteBuffer.allocateDirect(size);
}
data.position(0);
data.limit(size);
}
@Override
public void clear() {
super.clear();
if (data != null) {
data.clear();
}
}
@Override public AudioDecoderException(String detailMessage) {
public void release() { super(detailMessage);
owner.releaseOutputBuffer(this);
} }
} }
...@@ -13,26 +13,24 @@ ...@@ -13,26 +13,24 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.google.android.exoplayer.ext.flac; package com.google.android.exoplayer.util.extensions;
import com.google.android.exoplayer.util.extensions.OutputBuffer;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
/** /**
* Buffer for {@link FlacDecoder} output. * Buffer for {@link SimpleDecoder} output.
*/ */
public final class FlacOutputBuffer extends OutputBuffer { public class SimpleOutputBuffer extends OutputBuffer {
private final FlacDecoder owner; private final SimpleDecoder<?, SimpleOutputBuffer, ?> owner;
public ByteBuffer data; public ByteBuffer data;
/* package */ FlacOutputBuffer(FlacDecoder owner) { public SimpleOutputBuffer(SimpleDecoder<?, SimpleOutputBuffer, ?> owner) {
this.owner = owner; this.owner = owner;
} }
/* package */ void init(int size) { public void init(int size) {
if (data == null || data.capacity() < size) { if (data == null || data.capacity() < size) {
data = ByteBuffer.allocateDirect(size); data = ByteBuffer.allocateDirect(size);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment