mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Parse opus gain correctly as a signed value
Issue: #7046 PiperOrigin-RevId: 303354941
This commit is contained in:
parent
46a40c6026
commit
db61af23b9
@ -132,6 +132,8 @@
|
|||||||
* Add support for x86_64 for the ffmpeg extension.
|
* Add support for x86_64 for the ffmpeg extension.
|
||||||
* Cast extension: Implement playlist API and deprecate the old queue
|
* Cast extension: Implement playlist API and deprecate the old queue
|
||||||
manipulation API.
|
manipulation API.
|
||||||
|
* Opus extension: Fix parsing of negative gain values
|
||||||
|
([#7046](https://github.com/google/ExoPlayer/issues/7046)).
|
||||||
|
|
||||||
### 2.11.3 (2020-02-19) ###
|
### 2.11.3 (2020-02-19) ###
|
||||||
|
|
||||||
|
@ -38,7 +38,9 @@ import org.junit.runner.RunWith;
|
|||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class OpusPlaybackTest {
|
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
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@ -52,6 +54,11 @@ public class OpusPlaybackTest {
|
|||||||
playUri(BEAR_OPUS_URI);
|
playUri(BEAR_OPUS_URI);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void basicPlaybackNegativeGain() throws Exception {
|
||||||
|
playUri(BEAR_OPUS_NEGATIVE_GAIN_URI);
|
||||||
|
}
|
||||||
|
|
||||||
private void playUri(String uri) throws Exception {
|
private void playUri(String uri) throws Exception {
|
||||||
TestPlaybackRunnable testPlaybackRunnable =
|
TestPlaybackRunnable testPlaybackRunnable =
|
||||||
new TestPlaybackRunnable(Uri.parse(uri), ApplicationProvider.getApplicationContext());
|
new TestPlaybackRunnable(Uri.parse(uri), ApplicationProvider.getApplicationContext());
|
||||||
|
@ -90,8 +90,8 @@ import java.util.List;
|
|||||||
if (channelCount > 8) {
|
if (channelCount > 8) {
|
||||||
throw new OpusDecoderException("Invalid channel count: " + channelCount);
|
throw new OpusDecoderException("Invalid channel count: " + channelCount);
|
||||||
}
|
}
|
||||||
int preskip = readLittleEndian16(headerBytes, 10);
|
int preskip = readUnsignedLittleEndian16(headerBytes, 10);
|
||||||
int gain = readLittleEndian16(headerBytes, 16);
|
int gain = readSignedLittleEndian16(headerBytes, 16);
|
||||||
|
|
||||||
byte[] streamMap = new byte[8];
|
byte[] streamMap = new byte[8];
|
||||||
int numStreams;
|
int numStreams;
|
||||||
@ -228,12 +228,16 @@ import java.util.List;
|
|||||||
return (int) (ns * SAMPLE_RATE / 1000000000);
|
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;
|
int value = input[offset] & 0xFF;
|
||||||
value |= (input[offset + 1] & 0xFF) << 8;
|
value |= (input[offset + 1] & 0xFF) << 8;
|
||||||
return value;
|
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,
|
private native long opusInit(int sampleRate, int channelCount, int numStreams, int numCoupled,
|
||||||
int gain, byte[] streamMap);
|
int gain, byte[] streamMap);
|
||||||
private native int opusDecode(long decoder, long timeUs, ByteBuffer inputBuffer, int inputSize,
|
private native int opusDecode(long decoder, long timeUs, ByteBuffer inputBuffer, int inputSize,
|
||||||
|
BIN
testdata/src/test/assets/mka/bear-opus-negative-gain.mka
vendored
Normal file
BIN
testdata/src/test/assets/mka/bear-opus-negative-gain.mka
vendored
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user