Skip to content

Commit a87d6b0

Browse files
committed
videoio: synchronize ffmpeg open() call
1 parent 9ee60db commit a87d6b0

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

modules/videoio/src/cap_ffmpeg_impl.hpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,12 +716,25 @@ static int LockCallBack(void **mutex, AVLockOp op)
716716
static ImplMutex _mutex;
717717
static bool _initialized = false;
718718

719+
class AutoLock
720+
{
721+
public:
722+
AutoLock(ImplMutex& m) : mutex(&m) { mutex->lock(); }
723+
~AutoLock() { mutex->unlock(); }
724+
protected:
725+
ImplMutex* mutex;
726+
private:
727+
AutoLock(const AutoLock&); // disabled
728+
AutoLock& operator = (const AutoLock&); // disabled
729+
};
730+
731+
719732
class InternalFFMpegRegister
720733
{
721734
public:
722735
InternalFFMpegRegister()
723736
{
724-
_mutex.lock();
737+
AutoLock lock(_mutex);
725738
if (!_initialized)
726739
{
727740
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 13, 0)
@@ -738,7 +751,6 @@ class InternalFFMpegRegister
738751

739752
_initialized = true;
740753
}
741-
_mutex.unlock();
742754
}
743755

744756
~InternalFFMpegRegister()
@@ -752,6 +764,7 @@ static InternalFFMpegRegister _init;
752764

753765
bool CvCapture_FFMPEG::open( const char* _filename )
754766
{
767+
AutoLock lock(_mutex);
755768
unsigned i;
756769
bool valid = false;
757770

0 commit comments

Comments
 (0)