From bac5360494775545091c566880d2200aad81d8f7 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Mon, 19 Feb 2024 20:56:55 -0600 Subject: [PATCH] Provide better errors when RK renderer fails --- src/video/rk.c | 66 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 14 deletions(-) diff --git a/src/video/rk.c b/src/video/rk.c index 2e04a9f..94ffc1c 100644 --- a/src/video/rk.c +++ b/src/video/rk.c @@ -175,12 +175,17 @@ void *display_thread(void *param) { // We may need to modeset to apply colorspace changes when toggling HDR set_property(plane_id, DRM_MODE_OBJECT_PLANE, plane_props, "FB_ID", _fb_id); ret = drmModeAtomicCommit(fd, drm_request, DRM_MODE_ATOMIC_ALLOW_MODESET, NULL); + if (ret) { + perror("drmModeAtomicCommit"); + } } else { ret = drmModeSetPlane(fd, plane_id, crtc_id, _fb_id, 0, fb_x, fb_y, fb_width, fb_height, 0, 0, frm_width << 16, frm_height << 16); + if (ret) { + perror("drmModeSetPlane"); + } } - assert(!ret); } return NULL; @@ -244,7 +249,10 @@ void *frame_thread(void *param) { dmcd.width = hor_stride; dmcd.height = ver_stride * 2; // documentation say not v*2/3 but v*2 (additional info included) ret = drmIoctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &dmcd); - assert(!ret); + if (ret) { + perror("drmIoctl(DRM_IOCTL_MODE_CREATE_DUMB)"); + exit(EXIT_FAILURE); + } assert(dmcd.pitch == dmcd.width); assert(dmcd.size == dmcd.pitch * dmcd.height); frame_to_drm[i].handle = dmcd.handle; @@ -254,7 +262,10 @@ void *frame_thread(void *param) { dph.handle = dmcd.handle; dph.fd = -1; ret = drmIoctl(fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &dph); - assert(!ret); + if (ret) { + perror("drmIoctl(DRM_IOCTL_PRIME_HANDLE_TO_FD)"); + exit(EXIT_FAILURE); + } MppBufferInfo info = {0}; info.type = MPP_BUFFER_TYPE_DRM; info.size = dmcd.width * dmcd.height; @@ -272,7 +283,10 @@ void *frame_thread(void *param) { offsets[1] = pitches[0] * ver_stride; pitches[1] = dmcd.pitch; ret = drmModeAddFB2(fd, frm_width, frm_height, pixel_format, handles, pitches, offsets, &frame_to_drm[i].fb_id, 0); - assert(!ret); + if (ret) { + perror("drmModeAddFB2"); + exit(EXIT_FAILURE); + } } // register external frame group ret = mpi_api->control(mpi_ctx, MPP_DEC_SET_EXT_BUF_GROUP, mpi_frm_grp); @@ -369,7 +383,10 @@ int rk_setup(int videoFormat, int width, int height, int redrawRate, void* conte } resources = drmModeGetResources(fd); - assert(resources); + if (!resources) { + perror("drmModeGetResources"); + return -1; + } // find active monitor for (i = 0; i < resources->count_connectors; ++i) { @@ -417,7 +434,10 @@ int rk_setup(int videoFormat, int width, int height, int redrawRate, void* conte for (i = 0; i < resources->count_crtcs; ++i) { if (resources->crtcs[i] == encoder->crtc_id) { crtc = drmModeGetCrtc(fd, resources->crtcs[i]); - assert(crtc); + if (!crtc) { + perror("drmModeGetCrtc"); + continue; + } break; } } @@ -428,15 +448,25 @@ int rk_setup(int videoFormat, int width, int height, int redrawRate, void* conte uint32_t crtc_bit = (1 << i); ret = drmSetClientCap(fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1); - assert(!ret); + if (ret) { + perror("drmSetClientCap(DRM_CLIENT_CAP_UNIVERSAL_PLANES)"); + } if (atomic) { ret = drmSetClientCap(fd, DRM_CLIENT_CAP_ATOMIC, 1); - assert(!ret); - drm_request = drmModeAtomicAlloc(); - assert(drm_request); + if (ret) { + perror("drmSetClientCap(DRM_CLIENT_CAP_ATOMIC)"); + atomic = false; + } + else { + drm_request = drmModeAtomicAlloc(); + assert(drm_request); + } } plane_resources = drmModeGetPlaneResources(fd); - assert(plane_resources); + if (!plane_resources) { + perror("drmModeGetPlaneResources"); + return -1; + } // search for OVERLAY (for active connector, unused, NV12 support) for (i = 0; i < plane_resources->count_planes; i++) { @@ -492,7 +522,11 @@ int rk_setup(int videoFormat, int width, int height, int redrawRate, void* conte } drmModeFreePlane(ovr); } - assert(plane_id); + + if (!plane_id) { + fprintf(stderr, "Unable to find suitable plane\n"); + return -1; + } // DRM defines rotation in degrees counter-clockwise while we define // rotation in degrees clockwise, so we swap the 90 and 270 cases @@ -578,11 +612,15 @@ void rk_cleanup() { mpi_frm_grp = NULL; for (i = 0; i < MAX_FRAMES; i++) { ret = drmModeRmFB(fd, frame_to_drm[i].fb_id); - assert(!ret); + if (ret) { + perror("drmModeRmFB"); + } struct drm_mode_destroy_dumb dmdd = {0}; dmdd.handle = frame_to_drm[i].handle; ret = drmIoctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &dmdd); - assert(!ret); + if (ret) { + perror("drmIoctl(DRM_IOCTL_MODE_DESTROY_DUMB)"); + } } }