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;
import com.google.android.exoplayer.DecoderInputBuffer;
import com.google.android.exoplayer.util.extensions.SimpleDecoder;
import com.google.android.exoplayer.util.extensions.SimpleOutputBuffer;
import java.nio.ByteBuffer;
import java.util.List;
......@@ -25,21 +26,23 @@ import java.util.List;
* Flac decoder.
*/
/* package */ final class FlacDecoder extends
SimpleDecoder<DecoderInputBuffer, FlacOutputBuffer, FlacDecoderException> {
SimpleDecoder<DecoderInputBuffer, SimpleOutputBuffer, FlacDecoderException> {
private final int maxOutputBufferSize;
private final FlacJni decoder;
/**
* Creates a Flac decoder.
*
* @param numInputBuffers The number of input 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.
*/
public FlacDecoder(int numInputBuffers, int numOutputBuffers, List<byte[]> initializationData)
throws FlacDecoderException {
super(new DecoderInputBuffer[numInputBuffers], new FlacOutputBuffer[numOutputBuffers]);
super(new DecoderInputBuffer[numInputBuffers], new SimpleOutputBuffer[numOutputBuffers]);
if (initializationData.size() != 1) {
throw new FlacDecoderException("Wrong number of initialization data");
}
......@@ -63,18 +66,13 @@ import java.util.List;
}
@Override
public FlacOutputBuffer createOutputBuffer() {
return new FlacOutputBuffer(this);
}
@Override
protected void releaseOutputBuffer(FlacOutputBuffer buffer) {
super.releaseOutputBuffer(buffer);
public SimpleOutputBuffer createOutputBuffer() {
return new SimpleOutputBuffer(this);
}
@Override
public FlacDecoderException decode(DecoderInputBuffer inputBuffer,
FlacOutputBuffer outputBuffer, boolean reset) {
SimpleOutputBuffer outputBuffer, boolean reset) {
if (reset) {
decoder.flush();
}
......
......@@ -15,10 +15,12 @@
*/
package com.google.android.exoplayer.ext.flac;
import com.google.android.exoplayer.util.extensions.AudioDecoderException;
/**
* Thrown when an Flac decoder error occurs.
*/
public final class FlacDecoderException extends Exception {
public final class FlacDecoderException extends AudioDecoderException {
/* package */ FlacDecoderException(String message) {
super(message);
......
......@@ -18,6 +18,7 @@ package com.google.android.exoplayer.ext.opus;
import com.google.android.exoplayer.C;
import com.google.android.exoplayer.DecoderInputBuffer;
import com.google.android.exoplayer.util.extensions.SimpleDecoder;
import com.google.android.exoplayer.util.extensions.SimpleOutputBuffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
......@@ -27,7 +28,7 @@ import java.util.List;
* JNI wrapper for the libopus Opus decoder.
*/
/* package */ final class OpusDecoder extends
SimpleDecoder<DecoderInputBuffer, OpusOutputBuffer, OpusDecoderException> {
SimpleDecoder<DecoderInputBuffer, SimpleOutputBuffer, OpusDecoderException> {
/**
* Whether the underlying libopus library is available.
......@@ -77,7 +78,7 @@ import java.util.List;
*/
public OpusDecoder(int numInputBuffers, int numOutputBuffers, int initialInputBufferSize,
List<byte[]> initializationData) throws OpusDecoderException {
super(new DecoderInputBuffer[numInputBuffers], new OpusOutputBuffer[numOutputBuffers]);
super(new DecoderInputBuffer[numInputBuffers], new SimpleOutputBuffer[numOutputBuffers]);
byte[] headerBytes = initializationData.get(0);
if (headerBytes.length < 19) {
throw new OpusDecoderException("Header size is too small.");
......@@ -139,18 +140,13 @@ import java.util.List;
}
@Override
public OpusOutputBuffer createOutputBuffer() {
return new OpusOutputBuffer(this);
}
@Override
protected void releaseOutputBuffer(OpusOutputBuffer buffer) {
super.releaseOutputBuffer(buffer);
public SimpleOutputBuffer createOutputBuffer() {
return new SimpleOutputBuffer(this);
}
@Override
public OpusDecoderException decode(DecoderInputBuffer inputBuffer,
OpusOutputBuffer outputBuffer, boolean reset) {
SimpleOutputBuffer outputBuffer, boolean reset) {
if (reset) {
opusReset(nativeDecoderContext);
// When seeking to 0, skip number of samples as specified in opus header. When seeking to
......
......@@ -15,10 +15,12 @@
*/
package com.google.android.exoplayer.ext.opus;
import com.google.android.exoplayer.util.extensions.AudioDecoderException;
/**
* Thrown when an Opus decoder error occurs.
*/
public final class OpusDecoderException extends Exception {
public final class OpusDecoderException extends AudioDecoderException {
/* package */ OpusDecoderException(String message) {
super(message);
......
......@@ -59,13 +59,10 @@ public final class VpxOutputBuffer extends OutputBuffer {
/* package */ void initForRgbFrame(int width, int height) {
this.width = width;
this.height = height;
this.yuvPlanes = null;
int minimumRgbSize = width * height * 2;
if (data == null || data.capacity() < minimumRgbSize) {
data = ByteBuffer.allocateDirect(minimumRgbSize);
yuvPlanes = null;
}
data.position(0);
data.limit(minimumRgbSize);
initData(minimumRgbSize);
}
/**
......@@ -76,13 +73,12 @@ public final class VpxOutputBuffer extends OutputBuffer {
this.width = width;
this.height = height;
this.colorspace = colorspace;
int yLength = yStride * height;
int uvLength = uvStride * ((height + 1) / 2);
int minimumYuvSize = yLength + (uvLength * 2);
if (data == null || data.capacity() < minimumYuvSize) {
data = ByteBuffer.allocateDirect(minimumYuvSize);
}
data.limit(minimumYuvSize);
initData(minimumYuvSize);
if (yuvPlanes == null) {
yuvPlanes = new ByteBuffer[3];
}
......@@ -104,4 +100,12 @@ public final class VpxOutputBuffer extends OutputBuffer {
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");
* you may not use this file except in compliance with the License.
......@@ -13,44 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer.ext.opus;
import com.google.android.exoplayer.util.extensions.OutputBuffer;
import java.nio.ByteBuffer;
package com.google.android.exoplayer.util.extensions;
/**
* Buffer for {@link OpusDecoder} output.
* Thrown when a decoder error occurs.
*/
public final class OpusOutputBuffer extends OutputBuffer {
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();
}
}
public class AudioDecoderException extends Exception {
@Override
public void release() {
owner.releaseOutputBuffer(this);
public AudioDecoderException(String detailMessage) {
super(detailMessage);
}
}
......@@ -13,26 +13,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer.ext.flac;
import com.google.android.exoplayer.util.extensions.OutputBuffer;
package com.google.android.exoplayer.util.extensions;
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;
/* package */ FlacOutputBuffer(FlacDecoder owner) {
public SimpleOutputBuffer(SimpleDecoder<?, SimpleOutputBuffer, ?> owner) {
this.owner = owner;
}
/* package */ void init(int size) {
public void init(int size) {
if (data == null || data.capacity() < 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