Skip to content

Commit

Permalink
Add support for specifying camera resolution and frame rate
Browse files Browse the repository at this point in the history
This commit add three new CLI options for specifying the camera
resolution and frame rate. By default, the camera's native resolution
and Android's default frame rate (30 fps) are used. If the user selects
a high frame rate (> 60 fps), the capture will automatically switch to
the constrained high speed capture mode.

Signed-off-by: Andrew Gunnerson <[email protected]>
  • Loading branch information
chenxiaolong committed Sep 3, 2023
1 parent d0d0ece commit edb8f5b
Show file tree
Hide file tree
Showing 10 changed files with 252 additions and 33 deletions.
62 changes: 62 additions & 0 deletions app/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ enum {
OPT_DISPLAY_ID,
OPT_CAMERA_ID,
OPT_CAMERA_POSITION,
OPT_CAMERA_WIDTH,
OPT_CAMERA_HEIGHT,
OPT_CAMERA_FPS,
OPT_ROTATION,
OPT_RENDER_DRIVER,
OPT_NO_MIPMAPS,
Expand Down Expand Up @@ -268,6 +271,24 @@ static const struct sc_option options[] = {
"Valid values are: all, front, back, external\n"
"Default is all.",
},
{
.longopt_id = OPT_CAMERA_WIDTH,
.longopt = "camera-width",
.argdesc = "value",
.text = "Specify the camera capture resolution's width when using --video-source=camera.",
},
{
.longopt_id = OPT_CAMERA_HEIGHT,
.longopt = "camera-height",
.argdesc = "value",
.text = "Specify the camera capture resolution's width when using --video-source=camera.",
},
{
.longopt_id = OPT_CAMERA_FPS,
.longopt = "camera-fps",
.argdesc = "value",
.text = "Specify the camera capture frame rate when using --video-source=camera.",
},
{
.longopt_id = OPT_DISPLAY_BUFFER,
.longopt = "display-buffer",
Expand Down Expand Up @@ -1701,6 +1722,32 @@ parse_camera_position(const char *optarg, enum sc_camera_position *position) {
return false;
}

static bool
parse_camera_dimension(const char *s, uint16_t *dimension) {
long value;
bool ok = parse_integer_arg(s, &value, false, 0, 0xFFFF,
"camera dimension");
if (!ok) {
return false;
}

*dimension = (uint16_t) value;
return true;
}

static bool
parse_camera_fps(const char *s, uint16_t *fps) {
long value;
bool ok = parse_integer_arg(s, &value, false, 0, 0xFFFF,
"camera fps");
if (!ok) {
return false;
}

*fps = (uint16_t) value;
return true;
}

static bool
parse_time_limit(const char *s, sc_tick *tick) {
long value;
Expand Down Expand Up @@ -1748,6 +1795,21 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
case OPT_CAMERA_ID:
opts->camera_id = optarg;
break;
case OPT_CAMERA_WIDTH:
if (!parse_camera_dimension(optarg, &opts->camera_width)) {
return false;
}
break;
case OPT_CAMERA_HEIGHT:
if (!parse_camera_dimension(optarg, &opts->camera_height)) {
return false;
}
break;
case OPT_CAMERA_FPS:
if (!parse_camera_fps(optarg, &opts->camera_fps)) {
return false;
}
break;
case OPT_CAMERA_POSITION:
if (!parse_camera_position(optarg, &opts->camera_position)) {
return false;
Expand Down
3 changes: 3 additions & 0 deletions app/src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ const struct scrcpy_options scrcpy_options_default = {
.display_id = 0,
.camera_id = NULL,
.camera_position = SC_CAMERA_POSITION_ALL,
.camera_width = 0,
.camera_height = 0,
.camera_fps = 0,
.display_buffer = 0,
.audio_buffer = SC_TICK_FROM_MS(50),
.audio_output_buffer = SC_TICK_FROM_MS(5),
Expand Down
3 changes: 3 additions & 0 deletions app/src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ struct scrcpy_options {
uint32_t display_id;
const char* camera_id;
enum sc_camera_position camera_position;
uint16_t camera_width;
uint16_t camera_height;
uint16_t camera_fps;
sc_tick display_buffer;
sc_tick audio_buffer;
sc_tick audio_output_buffer;
Expand Down
3 changes: 3 additions & 0 deletions app/src/scrcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ scrcpy(struct scrcpy_options *options) {
.display_id = options->display_id,
.camera_id = options->camera_id,
.camera_position = options->camera_position,
.camera_width = options->camera_width,
.camera_height = options->camera_height,
.camera_fps = options->camera_fps,
.video = options->video,
.audio = options->audio,
.show_touches = options->show_touches,
Expand Down
9 changes: 9 additions & 0 deletions app/src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,15 @@ execute_server(struct sc_server *server,
break;
}
}
if (params->camera_width) {
ADD_PARAM("camera_width=%" PRIu16, params->camera_width);
}
if (params->camera_height) {
ADD_PARAM("camera_height=%" PRIu16, params->camera_height);
}
if (params->camera_fps) {
ADD_PARAM("camera_fps=%" PRIu16, params->camera_fps);
}
if (params->show_touches) {
ADD_PARAM("show_touches=true");
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ struct sc_server_params {
uint32_t display_id;
const char *camera_id;
enum sc_camera_position camera_position;
uint16_t camera_width;
uint16_t camera_height;
uint16_t camera_fps;
bool video;
bool audio;
bool show_touches;
Expand Down
Loading

0 comments on commit edb8f5b

Please sign in to comment.