mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-04-22 08:10:10 +00:00
Rename functions in libgamestream and provide better error handling
This commit is contained in:
65
src/main.c
65
src/main.c
@@ -46,22 +46,43 @@
|
||||
#define MOONLIGHT_PATH "/moonlight/"
|
||||
#define USER_PATHS ":~/.moonlight:./"
|
||||
|
||||
static void applist(const char* address) {
|
||||
struct app_list* list = client_applist(address);
|
||||
static void applist(PSERVER_DATA server) {
|
||||
PAPP_LIST list;
|
||||
if (gs_applist(server, list) != GS_OK) {
|
||||
fprintf(stderr, "Can't get app list\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 1;list != NULL;i++) {
|
||||
printf("%d. %s\n", i, list->name);
|
||||
list = list->next;
|
||||
}
|
||||
}
|
||||
|
||||
static void stream(STREAM_CONFIGURATION* config, const char* address, const char* app, bool sops, bool localaudio) {
|
||||
int appId = client_get_app_id(address, app);
|
||||
static int get_app_id(PSERVER_DATA server, const char *name) {
|
||||
PAPP_LIST list;
|
||||
if (gs_applist(server, list) != GS_OK) {
|
||||
fprintf(stderr, "Can't get app list\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (list != NULL) {
|
||||
if (strcmp(list->name, name) == 0)
|
||||
return list->id;
|
||||
|
||||
list = list->next;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void stream(PSERVER_DATA server, PSTREAM_CONFIGURATION config, const char* app, bool sops, bool localaudio) {
|
||||
int appId = get_app_id(server, app);
|
||||
if (appId<0) {
|
||||
fprintf(stderr, "Can't find app %s\n", app);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
client_start_app(config, address, appId, sops, localaudio);
|
||||
gs_start_app(server, config, appId, sops, localaudio);
|
||||
|
||||
video_init();
|
||||
evdev_init();
|
||||
@@ -69,7 +90,7 @@ static void stream(STREAM_CONFIGURATION* config, const char* address, const char
|
||||
cec_init();
|
||||
#endif /* HAVE_LIBCEC */
|
||||
|
||||
LiStartConnection(address, config, &connection_callbacks, decoder_callbacks, &audio_callbacks, NULL, NULL, 0, client_get_server_version());
|
||||
LiStartConnection(server->address, config, &connection_callbacks, decoder_callbacks, &audio_callbacks, NULL, NULL, 0, server->serverMajorVersion);
|
||||
|
||||
loop_main();
|
||||
|
||||
@@ -140,8 +161,8 @@ char* get_path(char* name) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void pair_check(void) {
|
||||
if (!client_is_paired(NULL)) {
|
||||
static void pair_check(PSERVER_DATA server) {
|
||||
if (!server->paired) {
|
||||
fprintf(stderr, "You must pair with the PC first\n");
|
||||
exit(-1);
|
||||
}
|
||||
@@ -260,27 +281,33 @@ int main(int argc, char* argv[]) {
|
||||
exit(-1);
|
||||
}
|
||||
address[0] = 0;
|
||||
discover_server(address);
|
||||
gs_discover_server(address);
|
||||
if (address[0] == 0) {
|
||||
fprintf(stderr, "Autodiscovery failed. Specify an IP address next time.\n");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
client_init(address);
|
||||
PSERVER_DATA server;
|
||||
if (gs_init(server, address) != GS_OK) {
|
||||
fprintf(stderr, "Can't connect to server %s\n", address);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (strcmp("list", action) == 0) {
|
||||
pair_check();
|
||||
applist(address);
|
||||
pair_check(server);
|
||||
applist(server);
|
||||
} else if (strcmp("stream", action) == 0) {
|
||||
udev_init(autoadd, mapping);
|
||||
pair_check();
|
||||
stream(&config, address, app, sops, localaudio);
|
||||
} else if (strcmp("pair", action) == 0)
|
||||
client_pair(address);
|
||||
else if (strcmp("quit", action) == 0) {
|
||||
pair_check();
|
||||
client_quit_app(address);
|
||||
pair_check(server);
|
||||
stream(server, &config, app, sops, localaudio);
|
||||
} else if (strcmp("pair", action) == 0) {
|
||||
char pin[5];
|
||||
sprintf(pin, "%d%d%d%d", (int)random() % 10, (int)random() % 10, (int)random() % 10, (int)random() % 10);
|
||||
gs_pair(server, &pin[0]);
|
||||
} else if (strcmp("quit", action) == 0) {
|
||||
pair_check(server);
|
||||
gs_quit_app(server);
|
||||
} else
|
||||
fprintf(stderr, "%s is not a valid action\n", action);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user