Skip to content

Commit

Permalink
[mmalcodec] Add shared lock around MMAL operations
Browse files Browse the repository at this point in the history
  • Loading branch information
popcornmix committed May 9, 2015
1 parent 16daaa0 commit ea5085e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions xbmc/cores/dvdplayer/DVDCodecs/Video/MMALCodec.cpp
Expand Up @@ -133,6 +133,7 @@ CMMALVideo::~CMMALVideo()
if (!m_finished)
Dispose();

CSingleLock lock(m_sharedSection);
pthread_mutex_destroy(&m_output_mutex);

if (m_deint && m_deint->control && m_deint->control->is_enabled)
Expand Down Expand Up @@ -176,6 +177,7 @@ CMMALVideo::~CMMALVideo()

void CMMALVideo::PortSettingsChanged(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
{
CSingleLock lock(m_sharedSection);
MMAL_EVENT_FORMAT_CHANGED_T *fmt = mmal_event_format_changed_get(buffer);
mmal_format_copy(m_es_format, fmt->format);

Expand Down Expand Up @@ -284,6 +286,7 @@ static void dec_output_port_cb_static(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *b

bool CMMALVideo::change_dec_output_format()
{
CSingleLock lock(m_sharedSection);
MMAL_STATUS_T status;
if (g_advancedSettings.CanLogComponent(LOGVIDEO))
CLog::Log(LOGDEBUG, "%s::%s", CLASSNAME, __func__);
Expand Down Expand Up @@ -320,6 +323,7 @@ bool CMMALVideo::change_dec_output_format()

bool CMMALVideo::CreateDeinterlace(EINTERLACEMETHOD interlace_method)
{
CSingleLock lock(m_sharedSection);
MMAL_STATUS_T status;

if (g_advancedSettings.CanLogComponent(LOGVIDEO))
Expand Down Expand Up @@ -417,6 +421,7 @@ bool CMMALVideo::CreateDeinterlace(EINTERLACEMETHOD interlace_method)

bool CMMALVideo::DestroyDeinterlace()
{
CSingleLock lock(m_sharedSection);
MMAL_STATUS_T status;

if (g_advancedSettings.CanLogComponent(LOGVIDEO))
Expand Down Expand Up @@ -473,6 +478,7 @@ bool CMMALVideo::DestroyDeinterlace()

bool CMMALVideo::SendCodecConfigData()
{
CSingleLock lock(m_sharedSection);
MMAL_STATUS_T status;
if (!m_dec_input_pool)
return true;
Expand Down Expand Up @@ -502,6 +508,7 @@ bool CMMALVideo::SendCodecConfigData()

bool CMMALVideo::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options)
{
CSingleLock lock(m_sharedSection);
if (g_advancedSettings.CanLogComponent(LOGVIDEO))
CLog::Log(LOGDEBUG, "%s::%s usemmal:%d software:%d %dx%d pool:%p", CLASSNAME, __func__, CSettings::Get().GetBool("videoplayer.usemmal"), hints.software, hints.width, hints.height, options.m_opaque_pointer);

Expand Down Expand Up @@ -702,6 +709,7 @@ bool CMMALVideo::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options)

void CMMALVideo::Dispose()
{
CSingleLock lock(m_sharedSection);
m_finished = true;
Reset();
}
Expand All @@ -714,6 +722,7 @@ void CMMALVideo::SetDropState(bool bDrop)

int CMMALVideo::Decode(uint8_t* pData, int iSize, double dts, double pts)
{
CSingleLock lock(m_sharedSection);
//if (g_advancedSettings.CanLogComponent(LOGVIDEO))
// CLog::Log(LOGDEBUG, "%s::%s - %-8p %-6d dts:%.3f pts:%.3f ready_queue(%d)",
// CLASSNAME, __func__, pData, iSize, dts == DVD_NOPTS_VALUE ? 0.0 : dts*1e-6, pts == DVD_NOPTS_VALUE ? 0.0 : pts*1e-6, m_output_ready.size());
Expand Down Expand Up @@ -861,6 +870,7 @@ int CMMALVideo::Decode(uint8_t* pData, int iSize, double dts, double pts)
if (g_advancedSettings.CanLogComponent(LOGVIDEO))
CLog::Log(LOGDEBUG, "%s::%s - Nothing to do: ready_queue(%d) demux_queue(%d) space(%d) preroll(%d)",
CLASSNAME, __func__, m_output_ready.size(), m_demux_queue_length, mmal_queue_length(m_dec_input_pool->queue) * m_dec_input->buffer_size, m_preroll);
lock.Leave();
Sleep(10); // otherwise we busy spin
}
return ret;
Expand All @@ -878,6 +888,7 @@ void CMMALVideo::Prime()

void CMMALVideo::Reset(void)
{
CSingleLock lock(m_sharedSection);
if (g_advancedSettings.CanLogComponent(LOGVIDEO))
CLog::Log(LOGDEBUG, "%s::%s", CLASSNAME, __func__);

Expand Down Expand Up @@ -943,6 +954,7 @@ void CMMALVideo::SetSpeed(int iSpeed)

void CMMALVideo::Recycle(MMAL_BUFFER_HEADER_T *buffer)
{
CSingleLock lock(m_sharedSection);
if (g_advancedSettings.CanLogComponent(LOGVIDEO))
CLog::Log(LOGDEBUG, "%s::%s %p", CLASSNAME, __func__, buffer);

Expand All @@ -968,6 +980,7 @@ void CMMALVideo::Recycle(MMAL_BUFFER_HEADER_T *buffer)

bool CMMALVideo::GetPicture(DVDVideoPicture* pDvdVideoPicture)
{
CSingleLock lock(m_sharedSection);
if (!m_output_ready.empty())
{
CMMALVideoBuffer *buffer;
Expand Down Expand Up @@ -1027,6 +1040,7 @@ bool CMMALVideo::GetPicture(DVDVideoPicture* pDvdVideoPicture)

bool CMMALVideo::ClearPicture(DVDVideoPicture* pDvdVideoPicture)
{
CSingleLock lock(m_sharedSection);
if (pDvdVideoPicture->format == RENDER_FMT_MMAL)
{
if (g_advancedSettings.CanLogComponent(LOGVIDEO))
Expand All @@ -1039,6 +1053,7 @@ bool CMMALVideo::ClearPicture(DVDVideoPicture* pDvdVideoPicture)

bool CMMALVideo::GetCodecStats(double &pts, int &droppedPics)
{
CSingleLock lock(m_sharedSection);
droppedPics= -1;
return false;
}
1 change: 1 addition & 0 deletions xbmc/cores/dvdplayer/DVDCodecs/Video/MMALCodec.h
Expand Up @@ -131,6 +131,7 @@ class CMMALVideo : public CDVDVideoCodec
int m_speed;
bool m_preroll;

CCriticalSection m_sharedSection;
MMAL_COMPONENT_T *m_dec;
MMAL_PORT_T *m_dec_input;
MMAL_PORT_T *m_dec_output;
Expand Down

0 comments on commit ea5085e

Please sign in to comment.