- Change 'applist' action to 'list' to match the documentation

- Add 'quit' action to quit the app being streamed
- Check if the device is paired before streaming
- Fix a typo that caused a segfault when streaming
This commit is contained in:
Cameron Gutman 2015-05-15 01:05:23 +00:00
parent 15e0048fca
commit 6be4ffef9f
5 changed files with 54 additions and 6 deletions

View File

@ -57,6 +57,7 @@ implementation.
pair Pair device with computer pair Pair device with computer
stream Stream computer to device stream Stream computer to device
list List available games and applications list List available games and applications
quit Quit the application or game being streamed
help Show this help help Show this help
Streaming options: Streaming options:

View File

@ -20,6 +20,7 @@
#include "http.h" #include "http.h"
#include "xml.h" #include "xml.h"
#include "mkcert.h" #include "mkcert.h"
#include "client.h"
#include "limelight-common/Limelight.h" #include "limelight-common/Limelight.h"
@ -217,6 +218,11 @@ cleanup:
void client_pair(const char *address) { void client_pair(const char *address) {
char url[4096]; char url[4096];
if (client_is_paired(NULL)) {
printf("Already paired\n");
return;
}
char pin[5]; char pin[5];
sprintf(pin, "%d%d%d%d", (int)random() % 10, (int)random() % 10, (int)random() % 10, (int)random() % 10); sprintf(pin, "%d%d%d%d", (int)random() % 10, (int)random() % 10, (int)random() % 10, (int)random() % 10);
printf("Please enter the following PIN on the target PC: %s\n", pin); printf("Please enter the following PIN on the target PC: %s\n", pin);
@ -302,6 +308,8 @@ void client_pair(const char *address) {
sprintf(url, "https://%s:47984/pair?uniqueid=%s&devicename=roth&updateState=1&phrase=pairchallenge", address, unique_id, challenge_response_hex); sprintf(url, "https://%s:47984/pair?uniqueid=%s&devicename=roth&updateState=1&phrase=pairchallenge", address, unique_id, challenge_response_hex);
http_request(url, data); http_request(url, data);
http_free_data(data); http_free_data(data);
printf("Paired\n");
} }
struct app_list *client_applist(const char *address) { struct app_list *client_applist(const char *address) {
@ -345,6 +353,28 @@ void client_start_app(STREAM_CONFIGURATION *config, const char *address, int app
http_free_data(data); http_free_data(data);
} }
void client_quit_app(const char *address) {
char url[4096];
struct http_data *data = http_create_data();
sprintf(url, "https://%s:47984/cancel?uniqueid=%s", address, unique_id);
http_request(url, data);
http_free_data(data);
}
bool client_is_paired(const char *address) {
if (address != NULL)
client_load_server_status(address);
return paired;
}
int client_get_current_game(const char *address) {
if (address != NULL)
client_load_server_status(address);
return currentGame;
}
void client_init(const char *address) { void client_init(const char *address) {
http_init(); http_init();
client_load_unique_id(); client_load_unique_id();

View File

@ -29,3 +29,6 @@ struct app_list* client_applist(const char* serverAddress);
int client_get_app_id(const char* serverAddress, char* name); int client_get_app_id(const char* serverAddress, char* name);
void client_pair(const char *address); void client_pair(const char *address);
int client_get_server_version(void); int client_get_server_version(void);
bool client_is_paired(const char *address);
int client_get_current_game(const char *address);
void client_quit_app(const char *address);

View File

@ -77,7 +77,7 @@ static void stream(STREAM_CONFIGURATION* config, const char* address, const char
} }
struct sockaddr_in *addr = (struct sockaddr_in*)res->ai_addr; struct sockaddr_in *addr = (struct sockaddr_in*)res->ai_addr;
LiStartConnection(addr->sin_addr.s_addr, config, &connection_callbacks, &decoder_callbacks, LiStartConnection(addr->sin_addr.s_addr, config, &connection_callbacks, decoder_callbacks,
&audio_callbacks, &platform_callbacks, NULL, 0, client_get_server_version()); &audio_callbacks, &platform_callbacks, NULL, 0, client_get_server_version());
freeaddrinfo(res); freeaddrinfo(res);
@ -93,6 +93,7 @@ static void help() {
printf("\tpair\t\t\tPair device with computer\n"); printf("\tpair\t\t\tPair device with computer\n");
printf("\tstream\t\t\tStream computer to device\n"); printf("\tstream\t\t\tStream computer to device\n");
printf("\tlist\t\t\tList available games and applications\n"); printf("\tlist\t\t\tList available games and applications\n");
printf("\tquit\t\t\tQuit the application or game being streamed\n");
printf("\thelp\t\t\tShow this help\n\n"); printf("\thelp\t\t\tShow this help\n\n");
printf(" Streaming options\n\n"); printf(" Streaming options\n\n");
printf("\t-720\t\t\tUse 1280x720 resolution [default]\n"); printf("\t-720\t\t\tUse 1280x720 resolution [default]\n");
@ -149,6 +150,13 @@ char* get_path(char* name) {
return NULL; return NULL;
} }
static void pair_check(void) {
if (!client_is_paired(NULL)) {
printf("You must pair with the PC first\n");
exit(-1);
}
}
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
STREAM_CONFIGURATION config; STREAM_CONFIGURATION config;
config.width = 1280; config.width = 1280;
@ -270,12 +278,17 @@ int main(int argc, char* argv[]) {
client_init(address); client_init(address);
if (strcmp("applist", action) == 0) if (strcmp("list", action) == 0) {
pair_check();
applist(address); applist(address);
else if (strcmp("stream", action) == 0) } else if (strcmp("stream", action) == 0) {
pair_check();
stream(&config, address, app, sops, localaudio); stream(&config, address, app, sops, localaudio);
else if (strcmp("pair", action) == 0) } else if (strcmp("pair", action) == 0)
client_pair(address); client_pair(address);
else else if (strcmp("quit", action) == 0) {
fprintf(stderr, "%s is not a valid actions\n", action); pair_check();
client_quit_app(address);
} else
fprintf(stderr, "%s is not a valid action\n", action);
} }

View File

@ -16,6 +16,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Moonlight; if not, see <http://www.gnu.org/licenses/>. * along with Moonlight; if not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once
#include <stdio.h> #include <stdio.h>