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
1b9992cf
authored
Aug 13, 2020
by
samrobinson
Committed by
kim-vde
Aug 17, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add a GTS test for MediaFormat change occurring at the correct time.
PiperOrigin-RevId: 326428782
parent
339e3f89
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
1 deletions
playbacktests/src/androidTest/java/com/google/android/exoplayer2/playbacktests/gts/DebugRenderersFactory.java
playbacktests/src/androidTest/java/com/google/android/exoplayer2/playbacktests/gts/DebugRenderersFactory.java
View file @
1b9992cf
...
@@ -20,6 +20,7 @@ import static java.lang.Math.max;
...
@@ -20,6 +20,7 @@ import static java.lang.Math.max;
import
android.content.Context
;
import
android.content.Context
;
import
android.media.MediaCodec
;
import
android.media.MediaCodec
;
import
android.media.MediaCrypto
;
import
android.media.MediaCrypto
;
import
android.media.MediaFormat
;
import
android.os.Handler
;
import
android.os.Handler
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.RequiresApi
;
import
androidx.annotation.RequiresApi
;
...
@@ -32,9 +33,11 @@ import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
...
@@ -32,9 +33,11 @@ import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import
com.google.android.exoplayer2.mediacodec.MediaCodecAdapter
;
import
com.google.android.exoplayer2.mediacodec.MediaCodecAdapter
;
import
com.google.android.exoplayer2.mediacodec.MediaCodecInfo
;
import
com.google.android.exoplayer2.mediacodec.MediaCodecInfo
;
import
com.google.android.exoplayer2.mediacodec.MediaCodecSelector
;
import
com.google.android.exoplayer2.mediacodec.MediaCodecSelector
;
import
com.google.android.exoplayer2.util.Util
;
import
com.google.android.exoplayer2.video.MediaCodecVideoRenderer
;
import
com.google.android.exoplayer2.video.MediaCodecVideoRenderer
;
import
com.google.android.exoplayer2.video.VideoRendererEventListener
;
import
com.google.android.exoplayer2.video.VideoRendererEventListener
;
import
java.nio.ByteBuffer
;
import
java.nio.ByteBuffer
;
import
java.util.ArrayDeque
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
/**
/**
...
@@ -42,6 +45,7 @@ import java.util.ArrayList;
...
@@ -42,6 +45,7 @@ import java.util.ArrayList;
* video buffer timestamp assertions, and modifies the default value for {@link
* video buffer timestamp assertions, and modifies the default value for {@link
* #setAllowedVideoJoiningTimeMs(long)} to be {@code 0}.
* #setAllowedVideoJoiningTimeMs(long)} to be {@code 0}.
*/
*/
// TODO: Move this class to `testutils` and add basic tests.
/* package */
final
class
DebugRenderersFactory
extends
DefaultRenderersFactory
{
/* package */
final
class
DebugRenderersFactory
extends
DefaultRenderersFactory
{
public
DebugRenderersFactory
(
Context
context
)
{
public
DebugRenderersFactory
(
Context
context
)
{
...
@@ -78,13 +82,19 @@ import java.util.ArrayList;
...
@@ -78,13 +82,19 @@ import java.util.ArrayList;
private
static
final
String
TAG
=
"DebugMediaCodecVideoRenderer"
;
private
static
final
String
TAG
=
"DebugMediaCodecVideoRenderer"
;
private
static
final
int
ARRAY_SIZE
=
1000
;
private
static
final
int
ARRAY_SIZE
=
1000
;
private
final
long
[]
timestampsList
=
new
long
[
ARRAY_SIZE
];
private
final
long
[]
timestampsList
;
private
final
ArrayDeque
<
Long
>
inputFormatChangeTimesUs
;
private
final
boolean
enableMediaFormatChangeTimeCheck
;
private
int
startIndex
;
private
int
startIndex
;
private
int
queueSize
;
private
int
queueSize
;
private
int
bufferCount
;
private
int
bufferCount
;
private
int
minimumInsertIndex
;
private
int
minimumInsertIndex
;
private
boolean
skipToPositionBeforeRenderingFirstFrame
;
private
boolean
skipToPositionBeforeRenderingFirstFrame
;
private
boolean
inputFormatChanged
;
private
boolean
outputMediaFormatChanged
;
@Nullable
private
MediaFormat
currentMediaFormat
;
public
DebugMediaCodecVideoRenderer
(
public
DebugMediaCodecVideoRenderer
(
Context
context
,
Context
context
,
...
@@ -100,6 +110,12 @@ import java.util.ArrayList;
...
@@ -100,6 +110,12 @@ import java.util.ArrayList;
eventHandler
,
eventHandler
,
eventListener
,
eventListener
,
maxDroppedFrameCountToNotify
);
maxDroppedFrameCountToNotify
);
timestampsList
=
new
long
[
ARRAY_SIZE
];
inputFormatChangeTimesUs
=
new
ArrayDeque
<>();
// As per [Internal ref: b/149818050, b/149751672], MediaFormat changes can occur early for
// SDK 29 and 30. Should be fixed for SDK 31 onwards.
enableMediaFormatChangeTimeCheck
=
Util
.
SDK_INT
<
29
||
Util
.
SDK_INT
>=
31
;
}
}
@Override
@Override
...
@@ -127,6 +143,13 @@ import java.util.ArrayList;
...
@@ -127,6 +143,13 @@ import java.util.ArrayList;
protected
void
resetCodecStateForFlush
()
{
protected
void
resetCodecStateForFlush
()
{
super
.
resetCodecStateForFlush
();
super
.
resetCodecStateForFlush
();
clearTimestamps
();
clearTimestamps
();
if
(
inputFormatChangeTimesUs
!=
null
)
{
inputFormatChangeTimesUs
.
clear
();
}
inputFormatChanged
=
false
;
outputMediaFormatChanged
=
false
;
currentMediaFormat
=
null
;
}
}
@Override
@Override
...
@@ -141,6 +164,7 @@ import java.util.ArrayList;
...
@@ -141,6 +164,7 @@ import java.util.ArrayList;
// Ensure timestamps of buffers queued after this format change are never inserted into the
// Ensure timestamps of buffers queued after this format change are never inserted into the
// queue of expected output timestamps before those of buffers that have already been queued.
// queue of expected output timestamps before those of buffers that have already been queued.
minimumInsertIndex
=
startIndex
+
queueSize
;
minimumInsertIndex
=
startIndex
+
queueSize
;
inputFormatChanged
=
true
;
}
}
@Override
@Override
...
@@ -148,6 +172,19 @@ import java.util.ArrayList;
...
@@ -148,6 +172,19 @@ import java.util.ArrayList;
super
.
onQueueInputBuffer
(
buffer
);
super
.
onQueueInputBuffer
(
buffer
);
insertTimestamp
(
buffer
.
timeUs
);
insertTimestamp
(
buffer
.
timeUs
);
maybeShiftTimestampsList
();
maybeShiftTimestampsList
();
if
(
inputFormatChanged
)
{
inputFormatChangeTimesUs
.
add
(
buffer
.
timeUs
);
inputFormatChanged
=
false
;
}
}
@Override
protected
void
onOutputFormatChanged
(
Format
format
,
@Nullable
MediaFormat
mediaFormat
)
{
super
.
onOutputFormatChanged
(
format
,
mediaFormat
);
if
(
mediaFormat
!=
null
&&
!
mediaFormat
.
equals
(
currentMediaFormat
))
{
outputMediaFormatChanged
=
true
;
currentMediaFormat
=
mediaFormat
;
}
}
}
@Override
@Override
...
@@ -208,6 +245,20 @@ import java.util.ArrayList;
...
@@ -208,6 +245,20 @@ import java.util.ArrayList;
+
"timestamp: "
+
expectedTimestampUs
+
". Instead got: "
+
presentationTimeUs
+
"timestamp: "
+
expectedTimestampUs
+
". Instead got: "
+
presentationTimeUs
+
" (Processed buffers since last flush: "
+
bufferCount
+
")."
);
+
" (Processed buffers since last flush: "
+
bufferCount
+
")."
);
}
}
if
(
outputMediaFormatChanged
)
{
long
inputFormatChangeTimeUs
=
inputFormatChangeTimesUs
.
remove
();
outputMediaFormatChanged
=
false
;
if
(
enableMediaFormatChangeTimeCheck
&&
presentationTimeUs
!=
inputFormatChangeTimeUs
)
{
throw
new
IllegalStateException
(
"Expected output MediaFormat change timestamp ("
+
presentationTimeUs
+
" us) to match input Format change timestamp ("
+
inputFormatChangeTimeUs
+
" us)."
);
}
}
}
}
private
void
clearTimestamps
()
{
private
void
clearTimestamps
()
{
...
...
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