diff options
| author | Tim Redfern <tim@eclectronics.org> | 2013-10-01 13:20:50 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2013-10-01 13:20:50 +0100 |
| commit | 36501495fa94759a5fcec3bd26ab184d684007c7 (patch) | |
| tree | 742c26da7dad722afd0522d60182c0ddc9bd05a2 | |
| parent | f67d7ee5b20105a05a0f170ed5eef81334ae12eb (diff) | |
scoped locks
| -rw-r--r-- | rotord/src/graph.cpp | 3 | ||||
| -rw-r--r-- | rotord/src/libavwrapper.cpp | 41 | ||||
| -rw-r--r-- | rotord/src/libavwrapper.h | 1 | ||||
| -rw-r--r-- | rotord/src/rendercontext.cpp | 1 |
4 files changed, 18 insertions, 28 deletions
diff --git a/rotord/src/graph.cpp b/rotord/src/graph.cpp index 771a807..2968c1f 100644 --- a/rotord/src/graph.cpp +++ b/rotord/src/graph.cpp @@ -543,6 +543,7 @@ bool Graph::load_audio(const string &filename,vector<Audio_processor*> processor Logger& logger = Logger::get("Rotor"); logger.information("Analysing "+filename); + audio_loaded=false; libav::audio_decoder loader; loader.open(filename); @@ -588,7 +589,7 @@ bool Graph::load_audio(const string &filename,vector<Audio_processor*> processor } logger.information("Finished audio analysis"); - + audio_loaded=true; return true; } bool Graph::load_video(const string &nodeID,const string &filename){ 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 <stdexcept> #include <iostream> #include <cassert> 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: "<<err.Buffer<<std::endl; - mutex.unlock(); return false; } int trackno = FFMS_GetFirstTrackOfType(index, FFMS_TYPE_VIDEO, &err); if (trackno < 0) { std::cerr<<"ffmpegsource: "<<err.Buffer<<std::endl; - mutex.unlock(); return false; } source = FFMS_CreateVideoSource(filename.c_str(), trackno, index, 1, FFMS_SEEK_NORMAL, &err); if (source == NULL) { std::cerr<<"ffmpegsource: "<<err.Buffer<<std::endl; - mutex.unlock(); return false; } FFMS_DestroyIndex(index); @@ -59,7 +56,6 @@ bool libav::video_decoder::open(const std::string& filename){ if (FFMS_SetOutputFormatV2(source, pixfmts, propframe->EncodedWidth, propframe->EncodedHeight, FFMS_RESIZER_BICUBIC, &err)) { std::cerr<<"ffmpegsource: "<<err.Buffer<<std::endl; - mutex.unlock(); return false; } int framenumber = 0; /* valid until next call to FFMS_GetFrame* on the same video object */ @@ -67,30 +63,26 @@ bool libav::video_decoder::open(const std::string& filename){ std::cerr<<"ffmpegsource: successfully opened "<<filename<<std::endl; loaded=true; - mutex.unlock(); return loaded; } bool libav::audio_decoder::open(const std::string& filename){ - mutex.lock(); + Mutex::ScopedLock lock(mutex); loaded=false; FFMS_Index *index = FFMS_MakeIndex(filename.c_str(),-1, 0, NULL, NULL, FFMS_IEH_IGNORE, NULL, NULL, &err); if (index == NULL) { std::cerr<<"ffmpegsource error making index for "<<filename<<":"<<err.Buffer<<std::endl; - mutex.unlock(); return false; } int trackno = FFMS_GetFirstTrackOfType(index, FFMS_TYPE_AUDIO, &err); if (trackno < 0) { std::cerr<<"ffmpegsource error finding audio track in "<<filename<<":"<<err.Buffer<<std::endl; - mutex.unlock(); return false; } std::cerr<<"ffmpegsource found audio track "<<trackno<<" in "<<filename<<":"<<err.Buffer<<std::endl; source = FFMS_CreateAudioSource(filename.c_str(), trackno, index, FFMS_DELAY_TIME_ZERO, &err); if (source == NULL) { std::cerr<<"ffmpegsource error creating audio source from "<<filename<<":"<<err.Buffer<<std::endl; - mutex.unlock(); return false; } FFMS_DestroyIndex(index); @@ -98,14 +90,12 @@ bool libav::audio_decoder::open(const std::string& filename){ std::cerr<<"ffmpegsource: successfully opened "<<filename<<std::endl; loaded=true; - mutex.unlock(); return loaded; } void libav::audio_decoder::cleanup(){ if (loaded) { - mutex.lock(); + Mutex::ScopedLock lock(mutex); FFMS_DestroyAudioSource(source); - mutex.unlock(); loaded=false; } } @@ -211,9 +201,8 @@ bool libav::exporter::record(std::string filename){ // open the output file, if needed // if (!(fmt->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); diff --git a/rotord/src/libavwrapper.h b/rotord/src/libavwrapper.h index 0d40503..4365899 100644 --- a/rotord/src/libavwrapper.h +++ b/rotord/src/libavwrapper.h @@ -7,6 +7,7 @@ #endif #include "Poco/Mutex.h" +#include "Poco/ScopedLock.h" extern "C" { #include <libavcodec/avcodec.h> diff --git a/rotord/src/rendercontext.cpp b/rotord/src/rendercontext.cpp index b04f3c4..47fa498 100644 --- a/rotord/src/rendercontext.cpp +++ b/rotord/src/rendercontext.cpp @@ -24,7 +24,6 @@ void Render_context::runTask() { } } if (graph.load_audio(graph.audio_filename,processors)) { - graph.audio_loaded=true; state=IDLE; } else { |
