Update Moonlight-common-c

This commit is contained in:
Iwan Timmer
2017-05-28 14:56:36 +02:00
parent 343e3992c1
commit a0462e49b8
10 changed files with 66 additions and 49 deletions
+4 -2
View File
@@ -23,13 +23,13 @@
#include <opus_multistream.h> #include <opus_multistream.h>
#include <alsa/asoundlib.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 snd_pcm_t *handle;
static OpusMSDecoder* decoder; static OpusMSDecoder* decoder;
static short pcmBuffer[FRAME_SIZE * MAX_CHANNEL_COUNT]; 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; int rc;
unsigned char alsaMapping[MAX_CHANNEL_COUNT]; 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); snd_pcm_sw_params_free(sw_params);
CHECK_RETURN(snd_pcm_prepare(handle)); CHECK_RETURN(snd_pcm_prepare(handle));
return 0;
} }
static void alsa_renderer_cleanup() { static void alsa_renderer_cleanup() {
+9 -7
View File
@@ -32,7 +32,7 @@ static OMX_BUFFERHEADERTYPE *buf;
static short pcmBuffer[FRAME_SIZE * MAX_CHANNEL_COUNT]; static short pcmBuffer[FRAME_SIZE * MAX_CHANNEL_COUNT];
static int channelCount; 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; int rc, error;
OMX_ERRORTYPE err; OMX_ERRORTYPE err;
unsigned char omxMapping[MAX_CHANNEL_COUNT]; unsigned char omxMapping[MAX_CHANNEL_COUNT];
@@ -54,17 +54,17 @@ static void omx_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGUR
handle = ilclient_init(); handle = ilclient_init();
if (handle == NULL) { if (handle == NULL) {
fprintf(stderr, "IL client init failed\n"); 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) { if (ilclient_create_component(handle, &component, componentName, ILCLIENT_DISABLE_ALL_PORTS | ILCLIENT_ENABLE_INPUT_BUFFERS) != 0) {
fprintf(stderr, "Component create failed\n"); fprintf(stderr, "Component create failed\n");
exit(1); return -1;
} }
if (ilclient_change_component_state(component, OMX_StateIdle)!= 0) { if (ilclient_change_component_state(component, OMX_StateIdle)!= 0) {
fprintf(stderr, "Couldn't change state to Idle\n"); fprintf(stderr, "Couldn't change state to Idle\n");
exit(1); return -1;
} }
// must be before we enable buffers // 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); err = OMX_SetParameter(ilclient_get_handle(component), OMX_IndexParamAudioPcm, &sPCMMode);
if(err != OMX_ErrorNone){ if(err != OMX_ErrorNone){
fprintf(stderr, "PCM mode unsupported\n"); fprintf(stderr, "PCM mode unsupported\n");
return; return -1;
} }
OMX_CONFIG_BRCMAUDIODESTINATIONTYPE arDest; 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); err = OMX_SetParameter(ilclient_get_handle(component), OMX_IndexConfigBrcmAudioDestination, &arDest);
if (err != OMX_ErrorNone) { if (err != OMX_ErrorNone) {
fprintf(stderr, "Error on setting audio destination\nomx option must be set to hdmi or local\n"); fprintf(stderr, "Error on setting audio destination\nomx option must be set to hdmi or local\n");
exit(1); return -1;
} }
} }
@@ -147,8 +147,10 @@ static void omx_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGUR
err = ilclient_change_component_state(component, OMX_StateExecuting); err = ilclient_change_component_state(component, OMX_StateExecuting);
if (err < 0) { if (err < 0) {
fprintf(stderr, "Couldn't change state to Executing\n"); fprintf(stderr, "Couldn't change state to Executing\n");
exit(1); return -1;
} }
return 0;
} }
static void omx_renderer_cleanup() { static void omx_renderer_cleanup() {
+4 -2
View File
@@ -47,7 +47,7 @@ bool audio_pulse_init() {
return (bool) dev; 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; int rc, error;
unsigned char alsaMapping[MAX_CHANNEL_COUNT]; unsigned char alsaMapping[MAX_CHANNEL_COUNT];
@@ -78,8 +78,10 @@ static void pulse_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIG
if (!dev) { if (!dev) {
printf("Pulseaudio error: %s\n", pa_strerror(error)); 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) { static void pulse_renderer_decode_and_play_sample(char* data, int length) {
+4 -1
View File
@@ -30,7 +30,7 @@ static short pcmBuffer[FRAME_SIZE * MAX_CHANNEL_COUNT];
static SDL_AudioDeviceID dev; static SDL_AudioDeviceID dev;
static int channelCount; 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; int rc;
decoder = opus_multistream_decoder_create(opusConfig->sampleRate, opusConfig->channelCount, opusConfig->streams, opusConfig->coupledStreams, opusConfig->mapping, &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); dev = SDL_OpenAudioDevice(NULL, 0, &want, &have, SDL_AUDIO_ALLOW_FORMAT_CHANGE);
if (dev == 0) { if (dev == 0) {
printf("Failed to open audio: %s\n", SDL_GetError()); printf("Failed to open audio: %s\n", SDL_GetError());
return -1;
} else { } else {
if (have.format != want.format) // we let this one thing change. if (have.format != want.format) // we let this one thing change.
printf("We didn't get requested audio format.\n"); printf("We didn't get requested audio format.\n");
SDL_PauseAudioDevice(dev, 0); // start audio playing. SDL_PauseAudioDevice(dev, 0); // start audio playing.
} }
return 0;
} }
static void sdl_renderer_cleanup() { static void sdl_renderer_cleanup() {
+4 -4
View File
@@ -54,7 +54,7 @@ static int osd_blank(char *path,int cmd) {
return -1; 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/fb0/blank",1);
osd_blank("/sys/class/graphics/fb1/blank",0); 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; break;
default: default:
printf("Video format not supported\n"); printf("Video format not supported\n");
exit(1); return -1;
} }
codecParam.am_sysinfo.width = width; codecParam.am_sysinfo.width = width;
@@ -98,12 +98,12 @@ void aml_setup(int videoFormat, int width, int height, int redrawRate, void* con
int ret; int ret;
if ((ret = codec_init(&codecParam)) != 0) { if ((ret = codec_init(&codecParam)) != 0) {
fprintf(stderr, "codec_init error: %x\n", ret); fprintf(stderr, "codec_init error: %x\n", ret);
exit(1); return -2;
} }
if ((ret = codec_set_freerun_mode(&codecParam, 1)) != 0) { if ((ret = codec_set_freerun_mode(&codecParam, 1)) != 0) {
fprintf(stderr, "Can't set Freerun mode: %x\n", ret); fprintf(stderr, "Can't set Freerun mode: %x\n", ret);
exit(1); return -2;
} }
} }
+13 -13
View File
@@ -115,10 +115,10 @@ static int frame_handle(int pipefd) {
return LOOP_OK; 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) { if (videoFormat != VIDEO_FORMAT_H264) {
fprintf(stderr, "Video format not supported\n"); fprintf(stderr, "Video format not supported\n");
exit(1); return -1;
} }
struct mxcfb_gbl_alpha alpha; 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){ if (fd_fb < 0){
fprintf(stderr, "Can't access framebuffer\n"); fprintf(stderr, "Can't access framebuffer\n");
exit(EXIT_FAILURE); return -2;
} }
alpha.alpha = 0; alpha.alpha = 0;
alpha.enable = 1; alpha.enable = 1;
if (ioctl(fd_fb, MXCFB_SET_GBL_ALPHA, &alpha) < 0){ if (ioctl(fd_fb, MXCFB_SET_GBL_ALPHA, &alpha) < 0){
fprintf(stderr, "Can't set framebuffer output\n"); fprintf(stderr, "Can't set framebuffer output\n");
exit(EXIT_FAILURE); return -2;
} }
close(fd_fb); 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); fd = open(v4l_device, O_RDWR, 0);
if (fd < 0){ if (fd < 0){
fprintf(stderr, "Can't access video output\n"); fprintf(stderr, "Can't access video output\n");
exit(EXIT_FAILURE); return -2;
} }
struct v4l2_rect icrop = {0}; 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; fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420;
if (ioctl(fd, VIDIOC_S_FMT, &fmt) < 0) { if (ioctl(fd, VIDIOC_S_FMT, &fmt) < 0) {
fprintf(stderr, "Can't set source video format\n"); fprintf(stderr, "Can't set source video format\n");
exit(EXIT_FAILURE); return -2;
} }
if (ioctl(fd, VIDIOC_G_FMT, &fmt) < 0) { 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) { if (ioctl(fd, VIDIOC_REQBUFS, &reqbuf) < 0) {
fprintf(stderr, "Can't get video buffers\n"); fprintf(stderr, "Can't get video buffers\n");
exit(EXIT_FAILURE); return -2;
} }
if (reqbuf.count < regfbcount) { if (reqbuf.count < regfbcount) {
fprintf(stderr, "Not enough video buffers\n"); fprintf(stderr, "Not enough video buffers\n");
exit(EXIT_FAILURE); return -2;
} }
for (int i = 0; i < regfbcount; i++) { 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)); buf = calloc(1, sizeof(struct vpu_buf));
if (buf == NULL) { if (buf == NULL) {
fprintf(stderr, "Not enough memory\n"); fprintf(stderr, "Not enough memory\n");
exit(EXIT_FAILURE); return -2;
} }
buffers[i] = buf; 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) { if (ioctl(fd, VIDIOC_QUERYBUF, &buffer) < 0) {
fprintf(stderr, "Can't get video buffer\n"); 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); 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) { if (ioctl(fd, VIDIOC_QUERYBUF, &buffer) < 0) {
fprintf(stderr, "Can't set source video format\n"); fprintf(stderr, "Can't set source video format\n");
exit(EXIT_FAILURE); return -2;
} }
buf->offset = buffer.m.offset; 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) { if (buf->start == MAP_FAILED) {
fprintf(stderr, "Failed to map video buffer\n"); 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) { if (pipe(pipefd) == -1 || pipe(clearpipefd) == -1) {
fprintf(stderr, "Can't create communication channel between threads\n"); fprintf(stderr, "Can't create communication channel between threads\n");
exit(EXIT_FAILURE); return -2;
} }
loop_add_fd(pipefd[0], &frame_handle, POLLIN); loop_add_fd(pipefd[0], &frame_handle, POLLIN);
+11 -9
View File
@@ -53,10 +53,10 @@ static unsigned char *dest;
static int port_settings_changed; static int port_settings_changed;
static int first_packet; 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) { if (videoFormat != VIDEO_FORMAT_H264) {
fprintf(stderr, "Video format not supported\n"); fprintf(stderr, "Video format not supported\n");
exit(1); return -1;
} }
bcm_host_init(); 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) { if((client = ilclient_init()) == NULL) {
fprintf(stderr, "Can't initialize video\n"); fprintf(stderr, "Can't initialize video\n");
exit(EXIT_FAILURE); return -2;
} }
if(OMX_Init() != OMX_ErrorNone) { if(OMX_Init() != OMX_ErrorNone) {
fprintf(stderr, "Can't initialize OMX\n"); fprintf(stderr, "Can't initialize OMX\n");
exit(EXIT_FAILURE); return -2;
} }
// create video_decode // create video_decode
if(ilclient_create_component(client, &video_decode, "video_decode", ILCLIENT_DISABLE_ALL_PORTS | ILCLIENT_ENABLE_INPUT_BUFFERS) != 0){ 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"); fprintf(stderr, "Can't create video decode\n");
exit(EXIT_FAILURE); return -2;
} }
list[0] = video_decode; list[0] = video_decode;
@@ -90,7 +90,7 @@ static void decoder_renderer_setup(int videoFormat, int width, int height, int r
// create video_render // create video_render
if(ilclient_create_component(client, &video_render, "video_render", ILCLIENT_DISABLE_ALL_PORTS) != 0){ if(ilclient_create_component(client, &video_render, "video_render", ILCLIENT_DISABLE_ALL_PORTS) != 0){
fprintf(stderr, "Can't create video renderer\n"); fprintf(stderr, "Can't create video renderer\n");
exit(EXIT_FAILURE); return -2;
} }
list[1] = video_render; 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 || 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) { OMX_SetParameter(ILC_GET_HANDLE(video_decode), OMX_IndexParamBrcmDataUnit, &unit) != OMX_ErrorNone) {
fprintf(stderr, "Failed to set video parameters\n"); fprintf(stderr, "Failed to set video parameters\n");
exit(EXIT_FAILURE); return -2;
} }
OMX_PARAM_PORTDEFINITIONTYPE port; OMX_PARAM_PORTDEFINITIONTYPE port;
@@ -128,7 +128,7 @@ static void decoder_renderer_setup(int videoFormat, int width, int height, int r
port.nPortIndex = 130; port.nPortIndex = 130;
if(OMX_GetParameter(ILC_GET_HANDLE(video_decode), OMX_IndexParamPortDefinition, &port) != OMX_ErrorNone) { if(OMX_GetParameter(ILC_GET_HANDLE(video_decode), OMX_IndexParamPortDefinition, &port) != OMX_ErrorNone) {
fprintf(stderr, "Failed to get decoder port definition\n"); fprintf(stderr, "Failed to get decoder port definition\n");
exit(EXIT_FAILURE); return -2;
} }
// Increase the buffer size to fit the largest possible frame // 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); ilclient_change_component_state(video_decode, OMX_StateExecuting);
} else { } else {
fprintf(stderr, "Can't setup video\n"); fprintf(stderr, "Can't setup video\n");
exit(EXIT_FAILURE); return -2;
} }
return 0;
} }
static void decoder_renderer_cleanup() { static void decoder_renderer_cleanup() {
+7 -4
View File
@@ -32,21 +32,24 @@
static char* ffmpeg_buffer; 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; int avc_flags = SLICE_THREADING;
if (drFlags & FORCE_HARDWARE_ACCELERATION) if (drFlags & FORCE_HARDWARE_ACCELERATION)
avc_flags |= HARDWARE_ACCELERATION; avc_flags |= HARDWARE_ACCELERATION;
if (ffmpeg_init(videoFormat, width, height, avc_flags, SDL_BUFFER_FRAMES, sysconf(_SC_NPROCESSORS_ONLN)) < 0) { if (ffmpeg_init(videoFormat, width, height, avc_flags, SDL_BUFFER_FRAMES, sysconf(_SC_NPROCESSORS_ONLN)) < 0) {
fprintf(stderr, "Couldn't initialize video decoding\n"); fprintf(stderr, "Couldn't initialize video decoding\n");
exit(1); return -1;
} }
ffmpeg_buffer = malloc(DECODER_BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE); ffmpeg_buffer = malloc(DECODER_BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
if (ffmpeg_buffer == NULL) { if (ffmpeg_buffer == NULL) {
fprintf(stderr, "Not enough memory\n"); fprintf(stderr, "Not enough memory\n");
exit(1); ffmpeg_destroy();
return -1;
} }
return 0;
} }
static void sdl_cleanup() { static void sdl_cleanup() {
@@ -92,5 +95,5 @@ DECODER_RENDERER_CALLBACKS decoder_callbacks_sdl = {
.setup = sdl_setup, .setup = sdl_setup,
.cleanup = sdl_cleanup, .cleanup = sdl_cleanup,
.submitDecodeUnit = sdl_submit_decode_unit, .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,
}; };
+8 -5
View File
@@ -34,27 +34,28 @@ static char* ffmpeg_buffer = NULL;
static Display *display; 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; int avc_flags = SLICE_THREADING;
if (drFlags & FORCE_HARDWARE_ACCELERATION) if (drFlags & FORCE_HARDWARE_ACCELERATION)
avc_flags |= HARDWARE_ACCELERATION; avc_flags |= HARDWARE_ACCELERATION;
if (ffmpeg_init(videoFormat, width, height, avc_flags, 2, 2) < 0) { if (ffmpeg_init(videoFormat, width, height, avc_flags, 2, 2) < 0) {
fprintf(stderr, "Couldn't initialize video decoding\n"); fprintf(stderr, "Couldn't initialize video decoding\n");
exit(1); return -1;
} }
ffmpeg_buffer = malloc(DECODER_BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE); ffmpeg_buffer = malloc(DECODER_BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
if (ffmpeg_buffer == NULL) { if (ffmpeg_buffer == NULL) {
fprintf(stderr, "Not enough memory\n"); fprintf(stderr, "Not enough memory\n");
exit(1); ffmpeg_destroy();
return -1;
} }
XInitThreads(); XInitThreads();
display = XOpenDisplay(NULL); display = XOpenDisplay(NULL);
if (!display) { if (!display) {
fprintf(stderr, "Error: failed to open X display.\n"); fprintf(stderr, "Error: failed to open X display.\n");
return; return -2;
} }
Window root = DefaultRootWindow(display); 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); egl_init(display, window, width, height);
x11_input_init(display, window); x11_input_init(display, window);
return 0;
} }
void x11_cleanup() { void x11_cleanup() {
@@ -110,5 +113,5 @@ DECODER_RENDERER_CALLBACKS decoder_callbacks_x11 = {
.setup = x11_setup, .setup = x11_setup,
.cleanup = x11_cleanup, .cleanup = x11_cleanup,
.submitDecodeUnit = x11_submit_decode_unit, .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,
}; };