Skip to content

Commit

Permalink
[mmalcodec] Return mmal buffers explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
popcornmix committed May 8, 2015
1 parent 2c1c4fb commit 98aa45a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
29 changes: 19 additions & 10 deletions xbmc/cores/dvdplayer/DVDCodecs/Video/MMALCodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ CMMALVideo::~CMMALVideo()
if (g_advancedSettings.CanLogComponent(LOGVIDEO))
CLog::Log(LOGDEBUG, "%s::%s %p", CLASSNAME, __func__, this);
assert(m_finished);
Reset();

pthread_mutex_destroy(&m_output_mutex);

Expand Down Expand Up @@ -408,7 +407,7 @@ bool CMMALVideo::CreateDeinterlace(EINTERLACEMETHOD interlace_method)

m_dec_output = m_deint->output[0];
m_interlace_method = interlace_method;

Prime();
return true;
}

Expand Down Expand Up @@ -464,6 +463,7 @@ bool CMMALVideo::DestroyDeinterlace()

m_dec_output = m_dec->output[0];
m_interlace_method = VS_INTERLACEMETHOD_NONE;
Prime();
return true;
}

Expand Down Expand Up @@ -692,6 +692,7 @@ bool CMMALVideo::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options, MMALVide
if (!SendCodecConfigData())
return false;

Prime();
m_startframe = false;
m_preroll = !m_hints.stills;
m_speed = DVD_PLAYSPEED_NORMAL;
Expand Down Expand Up @@ -734,8 +735,6 @@ int CMMALVideo::Decode(uint8_t* pData, int iSize, double dts, double pts)
MMAL_BUFFER_HEADER_T *buffer;
MMAL_STATUS_T status;

while (buffer = mmal_queue_get(m_dec_output_pool->queue), buffer)
Recycle(buffer);
// we need to queue then de-queue the demux packet, seems silly but
// mmal might not have an input buffer available when we are called
// and we must store the demuxer packet and try again later.
Expand All @@ -762,9 +761,6 @@ int CMMALVideo::Decode(uint8_t* pData, int iSize, double dts, double pts)

while (1)
{
while (buffer = mmal_queue_get(m_dec_output_pool->queue), buffer)
Recycle(buffer);

space = mmal_queue_length(m_dec_input_pool->queue) * m_dec_input->buffer_size;
if (!demuxer_bytes && !m_demux_queue.empty())
{
Expand Down Expand Up @@ -858,8 +854,6 @@ int CMMALVideo::Decode(uint8_t* pData, int iSize, double dts, double pts)
demuxer_content = NULL;
continue;
}
while (buffer = mmal_queue_get(m_dec_output_pool->queue), buffer)
Recycle(buffer);
}
}
if (!demuxer_bytes)
Expand Down Expand Up @@ -894,6 +888,13 @@ int CMMALVideo::Decode(uint8_t* pData, int iSize, double dts, double pts)
return ret;
}

void CMMALVideo::Prime()
{
MMAL_BUFFER_HEADER_T *buffer;
while (buffer = mmal_queue_get(m_dec_output_pool->queue), buffer)
Recycle(buffer);
}

void CMMALVideo::Reset(void)
{
if (g_advancedSettings.CanLogComponent(LOGVIDEO))
Expand Down Expand Up @@ -939,8 +940,10 @@ void CMMALVideo::Reset(void)
pthread_mutex_unlock(&m_output_mutex);

if (!m_finished)
{
SendCodecConfigData();

Prime();
}
m_startframe = false;
m_decoderPts = DVD_NOPTS_VALUE;
m_preroll = !m_hints.stills && (m_speed == DVD_PLAYSPEED_NORMAL || m_speed == DVD_PLAYSPEED_PAUSE);
Expand All @@ -959,6 +962,12 @@ void CMMALVideo::Recycle(MMAL_BUFFER_HEADER_T *buffer)
if (g_advancedSettings.CanLogComponent(LOGVIDEO))
CLog::Log(LOGDEBUG, "%s::%s %p", CLASSNAME, __func__, buffer);

if (m_finished)
{
mmal_buffer_header_release(buffer);
return;
}

MMAL_STATUS_T status;
mmal_buffer_header_reset(buffer);
buffer->cmd = 0;
Expand Down
1 change: 1 addition & 0 deletions xbmc/cores/dvdplayer/DVDCodecs/Video/MMALCodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class CMMALVideo
void QueryCodec(void);
bool CreateDeinterlace(EINTERLACEMETHOD interlace_method);
bool DestroyDeinterlace();
void Prime();

// Video format
int m_decoded_width;
Expand Down

0 comments on commit 98aa45a

Please sign in to comment.