From f6ad7687d8c909de478d56d2eed2cba369277df3 Mon Sep 17 00:00:00 2001 From: Jonas Karlman Date: Fri, 12 Jul 2024 13:43:57 +0000 Subject: [PATCH 1/2] MythV4L2M2MContext: Use GetDRMBuffer The FFmpeg internal V4L2RequestDescriptor type is not meant to be used by applications, instead applications should treat the returned frames as if a AVDRMFrameDescriptor was returned, as defined by the DRM_PRIME pix fmt. Remove the custom implementation of GetRequestBuffer and use the base GetDRMBuffer function instead. Signed-off-by: Jonas Karlman --- .../libmythtv/decoders/mythv4l2m2mcontext.cpp | 38 +------------------ .../libmythtv/decoders/mythv4l2m2mcontext.h | 1 - 2 files changed, 1 insertion(+), 38 deletions(-) diff --git a/mythtv/libs/libmythtv/decoders/mythv4l2m2mcontext.cpp b/mythtv/libs/libmythtv/decoders/mythv4l2m2mcontext.cpp index ce09f85362f..18dddeec6eb 100644 --- a/mythtv/libs/libmythtv/decoders/mythv4l2m2mcontext.cpp +++ b/mythtv/libs/libmythtv/decoders/mythv4l2m2mcontext.cpp @@ -25,11 +25,6 @@ // FFmpeg extern "C" { #include "libavutil/opt.h" -#ifdef USING_V4L2_REQUEST -#include "libavcodec/v4l2_request.h" -#else -struct V4L2RequestDescriptor { int drm; }; -#endif } #define LOC QString("V4L2_M2M: ") @@ -177,7 +172,7 @@ bool MythV4L2M2MContext::RetrieveFrame(AVCodecContext *Context, MythVideoFrame * return GetBuffer(Context, Frame, AvFrame, 0); if (m_request) - return MythV4L2M2MContext::GetRequestBuffer(Context, Frame, AvFrame); + return MythDRMPRIMEContext::GetDRMBuffer(Context, Frame, AvFrame, 0); return MythDRMPRIMEContext::RetrieveFrame(Context, Frame, AvFrame); } @@ -523,34 +518,3 @@ int MythV4L2M2MContext::InitialiseV4L2RequestContext(AVCodecContext *Context) Context->hw_device_ctx = hwdeviceref; return 0; } - -bool MythV4L2M2MContext::GetRequestBuffer(AVCodecContext* Context, MythVideoFrame* Frame, AVFrame* AvFrame) -{ - if (!Context || !AvFrame || !Frame) - return false; - - if (Frame->m_type != FMT_DRMPRIME || static_cast(AvFrame->format) != AV_PIX_FMT_DRM_PRIME) - { - LOG(VB_GENERAL, LOG_ERR, LOC + "Not a DRM PRIME buffer"); - return false; - } - - Frame->m_width = AvFrame->width; - Frame->m_height = AvFrame->height; - Frame->m_pixFmt = Context->pix_fmt; - Frame->m_swPixFmt = Context->sw_pix_fmt; - Frame->m_directRendering = true; - AvFrame->opaque = Frame; - AvFrame->reordered_opaque = Context->reordered_opaque; - - // Frame->data[0] holds V4L2RequestDescriptor which holds AVDRMFrameDescriptor - Frame->m_buffer = reinterpret_cast(&(reinterpret_cast(AvFrame->data[0])->drm)); - // Retain the buffer so it is not released before we display it - Frame->m_priv[0] = reinterpret_cast(av_buffer_ref(AvFrame->buf[0])); - // Set interop - Frame->m_priv[1] = reinterpret_cast(m_interop); - // Set the release method - AvFrame->buf[1] = av_buffer_create(reinterpret_cast(Frame), 0, MythCodecContext::ReleaseBuffer, - static_cast(Context->opaque), 0); - return true; -} diff --git a/mythtv/libs/libmythtv/decoders/mythv4l2m2mcontext.h b/mythtv/libs/libmythtv/decoders/mythv4l2m2mcontext.h index 640da5a7c52..8e48af16e81 100644 --- a/mythtv/libs/libmythtv/decoders/mythv4l2m2mcontext.h +++ b/mythtv/libs/libmythtv/decoders/mythv4l2m2mcontext.h @@ -28,7 +28,6 @@ class MythV4L2M2MContext : public MythDRMPRIMEContext static enum AVPixelFormat GetV4L2RequestFormat(AVCodecContext *Context, const AVPixelFormat *PixFmt); static int InitialiseV4L2RequestContext(AVCodecContext *Context); - bool GetRequestBuffer(AVCodecContext* Context, MythVideoFrame* Frame, AVFrame* AvFrame); protected: static const V4L2Profiles& GetStandardProfiles(); From 27f436301ee26efe22e4aa471a891fe22f8eb8ce Mon Sep 17 00:00:00 2001 From: Jonas Karlman Date: Fri, 12 Jul 2024 13:43:57 +0000 Subject: [PATCH 2/2] MythV4L2M2MContext: Remove unneeded av_hwdevice_ctx_init() call av_hwdevice_ctx_init() is already called internally by FFmpeg function av_hwdevice_ctx_create(), and is not meant to be called a second time. Remove the unneeded av_hwdevice_ctx_init() to simplify the code. Signed-off-by: Jonas Karlman --- mythtv/libs/libmythtv/decoders/mythv4l2m2mcontext.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/mythtv/libs/libmythtv/decoders/mythv4l2m2mcontext.cpp b/mythtv/libs/libmythtv/decoders/mythv4l2m2mcontext.cpp index 18dddeec6eb..a1caaf30224 100644 --- a/mythtv/libs/libmythtv/decoders/mythv4l2m2mcontext.cpp +++ b/mythtv/libs/libmythtv/decoders/mythv4l2m2mcontext.cpp @@ -502,19 +502,11 @@ int MythV4L2M2MContext::InitialiseV4L2RequestContext(AVCodecContext *Context) return -1; // N.B. Interop support should already have been checked - // Allocate the device context + // Create the device context auto * hwdeviceref = MythCodecContext::CreateDevice(AV_HWDEVICE_TYPE_DRM, nullptr); if (!hwdeviceref) return -1; - // Initialise device context - if (av_hwdevice_ctx_init(hwdeviceref) < 0) - { - LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to initialise device context"); - av_buffer_unref(&hwdeviceref); - return -1; - } - Context->hw_device_ctx = hwdeviceref; return 0; }