2018-07-13 09:28:10 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <SDL.h>
|
|
|
|
|
2019-04-12 05:27:20 +00:00
|
|
|
#include "streaming/video/decoder.h"
|
2019-02-13 02:43:38 +00:00
|
|
|
#include "streaming/video/overlaymanager.h"
|
|
|
|
|
2018-07-13 09:28:10 +00:00
|
|
|
extern "C" {
|
|
|
|
#include <libavcodec/avcodec.h>
|
2022-01-29 23:14:18 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_DRM
|
|
|
|
#include <libavutil/hwcontext_drm.h>
|
|
|
|
#endif
|
2018-07-13 09:28:10 +00:00
|
|
|
}
|
|
|
|
|
2021-01-31 23:01:11 +00:00
|
|
|
#ifdef HAVE_EGL
|
2021-02-01 00:41:53 +00:00
|
|
|
#define MESA_EGL_NO_X11_HEADERS
|
2021-01-31 23:01:11 +00:00
|
|
|
#define EGL_NO_X11
|
|
|
|
#include <SDL_egl.h>
|
|
|
|
|
|
|
|
#ifndef EGL_VERSION_1_5
|
|
|
|
typedef intptr_t EGLAttrib;
|
2020-04-13 08:40:28 +00:00
|
|
|
typedef void *EGLImage;
|
2022-04-22 02:13:39 +00:00
|
|
|
typedef khronos_utime_nanoseconds_t EGLTime;
|
2022-04-09 00:28:22 +00:00
|
|
|
|
|
|
|
typedef void *EGLSync;
|
|
|
|
#define EGL_NO_SYNC ((EGLSync)0)
|
|
|
|
#define EGL_SYNC_FENCE 0x30F9
|
|
|
|
#define EGL_FOREVER 0xFFFFFFFFFFFFFFFFull
|
|
|
|
#define EGL_SYNC_FLUSH_COMMANDS_BIT 0x0001
|
2021-02-01 03:42:56 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(EGL_VERSION_1_5) || !defined(EGL_EGL_PROTOTYPES)
|
2022-04-09 00:28:22 +00:00
|
|
|
typedef EGLSync (EGLAPIENTRYP PFNEGLCREATESYNCPROC) (EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list);
|
|
|
|
typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSYNCPROC) (EGLDisplay dpy, EGLSync sync);
|
|
|
|
typedef EGLint (EGLAPIENTRYP PFNEGLCLIENTWAITSYNCPROC) (EGLDisplay dpy, EGLSync sync, EGLint flags, EGLTime timeout);
|
|
|
|
|
2021-01-31 23:01:11 +00:00
|
|
|
typedef EGLImage (EGLAPIENTRYP PFNEGLCREATEIMAGEPROC) (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLAttrib *attrib_list);
|
|
|
|
typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYIMAGEPROC) (EGLDisplay dpy, EGLImage image);
|
2021-02-01 03:42:56 +00:00
|
|
|
typedef EGLDisplay (EGLAPIENTRYP PFNEGLGETPLATFORMDISPLAYPROC) (EGLenum platform, void *native_display, const EGLAttrib *attrib_list);
|
2021-01-31 23:01:11 +00:00
|
|
|
#endif
|
|
|
|
|
2021-02-01 03:42:56 +00:00
|
|
|
#if !defined(EGL_KHR_image) || !defined(EGL_EGLEXT_PROTOTYPES)
|
2021-01-31 23:01:11 +00:00
|
|
|
// EGL_KHR_image technically uses EGLImageKHR instead of EGLImage, but they're compatible
|
|
|
|
// so we swap them here to avoid mixing them all over the place
|
|
|
|
typedef EGLImage (EGLAPIENTRYP PFNEGLCREATEIMAGEKHRPROC) (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list);
|
|
|
|
typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYIMAGEKHRPROC) (EGLDisplay dpy, EGLImage image);
|
|
|
|
#endif
|
|
|
|
|
2021-02-01 03:42:56 +00:00
|
|
|
#if !defined(EGL_EXT_platform_base) || !defined(EGL_EGLEXT_PROTOTYPES)
|
|
|
|
typedef EGLDisplay (EGLAPIENTRYP PFNEGLGETPLATFORMDISPLAYEXTPROC) (EGLenum platform, void *native_display, const EGLint *attrib_list);
|
|
|
|
#endif
|
|
|
|
|
2022-04-09 00:28:22 +00:00
|
|
|
#if !defined(EGL_KHR_fence_sync) || !defined(EGL_EGLEXT_PROTOTYPES)
|
|
|
|
typedef EGLSyncKHR (EGLAPIENTRYP PFNEGLCREATESYNCKHRPROC) (EGLDisplay dpy, EGLenum type, const EGLint *attrib_list);
|
|
|
|
#endif
|
|
|
|
|
2021-01-31 23:01:11 +00:00
|
|
|
#ifndef EGL_EXT_image_dma_buf_import
|
|
|
|
#define EGL_LINUX_DMA_BUF_EXT 0x3270
|
|
|
|
#define EGL_LINUX_DRM_FOURCC_EXT 0x3271
|
|
|
|
#define EGL_DMA_BUF_PLANE0_FD_EXT 0x3272
|
|
|
|
#define EGL_DMA_BUF_PLANE0_OFFSET_EXT 0x3273
|
|
|
|
#define EGL_DMA_BUF_PLANE0_PITCH_EXT 0x3274
|
2021-03-22 04:59:08 +00:00
|
|
|
#define EGL_DMA_BUF_PLANE1_FD_EXT 0x3275
|
|
|
|
#define EGL_DMA_BUF_PLANE1_OFFSET_EXT 0x3276
|
|
|
|
#define EGL_DMA_BUF_PLANE1_PITCH_EXT 0x3277
|
2021-03-22 05:01:54 +00:00
|
|
|
#define EGL_DMA_BUF_PLANE2_FD_EXT 0x3278
|
|
|
|
#define EGL_DMA_BUF_PLANE2_OFFSET_EXT 0x3279
|
|
|
|
#define EGL_DMA_BUF_PLANE2_PITCH_EXT 0x327A
|
2021-11-19 07:15:33 +00:00
|
|
|
#define EGL_YUV_COLOR_SPACE_HINT_EXT 0x327B
|
|
|
|
#define EGL_SAMPLE_RANGE_HINT_EXT 0x327C
|
|
|
|
#define EGL_YUV_CHROMA_HORIZONTAL_SITING_HINT_EXT 0x327D
|
|
|
|
#define EGL_YUV_CHROMA_VERTICAL_SITING_HINT_EXT 0x327E
|
|
|
|
#define EGL_ITU_REC601_EXT 0x327F
|
|
|
|
#define EGL_ITU_REC709_EXT 0x3280
|
|
|
|
#define EGL_ITU_REC2020_EXT 0x3281
|
|
|
|
#define EGL_YUV_FULL_RANGE_EXT 0x3282
|
|
|
|
#define EGL_YUV_NARROW_RANGE_EXT 0x3283
|
|
|
|
#define EGL_YUV_CHROMA_SITING_0_EXT 0x3284
|
|
|
|
#define EGL_YUV_CHROMA_SITING_0_5_EXT 0x3285
|
2021-01-31 23:01:11 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef EGL_EXT_image_dma_buf_import_modifiers
|
2021-03-22 05:46:04 +00:00
|
|
|
#define EGL_DMA_BUF_PLANE3_FD_EXT 0x3440
|
|
|
|
#define EGL_DMA_BUF_PLANE3_OFFSET_EXT 0x3441
|
|
|
|
#define EGL_DMA_BUF_PLANE3_PITCH_EXT 0x3442
|
2021-01-31 23:01:11 +00:00
|
|
|
#define EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT 0x3443
|
|
|
|
#define EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT 0x3444
|
2021-03-22 04:59:08 +00:00
|
|
|
#define EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT 0x3445
|
|
|
|
#define EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT 0x3446
|
|
|
|
#define EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT 0x3447
|
|
|
|
#define EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT 0x3448
|
2021-03-22 05:46:04 +00:00
|
|
|
#define EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT 0x3449
|
|
|
|
#define EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT 0x344A
|
2021-01-31 23:01:11 +00:00
|
|
|
#endif
|
|
|
|
|
2020-04-13 08:40:28 +00:00
|
|
|
#define EGL_MAX_PLANES 4
|
|
|
|
|
|
|
|
class EGLExtensions {
|
|
|
|
public:
|
|
|
|
EGLExtensions(EGLDisplay dpy);
|
|
|
|
~EGLExtensions() {}
|
|
|
|
bool isSupported(const QString &extension) const;
|
|
|
|
private:
|
|
|
|
const QStringList m_Extensions;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2020-02-09 19:35:05 +00:00
|
|
|
#define RENDERER_ATTRIBUTE_FULLSCREEN_ONLY 0x01
|
2020-02-23 08:43:43 +00:00
|
|
|
#define RENDERER_ATTRIBUTE_1080P_MAX 0x02
|
2022-01-29 06:59:04 +00:00
|
|
|
#define RENDERER_ATTRIBUTE_HDR_SUPPORT 0x04
|
2022-04-24 22:43:35 +00:00
|
|
|
#define RENDERER_ATTRIBUTE_NO_BUFFERING 0x08
|
|
|
|
#define RENDERER_ATTRIBUTE_FORCE_PACING 0x10
|
2020-02-09 19:35:05 +00:00
|
|
|
|
2019-02-13 02:43:38 +00:00
|
|
|
class IFFmpegRenderer : public Overlay::IOverlayRenderer {
|
2018-07-13 09:28:10 +00:00
|
|
|
public:
|
2019-04-12 05:27:20 +00:00
|
|
|
virtual bool initialize(PDECODER_PARAMETERS params) = 0;
|
2020-02-09 01:47:26 +00:00
|
|
|
virtual bool prepareDecoderContext(AVCodecContext* context, AVDictionary** options) = 0;
|
2019-02-16 03:31:01 +00:00
|
|
|
virtual void renderFrame(AVFrame* frame) = 0;
|
2019-04-13 05:12:53 +00:00
|
|
|
|
2022-04-08 02:46:48 +00:00
|
|
|
// Called for threaded renderers to allow them to wait prior to us latching
|
|
|
|
// the next frame for rendering (as opposed to waiting on buffer swap with
|
|
|
|
// an older frame already queued for display).
|
|
|
|
virtual void waitToRender() {
|
|
|
|
// Don't wait by default
|
|
|
|
}
|
|
|
|
|
2022-04-08 02:30:20 +00:00
|
|
|
// Called on the same thread as renderFrame() during destruction of the renderer
|
|
|
|
virtual void cleanupRenderContext() {
|
|
|
|
// Nothing
|
|
|
|
}
|
|
|
|
|
2021-03-23 03:51:29 +00:00
|
|
|
virtual bool testRenderFrame(AVFrame*) {
|
|
|
|
// If the renderer doesn't provide an explicit test routine,
|
|
|
|
// we will always assume that any returned AVFrame can be
|
|
|
|
// rendered successfully.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-04-13 05:12:53 +00:00
|
|
|
virtual bool needsTestFrame() {
|
|
|
|
// No test frame required by default
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int getDecoderCapabilities() {
|
|
|
|
// No special capabilities by default
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-09 19:35:05 +00:00
|
|
|
virtual int getRendererAttributes() {
|
|
|
|
// No special attributes by default
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-12-14 23:25:56 +00:00
|
|
|
virtual int getDecoderColorspace() {
|
|
|
|
// Rec 601 is default
|
|
|
|
return COLORSPACE_REC_601;
|
|
|
|
}
|
|
|
|
|
2019-04-13 05:12:53 +00:00
|
|
|
virtual bool isRenderThreadSupported() {
|
|
|
|
// Render thread is supported by default
|
|
|
|
return true;
|
|
|
|
}
|
2019-02-13 02:43:38 +00:00
|
|
|
|
2019-04-13 05:54:21 +00:00
|
|
|
virtual bool isDirectRenderingSupported() {
|
|
|
|
// The renderer can render directly to the display
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-02-05 01:39:18 +00:00
|
|
|
virtual AVPixelFormat getPreferredPixelFormat(int videoFormat) {
|
2022-06-26 21:22:05 +00:00
|
|
|
if (videoFormat & VIDEO_FORMAT_MASK_10BIT) {
|
2019-11-05 06:56:42 +00:00
|
|
|
// 10-bit YUV 4:2:0
|
|
|
|
return AV_PIX_FMT_P010;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Planar YUV 4:2:0
|
|
|
|
return AV_PIX_FMT_YUV420P;
|
|
|
|
}
|
2019-04-16 04:56:01 +00:00
|
|
|
}
|
|
|
|
|
2021-02-05 01:39:18 +00:00
|
|
|
virtual bool isPixelFormatSupported(int videoFormat, AVPixelFormat pixelFormat) {
|
2020-01-26 23:02:29 +00:00
|
|
|
// By default, we only support the preferred pixel format
|
|
|
|
return getPreferredPixelFormat(videoFormat) == pixelFormat;
|
|
|
|
}
|
|
|
|
|
2022-01-29 04:10:50 +00:00
|
|
|
virtual void setHdrMode(bool) {
|
|
|
|
// Nothing
|
|
|
|
}
|
|
|
|
|
2022-02-05 03:51:34 +00:00
|
|
|
virtual bool prepareDecoderContextInGetFormat(AVCodecContext*, AVPixelFormat) {
|
|
|
|
// Assume no further initialization is required
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-02-13 02:43:38 +00:00
|
|
|
// IOverlayRenderer
|
|
|
|
virtual void notifyOverlayUpdated(Overlay::OverlayType) override {
|
|
|
|
// Nothing
|
|
|
|
}
|
2020-04-13 08:40:28 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_EGL
|
|
|
|
// By default we can't do EGL
|
|
|
|
virtual bool canExportEGL() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-02-05 01:39:18 +00:00
|
|
|
virtual AVPixelFormat getEGLImagePixelFormat() {
|
|
|
|
return AV_PIX_FMT_NONE;
|
|
|
|
}
|
|
|
|
|
2020-04-13 08:40:28 +00:00
|
|
|
virtual bool initializeEGL(EGLDisplay,
|
|
|
|
const EGLExtensions &) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ssize_t exportEGLImages(AVFrame *,
|
|
|
|
EGLDisplay,
|
|
|
|
EGLImage[EGL_MAX_PLANES]) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Free the ressources allocated during the last `exportEGLImages` call
|
|
|
|
virtual void freeEGLImages(EGLDisplay, EGLImage[EGL_MAX_PLANES]) {}
|
|
|
|
#endif
|
2022-01-29 23:14:18 +00:00
|
|
|
|
2022-04-05 05:26:13 +00:00
|
|
|
#ifdef HAVE_DRM
|
2022-01-29 23:14:18 +00:00
|
|
|
// By default we can't do DRM PRIME export
|
|
|
|
virtual bool canExportDrmPrime() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool mapDrmPrimeFrame(AVFrame*, AVDRMFrameDescriptor*) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void unmapDrmPrimeFrame(AVDRMFrameDescriptor*) {}
|
|
|
|
#endif
|
2018-07-13 09:28:10 +00:00
|
|
|
};
|