Add option for disabling all input (view-only mode) in streaming session

* By default this option is set to `false` and can be enabled using the
  new `-viewonly`/`viewonly` command-line/config options.
* When enabled, none of the input modules will be initialised, making
  the streaming session view-only, i.e. no input is sent to host.

To facilitate implementation, SDL initialisation with `sdl_init()` was moved
a bit earlier in the code to decouple from input initialisation.
This commit is contained in:
Hugo Hromic 2019-10-05 19:27:54 +01:00
parent 4ee5015557
commit ecf09e8907
5 changed files with 69 additions and 42 deletions

View File

@ -149,6 +149,10 @@ Try streaming if GFE version or options are unsupported
Send quit app request to remote after quitting session
=item B<-viewonly>
Disable all input processing (view-only mode)
=item B<-verbose>
Enable verbose output

View File

@ -43,6 +43,9 @@
## Send quit app request to remote after quitting session
#quitappafter = false
## Disable all input processing (view-only mode)
#viewonly = false
## Select audio device to play sound on
#audio = sysdefault

View File

@ -66,6 +66,7 @@ static struct option long_options[] = {
{"codec", required_argument, NULL, 'x'},
{"unsupported", no_argument, NULL, 'y'},
{"quitappafter", no_argument, NULL, '1'},
{"viewonly", no_argument, NULL, '2'},
{"verbose", no_argument, NULL, 'z'},
{"debug", no_argument, NULL, 'Z'},
{0, 0, 0, 0},
@ -216,6 +217,9 @@ static void parse_argument(int c, char* value, PCONFIGURATION config) {
case '1':
config->quitappafter = true;
break;
case '2':
config->viewonly = true;
break;
case 'z':
config->debug_level = 1;
break;
@ -289,6 +293,8 @@ void config_save(char* filename, PCONFIGURATION config) {
write_config_bool(fd, "localaudio", config->localaudio);
if (config->quitappafter)
write_config_bool(fd, "quitappafter", config->quitappafter);
if (config->viewonly)
write_config_bool(fd, "viewonly", config->viewonly);
if (strcmp(config->app, "Steam") != 0)
write_config_string(fd, "app", config->app);
@ -320,6 +326,7 @@ void config_parse(int argc, char* argv[], PCONFIGURATION config) {
config->fullscreen = true;
config->unsupported = false;
config->quitappafter = false;
config->viewonly = false;
config->codec = CODEC_UNSPECIFIED;
config->inputsCount = 0;

View File

@ -41,6 +41,7 @@ typedef struct _CONFIGURATION {
bool fullscreen;
bool unsupported;
bool quitappafter;
bool viewonly;
char* inputs[MAX_INPUTS];
int inputsCount;
enum codecs codec;

View File

@ -128,8 +128,10 @@ static void stream(PSERVER_DATA server, PCONFIGURATION config, enum platform sys
LiStartConnection(&server->serverInfo, &config->stream, &connection_callbacks, platform_get_video(system), platform_get_audio(system, config->audio_device), NULL, drFlags, config->audio_device, 0);
if (IS_EMBEDDED(system)) {
if (!config->viewonly)
evdev_start();
loop_main();
if (!config->viewonly)
evdev_stop();
}
#ifdef HAVE_SDL
@ -185,6 +187,7 @@ static void help() {
printf("\t-platform <system>\tSpecify system used for audio, video and input: pi/imx/aml/rk/x11/x11_vdpau/sdl/fake (default auto)\n");
printf("\t-unsupported\t\tTry streaming if GFE version or options are unsupported\n");
printf("\t-quitappafter\t\tSend quit app request to remote after quitting session\n");
printf("\t-viewonly\t\tDisable all input processing (view-only mode)\n");
#if defined(HAVE_SDL) || defined(HAVE_X11)
printf("\n WM options (SDL and X11 only)\n\n");
printf("\t-windowed\t\tDisplay screen in a window\n");
@ -288,6 +291,15 @@ int main(int argc, char* argv[]) {
}
config.stream.supportsHevc = config.codec != CODEC_H264 && (config.codec == CODEC_HEVC || platform_supports_hevc(system));
#ifdef HAVE_SDL
if (system == SDL)
sdl_init(config.stream.width, config.stream.height, config.fullscreen);
#endif
if (config.viewonly) {
if (config.debug_level > 0)
printf("View-only mode enabled, no input will be sent to the host computer\n");
} else {
if (IS_EMBEDDED(system)) {
char* mapping_env = getenv("SDL_GAMECONTROLLERCONFIG");
if (config.mapping == NULL && mapping_env == NULL) {
@ -326,11 +338,11 @@ int main(int argc, char* argv[]) {
exit(-1);
}
sdl_init(config.stream.width, config.stream.height, config.fullscreen);
sdlinput_init(config.mapping);
rumble_handler = sdlinput_rumble;
}
#endif
}
stream(&server, &config, system);
} else if (strcmp("pair", config.action) == 0) {