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
0370e053
authored
Apr 01, 2022
by
hschlueter
Committed by
Ian Baker
Apr 07, 2022
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add FrameProcessorChain factory method and make constructor private.
PiperOrigin-RevId: 438804850
parent
63c42b79
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
58 deletions
library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/FrameProcessorChainPixelTest.java
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/FrameProcessorChain.java
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/VideoTranscodingSamplePipeline.java
library/transformer/src/test/java/com/google/android/exoplayer2/transformer/FrameProcessorChainTest.java
library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/FrameProcessorChainPixelTest.java
View file @
0370e053
...
...
@@ -246,7 +246,7 @@ public final class FrameProcessorChainPixelTest {
int
inputWidth
=
checkNotNull
(
mediaFormat
).
getInteger
(
MediaFormat
.
KEY_WIDTH
);
int
inputHeight
=
mediaFormat
.
getInteger
(
MediaFormat
.
KEY_HEIGHT
);
frameProcessorChain
=
new
FrameProcessorChain
(
FrameProcessorChain
.
create
(
context
,
PIXEL_WIDTH_HEIGHT_RATIO
,
inputWidth
,
...
...
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/FrameProcessorChain.java
View file @
0370e053
...
...
@@ -63,6 +63,49 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
GlUtil
.
glAssertionsEnabled
=
true
;
}
/**
* Creates a new instance.
*
* @param context A {@link Context}.
* @param pixelWidthHeightRatio The ratio of width over height, for each pixel.
* @param inputWidth The input frame width, in pixels.
* @param inputHeight The input frame height, in pixels.
* @param frameProcessors The {@link GlFrameProcessor GlFrameProcessors} to apply to each frame.
* @param enableExperimentalHdrEditing Whether to attempt to process the input as an HDR signal.
* @return A new instance.
* @throws TransformationException If the {@code pixelWidthHeightRatio} isn't 1.
*/
public
static
FrameProcessorChain
create
(
Context
context
,
float
pixelWidthHeightRatio
,
int
inputWidth
,
int
inputHeight
,
List
<
GlFrameProcessor
>
frameProcessors
,
boolean
enableExperimentalHdrEditing
)
throws
TransformationException
{
if
(
pixelWidthHeightRatio
!=
1.0f
)
{
// TODO(b/211782176): Consider implementing support for non-square pixels.
throw
TransformationException
.
createForFrameProcessorChain
(
new
UnsupportedOperationException
(
"Transformer's FrameProcessorChain currently does not support frame edits on"
+
" non-square pixels. The pixelWidthHeightRatio is: "
+
pixelWidthHeightRatio
),
TransformationException
.
ERROR_CODE_GL_INIT_FAILED
);
}
ExternalCopyFrameProcessor
externalCopyFrameProcessor
=
new
ExternalCopyFrameProcessor
(
context
,
enableExperimentalHdrEditing
);
externalCopyFrameProcessor
.
setInputSize
(
inputWidth
,
inputHeight
);
Size
inputSize
=
externalCopyFrameProcessor
.
getOutputSize
();
for
(
int
i
=
0
;
i
<
frameProcessors
.
size
();
i
++)
{
frameProcessors
.
get
(
i
).
setInputSize
(
inputSize
.
getWidth
(),
inputSize
.
getHeight
());
inputSize
=
frameProcessors
.
get
(
i
).
getOutputSize
();
}
return
new
FrameProcessorChain
(
externalCopyFrameProcessor
,
frameProcessors
,
enableExperimentalHdrEditing
);
}
private
static
final
String
THREAD_NAME
=
"Transformer:FrameProcessorChain"
;
private
final
boolean
enableExperimentalHdrEditing
;
...
...
@@ -78,7 +121,6 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
private
volatile
boolean
releaseRequested
;
private
boolean
inputStreamEnded
;
private
final
Size
inputSize
;
/** Wraps the {@link #inputSurfaceTexture}. */
private
@MonotonicNonNull
Surface
inputSurface
;
/** Associated with an OpenGL external texture. */
...
...
@@ -116,48 +158,23 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
*/
private
@MonotonicNonNull
EGLSurface
debugPreviewEglSurface
;
/**
* Creates a new instance.
*
* @param context A {@link Context}.
* @param pixelWidthHeightRatio The ratio of width over height, for each pixel.
* @param inputWidth The input frame width, in pixels.
* @param inputHeight The input frame height, in pixels.
* @param frameProcessors The {@link GlFrameProcessor GlFrameProcessors} to apply to each frame.
* @param enableExperimentalHdrEditing Whether to attempt to process the input as an HDR signal.
* @throws TransformationException If the {@code pixelWidthHeightRatio} isn't 1.
*/
public
FrameProcessorChain
(
Context
context
,
float
pixelWidthHeightRatio
,
int
inputWidth
,
int
inputHeight
,
private
FrameProcessorChain
(
ExternalCopyFrameProcessor
externalCopyFrameProcessor
,
List
<
GlFrameProcessor
>
frameProcessors
,
boolean
enableExperimentalHdrEditing
)
throws
TransformationException
{
if
(
pixelWidthHeightRatio
!=
1.0f
)
{
// TODO(b/211782176): Consider implementing support for non-square pixels.
throw
TransformationException
.
createForFrameProcessorChain
(
new
UnsupportedOperationException
(
"Transformer's FrameProcessorChain currently does not support frame edits on"
+
" non-square pixels. The pixelWidthHeightRatio is: "
+
pixelWidthHeightRatio
),
TransformationException
.
ERROR_CODE_GL_INIT_FAILED
);
}
this
.
enableExperimentalHdrEditing
=
enableExperimentalHdrEditing
;
boolean
enableExperimentalHdrEditing
)
{
this
.
externalCopyFrameProcessor
=
externalCopyFrameProcessor
;
this
.
frameProcessors
=
ImmutableList
.
copyOf
(
frameProcessors
);
this
.
enableExperimentalHdrEditing
=
enableExperimentalHdrEditing
;
singleThreadExecutorService
=
Util
.
newSingleThreadExecutor
(
THREAD_NAME
);
futures
=
new
ConcurrentLinkedQueue
<>();
pendingFrameCount
=
new
AtomicInteger
();
inputSize
=
new
Size
(
inputWidth
,
inputHeight
);
textureTransformMatrix
=
new
float
[
16
];
externalCopyFrameProcessor
=
new
ExternalCopyFrameProcessor
(
context
,
enableExperimentalHdrEditing
);
framebuffers
=
new
int
[
frameProcessors
.
size
()];
configureFrameProcessorSizes
(
inputSize
,
frameProcessors
);
outputSize
=
frameProcessors
.
isEmpty
()
?
inputSize
:
getLast
(
frameProcessors
).
getOutputSize
();
outputSize
=
frameProcessors
.
isEmpty
()
?
externalCopyFrameProcessor
.
getOutputSize
()
:
getLast
(
frameProcessors
).
getOutputSize
();
debugPreviewWidth
=
C
.
LENGTH_UNSET
;
debugPreviewHeight
=
C
.
LENGTH_UNSET
;
}
...
...
@@ -380,10 +397,9 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
}
inputExternalTexId
=
GlUtil
.
createExternalTexture
();
externalCopyFrameProcessor
.
setInputSize
(
inputSize
.
getWidth
(),
inputSize
.
getHeight
());
externalCopyFrameProcessor
.
initialize
(
inputExternalTexId
);
Size
intermediateSize
=
inputSize
;
Size
intermediateSize
=
externalCopyFrameProcessor
.
getOutputSize
()
;
for
(
int
i
=
0
;
i
<
frameProcessors
.
size
();
i
++)
{
int
inputTexId
=
GlUtil
.
createTexture
(
intermediateSize
.
getWidth
(),
intermediateSize
.
getHeight
());
...
...
@@ -411,13 +427,14 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
GlUtil
.
focusEglSurface
(
eglDisplay
,
eglContext
,
eglSurface
,
outputSize
.
getWidth
(),
outputSize
.
getHeight
());
}
else
{
Size
intermediateSize
=
externalCopyFrameProcessor
.
getOutputSize
();
GlUtil
.
focusFramebuffer
(
eglDisplay
,
eglContext
,
eglSurface
,
framebuffers
[
0
],
in
put
Size
.
getWidth
(),
in
put
Size
.
getHeight
());
in
termediate
Size
.
getWidth
(),
in
termediate
Size
.
getHeight
());
}
inputSurfaceTexture
.
updateTexImage
();
inputSurfaceTexture
.
getTransformMatrix
(
textureTransformMatrix
);
...
...
@@ -466,16 +483,4 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
GLES20
.
glClear
(
GLES20
.
GL_COLOR_BUFFER_BIT
);
GlUtil
.
checkGlError
();
}
/**
* Configures the input and output {@linkplain Size sizes} of a list of {@link GlFrameProcessor
* GlFrameProcessors}.
*/
private
static
void
configureFrameProcessorSizes
(
Size
inputSize
,
List
<
GlFrameProcessor
>
frameProcessors
)
{
for
(
int
i
=
0
;
i
<
frameProcessors
.
size
();
i
++)
{
frameProcessors
.
get
(
i
).
setInputSize
(
inputSize
.
getWidth
(),
inputSize
.
getHeight
());
inputSize
=
frameProcessors
.
get
(
i
).
getOutputSize
();
}
}
}
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/VideoTranscodingSamplePipeline.java
View file @
0370e053
...
...
@@ -81,7 +81,7 @@ import org.checkerframework.dataflow.qual.Pure;
.
setResolution
(
transformationRequest
.
outputHeight
)
.
build
();
frameProcessorChain
=
new
FrameProcessorChain
(
FrameProcessorChain
.
create
(
context
,
inputFormat
.
pixelWidthHeightRatio
,
/* inputWidth= */
decodedWidth
,
...
...
library/transformer/src/test/java/com/google/android/exoplayer2/transformer/FrameProcessorChainTest.java
View file @
0370e053
...
...
@@ -37,11 +37,11 @@ import org.junit.runner.RunWith;
public
final
class
FrameProcessorChainTest
{
@Test
public
void
c
onstruct
_withSupportedPixelWidthHeightRatio_completesSuccessfully
()
public
void
c
reate
_withSupportedPixelWidthHeightRatio_completesSuccessfully
()
throws
TransformationException
{
Context
context
=
getApplicationContext
();
new
FrameProcessorChain
(
FrameProcessorChain
.
create
(
context
,
/* pixelWidthHeightRatio= */
1
,
/* inputWidth= */
200
,
...
...
@@ -51,14 +51,14 @@ public final class FrameProcessorChainTest {
}
@Test
public
void
c
onstruct
_withUnsupportedPixelWidthHeightRatio_throwsException
()
{
public
void
c
reate
_withUnsupportedPixelWidthHeightRatio_throwsException
()
{
Context
context
=
getApplicationContext
();
TransformationException
exception
=
assertThrows
(
TransformationException
.
class
,
()
->
new
FrameProcessorChain
(
FrameProcessorChain
.
create
(
context
,
/* pixelWidthHeightRatio= */
2
,
/* inputWidth= */
200
,
...
...
@@ -121,7 +121,7 @@ public final class FrameProcessorChainTest {
for
(
Size
element
:
frameProcessorOutputSizes
)
{
frameProcessors
.
add
(
new
FakeFrameProcessor
(
element
));
}
return
new
FrameProcessorChain
(
return
FrameProcessorChain
.
create
(
getApplicationContext
(),
/* pixelWidthHeightRatio= */
1
,
inputSize
.
getWidth
(),
...
...
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