Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
9f586d2b
authored
Feb 10, 2022
by
olly
Committed by
Ian Baker
Feb 17, 2022
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Trim CodecDelay/PreSkip In New OpusDecoder Instances By Default
PiperOrigin-RevId: 427819209
parent
d5cb1007
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
0 deletions
extensions/opus/src/main/java/com/google/android/exoplayer2/ext/opus/OpusDecoder.java
extensions/opus/src/test/java/com/google/android/exoplayer2/ext/opus/OpusDecoderTest.java
extensions/opus/src/main/java/com/google/android/exoplayer2/ext/opus/OpusDecoder.java
View file @
9f586d2b
...
@@ -97,6 +97,7 @@ public final class OpusDecoder
...
@@ -97,6 +97,7 @@ public final class OpusDecoder
}
}
preSkipSamples
=
getPreSkipSamples
(
initializationData
);
preSkipSamples
=
getPreSkipSamples
(
initializationData
);
seekPreRollSamples
=
getSeekPreRollSamples
(
initializationData
);
seekPreRollSamples
=
getSeekPreRollSamples
(
initializationData
);
skipSamples
=
preSkipSamples
;
byte
[]
headerBytes
=
initializationData
.
get
(
0
);
byte
[]
headerBytes
=
initializationData
.
get
(
0
);
if
(
headerBytes
.
length
<
19
)
{
if
(
headerBytes
.
length
<
19
)
{
...
...
extensions/opus/src/test/java/com/google/android/exoplayer2/ext/opus/OpusDecoderTest.java
View file @
9f586d2b
...
@@ -17,11 +17,16 @@ package com.google.android.exoplayer2.ext.opus;
...
@@ -17,11 +17,16 @@ package com.google.android.exoplayer2.ext.opus;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
androidx.annotation.Nullable
;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.decoder.DecoderInputBuffer
;
import
com.google.android.exoplayer2.decoder.SimpleDecoderOutputBuffer
;
import
com.google.android.exoplayer2.util.LibraryLoader
;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.ImmutableList
;
import
java.nio.ByteBuffer
;
import
java.nio.ByteBuffer
;
import
java.nio.ByteOrder
;
import
java.nio.ByteOrder
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
...
@@ -29,9 +34,14 @@ import org.junit.runner.RunWith;
...
@@ -29,9 +34,14 @@ import org.junit.runner.RunWith;
@RunWith
(
AndroidJUnit4
.
class
)
@RunWith
(
AndroidJUnit4
.
class
)
public
final
class
OpusDecoderTest
{
public
final
class
OpusDecoderTest
{
private
static
final
LibraryLoader
LOADER
=
new
LibraryLoader
(
"opusV2JNI"
);
private
static
final
byte
[]
HEADER
=
private
static
final
byte
[]
HEADER
=
new
byte
[]
{
79
,
112
,
117
,
115
,
72
,
101
,
97
,
100
,
0
,
2
,
1
,
56
,
0
,
0
,
-
69
,
-
128
,
0
,
0
,
0
};
new
byte
[]
{
79
,
112
,
117
,
115
,
72
,
101
,
97
,
100
,
0
,
2
,
1
,
56
,
0
,
0
,
-
69
,
-
128
,
0
,
0
,
0
};
private
static
final
byte
[]
ENCODED_DATA
=
new
byte
[]
{-
4
};
private
static
final
int
DECODED_DATA_SIZE
=
3840
;
private
static
final
int
HEADER_PRE_SKIP_SAMPLES
=
14337
;
private
static
final
int
HEADER_PRE_SKIP_SAMPLES
=
14337
;
private
static
final
int
DEFAULT_SEEK_PRE_ROLL_SAMPLES
=
3840
;
private
static
final
int
DEFAULT_SEEK_PRE_ROLL_SAMPLES
=
3840
;
...
@@ -39,6 +49,7 @@ public final class OpusDecoderTest {
...
@@ -39,6 +49,7 @@ public final class OpusDecoderTest {
private
static
final
ImmutableList
<
byte
[]>
HEADER_ONLY_INITIALIZATION_DATA
=
private
static
final
ImmutableList
<
byte
[]>
HEADER_ONLY_INITIALIZATION_DATA
=
ImmutableList
.
of
(
HEADER
);
ImmutableList
.
of
(
HEADER
);
private
static
final
long
PRE_SKIP_NANOS
=
6_500_000
;
private
static
final
long
CUSTOM_PRE_SKIP_SAMPLES
=
28674
;
private
static
final
long
CUSTOM_PRE_SKIP_SAMPLES
=
28674
;
private
static
final
byte
[]
CUSTOM_PRE_SKIP_BYTES
=
private
static
final
byte
[]
CUSTOM_PRE_SKIP_BYTES
=
buildNativeOrderByteArray
(
sampleCountToNanoseconds
(
CUSTOM_PRE_SKIP_SAMPLES
));
buildNativeOrderByteArray
(
sampleCountToNanoseconds
(
CUSTOM_PRE_SKIP_SAMPLES
));
...
@@ -50,6 +61,11 @@ public final class OpusDecoderTest {
...
@@ -50,6 +61,11 @@ public final class OpusDecoderTest {
private
static
final
ImmutableList
<
byte
[]>
FULL_INITIALIZATION_DATA
=
private
static
final
ImmutableList
<
byte
[]>
FULL_INITIALIZATION_DATA
=
ImmutableList
.
of
(
HEADER
,
CUSTOM_PRE_SKIP_BYTES
,
CUSTOM_SEEK_PRE_ROLL_BYTES
);
ImmutableList
.
of
(
HEADER
,
CUSTOM_PRE_SKIP_BYTES
,
CUSTOM_SEEK_PRE_ROLL_BYTES
);
@Before
public
void
setUp
()
{
assertThat
(
LOADER
.
isAvailable
()).
isTrue
();
}
@Test
@Test
public
void
getChannelCount
()
{
public
void
getChannelCount
()
{
int
channelCount
=
OpusDecoder
.
getChannelCount
(
HEADER
);
int
channelCount
=
OpusDecoder
.
getChannelCount
(
HEADER
);
...
@@ -80,11 +96,56 @@ public final class OpusDecoderTest {
...
@@ -80,11 +96,56 @@ public final class OpusDecoderTest {
assertThat
(
seekPreRollSamples
).
isEqualTo
(
DEFAULT_SEEK_PRE_ROLL_SAMPLES
);
assertThat
(
seekPreRollSamples
).
isEqualTo
(
DEFAULT_SEEK_PRE_ROLL_SAMPLES
);
}
}
@Test
public
void
decode_removesPreSkipFromOutput
()
throws
OpusDecoderException
{
OpusDecoder
decoder
=
new
OpusDecoder
(
/* numInputBuffers= */
0
,
/* numOutputBuffers= */
0
,
/* initialInputBufferSize= */
0
,
createInitializationData
(
/* preSkipNanos= */
PRE_SKIP_NANOS
),
/* cryptoConfig= */
null
,
/* outputFloat= */
false
);
DecoderInputBuffer
input
=
createInputBuffer
(
decoder
,
ENCODED_DATA
,
/* supplementalData= */
null
);
SimpleDecoderOutputBuffer
output
=
decoder
.
createOutputBuffer
();
assertThat
(
decoder
.
decode
(
input
,
output
,
false
)).
isNull
();
assertThat
(
output
.
data
.
remaining
())
.
isEqualTo
(
DECODED_DATA_SIZE
-
nanosecondsToBytes
(
PRE_SKIP_NANOS
));
}
private
static
long
sampleCountToNanoseconds
(
long
sampleCount
)
{
private
static
long
sampleCountToNanoseconds
(
long
sampleCount
)
{
return
(
sampleCount
*
C
.
NANOS_PER_SECOND
)
/
OpusDecoder
.
SAMPLE_RATE
;
return
(
sampleCount
*
C
.
NANOS_PER_SECOND
)
/
OpusDecoder
.
SAMPLE_RATE
;
}
}
private
static
long
nanosecondsToSampleCount
(
long
nanoseconds
)
{
return
(
nanoseconds
*
OpusDecoder
.
SAMPLE_RATE
)
/
C
.
NANOS_PER_SECOND
;
}
private
static
long
nanosecondsToBytes
(
long
nanoseconds
)
{
return
nanosecondsToSampleCount
(
nanoseconds
)
*
4
;
}
private
static
byte
[]
buildNativeOrderByteArray
(
long
value
)
{
private
static
byte
[]
buildNativeOrderByteArray
(
long
value
)
{
return
ByteBuffer
.
allocate
(
8
).
order
(
ByteOrder
.
nativeOrder
()).
putLong
(
value
).
array
();
return
ByteBuffer
.
allocate
(
8
).
order
(
ByteOrder
.
nativeOrder
()).
putLong
(
value
).
array
();
}
}
private
static
ImmutableList
<
byte
[]>
createInitializationData
(
long
preSkipNanos
)
{
byte
[]
preSkip
=
buildNativeOrderByteArray
(
preSkipNanos
);
return
ImmutableList
.
of
(
HEADER
,
preSkip
,
CUSTOM_SEEK_PRE_ROLL_BYTES
);
}
private
static
DecoderInputBuffer
createInputBuffer
(
OpusDecoder
decoder
,
byte
[]
data
,
@Nullable
byte
[]
supplementalData
)
{
DecoderInputBuffer
input
=
decoder
.
createInputBuffer
();
input
.
ensureSpaceForWrite
(
data
.
length
);
input
.
data
.
put
(
data
);
input
.
data
.
position
(
0
).
limit
(
data
.
length
);
if
(
supplementalData
!=
null
)
{
input
.
resetSupplementalData
(
supplementalData
.
length
);
input
.
supplementalData
.
put
(
supplementalData
).
rewind
();
input
.
addFlag
(
C
.
BUFFER_FLAG_HAS_SUPPLEMENTAL_DATA
);
}
return
input
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment