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
4a059884
authored
May 11, 2023
by
tofunmi
Committed by
Ian Baker
May 12, 2023
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Refactor ChainingGlShaderProgramListener to use FrameConsumptionManager
PiperOrigin-RevId: 531180020
parent
25e793ff
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
52 deletions
library/effect/src/main/java/com/google/android/exoplayer2/effect/ChainingGlShaderProgramListener.java
library/effect/src/main/java/com/google/android/exoplayer2/effect/FrameConsumptionManager.java
library/effect/src/main/java/com/google/android/exoplayer2/effect/ChainingGlShaderProgramListener.java
View file @
4a059884
...
...
@@ -15,15 +15,9 @@
*/
package
com
.
google
.
android
.
exoplayer2
.
effect
;
import
android.util.Pair
;
import
androidx.annotation.GuardedBy
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.effect.GlShaderProgram.InputListener
;
import
com.google.android.exoplayer2.effect.GlShaderProgram.OutputListener
;
import
com.google.android.exoplayer2.util.GlTextureInfo
;
import
java.util.ArrayDeque
;
import
java.util.Queue
;
/**
* Connects a producing and a consuming {@link GlShaderProgram} instance.
...
...
@@ -35,15 +29,9 @@ import java.util.Queue;
implements
GlShaderProgram
.
InputListener
,
GlShaderProgram
.
OutputListener
{
private
final
GlShaderProgram
producingGlShaderProgram
;
private
final
GlShaderProgram
consumingGlShaderProgram
;
private
final
FrameConsumptionManager
frameConsumptionManager
;
private
final
VideoFrameProcessingTaskExecutor
videoFrameProcessingTaskExecutor
;
@GuardedBy
(
"this"
)
private
final
Queue
<
Pair
<
GlTextureInfo
,
Long
>>
availableFrames
;
@GuardedBy
(
"this"
)
private
int
consumingGlShaderProgramInputCapacity
;
/**
* Creates a new instance.
*
...
...
@@ -61,29 +49,14 @@ import java.util.Queue;
GlShaderProgram
consumingGlShaderProgram
,
VideoFrameProcessingTaskExecutor
videoFrameProcessingTaskExecutor
)
{
this
.
producingGlShaderProgram
=
producingGlShaderProgram
;
this
.
consumingGlShaderProgram
=
consumingGlShaderProgram
;
frameConsumptionManager
=
new
FrameConsumptionManager
(
consumingGlShaderProgram
,
videoFrameProcessingTaskExecutor
);
this
.
videoFrameProcessingTaskExecutor
=
videoFrameProcessingTaskExecutor
;
availableFrames
=
new
ArrayDeque
<>();
}
@Override
public
synchronized
void
onReadyToAcceptInputFrame
()
{
@Nullable
Pair
<
GlTextureInfo
,
Long
>
pendingFrame
=
availableFrames
.
poll
();
if
(
pendingFrame
==
null
)
{
consumingGlShaderProgramInputCapacity
++;
return
;
}
long
presentationTimeUs
=
pendingFrame
.
second
;
if
(
presentationTimeUs
==
C
.
TIME_END_OF_SOURCE
)
{
videoFrameProcessingTaskExecutor
.
submit
(
consumingGlShaderProgram:
:
signalEndOfCurrentInputStream
);
}
else
{
videoFrameProcessingTaskExecutor
.
submit
(
()
->
consumingGlShaderProgram
.
queueInputFrame
(
/* inputTexture= */
pendingFrame
.
first
,
presentationTimeUs
));
}
frameConsumptionManager
.
onReadyToAcceptInputFrame
();
}
@Override
...
...
@@ -94,32 +67,18 @@ import java.util.Queue;
@Override
public
synchronized
void
onFlush
()
{
consumingGlShaderProgramInputCapacity
=
0
;
availableFrames
.
clear
();
frameConsumptionManager
.
onFlush
();
videoFrameProcessingTaskExecutor
.
submit
(
producingGlShaderProgram:
:
flush
);
}
@Override
public
synchronized
void
onOutputFrameAvailable
(
GlTextureInfo
outputTexture
,
long
presentationTimeUs
)
{
if
(
consumingGlShaderProgramInputCapacity
>
0
)
{
videoFrameProcessingTaskExecutor
.
submit
(
()
->
consumingGlShaderProgram
.
queueInputFrame
(
/* inputTexture= */
outputTexture
,
presentationTimeUs
));
consumingGlShaderProgramInputCapacity
--;
}
else
{
availableFrames
.
add
(
new
Pair
<>(
outputTexture
,
presentationTimeUs
));
}
frameConsumptionManager
.
queueInputFrame
(
outputTexture
,
presentationTimeUs
);
}
@Override
public
synchronized
void
onCurrentOutputStreamEnded
()
{
if
(!
availableFrames
.
isEmpty
())
{
availableFrames
.
add
(
new
Pair
<>(
GlTextureInfo
.
UNSET
,
C
.
TIME_END_OF_SOURCE
));
}
else
{
videoFrameProcessingTaskExecutor
.
submit
(
consumingGlShaderProgram:
:
signalEndOfCurrentInputStream
);
}
frameConsumptionManager
.
signalEndOfCurrentStream
();
}
}
library/effect/src/main/java/com/google/android/exoplayer2/effect/FrameConsumptionManager.java
View file @
4a059884
...
...
@@ -26,12 +26,11 @@ import java.util.Queue;
/**
* Manages queueing frames and sending them to a given {@link GlShaderProgram
* consumingG
L
ShaderProgram} at a consumable pace.
* consumingG
l
ShaderProgram} at a consumable pace.
*
* <p>Frames are stored as a {@link GlTextureInfo} with a {@code presentationTimeUs}.
*/
// TODO(b/261820382): Converge ChainingGlShaderProgramListener with this class.
/* package */
final
class
FrameConsumptionManager
implements
GlShaderProgram
.
InputListener
{
private
final
GlShaderProgram
consumingGlShaderProgram
;
private
final
VideoFrameProcessingTaskExecutor
videoFrameProcessingTaskExecutor
;
...
...
@@ -45,8 +44,7 @@ import java.util.Queue;
/**
* Creates a new instance.
*
* @param consumingGlShaderProgram The {@link GlShaderProgram} for which this {@code
* texIdTextureManager} will be set as the {@link GlShaderProgram.InputListener}.
* @param consumingGlShaderProgram The {@link GlShaderProgram} that frames are queued to.
* @param videoFrameProcessingTaskExecutor The {@link VideoFrameProcessingTaskExecutor}.
*/
public
FrameConsumptionManager
(
...
...
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