mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-02-16 10:30:47 +00:00
Rename functions in libgamestream and provide better error handling
This commit is contained in:
27
src/global.c
Normal file
27
src/global.c
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* This file is part of Moonlight Embedded.
|
||||
*
|
||||
* Copyright (C) 2015 Iwan Timmer
|
||||
*
|
||||
* Moonlight is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Moonlight is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Moonlight; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
#include <pthread.h>
|
||||
|
||||
pthread_t main_thread_id;
|
||||
|
||||
void quit() {
|
||||
pthread_kill(main_thread_id, SIGTERM);
|
||||
}
|
||||
24
src/global.h
Normal file
24
src/global.h
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* This file is part of Moonlight Embedded.
|
||||
*
|
||||
* Copyright (C) 2015 Iwan Timmer
|
||||
*
|
||||
* Moonlight is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Moonlight is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Moonlight; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
extern pthread_t main_thread_id;
|
||||
|
||||
void quit();
|
||||
@@ -18,10 +18,10 @@
|
||||
*/
|
||||
|
||||
#include "../loop.h"
|
||||
#include "../global.h"
|
||||
|
||||
#include "keyboard.h"
|
||||
#include "mapping.h"
|
||||
#include "global.h"
|
||||
|
||||
#include "libevdev/libevdev.h"
|
||||
#include "limelight-common/Limelight.h"
|
||||
|
||||
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