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
a4ad85d2
authored
Feb 17, 2023
by
tofunmi
Committed by
christosts
Feb 17, 2023
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
InternalTextureManager: delete texture after use
PiperOrigin-RevId: 510377977
parent
7614ac47
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
29 deletions
library/effect/src/main/java/com/google/android/exoplayer2/effect/InternalTextureManager.java
library/effect/src/main/java/com/google/android/exoplayer2/effect/InternalTextureManager.java
View file @
a4ad85d2
...
...
@@ -28,6 +28,7 @@ import com.google.android.exoplayer2.util.VideoFrameProcessingException;
import
com.google.android.exoplayer2.util.VideoFrameProcessor
;
import
java.util.Queue
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
org.checkerframework.checker.nullness.qual.MonotonicNonNull
;
/**
* Forwards a video frame produced from a {@link Bitmap} to a {@link GlShaderProgram} for
...
...
@@ -41,10 +42,12 @@ import java.util.concurrent.LinkedBlockingQueue;
// The queue holds all bitmaps with one or more frames pending to be sent downstream.
private
final
Queue
<
BitmapFrameSequenceInfo
>
pendingBitmaps
;
private
@MonotonicNonNull
TextureInfo
currentTextureInfo
;
private
int
downstreamShaderProgramCapacity
;
private
int
framesToQueueForCurrentBitmap
;
private
long
currentPresentationTimeUs
;
private
boolean
inputEnded
;
private
boolean
useHdr
;
private
boolean
outputEnded
;
/**
...
...
@@ -65,10 +68,6 @@ import java.util.concurrent.LinkedBlockingQueue;
@Override
public
void
onReadyToAcceptInputFrame
()
{
// TODO(b/262693274): Delete texture when last duplicate of the frame comes back from the shader
// program and change to only allocate one texId at a time. A change to the
// onInputFrameProcessed() method signature to include presentationTimeUs will probably be
// needed to do this.
videoFrameProcessingTaskExecutor
.
submit
(
()
->
{
downstreamShaderProgramCapacity
++;
...
...
@@ -103,48 +102,54 @@ import java.util.concurrent.LinkedBlockingQueue;
@WorkerThread
private
void
setupBitmap
(
Bitmap
bitmap
,
long
durationUs
,
float
frameRate
,
boolean
useHdr
)
throws
VideoFrameProcessingException
{
this
.
useHdr
=
useHdr
;
if
(
inputEnded
)
{
return
;
}
int
bitmapTexId
;
try
{
bitmapTexId
=
GlUtil
.
createTexture
(
bitmap
.
getWidth
(),
bitmap
.
getHeight
(),
/* useHighPrecisionColorComponents= */
useHdr
);
GLES20
.
glBindTexture
(
GLES20
.
GL_TEXTURE_2D
,
bitmapTexId
);
GLUtils
.
texImage2D
(
GLES20
.
GL_TEXTURE_2D
,
/* level= */
0
,
bitmap
,
/* border= */
0
);
GlUtil
.
checkGlError
();
}
catch
(
GlUtil
.
GlException
e
)
{
throw
VideoFrameProcessingException
.
from
(
e
);
}
TextureInfo
textureInfo
=
new
TextureInfo
(
bitmapTexId
,
/* fboId= */
C
.
INDEX_UNSET
,
bitmap
.
getWidth
(),
bitmap
.
getHeight
());
int
framesToAdd
=
(
int
)
floor
(
frameRate
*
(
durationUs
/
(
float
)
C
.
MICROS_PER_SECOND
));
long
frameDurationUs
=
(
long
)
floor
(
C
.
MICROS_PER_SECOND
/
frameRate
);
pendingBitmaps
.
add
(
new
BitmapFrameSequenceInfo
(
textureInfo
,
frameDurationUs
,
framesToAdd
));
pendingBitmaps
.
add
(
new
BitmapFrameSequenceInfo
(
bitmap
,
frameDurationUs
,
framesToAdd
));
maybeQueueToShaderProgram
();
}
@WorkerThread
private
void
maybeQueueToShaderProgram
()
{
private
void
maybeQueueToShaderProgram
()
throws
VideoFrameProcessingException
{
if
(
pendingBitmaps
.
isEmpty
()
||
downstreamShaderProgramCapacity
==
0
)
{
return
;
}
BitmapFrameSequenceInfo
currentBitmap
=
checkNotNull
(
pendingBitmaps
.
peek
());
BitmapFrameSequenceInfo
currentBitmap
Info
=
checkNotNull
(
pendingBitmaps
.
peek
());
if
(
framesToQueueForCurrentBitmap
==
0
)
{
framesToQueueForCurrentBitmap
=
currentBitmap
.
numberOfFrames
;
Bitmap
bitmap
=
currentBitmapInfo
.
bitmap
;
framesToQueueForCurrentBitmap
=
currentBitmapInfo
.
numberOfFrames
;
int
currentTexId
;
try
{
if
(
currentTextureInfo
!=
null
)
{
GlUtil
.
deleteTexture
(
currentTextureInfo
.
texId
);
}
currentTexId
=
GlUtil
.
createTexture
(
bitmap
.
getWidth
(),
bitmap
.
getHeight
(),
/* useHighPrecisionColorComponents= */
useHdr
);
GLES20
.
glBindTexture
(
GLES20
.
GL_TEXTURE_2D
,
currentTexId
);
GLUtils
.
texImage2D
(
GLES20
.
GL_TEXTURE_2D
,
/* level= */
0
,
bitmap
,
/* border= */
0
);
GlUtil
.
checkGlError
();
}
catch
(
GlUtil
.
GlException
e
)
{
throw
VideoFrameProcessingException
.
from
(
e
);
}
currentTextureInfo
=
new
TextureInfo
(
currentTexId
,
/* fboId= */
C
.
INDEX_UNSET
,
bitmap
.
getWidth
(),
bitmap
.
getHeight
());
}
framesToQueueForCurrentBitmap
--;
downstreamShaderProgramCapacity
--;
shaderProgram
.
queueInputFrame
(
c
urrentBitmap
.
textureInfo
,
currentPresentationTimeUs
);
shaderProgram
.
queueInputFrame
(
c
heckNotNull
(
currentTextureInfo
)
,
currentPresentationTimeUs
);
currentPresentationTimeUs
+=
currentBitmap
.
frameDurationUs
;
currentPresentationTimeUs
+=
currentBitmap
Info
.
frameDurationUs
;
if
(
framesToQueueForCurrentBitmap
==
0
)
{
pendingBitmaps
.
remove
();
maybeSignalEndOfOutput
();
...
...
@@ -164,13 +169,12 @@ import java.util.concurrent.LinkedBlockingQueue;
/** Information to generate all the frames associated with a specific {@link Bitmap}. */
private
static
final
class
BitmapFrameSequenceInfo
{
public
final
TextureInfo
textureInfo
;
public
final
Bitmap
bitmap
;
public
final
long
frameDurationUs
;
public
final
int
numberOfFrames
;
public
BitmapFrameSequenceInfo
(
TextureInfo
textureInfo
,
long
frameDurationUs
,
int
numberOfFrames
)
{
this
.
textureInfo
=
textureInfo
;
public
BitmapFrameSequenceInfo
(
Bitmap
bitmap
,
long
frameDurationUs
,
int
numberOfFrames
)
{
this
.
bitmap
=
bitmap
;
this
.
frameDurationUs
=
frameDurationUs
;
this
.
numberOfFrames
=
numberOfFrames
;
}
...
...
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