mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-04-22 04:25:01 +00:00
Write streamer header from ScreenEncoder
The screen encoder is responsible to write data to the video streamer from its own thread (which will be added later).
This commit is contained in:
parent
842fdccaa9
commit
e37f9a4d7c
3 changed files with 16 additions and 10 deletions
|
@ -64,6 +64,9 @@ public class ScreenEncoder implements Device.RotationListener {
|
|||
MediaFormat format = createFormat(videoMimeType, bitRate, maxFps, codecOptions);
|
||||
IBinder display = createDisplay();
|
||||
device.setRotationListener(this);
|
||||
|
||||
streamer.writeHeader();
|
||||
|
||||
boolean alive;
|
||||
try {
|
||||
do {
|
||||
|
|
|
@ -104,10 +104,7 @@ public final class Server {
|
|||
|
||||
try {
|
||||
// synchronous
|
||||
VideoStreamer videoStreamer = new VideoStreamer(connection.getVideoFd(), options.getSendFrameMeta());
|
||||
if (options.getSendCodecId()) {
|
||||
videoStreamer.writeHeader(codec.getId());
|
||||
}
|
||||
VideoStreamer videoStreamer = new VideoStreamer(connection.getVideoFd(), codec, options.getSendCodecId(), options.getSendFrameMeta());
|
||||
screenEncoder.streamScreen(device, videoStreamer);
|
||||
} catch (IOException e) {
|
||||
// this is expected on close
|
||||
|
|
|
@ -12,20 +12,26 @@ public final class VideoStreamer {
|
|||
private static final long PACKET_FLAG_KEY_FRAME = 1L << 62;
|
||||
|
||||
private final FileDescriptor fd;
|
||||
private final VideoCodec codec;
|
||||
private final boolean sendCodecId;
|
||||
private final boolean sendFrameMeta;
|
||||
|
||||
private final ByteBuffer headerBuffer = ByteBuffer.allocate(12);
|
||||
|
||||
public VideoStreamer(FileDescriptor fd, boolean sendFrameMeta) {
|
||||
public VideoStreamer(FileDescriptor fd, VideoCodec codec, boolean sendCodecId, boolean sendFrameMeta) {
|
||||
this.fd = fd;
|
||||
this.codec = codec;
|
||||
this.sendCodecId = sendCodecId;
|
||||
this.sendFrameMeta = sendFrameMeta;
|
||||
}
|
||||
|
||||
public void writeHeader(int codecId) throws IOException {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(4);
|
||||
buffer.putInt(codecId);
|
||||
buffer.flip();
|
||||
IO.writeFully(fd, buffer);
|
||||
public void writeHeader() throws IOException {
|
||||
if (sendCodecId) {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(4);
|
||||
buffer.putInt(codec.getId());
|
||||
buffer.flip();
|
||||
IO.writeFully(fd, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
public void writePacket(ByteBuffer codecBuffer, MediaCodec.BufferInfo bufferInfo) throws IOException {
|
||||
|
|
Loading…
Add table
Reference in a new issue