mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-04-20 23:30:37 +00:00
Update Moonlight-common-c
This commit is contained in:
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user