Permalink
Browse files

Merge pull request #5090 from popcornmix/jpeghang

[omx] Avoid hang following jpegs that failed to decode
  • Loading branch information...
2 parents 7494113 + 8064406 commit ebc5a303baa27aba111b695e3e5b203ed23a3d9e @jmarshallnz jmarshallnz committed Aug 2, 2014
Showing with 56 additions and 26 deletions.
  1. +52 −26 xbmc/cores/omxplayer/OMXImage.cpp
  2. +4 −0 xbmc/cores/omxplayer/OMXImage.h
@@ -905,6 +905,7 @@ COMXImageDec::COMXImageDec()
{
m_decoded_buffer = NULL;
OMX_INIT_STRUCTURE(m_decoded_format);
+ m_success = false;
}
COMXImageDec::~COMXImageDec()
@@ -919,15 +920,20 @@ void COMXImageDec::Close()
{
CSingleLock lock(m_OMXSection);
- if(m_omx_decoder.IsInitialized())
- {
- m_omx_decoder.FlushInput();
- m_omx_decoder.FreeInputBuffers();
- }
- if(m_omx_resize.IsInitialized())
+ if (!m_success)
{
- m_omx_resize.FlushOutput();
- m_omx_resize.FreeOutputBuffers();
+ if(m_omx_decoder.IsInitialized())
+ {
+ m_omx_decoder.SetStateForComponent(OMX_StateIdle);
+ m_omx_decoder.FlushInput();
+ m_omx_decoder.FreeInputBuffers();
+ }
+ if(m_omx_resize.IsInitialized())
+ {
+ m_omx_resize.SetStateForComponent(OMX_StateIdle);
+ m_omx_resize.FlushOutput();
+ m_omx_resize.FreeOutputBuffers();
+ }
}
if(m_omx_tunnel_decode.IsInitialized())
m_omx_tunnel_decode.Deestablish();
@@ -1180,6 +1186,7 @@ bool COMXImageDec::Decode(const uint8_t *demuxer_content, unsigned demuxer_bytes
memcpy( (char*)pixels, m_decoded_buffer->pBuffer, stride * height);
+ m_success = true;
Close();
return true;
}
@@ -1194,6 +1201,7 @@ COMXImageEnc::COMXImageEnc()
CSingleLock lock(m_OMXSection);
OMX_INIT_STRUCTURE(m_encoded_format);
m_encoded_buffer = NULL;
+ m_success = false;
}
COMXImageEnc::~COMXImageEnc()
@@ -1419,6 +1427,7 @@ COMXImageReEnc::COMXImageReEnc()
m_encoded_buffer = NULL;
m_pDestBuffer = NULL;
m_nDestAllocSize = 0;
+ m_success = false;
}
COMXImageReEnc::~COMXImageReEnc()
@@ -1434,15 +1443,24 @@ void COMXImageReEnc::Close()
{
CSingleLock lock(m_OMXSection);
- if(m_omx_decoder.IsInitialized())
- {
- m_omx_decoder.FlushInput();
- m_omx_decoder.FreeInputBuffers();
- }
- if(m_omx_encoder.IsInitialized())
+ if (!m_success)
{
- m_omx_encoder.FlushOutput();
- m_omx_encoder.FreeOutputBuffers();
+ if(m_omx_decoder.IsInitialized())
+ {
+ m_omx_decoder.SetStateForComponent(OMX_StateIdle);
+ m_omx_decoder.FlushInput();
+ m_omx_decoder.FreeInputBuffers();
+ }
+ if(m_omx_resize.IsInitialized())
+ {
+ m_omx_resize.SetStateForComponent(OMX_StateIdle);
+ }
+ if(m_omx_encoder.IsInitialized())
+ {
+ m_omx_encoder.SetStateForComponent(OMX_StateIdle);
+ m_omx_encoder.FlushOutput();
+ m_omx_encoder.FreeOutputBuffers();
+ }
}
if(m_omx_tunnel_decode.IsInitialized())
m_omx_tunnel_decode.Deestablish();
@@ -1859,14 +1877,15 @@ bool COMXImageReEnc::ReEncode(COMXImageFile &srcFile, unsigned int maxWidth, uns
}
}
- Close();
-
if(m_omx_decoder.BadState())
return false;
pDestBuffer = m_pDestBuffer;
CLog::Log(LOGDEBUG, "%s::%s : %s %dx%d -> %dx%d\n", CLASSNAME, __func__, srcFile.GetFilename(), srcFile.GetWidth(), srcFile.GetHeight(), maxWidth, maxHeight);
+ m_success = true;
+ Close();
+
return true;
}
@@ -1878,6 +1897,7 @@ bool COMXImageReEnc::ReEncode(COMXImageFile &srcFile, unsigned int maxWidth, uns
COMXTexture::COMXTexture()
{
+ m_success = false;
}
COMXTexture::~COMXTexture()
@@ -1889,15 +1909,20 @@ void COMXTexture::Close()
{
CSingleLock lock(m_OMXSection);
- if(m_omx_decoder.IsInitialized())
- {
- m_omx_decoder.FlushInput();
- m_omx_decoder.FreeInputBuffers();
- }
- if(m_omx_egl_render.IsInitialized())
+ if (!m_success)
{
- m_omx_egl_render.FlushOutput();
- m_omx_egl_render.FreeOutputBuffers();
+ if(m_omx_decoder.IsInitialized())
+ {
+ m_omx_decoder.SetStateForComponent(OMX_StateIdle);
+ m_omx_decoder.FlushInput();
+ m_omx_decoder.FreeInputBuffers();
+ }
+ if(m_omx_egl_render.IsInitialized())
+ {
+ m_omx_egl_render.SetStateForComponent(OMX_StateIdle);
+ m_omx_egl_render.FlushOutput();
+ m_omx_egl_render.FreeOutputBuffers();
+ }
}
if (m_omx_tunnel_decode.IsInitialized())
m_omx_tunnel_decode.Deestablish();
@@ -2199,6 +2224,7 @@ bool COMXTexture::Decode(const uint8_t *demuxer_content, unsigned demuxer_bytes,
eos = true;
}
}
+ m_success = true;
Close();
return true;
}
@@ -132,6 +132,7 @@ class COMXImageDec
OMX_BUFFERHEADERTYPE *m_decoded_buffer;
OMX_PARAM_PORTDEFINITIONTYPE m_decoded_format;
CCriticalSection m_OMXSection;
+ bool m_success;
};
class COMXImageEnc
@@ -150,6 +151,7 @@ class COMXImageEnc
OMX_BUFFERHEADERTYPE *m_encoded_buffer;
OMX_PARAM_PORTDEFINITIONTYPE m_encoded_format;
CCriticalSection m_OMXSection;
+ bool m_success;
};
class COMXImageReEnc
@@ -173,6 +175,7 @@ class COMXImageReEnc
CCriticalSection m_OMXSection;
void *m_pDestBuffer;
unsigned int m_nDestAllocSize;
+ bool m_success;
};
class COMXTexture
@@ -197,6 +200,7 @@ class COMXTexture
OMX_BUFFERHEADERTYPE *m_egl_buffer;
CCriticalSection m_OMXSection;
+ bool m_success;
};
extern COMXImage g_OMXImage;

0 comments on commit ebc5a30

Please sign in to comment.