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

128 lines
3.9 KiB
C
Raw Normal View History

2018-07-21 07:16:03 +00:00
#pragma once
#include "renderer.h"
// Avoid X11 if SDL was built without it
#if !defined(SDL_VIDEO_DRIVER_X11) && defined(HAVE_LIBVA_X11)
#warning Unable to use libva-x11 without SDL X11 backend
#undef HAVE_LIBVA_X11
#endif
// Avoid Wayland if SDL was built without it
#if !defined(SDL_VIDEO_DRIVER_WAYLAND) && defined(HAVE_LIBVA_WAYLAND)
#warning Unable to use libva-wayland without SDL Wayland backend
#undef HAVE_LIBVA_WAYLAND
#endif
// Avoid KMSDRM if SDL was built without it
#if !defined(SDL_VIDEO_DRIVER_KMSDRM) && defined(HAVE_LIBVA_DRM)
#warning Unable to use libva-drm without SDL KMSDRM backend
#undef HAVE_LIBVA_DRM
#endif
// Avoid KMSDRM if SDL is too old for FD sharing
#if defined(HAVE_LIBVA_DRM) && defined(SDL_VIDEO_DRIVER_KMSDRM) && !SDL_VERSION_ATLEAST(2, 0, 15)
#warning Unable to use libva-drm because SDL is not version 2.0.16 or later
#undef HAVE_LIBVA_DRM
#endif
// Avoid KMSDRM if built without libdrm
#if defined(HAVE_LIBVA_DRM) && !defined(HAVE_DRM)
#warning Unable to use libva-drm without libdrm available
#undef HAVE_LIBVA_DRM
#endif
#ifdef HAVE_EGL
#include "eglimagefactory.h"
#endif
2018-07-21 07:16:03 +00:00
extern "C" {
#include <va/va.h>
2018-08-12 02:43:36 +00:00
#ifdef HAVE_LIBVA_X11
2018-07-21 07:16:03 +00:00
#include <va/va_x11.h>
2018-08-12 02:43:36 +00:00
#endif
#ifdef HAVE_LIBVA_WAYLAND
#include <va/va_wayland.h>
#endif
2019-07-07 22:31:15 +00:00
#ifdef HAVE_LIBVA_DRM
#include <va/va_drm.h>
#endif
2018-07-21 07:16:03 +00:00
#include <libavutil/hwcontext_vaapi.h>
#if defined(HAVE_EGL) || defined(HAVE_DRM)
#include <va/va_drmcommon.h>
#endif
2018-07-21 07:16:03 +00:00
}
class VAAPIRenderer : public IFFmpegRenderer
{
public:
VAAPIRenderer(int decoderSelectionPass);
2019-04-13 05:12:53 +00:00
virtual ~VAAPIRenderer() override;
virtual bool initialize(PDECODER_PARAMETERS params) override;
virtual bool prepareDecoderContext(AVCodecContext* context, AVDictionary** options) override;
2019-04-13 05:12:53 +00:00
virtual void renderFrame(AVFrame* frame) override;
virtual bool needsTestFrame() override;
2019-04-13 05:54:21 +00:00
virtual bool isDirectRenderingSupported() override;
virtual int getDecoderColorspace() override;
virtual int getDecoderCapabilities() override;
virtual void notifyOverlayUpdated(Overlay::OverlayType) override;
virtual bool notifyWindowChanged(PWINDOW_STATE_CHANGE_INFO) 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
2018-07-21 07:16:03 +00:00
2022-04-05 05:26:13 +00:00
#ifdef HAVE_DRM
virtual bool canExportDrmPrime() override;
virtual bool mapDrmPrimeFrame(AVFrame* frame, AVDRMFrameDescriptor* drmDescriptor) override;
virtual void unmapDrmPrimeFrame(AVDRMFrameDescriptor* drmDescriptor) override;
#endif
2018-07-21 07:16:03 +00:00
private:
VADisplay openDisplay(SDL_Window* window);
VAStatus tryVaInitialize(AVVAAPIDeviceContext* vaDeviceContext, PDECODER_PARAMETERS params, int* major, int* minor);
void renderOverlay(VADisplay display, VASurfaceID surface, Overlay::OverlayType type);
#if defined(HAVE_EGL) || defined(HAVE_DRM)
bool canExportSurfaceHandle(int layerTypeFlag, VADRMPRIMESurfaceDescriptor* descriptor);
#endif
int m_DecoderSelectionPass;
2018-08-12 02:43:36 +00:00
int m_WindowSystem;
2018-07-21 07:16:03 +00:00
AVBufferRef* m_HwContext;
bool m_BlacklistedForDirectRendering;
bool m_HasRfiLatencyBug;
2018-08-12 02:43:36 +00:00
SDL_mutex* m_OverlayMutex;
VAImageFormat m_OverlayFormat;
Uint32 m_OverlaySdlPixelFormat;
VAImage m_OverlayImage[Overlay::OverlayMax];
VASubpictureID m_OverlaySubpicture[Overlay::OverlayMax];
SDL_Rect m_OverlayRect[Overlay::OverlayMax];
2018-08-12 02:43:36 +00:00
#ifdef HAVE_LIBVA_X11
Window m_XWindow;
#endif
#ifdef HAVE_LIBVA_DRM
int m_DrmFd;
#endif
SDL_Window* m_Window;
int m_VideoFormat;
#ifdef HAVE_EGL
enum class EglExportType {
Unknown,
Separate,
Composed
} m_EglExportType;
VADRMPRIMESurfaceDescriptor m_PrimeDescriptor;
EglImageFactory m_EglImageFactory;
#endif
2018-07-21 07:16:03 +00:00
};