Skip to content

Commit

Permalink
Retry opening the context if it fails at first.
Browse files Browse the repository at this point in the history
This fixes #4550, the hang on the crash video in FF4.
  • Loading branch information
unknownbrackets committed Jan 2, 2014
1 parent c1dcebc commit 2c38805
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
55 changes: 30 additions & 25 deletions Core/HW/MediaEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,34 +152,11 @@ MediaEngine::~MediaEngine() {
}

void MediaEngine::closeMedia() {
#ifdef USE_FFMPEG
if (m_buffer)
av_free(m_buffer);
if (m_pFrameRGB)
av_free(m_pFrameRGB);
if (m_pFrame)
av_free(m_pFrame);
if (m_pIOContext && m_pIOContext->buffer)
av_free(m_pIOContext->buffer);
if (m_pIOContext)
av_free(m_pIOContext);
if (m_pCodecCtx)
avcodec_close(m_pCodecCtx);
if (m_pFormatCtx)
avformat_close_input(&m_pFormatCtx);
#endif // USE_FFMPEG
closeContext();
if (m_pdata)
delete m_pdata;
if (m_demux)
delete m_demux;
m_buffer = 0;
#ifdef USE_FFMPEG
m_pFrame = 0;
m_pFrameRGB = 0;
m_pIOContext = 0;
m_pCodecCtx = 0;
m_pFormatCtx = 0;
#endif
m_pdata = 0;
m_demux = 0;
AT3Close(&m_audioContext);
Expand Down Expand Up @@ -267,8 +244,10 @@ bool MediaEngine::openContext() {
if (avformat_open_input((AVFormatContext**)&m_pFormatCtx, NULL, NULL, NULL) != 0)
return false;

if (avformat_find_stream_info(m_pFormatCtx, NULL) < 0)
if (avformat_find_stream_info(m_pFormatCtx, NULL) < 0) {
closeContext();
return false;
}

if (m_videoStream >= (int)m_pFormatCtx->nb_streams) {
WARN_LOG_REPORT(ME, "Bad video stream %d", m_videoStream);
Expand Down Expand Up @@ -310,6 +289,32 @@ bool MediaEngine::openContext() {
return true;
}

void MediaEngine::closeContext()
{
#ifdef USE_FFMPEG
if (m_buffer)
av_free(m_buffer);
if (m_pFrameRGB)
av_free(m_pFrameRGB);
if (m_pFrame)
av_free(m_pFrame);
if (m_pIOContext && m_pIOContext->buffer)
av_free(m_pIOContext->buffer);
if (m_pIOContext)
av_free(m_pIOContext);
if (m_pCodecCtx)
avcodec_close(m_pCodecCtx);
if (m_pFormatCtx)
avformat_close_input(&m_pFormatCtx);
m_pFrame = 0;
m_pFrameRGB = 0;
m_pIOContext = 0;
m_pCodecCtx = 0;
m_pFormatCtx = 0;
#endif
m_buffer = 0;
}

bool MediaEngine::loadStream(u8* buffer, int readSize, int RingbufferSize)
{
closeMedia();
Expand Down
1 change: 1 addition & 0 deletions Core/HW/MediaEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class MediaEngine
bool loadStream(u8* buffer, int readSize, int RingbufferSize);
// open the mpeg context
bool openContext();
void closeContext();

// Returns number of packets actually added. I guess the buffer might be full.
int addStreamData(u8* buffer, int addSize);
Expand Down

0 comments on commit 2c38805

Please sign in to comment.