Skip to content

Commit

Permalink
Merged with Dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Stamoulohta committed Feb 17, 2020
2 parents 57e0506 + 96bd2c9 commit 1a63a91
Show file tree
Hide file tree
Showing 21 changed files with 368 additions and 144 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,14 @@ scrcpy -b 2M # short version

#### Limit frame rate

On devices with Android >= 10, the capture frame rate can be limited:
The capture frame rate can be limited:

```bash
scrcpy --max-fps 15
```

This is officially supported since Android 10, but may work on earlier versions.

#### Crop

The device screen may be cropped to mirror only part of the screen.
Expand Down
7 changes: 3 additions & 4 deletions app/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,9 @@ cc = meson.get_compiler('c')

if host_machine.system() == 'windows'
src += [ 'src/sys/win/command.c' ]
src += [ 'src/sys/win/net.c' ]
dependencies += cc.find_library('ws2_32')
else
src += [ 'src/sys/unix/command.c' ]
src += [ 'src/sys/unix/net.c' ]
endif

conf = configuration_data()
Expand All @@ -98,9 +96,10 @@ conf.set_quoted('PREFIX', get_option('prefix'))
# directory as the executable)
conf.set('PORTABLE', get_option('portable'))

# the default client TCP port for the "adb reverse" tunnel
# the default client TCP port range for the "adb reverse" tunnel
# overridden by option --port
conf.set('DEFAULT_LOCAL_PORT', '27183')
conf.set('DEFAULT_LOCAL_PORT_RANGE_FIRST', '27183')
conf.set('DEFAULT_LOCAL_PORT_RANGE_LAST', '27199')

# the default max video size for both dimensions, in pixels
# overridden by option --max-size
Expand Down
8 changes: 4 additions & 4 deletions app/scrcpy.1
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Print this help.

.TP
.BI "\-\-max\-fps " value
Limit the framerate of screen capture (only supported on devices with Android >= 10).
Limit the framerate of screen capture (officially supported since Android 10, but may work on earlier versions).

.TP
.BI "\-m, \-\-max\-size " value
Expand All @@ -66,10 +66,10 @@ Disable device control (mirror the device in read\-only).
Do not display device (only when screen recording is enabled).

.TP
.BI "\-p, \-\-port " port
Set the TCP port the client listens on.
.BI "\-p, \-\-port " port[:port]
Set the TCP port (range) used by the client to listen.

Default is 27183.
Default is 27183:27199.

.TP
.B \-\-prefer\-text
Expand Down
61 changes: 49 additions & 12 deletions app/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ scrcpy_print_usage(const char *arg0) {
" Print this help.\n"
"\n"
" --max-fps value\n"
" Limit the frame rate of screen capture (only supported on\n"
" devices with Android >= 10).\n"
" Limit the frame rate of screen capture (officially supported\n"
" since Android 10, but may work on earlier versions).\n"
"\n"
" -m, --max-size value\n"
" Limit both the width and height of the video to value. The\n"
Expand All @@ -64,9 +64,9 @@ scrcpy_print_usage(const char *arg0) {
" Do not display device (only when screen recording is\n"
" enabled).\n"
"\n"
" -p, --port port\n"
" Set the TCP port the client listens on.\n"
" Default is %d.\n"
" -p, --port port[:port]\n"
" Set the TCP port (range) used by the client to listen.\n"
" Default is %d:%d.\n"
"\n"
" --prefer-text\n"
" Inject alpha characters and space as text events instead of\n"
Expand Down Expand Up @@ -200,7 +200,7 @@ scrcpy_print_usage(const char *arg0) {
DEFAULT_BIT_RATE,
DEFAULT_MAX_SIZE, DEFAULT_MAX_SIZE ? "" : " (unlimited)",
DEFAULT_LOCK_VIDEO_ORIENTATION, DEFAULT_LOCK_VIDEO_ORIENTATION >= 0 ? "" : " (unlocked)",
DEFAULT_LOCAL_PORT);
DEFAULT_LOCAL_PORT_RANGE_FIRST, DEFAULT_LOCAL_PORT_RANGE_LAST);
}

static bool
Expand Down Expand Up @@ -228,6 +228,27 @@ parse_integer_arg(const char *s, long *out, bool accept_suffix, long min,
return true;
}

static size_t
parse_integers_arg(const char *s, size_t max_items, long *out, long min,
long max, const char *name) {
size_t count = parse_integers(s, ':', max_items, out);
if (!count) {
LOGE("Could not parse %s: %s", name, s);
return 0;
}

for (size_t i = 0; i < count; ++i) {
long value = out[i];
if (value < min || value > max) {
LOGE("Could not parse %s: value (%ld) out-of-range (%ld; %ld)",
name, value, min, max);
return 0;
}
}

return count;
}

static bool
parse_bit_rate(const char *s, uint32_t *bit_rate) {
long value;
Expand Down Expand Up @@ -306,14 +327,30 @@ parse_window_dimension(const char *s, uint16_t *dimension) {
}

static bool
parse_port(const char *s, uint16_t *port) {
long value;
bool ok = parse_integer_arg(s, &value, false, 0, 0xFFFF, "port");
if (!ok) {
parse_port_range(const char *s, struct port_range *port_range) {
long values[2];
size_t count = parse_integers_arg(s, 2, values, 0, 0xFFFF, "port");
if (!count) {
return false;
}

*port = (uint16_t) value;
uint16_t v0 = (uint16_t) values[0];
if (count == 1) {
port_range->first = v0;
port_range->last = v0;
return true;
}

assert(count == 2);
uint16_t v1 = (uint16_t) values[1];
if (v0 < v1) {
port_range->first = v0;
port_range->last = v1;
} else {
port_range->first = v1;
port_range->last = v0;
}

return true;
}

Expand Down Expand Up @@ -451,7 +488,7 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
opts->display = false;
break;
case 'p':
if (!parse_port(optarg, &opts->port)) {
if (!parse_port_range(optarg, &opts->port_range)) {
return false;
}
break;
Expand Down
14 changes: 0 additions & 14 deletions app/src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

#include "config.h"
#include "common.h"
Expand Down Expand Up @@ -205,14 +202,3 @@ process_check_success(process_t proc, const char *name) {
}
return true;
}

bool
is_regular_file(const char *path) {
struct stat path_stat;
int r = stat(path, &path_stat);
if (r) {
perror("stat");
return false;
}
return S_ISREG(path_stat.st_mode);
}
5 changes: 5 additions & 0 deletions app/src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ struct position {
struct point point;
};

struct port_range {
uint16_t first;
uint16_t last;
};

#endif
2 changes: 1 addition & 1 deletion app/src/scrcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ scrcpy(const struct scrcpy_options *options) {
bool record = !!options->record_filename;
struct server_params params = {
.crop = options->crop,
.local_port = options->port,
.port_range = options->port_range,
.max_size = options->max_size,
.bit_rate = options->bit_rate,
.max_fps = options->max_fps,
Expand Down
8 changes: 6 additions & 2 deletions app/src/scrcpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <stdint.h>

#include "config.h"
#include "common.h"
#include "input_manager.h"
#include "recorder.h"

Expand All @@ -15,7 +16,7 @@ struct scrcpy_options {
const char *window_title;
const char *push_target;
enum recorder_format record_format;
uint16_t port;
struct port_range port_range;
uint16_t max_size;
uint32_t bit_rate;
uint16_t max_fps;
Expand All @@ -42,7 +43,10 @@ struct scrcpy_options {
.window_title = NULL, \
.push_target = NULL, \
.record_format = RECORDER_FORMAT_AUTO, \
.port = DEFAULT_LOCAL_PORT, \
.port_range = { \
.first = DEFAULT_LOCAL_PORT_RANGE_FIRST, \
.last = DEFAULT_LOCAL_PORT_RANGE_LAST, \
}, \
.max_size = DEFAULT_MAX_SIZE, \
.bit_rate = DEFAULT_BIT_RATE, \
.max_fps = 0, \
Expand Down
Loading

0 comments on commit 1a63a91

Please sign in to comment.