Skip to content

Commit

Permalink
Add high level locking to OMXVideo
Browse files Browse the repository at this point in the history
Shutdown and decoding come from different threads.
If the components are shut down while a packet is being submitted, we get an OMX error.

OMXAudio already uses a critical section lock. OMXVideo should also do too.
  • Loading branch information
popcornmix committed Oct 23, 2013
1 parent 01c5c2b commit fd8fe4a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 15 additions & 1 deletion OMXVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ COMXVideo::~COMXVideo()

bool COMXVideo::SendDecoderConfig()
{
CSingleLock lock (m_critSection);
OMX_ERRORTYPE omx_err = OMX_ErrorNone;

/* send decoder config */
Expand Down Expand Up @@ -140,6 +141,7 @@ bool COMXVideo::NaluFormatStartCodes(enum AVCodecID codec, uint8_t *in_extradata

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

if (m_settings_changed)
Expand Down Expand Up @@ -333,6 +335,7 @@ bool COMXVideo::PortSettingsChanged()

bool COMXVideo::Open(COMXStreamInfo &hints, OMXClock *clock, const CRect &DestRect, float display_aspect, EDEINTERLACEMODE deinterlace, bool hdmi_clock_sync, float fifo_size)
{
CSingleLock lock (m_critSection);
bool vflip = false;
Close();
OMX_ERRORTYPE omx_err = OMX_ErrorNone;
Expand Down Expand Up @@ -760,6 +763,7 @@ bool COMXVideo::Open(COMXStreamInfo &hints, OMXClock *clock, const CRect &DestRe

void COMXVideo::Close()
{
CSingleLock lock (m_critSection);
m_omx_tunnel_clock.Deestablish();
m_omx_tunnel_decoder.Deestablish();
if(m_deinterlace)
Expand Down Expand Up @@ -795,19 +799,22 @@ void COMXVideo::SetDropState(bool bDrop)

unsigned int COMXVideo::GetFreeSpace()
{
CSingleLock lock (m_critSection);
return m_omx_decoder.GetInputBufferSpace();
}

unsigned int COMXVideo::GetSize()
{
CSingleLock lock (m_critSection);
return m_omx_decoder.GetInputBufferSize();
}

int COMXVideo::Decode(uint8_t *pData, int iSize, double pts)
{
CSingleLock lock (m_critSection);
OMX_ERRORTYPE omx_err;

if( m_drop_state )
if( m_drop_state || !m_is_open )
return true;

unsigned int demuxer_bytes = (unsigned int)iSize;
Expand Down Expand Up @@ -896,6 +903,7 @@ int COMXVideo::Decode(uint8_t *pData, int iSize, double pts)

void COMXVideo::Reset(void)
{
CSingleLock lock (m_critSection);
if(!m_is_open)
return;

Expand All @@ -910,6 +918,7 @@ void COMXVideo::Reset(void)
///////////////////////////////////////////////////////////////////////////////////////////
void COMXVideo::SetVideoRect(const CRect& SrcRect, const CRect& DestRect)
{
CSingleLock lock (m_critSection);
if(!m_is_open)
return;

Expand Down Expand Up @@ -958,11 +967,13 @@ void COMXVideo::SetVideoRect(const CRect& SrcRect, const CRect& DestRect)

int COMXVideo::GetInputBufferSize()
{
CSingleLock lock (m_critSection);
return m_omx_decoder.GetInputBufferSize();
}

void COMXVideo::SubmitEOS()
{
CSingleLock lock (m_critSection);
if(!m_is_open)
return;

Expand Down Expand Up @@ -996,6 +1007,7 @@ void COMXVideo::SubmitEOS()

bool COMXVideo::IsEOS()
{
CSingleLock lock (m_critSection);
if(!m_is_open)
return true;
if (!m_failed_eos && !m_omx_render.IsEOS())
Expand All @@ -1010,6 +1022,7 @@ bool COMXVideo::IsEOS()

OMXPacket *COMXVideo::GetText()
{
CSingleLock lock (m_critSection);
OMX_BUFFERHEADERTYPE *omx_buffer = m_omx_text.GetOutputBuffer(0);
OMXPacket *pkt = NULL;

Expand Down Expand Up @@ -1037,6 +1050,7 @@ OMXPacket *COMXVideo::GetText()

int COMXVideo::DecodeText(uint8_t *pData, int iSize, double dts, double pts)
{
CSingleLock lock (m_critSection);
OMX_ERRORTYPE omx_err;

if (pData || iSize > 0)
Expand Down
2 changes: 2 additions & 0 deletions OMXVideo.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "OMXReader.h"

#include "guilib/Geometry.h"
#include "utils/SingleLock.h"

#define VIDEO_BUFFERS 60

Expand Down Expand Up @@ -113,6 +114,7 @@ class COMXVideo
bool m_failed_eos;
OMX_DISPLAYTRANSFORMTYPE m_transform;
bool m_settings_changed;
CCriticalSection m_critSection;
};

#endif

0 comments on commit fd8fe4a

Please sign in to comment.