mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-04-06 16:06:02 +00:00
Update Moonlight-common-c
This commit is contained in:
@@ -23,13 +23,13 @@
|
||||
#include <opus_multistream.h>
|
||||
#include <alsa/asoundlib.h>
|
||||
|
||||
#define CHECK_RETURN(f) if ((rc = f) < 0) { printf("Alsa error code %d\n", rc); exit(-1); }
|
||||
#define CHECK_RETURN(f) if ((rc = f) < 0) { printf("Alsa error code %d\n", rc); return -1; }
|
||||
|
||||
static snd_pcm_t *handle;
|
||||
static OpusMSDecoder* decoder;
|
||||
static short pcmBuffer[FRAME_SIZE * MAX_CHANNEL_COUNT];
|
||||
|
||||
static void alsa_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig) {
|
||||
static int alsa_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig) {
|
||||
int rc;
|
||||
unsigned char alsaMapping[MAX_CHANNEL_COUNT];
|
||||
|
||||
@@ -81,6 +81,8 @@ static void alsa_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGU
|
||||
snd_pcm_sw_params_free(sw_params);
|
||||
|
||||
CHECK_RETURN(snd_pcm_prepare(handle));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void alsa_renderer_cleanup() {
|
||||
|
||||
@@ -32,7 +32,7 @@ static OMX_BUFFERHEADERTYPE *buf;
|
||||
static short pcmBuffer[FRAME_SIZE * MAX_CHANNEL_COUNT];
|
||||
static int channelCount;
|
||||
|
||||
static void omx_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig) {
|
||||
static int omx_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig) {
|
||||
int rc, error;
|
||||
OMX_ERRORTYPE err;
|
||||
unsigned char omxMapping[MAX_CHANNEL_COUNT];
|
||||
@@ -54,17 +54,17 @@ static void omx_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGUR
|
||||
handle = ilclient_init();
|
||||
if (handle == NULL) {
|
||||
fprintf(stderr, "IL client init failed\n");
|
||||
exit(1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ilclient_create_component(handle, &component, componentName, ILCLIENT_DISABLE_ALL_PORTS | ILCLIENT_ENABLE_INPUT_BUFFERS) != 0) {
|
||||
fprintf(stderr, "Component create failed\n");
|
||||
exit(1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ilclient_change_component_state(component, OMX_StateIdle)!= 0) {
|
||||
fprintf(stderr, "Couldn't change state to Idle\n");
|
||||
exit(1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// must be before we enable buffers
|
||||
@@ -119,7 +119,7 @@ static void omx_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGUR
|
||||
err = OMX_SetParameter(ilclient_get_handle(component), OMX_IndexParamAudioPcm, &sPCMMode);
|
||||
if(err != OMX_ErrorNone){
|
||||
fprintf(stderr, "PCM mode unsupported\n");
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
OMX_CONFIG_BRCMAUDIODESTINATIONTYPE arDest;
|
||||
|
||||
@@ -136,7 +136,7 @@ static void omx_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGUR
|
||||
err = OMX_SetParameter(ilclient_get_handle(component), OMX_IndexConfigBrcmAudioDestination, &arDest);
|
||||
if (err != OMX_ErrorNone) {
|
||||
fprintf(stderr, "Error on setting audio destination\nomx option must be set to hdmi or local\n");
|
||||
exit(1);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,9 +146,11 @@ static void omx_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGUR
|
||||
|
||||
err = ilclient_change_component_state(component, OMX_StateExecuting);
|
||||
if (err < 0) {
|
||||
fprintf(stderr, "Couldn't change state to Executing\n");
|
||||
exit(1);
|
||||
fprintf(stderr, "Couldn't change state to Executing\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void omx_renderer_cleanup() {
|
||||
|
||||
@@ -47,7 +47,7 @@ bool audio_pulse_init() {
|
||||
return (bool) dev;
|
||||
}
|
||||
|
||||
static void pulse_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig) {
|
||||
static int pulse_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig) {
|
||||
int rc, error;
|
||||
unsigned char alsaMapping[MAX_CHANNEL_COUNT];
|
||||
|
||||
@@ -78,8 +78,10 @@ static void pulse_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIG
|
||||
|
||||
if (!dev) {
|
||||
printf("Pulseaudio error: %s\n", pa_strerror(error));
|
||||
exit(-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void pulse_renderer_decode_and_play_sample(char* data, int length) {
|
||||
|
||||
@@ -30,7 +30,7 @@ static short pcmBuffer[FRAME_SIZE * MAX_CHANNEL_COUNT];
|
||||
static SDL_AudioDeviceID dev;
|
||||
static int channelCount;
|
||||
|
||||
static void sdl_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig) {
|
||||
static int sdl_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig) {
|
||||
int rc;
|
||||
decoder = opus_multistream_decoder_create(opusConfig->sampleRate, opusConfig->channelCount, opusConfig->streams, opusConfig->coupledStreams, opusConfig->mapping, &rc);
|
||||
|
||||
@@ -48,11 +48,14 @@ static void sdl_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGUR
|
||||
dev = SDL_OpenAudioDevice(NULL, 0, &want, &have, SDL_AUDIO_ALLOW_FORMAT_CHANGE);
|
||||
if (dev == 0) {
|
||||
printf("Failed to open audio: %s\n", SDL_GetError());
|
||||
return -1;
|
||||
} else {
|
||||
if (have.format != want.format) // we let this one thing change.
|
||||
printf("We didn't get requested audio format.\n");
|
||||
SDL_PauseAudioDevice(dev, 0); // start audio playing.
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void sdl_renderer_cleanup() {
|
||||
|
||||
@@ -54,7 +54,7 @@ static int osd_blank(char *path,int cmd) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
void aml_setup(int videoFormat, int width, int height, int redrawRate, void* context, int drFlags) {
|
||||
int aml_setup(int videoFormat, int width, int height, int redrawRate, void* context, int drFlags) {
|
||||
osd_blank("/sys/class/graphics/fb0/blank",1);
|
||||
osd_blank("/sys/class/graphics/fb1/blank",0);
|
||||
|
||||
@@ -87,7 +87,7 @@ void aml_setup(int videoFormat, int width, int height, int redrawRate, void* con
|
||||
break;
|
||||
default:
|
||||
printf("Video format not supported\n");
|
||||
exit(1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
codecParam.am_sysinfo.width = width;
|
||||
@@ -98,12 +98,12 @@ void aml_setup(int videoFormat, int width, int height, int redrawRate, void* con
|
||||
int ret;
|
||||
if ((ret = codec_init(&codecParam)) != 0) {
|
||||
fprintf(stderr, "codec_init error: %x\n", ret);
|
||||
exit(1);
|
||||
return -2;
|
||||
}
|
||||
|
||||
if ((ret = codec_set_freerun_mode(&codecParam, 1)) != 0) {
|
||||
fprintf(stderr, "Can't set Freerun mode: %x\n", ret);
|
||||
exit(1);
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -115,10 +115,10 @@ static int frame_handle(int pipefd) {
|
||||
return LOOP_OK;
|
||||
}
|
||||
|
||||
static void decoder_renderer_setup(int videoFormat, int width, int height, int redrawRate, void* context, int drFlags) {
|
||||
int void decoder_renderer_setup(int videoFormat, int width, int height, int redrawRate, void* context, int drFlags) {
|
||||
if (videoFormat != VIDEO_FORMAT_H264) {
|
||||
fprintf(stderr, "Video format not supported\n");
|
||||
exit(1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct mxcfb_gbl_alpha alpha;
|
||||
@@ -127,14 +127,14 @@ static void decoder_renderer_setup(int videoFormat, int width, int height, int r
|
||||
|
||||
if (fd_fb < 0){
|
||||
fprintf(stderr, "Can't access framebuffer\n");
|
||||
exit(EXIT_FAILURE);
|
||||
return -2;
|
||||
}
|
||||
|
||||
alpha.alpha = 0;
|
||||
alpha.enable = 1;
|
||||
if (ioctl(fd_fb, MXCFB_SET_GBL_ALPHA, &alpha) < 0){
|
||||
fprintf(stderr, "Can't set framebuffer output\n");
|
||||
exit(EXIT_FAILURE);
|
||||
return -2;
|
||||
}
|
||||
|
||||
close(fd_fb);
|
||||
@@ -148,7 +148,7 @@ static void decoder_renderer_setup(int videoFormat, int width, int height, int r
|
||||
fd = open(v4l_device, O_RDWR, 0);
|
||||
if (fd < 0){
|
||||
fprintf(stderr, "Can't access video output\n");
|
||||
exit(EXIT_FAILURE);
|
||||
return -2;
|
||||
}
|
||||
|
||||
struct v4l2_rect icrop = {0};
|
||||
@@ -167,7 +167,7 @@ static void decoder_renderer_setup(int videoFormat, int width, int height, int r
|
||||
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420;
|
||||
if (ioctl(fd, VIDIOC_S_FMT, &fmt) < 0) {
|
||||
fprintf(stderr, "Can't set source video format\n");
|
||||
exit(EXIT_FAILURE);
|
||||
return -2;
|
||||
}
|
||||
|
||||
if (ioctl(fd, VIDIOC_G_FMT, &fmt) < 0) {
|
||||
@@ -184,12 +184,12 @@ static void decoder_renderer_setup(int videoFormat, int width, int height, int r
|
||||
|
||||
if (ioctl(fd, VIDIOC_REQBUFS, &reqbuf) < 0) {
|
||||
fprintf(stderr, "Can't get video buffers\n");
|
||||
exit(EXIT_FAILURE);
|
||||
return -2;
|
||||
}
|
||||
|
||||
if (reqbuf.count < regfbcount) {
|
||||
fprintf(stderr, "Not enough video buffers\n");
|
||||
exit(EXIT_FAILURE);
|
||||
return -2;
|
||||
}
|
||||
|
||||
for (int i = 0; i < regfbcount; i++) {
|
||||
@@ -199,7 +199,7 @@ static void decoder_renderer_setup(int videoFormat, int width, int height, int r
|
||||
buf = calloc(1, sizeof(struct vpu_buf));
|
||||
if (buf == NULL) {
|
||||
fprintf(stderr, "Not enough memory\n");
|
||||
exit(EXIT_FAILURE);
|
||||
return -2;
|
||||
}
|
||||
|
||||
buffers[i] = buf;
|
||||
@@ -210,7 +210,7 @@ static void decoder_renderer_setup(int videoFormat, int width, int height, int r
|
||||
|
||||
if (ioctl(fd, VIDIOC_QUERYBUF, &buffer) < 0) {
|
||||
fprintf(stderr, "Can't get video buffer\n");
|
||||
exit(EXIT_FAILURE);
|
||||
return -2;
|
||||
}
|
||||
buf->start = mmap(NULL, buffer.length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, buffer.m.offset);
|
||||
|
||||
@@ -221,7 +221,7 @@ static void decoder_renderer_setup(int videoFormat, int width, int height, int r
|
||||
*/
|
||||
if (ioctl(fd, VIDIOC_QUERYBUF, &buffer) < 0) {
|
||||
fprintf(stderr, "Can't set source video format\n");
|
||||
exit(EXIT_FAILURE);
|
||||
return -2;
|
||||
}
|
||||
|
||||
buf->offset = buffer.m.offset;
|
||||
@@ -229,7 +229,7 @@ static void decoder_renderer_setup(int videoFormat, int width, int height, int r
|
||||
|
||||
if (buf->start == MAP_FAILED) {
|
||||
fprintf(stderr, "Failed to map video buffer\n");
|
||||
exit(EXIT_FAILURE);
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ static void decoder_renderer_setup(int videoFormat, int width, int height, int r
|
||||
|
||||
if (pipe(pipefd) == -1 || pipe(clearpipefd) == -1) {
|
||||
fprintf(stderr, "Can't create communication channel between threads\n");
|
||||
exit(EXIT_FAILURE);
|
||||
return -2;
|
||||
}
|
||||
|
||||
loop_add_fd(pipefd[0], &frame_handle, POLLIN);
|
||||
|
||||
@@ -53,10 +53,10 @@ static unsigned char *dest;
|
||||
static int port_settings_changed;
|
||||
static int first_packet;
|
||||
|
||||
static void decoder_renderer_setup(int videoFormat, int width, int height, int redrawRate, void* context, int drFlags) {
|
||||
int void decoder_renderer_setup(int videoFormat, int width, int height, int redrawRate, void* context, int drFlags) {
|
||||
if (videoFormat != VIDEO_FORMAT_H264) {
|
||||
fprintf(stderr, "Video format not supported\n");
|
||||
exit(1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
bcm_host_init();
|
||||
@@ -71,18 +71,18 @@ static void decoder_renderer_setup(int videoFormat, int width, int height, int r
|
||||
|
||||
if((client = ilclient_init()) == NULL) {
|
||||
fprintf(stderr, "Can't initialize video\n");
|
||||
exit(EXIT_FAILURE);
|
||||
return -2;
|
||||
}
|
||||
|
||||
if(OMX_Init() != OMX_ErrorNone) {
|
||||
fprintf(stderr, "Can't initialize OMX\n");
|
||||
exit(EXIT_FAILURE);
|
||||
return -2;
|
||||
}
|
||||
|
||||
// create video_decode
|
||||
if(ilclient_create_component(client, &video_decode, "video_decode", ILCLIENT_DISABLE_ALL_PORTS | ILCLIENT_ENABLE_INPUT_BUFFERS) != 0){
|
||||
fprintf(stderr, "Can't create video decode\n");
|
||||
exit(EXIT_FAILURE);
|
||||
return -2;
|
||||
}
|
||||
|
||||
list[0] = video_decode;
|
||||
@@ -90,7 +90,7 @@ static void decoder_renderer_setup(int videoFormat, int width, int height, int r
|
||||
// create video_render
|
||||
if(ilclient_create_component(client, &video_render, "video_render", ILCLIENT_DISABLE_ALL_PORTS) != 0){
|
||||
fprintf(stderr, "Can't create video renderer\n");
|
||||
exit(EXIT_FAILURE);
|
||||
return -2;
|
||||
}
|
||||
|
||||
list[1] = video_render;
|
||||
@@ -117,7 +117,7 @@ static void decoder_renderer_setup(int videoFormat, int width, int height, int r
|
||||
if(OMX_SetParameter(ILC_GET_HANDLE(video_decode), OMX_IndexParamVideoPortFormat, &format) != OMX_ErrorNone ||
|
||||
OMX_SetParameter(ILC_GET_HANDLE(video_decode), OMX_IndexParamBrcmDataUnit, &unit) != OMX_ErrorNone) {
|
||||
fprintf(stderr, "Failed to set video parameters\n");
|
||||
exit(EXIT_FAILURE);
|
||||
return -2;
|
||||
}
|
||||
|
||||
OMX_PARAM_PORTDEFINITIONTYPE port;
|
||||
@@ -128,7 +128,7 @@ static void decoder_renderer_setup(int videoFormat, int width, int height, int r
|
||||
port.nPortIndex = 130;
|
||||
if(OMX_GetParameter(ILC_GET_HANDLE(video_decode), OMX_IndexParamPortDefinition, &port) != OMX_ErrorNone) {
|
||||
fprintf(stderr, "Failed to get decoder port definition\n");
|
||||
exit(EXIT_FAILURE);
|
||||
return -2;
|
||||
}
|
||||
|
||||
// Increase the buffer size to fit the largest possible frame
|
||||
@@ -143,8 +143,10 @@ static void decoder_renderer_setup(int videoFormat, int width, int height, int r
|
||||
ilclient_change_component_state(video_decode, OMX_StateExecuting);
|
||||
} else {
|
||||
fprintf(stderr, "Can't setup video\n");
|
||||
exit(EXIT_FAILURE);
|
||||
return -2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void decoder_renderer_cleanup() {
|
||||
|
||||
@@ -32,21 +32,24 @@
|
||||
|
||||
static char* ffmpeg_buffer;
|
||||
|
||||
static void sdl_setup(int videoFormat, int width, int height, int redrawRate, void* context, int drFlags) {
|
||||
static int sdl_setup(int videoFormat, int width, int height, int redrawRate, void* context, int drFlags) {
|
||||
int avc_flags = SLICE_THREADING;
|
||||
if (drFlags & FORCE_HARDWARE_ACCELERATION)
|
||||
avc_flags |= HARDWARE_ACCELERATION;
|
||||
|
||||
if (ffmpeg_init(videoFormat, width, height, avc_flags, SDL_BUFFER_FRAMES, sysconf(_SC_NPROCESSORS_ONLN)) < 0) {
|
||||
fprintf(stderr, "Couldn't initialize video decoding\n");
|
||||
exit(1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ffmpeg_buffer = malloc(DECODER_BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
|
||||
if (ffmpeg_buffer == NULL) {
|
||||
fprintf(stderr, "Not enough memory\n");
|
||||
exit(1);
|
||||
ffmpeg_destroy();
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void sdl_cleanup() {
|
||||
@@ -92,5 +95,5 @@ DECODER_RENDERER_CALLBACKS decoder_callbacks_sdl = {
|
||||
.setup = sdl_setup,
|
||||
.cleanup = sdl_cleanup,
|
||||
.submitDecodeUnit = sdl_submit_decode_unit,
|
||||
.capabilities = CAPABILITY_SLICES_PER_FRAME(4) | CAPABILITY_REFERENCE_FRAME_INVALIDATION | CAPABILITY_DIRECT_SUBMIT,
|
||||
.capabilities = CAPABILITY_SLICES_PER_FRAME(4) | CAPABILITY_REFERENCE_FRAME_INVALIDATION_AVC | CAPABILITY_REFERENCE_FRAME_INVALIDATION_HEVC | CAPABILITY_DIRECT_SUBMIT,
|
||||
};
|
||||
|
||||
@@ -34,27 +34,28 @@ static char* ffmpeg_buffer = NULL;
|
||||
|
||||
static Display *display;
|
||||
|
||||
void x11_setup(int videoFormat, int width, int height, int redrawRate, void* context, int drFlags) {
|
||||
int x11_setup(int videoFormat, int width, int height, int redrawRate, void* context, int drFlags) {
|
||||
int avc_flags = SLICE_THREADING;
|
||||
if (drFlags & FORCE_HARDWARE_ACCELERATION)
|
||||
avc_flags |= HARDWARE_ACCELERATION;
|
||||
|
||||
if (ffmpeg_init(videoFormat, width, height, avc_flags, 2, 2) < 0) {
|
||||
fprintf(stderr, "Couldn't initialize video decoding\n");
|
||||
exit(1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ffmpeg_buffer = malloc(DECODER_BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
|
||||
if (ffmpeg_buffer == NULL) {
|
||||
fprintf(stderr, "Not enough memory\n");
|
||||
exit(1);
|
||||
ffmpeg_destroy();
|
||||
return -1;
|
||||
}
|
||||
|
||||
XInitThreads();
|
||||
display = XOpenDisplay(NULL);
|
||||
if (!display) {
|
||||
fprintf(stderr, "Error: failed to open X display.\n");
|
||||
return;
|
||||
return -2;
|
||||
}
|
||||
|
||||
Window root = DefaultRootWindow(display);
|
||||
@@ -81,6 +82,8 @@ void x11_setup(int videoFormat, int width, int height, int redrawRate, void* con
|
||||
|
||||
egl_init(display, window, width, height);
|
||||
x11_input_init(display, window);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void x11_cleanup() {
|
||||
@@ -110,5 +113,5 @@ DECODER_RENDERER_CALLBACKS decoder_callbacks_x11 = {
|
||||
.setup = x11_setup,
|
||||
.cleanup = x11_cleanup,
|
||||
.submitDecodeUnit = x11_submit_decode_unit,
|
||||
.capabilities = CAPABILITY_SLICES_PER_FRAME(4) | CAPABILITY_REFERENCE_FRAME_INVALIDATION | CAPABILITY_DIRECT_SUBMIT,
|
||||
.capabilities = CAPABILITY_SLICES_PER_FRAME(4) | CAPABILITY_REFERENCE_FRAME_INVALIDATION_AVC | CAPABILITY_REFERENCE_FRAME_INVALIDATION_HEVC | CAPABILITY_DIRECT_SUBMIT,
|
||||
};
|
||||
|
||||
2
third_party/moonlight-common-c
vendored
2
third_party/moonlight-common-c
vendored
Submodule third_party/moonlight-common-c updated: cd9f47371a...560cd3241f
Reference in New Issue
Block a user