Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal VNC server implementation #3959

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
make VNC optional
  • Loading branch information
DavidVentura committed May 1, 2023
commit 6d2682eca58d44eafad1d89e67fe0943807f7cb4
15 changes: 12 additions & 3 deletions app/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ src = [
'src/screen.c',
'src/server.c',
'src/version.c',
'src/vnc_sink.c',
'src/trait/frame_source.c',
'src/trait/packet_source.c',
'src/util/acksync.c',
Expand Down Expand Up @@ -84,6 +83,11 @@ if v4l2_support
src += [ 'src/v4l2_sink.c' ]
endif

vnc_support = get_option('vnc') and host_machine.system() == 'linux'
if vnc_support
src += [ 'src/vnc_sink.c' ]
endif

usb_support = get_option('usb')
if usb_support
src += [
Expand All @@ -109,13 +113,15 @@ if not crossbuild_windows
dependency('libavutil'),
dependency('libswresample'),
dependency('sdl2', version: '>= 2.0.5'),
dependency('libswscale'),
dependency('libvncserver'),
]

if v4l2_support
dependencies += dependency('libavdevice')
endif
if vnc_support
dependencies += dependency('libswscale')
dependencies += dependency('libvncserver')
endif

if usb_support
dependencies += dependency('libusb-1.0')
Expand Down Expand Up @@ -217,6 +223,9 @@ conf.set('SERVER_DEBUGGER_METHOD_NEW', get_option('server_debugger_method') == '
# enable V4L2 support (linux only)
conf.set('HAVE_V4L2', v4l2_support)

# enable libvnc support
conf.set('HAVE_VNC', vnc_support)

# enable HID over AOA support (linux only)
conf.set('HAVE_USB', usb_support)

Expand Down
30 changes: 20 additions & 10 deletions app/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -1868,7 +1868,12 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
}
break;
case OPT_VNC_SERVER:
#ifdef HAVE_VNC
opts->vnc_server = true;
#else
LOGE("VNC (--vnc-server) is disabled.");
return false;
#endif
break;
default:
// getopt prints the error message on stderr
Expand Down Expand Up @@ -1898,11 +1903,22 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
return false;
}

bool has_sink = opts->record_filename;
#ifdef HAVE_V4L2
has_sink |= (opts->v4l2_device != NULL);
#endif
#ifdef HAVE_VNC
has_sink |= opts->vnc_server;
#endif
if (!opts->display && !has_sink) {
LOGE("-N/--no-display requires at least one of the following to be set: ");
LOGE("* screen recording (-r/--record)");
#ifdef HAVE_V4L2
if (!opts->display && !opts->record_filename && !opts->v4l2_device && !opts->vnc_server) {
LOGE("-N/--no-display requires either screen recording (-r/--record)"
" or sink to v4l2loopback device (--v4l2-sink) or setting up a VNC server"
" (--vnc-server)");
LOGE("* sink to v4l2loopback device (--v4l2-sink)");
#endif
#ifdef HAVE_VNC
LOGE("* setting up a VNC server (--vnc-server)");
#endif
return false;
}

Expand All @@ -1924,12 +1940,6 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
LOGE("V4L2 buffer value without V4L2 sink\n");
return false;
}
#else
if (!opts->display && !opts->record_filename) {
LOGE("-N/--no-display requires screen recording (-r/--record)");
return false;
}
#endif

if (opts->audio && !opts->display && !opts->record_filename) {
LOGI("No display and no recording: audio disabled");
Expand Down
14 changes: 12 additions & 2 deletions app/src/scrcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "recorder.h"
#include "screen.h"
#include "server.h"
#include "vnc_sink.h"
#ifdef HAVE_USB
# include "usb/aoa_hid.h"
# include "usb/hid_keyboard.h"
Expand All @@ -39,6 +38,9 @@
#ifdef HAVE_V4L2
# include "v4l2_sink.h"
#endif
#ifdef HAVE_VNC
#include "vnc_sink.h"
#endif

struct scrcpy {
struct sc_server server;
Expand All @@ -49,8 +51,10 @@ struct scrcpy {
struct sc_decoder video_decoder;
struct sc_decoder audio_decoder;
struct sc_recorder recorder;
struct sc_vnc_sink vnc_sink;
struct sc_delay_buffer display_buffer;
#ifdef HAVE_VNC
struct sc_vnc_sink vnc_sink;
#endif
#ifdef HAVE_V4L2
struct sc_v4l2_sink v4l2_sink;
struct sc_delay_buffer v4l2_buffer;
Expand Down Expand Up @@ -313,7 +317,9 @@ scrcpy(struct scrcpy_options *options) {
#ifdef HAVE_V4L2
bool v4l2_sink_initialized = false;
#endif
#ifdef HAVE_VNC
bool vnc_sink_initialized = false;
#endif
bool video_demuxer_started = false;
bool audio_demuxer_started = false;
#ifdef HAVE_USB
Expand Down Expand Up @@ -697,6 +703,7 @@ scrcpy(struct scrcpy_options *options) {
&s->audio_player.frame_sink);
}
}
#ifdef HAVE_VNC
if (options->vnc_server) {
if (!sc_vnc_sink_init(&s->vnc_sink, "my vnc server", controller)) {
printf("bad vnc init \n");
Expand All @@ -706,6 +713,7 @@ scrcpy(struct scrcpy_options *options) {
struct sc_frame_source *src = &s->video_decoder.frame_source;
sc_frame_source_add_sink(src, &s->vnc_sink.frame_sink);
}
#endif

#ifdef HAVE_V4L2
if (options->v4l2_device) {
Expand Down Expand Up @@ -798,9 +806,11 @@ scrcpy(struct scrcpy_options *options) {
sc_v4l2_sink_destroy(&s->v4l2_sink);
}
#endif
#ifdef HAVE_VNC
if (vnc_sink_initialized) {
sc_vnc_sink_destroy(&s->vnc_sink);
}
#endif

#ifdef HAVE_USB
if (aoa_hid_initialized) {
Expand Down
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ option('portable', type: 'boolean', value: false, description: 'Use scrcpy-serve
option('server_debugger', type: 'boolean', value: false, description: 'Run a server debugger and wait for a client to be attached')
option('server_debugger_method', type: 'combo', choices: ['old', 'new'], value: 'new', description: 'Select the debugger method (Android < 9: "old", Android >= 9: "new")')
option('v4l2', type: 'boolean', value: true, description: 'Enable V4L2 feature when supported')
option('vnc', type: 'boolean', value: true, description: 'Enable VNC server feature when supported')
option('usb', type: 'boolean', value: true, description: 'Enable HID/OTG features when supported')