Write streamer header from ScreenEncoder
The screen encoder is responsible for writing data to the video streamer.
This commit is contained in:
parent
ae29e5b562
commit
51628201b7
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);
|
MediaFormat format = createFormat(videoMimeType, bitRate, maxFps, codecOptions);
|
||||||
IBinder display = createDisplay();
|
IBinder display = createDisplay();
|
||||||
device.setRotationListener(this);
|
device.setRotationListener(this);
|
||||||
|
|
||||||
|
streamer.writeHeader();
|
||||||
|
|
||||||
boolean alive;
|
boolean alive;
|
||||||
try {
|
try {
|
||||||
do {
|
do {
|
||||||
|
|
|
@ -104,10 +104,7 @@ public final class Server {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// synchronous
|
// synchronous
|
||||||
VideoStreamer videoStreamer = new VideoStreamer(connection.getVideoFd(), options.getSendFrameMeta());
|
VideoStreamer videoStreamer = new VideoStreamer(connection.getVideoFd(), codec, options.getSendCodecId(), options.getSendFrameMeta());
|
||||||
if (options.getSendCodecId()) {
|
|
||||||
videoStreamer.writeHeader(codec.getId());
|
|
||||||
}
|
|
||||||
screenEncoder.streamScreen(device, videoStreamer);
|
screenEncoder.streamScreen(device, videoStreamer);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// Broken pipe is expected on close, because the socket is closed by the client
|
// Broken pipe is expected on close, because the socket is closed by the client
|
||||||
|
|
|
@ -12,21 +12,27 @@ public final class VideoStreamer {
|
||||||
private static final long PACKET_FLAG_KEY_FRAME = 1L << 62;
|
private static final long PACKET_FLAG_KEY_FRAME = 1L << 62;
|
||||||
|
|
||||||
private final FileDescriptor fd;
|
private final FileDescriptor fd;
|
||||||
|
private final VideoCodec codec;
|
||||||
|
private final boolean sendCodecId;
|
||||||
private final boolean sendFrameMeta;
|
private final boolean sendFrameMeta;
|
||||||
|
|
||||||
private final ByteBuffer headerBuffer = ByteBuffer.allocate(12);
|
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.fd = fd;
|
||||||
|
this.codec = codec;
|
||||||
|
this.sendCodecId = sendCodecId;
|
||||||
this.sendFrameMeta = sendFrameMeta;
|
this.sendFrameMeta = sendFrameMeta;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeHeader(int codecId) throws IOException {
|
public void writeHeader() throws IOException {
|
||||||
|
if (sendCodecId) {
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(4);
|
ByteBuffer buffer = ByteBuffer.allocate(4);
|
||||||
buffer.putInt(codecId);
|
buffer.putInt(codec.getId());
|
||||||
buffer.flip();
|
buffer.flip();
|
||||||
IO.writeFully(fd, buffer);
|
IO.writeFully(fd, buffer);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void writePacket(ByteBuffer codecBuffer, MediaCodec.BufferInfo bufferInfo) throws IOException {
|
public void writePacket(ByteBuffer codecBuffer, MediaCodec.BufferInfo bufferInfo) throws IOException {
|
||||||
if (sendFrameMeta) {
|
if (sendFrameMeta) {
|
||||||
|
|
Loading…
Reference in a new issue