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
dd86103b
authored
Apr 13, 2023
by
tofunmi
Committed by
Rohit Singh
Apr 17, 2023
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add FrameDropping GlEffect
PiperOrigin-RevId: 524030672
parent
85ec03c5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
147 additions
and
2 deletions
library/effect/src/main/java/com/google/android/exoplayer2/effect/BaseGlShaderProgram.java
library/effect/src/main/java/com/google/android/exoplayer2/effect/FrameCacheGlShaderProgram.java
library/effect/src/main/java/com/google/android/exoplayer2/effect/FrameDropEffect.java
library/effect/src/main/java/com/google/android/exoplayer2/effect/FrameDroppingShaderProgram.java
library/effect/src/main/java/com/google/android/exoplayer2/effect/BaseGlShaderProgram.java
View file @
dd86103b
...
...
@@ -51,7 +51,7 @@ public abstract class BaseGlShaderProgram implements GlShaderProgram {
private
final
boolean
useHdr
;
private
GlObjectsProvider
glObjectsProvider
;
pr
ivate
InputListener
inputListener
;
pr
otected
InputListener
inputListener
;
private
OutputListener
outputListener
;
private
ErrorListener
errorListener
;
private
Executor
errorListenerExecutor
;
...
...
library/effect/src/main/java/com/google/android/exoplayer2/effect/FrameCacheGlShaderProgram.java
View file @
dd86103b
...
...
@@ -29,7 +29,7 @@ import java.io.IOException;
*
* <p>Implements {@link FrameCache}.
*/
/* package */
final
class
FrameCacheGlShaderProgram
extends
BaseGlShaderProgram
{
/* package */
class
FrameCacheGlShaderProgram
extends
BaseGlShaderProgram
{
private
static
final
String
VERTEX_SHADER_TRANSFORMATION_ES2_PATH
=
"shaders/vertex_shader_transformation_es2.glsl"
;
private
static
final
String
FRAGMENT_SHADER_TRANSFORMATION_ES2_PATH
=
...
...
library/effect/src/main/java/com/google/android/exoplayer2/effect/FrameDropEffect.java
0 → 100644
View file @
dd86103b
/*
* Copyright 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
google
.
android
.
exoplayer2
.
effect
;
import
android.content.Context
;
import
com.google.android.exoplayer2.util.VideoFrameProcessingException
;
/** Drops frames to lower average frame rate to around {@code targetFrameRate}. */
public
class
FrameDropEffect
implements
GlEffect
{
private
final
float
targetFrameRate
;
/**
* Creates an instance.
*
* @param targetFrameRate The number of frames per second the output video should roughly have.
*/
public
FrameDropEffect
(
float
targetFrameRate
)
{
this
.
targetFrameRate
=
targetFrameRate
;
}
@Override
public
GlShaderProgram
toGlShaderProgram
(
Context
context
,
boolean
useHdr
)
throws
VideoFrameProcessingException
{
return
new
FrameDroppingShaderProgram
(
context
,
useHdr
,
targetFrameRate
);
}
}
library/effect/src/main/java/com/google/android/exoplayer2/effect/FrameDroppingShaderProgram.java
0 → 100644
View file @
dd86103b
/*
* Copyright 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
google
.
android
.
exoplayer2
.
effect
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Assertions
.
checkNotNull
;
import
static
java
.
lang
.
Math
.
abs
;
import
android.content.Context
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.util.GlTextureInfo
;
import
com.google.android.exoplayer2.util.VideoFrameProcessingException
;
// TODO(b/227625363): Add tests for this file.
/**
* Drops frames by only queuing input frames that are chosen by the frame dropping strategy.
*
* <p>The strategy used is to queue the current frame, x, with timestamp T_x if and only if one of
* the following is true:
*
* <ul>
* <li>x is the first frame,
* <li>(T_x - T_lastQueued) is closer to the target frame interval than (T_(x+1) - T_lastQueued)
* </ul>
*
* <p>Where T_lastQueued is the timestamp of the last queued frame and T_(x+1) is the timestamp of
* the next frame. The target frame interval is determined from {@code targetFps}.
*/
/* package */
final
class
FrameDroppingShaderProgram
extends
FrameCacheGlShaderProgram
{
private
final
long
targetFrameDeltaUs
;
@Nullable
private
GlTextureInfo
previousTexture
;
private
long
previousPresentationTimeUs
;
private
long
lastQueuedPresentationTimeUs
;
private
boolean
isPreviousFrameFirstFrame
;
/**
* Creates a new instance.
*
* @param context The {@link Context}.
* @param useHdr Whether input textures come from an HDR source. If {@code true}, colors will be
* in linear RGB BT.2020. If {@code false}, colors will be in linear RGB BT.709.
* @param targetFps The number of frames per second the output video should roughly have.
*/
public
FrameDroppingShaderProgram
(
Context
context
,
boolean
useHdr
,
float
targetFps
)
throws
VideoFrameProcessingException
{
super
(
context
,
/* capacity= */
1
,
useHdr
);
this
.
targetFrameDeltaUs
=
(
long
)
(
C
.
MICROS_PER_SECOND
/
targetFps
);
lastQueuedPresentationTimeUs
=
C
.
TIME_UNSET
;
previousPresentationTimeUs
=
C
.
TIME_UNSET
;
}
@Override
public
void
queueInputFrame
(
GlTextureInfo
inputTexture
,
long
presentationTimeUs
)
{
if
(
previousTexture
==
null
)
{
super
.
queueInputFrame
(
inputTexture
,
presentationTimeUs
);
lastQueuedPresentationTimeUs
=
presentationTimeUs
;
isPreviousFrameFirstFrame
=
true
;
}
else
if
(
shouldQueuePreviousFrame
(
presentationTimeUs
))
{
super
.
queueInputFrame
(
checkNotNull
(
previousTexture
),
previousPresentationTimeUs
);
lastQueuedPresentationTimeUs
=
previousPresentationTimeUs
;
}
else
{
inputListener
.
onInputFrameProcessed
(
checkNotNull
(
previousTexture
));
inputListener
.
onReadyToAcceptInputFrame
();
}
previousTexture
=
inputTexture
;
previousPresentationTimeUs
=
presentationTimeUs
;
}
@Override
public
void
flush
()
{
super
.
flush
();
lastQueuedPresentationTimeUs
=
C
.
TIME_UNSET
;
previousPresentationTimeUs
=
C
.
TIME_UNSET
;
previousTexture
=
null
;
}
private
boolean
shouldQueuePreviousFrame
(
long
currentPresentationTimeUs
)
{
if
(
isPreviousFrameFirstFrame
)
{
isPreviousFrameFirstFrame
=
false
;
return
false
;
}
long
previousFrameTimeDeltaUs
=
previousPresentationTimeUs
-
lastQueuedPresentationTimeUs
;
long
currentFrameTimeDeltaUs
=
currentPresentationTimeUs
-
lastQueuedPresentationTimeUs
;
return
abs
(
previousFrameTimeDeltaUs
-
targetFrameDeltaUs
)
<
abs
(
currentFrameTimeDeltaUs
-
targetFrameDeltaUs
);
}
}
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