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

reformat missing files

This commit is contained in:
Dirk Nehring 2021-12-29 12:08:12 +01:00
parent 177e44de98
commit 43135c43bc
3 changed files with 469 additions and 402 deletions

View File

@ -393,7 +393,7 @@ clean:
HDRS = $(wildcard *.h)
indent:
for i in $(SRCS) $(HDRS); do \
for i in $(SRCS) drm.c hdr.c $(HDRS); do \
clang-format -i $$i; \
done

200
drm.c
View File

@ -1,9 +1,7 @@
#include <unistd.h>
#include <drm_fourcc.h>
#include <gbm.h>
#include <sys/mman.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
#include <drm_fourcc.h>
#include <unistd.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
@ -13,8 +11,7 @@
// DRM
//----------------------------------------------------------------------------
struct _Drm_Render_
{
struct _Drm_Render_ {
int fd_drm;
drmModeModeInfo mode;
drmModeCrtc *saved_crtc;
@ -24,7 +21,6 @@ struct _Drm_Render_
uint32_t hdr_metadata;
uint32_t mmWidth, mmHeight; // Size in mm
uint32_t hdr_blob_id;
};
typedef struct _Drm_Render_ VideoRender;
@ -46,10 +42,7 @@ struct type_name {
const char *name;
};
static const char *util_lookup_type_name(unsigned int type,
const struct type_name *table,
unsigned int count)
{
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++)
@ -80,21 +73,16 @@ static const struct type_name connector_type_names[] = {
{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));
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)
{
static uint64_t GetPropertyValue(int fd_drm, uint32_t objectID, uint32_t objectType, const char *propName) {
uint32_t i;
int found = 0;
uint64_t value = 0;
drmModePropertyPtr Prop;
drmModeObjectPropertiesPtr objectProps =
drmModeObjectGetProperties(fd_drm, objectID, objectType);
drmModeObjectPropertiesPtr objectProps = drmModeObjectGetProperties(fd_drm, objectID, objectType);
for (i = 0; i < objectProps->count_props; i++) {
if ((Prop = drmModeGetProperty(fd_drm, objectProps->props[i])) == NULL)
@ -115,20 +103,16 @@ static uint64_t GetPropertyValue(int fd_drm, uint32_t objectID,
#ifdef DRM_DEBUG
if (!found)
fprintf(stderr, "GetPropertyValue: Unable to find value for property \'%s\'.\n",
propName);
fprintf(stderr, "GetPropertyValue: Unable to find value for property \'%s\'.\n", propName);
#endif
return value;
}
static uint32_t GetPropertyID(int fd_drm, uint32_t objectID,
uint32_t objectType, const char *propName)
{
static uint32_t GetPropertyID(int fd_drm, uint32_t objectID, uint32_t objectType, const char *propName) {
uint32_t i;
int found = 0;
uint32_t value = -1;
drmModePropertyPtr Prop;
drmModeObjectPropertiesPtr objectProps =
drmModeObjectGetProperties(fd_drm, objectID, objectType);
drmModeObjectPropertiesPtr objectProps = drmModeObjectGetProperties(fd_drm, objectID, objectType);
for (i = 0; i < objectProps->count_props; i++) {
if ((Prop = drmModeGetProperty(fd_drm, objectProps->props[i])) == NULL)
@ -151,15 +135,12 @@ static uint32_t GetPropertyID(int fd_drm, uint32_t objectID,
return value;
}
static int SetPropertyRequest(drmModeAtomicReqPtr ModeReq, int fd_drm,
uint32_t objectID, uint32_t objectType,
const char *propName, uint64_t value)
{
static int SetPropertyRequest(drmModeAtomicReqPtr ModeReq, int fd_drm, uint32_t objectID, uint32_t objectType,
const char *propName, uint64_t value) {
uint32_t i;
uint64_t id = 0;
drmModePropertyPtr Prop;
drmModeObjectPropertiesPtr objectProps =
drmModeObjectGetProperties(fd_drm, objectID, objectType);
drmModeObjectPropertiesPtr objectProps = drmModeObjectGetProperties(fd_drm, objectID, objectType);
for (i = 0; i < objectProps->count_props; i++) {
if ((Prop = drmModeGetProperty(fd_drm, objectProps->props[i])) == NULL)
@ -177,15 +158,13 @@ static int SetPropertyRequest(drmModeAtomicReqPtr ModeReq, int fd_drm,
drmModeFreeObjectProperties(objectProps);
if (id == 0)
printf( "SetPropertyRequest: Unable to find value for property \'%s\'.\n",
propName);
printf("SetPropertyRequest: Unable to find value for property \'%s\'.\n", propName);
return drmModeAtomicAddProperty(ModeReq, objectID, id, value);
}
static void CuvidSetVideoMode(void);
void set_video_mode(int width, int height)
{
void set_video_mode(int width, int height) {
drmModeConnector *connector;
drmModeModeInfo *mode;
int ii;
@ -195,11 +174,8 @@ void set_video_mode(int width, int height)
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 (width == mode->hdisplay &&
height == mode->vdisplay &&
mode->vrefresh == DRMRefresh &&
render->mode.hdisplay != width &&
render->mode.vdisplay != height &&
if (width == mode->hdisplay && height == mode->vdisplay && mode->vrefresh == DRMRefresh &&
render->mode.hdisplay != width && render->mode.vdisplay != height &&
!(mode->flags & DRM_MODE_FLAG_INTERLACE)) {
memcpy(&render->mode, mode, sizeof(drmModeModeInfo));
VideoWindowWidth = mode->hdisplay;
@ -215,8 +191,7 @@ void set_video_mode(int width, int height)
}
}
static int FindDevice(VideoRender * render)
{
static int FindDevice(VideoRender *render) {
drmVersion *version;
drmModeRes *resources;
drmModeConnector *connector;
@ -243,20 +218,17 @@ static int FindDevice(VideoRender * render)
int ret = drmSetMaster(render->fd_drm);
if (ret < 0)
{
if (ret < 0) {
drm_magic_t magic;
ret = drmGetMagic(render->fd_drm, &magic);
if (ret < 0)
{
if (ret < 0) {
Debug(3, "drm:%s - failed to get drm magic: %s\n", __FUNCTION__, strerror(errno));
return -1;
}
ret = drmAuthMagic(render->fd_drm, magic);
if (ret < 0)
{
if (ret < 0) {
Debug(3, "drm:%s - failed to authorize drm magic: %s\n", __FUNCTION__, strerror(errno));
return -1;
}
@ -290,9 +262,8 @@ static int FindDevice(VideoRender * render)
}
#ifdef DEBUG
Debug(3,"[FindDevice] DRM have %i connectors, %i crtcs, %i encoders\n",
resources->count_connectors, resources->count_crtcs,
resources->count_encoders);
Debug(3, "[FindDevice] DRM have %i connectors, %i crtcs, %i encoders\n", resources->count_connectors,
resources->count_crtcs, resources->count_encoders);
#endif
// find all available connectors
@ -303,8 +274,10 @@ 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 ");
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;
@ -325,9 +298,10 @@ static int FindDevice(VideoRender * render)
}
render->crtc_id = encoder->crtc_id;
render->hdr_metadata = GetPropertyID(render->fd_drm, connector->connector_id,
DRM_MODE_OBJECT_CONNECTOR, "HDR_OUTPUT_METADATA");
printf("ID %d of METADATA in Connector %d connected %d\n",render->hdr_metadata,connector->connector_id,connector->connection);
render->hdr_metadata = GetPropertyID(render->fd_drm, connector->connector_id, DRM_MODE_OBJECT_CONNECTOR,
"HDR_OUTPUT_METADATA");
printf("ID %d of METADATA in Connector %d connected %d\n", render->hdr_metadata, connector->connector_id,
connector->connection);
memcpy(&render->mode, &connector->modes[0], sizeof(drmModeModeInfo)); // set fallback
// search Modes for Connector
@ -337,15 +311,12 @@ static int FindDevice(VideoRender * render)
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 &&
mode->vrefresh == DRMRefresh &&
!(mode->flags & DRM_MODE_FLAG_INTERLACE)) {
if (VideoWindowWidth == mode->hdisplay && VideoWindowHeight == mode->vdisplay &&
mode->vrefresh == DRMRefresh && !(mode->flags & DRM_MODE_FLAG_INTERLACE)) {
memcpy(&render->mode, mode, sizeof(drmModeModeInfo));
break;
}
}
else {
} else {
if (!(mode->flags & DRM_MODE_FLAG_INTERLACE)) {
memcpy(&render->mode, mode, sizeof(drmModeModeInfo));
VideoWindowWidth = mode->hdisplay;
@ -360,7 +331,8 @@ static int FindDevice(VideoRender * render)
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);
printf("Use Mode %d %dx%d Rate %d\n", ii, render->mode.hdisplay, render->mode.vdisplay,
render->mode.vrefresh);
drmModeFreeConnector(connector);
}
if (!found) {
@ -384,16 +356,16 @@ static int FindDevice(VideoRender * render)
break;
}
uint64_t type = GetPropertyValue(render->fd_drm, plane_res->planes[j],
DRM_MODE_OBJECT_PLANE, "type");
uint64_t type = GetPropertyValue(render->fd_drm, plane_res->planes[j], DRM_MODE_OBJECT_PLANE, "type");
uint64_t zpos = 0;
#ifdef DRM_DEBUG // If more then 2 crtcs this must rewriten!!!
printf("[FindDevice] Plane id %i crtc_id %i possible_crtcs %i possible CRTC %i type %s\n",
plane->plane_id, plane->crtc_id, plane->possible_crtcs, resources->crtcs[i],
(type == DRM_PLANE_TYPE_PRIMARY) ? "primary plane" :
(type == DRM_PLANE_TYPE_OVERLAY) ? "overlay plane" :
(type == DRM_PLANE_TYPE_CURSOR) ? "cursor plane" : "No plane type");
printf("[FindDevice] Plane id %i crtc_id %i possible_crtcs %i possible CRTC %i type %s\n", plane->plane_id,
plane->crtc_id, plane->possible_crtcs, resources->crtcs[i],
(type == DRM_PLANE_TYPE_PRIMARY) ? "primary plane"
: (type == DRM_PLANE_TYPE_OVERLAY) ? "overlay plane"
: (type == DRM_PLANE_TYPE_CURSOR) ? "cursor plane"
: "No plane type");
#endif
// test pixel format and plane caps
@ -423,8 +395,7 @@ static int FindDevice(VideoRender * render)
drmModeFreeResources(resources);
#ifdef DRM_DEBUG
printf("[FindDevice] DRM setup CRTC: %i video_plane: %i \n",
render->crtc_id, render->video_plane);
printf("[FindDevice] DRM setup CRTC: %i video_plane: %i \n", render->crtc_id, render->video_plane);
#endif
// save actual modesetting
@ -436,8 +407,7 @@ static int FindDevice(VideoRender * render)
///
/// Initialize video output module.
///
void VideoInitDrm()
{
void VideoInitDrm() {
int i;
if (!(render = calloc(1, sizeof(*render)))) {
@ -454,8 +424,7 @@ void VideoInitDrm()
PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display = NULL;
get_platform_display =
(void *) eglGetProcAddress("eglGetPlatformDisplayEXT");
get_platform_display = (void *)eglGetProcAddress("eglGetPlatformDisplayEXT");
assert(get_platform_display != NULL);
eglDisplay = get_platform_display(EGL_PLATFORM_GBM_KHR, gbm.dev, NULL);
@ -478,12 +447,10 @@ void VideoInitDrm()
return;
}
printf("set CRTC %d of Connector %d aktiv\n", render->crtc_id, render->connector_id);
SetPropertyRequest(ModeReq, render->fd_drm, render->crtc_id,
DRM_MODE_OBJECT_CRTC, "MODE_ID", modeID);
SetPropertyRequest(ModeReq, render->fd_drm, render->connector_id,
DRM_MODE_OBJECT_CONNECTOR, "CRTC_ID", render->crtc_id);
SetPropertyRequest(ModeReq, render->fd_drm, render->crtc_id,
DRM_MODE_OBJECT_CRTC, "ACTIVE", 1);
SetPropertyRequest(ModeReq, render->fd_drm, render->crtc_id, DRM_MODE_OBJECT_CRTC, "MODE_ID", modeID);
SetPropertyRequest(ModeReq, render->fd_drm, render->connector_id, DRM_MODE_OBJECT_CONNECTOR, "CRTC_ID",
render->crtc_id);
SetPropertyRequest(ModeReq, render->fd_drm, render->crtc_id, DRM_MODE_OBJECT_CRTC, "ACTIVE", 1);
if (drmModeAtomicCommit(render->fd_drm, ModeReq, flags, NULL) != 0)
fprintf(stderr, "cannot set atomic mode (%d): %m\n", errno);
@ -492,11 +459,9 @@ void VideoInitDrm()
fprintf(stderr, "cannot destroy property blob (%d): %m\n", errno);
drmModeAtomicFree(ModeReq);
}
void get_drm_aspect(int *num,int *den)
{
void get_drm_aspect(int *num, int *den) {
*num = VideoWindowWidth;
*den = VideoWindowHeight;
}
@ -516,7 +481,6 @@ void InitBo(int bpp) {
assert(gbm.surface != NULL);
eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, gbm.surface, NULL);
assert(eglSurface != NULL);
}
static struct gbm_bo *previous_bo = NULL;
@ -537,8 +501,8 @@ static void drm_swap_buffers () {
uint32_t handle = gbm_bo_get_handle(bo).u32;
uint32_t pitch = gbm_bo_get_stride(bo);
drmModeAddFB (render->fd_drm, VideoWindowWidth,VideoWindowHeight,render->bpp==10? 30:24, 32, pitch, handle, &fb);
drmModeAddFB(render->fd_drm, VideoWindowWidth, VideoWindowHeight, render->bpp == 10 ? 30 : 24, 32, pitch, handle,
&fb);
// drmModeSetCrtc (render->fd_drm, render->crtc_id, fb, 0, 0, &render->connector_id, 1, &render->mode);
if (m_need_modeset) {
@ -556,23 +520,19 @@ static void drm_swap_buffers () {
}
// Need to disable the CRTC in order to submit the HDR data....
SetPropertyRequest(ModeReq, render->fd_drm, render->crtc_id,
DRM_MODE_OBJECT_CRTC, "ACTIVE", 0);
SetPropertyRequest(ModeReq, render->fd_drm, render->crtc_id, DRM_MODE_OBJECT_CRTC, "ACTIVE", 0);
if (drmModeAtomicCommit(render->fd_drm, ModeReq, flags, NULL) != 0)
fprintf(stderr, "cannot set atomic mode (%d): %m\n", errno);
SetPropertyRequest(ModeReq, render->fd_drm, render->connector_id,
DRM_MODE_OBJECT_CONNECTOR, "Colorspace",old_color==AVCOL_PRI_BT2020?9:2 );
SetPropertyRequest(ModeReq, render->fd_drm, render->video_plane,
DRM_MODE_OBJECT_PLANE, "COLOR_ENCODING",old_color==AVCOL_PRI_BT2020?2:1 );
SetPropertyRequest(ModeReq, render->fd_drm, render->video_plane,
DRM_MODE_OBJECT_PLANE, "COLOR_RANGE",0 );
SetPropertyRequest(ModeReq, render->fd_drm, render->crtc_id,
DRM_MODE_OBJECT_CRTC, "MODE_ID", modeID);
SetPropertyRequest(ModeReq, render->fd_drm, render->connector_id,
DRM_MODE_OBJECT_CONNECTOR, "CRTC_ID", render->crtc_id);
SetPropertyRequest(ModeReq, render->fd_drm, render->crtc_id,
DRM_MODE_OBJECT_CRTC, "ACTIVE", 1);
SetPropertyRequest(ModeReq, render->fd_drm, render->connector_id, DRM_MODE_OBJECT_CONNECTOR, "Colorspace",
old_color == AVCOL_PRI_BT2020 ? 9 : 2);
SetPropertyRequest(ModeReq, render->fd_drm, render->video_plane, DRM_MODE_OBJECT_PLANE, "COLOR_ENCODING",
old_color == AVCOL_PRI_BT2020 ? 2 : 1);
SetPropertyRequest(ModeReq, render->fd_drm, render->video_plane, DRM_MODE_OBJECT_PLANE, "COLOR_RANGE", 0);
SetPropertyRequest(ModeReq, render->fd_drm, render->crtc_id, DRM_MODE_OBJECT_CRTC, "MODE_ID", modeID);
SetPropertyRequest(ModeReq, render->fd_drm, render->connector_id, DRM_MODE_OBJECT_CONNECTOR, "CRTC_ID",
render->crtc_id);
SetPropertyRequest(ModeReq, render->fd_drm, render->crtc_id, DRM_MODE_OBJECT_CRTC, "ACTIVE", 1);
if (drmModeAtomicCommit(render->fd_drm, ModeReq, flags, NULL) != 0)
fprintf(stderr, "cannot set atomic mode modeset 2 (%d): %m\n", errno);
@ -592,7 +552,6 @@ static void drm_swap_buffers () {
}
previous_bo = bo;
previous_fb = fb;
}
static void drm_clean_up() {
@ -607,8 +566,8 @@ static void drm_clean_up () {
gbm_surface_release_buffer(gbm.surface, previous_bo);
}
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);
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);
if (has_modeset) {
@ -626,25 +585,19 @@ static void drm_clean_up () {
}
// Need to disable the CRTC in order to submit the HDR data....
SetPropertyRequest(ModeReq, render->fd_drm, render->crtc_id,
DRM_MODE_OBJECT_CRTC, "ACTIVE", 0);
SetPropertyRequest(ModeReq, render->fd_drm, render->crtc_id, DRM_MODE_OBJECT_CRTC, "ACTIVE", 0);
if (drmModeAtomicCommit(render->fd_drm, ModeReq, flags, NULL) != 0)
fprintf(stderr, "cannot set atomic mode (%d): %m\n", errno);
SetPropertyRequest(ModeReq, render->fd_drm, render->connector_id,
DRM_MODE_OBJECT_CONNECTOR, "HDR_OUTPUT_METADATA", 0);
SetPropertyRequest(ModeReq, render->fd_drm, render->connector_id,
DRM_MODE_OBJECT_CONNECTOR, "Colorspace",2 );
SetPropertyRequest(ModeReq, render->fd_drm, render->video_plane,
DRM_MODE_OBJECT_PLANE, "COLOR_ENCODING",1 );
SetPropertyRequest(ModeReq, render->fd_drm, render->video_plane,
DRM_MODE_OBJECT_PLANE, "COLOR_RANGE",1 );
SetPropertyRequest(ModeReq, render->fd_drm, render->crtc_id,
DRM_MODE_OBJECT_CRTC, "MODE_ID", modeID);
SetPropertyRequest(ModeReq, render->fd_drm, render->connector_id,
DRM_MODE_OBJECT_CONNECTOR, "CRTC_ID", render->crtc_id);
SetPropertyRequest(ModeReq, render->fd_drm, render->crtc_id,
DRM_MODE_OBJECT_CRTC, "ACTIVE", 1);
SetPropertyRequest(ModeReq, render->fd_drm, render->connector_id, DRM_MODE_OBJECT_CONNECTOR,
"HDR_OUTPUT_METADATA", 0);
SetPropertyRequest(ModeReq, render->fd_drm, render->connector_id, DRM_MODE_OBJECT_CONNECTOR, "Colorspace", 2);
SetPropertyRequest(ModeReq, render->fd_drm, render->video_plane, DRM_MODE_OBJECT_PLANE, "COLOR_ENCODING", 1);
SetPropertyRequest(ModeReq, render->fd_drm, render->video_plane, DRM_MODE_OBJECT_PLANE, "COLOR_RANGE", 1);
SetPropertyRequest(ModeReq, render->fd_drm, render->crtc_id, DRM_MODE_OBJECT_CRTC, "MODE_ID", modeID);
SetPropertyRequest(ModeReq, render->fd_drm, render->connector_id, DRM_MODE_OBJECT_CONNECTOR, "CRTC_ID",
render->crtc_id);
SetPropertyRequest(ModeReq, render->fd_drm, render->crtc_id, DRM_MODE_OBJECT_CRTC, "ACTIVE", 1);
if (drmModeAtomicCommit(render->fd_drm, ModeReq, flags, NULL) != 0)
fprintf(stderr, "cannot set atomic mode (%d): %m\n", errno);
@ -677,5 +630,4 @@ static void drm_clean_up () {
close(render->fd_drm);
eglDisplay = NULL;
free(render);
}

367
hdr.c
View File

@ -87,7 +87,6 @@ struct hdr_output_metadata {
};
#endif
enum hdr_metadata_eotf {
EOTF_TRADITIONAL_GAMMA_SDR,
EOTF_TRADITIONAL_GAMMA_HDR,
@ -95,27 +94,15 @@ enum hdr_metadata_eotf {
EOTF_HLG,
};
enum metadata_id {
METADATA_TYPE1,
};
void
weston_hdr_metadata(void *data,
uint16_t display_primary_r_x,
uint16_t display_primary_r_y,
uint16_t display_primary_g_x,
uint16_t display_primary_g_y,
uint16_t display_primary_b_x,
uint16_t display_primary_b_y,
uint16_t white_point_x,
uint16_t white_point_y,
uint16_t min_luminance,
uint16_t max_luminance,
uint16_t max_cll,
uint16_t max_fall,
enum hdr_metadata_eotf eotf)
{
void weston_hdr_metadata(void *data, uint16_t display_primary_r_x, uint16_t display_primary_r_y,
uint16_t display_primary_g_x, uint16_t display_primary_g_y, uint16_t display_primary_b_x,
uint16_t display_primary_b_y, uint16_t white_point_x, uint16_t white_point_y,
uint16_t min_luminance, uint16_t max_luminance, uint16_t max_cll, uint16_t max_fall,
enum hdr_metadata_eotf eotf) {
uint8_t *data8;
uint16_t *data16;
@ -155,151 +142,302 @@ struct weston_colorspace {
struct weston_colorspace hdr10;
static const struct weston_colorspace bt470m = {
.r = {{ 0.670f, 0.330f, }},
.g = {{ 0.210f, 0.710f, }},
.b = {{ 0.140f, 0.080f, }},
.whitepoint = {{ 0.3101f, 0.3162f, }},
.r = {{
0.670f,
0.330f,
}},
.g = {{
0.210f,
0.710f,
}},
.b = {{
0.140f,
0.080f,
}},
.whitepoint = {{
0.3101f,
0.3162f,
}},
.name = "BT.470 M",
.whitepoint_name = "C",
};
static const struct weston_colorspace bt470bg = {
.r = {{ 0.640f, 0.330f, }},
.g = {{ 0.290f, 0.600f, }},
.b = {{ 0.150f, 0.060f, }},
.whitepoint = {{ 0.3127f, 0.3290f, }},
.r = {{
0.640f,
0.330f,
}},
.g = {{
0.290f,
0.600f,
}},
.b = {{
0.150f,
0.060f,
}},
.whitepoint = {{
0.3127f,
0.3290f,
}},
.name = "BT.470 B/G",
.whitepoint_name = "D65",
};
static const struct weston_colorspace smpte170m = {
.r = {{ 0.630f, 0.340f, }},
.g = {{ 0.310f, 0.595f, }},
.b = {{ 0.155f, 0.070f, }},
.whitepoint = {{ 0.3127f, 0.3290f, }},
.r = {{
0.630f,
0.340f,
}},
.g = {{
0.310f,
0.595f,
}},
.b = {{
0.155f,
0.070f,
}},
.whitepoint = {{
0.3127f,
0.3290f,
}},
.name = "SMPTE 170M",
.whitepoint_name = "D65",
};
static const struct weston_colorspace smpte240m = {
.r = {{ 0.630f, 0.340f, }},
.g = {{ 0.310f, 0.595f, }},
.b = {{ 0.155f, 0.070f, }},
.whitepoint = {{ 0.3127f, 0.3290f, }},
.r = {{
0.630f,
0.340f,
}},
.g = {{
0.310f,
0.595f,
}},
.b = {{
0.155f,
0.070f,
}},
.whitepoint = {{
0.3127f,
0.3290f,
}},
.name = "SMPTE 240M",
.whitepoint_name = "D65",
};
static const struct weston_colorspace bt709 = {
.r = {{ 0.640f, 0.330f, }},
.g = {{ 0.300f, 0.600f, }},
.b = {{ 0.150f, 0.060f, }},
.whitepoint = {{ 0.3127f, 0.3290f, }},
.r = {{
0.640f,
0.330f,
}},
.g = {{
0.300f,
0.600f,
}},
.b = {{
0.150f,
0.060f,
}},
.whitepoint = {{
0.3127f,
0.3290f,
}},
.name = "BT.709",
.whitepoint_name = "D65",
};
static const struct weston_colorspace bt2020 = {
.r = {{ 0.708f, 0.292f, }},
.g = {{ 0.170f, 0.797f, }},
.b = {{ 0.131f, 0.046f, }},
.whitepoint = {{ 0.3127f, 0.3290f, }},
.r = {{
0.708f,
0.292f,
}},
.g = {{
0.170f,
0.797f,
}},
.b = {{
0.131f,
0.046f,
}},
.whitepoint = {{
0.3127f,
0.3290f,
}},
.name = "BT.2020",
.whitepoint_name = "D65",
};
static const struct weston_colorspace srgb = {
.r = {{ 0.640f, 0.330f, }},
.g = {{ 0.300f, 0.600f, }},
.b = {{ 0.150f, 0.060f, }},
.whitepoint = {{ 0.3127f, 0.3290f, }},
.r = {{
0.640f,
0.330f,
}},
.g = {{
0.300f,
0.600f,
}},
.b = {{
0.150f,
0.060f,
}},
.whitepoint = {{
0.3127f,
0.3290f,
}},
.name = "sRGB",
.whitepoint_name = "D65",
};
static const struct weston_colorspace adobergb = {
.r = {{ 0.640f, 0.330f, }},
.g = {{ 0.210f, 0.710f, }},
.b = {{ 0.150f, 0.060f, }},
.whitepoint = {{ 0.3127f, 0.3290f, }},
.r = {{
0.640f,
0.330f,
}},
.g = {{
0.210f,
0.710f,
}},
.b = {{
0.150f,
0.060f,
}},
.whitepoint = {{
0.3127f,
0.3290f,
}},
.name = "AdobeRGB",
.whitepoint_name = "D65",
};
static const struct weston_colorspace dci_p3 = {
.r = {{ 0.680f, 0.320f, }},
.g = {{ 0.265f, 0.690f, }},
.b = {{ 0.150f, 0.060f, }},
.whitepoint = {{ 0.3127f, 0.3290f, }},
.r = {{
0.680f,
0.320f,
}},
.g = {{
0.265f,
0.690f,
}},
.b = {{
0.150f,
0.060f,
}},
.whitepoint = {{
0.3127f,
0.3290f,
}},
.name = "DCI-P3 D65",
.whitepoint_name = "D65",
};
static const struct weston_colorspace prophotorgb = {
.r = {{ 0.7347f, 0.2653f, }},
.g = {{ 0.1596f, 0.8404f, }},
.b = {{ 0.0366f, 0.0001f, }},
.r = {{
0.7347f,
0.2653f,
}},
.g = {{
0.1596f,
0.8404f,
}},
.b = {{
0.0366f,
0.0001f,
}},
.whitepoint = {{.3457, .3585}},
.name = "ProPhoto RGB",
.whitepoint_name = "D50",
};
static const struct weston_colorspace ciergb = {
.r = {{ 0.7347f, 0.2653f, }},
.g = {{ 0.2738f, 0.7174f, }},
.b = {{ 0.1666f, 0.0089f, }},
.whitepoint = {{ 1.0f / 3.0f, 1.0f / 3.0f, }},
.r = {{
0.7347f,
0.2653f,
}},
.g = {{
0.2738f,
0.7174f,
}},
.b = {{
0.1666f,
0.0089f,
}},
.whitepoint = {{
1.0f / 3.0f,
1.0f / 3.0f,
}},
.name = "CIE RGB",
.whitepoint_name = "E",
};
static const struct weston_colorspace ciexyz = {
.r = {{ 1.0f, 0.0f, }},
.g = {{ 0.0f, 1.0f, }},
.b = {{ 0.0f, 0.0f, }},
.whitepoint = {{ 1.0f / 3.0f, 1.0f / 3.0f, }},
.r = {{
1.0f,
0.0f,
}},
.g = {{
0.0f,
1.0f,
}},
.b = {{
0.0f,
0.0f,
}},
.whitepoint = {{
1.0f / 3.0f,
1.0f / 3.0f,
}},
.name = "CIE XYZ",
.whitepoint_name = "E",
};
const struct weston_colorspace ap0 = {
.r = {{ 0.7347f, 0.2653f, }},
.g = {{ 0.0000f, 1.0000f, }},
.b = {{ 0.0001f, -0.0770f, }},
.whitepoint = {{ .32168f, .33767f, }},
.r = {{
0.7347f,
0.2653f,
}},
.g = {{
0.0000f,
1.0000f,
}},
.b = {{
0.0001f,
-0.0770f,
}},
.whitepoint = {{
.32168f,
.33767f,
}},
.name = "ACES primaries #0",
.whitepoint_name = "D60",
};
const struct weston_colorspace ap1 = {
.r = {{ 0.713f, 0.393f, }},
.g = {{ 0.165f, 0.830f, }},
.b = {{ 0.128f, 0.044f, }},
.whitepoint = {{ 0.32168f, 0.33767f, }},
.r = {{
0.713f,
0.393f,
}},
.g = {{
0.165f,
0.830f,
}},
.b = {{
0.128f,
0.044f,
}},
.whitepoint = {{
0.32168f,
0.33767f,
}},
.name = "ACES primaries #1",
.whitepoint_name = "D60",
};
static const struct weston_colorspace *const colorspaces[] = {
&bt470m,
&bt470bg,
&smpte170m,
&smpte240m,
&bt709,
&bt2020,
&srgb,
&adobergb,
&dci_p3,
&prophotorgb,
&ciergb,
&ciexyz,
&ap0,
&ap1,
&bt470m, &bt470bg, &smpte170m, &smpte240m, &bt709, &bt2020, &srgb,
&adobergb, &dci_p3, &prophotorgb, &ciergb, &ciexyz, &ap0, &ap1,
};
#define ARRAY_LENGTH(a) (sizeof(a) / sizeof(a)[0])
const struct weston_colorspace *
weston_colorspace_lookup(const char *name)
{
const struct weston_colorspace *weston_colorspace_lookup(const char *name) {
unsigned i;
if (!name)
@ -317,15 +455,10 @@ weston_colorspace_lookup(const char *name)
static int cleanup = 0;
static uint16_t encode_xyy(float xyy)
{
return xyy * 50000;
}
static uint16_t encode_xyy(float xyy) { return xyy * 50000; }
static AVMasteringDisplayMetadata md_save = {0};
static AVContentLightMetadata ld_save = {0};
static void set_hdr_metadata(int color,int trc, AVFrameSideData *sd1, AVFrameSideData *sd2)
{
static void set_hdr_metadata(int color, int trc, AVFrameSideData *sd1, AVFrameSideData *sd2) {
drmModeAtomicReqPtr ModeReq;
struct weston_colorspace *cs;
enum hdr_metadata_eotf eotf;
@ -335,13 +468,10 @@ static void set_hdr_metadata(int color,int trc, AVFrameSideData *sd1, AVFrameSid
struct AVMasteringDisplayMetadata *md = NULL;
struct AVContentLightMetadata *ld = NULL;
// clean up FFMEPG stuff
if (trc == AVCOL_TRC_BT2020_10)
trc = AVCOL_TRC_ARIB_STD_B67;
if ((old_color == color && old_trc == trc && !sd1 && !sd2) || !render->hdr_metadata)
return; // nothing to do
@ -354,8 +484,7 @@ static void set_hdr_metadata(int color,int trc, AVFrameSideData *sd1, AVFrameSid
if (md && !memcmp(md, &md_save, sizeof(md_save)))
if (ld && !memcmp(ld, &ld_save, sizeof(ld_save))) {
return;
}
else if (ld && !memcmp(ld,&ld_save,sizeof(ld_save))) {
} else if (ld && !memcmp(ld, &ld_save, sizeof(ld_save))) {
return;
}
@ -369,7 +498,6 @@ static void set_hdr_metadata(int color,int trc, AVFrameSideData *sd1, AVFrameSid
old_color = color;
old_trc = trc;
if (VulkanTargetColorSpace != 3) { // no HDR TV
m_need_modeset = 1; // change in colorsettings
return;
@ -414,17 +542,14 @@ static void set_hdr_metadata(int color,int trc, AVFrameSideData *sd1, AVFrameSid
if (md) { // we got Metadata
if (md->has_primaries) {
Debug(3,"Mastering Display Metadata,\n has_primaries:%d has_luminance:%d \n"
Debug(3,
"Mastering Display Metadata,\n has_primaries:%d has_luminance:%d \n"
"r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f) \n"
"min_luminance=%f, max_luminance=%f\n",
md->has_primaries, md->has_luminance,
av_q2d(md->display_primaries[0][0]),
av_q2d(md->display_primaries[0][1]),
av_q2d(md->display_primaries[1][0]),
av_q2d(md->display_primaries[1][1]),
av_q2d(md->display_primaries[2][0]),
av_q2d(md->display_primaries[2][1]),
av_q2d(md->white_point[0]), av_q2d(md->white_point[1]),
md->has_primaries, md->has_luminance, av_q2d(md->display_primaries[0][0]),
av_q2d(md->display_primaries[0][1]), av_q2d(md->display_primaries[1][0]),
av_q2d(md->display_primaries[1][1]), av_q2d(md->display_primaries[2][0]),
av_q2d(md->display_primaries[2][1]), av_q2d(md->white_point[0]), av_q2d(md->white_point[1]),
av_q2d(md->min_luminance), av_q2d(md->max_luminance));
cs = &hdr10;
@ -449,23 +574,15 @@ static void set_hdr_metadata(int color,int trc, AVFrameSideData *sd1, AVFrameSid
MaxFALL = ld->MaxFALL;
}
data.metadata_type = 7; // ????????????????????????
weston_hdr_metadata(&data.hdmi_metadata_type1,
encode_xyy(cs->r.f[0]),
encode_xyy(cs->r.f[1]),
encode_xyy(cs->g.f[0]),
encode_xyy(cs->g.f[1]),
encode_xyy(cs->b.f[0]),
encode_xyy(cs->b.f[1]),
encode_xyy(cs->whitepoint.f[0]),
encode_xyy(cs->whitepoint.f[1]),
weston_hdr_metadata(&data.hdmi_metadata_type1, encode_xyy(cs->r.f[0]), encode_xyy(cs->r.f[1]),
encode_xyy(cs->g.f[0]), encode_xyy(cs->g.f[1]), encode_xyy(cs->b.f[0]), encode_xyy(cs->b.f[1]),
encode_xyy(cs->whitepoint.f[0]), encode_xyy(cs->whitepoint.f[1]),
max_lum, // max_display_mastering_luminance
min_lum, // min_display_mastering_luminance
MaxCLL, // Maximum Content Light Level (MaxCLL)
MaxFALL, // Maximum Frame-Average Light Level (MaxFALL)
eotf);
ret = drmModeCreatePropertyBlob(render->fd_drm, &data, sizeof(data), &render->hdr_blob_id);
if (ret) {
printf("DRM: HDR metadata: failed blob create \n");
@ -473,8 +590,7 @@ static void set_hdr_metadata(int color,int trc, AVFrameSideData *sd1, AVFrameSid
return;
}
ret = drmModeConnectorSetProperty(render->fd_drm, render->connector_id,
render->hdr_metadata, render->hdr_blob_id);
ret = drmModeConnectorSetProperty(render->fd_drm, render->connector_id, render->hdr_metadata, render->hdr_blob_id);
if (ret) {
printf("DRM: HDR metadata: failed property set %d\n", ret);
@ -487,5 +603,4 @@ static void set_hdr_metadata(int color,int trc, AVFrameSideData *sd1, AVFrameSid
m_need_modeset = 1;
Debug(3, "DRM: HDR metadata: prop set\n");
}