Commit 58c5be00 authored by Maksim Shabunin's avatar Maksim Shabunin

Merge pull request #9006 from alalek:videoio_synchronize_ffmpeg_open

parents 9e9f57c1 a87d6b09
...@@ -716,12 +716,25 @@ static int LockCallBack(void **mutex, AVLockOp op) ...@@ -716,12 +716,25 @@ static int LockCallBack(void **mutex, AVLockOp op)
static ImplMutex _mutex; static ImplMutex _mutex;
static bool _initialized = false; static bool _initialized = false;
class AutoLock
{
public:
AutoLock(ImplMutex& m) : mutex(&m) { mutex->lock(); }
~AutoLock() { mutex->unlock(); }
protected:
ImplMutex* mutex;
private:
AutoLock(const AutoLock&); // disabled
AutoLock& operator = (const AutoLock&); // disabled
};
class InternalFFMpegRegister class InternalFFMpegRegister
{ {
public: public:
InternalFFMpegRegister() InternalFFMpegRegister()
{ {
_mutex.lock(); AutoLock lock(_mutex);
if (!_initialized) if (!_initialized)
{ {
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 13, 0) #if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 13, 0)
...@@ -738,7 +751,6 @@ public: ...@@ -738,7 +751,6 @@ public:
_initialized = true; _initialized = true;
} }
_mutex.unlock();
} }
~InternalFFMpegRegister() ~InternalFFMpegRegister()
...@@ -752,6 +764,7 @@ static InternalFFMpegRegister _init; ...@@ -752,6 +764,7 @@ static InternalFFMpegRegister _init;
bool CvCapture_FFMPEG::open( const char* _filename ) bool CvCapture_FFMPEG::open( const char* _filename )
{ {
AutoLock lock(_mutex);
unsigned i; unsigned i;
bool valid = false; bool valid = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment