Skip to content
Permalink
Browse files

MMAL: Report deinterlace method to processinfo overlay

  • Loading branch information...
popcornmix committed Sep 15, 2016
1 parent d2dbd18 commit 3f55be69fefc2df7d47a200d825c6f2f6843907b
@@ -81,9 +81,20 @@ CMMALVideoBuffer::~CMMALVideoBuffer()
CLog::Log(LOGDEBUG, "%s::%s %p", CLASSNAME, __func__, this);
}

void CMMALVideoBuffer::SetVideoDeintMethod(std::string method)
{
if (m_omv)
m_omv->SetVideoDeintMethod(method);
}

#undef CLASSNAME
#define CLASSNAME "CMMALVideo"

void CMMALVideo::SetVideoDeintMethod(std::string method)
{
m_processInfo.SetVideoDeintMethod(method);
}

CMMALVideo::CMMALVideo(CProcessInfo &processInfo) : CDVDVideoCodec(processInfo)
{
if (g_advancedSettings.CanLogComponent(LOGVIDEO))
@@ -59,6 +59,7 @@ class CMMALBuffer : public IDVDResourceCounted<CMMALBuffer>
float m_aspect_ratio;
MMALState m_state;
bool m_rendered;
virtual void SetVideoDeintMethod(std::string method) = 0;
const char *GetStateName() {
static const char *names[] = { "MMALStateNone", "MMALStateHWDec", "MMALStateFFDec", "MMALStateDeint", };
if ((size_t)m_state < vcos_countof(names))
@@ -79,6 +80,7 @@ class CMMALVideoBuffer : public CMMALBuffer
CMMALVideoBuffer(CMMALVideo *dec, std::shared_ptr<CMMALPool> pool);
virtual ~CMMALVideoBuffer();
CMMALVideo *m_omv;
void SetVideoDeintMethod(std::string method);
protected:
std::shared_ptr<CMMALPool> m_pool;
};
@@ -106,6 +108,7 @@ class CMMALVideo : public CDVDVideoCodec
void dec_output_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer);
void dec_control_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer);
void dec_input_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer);
void SetVideoDeintMethod(std::string method);

protected:
void QueryCodec(void);
@@ -42,8 +42,8 @@ using namespace MMAL;

#define CLASSNAME "CMMALYUVBuffer"

CMMALYUVBuffer::CMMALYUVBuffer(std::shared_ptr<CMMALPool> pool, uint32_t mmal_encoding, uint32_t width, uint32_t height, uint32_t aligned_width, uint32_t aligned_height, uint32_t size)
: m_pool(pool)
CMMALYUVBuffer::CMMALYUVBuffer(CDecoder *omv, std::shared_ptr<CMMALPool> pool, uint32_t mmal_encoding, uint32_t width, uint32_t height, uint32_t aligned_width, uint32_t aligned_height, uint32_t size)
: m_omv(omv), m_pool(pool)
{
uint32_t size_pic = 0;
m_width = width;
@@ -86,13 +86,24 @@ CMMALYUVBuffer::~CMMALYUVBuffer()
mmal_buffer_header_release(mmal_buffer);
}

void CMMALYUVBuffer::SetVideoDeintMethod(std::string method)
{
if (m_omv)
m_omv->SetVideoDeintMethod(method);
}

//-----------------------------------------------------------------------------
// MMAL Decoder
//-----------------------------------------------------------------------------

#undef CLASSNAME
#define CLASSNAME "CDecoder"

void CDecoder::SetVideoDeintMethod(std::string method)
{
m_processInfo.SetVideoDeintMethod(method);
}

CDecoder::CDecoder(CProcessInfo &processInfo) : m_processInfo(processInfo)
{
if (g_advancedSettings.CanLogComponent(LOGVIDEO))
@@ -243,6 +254,7 @@ bool CDecoder::Open(AVCodecContext *avctx, AVCodecContext* mainctx, enum AVPixel
CLog::Log(LOGERROR, "%s::%s Failed to create pool for decoder output", CLASSNAME, __func__);
return false;
}
m_pool->SetDecoder(this);

std::list<EINTERLACEMETHOD> deintMethods;
deintMethods.push_back(EINTERLACEMETHOD::VS_INTERLACEMETHOD_AUTO);
@@ -40,10 +40,12 @@ class CGPUPool;
class CMMALYUVBuffer : public CMMALBuffer
{
public:
CMMALYUVBuffer(std::shared_ptr<CMMALPool> pool, uint32_t mmal_encoding, uint32_t width, uint32_t height, uint32_t aligned_width, uint32_t aligned_height, uint32_t size);
CMMALYUVBuffer(CDecoder *dec, std::shared_ptr<CMMALPool> pool, uint32_t mmal_encoding, uint32_t width, uint32_t height, uint32_t aligned_width, uint32_t aligned_height, uint32_t size);
virtual ~CMMALYUVBuffer();

CGPUMEM *gmem;
CDecoder *m_omv;
void SetVideoDeintMethod(std::string method);
private:
std::shared_ptr<CMMALPool> m_pool;
};
@@ -62,6 +64,7 @@ class CDecoder
virtual const std::string Name() { return "mmal"; }
virtual unsigned GetAllowedReferences();
virtual long Release();
void SetVideoDeintMethod(std::string method);

static void FFReleaseBuffer(void *opaque, uint8_t *data);
static int FFGetBuffer(AVCodecContext *avctx, AVFrame *pic, int flags);
@@ -72,6 +72,7 @@ CMMALPool::CMMALPool(const char *component_name, bool input, uint32_t num_buffer

m_mmal_pool = mmal_port_pool_create(port, port->buffer_num, port->buffer_size);
m_closing = false;
m_software = false;
m_mmal_format = 0;
m_width = 0;
m_height = 0;
@@ -208,14 +209,14 @@ CMMALBuffer *CMMALPool::GetBuffer(uint32_t timeout)
// ffmpeg requirements
uint32_t aligned_width = m_aligned_width, aligned_height = m_aligned_height;
AlignedSize(m_avctx, aligned_width, aligned_height);
if (m_dec)
if (!IsSoftware())
{
CMMALVideoBuffer *vid = new CMMALVideoBuffer(m_dec, shared_from_this());
CMMALVideoBuffer *vid = new CMMALVideoBuffer(static_cast<CMMALVideo *>(m_dec), shared_from_this());
omvb = vid;
}
else
{
MMAL::CMMALYUVBuffer *yuv = new MMAL::CMMALYUVBuffer(shared_from_this(), m_mmal_format, m_width, m_height, aligned_width, aligned_height, m_size);
MMAL::CMMALYUVBuffer *yuv = new MMAL::CMMALYUVBuffer(static_cast<MMAL::CDecoder *>(m_dec), shared_from_this(), m_mmal_format, m_width, m_height, aligned_width, aligned_height, m_size);
if (yuv)
{
CGPUMEM *gmem = yuv->gmem;
@@ -561,10 +562,13 @@ void CMMALRenderer::Run()
if (interlace_method == VS_INTERLACEMETHOD_NONE)
{
if (m_deint_input)
{
DestroyDeinterlace();
omvb->SetVideoDeintMethod("none");
}
}
else if (m_deint_input || interlace)
CheckConfigurationDeint(omvb->m_width, omvb->m_height, omvb->m_aligned_width, omvb->m_aligned_height, omvb->m_encoding, interlace_method);
CheckConfigurationDeint(omvb, interlace_method);

if (m_deint_input)
{
@@ -1194,8 +1198,9 @@ void CMMALRenderer::DestroyDeinterlace()
m_deint = nullptr;
}

bool CMMALRenderer::CheckConfigurationDeint(uint32_t width, uint32_t height, uint32_t aligned_width, uint32_t aligned_height, uint32_t encoding, EINTERLACEMETHOD interlace_method)
bool CMMALRenderer::CheckConfigurationDeint(CMMALBuffer *omvb, EINTERLACEMETHOD interlace_method)
{
uint32_t width = omvb->m_width, height = omvb->m_height, aligned_width = omvb->m_aligned_width, aligned_height = omvb->m_aligned_height, encoding = omvb->m_encoding;
MMAL_STATUS_T status;
bool sizeChanged = width != m_deint_width || height != m_deint_height || aligned_width != m_deint_aligned_width || aligned_height != m_deint_aligned_height;
bool deinterlaceChanged = interlace_method != m_interlace_method;
@@ -1315,6 +1320,15 @@ bool CMMALRenderer::CheckConfigurationDeint(uint32_t width, uint32_t height, uin
status = mmal_port_parameter_set_uint32(m_deint_input, MMAL_PARAMETER_EXTRA_BUFFERS, 6 - 5 + advanced_deinterlace ? 2:0);
if (status != MMAL_SUCCESS)
CLog::Log(LOGERROR, "%s::%s Failed to enable extra buffers on %s (status=%x %s)", CLASSNAME, __func__, m_deint_input->name, status, mmal_status_to_string(status));

if (advanced_deinterlace && !half_framerate)
omvb->SetVideoDeintMethod("adv(x2)");
else if (advanced_deinterlace && half_framerate)
omvb->SetVideoDeintMethod("adv(x1)");
else if (!advanced_deinterlace && !half_framerate)
omvb->SetVideoDeintMethod("bob(x2)");
else if (!advanced_deinterlace && half_framerate)
omvb->SetVideoDeintMethod("bob(x1)");
}

if (m_deint_output && (sizeChanged || deinterlaceChanged || encodingChanged))
@@ -62,20 +62,22 @@ class CMMALPool : public std::enable_shared_from_this<CMMALPool>
void ReleaseBuffer(CGPUMEM *gmem);
void Close();
void Prime();
void SetDecoder(CMMALVideo *dec) { m_dec = dec; }
void SetDecoder(void *dec) { m_dec = dec; }
void SetFormat(uint32_t mmal_format, uint32_t width, uint32_t height, uint32_t aligned_width, uint32_t aligned_height, uint32_t size, AVCodecContext *avctx)
{ m_mmal_format = mmal_format; m_width = width; m_height = height; m_aligned_width = aligned_width; m_aligned_height = aligned_height; m_size = size, m_avctx = avctx; }
{ m_mmal_format = mmal_format; m_width = width; m_height = height; m_aligned_width = aligned_width; m_aligned_height = aligned_height; m_size = size, m_avctx = avctx; m_software = true; }
bool IsSoftware() { return m_software; }
protected:
uint32_t m_mmal_format, m_width, m_height, m_aligned_width, m_aligned_height, m_size;
AVCodecContext *m_avctx;
CMMALVideo *m_dec;
void *m_dec;
MMALState m_state;
bool m_input;
MMAL_POOL_T *m_mmal_pool;
MMAL_COMPONENT_T *m_component;
CCriticalSection m_section;
std::deque<CGPUMEM *> m_freeBuffers;
bool m_closing;
bool m_software;
};

class CMMALRenderer : public CBaseRenderer, public CThread, public IRunnable
@@ -157,7 +159,7 @@ class CMMALRenderer : public CBaseRenderer, public CThread, public IRunnable
uint32_t m_deint_width, m_deint_height, m_deint_aligned_width, m_deint_aligned_height;
MMAL_FOURCC_T m_deinterlace_out_encoding;
void DestroyDeinterlace();
bool CheckConfigurationDeint(uint32_t width, uint32_t height, uint32_t aligned_width, uint32_t aligned_height, uint32_t encoding, EINTERLACEMETHOD interlace_method);
bool CheckConfigurationDeint(CMMALBuffer *omvb, EINTERLACEMETHOD interlace_method);

bool CheckConfigurationVout(uint32_t width, uint32_t height, uint32_t aligned_width, uint32_t aligned_height, uint32_t encoding);
uint32_t m_vsync_count;

0 comments on commit 3f55be6

Please sign in to comment.
You can’t perform that action at this time.