1package com.genymobile.scrcpy;
2
3import android.media.MediaCodec;
4
5import java.io.FileDescriptor;
6import java.io.IOException;
7import java.nio.ByteBuffer;
8import java.util.Arrays;
9
10public final class Streamer {
11
12 private static final long PACKET_FLAG_CONFIG = 1L << 63;
13 private static final long PACKET_FLAG_KEY_FRAME = 1L << 62;
14
15 private final FileDescriptor fd;
16 private final Codec codec;
17 private final boolean sendCodecMeta;
18 private final boolean sendFrameMeta;
19
20 private final ByteBuffer headerBuffer = ByteBuffer.allocate(12);
…lines 21–114 unchanged (94 lines)
115 //
116 // <https://developer.android.com/reference/android/media/MediaCodec#CSD>
117
118 if (buffer.remaining() < 16) {
119 throw new IOException("Not enough data in OPUS config packet");
120 }
121
122 final byte[] opusHeaderId = {'A', 'O', 'P', 'U', 'S', 'H', 'D', 'R'};
123 byte[] idBuffer = new byte[8];
124 buffer.get(idBuffer);
125 if (!Arrays.equals(idBuffer, opusHeaderId)) {
126 throw new IOException("OPUS header not found");
127 }
128
129 // The size is in native byte-order
130 long sizeLong = buffer.getLong();
131 if (sizeLong < 0 || sizeLong >= 0x7FFFFFFF) {
132 throw new IOException("Invalid block size in OPUS header: " + sizeLong);
133 }
134
135 int size = (int) sizeLong;
…lines 136–144 unchanged (9 lines)