mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-04-22 04:25:01 +00:00
Use VideoStreamer directly from ScreenEncoder
The Callbacks interface notifies new packets. In addition, the screen
encoder will need to write headers on start from its own thread (which
will be added later).
We could add a function onStart() instead, but for simplicity, just
remove the interface, which brings no value, and call the streamer
directly.
Refs 87972e2022
This commit is contained in:
parent
8cdae30b01
commit
842fdccaa9
2 changed files with 6 additions and 11 deletions
|
@ -21,10 +21,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||
|
||||
public class ScreenEncoder implements Device.RotationListener {
|
||||
|
||||
public interface Callbacks {
|
||||
void onPacket(ByteBuffer codecBuffer, MediaCodec.BufferInfo bufferInfo) throws IOException;
|
||||
}
|
||||
|
||||
private static final int DEFAULT_I_FRAME_INTERVAL = 10; // seconds
|
||||
private static final int REPEAT_FRAME_DELAY_US = 100_000; // repeat after 100ms
|
||||
private static final String KEY_MAX_FPS_TO_ENCODER = "max-fps-to-encoder";
|
||||
|
@ -63,7 +59,7 @@ public class ScreenEncoder implements Device.RotationListener {
|
|||
return rotationChanged.getAndSet(false);
|
||||
}
|
||||
|
||||
public void streamScreen(Device device, Callbacks callbacks) throws IOException {
|
||||
public void streamScreen(Device device, VideoStreamer streamer) throws IOException {
|
||||
MediaCodec codec = createCodec(videoMimeType, encoderName);
|
||||
MediaFormat format = createFormat(videoMimeType, bitRate, maxFps, codecOptions);
|
||||
IBinder display = createDisplay();
|
||||
|
@ -92,7 +88,7 @@ public class ScreenEncoder implements Device.RotationListener {
|
|||
|
||||
codec.start();
|
||||
|
||||
alive = encode(codec, callbacks);
|
||||
alive = encode(codec, streamer);
|
||||
// do not call stop() on exception, it would trigger an IllegalStateException
|
||||
codec.stop();
|
||||
} catch (IllegalStateException | IllegalArgumentException e) {
|
||||
|
@ -161,7 +157,7 @@ public class ScreenEncoder implements Device.RotationListener {
|
|||
return 0;
|
||||
}
|
||||
|
||||
private boolean encode(MediaCodec codec, Callbacks callbacks) throws IOException {
|
||||
private boolean encode(MediaCodec codec, VideoStreamer streamer) throws IOException {
|
||||
boolean eof = false;
|
||||
MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
|
||||
|
||||
|
@ -184,7 +180,7 @@ public class ScreenEncoder implements Device.RotationListener {
|
|||
consecutiveErrors = 0;
|
||||
}
|
||||
|
||||
callbacks.onPacket(codecBuffer, bufferInfo);
|
||||
streamer.writePacket(codecBuffer, bufferInfo);
|
||||
}
|
||||
} finally {
|
||||
if (outputBufferId >= 0) {
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.io.FileDescriptor;
|
|||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public final class VideoStreamer implements ScreenEncoder.Callbacks {
|
||||
public final class VideoStreamer {
|
||||
|
||||
private static final long PACKET_FLAG_CONFIG = 1L << 63;
|
||||
private static final long PACKET_FLAG_KEY_FRAME = 1L << 62;
|
||||
|
@ -28,8 +28,7 @@ public final class VideoStreamer implements ScreenEncoder.Callbacks {
|
|||
IO.writeFully(fd, buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacket(ByteBuffer codecBuffer, MediaCodec.BufferInfo bufferInfo) throws IOException {
|
||||
public void writePacket(ByteBuffer codecBuffer, MediaCodec.BufferInfo bufferInfo) throws IOException {
|
||||
if (sendFrameMeta) {
|
||||
writeFrameMeta(fd, bufferInfo, codecBuffer.remaining());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue