Skip to content

Commit

Permalink
Merge pull request #9975 from popcornmix/mmallazy
Browse files Browse the repository at this point in the history
 mmal_renderer: Use shared pointers to maintain the pool until the decoder has been destroyed
  • Loading branch information
popcornmix committed Jun 13, 2016
2 parents 95949e5 + 7b679f0 commit f484b66
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 19 deletions.
5 changes: 4 additions & 1 deletion xbmc/cores/VideoPlayer/DVDCodecs/Video/MMALCodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,10 @@ void CMMALVideo::Prime()
{
MMAL_BUFFER_HEADER_T *buffer;
assert(m_renderer);
MMAL_POOL_T *render_pool = m_renderer->GetPool(RENDER_FMT_MMAL, AV_PIX_FMT_YUV420P, true);
if (!m_pool)
m_pool = m_renderer->GetPool(RENDER_FMT_MMAL, AV_PIX_FMT_YUV420P, true);
assert(m_pool);
MMAL_POOL_T *render_pool = m_pool->Get();
assert(render_pool);
if (VERBOSE && g_advancedSettings.CanLogComponent(LOGVIDEO))
CLog::Log(LOGDEBUG, "%s::%s - queue(%p)", CLASSNAME, __func__, render_pool);
Expand Down
2 changes: 2 additions & 0 deletions xbmc/cores/VideoPlayer/DVDCodecs/Video/MMALCodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class CMMALBuffer : public IDVDResourceCounted<CMMALBuffer>

class CMMALVideo;
class CMMALRenderer;
class CMMALPool;

// a mmal video frame
class CMMALVideoBuffer : public CMMALBuffer
Expand Down Expand Up @@ -140,6 +141,7 @@ class CMMALVideo : public CDVDVideoCodec
MMAL_PORT_T *m_dec_output;
MMAL_POOL_T *m_dec_input_pool;
CMMALRenderer *m_renderer;
std::shared_ptr<CMMALPool> m_pool;

MMAL_ES_FORMAT_T *m_es_format;
MMAL_COMPONENT_T *m_deint;
Expand Down
6 changes: 5 additions & 1 deletion xbmc/cores/VideoPlayer/DVDCodecs/Video/MMALFFmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,11 @@ int CDecoder::Decode(AVCodecContext* avctx, AVFrame* frame)

MMAL_BUFFER_HEADER_T *CDecoder::GetMmal()
{
MMAL_POOL_T *render_pool = m_renderer->GetPool(RENDER_FMT_MMAL, m_fmt, false);
if (!m_pool)
m_pool = m_renderer->GetPool(RENDER_FMT_MMAL, m_fmt, false);

assert(m_pool);
MMAL_POOL_T *render_pool = m_pool->Get();
assert(render_pool);
MMAL_BUFFER_HEADER_T *mmal_buffer = mmal_queue_timedwait(render_pool->queue, 500);
if (!mmal_buffer)
Expand Down
2 changes: 2 additions & 0 deletions xbmc/cores/VideoPlayer/DVDCodecs/Video/MMALFFmpeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "MMALCodec.h"

class CMMALRenderer;
class CMMALPool;
struct MMAL_BUFFER_HEADER_T;
class CGPUMEM;

Expand Down Expand Up @@ -76,6 +77,7 @@ class CDecoder
unsigned int m_shared;
CCriticalSection m_section;
CMMALRenderer *m_renderer;
std::shared_ptr<CMMALPool> m_pool;
std::deque<CGPUMEM *> m_freeBuffers;
bool m_closing;
};
Expand Down
39 changes: 24 additions & 15 deletions xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/MMALRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

#define VERBOSE 0

MMAL_POOL_T *CMMALRenderer::GetPool(ERenderFormat format, AVPixelFormat pixfmt, bool opaque)
std::shared_ptr<CMMALPool> CMMALRenderer::GetPool(ERenderFormat format, AVPixelFormat pixfmt, bool opaque)
{
CSingleLock lock(m_sharedSection);
bool formatChanged = m_format != format || m_opaque != opaque;
Expand All @@ -55,7 +55,7 @@ CRenderInfo CMMALRenderer::GetRenderInfo()
CRenderInfo info;

if (g_advancedSettings.CanLogComponent(LOGVIDEO))
CLog::Log(LOGDEBUG, "%s::%s cookie:%p", CLASSNAME, __func__, (void *)m_vout_input_pool);
CLog::Log(LOGDEBUG, "%s::%s opaque:%p", CLASSNAME, __func__, this);

info.max_buffer_size = NUM_BUFFERS;
info.optimal_buffer_size = NUM_BUFFERS;
Expand Down Expand Up @@ -113,6 +113,24 @@ static uint32_t pixfmt_to_encoding(AVPixelFormat pixfmt)
return pixfmt_to_encoding_table[i].encoding;
}

CMMALPool::CMMALPool(MMAL_PORT_T *input, uint32_t num_buffers, uint32_t buffer_size)
{
m_input = input;
m_pool = mmal_port_pool_create(input, num_buffers, buffer_size);
if (!m_pool)
CLog::Log(LOGERROR, "%s::%s Failed to create pool for decoder input port", CLASSNAME, __func__);
else
CLog::Log(LOGDEBUG, "%s::%s Created pool %p of size %d x %d", CLASSNAME, __func__, m_pool, num_buffers, buffer_size);
}

CMMALPool::~CMMALPool()
{
CLog::Log(LOGDEBUG, "%s::%s destroying pool (%p)", CLASSNAME, __func__, m_pool);
mmal_port_pool_destroy(m_input, m_pool);
m_pool = nullptr;
m_input = nullptr;
}

bool CMMALRenderer::init_vout(ERenderFormat format, AVPixelFormat pixfmt, bool opaque)
{
CSingleLock lock(m_sharedSection);
Expand Down Expand Up @@ -193,13 +211,7 @@ bool CMMALRenderer::init_vout(ERenderFormat format, AVPixelFormat pixfmt, bool o
return false;
}

CLog::Log(LOGDEBUG, "%s::%s Created pool of size %d x %d", CLASSNAME, __func__, m_vout_input->buffer_num, m_vout_input->buffer_size);
m_vout_input_pool = mmal_port_pool_create(m_vout_input , m_vout_input->buffer_num, m_opaque ? m_vout_input->buffer_size:0);
if (!m_vout_input_pool)
{
CLog::Log(LOGERROR, "%s::%s Failed to create pool for decoder input port (status=%x %s)", CLASSNAME, __func__, status, mmal_status_to_string(status));
return false;
}
m_vout_input_pool = std::make_shared<CMMALPool>(m_vout_input, m_vout_input->buffer_num, m_opaque ? m_vout_input->buffer_size:0);
if (!CSettings::GetInstance().GetBool("videoplayer.usedisplayasclock"))
{
m_queue = mmal_queue_create();
Expand Down Expand Up @@ -501,7 +513,7 @@ void CMMALRenderer::ReleaseBuffers()
void CMMALRenderer::UnInitMMAL()
{
CSingleLock lock(m_sharedSection);
CLog::Log(LOGDEBUG, "%s::%s pool(%p)", CLASSNAME, __func__, m_vout_input_pool);
CLog::Log(LOGDEBUG, "%s::%s pool(%p)", CLASSNAME, __func__, m_vout_input_pool ? m_vout_input_pool->Get() : nullptr);
if (m_queue)
{
StopThread(true);
Expand All @@ -521,11 +533,8 @@ void CMMALRenderer::UnInitMMAL()

ReleaseBuffers();

if (m_vout_input_pool)
{
mmal_port_pool_destroy(m_vout_input, m_vout_input_pool);
m_vout_input_pool = NULL;
}
m_vout_input_pool = NULL;

m_vout_input = NULL;

if (m_vout)
Expand Down
15 changes: 13 additions & 2 deletions xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/MMALRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ class CMMALBuffer;

struct DVDVideoPicture;

class CMMALPool
{
public:
CMMALPool(MMAL_PORT_T *input, uint32_t num_buffers, uint32_t buffer_size);
~CMMALPool();
MMAL_POOL_T *Get() { return m_pool; }
protected:
MMAL_POOL_T *m_pool;
MMAL_PORT_T *m_input;
};

class CMMALRenderer : public CBaseRenderer, public CThread
{
public:
Expand Down Expand Up @@ -83,7 +94,7 @@ class CMMALRenderer : public CBaseRenderer, public CThread
virtual bool IsGuiLayer() { return false; }

void vout_input_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer);
MMAL_POOL_T *GetPool(ERenderFormat format, AVPixelFormat pixfmt, bool opaque);
std::shared_ptr<CMMALPool> GetPool(ERenderFormat format, AVPixelFormat pixfmt, bool opaque);
protected:
int m_iYV12RenderBuffer;
int m_NumYV12Buffers;
Expand All @@ -108,7 +119,7 @@ class CMMALRenderer : public CBaseRenderer, public CThread
CCriticalSection m_sharedSection;
MMAL_COMPONENT_T *m_vout;
MMAL_PORT_T *m_vout_input;
MMAL_POOL_T *m_vout_input_pool;
std::shared_ptr<CMMALPool> m_vout_input_pool;
MMAL_QUEUE_T *m_queue;
double m_error;

Expand Down

0 comments on commit f484b66

Please sign in to comment.