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

Merge branch 'master' of github.com:jojo61/vdr-plugin-softhdcuvid

This commit is contained in:
jojo61 2022-10-19 16:48:11 +02:00
commit 101bffd01f
6 changed files with 90 additions and 159 deletions

38
codec.c
View File

@ -234,20 +234,6 @@ void CodecVideoOpen(VideoDecoder *decoder, int codec_id) {
break;
}
}
#endif
#ifdef RASPI
switch (codec_id) {
case AV_CODEC_ID_MPEG2VIDEO:
name = "mpeg2_v4l2m2m";
break;
case AV_CODEC_ID_H264:
name = "h264_v4l2m2m";
// name = "h264_mmal";
break;
case AV_CODEC_ID_HEVC:
name = "hevc_v4l2m2m";
break;
}
#endif
if (name && (video_codec = avcodec_find_decoder_by_name(name))) {
Debug(3, "codec: decoder found\n");
@ -264,16 +250,10 @@ void CodecVideoOpen(VideoDecoder *decoder, int codec_id) {
Fatal(_("codec: can't allocate video codec context\n"));
}
#ifndef RASPI
if (!HwDeviceContext) {
Fatal("codec: no hw device context to be used");
}
decoder->VideoCtx->hw_device_ctx = av_buffer_ref(HwDeviceContext);
#else
decoder->VideoCtx->pix_fmt = AV_PIX_FMT_DRM_PRIME; /* request a DRM frame */
// decoder->VideoCtx->pix_fmt = AV_PIX_FMT_MMAL; /* request a DRM frame
//*/
#endif
// FIXME: for software decoder use all cpus, otherwise 1
decoder->VideoCtx->thread_count = 1;
@ -288,7 +268,7 @@ void CodecVideoOpen(VideoDecoder *decoder, int codec_id) {
#ifdef YADIF
deint = 2;
#endif
#if defined VAAPI && !defined RASPI
#if defined VAAPI
// decoder->VideoCtx->extra_hw_frames = 8; // VIDEO_SURFACES_MAX +1
if (video_codec->capabilities & (AV_CODEC_CAP_AUTO_THREADS)) {
Debug(3, "codec: auto threads enabled");
@ -319,20 +299,6 @@ void CodecVideoOpen(VideoDecoder *decoder, int codec_id) {
#endif
#ifdef RASPI
decoder->VideoCtx->codec_id = codec_id;
decoder->VideoCtx->flags |= AV_CODEC_FLAG_BITEXACT;
if (video_codec->capabilities & AV_CODEC_CAP_FRAME_THREADS || AV_CODEC_CAP_SLICE_THREADS) {
Debug(3, "codec: supports frame threads");
decoder->VideoCtx->thread_count = 4;
// decoder->VideoCtx->thread_type |= FF_THREAD_FRAME;
}
if (video_codec->capabilities & AV_CODEC_CAP_SLICE_THREADS) {
Debug(3, "codec: supports slice threads");
decoder->VideoCtx->thread_type |= FF_THREAD_SLICE;
}
#endif
#ifdef CUVID
if (strcmp(decoder->VideoCodec->long_name,
"Nvidia CUVID MPEG2VIDEO decoder") == 0) { // deinterlace for mpeg2 is somehow broken
@ -401,7 +367,7 @@ void CodecVideoOpen(VideoDecoder *decoder, int codec_id) {
// reset buggy ffmpeg/libav flag
decoder->GetFormatDone = 0;
#if defined(YADIF) || defined(RASPI)
#if defined(YADIF)
decoder->filter = 0;
#endif
}

8
drm.c
View File

@ -206,11 +206,7 @@ static int FindDevice(VideoRender *render) {
int i, ii = 0;
char connectorstr[10];
int found = 0;
#ifdef RASPI
render->fd_drm = open("/dev/dri/card1", O_RDWR);
#else
render->fd_drm = open("/dev/dri/card0", O_RDWR);
#endif
if (render->fd_drm < 0) {
fprintf(stderr, "FindDevice: cannot open /dev/dri/card0: %m\n");
return -errno;
@ -372,11 +368,7 @@ static int FindDevice(VideoRender *render) {
for (k = 0; k < plane->count_formats; k++) {
if (encoder->possible_crtcs & plane->possible_crtcs) {
switch (plane->formats[k]) {
#ifdef RASPI
case DRM_FORMAT_ARGB8888:
#else
case DRM_FORMAT_XRGB2101010:
#endif
if (!render->video_plane) {
render->video_plane = plane->plane_id;
}

View File

@ -20,11 +20,7 @@ void ConvertColor(const GLint &colARGB, glm::vec4 &col) {
#ifdef CUVID
const char *glversion = "#version 330 core ";
#else
#ifdef RASPI
const char *glversion = "#version 300 es ";
#else
const char *glversion = "#version 300 es ";
#endif
#endif
const char *rectVertexShader = "%s\n \

View File

@ -4,11 +4,7 @@
#ifdef CUVID
const char *gl_version = "#version 330";
#else
#ifdef RASPI
const char *gl_version = "#version 300 es ";
#else
const char *gl_version = "#version 300 es ";
#endif
#endif
/* Color conversion matrix: RGB = m * YUV + c

View File

@ -645,30 +645,81 @@ void cSoftOsd::Flush(void) {
// Dummy Pixmap for skins
class cDummyPixmap : public cPixmap {
public:
cDummyPixmap(int Layer, const cRect &ViewPort, const cRect &DrawPort = cRect::Null) : cPixmap(Layer, ViewPort, DrawPort) {}
cDummyPixmap(int Layer, const cRect &ViewPort, const cRect &DrawPort = cRect::Null)
: cPixmap(Layer, ViewPort, DrawPort) {}
virtual ~cDummyPixmap(void) {}
virtual void Clear(void) {}
virtual void Fill(tColor Color) { (void)Color; }
virtual void DrawImage(const cPoint &Point, const cImage &Image) { (void)Point; (void)Image; }
virtual void DrawImage(const cPoint &Point, int ImageHandle) { (void)Point; (void)ImageHandle; }
virtual void DrawPixel(const cPoint &Point, tColor Color) { (void)Point; (void)Color; }
virtual void DrawBitmap(const cPoint &Point, const cBitmap &Bitmap, tColor ColorFg = 0, tColor ColorBg = 0, bool Overlay = false) {
(void) Point; (void)Bitmap; (void)ColorFg; (void)ColorBg; (void)Overlay; }
virtual void DrawText(const cPoint &Point, const char *s, tColor ColorFg, tColor ColorBg, const cFont *Font, int Width = 0, int Height = 0, int Alignment = taDefault) {
(void)Point; (void)s; (void)ColorFg; (void) ColorBg; (void) Font; (void)Width; (void)Height; (void)Alignment; }
virtual void DrawRectangle(const cRect &Rect, tColor Color) { (void)Rect; (void)Color; }
virtual void DrawEllipse(const cRect &Rect, tColor Color, int Quadrants = 0) { (void)Rect; (void)Color; (void)Quadrants; }
virtual void DrawSlope(const cRect &Rect, tColor Color, int Type) { (void)Rect; (void)Color; (void)Type; }
virtual void Render(const cPixmap *Pixmap, const cRect &Source, const cPoint &Dest) { (void)Pixmap; (void)Source; (void)Dest; }
virtual void Copy(const cPixmap *Pixmap, const cRect &Source, const cPoint &Dest) { (void)Pixmap; (void)Source; (void)Dest; }
virtual void Scroll(const cPoint &Dest, const cRect &Source = cRect::Null) { (void)Dest; (void)Source; }
virtual void Pan(const cPoint &Dest, const cRect &Source = cRect::Null) { (void)Dest; (void)Source; }
virtual void DrawImage(const cPoint &Point, const cImage &Image) {
(void)Point;
(void)Image;
}
virtual void DrawImage(const cPoint &Point, int ImageHandle) {
(void)Point;
(void)ImageHandle;
}
virtual void DrawPixel(const cPoint &Point, tColor Color) {
(void)Point;
(void)Color;
}
virtual void DrawBitmap(const cPoint &Point, const cBitmap &Bitmap, tColor ColorFg = 0, tColor ColorBg = 0,
bool Overlay = false) {
(void)Point;
(void)Bitmap;
(void)ColorFg;
(void)ColorBg;
(void)Overlay;
}
virtual void DrawText(const cPoint &Point, const char *s, tColor ColorFg, tColor ColorBg, const cFont *Font,
int Width = 0, int Height = 0, int Alignment = taDefault) {
(void)Point;
(void)s;
(void)ColorFg;
(void)ColorBg;
(void)Font;
(void)Width;
(void)Height;
(void)Alignment;
}
virtual void DrawRectangle(const cRect &Rect, tColor Color) {
(void)Rect;
(void)Color;
}
virtual void DrawEllipse(const cRect &Rect, tColor Color, int Quadrants = 0) {
(void)Rect;
(void)Color;
(void)Quadrants;
}
virtual void DrawSlope(const cRect &Rect, tColor Color, int Type) {
(void)Rect;
(void)Color;
(void)Type;
}
virtual void Render(const cPixmap *Pixmap, const cRect &Source, const cPoint &Dest) {
(void)Pixmap;
(void)Source;
(void)Dest;
}
virtual void Copy(const cPixmap *Pixmap, const cRect &Source, const cPoint &Dest) {
(void)Pixmap;
(void)Source;
(void)Dest;
}
virtual void Scroll(const cPoint &Dest, const cRect &Source = cRect::Null) {
(void)Dest;
(void)Source;
}
virtual void Pan(const cPoint &Dest, const cRect &Source = cRect::Null) {
(void)Dest;
(void)Source;
}
};
// Dummy OSD for OpenGL OSD if no X Server is available
class cDummyOsd : public cOsd {
private:
cDummyPixmap *p;
public:
cDummyOsd(int Left, int Top, uint Level) : cOsd(Left, Top, Level) {}
virtual ~cDummyOsd() {}

84
video.c
View File

@ -158,12 +158,9 @@ typedef enum {
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 74, 100)
#include <libavcodec/vaapi.h>
#endif
#include <libavutil/hwcontext_vaapi.h>
#include <libdrm/drm_fourcc.h>
#include <va/va_drmcommon.h>
#ifdef RASPI
#include <libavutil/hwcontext_drm.h>
#endif
#include <libavutil/hwcontext_vaapi.h>
#define TO_AVHW_DEVICE_CTX(x) ((AVHWDeviceContext *)x->data)
#define TO_AVHW_FRAMES_CTX(x) ((AVHWFramesContext *)x->data)
#define TO_VAAPI_DEVICE_CTX(x) ((AVVAAPIDeviceContext *)TO_AVHW_DEVICE_CTX(x)->hwctx)
@ -341,7 +338,7 @@ typedef struct {
#define NUM_SHADERS 5 // Number of supported user shaders with placebo
#if defined VAAPI && !defined RASPI
#if defined VAAPI
#define PIXEL_FORMAT AV_PIX_FMT_VAAPI
#define SWAP_BUFFER_SIZE 3
#endif
@ -349,21 +346,13 @@ typedef struct {
#define PIXEL_FORMAT AV_PIX_FMT_CUDA
#define SWAP_BUFFER_SIZE 3
#endif
#if defined RASPI
#define PIXEL_FORMAT AV_PIX_FMT_MMAL
#define SWAP_BUFFER_SIZE 3
#endif
//----------------------------------------------------------------------------
// Variables
//----------------------------------------------------------------------------
AVBufferRef *HwDeviceContext; ///< ffmpeg HW device context
char VideoIgnoreRepeatPict; ///< disable repeat pict warning
#ifdef RASPI
int Planes = 3;
#else
int Planes = 2;
#endif
unsigned char *posd;
@ -1866,7 +1855,6 @@ static bool create_context_cb(EGLDisplay display, int es_version, EGLContext *ou
EGL_NONE};
EGLint num_configs = 0;
#ifndef RASPI
attribs = attributes10;
*bpp = 10;
if (!eglChooseConfig(display, attributes10, NULL, 0,
@ -1879,9 +1867,7 @@ static bool create_context_cb(EGLDisplay display, int es_version, EGLContext *ou
&num_configs)) { // try 8 Bit
num_configs = 0;
}
} else
#endif
if (num_configs == 0) {
} else if (num_configs == 0) {
EglCheck();
Debug(3, " 10 Bit egl Failed\n");
attribs = attributes8;
@ -2014,22 +2000,20 @@ static CuvidDecoder *CuvidNewHwDecoder(VideoStream *stream) {
Fatal("codec: can't allocate HW video codec context err %04x", i);
}
#endif
#if defined(VAAPI) && !defined(RASPI)
#if defined(VAAPI)
// if ((i = av_hwdevice_ctx_create(&hw_device_ctx, AV_HWDEVICE_TYPE_VAAPI,
// ":0.0" , NULL, 0)) != 0 ) {
if ((i = av_hwdevice_ctx_create(&hw_device_ctx, AV_HWDEVICE_TYPE_VAAPI, "/dev/dri/renderD128", NULL, 0)) != 0) {
Fatal("codec: can't allocate HW video codec context err %04x", i);
}
#endif
#ifndef RASPI
HwDeviceContext = av_buffer_ref(hw_device_ctx);
#endif
if (!(decoder = calloc(1, sizeof(*decoder)))) {
Error(_("video/cuvid: out of memory\n"));
return NULL;
}
#if defined(VAAPI) && !defined(RASPI)
#if defined(VAAPI)
VaDisplay = TO_VAAPI_DEVICE_CTX(HwDeviceContext)->display;
decoder->VaDisplay = VaDisplay;
#endif
@ -2495,21 +2479,12 @@ void createTextureDst(CuvidDecoder *decoder, int anz, unsigned int size_x, unsig
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
#ifdef RASPI
if (PixFmt == AV_PIX_FMT_NV12)
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, n == 0 ? size_x : size_x / 2, n == 0 ? size_y : size_y / 2, 0,
GL_RED, GL_UNSIGNED_BYTE, NULL);
else
glTexImage2D(GL_TEXTURE_2D, 0, GL_R16, n == 0 ? size_x : size_x / 2, n == 0 ? size_y : size_y / 2, 0,
GL_RED, GL_UNSIGNED_SHORT, NULL);
#else
if (PixFmt == AV_PIX_FMT_NV12)
glTexImage2D(GL_TEXTURE_2D, 0, n == 0 ? GL_R8 : GL_RG8, n == 0 ? size_x : size_x / 2,
n == 0 ? size_y : size_y / 2, 0, n == 0 ? GL_RED : GL_RG, GL_UNSIGNED_BYTE, NULL);
else
glTexImage2D(GL_TEXTURE_2D, 0, n == 0 ? GL_R16 : GL_RG16, n == 0 ? size_x : size_x / 2,
n == 0 ? size_y : size_y / 2, 0, n == 0 ? GL_RED : GL_RG, GL_UNSIGNED_SHORT, NULL);
#endif
SDK_CHECK_ERROR_GL();
// register this texture with CUDA
#ifdef CUVID
@ -2555,7 +2530,7 @@ void generateVAAPIImage(CuvidDecoder *decoder, VASurfaceID index, const AVFrame
uint64_t first_time;
#if defined(VAAPI) && !defined(RASPI)
#if defined(VAAPI)
VADRMPRIMESurfaceDescriptor desc;
vaSyncSurface(decoder->VaDisplay, (VASurfaceID)(uintptr_t)frame->data[3]);
@ -2569,12 +2544,6 @@ void generateVAAPIImage(CuvidDecoder *decoder, VASurfaceID index, const AVFrame
}
// vaSyncSurface(decoder->VaDisplay, (VASurfaceID) (uintptr_t)
// frame->data[3]);
#endif
#ifdef RASPI
AVDRMFrameDescriptor desc;
memcpy(&desc, frame->data[0], sizeof(desc));
#endif
eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, eglSharedContext);
@ -2585,7 +2554,7 @@ void generateVAAPIImage(CuvidDecoder *decoder, VASurfaceID index, const AVFrame
uint num_attribs = 0;
int fd;
#if defined(VAAPI) && !defined(RASPI)
#if defined(VAAPI)
ADD_ATTRIB(EGL_LINUX_DRM_FOURCC_EXT, desc.layers[n].drm_format);
ADD_ATTRIB(EGL_WIDTH, n == 0 ? image_width : image_width / 2);
ADD_ATTRIB(EGL_HEIGHT, n == 0 ? image_height : image_height / 2);
@ -3060,18 +3029,10 @@ int get_RGB(CuvidDecoder *decoder) {
glUniform1i(texLoc, 0);
texLoc = glGetUniformLocation(gl_prog, "texture1");
glUniform1i(texLoc, 1);
#ifdef RASPI
texLoc = glGetUniformLocation(gl_prog, "texture2");
glUniform1i(texLoc, 2);
#endif
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, decoder->gl_textures[current * Planes + 0]);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, decoder->gl_textures[current * Planes + 1]);
#ifdef RASPI
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, decoder->gl_textures[current * Planes + 2]);
#endif
glBindFramebuffer(GL_FRAMEBUFFER, fb);
render_pass_quad(1, 0.0, 0.0);
@ -3501,32 +3462,10 @@ static void CuvidRenderFrame(CuvidDecoder *decoder, const AVCodecContext *video_
// printf("Patched colorspace %d Primaries %d TRC
// %d\n",frame->colorspace,frame->color_primaries,frame->color_trc);
#ifdef RASPI
//
// Check image, format, size
//
if ( // decoder->PixFmt != video_ctx->pix_fmt
video_ctx->width != decoder->InputWidth
// || decoder->ColorSpace != color
|| video_ctx->height != decoder->InputHeight) {
Debug(3, "fmt %02d:%02d width %d:%d hight %d:%d\n", decoder->ColorSpace, frame->colorspace, video_ctx->width,
decoder->InputWidth, video_ctx->height, decoder->InputHeight);
decoder->PixFmt = AV_PIX_FMT_NV12;
decoder->InputWidth = video_ctx->width;
decoder->InputHeight = video_ctx->height;
CuvidCleanup(decoder);
decoder->SurfacesNeeded = VIDEO_SURFACES_MAX + 1;
CuvidSetupOutput(decoder);
}
#endif
//
// Copy data from frame to image
//
#ifdef RASPI
if (video_ctx->pix_fmt == 0) {
#else
if (video_ctx->pix_fmt == PIXEL_FORMAT) {
#endif
int w = decoder->InputWidth;
int h = decoder->InputHeight;
@ -3821,19 +3760,11 @@ static void CuvidMixVideo(CuvidDecoder *decoder, __attribute__((unused)) int lev
glUniform1i(texLoc, 0);
texLoc = glGetUniformLocation(gl_prog, "texture1");
glUniform1i(texLoc, 1);
#ifdef RASPI
texLoc = glGetUniformLocation(gl_prog, "texture2");
glUniform1i(texLoc, 2);
#endif
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, decoder->gl_textures[current * Planes + 0]);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, decoder->gl_textures[current * Planes + 1]);
#ifdef RASPI
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, decoder->gl_textures[current * Planes + 2]);
#endif
render_pass_quad(0, xcropf, ycropf);
@ -7022,7 +6953,6 @@ void VideoInit(const char *display_name) {
if (!display_name && !(display_name = getenv("DISPLAY"))) {
// if no environment variable, use :0.0 as default display name
display_name = ":0.0";
}
if (!getenv("DISPLAY")) {
// force set DISPLAY environment variable, otherwise nvidia driver