Update moonlight-common-c with Sunshine extensions

This commit is contained in:
Cameron Gutman
2023-08-29 20:46:35 -05:00
parent 606e6d1181
commit ab53f149f2
9 changed files with 48 additions and 28 deletions

View File

@@ -17,6 +17,7 @@
* along with Moonlight; if not, see <http://www.gnu.org/licenses/>.
*/
#include "platform.h"
#include "config.h"
#include "util.h"
@@ -225,6 +226,8 @@ static void parse_argument(int c, char* value, PCONFIGURATION config) {
config->codec = CODEC_H264;
else if (strcasecmp(value, "h265") == 0 || strcasecmp(value, "hevc") == 0)
config->codec = CODEC_HEVC;
else if (strcasecmp(value, "av1") == 0)
config->codec = CODEC_AV1;
break;
case 'y':
config->unsupported = false;
@@ -254,7 +257,7 @@ static void parse_argument(int c, char* value, PCONFIGURATION config) {
config->port = atoi(value);
break;
case '7':
config->stream.enableHdr = true;
config->hdr = true;
break;
case 1:
if (config->action == NULL)
@@ -344,8 +347,7 @@ void config_parse(int argc, char* argv[], PCONFIGURATION config) {
config->stream.packetSize = 1392;
config->stream.streamingRemotely = STREAM_CFG_AUTO;
config->stream.audioConfiguration = AUDIO_CONFIGURATION_STEREO;
config->stream.supportsHevc = false;
config->stream.enableHdr = false;
config->stream.supportedVideoFormats = SCM_H264;
config->stream.encryptionFlags = ENCFLG_AUDIO;
#ifdef __arm__
@@ -377,6 +379,7 @@ void config_parse(int argc, char* argv[], PCONFIGURATION config) {
config->mouse_emulation = true;
config->rotate = 0;
config->codec = CODEC_UNSPECIFIED;
config->hdr = false;
config->pin = 0;
config->port = 47989;

View File

@@ -23,8 +23,6 @@
#define MAX_INPUTS 6
enum codecs { CODEC_UNSPECIFIED, CODEC_H264, CODEC_HEVC };
typedef struct _CONFIGURATION {
STREAM_CONFIGURATION stream;
int debug_level;
@@ -47,6 +45,7 @@ typedef struct _CONFIGURATION {
char* inputs[MAX_INPUTS];
int inputsCount;
enum codecs codec;
bool hdr;
int pin;
unsigned short port;
} CONFIGURATION, *PCONFIGURATION;

View File

@@ -20,8 +20,8 @@
#include "loop.h"
#include "connection.h"
#include "configuration.h"
#include "config.h"
#include "platform.h"
#include "config.h"
#include "sdl.h"
#include "audio/audio.h"
@@ -96,7 +96,7 @@ static void stream(PSERVER_DATA server, PCONFIGURATION config, enum platform sys
gamepads += sdl_gamepads;
#endif
int gamepad_mask = 0;
for (int i = 0; i < gamepads && i < 4; i++)
for (int i = 0; i < gamepads; i++)
gamepad_mask = (gamepad_mask << 1) + 1;
int ret = gs_start_app(server, &config->stream, appId, config->sops, config->localaudio, gamepad_mask);
@@ -201,7 +201,7 @@ static void help() {
printf("\t-fps <fps>\t\tSpecify the fps to use (default 60)\n");
printf("\t-bitrate <bitrate>\tSpecify the bitrate in Kbps\n");
printf("\t-packetsize <size>\tSpecify the maximum packetsize in bytes\n");
printf("\t-codec <codec>\t\tSelect used codec: auto/h264/h265 (default auto)\n");
printf("\t-codec <codec>\t\tSelect used codec: auto/h264/h265/av1 (default auto)\n");
printf("\t-hdr\t\tEnable HDR streaming (experimental, requires host and device support)\n");
printf("\t-remote <yes/no/auto>\t\t\tEnable optimizations for WAN streaming (default auto)\n");
printf("\t-app <app>\t\tName of app to stream\n");
@@ -316,9 +316,21 @@ int main(int argc, char* argv[]) {
fprintf(stderr, "You can't select a audio device for SDL\n");
exit(-1);
}
config.stream.supportsHevc = config.codec != CODEC_H264 && (config.codec == CODEC_HEVC || platform_supports_hevc(system));
if (config.stream.enableHdr && !config.stream.supportsHevc) {
fprintf(stderr, "HDR streaming requires HEVC codec\n");
config.stream.supportedVideoFormats = SCM_H264;
if (config.codec == CODEC_HEVC || (config.codec == CODEC_UNSPECIFIED && platform_prefers_codec(system, config.codec))) {
config.stream.supportedVideoFormats |= SCM_HEVC;
if (config.hdr)
config.stream.supportedVideoFormats |= SCM_HEVC_MAIN10;
}
if (config.codec == CODEC_AV1 || (config.codec == CODEC_UNSPECIFIED && platform_prefers_codec(system, config.codec))) {
config.stream.supportedVideoFormats |= SCM_AV1_MAIN8;
if (config.hdr)
config.stream.supportedVideoFormats |= SCM_AV1_MAIN10;
}
if (config.hdr && !(config.stream.supportedVideoFormats & VIDEO_FORMAT_MASK_10BIT)) {
fprintf(stderr, "HDR streaming requires HEVC or AV1 codec\n");
exit(-1);
}

View File

@@ -206,13 +206,22 @@ AUDIO_RENDERER_CALLBACKS* platform_get_audio(enum platform system, char* audio_d
return NULL;
}
bool platform_supports_hevc(enum platform system) {
switch (system) {
case AML:
case RK:
case X11_VAAPI:
case X11_VDPAU:
bool platform_prefers_codec(enum platform system, enum codecs codec) {
switch (codec) {
case CODEC_H264:
// H.264 is always supported
return true;
case CODEC_HEVC:
switch (system) {
case AML:
case RK:
case X11_VAAPI:
case X11_VDPAU:
return true;
}
return false;
case CODEC_AV1:
return false;
}
return false;
}

View File

@@ -27,11 +27,12 @@
#define IS_EMBEDDED(SYSTEM) SYSTEM != SDL
enum platform { NONE, SDL, X11, X11_VDPAU, X11_VAAPI, PI, MMAL, IMX, AML, RK, FAKE };
enum codecs { CODEC_UNSPECIFIED, CODEC_H264, CODEC_HEVC, CODEC_AV1 };
enum platform platform_check(char*);
PDECODER_RENDERER_CALLBACKS platform_get_video(enum platform system);
PAUDIO_RENDERER_CALLBACKS platform_get_audio(enum platform system, char* audio_device);
bool platform_supports_hevc(enum platform system);
bool platform_prefers_codec(enum platform system, enum codecs codec);
char* platform_name(enum platform system);
void platform_start(enum platform system);