mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-08-04 15:19:11 +00:00
Client orientation option
This commit is contained in:
parent
40c912d8cb
commit
1d88200db3
15 changed files with 147 additions and 31 deletions
|
@ -286,6 +286,14 @@ The initial window position and size may be specified:
|
||||||
scrcpy --window-x 100 --window-y 100 --window-width 800 --window-height 600
|
scrcpy --window-x 100 --window-y 100 --window-width 800 --window-height 600
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Lock orientation
|
||||||
|
|
||||||
|
Keep the window in landscape orientation:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scrcpy --orientation 3
|
||||||
|
```
|
||||||
|
|
||||||
#### Borderless
|
#### Borderless
|
||||||
|
|
||||||
To disable window decorations:
|
To disable window decorations:
|
||||||
|
|
|
@ -106,6 +106,11 @@ conf.set('DEFAULT_LOCAL_PORT', '27183')
|
||||||
# overridden by option --max-size
|
# overridden by option --max-size
|
||||||
conf.set('DEFAULT_MAX_SIZE', '0') # 0: unlimited
|
conf.set('DEFAULT_MAX_SIZE', '0') # 0: unlimited
|
||||||
|
|
||||||
|
# the default client orientation
|
||||||
|
# natural device orientation is 0 and each increment adds 90 degrees
|
||||||
|
# overridden by option --orientation
|
||||||
|
conf.set('DEFAULT_ORIENTATION', '-1') # -1: unlocked
|
||||||
|
|
||||||
# the default video bitrate, in bits/second
|
# the default video bitrate, in bits/second
|
||||||
# overridden by option --bit-rate
|
# overridden by option --bit-rate
|
||||||
conf.set('DEFAULT_BIT_RATE', '8000000') # 8Mbps
|
conf.set('DEFAULT_BIT_RATE', '8000000') # 8Mbps
|
||||||
|
|
10
app/scrcpy.1
10
app/scrcpy.1
|
@ -29,7 +29,9 @@ Default is 8000000.
|
||||||
.BI "\-\-crop " width\fR:\fIheight\fR:\fIx\fR:\fIy
|
.BI "\-\-crop " width\fR:\fIheight\fR:\fIx\fR:\fIy
|
||||||
Crop the device screen on the server.
|
Crop the device screen on the server.
|
||||||
|
|
||||||
The values are expressed in the device natural orientation (typically, portrait for a phone, landscape for a tablet). Any
|
The values are expressed in the device natural clientOrientation (typically, portrait for a phone, landscape for a tablet) unless
|
||||||
|
.B \-\-orientation
|
||||||
|
is specified. Any
|
||||||
.B \-\-max\-size
|
.B \-\-max\-size
|
||||||
value is computed on the cropped size.
|
value is computed on the cropped size.
|
||||||
|
|
||||||
|
@ -51,6 +53,12 @@ Limit both the width and height of the video to \fIvalue\fR. The other dimension
|
||||||
|
|
||||||
Default is 0 (unlimited).
|
Default is 0 (unlimited).
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.BI "\-o, \-\-orientation " value
|
||||||
|
Lock client orientation to \fIvalue\fR. Values are integers in the range [0..3]. Natural device orientation is 0 and each increment adds 90 degrees.
|
||||||
|
|
||||||
|
Default is -1 (unlocked).
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B \-n, \-\-no\-control
|
.B \-n, \-\-no\-control
|
||||||
Disable device control (mirror the device in read\-only).
|
Disable device control (mirror the device in read\-only).
|
||||||
|
|
|
@ -51,6 +51,12 @@ scrcpy_print_usage(const char *arg0) {
|
||||||
" is preserved.\n"
|
" is preserved.\n"
|
||||||
" Default is %d%s.\n"
|
" Default is %d%s.\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
" -o, --orientation value\n"
|
||||||
|
" Lock client orientation to value. Values are integers in the\n"
|
||||||
|
" range [0..3]. Natural device orientation is 0 and each\n"
|
||||||
|
" increment adds 90 degrees.\n"
|
||||||
|
" Default is %d%s.\n"
|
||||||
|
"\n"
|
||||||
" -n, --no-control\n"
|
" -n, --no-control\n"
|
||||||
" Disable device control (mirror the device in read-only).\n"
|
" Disable device control (mirror the device in read-only).\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
@ -193,6 +199,7 @@ scrcpy_print_usage(const char *arg0) {
|
||||||
arg0,
|
arg0,
|
||||||
DEFAULT_BIT_RATE,
|
DEFAULT_BIT_RATE,
|
||||||
DEFAULT_MAX_SIZE, DEFAULT_MAX_SIZE ? "" : " (unlimited)",
|
DEFAULT_MAX_SIZE, DEFAULT_MAX_SIZE ? "" : " (unlimited)",
|
||||||
|
DEFAULT_ORIENTATION, DEFAULT_ORIENTATION >= 0 ? "" : " (unlocked)",
|
||||||
DEFAULT_LOCAL_PORT);
|
DEFAULT_LOCAL_PORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,6 +266,19 @@ parse_max_fps(const char *s, uint16_t *max_fps) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
parse_orientation(const char *s, int8_t *orientation) {
|
||||||
|
long value;
|
||||||
|
bool ok = parse_integer_arg(s, &value, false, -1, 3,
|
||||||
|
"orientation");
|
||||||
|
if (!ok) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
*orientation = (int8_t) value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
parse_window_position(const char *s, int16_t *position) {
|
parse_window_position(const char *s, int16_t *position) {
|
||||||
long value;
|
long value;
|
||||||
|
@ -351,6 +371,7 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
|
||||||
{"help", no_argument, NULL, 'h'},
|
{"help", no_argument, NULL, 'h'},
|
||||||
{"max-fps", required_argument, NULL, OPT_MAX_FPS},
|
{"max-fps", required_argument, NULL, OPT_MAX_FPS},
|
||||||
{"max-size", required_argument, NULL, 'm'},
|
{"max-size", required_argument, NULL, 'm'},
|
||||||
|
{"orientation", required_argument, NULL, 'o'},
|
||||||
{"no-control", no_argument, NULL, 'n'},
|
{"no-control", no_argument, NULL, 'n'},
|
||||||
{"no-display", no_argument, NULL, 'N'},
|
{"no-display", no_argument, NULL, 'N'},
|
||||||
{"port", required_argument, NULL, 'p'},
|
{"port", required_argument, NULL, 'p'},
|
||||||
|
@ -379,7 +400,7 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
|
||||||
optind = 0; // reset to start from the first argument in tests
|
optind = 0; // reset to start from the first argument in tests
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
while ((c = getopt_long(argc, argv, "b:c:fF:hm:nNp:r:s:StTv", long_options,
|
while ((c = getopt_long(argc, argv, "b:c:fF:hm:o:nNp:r:s:StTv", long_options,
|
||||||
NULL)) != -1) {
|
NULL)) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'b':
|
case 'b':
|
||||||
|
@ -417,6 +438,11 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'o':
|
||||||
|
if(!parse_orientation(optarg, &opts->orientation)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
opts->control = false;
|
opts->control = false;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -284,6 +284,7 @@ scrcpy(const struct scrcpy_options *options) {
|
||||||
.max_size = options->max_size,
|
.max_size = options->max_size,
|
||||||
.bit_rate = options->bit_rate,
|
.bit_rate = options->bit_rate,
|
||||||
.max_fps = options->max_fps,
|
.max_fps = options->max_fps,
|
||||||
|
.orientation = options->orientation,
|
||||||
.control = options->control,
|
.control = options->control,
|
||||||
};
|
};
|
||||||
if (!server_start(&server, options->serial, ¶ms)) {
|
if (!server_start(&server, options->serial, ¶ms)) {
|
||||||
|
|
|
@ -19,6 +19,7 @@ struct scrcpy_options {
|
||||||
uint16_t max_size;
|
uint16_t max_size;
|
||||||
uint32_t bit_rate;
|
uint32_t bit_rate;
|
||||||
uint16_t max_fps;
|
uint16_t max_fps;
|
||||||
|
int8_t orientation;
|
||||||
int16_t window_x;
|
int16_t window_x;
|
||||||
int16_t window_y;
|
int16_t window_y;
|
||||||
uint16_t window_width;
|
uint16_t window_width;
|
||||||
|
@ -45,6 +46,7 @@ struct scrcpy_options {
|
||||||
.max_size = DEFAULT_MAX_SIZE, \
|
.max_size = DEFAULT_MAX_SIZE, \
|
||||||
.bit_rate = DEFAULT_BIT_RATE, \
|
.bit_rate = DEFAULT_BIT_RATE, \
|
||||||
.max_fps = 0, \
|
.max_fps = 0, \
|
||||||
|
.orientation = DEFAULT_ORIENTATION, \
|
||||||
.window_x = -1, \
|
.window_x = -1, \
|
||||||
.window_y = -1, \
|
.window_y = -1, \
|
||||||
.window_width = 0, \
|
.window_width = 0, \
|
||||||
|
|
|
@ -124,9 +124,11 @@ execute_server(struct server *server, const struct server_params *params) {
|
||||||
char max_size_string[6];
|
char max_size_string[6];
|
||||||
char bit_rate_string[11];
|
char bit_rate_string[11];
|
||||||
char max_fps_string[6];
|
char max_fps_string[6];
|
||||||
|
char orientation_string[4];
|
||||||
sprintf(max_size_string, "%"PRIu16, params->max_size);
|
sprintf(max_size_string, "%"PRIu16, params->max_size);
|
||||||
sprintf(bit_rate_string, "%"PRIu32, params->bit_rate);
|
sprintf(bit_rate_string, "%"PRIu32, params->bit_rate);
|
||||||
sprintf(max_fps_string, "%"PRIu16, params->max_fps);
|
sprintf(max_fps_string, "%"PRIu16, params->max_fps);
|
||||||
|
sprintf(orientation_string, "%"PRIi8, params->orientation);
|
||||||
const char *const cmd[] = {
|
const char *const cmd[] = {
|
||||||
"shell",
|
"shell",
|
||||||
"CLASSPATH=" DEVICE_SERVER_PATH,
|
"CLASSPATH=" DEVICE_SERVER_PATH,
|
||||||
|
@ -142,6 +144,7 @@ execute_server(struct server *server, const struct server_params *params) {
|
||||||
max_size_string,
|
max_size_string,
|
||||||
bit_rate_string,
|
bit_rate_string,
|
||||||
max_fps_string,
|
max_fps_string,
|
||||||
|
orientation_string,
|
||||||
server->tunnel_forward ? "true" : "false",
|
server->tunnel_forward ? "true" : "false",
|
||||||
params->crop ? params->crop : "-",
|
params->crop ? params->crop : "-",
|
||||||
"true", // always send frame meta (packet boundaries + timestamp)
|
"true", // always send frame meta (packet boundaries + timestamp)
|
||||||
|
|
|
@ -36,6 +36,7 @@ struct server_params {
|
||||||
uint16_t max_size;
|
uint16_t max_size;
|
||||||
uint32_t bit_rate;
|
uint32_t bit_rate;
|
||||||
uint16_t max_fps;
|
uint16_t max_fps;
|
||||||
|
int8_t orientation;
|
||||||
bool control;
|
bool control;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@ static void test_options(void) {
|
||||||
"--fullscreen",
|
"--fullscreen",
|
||||||
"--max-fps", "30",
|
"--max-fps", "30",
|
||||||
"--max-size", "1024",
|
"--max-size", "1024",
|
||||||
|
"--orientation", "2",
|
||||||
// "--no-control" is not compatible with "--turn-screen-off"
|
// "--no-control" is not compatible with "--turn-screen-off"
|
||||||
// "--no-display" is not compatible with "--fulscreen"
|
// "--no-display" is not compatible with "--fulscreen"
|
||||||
"--port", "1234",
|
"--port", "1234",
|
||||||
|
@ -78,6 +79,7 @@ static void test_options(void) {
|
||||||
assert(opts->fullscreen);
|
assert(opts->fullscreen);
|
||||||
assert(opts->max_fps == 30);
|
assert(opts->max_fps == 30);
|
||||||
assert(opts->max_size == 1024);
|
assert(opts->max_size == 1024);
|
||||||
|
assert(opts->orientation == 2);
|
||||||
assert(opts->port == 1234);
|
assert(opts->port == 1234);
|
||||||
assert(!strcmp(opts->push_target, "/sdcard/Movies"));
|
assert(!strcmp(opts->push_target, "/sdcard/Movies"));
|
||||||
assert(!strcmp(opts->record_filename, "file"));
|
assert(!strcmp(opts->record_filename, "file"));
|
||||||
|
|
|
@ -18,10 +18,13 @@ public class ControlMessageReader {
|
||||||
public static final int CLIPBOARD_TEXT_MAX_LENGTH = 4093;
|
public static final int CLIPBOARD_TEXT_MAX_LENGTH = 4093;
|
||||||
private static final int RAW_BUFFER_SIZE = 1024;
|
private static final int RAW_BUFFER_SIZE = 1024;
|
||||||
|
|
||||||
|
private static int rotationOffset = 0;
|
||||||
|
|
||||||
private final byte[] rawBuffer = new byte[RAW_BUFFER_SIZE];
|
private final byte[] rawBuffer = new byte[RAW_BUFFER_SIZE];
|
||||||
private final ByteBuffer buffer = ByteBuffer.wrap(rawBuffer);
|
private final ByteBuffer buffer = ByteBuffer.wrap(rawBuffer);
|
||||||
private final byte[] textBuffer = new byte[CLIPBOARD_TEXT_MAX_LENGTH];
|
private final byte[] textBuffer = new byte[CLIPBOARD_TEXT_MAX_LENGTH];
|
||||||
|
|
||||||
|
|
||||||
public ControlMessageReader() {
|
public ControlMessageReader() {
|
||||||
// invariant: the buffer is always in "get" mode
|
// invariant: the buffer is always in "get" mode
|
||||||
buffer.limit(0);
|
buffer.limit(0);
|
||||||
|
@ -169,7 +172,30 @@ public class ControlMessageReader {
|
||||||
int y = buffer.getInt();
|
int y = buffer.getInt();
|
||||||
int screenWidth = toUnsigned(buffer.getShort());
|
int screenWidth = toUnsigned(buffer.getShort());
|
||||||
int screenHeight = toUnsigned(buffer.getShort());
|
int screenHeight = toUnsigned(buffer.getShort());
|
||||||
return new Position(x, y, screenWidth, screenHeight);
|
return rotatePosition(x, y, screenWidth, screenHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("SuspiciousNameCombination")
|
||||||
|
private static Position rotatePosition(int x, int y, int screenWidth, int screenHeight) {
|
||||||
|
Position position;
|
||||||
|
switch (rotationOffset) {
|
||||||
|
case 1:
|
||||||
|
position = new Position(y, screenWidth - x, screenHeight, screenWidth);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
position = new Position(screenWidth - x, screenHeight - y, screenWidth, screenHeight);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
position = new Position(screenHeight - y, x, screenHeight, screenWidth);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
position = new Position(x, y, screenWidth, screenHeight);
|
||||||
|
}
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setRotationOffset(int newRotationOffset) {
|
||||||
|
rotationOffset = newRotationOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("checkstyle:MagicNumber")
|
@SuppressWarnings("checkstyle:MagicNumber")
|
||||||
|
|
|
@ -48,11 +48,11 @@ public final class Device {
|
||||||
|
|
||||||
private ScreenInfo computeScreenInfo(Rect crop, int maxSize) {
|
private ScreenInfo computeScreenInfo(Rect crop, int maxSize) {
|
||||||
DisplayInfo displayInfo = serviceManager.getDisplayManager().getDisplayInfo();
|
DisplayInfo displayInfo = serviceManager.getDisplayManager().getDisplayInfo();
|
||||||
boolean rotated = (displayInfo.getRotation() & 1) != 0;
|
int rotation = displayInfo.getRotation();
|
||||||
Size deviceSize = displayInfo.getSize();
|
Size deviceSize = displayInfo.getSize();
|
||||||
Rect contentRect = new Rect(0, 0, deviceSize.getWidth(), deviceSize.getHeight());
|
Rect contentRect = new Rect(0, 0, deviceSize.getWidth(), deviceSize.getHeight());
|
||||||
if (crop != null) {
|
if (crop != null) {
|
||||||
if (rotated) {
|
if (rotation % 2 != 0 ) { // 180s preserve dimensions
|
||||||
// the crop (provided by the user) is expressed in the natural orientation
|
// the crop (provided by the user) is expressed in the natural orientation
|
||||||
crop = flipRect(crop);
|
crop = flipRect(crop);
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ public final class Device {
|
||||||
}
|
}
|
||||||
|
|
||||||
Size videoSize = computeVideoSize(contentRect.width(), contentRect.height(), maxSize);
|
Size videoSize = computeVideoSize(contentRect.width(), contentRect.height(), maxSize);
|
||||||
return new ScreenInfo(contentRect, videoSize, rotated);
|
return new ScreenInfo(contentRect, videoSize, rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String formatCrop(Rect rect) {
|
private static String formatCrop(Rect rect) {
|
||||||
|
@ -192,7 +192,9 @@ public final class Device {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("SuspiciousNameCombination")
|
||||||
static Rect flipRect(Rect crop) {
|
static Rect flipRect(Rect crop) {
|
||||||
return new Rect(crop.top, crop.left, crop.bottom, crop.right);
|
crop.set(crop.top, crop.left, crop.bottom, crop.right);
|
||||||
|
return crop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ public class Options {
|
||||||
private int maxSize;
|
private int maxSize;
|
||||||
private int bitRate;
|
private int bitRate;
|
||||||
private int maxFps;
|
private int maxFps;
|
||||||
|
private int clientOrientation;
|
||||||
private boolean tunnelForward;
|
private boolean tunnelForward;
|
||||||
private Rect crop;
|
private Rect crop;
|
||||||
private boolean sendFrameMeta; // send PTS so that the client may record properly
|
private boolean sendFrameMeta; // send PTS so that the client may record properly
|
||||||
|
@ -35,6 +36,14 @@ public class Options {
|
||||||
this.maxFps = maxFps;
|
this.maxFps = maxFps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getClientOrientation() {
|
||||||
|
return clientOrientation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClientOrientation(int clientOrientation) {
|
||||||
|
this.clientOrientation = clientOrientation;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isTunnelForward() {
|
public boolean isTunnelForward() {
|
||||||
return tunnelForward;
|
return tunnelForward;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,23 +27,27 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||||
|
|
||||||
private int bitRate;
|
private int bitRate;
|
||||||
private int maxFps;
|
private int maxFps;
|
||||||
|
private int clientOrientation;
|
||||||
|
private int rotationOffset = 0;
|
||||||
private int iFrameInterval;
|
private int iFrameInterval;
|
||||||
private boolean sendFrameMeta;
|
private boolean sendFrameMeta;
|
||||||
private long ptsOrigin;
|
private long ptsOrigin;
|
||||||
|
|
||||||
public ScreenEncoder(boolean sendFrameMeta, int bitRate, int maxFps, int iFrameInterval) {
|
public ScreenEncoder(boolean sendFrameMeta, int bitRate, int maxFps, int clientOrientation, int iFrameInterval) {
|
||||||
this.sendFrameMeta = sendFrameMeta;
|
this.sendFrameMeta = sendFrameMeta;
|
||||||
this.bitRate = bitRate;
|
this.bitRate = bitRate;
|
||||||
this.maxFps = maxFps;
|
this.maxFps = maxFps;
|
||||||
|
this.clientOrientation = clientOrientation;
|
||||||
this.iFrameInterval = iFrameInterval;
|
this.iFrameInterval = iFrameInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScreenEncoder(boolean sendFrameMeta, int bitRate, int maxFps) {
|
public ScreenEncoder(boolean sendFrameMeta, int bitRate, int maxFps, int clientOrientation) {
|
||||||
this(sendFrameMeta, bitRate, maxFps, DEFAULT_I_FRAME_INTERVAL);
|
this(sendFrameMeta, bitRate, maxFps, clientOrientation, DEFAULT_I_FRAME_INTERVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRotationChanged(int rotation) {
|
public void onRotationChanged(int rotation) {
|
||||||
|
setRotationOffset(rotation);
|
||||||
rotationChanged.set(true);
|
rotationChanged.set(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +61,7 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||||
|
|
||||||
MediaFormat format = createFormat(bitRate, maxFps, iFrameInterval);
|
MediaFormat format = createFormat(bitRate, maxFps, iFrameInterval);
|
||||||
device.setRotationListener(this);
|
device.setRotationListener(this);
|
||||||
|
setRotationOffset(device.getScreenInfo().getRotation());
|
||||||
boolean alive;
|
boolean alive;
|
||||||
try {
|
try {
|
||||||
do {
|
do {
|
||||||
|
@ -64,10 +69,10 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||||
IBinder display = createDisplay();
|
IBinder display = createDisplay();
|
||||||
Rect contentRect = device.getScreenInfo().getContentRect();
|
Rect contentRect = device.getScreenInfo().getContentRect();
|
||||||
Rect videoRect = device.getScreenInfo().getVideoSize().toRect();
|
Rect videoRect = device.getScreenInfo().getVideoSize().toRect();
|
||||||
setSize(format, videoRect.width(), videoRect.height());
|
setSize(format, rotationOffset, videoRect.width(), videoRect.height());
|
||||||
configure(codec, format);
|
configure(codec, format);
|
||||||
Surface surface = codec.createInputSurface();
|
Surface surface = codec.createInputSurface();
|
||||||
setDisplaySurface(display, surface, contentRect, videoRect);
|
setDisplaySurface(display, surface, rotationOffset, contentRect, videoRect);
|
||||||
codec.start();
|
codec.start();
|
||||||
try {
|
try {
|
||||||
alive = encode(codec, fd);
|
alive = encode(codec, fd);
|
||||||
|
@ -134,6 +139,13 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||||
IO.writeFully(fd, headerBuffer);
|
IO.writeFully(fd, headerBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setRotationOffset(int rotation) {
|
||||||
|
if(clientOrientation != -1) {// user has requested orientation
|
||||||
|
rotationOffset = rotation + clientOrientation % 4;
|
||||||
|
ControlMessageReader.setRotationOffset(rotationOffset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static MediaCodec createCodec() throws IOException {
|
private static MediaCodec createCodec() throws IOException {
|
||||||
return MediaCodec.createEncoderByType("video/avc");
|
return MediaCodec.createEncoderByType("video/avc");
|
||||||
}
|
}
|
||||||
|
@ -167,16 +179,21 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||||
codec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
|
codec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setSize(MediaFormat format, int width, int height) {
|
private static void setSize(MediaFormat format, int orientation, int width, int height) {
|
||||||
format.setInteger(MediaFormat.KEY_WIDTH, width);
|
if(orientation % 2 == 0) {
|
||||||
format.setInteger(MediaFormat.KEY_HEIGHT, height);
|
format.setInteger(MediaFormat.KEY_WIDTH, width);
|
||||||
|
format.setInteger(MediaFormat.KEY_HEIGHT, height);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
format.setInteger(MediaFormat.KEY_WIDTH, height);
|
||||||
|
format.setInteger(MediaFormat.KEY_HEIGHT, width);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setDisplaySurface(IBinder display, Surface surface, Rect deviceRect, Rect displayRect) {
|
private static void setDisplaySurface(IBinder display, Surface surface, int orientation, Rect deviceRect, Rect displayRect) {
|
||||||
SurfaceControl.openTransaction();
|
SurfaceControl.openTransaction();
|
||||||
try {
|
try {
|
||||||
SurfaceControl.setDisplaySurface(display, surface);
|
SurfaceControl.setDisplaySurface(display, surface);
|
||||||
SurfaceControl.setDisplayProjection(display, 0, deviceRect, displayRect);
|
SurfaceControl.setDisplayProjection(display, orientation, deviceRect, displayRect);
|
||||||
SurfaceControl.setDisplayLayerStack(display, 0);
|
SurfaceControl.setDisplayLayerStack(display, 0);
|
||||||
} finally {
|
} finally {
|
||||||
SurfaceControl.closeTransaction();
|
SurfaceControl.closeTransaction();
|
||||||
|
|
|
@ -5,12 +5,12 @@ import android.graphics.Rect;
|
||||||
public final class ScreenInfo {
|
public final class ScreenInfo {
|
||||||
private final Rect contentRect; // device size, possibly cropped
|
private final Rect contentRect; // device size, possibly cropped
|
||||||
private final Size videoSize;
|
private final Size videoSize;
|
||||||
private final boolean rotated;
|
private final int rotation;
|
||||||
|
|
||||||
public ScreenInfo(Rect contentRect, Size videoSize, boolean rotated) {
|
public ScreenInfo(Rect contentRect, Size videoSize, int rotation) {
|
||||||
this.contentRect = contentRect;
|
this.contentRect = contentRect;
|
||||||
this.videoSize = videoSize;
|
this.videoSize = videoSize;
|
||||||
this.rotated = rotated;
|
this.rotation = rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Rect getContentRect() {
|
public Rect getContentRect() {
|
||||||
|
@ -21,11 +21,14 @@ public final class ScreenInfo {
|
||||||
return videoSize;
|
return videoSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScreenInfo withRotation(int rotation) {
|
public int getRotation() {
|
||||||
boolean newRotated = (rotation & 1) != 0;
|
return rotation;
|
||||||
if (rotated == newRotated) {
|
}
|
||||||
|
|
||||||
|
public ScreenInfo withRotation(int newRotation) {
|
||||||
|
if ((rotation + newRotation) % 2 == 0) { // 180s don't need flipping
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
return new ScreenInfo(Device.flipRect(contentRect), videoSize.rotate(), newRotated);
|
return new ScreenInfo(Device.flipRect(contentRect), videoSize.rotate(), newRotation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ public final class Server {
|
||||||
final Device device = new Device(options);
|
final Device device = new Device(options);
|
||||||
boolean tunnelForward = options.isTunnelForward();
|
boolean tunnelForward = options.isTunnelForward();
|
||||||
try (DesktopConnection connection = DesktopConnection.open(device, tunnelForward)) {
|
try (DesktopConnection connection = DesktopConnection.open(device, tunnelForward)) {
|
||||||
ScreenEncoder screenEncoder = new ScreenEncoder(options.getSendFrameMeta(), options.getBitRate(), options.getMaxFps());
|
ScreenEncoder screenEncoder = new ScreenEncoder(options.getSendFrameMeta(), options.getBitRate(), options.getMaxFps(), options.getClientOrientation());
|
||||||
|
|
||||||
if (options.getControl()) {
|
if (options.getControl()) {
|
||||||
Controller controller = new Controller(device, connection);
|
Controller controller = new Controller(device, connection);
|
||||||
|
@ -79,8 +79,8 @@ public final class Server {
|
||||||
"The server version (" + clientVersion + ") does not match the client " + "(" + BuildConfig.VERSION_NAME + ")");
|
"The server version (" + clientVersion + ") does not match the client " + "(" + BuildConfig.VERSION_NAME + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length != 8) {
|
if (args.length != 9) {
|
||||||
throw new IllegalArgumentException("Expecting 8 parameters");
|
throw new IllegalArgumentException("Expecting 9 parameters");
|
||||||
}
|
}
|
||||||
|
|
||||||
Options options = new Options();
|
Options options = new Options();
|
||||||
|
@ -94,17 +94,20 @@ public final class Server {
|
||||||
int maxFps = Integer.parseInt(args[3]);
|
int maxFps = Integer.parseInt(args[3]);
|
||||||
options.setMaxFps(maxFps);
|
options.setMaxFps(maxFps);
|
||||||
|
|
||||||
|
int clientOrientation = Integer.parseInt(args[4]);
|
||||||
|
options.setClientOrientation(clientOrientation);
|
||||||
|
|
||||||
// use "adb forward" instead of "adb tunnel"? (so the server must listen)
|
// use "adb forward" instead of "adb tunnel"? (so the server must listen)
|
||||||
boolean tunnelForward = Boolean.parseBoolean(args[4]);
|
boolean tunnelForward = Boolean.parseBoolean(args[5]);
|
||||||
options.setTunnelForward(tunnelForward);
|
options.setTunnelForward(tunnelForward);
|
||||||
|
|
||||||
Rect crop = parseCrop(args[5]);
|
Rect crop = parseCrop(args[6]);
|
||||||
options.setCrop(crop);
|
options.setCrop(crop);
|
||||||
|
|
||||||
boolean sendFrameMeta = Boolean.parseBoolean(args[6]);
|
boolean sendFrameMeta = Boolean.parseBoolean(args[7]);
|
||||||
options.setSendFrameMeta(sendFrameMeta);
|
options.setSendFrameMeta(sendFrameMeta);
|
||||||
|
|
||||||
boolean control = Boolean.parseBoolean(args[7]);
|
boolean control = Boolean.parseBoolean(args[8]);
|
||||||
options.setControl(control);
|
options.setControl(control);
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue