diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-05-02 17:45:42 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-05-02 17:45:42 +0100 |
| commit | fde38b664c98205dd4fe3721b125469d5dd2ecbe (patch) | |
| tree | d6462797c4f2c27d2a3342112555e61c9c097e03 /src/lib | |
| parent | 693c691413536c523150fa1c96ab00a4a39f23ac (diff) | |
Hack around crash on exist of tests due to race between ~FFmpeg and __cxa_finalize.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/ffmpeg.cc | 18 | ||||
| -rw-r--r-- | src/lib/ffmpeg.h | 2 |
2 files changed, 15 insertions, 5 deletions
diff --git a/src/lib/ffmpeg.cc b/src/lib/ffmpeg.cc index a98aa9828..b78a0bbf6 100644 --- a/src/lib/ffmpeg.cc +++ b/src/lib/ffmpeg.cc @@ -35,7 +35,13 @@ using std::stringstream; using boost::shared_ptr; using boost::lexical_cast; -boost::mutex FFmpeg::_mutex; +/* This should not really be a pointer, but I find that __cxa_finalize tries + * to destroy the mutex while a call to ~FFmpeg is in progress; this crashes + * with a failure of assert (!posix::pthread_mutex_destroy(&m)); + * + * The hacky work-around is never to destroy the mutex... + */ +boost::mutex* FFmpeg::_mutex; FFmpeg::FFmpeg (boost::shared_ptr<const FFmpegContent> c) : _ffmpeg_content (c) @@ -46,6 +52,10 @@ FFmpeg::FFmpeg (boost::shared_ptr<const FFmpegContent> c) , _frame (0) , _video_stream (-1) { + if (!_mutex) { + _mutex = new boost::mutex (); + } + setup_general (); setup_video (); setup_audio (); @@ -53,7 +63,7 @@ FFmpeg::FFmpeg (boost::shared_ptr<const FFmpegContent> c) FFmpeg::~FFmpeg () { - boost::mutex::scoped_lock lm (_mutex); + boost::mutex::scoped_lock lm (*_mutex); for (uint32_t i = 0; i < _format_context->nb_streams; ++i) { AVCodecContext* context = _format_context->streams[i]->codec; @@ -145,7 +155,7 @@ FFmpeg::setup_general () void FFmpeg::setup_video () { - boost::mutex::scoped_lock lm (_mutex); + boost::mutex::scoped_lock lm (*_mutex); assert (_video_stream >= 0); AVCodecContext* context = _format_context->streams[_video_stream]->codec; @@ -163,7 +173,7 @@ FFmpeg::setup_video () void FFmpeg::setup_audio () { - boost::mutex::scoped_lock lm (_mutex); + boost::mutex::scoped_lock lm (*_mutex); for (uint32_t i = 0; i < _format_context->nb_streams; ++i) { AVCodecContext* context = _format_context->streams[i]->codec; diff --git a/src/lib/ffmpeg.h b/src/lib/ffmpeg.h index 760918437..04be4873a 100644 --- a/src/lib/ffmpeg.h +++ b/src/lib/ffmpeg.h @@ -75,7 +75,7 @@ protected: a mutex around calls to avcodec_open* and avcodec_close... and here it is. */ - static boost::mutex _mutex; + static boost::mutex* _mutex; private: void setup_general (); |
