tight: Add some error handling

pull/30/head
Andri Yngvason 2020-04-02 21:12:09 +00:00
parent 10a3fd6238
commit 1724797a27
1 changed files with 13 additions and 3 deletions

View File

@ -20,6 +20,7 @@
#include "fb.h" #include "fb.h"
#include "tight.h" #include "tight.h"
#include "common.h" #include "common.h"
#include "logging.h"
#include <pixman.h> #include <pixman.h>
#include <turbojpeg.h> #include <turbojpeg.h>
@ -86,11 +87,18 @@ int tight_encode_box(struct vec* dst, struct nvnc_client* client,
vec_append(dst, &rect, sizeof(rect)); vec_append(dst, &rect, sizeof(rect));
tjhandle handle = tjInitCompress(); tjhandle handle = tjInitCompress();
if (!handle)
return -1;
void* img = (uint32_t*)fb->addr + x + y * stride; void* img = (uint32_t*)fb->addr + x + y * stride;
tjCompress2(handle, img, width, stride * 4, height, tjfmt, &buffer, int rc = -1;
rc = tjCompress2(handle, img, width, stride * 4, height, tjfmt, &buffer,
&size, TJSAMP_422, quality, TJFLAG_FASTDCT); &size, TJSAMP_422, quality, TJFLAG_FASTDCT);
if (rc < 0) {
log_error("Failed to encode tight JPEG box: %s\n", tjGetErrorStr());
goto compress_failure;
}
vec_fast_append_8(dst, TIGHT_JPEG); vec_fast_append_8(dst, TIGHT_JPEG);
@ -98,10 +106,12 @@ int tight_encode_box(struct vec* dst, struct nvnc_client* client,
vec_append(dst, buffer, size); vec_append(dst, buffer, size);
rc = 0;
tjFree(buffer); tjFree(buffer);
compress_failure:
tjDestroy(handle); tjDestroy(handle);
return 0; return rc;
} }
int tight_encode_frame(struct vec* dst, struct nvnc_client* client, int tight_encode_frame(struct vec* dst, struct nvnc_client* client,