Skip to content

Commit

Permalink
[omxplayer] Avoid calling render callback with the lock held to avoid…
Browse files Browse the repository at this point in the history
… a deadlock
  • Loading branch information
popcornmix committed Sep 16, 2015
1 parent cd5269b commit e9f59b4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
27 changes: 14 additions & 13 deletions xbmc/cores/omxplayer/OMXVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,8 @@ bool COMXVideo::NaluFormatStartCodes(enum AVCodecID codec, uint8_t *in_extradata
return false;
}

bool COMXVideo::PortSettingsChanged()
bool COMXVideo::PortSettingsChanged(ResolutionUpdateInfo &resinfo)
{
CSingleLock lock (m_critSection);
OMX_ERRORTYPE omx_err = OMX_ErrorNone;

if (m_settings_changed)
Expand Down Expand Up @@ -187,15 +186,13 @@ bool COMXVideo::PortSettingsChanged()
port_image.format.video.xFramerate / (float)(1<<16), interlace.eMode, m_deinterlace);

// let OMXPlayerVideo know about resolution so it can inform RenderManager
if (m_res_callback)
{
float display_aspect = 0.0f;
if (pixel_aspect.nX && pixel_aspect.nY)
display_aspect = (float)pixel_aspect.nX * port_image.format.video.nFrameWidth /
((float)pixel_aspect.nY * port_image.format.video.nFrameHeight);
m_res_callback(m_res_ctx, port_image.format.video.nFrameWidth, port_image.format.video.nFrameHeight,
port_image.format.video.xFramerate / (float)(1<<16), display_aspect);
}
resinfo.width = port_image.format.video.nFrameWidth;
resinfo.height = port_image.format.video.nFrameHeight;
resinfo.framerate = port_image.format.video.xFramerate / (float)(1<<16);
resinfo.display_aspect = 0.0f;
resinfo.changed = true;
if (pixel_aspect.nX && pixel_aspect.nY)
resinfo.display_aspect = (float)pixel_aspect.nX * port_image.format.video.nFrameWidth / ((float)pixel_aspect.nY * port_image.format.video.nFrameHeight);

if (m_settings_changed)
{
Expand Down Expand Up @@ -799,10 +796,11 @@ int COMXVideo::Decode(uint8_t *pData, int iSize, double dts, double pts)
}
//CLog::Log(LOGINFO, "VideD: dts:%.0f pts:%.0f size:%d)\n", dts, pts, iSize);

ResolutionUpdateInfo resinfo = {};
omx_err = m_omx_decoder.WaitForEvent(OMX_EventPortSettingsChanged, 0);
if (omx_err == OMX_ErrorNone)
{
if(!PortSettingsChanged())
if(!PortSettingsChanged(resinfo))
{
CLog::Log(LOGERROR, "%s::%s - error PortSettingsChanged omx_err(0x%08x)\n", CLASSNAME, __func__, omx_err);
return false;
Expand All @@ -811,11 +809,14 @@ int COMXVideo::Decode(uint8_t *pData, int iSize, double dts, double pts)
omx_err = m_omx_decoder.WaitForEvent(OMX_EventParamOrConfigChanged, 0);
if (omx_err == OMX_ErrorNone)
{
if(!PortSettingsChanged())
if(!PortSettingsChanged(resinfo))
{
CLog::Log(LOGERROR, "%s::%s - error PortSettingsChanged (EventParamOrConfigChanged) omx_err(0x%08x)\n", CLASSNAME, __func__, omx_err);
}
}
lock.Leave();
if (resinfo.changed && m_res_callback)
m_res_callback(m_res_ctx, resinfo.width, resinfo.height, resinfo.framerate, resinfo.display_aspect);
}
return true;

Expand Down
10 changes: 9 additions & 1 deletion xbmc/cores/omxplayer/OMXVideo.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@

typedef void (*ResolutionUpdateCallBackFn)(void *ctx, uint32_t width, uint32_t height, float framerate, float display_aspect);

struct ResolutionUpdateInfo {
uint32_t width;
uint32_t height;
float framerate;
float display_aspect;
bool changed;
};

class COMXVideo
{
public:
Expand All @@ -51,7 +59,7 @@ class COMXVideo
// Required overrides
bool SendDecoderConfig();
bool Open(CDVDStreamInfo &hints, OMXClock *clock, EDEINTERLACEMODE deinterlace = VS_DEINTERLACEMODE_OFF, bool hdmi_clock_sync = false);
bool PortSettingsChanged();
bool PortSettingsChanged(ResolutionUpdateInfo &resinfo);
void RegisterResolutionUpdateCallBack(void *ctx, ResolutionUpdateCallBackFn callback) { m_res_ctx = ctx; m_res_callback = callback; }
void Close(void);
unsigned int GetFreeSpace();
Expand Down

0 comments on commit e9f59b4

Please sign in to comment.