VideoFrameReleaseHelper
@UnstableApi
public final class VideoFrameReleaseHelper
A helper to release video frames to a Surface. This helper:
- Adjusts frame release timestamps to achieve a smoother visual result. The release timestamps are smoothed, and aligned with the default display's vsync signal.
- Adjusts the
Surfaceframe rate to inform the underlying platform of a fixed frame rate, when there is one.
Summary
Constants |
|
|---|---|
static final long |
The period between sampling display VSYNC timestamps, in milliseconds. |
Public constructors |
|---|
VideoFrameReleaseHelper(Context context)Constructs an instance. |
Public methods |
|
|---|---|
long |
adjustReleaseTime(Adjusts the release timestamp for the frame with the given presentation timestamp. |
void |
onPlaybackSpeed(float playbackSpeed)Called when the playback speed changes. |
void |
Called when the position is reset. |
void |
Called when rendering starts. |
void |
Called when rendering stops. |
void |
onSurfaceChanged(@Nullable Surface surface)Called when the |
void |
setChangeFrameRateStrategy(Changes the |
void |
setSurfaceMediaFrameRate(float surfaceMediaFrameRate)Sets the media frame rate used to calculate the playback frame rate of the surface. |
void |
@VisibleForTesting |
Constants
VSYNC_SAMPLE_UPDATE_PERIOD_MS
@VisibleForTesting
public static final long VSYNC_SAMPLE_UPDATE_PERIOD_MS = 500
The period between sampling display VSYNC timestamps, in milliseconds.
Public constructors
VideoFrameReleaseHelper
public VideoFrameReleaseHelper(Context context)
Constructs an instance.
| Parameters | |
|---|---|
Context context |
A context from which information about the default display can be retrieved. |
Public methods
adjustReleaseTime
public long adjustReleaseTime(
long releaseTimeNs,
long presentationTimeUs,
long frameDurationNs,
long frameIndex
)
Adjusts the release timestamp for the frame with the given presentation timestamp.
This method may be called any number of times for each frame, including zero times (for skipped frames, or when rendering the first frame prior to playback starting), or more than once (if the caller wishes to give the helper the opportunity to refine a release time closer to when the frame needs to be released).
| Parameters | |
|---|---|
long releaseTimeNs |
The frame's unadjusted release time, in nanoseconds and in the same time base as |
long presentationTimeUs |
The frame's presentation timestamp in microsecond. |
long frameDurationNs |
The estimated fixed frame duration in nanoseconds, or |
long frameIndex |
A monotonically increasing index for the frame, or |
| Returns | |
|---|---|
long |
The adjusted frame release timestamp, in nanoseconds and in the same time base as |
onPlaybackSpeed
public void onPlaybackSpeed(float playbackSpeed)
Called when the playback speed changes.
| Parameters | |
|---|---|
float playbackSpeed |
The factor by which playback is sped up. |
onSurfaceChanged
public void onSurfaceChanged(@Nullable Surface surface)
Called when the Surface on which to render changes.
setChangeFrameRateStrategy
public void setChangeFrameRateStrategy(
@C.VideoChangeFrameRateStrategy int changeFrameRateStrategy
)
Changes the C.VideoChangeFrameRateStrategy used when calling setFrameRate.
The default value is VIDEO_CHANGE_FRAME_RATE_STRATEGY_ONLY_IF_SEAMLESS.
setSurfaceMediaFrameRate
public void setSurfaceMediaFrameRate(float surfaceMediaFrameRate)
Sets the media frame rate used to calculate the playback frame rate of the surface.
| Parameters | |
|---|---|
float surfaceMediaFrameRate |
The media frame rate, or |
setVsyncData
@VisibleForTesting
public void setVsyncData(long vsyncSampleTimeNs, long vsyncDurationNs)