1
0
mirror of https://github.com/jojo61/vdr-plugin-softhdcuvid.git synced 2023-10-10 13:37:41 +02:00

Enabled -C Option for DRM

This commit is contained in:
jojo61 2019-12-17 12:15:35 +01:00
parent 1274e673ec
commit 67832ac333

70
drm.c
View File

@ -37,6 +37,53 @@ VideoRender *render;
//----------------------------------------------------------------------------
// Helper functions
//----------------------------------------------------------------------------
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#endif
struct type_name {
unsigned int type;
const char *name;
};
static const char *util_lookup_type_name(unsigned int type,
const struct type_name *table,
unsigned int count)
{
unsigned int i;
for (i = 0; i < count; i++)
if (table[i].type == type)
return table[i].name;
return NULL;
}
static const struct type_name connector_type_names[] = {
{ DRM_MODE_CONNECTOR_Unknown, "unknown" },
{ DRM_MODE_CONNECTOR_VGA, "VGA" },
{ DRM_MODE_CONNECTOR_DVII, "DVI-I" },
{ DRM_MODE_CONNECTOR_DVID, "DVI-D" },
{ DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
{ DRM_MODE_CONNECTOR_Composite, "composite" },
{ DRM_MODE_CONNECTOR_SVIDEO, "s-video" },
{ DRM_MODE_CONNECTOR_LVDS, "LVDS" },
{ DRM_MODE_CONNECTOR_Component, "component" },
{ DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" },
{ DRM_MODE_CONNECTOR_DisplayPort, "DP" },
{ DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
{ DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
{ DRM_MODE_CONNECTOR_TV, "TV" },
{ DRM_MODE_CONNECTOR_eDP, "eDP" },
{ DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" },
{ DRM_MODE_CONNECTOR_DSI, "DSI" },
{ DRM_MODE_CONNECTOR_DPI, "DPI" },
};
const char *util_lookup_connector_type_name(unsigned int type)
{
return util_lookup_type_name(type, connector_type_names,
ARRAY_SIZE(connector_type_names));
}
static uint64_t GetPropertyValue(int fd_drm, uint32_t objectID,
uint32_t objectType, const char *propName)
@ -149,6 +196,8 @@ static int FindDevice(VideoRender * render)
uint64_t has_dumb;
uint64_t has_prime;
int i,ii=0;
char connectorstr[10];
int found = 0;
render->fd_drm = open("/dev/dri/card0", O_RDWR);
if (render->fd_drm < 0) {
@ -198,6 +247,11 @@ static int FindDevice(VideoRender * render)
return -errno;
}
sprintf(connectorstr,"%s-%u",util_lookup_connector_type_name(connector->connector_type),connector->connector_type_id);
printf("Connector >%s< is %sconnected\n",connectorstr,connector->connection == DRM_MODE_CONNECTED?"":"not ");
if (DRMConnector && strcmp(DRMConnector,connectorstr))
continue;
if (connector->connection == DRM_MODE_CONNECTED && connector->count_modes > 0) {
render->connector_id = connector->connector_id;
render->mmHeight = connector->mmHeight;
@ -218,7 +272,9 @@ static int FindDevice(VideoRender * render)
// search Modes for Connector
for (ii = 0; ii < connector->count_modes; ii++) {
mode = &connector->modes[ii];
printf("Mode %d %dx%d Rate %d\n",ii,mode->hdisplay,mode->vdisplay,mode->vrefresh);
if (VideoWindowWidth && VideoWindowHeight) { // preset by command line
if (VideoWindowWidth == mode->hdisplay &&
VideoWindowHeight == mode->vdisplay &&
@ -237,13 +293,20 @@ static int FindDevice(VideoRender * render)
}
}
}
found = 1;
i = resources->count_connectors; // uuuuhh
}
VideoWindowWidth = render->mode.hdisplay;
VideoWindowHeight = render->mode.vdisplay;
if (found)
printf("Use Mode %d %dx%d Rate %d\n",ii,render->mode.hdisplay,render->mode.vdisplay,render->mode.vrefresh);
drmModeFreeConnector(connector);
}
if (!found) {
Debug(3,"Requested Connector not found or not connected\n");
printf("Requested Connector not found or not connected\n");
return -1;
}
// find first plane
if ((plane_res = drmModeGetPlaneResources(render->fd_drm)) == NULL)
@ -315,12 +378,12 @@ void VideoInitDrm()
int i;
if (!(render = calloc(1, sizeof(*render)))) {
Error(_("video/DRM: out of memory\n"));
Fatal(_("video/DRM: out of memory\n"));
return;
}
if (FindDevice(render)){
fprintf(stderr, "VideoInit: FindDevice() failed\n");
Fatal(_( "VideoInit: FindDevice() failed\n"));
}
gbm.dev = gbm_create_device (render->fd_drm);
@ -461,6 +524,9 @@ static void drm_swap_buffers () {
static void drm_clean_up () {
// set the previous crtc
if (!render)
return;
drmModeSetCrtc (render->fd_drm, render->saved_crtc->crtc_id, render->saved_crtc->buffer_id,
render->saved_crtc->x, render->saved_crtc->y, &render->connector_id, 1, &render->saved_crtc->mode);
drmModeFreeCrtc (render->saved_crtc);