Fix OPUS packet in an endian-independent way
Reading the header id as an int assumed that the current endianness was little endian. Read to a byte array to remove this assumption.
This commit is contained in:
parent
80defdd8aa
commit
783719c72e
@ -5,14 +5,13 @@ import android.media.MediaCodec;
|
|||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public final class Streamer {
|
public final class Streamer {
|
||||||
|
|
||||||
private static final long PACKET_FLAG_CONFIG = 1L << 63;
|
private static final long PACKET_FLAG_CONFIG = 1L << 63;
|
||||||
private static final long PACKET_FLAG_KEY_FRAME = 1L << 62;
|
private static final long PACKET_FLAG_KEY_FRAME = 1L << 62;
|
||||||
|
|
||||||
private static final long AOPUSHDR = 0x5244485355504F41L; // "AOPUSHDR" in ASCII (little-endian)
|
|
||||||
|
|
||||||
private final FileDescriptor fd;
|
private final FileDescriptor fd;
|
||||||
private final Codec codec;
|
private final Codec codec;
|
||||||
private final boolean sendCodecMeta;
|
private final boolean sendCodecMeta;
|
||||||
@ -120,11 +119,14 @@ public final class Streamer {
|
|||||||
throw new IOException("Not enough data in OPUS config packet");
|
throw new IOException("Not enough data in OPUS config packet");
|
||||||
}
|
}
|
||||||
|
|
||||||
long id = buffer.getLong();
|
final byte[] opusHeaderId = {'A', 'O', 'P', 'U', 'S', 'H', 'D', 'R'};
|
||||||
if (id != AOPUSHDR) {
|
byte[] idBuffer = new byte[8];
|
||||||
|
buffer.get(idBuffer);
|
||||||
|
if (!Arrays.equals(idBuffer, opusHeaderId)) {
|
||||||
throw new IOException("OPUS header not found");
|
throw new IOException("OPUS header not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The size is in native byte-order
|
||||||
long sizeLong = buffer.getLong();
|
long sizeLong = buffer.getLong();
|
||||||
if (sizeLong < 0 || sizeLong >= 0x7FFFFFFF) {
|
if (sizeLong < 0 || sizeLong >= 0x7FFFFFFF) {
|
||||||
throw new IOException("Invalid block size in OPUS header: " + sizeLong);
|
throw new IOException("Invalid block size in OPUS header: " + sizeLong);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user