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

Fixes for drm Aspectratio and UHD HDR

This commit is contained in:
jojo61 2020-01-15 18:01:27 +01:00
parent 269c396a2c
commit 1674600882
3 changed files with 78 additions and 65 deletions

97
codec.c
View File

@ -258,18 +258,18 @@ void CodecVideoOpen(VideoDecoder * decoder, int codec_id)
} }
#endif #endif
#ifdef RASPI #ifdef RASPI
switch (codec_id) { switch (codec_id) {
case AV_CODEC_ID_MPEG2VIDEO: case AV_CODEC_ID_MPEG2VIDEO:
name = "mpeg2_v4l2m2m"; name = "mpeg2_v4l2m2m";
break; break;
case AV_CODEC_ID_H264: case AV_CODEC_ID_H264:
name = "h264_v4l2m2m"; name = "h264_v4l2m2m";
// name = "h264_mmal"; // name = "h264_mmal";
break; break;
case AV_CODEC_ID_HEVC: case AV_CODEC_ID_HEVC:
name = "hevc_v4l2m2m"; name = "hevc_v4l2m2m";
break; break;
} }
#endif #endif
if (name && (video_codec = avcodec_find_decoder_by_name(name))) { if (name && (video_codec = avcodec_find_decoder_by_name(name))) {
Debug(3, "codec: decoder found\n"); Debug(3, "codec: decoder found\n");
@ -287,13 +287,13 @@ void CodecVideoOpen(VideoDecoder * decoder, int codec_id)
} }
#ifndef RASPI #ifndef RASPI
if (!HwDeviceContext) { if (!HwDeviceContext) {
Fatal("codec: no hw device context to be used"); Fatal("codec: no hw device context to be used");
} }
decoder->VideoCtx->hw_device_ctx = av_buffer_ref(HwDeviceContext); decoder->VideoCtx->hw_device_ctx = av_buffer_ref(HwDeviceContext);
#else #else
decoder->VideoCtx->pix_fmt = AV_PIX_FMT_DRM_PRIME; /* request a DRM frame 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 */ // decoder->VideoCtx->pix_fmt = AV_PIX_FMT_MMAL; /* request a DRM frame */
#endif #endif
// FIXME: for software decoder use all cpus, otherwise 1 // FIXME: for software decoder use all cpus, otherwise 1
@ -341,8 +341,8 @@ void CodecVideoOpen(VideoDecoder * decoder, int codec_id)
#endif #endif
#ifdef RASPI #ifdef RASPI
decoder->VideoCtx->codec_id = codec_id; decoder->VideoCtx->codec_id = codec_id;
decoder->VideoCtx->flags |= AV_CODEC_FLAG_BITEXACT; decoder->VideoCtx->flags |= AV_CODEC_FLAG_BITEXACT;
if (video_codec->capabilities & AV_CODEC_CAP_FRAME_THREADS || AV_CODEC_CAP_SLICE_THREADS) { if (video_codec->capabilities & AV_CODEC_CAP_FRAME_THREADS || AV_CODEC_CAP_SLICE_THREADS) {
Debug(3, "codec: supports frame threads"); Debug(3, "codec: supports frame threads");
decoder->VideoCtx->thread_count = 4; decoder->VideoCtx->thread_count = 4;
@ -502,6 +502,7 @@ extern int CuvidTestSurfaces();
extern int init_filters(AVCodecContext * dec_ctx, void *decoder, AVFrame * frame); extern int init_filters(AVCodecContext * dec_ctx, void *decoder, AVFrame * frame);
extern int push_filters(AVCodecContext * dec_ctx, void *decoder, AVFrame * frame); extern int push_filters(AVCodecContext * dec_ctx, void *decoder, AVFrame * frame);
#endif #endif
#ifdef VAAPI #ifdef VAAPI
void CodecVideoDecode(VideoDecoder * decoder, const AVPacket * avpkt) void CodecVideoDecode(VideoDecoder * decoder, const AVPacket * avpkt)
{ {
@ -519,39 +520,45 @@ void CodecVideoDecode(VideoDecoder * decoder, const AVPacket * avpkt)
return; return;
} }
if (!CuvidTestSurfaces()) if (!CuvidTestSurfaces())
usleep(1000); usleep(1000);
frame = av_frame_alloc(); ret = 0;
ret = avcodec_receive_frame(video_ctx, frame); while (ret >= 0) {
if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) { frame = av_frame_alloc();
Debug(4, "codec: receiving video frame failed"); ret = avcodec_receive_frame(video_ctx, frame);
av_frame_free(&frame);
return; if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) {
} Debug(4, "codec: receiving video frame failed");
if (ret >= 0) { av_frame_free(&frame);
if (decoder->filter) { return;
if (decoder->filter == 1) { }
if (init_filters(video_ctx, decoder->HwDecoder, frame) < 0) { if (ret >= 0) {
Debug(3, "video: Init of VAAPI deint Filter failed\n"); if (decoder->filter) {
decoder->filter = 0; if (decoder->filter == 1) {
} else { if (init_filters(video_ctx, decoder->HwDecoder, frame) < 0) {
Debug(3, "Init VAAPI deint ok\n"); Debug(3, "video: Init of VAAPI deint Filter failed\n");
decoder->filter = 2; decoder->filter = 0;
} else {
Debug(3, "Init VAAPI deint ok\n");
decoder->filter = 2;
}
}
if (frame->interlaced_frame && decoder->filter == 2 && (frame->height != 720)) { // broken ZDF sends Interlaced flag
push_filters(video_ctx, decoder->HwDecoder, frame);
continue;
} }
} }
if (frame->interlaced_frame && decoder->filter == 2 && (frame->height != 720)) { // broken ZDF sends Interlaced flag VideoRenderFrame(decoder->HwDecoder, video_ctx, frame);
ret = push_filters(video_ctx, decoder->HwDecoder, frame); } else {
return; av_frame_free(&frame);
} return;
} }
VideoRenderFrame(decoder->HwDecoder, video_ctx, frame);
} else {
av_frame_free(&frame);
} }
} }
} }
#endif #endif
#ifdef CUVID #ifdef CUVID
void CodecVideoDecode(VideoDecoder * decoder, const AVPacket * avpkt) void CodecVideoDecode(VideoDecoder * decoder, const AVPacket * avpkt)
@ -582,7 +589,7 @@ void CodecVideoDecode(VideoDecoder * decoder, const AVPacket * avpkt)
if (!CuvidTestSurfaces()) if (!CuvidTestSurfaces())
usleep(1000); usleep(1000);
// printf("send packet to decode %s\n",consumed?"ok":"Full"); // printf("send packet to decode %s %04x\n",consumed?"ok":"Full",ret1);
if ((ret1 == AVERROR(EAGAIN) || ret1 == AVERROR_EOF || ret1 >= 0) && CuvidTestSurfaces()) { if ((ret1 == AVERROR(EAGAIN) || ret1 == AVERROR_EOF || ret1 >= 0) && CuvidTestSurfaces()) {
ret = 0; ret = 0;
@ -594,7 +601,7 @@ void CodecVideoDecode(VideoDecoder * decoder, const AVPacket * avpkt)
} else { } else {
got_frame = 0; got_frame = 0;
} }
// printf("got %s packet from decoder\n",got_frame?"1":"no"); // printf("got %s packet from decoder\n",got_frame?"1":"no");
if (got_frame) { // frame completed if (got_frame) { // frame completed
#ifdef YADIF #ifdef YADIF
if (decoder->filter) { if (decoder->filter) {

13
drm.c
View File

@ -257,10 +257,15 @@ static int FindDevice(VideoRender * render)
continue; continue;
if (connector->connection == DRM_MODE_CONNECTED && connector->count_modes > 0) { if (connector->connection == DRM_MODE_CONNECTED && connector->count_modes > 0) {
render->connector_id = connector->connector_id; float aspect = (float)connector->mmWidth / (float)connector->mmHeight;
render->mmHeight = connector->mmHeight; if ((aspect > 1.70) && (aspect < 1.85)) {
render->mmWidth = connector->mmWidth; render->mmHeight = 90;
render->mmWidth = 160;
} else {
render->mmHeight = connector->mmHeight;
render->mmWidth = connector->mmWidth;
}
render->connector_id = connector->connector_id;
// FIXME: use default encoder/crtc pair // FIXME: use default encoder/crtc pair
if ((encoder = drmModeGetEncoder(render->fd_drm, connector->encoder_id)) == NULL){ if ((encoder = drmModeGetEncoder(render->fd_drm, connector->encoder_id)) == NULL){
fprintf(stderr, "FindDevice: cannot retrieve encoder (%d): %m\n", errno); fprintf(stderr, "FindDevice: cannot retrieve encoder (%d): %m\n", errno);

View File

@ -1168,6 +1168,7 @@ static void EglInit(void)
// create egl context // create egl context
setenv("MESA_GL_VERSION_OVERRIDE","3.3",0); setenv("MESA_GL_VERSION_OVERRIDE","3.3",0);
setenv("V3D_DOUBLE_BUFFER","1",0);
make_egl(); make_egl();
if (!glewdone) { if (!glewdone) {
@ -1700,7 +1701,7 @@ static void CuvidReleaseSurface(CuvidDecoder * decoder, int surface)
#endif #endif
if (decoder->fds[surface*Planes]) { if (decoder->fds[surface*Planes]) {
close(decoder->fds[surface*Planes]); close(decoder->fds[surface*Planes]);
close(decoder->fds[surface*Planes+1]); // close(decoder->fds[surface*Planes+1]);
#ifdef RASPI #ifdef RASPI
close(decoder->fds[surface*Planes+2]); close(decoder->fds[surface*Planes+2]);
#endif #endif
@ -2550,10 +2551,9 @@ void generateVAAPIImage(CuvidDecoder * decoder, int index, const AVFrame * frame
EGLImageTargetTexture2DOES(GL_TEXTURE_2D, decoder->images[index * Planes + n]); EGLImageTargetTexture2DOES(GL_TEXTURE_2D, decoder->images[index * Planes + n]);
#ifdef RASPI #ifdef RASPI
decoder->fds[index*Planes+n] = fd; decoder->fds[index*Planes+n] = fd;
#else
decoder->fds[index*Planes+n] = desc.objects[desc.layers[n].object_index[0]].fd;
#endif #endif
} }
decoder->fds[index*Planes+n] = desc.objects[0].fd;
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
EglCheck(); EglCheck();
@ -3548,7 +3548,7 @@ static void CuvidMixVideo(CuvidDecoder * decoder, __attribute__((unused))
#endif #endif
} }
// Render Progressive frame // Render Progressive frame
#ifndef PLACEBO #ifndef PLACEBO
y = VideoWindowHeight - decoder->OutputY - decoder->OutputHeight; y = VideoWindowHeight - decoder->OutputY - decoder->OutputHeight;
if (y < 0) if (y < 0)
@ -5255,6 +5255,7 @@ void exit_display()
} }
#endif #endif
Debug(3,"display thread exit\n"); Debug(3,"display thread exit\n");
} }
static void *VideoHandlerThread(void *dummy) static void *VideoHandlerThread(void *dummy)