summaryrefslogtreecommitdiff
path: root/rotord/src/libavwrapper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rotord/src/libavwrapper.cpp')
-rw-r--r--rotord/src/libavwrapper.cpp41
1 files changed, 15 insertions, 26 deletions
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);