Commit 69ca5349 by olly Committed by Oliver Woodman

Parse opus gain correctly as a signed value

Issue: #7046
PiperOrigin-RevId: 303354941
parent a9cbbf91
......@@ -24,6 +24,8 @@
in spherical playbacks
([#6761](https://github.com/google/ExoPlayer/issues/6761)).
* FFmpeg extension: Add support for x86_64.
* Opus extension: Fix parsing of negative gain values
([#7046](https://github.com/google/ExoPlayer/issues/7046)).
### 2.11.3 (2020-02-19) ###
......
......@@ -37,7 +37,9 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class OpusPlaybackTest {
private static final String BEAR_OPUS_URI = "asset:///bear-opus.webm";
private static final String BEAR_OPUS_URI = "asset:///bear-opus.mka";
private static final String BEAR_OPUS_NEGATIVE_GAIN_URI =
"asset:///bear-opus-negative-gain.mka";
@Before
public void setUp() {
......@@ -51,6 +53,11 @@ public class OpusPlaybackTest {
playUri(BEAR_OPUS_URI);
}
@Test
public void basicPlaybackNegativeGain() throws Exception {
playUri(BEAR_OPUS_NEGATIVE_GAIN_URI);
}
private void playUri(String uri) throws Exception {
TestPlaybackRunnable testPlaybackRunnable =
new TestPlaybackRunnable(Uri.parse(uri), ApplicationProvider.getApplicationContext());
......
......@@ -90,8 +90,8 @@ import java.util.List;
if (channelCount > 8) {
throw new OpusDecoderException("Invalid channel count: " + channelCount);
}
int preskip = readLittleEndian16(headerBytes, 10);
int gain = readLittleEndian16(headerBytes, 16);
int preskip = readUnsignedLittleEndian16(headerBytes, 10);
int gain = readSignedLittleEndian16(headerBytes, 16);
byte[] streamMap = new byte[8];
int numStreams;
......@@ -228,12 +228,16 @@ import java.util.List;
return (int) (ns * SAMPLE_RATE / 1000000000);
}
private static int readLittleEndian16(byte[] input, int offset) {
private static int readUnsignedLittleEndian16(byte[] input, int offset) {
int value = input[offset] & 0xFF;
value |= (input[offset + 1] & 0xFF) << 8;
return value;
}
private static int readSignedLittleEndian16(byte[] input, int offset) {
return (short) readUnsignedLittleEndian16(input, offset);
}
private native long opusInit(int sampleRate, int channelCount, int numStreams, int numCoupled,
int gain, byte[] streamMap);
private native int opusDecode(long decoder, long timeUs, ByteBuffer inputBuffer, int inputSize,
......
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