moonlight-qt/app/streaming/video/ffmpeg-renderers/drm.h

98 lines
2.9 KiB
C
Raw Normal View History

2019-04-21 05:22:37 +00:00
#pragma once
#include "renderer.h"
#include <xf86drm.h>
#include <xf86drmMode.h>
2022-01-29 06:28:46 +00:00
// Newer libdrm headers have these HDR structs, but some older ones don't.
namespace DrmDefs
{
// HDR structs is copied from linux include/linux/hdmi.h
struct hdr_metadata_infoframe
{
uint8_t eotf;
uint8_t metadata_type;
struct
{
uint16_t x, y;
} display_primaries[3];
struct
{
uint16_t x, y;
} white_point;
uint16_t max_display_mastering_luminance;
uint16_t min_display_mastering_luminance;
uint16_t max_cll;
uint16_t max_fall;
};
struct hdr_output_metadata
{
uint32_t metadata_type;
union {
struct hdr_metadata_infoframe hdmi_metadata_type1;
};
};
}
2019-04-21 05:22:37 +00:00
class DrmRenderer : public IFFmpegRenderer {
public:
DrmRenderer(IFFmpegRenderer *backendRenderer = nullptr);
2019-04-21 05:22:37 +00:00
virtual ~DrmRenderer() override;
virtual bool initialize(PDECODER_PARAMETERS params) override;
virtual bool prepareDecoderContext(AVCodecContext* context, AVDictionary** options) override;
2019-04-21 05:22:37 +00:00
virtual void renderFrame(AVFrame* frame) override;
virtual enum AVPixelFormat getPreferredPixelFormat(int videoFormat) override;
virtual bool isPixelFormatSupported(int videoFormat, AVPixelFormat pixelFormat) override;
virtual int getRendererAttributes() override;
virtual bool needsTestFrame() override;
virtual bool testRenderFrame(AVFrame* frame) override;
virtual bool isDirectRenderingSupported() override;
2022-01-29 04:40:07 +00:00
virtual void setHdrMode(bool enabled) override;
#ifdef HAVE_EGL
virtual bool canExportEGL() override;
virtual AVPixelFormat getEGLImagePixelFormat() override;
virtual bool initializeEGL(EGLDisplay dpy, const EGLExtensions &ext) override;
virtual ssize_t exportEGLImages(AVFrame *frame, EGLDisplay dpy, EGLImage images[EGL_MAX_PLANES]) override;
virtual void freeEGLImages(EGLDisplay dpy, EGLImage[EGL_MAX_PLANES]) override;
#endif
2019-04-21 05:22:37 +00:00
private:
2022-01-24 03:03:56 +00:00
const char* getDrmColorEncodingValue(AVFrame* frame);
const char* getDrmColorRangeValue(AVFrame* frame);
IFFmpegRenderer* m_BackendRenderer;
AVBufferRef* m_HwContext;
2019-04-21 05:22:37 +00:00
int m_DrmFd;
bool m_SdlOwnsDrmFd;
bool m_SupportsDirectRendering;
2022-01-28 04:36:49 +00:00
bool m_Main10Hdr;
2022-01-24 03:03:56 +00:00
uint32_t m_ConnectorId;
uint32_t m_EncoderId;
2019-04-21 05:22:37 +00:00
uint32_t m_CrtcId;
uint32_t m_PlaneId;
uint32_t m_CurrentFbId;
2022-01-24 03:03:56 +00:00
AVColorRange m_LastColorRange;
AVColorSpace m_LastColorSpace;
drmModePropertyPtr m_ColorEncodingProp;
drmModePropertyPtr m_ColorRangeProp;
drmModePropertyPtr m_HdrOutputMetadataProp;
2022-01-29 04:40:07 +00:00
uint32_t m_HdrOutputMetadataBlobId;
2019-04-21 05:22:37 +00:00
SDL_Rect m_OutputRect;
#ifdef HAVE_EGL
bool m_EGLExtDmaBuf;
PFNEGLCREATEIMAGEPROC m_eglCreateImage;
PFNEGLDESTROYIMAGEPROC m_eglDestroyImage;
PFNEGLCREATEIMAGEKHRPROC m_eglCreateImageKHR;
PFNEGLDESTROYIMAGEKHRPROC m_eglDestroyImageKHR;
#endif
2019-04-21 05:22:37 +00:00
};