Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MythV4L2M2MContext: Prepare for planned V4L2 Request API hwaccel changes #929

Merged
merged 2 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 2 additions & 46 deletions mythtv/libs/libmythtv/decoders/mythv4l2m2mcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: ")
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -507,50 +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;
}

bool MythV4L2M2MContext::GetRequestBuffer(AVCodecContext* Context, MythVideoFrame* Frame, AVFrame* AvFrame)
{
if (!Context || !AvFrame || !Frame)
return false;

if (Frame->m_type != FMT_DRMPRIME || static_cast<AVPixelFormat>(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<uint8_t*>(&(reinterpret_cast<V4L2RequestDescriptor*>(AvFrame->data[0])->drm));
// Retain the buffer so it is not released before we display it
Frame->m_priv[0] = reinterpret_cast<unsigned char*>(av_buffer_ref(AvFrame->buf[0]));
// Set interop
Frame->m_priv[1] = reinterpret_cast<unsigned char*>(m_interop);
// Set the release method
AvFrame->buf[1] = av_buffer_create(reinterpret_cast<uint8_t*>(Frame), 0, MythCodecContext::ReleaseBuffer,
static_cast<AvFormatDecoder*>(Context->opaque), 0);
return true;
}
1 change: 0 additions & 1 deletion mythtv/libs/libmythtv/decoders/mythv4l2m2mcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading