Parse opus gain correctly as a signed value

Issue: #7046
PiperOrigin-RevId: 303354941
This commit is contained in:
olly 2020-03-27 17:15:49 +00:00 committed by Oliver Woodman
parent 46a40c6026
commit db61af23b9
5 changed files with 17 additions and 4 deletions

View File

@ -132,6 +132,8 @@
* Add support for x86_64 for the ffmpeg extension.
* Cast extension: Implement playlist API and deprecate the old queue
manipulation API.
* Opus extension: Fix parsing of negative gain values
([#7046](https://github.com/google/ExoPlayer/issues/7046)).
### 2.11.3 (2020-02-19) ###

View File

@ -38,7 +38,9 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class OpusPlaybackTest {
private static final String BEAR_OPUS_URI = "asset:///ogg/bear-opus.webm";
private static final String BEAR_OPUS_URI = "asset:///mka/bear-opus.mka";
private static final String BEAR_OPUS_NEGATIVE_GAIN_URI =
"asset:///mka/bear-opus-negative-gain.mka";
@Before
public void setUp() {
@ -52,6 +54,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());

View File

@ -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,

Binary file not shown.