From 36501495fa94759a5fcec3bd26ab184d684007c7 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Tue, 1 Oct 2013 13:20:50 +0100 Subject: scoped locks --- rotord/src/libavwrapper.cpp | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) (limited to 'rotord/src/libavwrapper.cpp') diff --git a/rotord/src/libavwrapper.cpp b/rotord/src/libavwrapper.cpp index 0c4004b..7ce9a0e 100644 --- a/rotord/src/libavwrapper.cpp +++ b/rotord/src/libavwrapper.cpp @@ -1,13 +1,14 @@ #include "libavwrapper.h" -extern Poco::FastMutex mutex; //application wide mutex -static Poco::FastMutex mutex; +extern Poco::Mutex mutex; //application wide mutex +static Poco::Mutex mutex; #include #include #include using namespace std; +using namespace Poco; void libav::maybeInitFFMpegLib() { @@ -22,32 +23,28 @@ void libav::maybeInitFFMpegLib() void libav::video_decoder::cleanup(){ if (loaded) { - mutex.lock(); + Mutex::ScopedLock lock(mutex); FFMS_DestroyVideoSource(source); - mutex.unlock(); loaded=false; } } bool libav::video_decoder::open(const std::string& filename){ - mutex.lock(); + Mutex::ScopedLock lock(mutex); loaded=false; FFMS_Index *index = FFMS_MakeIndex(filename.c_str(), 0, 0, NULL, NULL, FFMS_IEH_IGNORE, NULL, NULL, &err); if (index == NULL) { std::cerr<<"ffmpegsource: "<EncodedWidth, propframe->EncodedHeight, FFMS_RESIZER_BICUBIC, &err)) { std::cerr<<"ffmpegsource: "<flags & AVFMT_NOFILE)) { - mutex.lock(); + Mutex::ScopedLock lock(mutex); int ret = avio_open(&oc->pb, filename.c_str(), AVIO_FLAG_WRITE); - mutex.unlock(); if (ret < 0) { std::cerr <<"Could not open " << filename.c_str() << std::endl; return false; @@ -327,9 +316,8 @@ void libav::exporter::finishRecord(){ if (!(fmt->flags & AVFMT_NOFILE)) { // Close the output file. // - mutex.lock(); + Mutex::ScopedLock lock(mutex); avio_close(oc->pb); - mutex.unlock(); } // free the stream // @@ -424,11 +412,12 @@ void libav::exporter::open_video(AVFormatContext *oc, AVCodec *codec, AVStream * printf("open video 2.\n"); // open the codec // - mutex.lock(); - printf("open video 3.\n"); - ret = avcodec_open2(c, codec, NULL); //OPTIONS CAN GO HERE - printf("open video 4.\n"); - mutex.unlock(); + { + Mutex::ScopedLock lock(mutex); + printf("open video 3.\n"); + ret = avcodec_open2(c, codec, NULL); //OPTIONS CAN GO HERE + printf("open video 4.\n"); + } if (ret < 0) { //fprintf(stderr, "Could not open video codec: %s\n", av_err2str(ret)); exit(1); -- cgit v1.2.3