Skip to content

Commit

Permalink
Add support for displaying the rendered frame times
Browse files Browse the repository at this point in the history
  • Loading branch information
cgutman committed Nov 18, 2016
1 parent 6c3aaed commit 3d177e9
Showing 1 changed file with 22 additions and 2 deletions.
Expand Up @@ -25,6 +25,8 @@

public class MediaCodecDecoderRenderer extends EnhancedDecoderRenderer {

private static final boolean USE_FRAME_RENDER_TIME = false;

// Used on versions < 5.0
private ByteBuffer[] legacyInputBuffers;

Expand Down Expand Up @@ -213,6 +215,20 @@ else if (videoFormat == VideoFormat.H265) {
videoDecoder.configure(videoFormat, ((SurfaceHolder)renderTarget).getSurface(), null, 0);
videoDecoder.setVideoScalingMode(MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT);

if (USE_FRAME_RENDER_TIME && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
videoDecoder.setOnFrameRenderedListener(new MediaCodec.OnFrameRenderedListener() {
@Override
public void onFrameRendered(MediaCodec mediaCodec, long presentationTimeUs, long renderTimeNanos) {
long delta = (renderTimeNanos / 1000000L) - (presentationTimeUs / 1000);
if (delta >= 0 && delta < 1000) {
if (USE_FRAME_RENDER_TIME) {
totalTimeMs += delta;
}
}
}
}, null);
}

LimeLog.info("Using codec "+selectedDecoderName+" for hardware decoding "+mimeType);

return true;
Expand Down Expand Up @@ -273,7 +289,9 @@ public void run() {
long delta = MediaCodecHelper.getMonotonicMillis() - (presentationTimeUs / 1000);
if (delta >= 0 && delta < 1000) {
decoderTimeMs += delta;
totalTimeMs += delta;
if (!USE_FRAME_RENDER_TIME) {
totalTimeMs += delta;
}
}
} else {
switch (outIndex) {
Expand Down Expand Up @@ -421,7 +439,9 @@ public void run() {
long delta = MediaCodecHelper.getMonotonicMillis()-(presentationTimeUs/1000);
if (delta >= 0 && delta < 1000) {
decoderTimeMs += delta;
totalTimeMs += delta;
if (!USE_FRAME_RENDER_TIME) {
totalTimeMs += delta;
}
}
} else {
switch (outIndex) {
Expand Down

0 comments on commit 3d177e9

Please sign in to comment.