From 475912a39c9caedda545972d405f88494ce12aa8 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sun, 11 Nov 2018 00:35:53 +0100 Subject: [PATCH] Do not transmit MediaCodec flags Since PTS handling has been fixed, the recorder do not associate a PTS to a wrong frame anymore, so PTS of "configuration packets" (which never produce a frame), are never read by the recorder. Therefore, there is no need to ignore them explicitly, so we can remove the MediaCodec flags completely. --- app/src/decoder.c | 27 +++++++------------ app/src/decoder.h | 1 - .../com/genymobile/scrcpy/ScreenEncoder.java | 3 +-- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/app/src/decoder.c b/app/src/decoder.c index 83583cc3..d03ec3e6 100644 --- a/app/src/decoder.c +++ b/app/src/decoder.c @@ -15,7 +15,6 @@ #include "recorder.h" #define BUFSIZE 0x10000 -#define MEDIA_CODEC_FLAG_CONFIG 2 // MediaCodec.BUFFER_FLAG_CODEC_CONFIG static inline uint64_t from_be(uint8_t *b, int size) { @@ -30,7 +29,7 @@ static inline uint64_t from_be(uint8_t *b, int size) return x; } -#define HEADER_SIZE 16 +#define HEADER_SIZE 12 static int read_packet(void *opaque, uint8_t *buf, int buf_size) { struct decoder *decoder = opaque; @@ -50,8 +49,7 @@ static int read_packet(void *opaque, uint8_t *buf, int buf_size) { // read the PTS for the next frame decoder->next_pts = from_be(header, 8); - decoder->buffer_info_flags = from_be(header + 8, 4); - remaining = from_be(header + 12, 4); + remaining = from_be(header + 8, 4); } if (buf_size > remaining) @@ -181,20 +179,15 @@ static int run_decoder(void *data) { #endif if (decoder->recorder) { - // do not record configuration packets - // (they contain no media data and have no PTS/DTS) - // FIXME do not use MediaCodec specific flags - if (!(decoder->buffer_info_flags & MEDIA_CODEC_FLAG_CONFIG)) { - packet.pts = decoder->pts; - packet.dts = decoder->pts; + packet.pts = decoder->pts; + packet.dts = decoder->pts; - // no need to rescale with av_packet_rescale_ts(), the timestamps - // are in microseconds both in input and output - if (!recorder_write(decoder->recorder, &packet)) { - LOGE("Could not write frame to output file"); - av_packet_unref(&packet); - goto run_quit; - } + // no need to rescale with av_packet_rescale_ts(), the timestamps + // are in microseconds both in input and output + if (!recorder_write(decoder->recorder, &packet)) { + LOGE("Could not write frame to output file"); + av_packet_unref(&packet); + goto run_quit; } } diff --git a/app/src/decoder.h b/app/src/decoder.h index b502b625..235afba0 100644 --- a/app/src/decoder.h +++ b/app/src/decoder.h @@ -17,7 +17,6 @@ struct decoder { struct recorder *recorder; uint64_t next_pts; uint64_t pts; - uint32_t buffer_info_flags; int remaining; }; diff --git a/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java b/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java index 325febbb..a76ce7a9 100644 --- a/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java +++ b/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java @@ -82,7 +82,7 @@ public class ScreenEncoder implements Device.RotationListener { private boolean encode(MediaCodec codec, FileDescriptor fd) throws IOException { boolean eof = false; MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo(); - ByteBuffer bBuffer = ByteBuffer.allocate(16); + ByteBuffer bBuffer = ByteBuffer.allocate(12); while (!consumeRotationChange() && !eof) { int outputBufferId = codec.dequeueOutputBuffer(bufferInfo, -1); @@ -107,7 +107,6 @@ public class ScreenEncoder implements Device.RotationListener { } bBuffer.putLong(pts); - bBuffer.putInt(bufferInfo.flags); bBuffer.putInt(codecBuffer.remaining()); bBuffer.flip(); IO.writeFully(fd, bBuffer);