From 22ff03f2f793dafe6ff86f4c101f8f1d1555a551 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sun, 11 Nov 2018 15:38:06 +0100 Subject: [PATCH] Do not queue invalid PTS Configuration packets produced by MediaCodec have no valid PTS, and do not produce frame. Do not queue their (invalid) PTS not to break the matching between frames and their PTS. --- app/src/decoder.c | 3 ++- server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/decoder.c b/app/src/decoder.c index bc164210..7e1e041d 100644 --- a/app/src/decoder.c +++ b/app/src/decoder.c @@ -19,6 +19,7 @@ #define BUFSIZE 0x10000 #define HEADER_SIZE 12 +#define NO_PTS UINT64_C(-1) static struct frame_meta *frame_meta_new(uint64_t pts) { struct frame_meta *meta = malloc(sizeof(*meta)); @@ -89,7 +90,7 @@ static int read_packet_with_meta(void *opaque, uint8_t *buf, int buf_size) { uint64_t pts = buffer_read64be(header); state->remaining = buffer_read32be(&header[8]); - if (!receiver_state_push_meta(state, pts)) { + if (pts != NO_PTS && !receiver_state_push_meta(state, pts)) { LOGE("Could not store PTS for recording"); // we cannot save the PTS, the recording would be broken return -1; diff --git a/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java b/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java index be4a42eb..0419dc52 100644 --- a/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java +++ b/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java @@ -23,6 +23,7 @@ public class ScreenEncoder implements Device.RotationListener { private static final int REPEAT_FRAME_DELAY = 6; // repeat after 6 frames private static final int MICROSECONDS_IN_ONE_SECOND = 1_000_000; + private static final int NO_PTS = -1; private final AtomicBoolean rotationChanged = new AtomicBoolean(); private final ByteBuffer headerBuffer = ByteBuffer.allocate(12); @@ -119,7 +120,7 @@ public class ScreenEncoder implements Device.RotationListener { long pts; if ((bufferInfo.flags & MediaCodec.BUFFER_FLAG_CODEC_CONFIG) != 0) { - pts = 0; // non-media data packet + pts = NO_PTS; // non-media data packet } else { if (ptsOrigin == 0) { ptsOrigin = bufferInfo.presentationTimeUs;